Remix.run Logo
ekjhgkejhgk 7 hours ago

Can someone explain smart contracts to me?

Ok, I understand that it's a description in code of "if X happens, then state becomes Y". Like a contract but in code. But, someone has to input that X has happened. So is it not trivially manipulated by that person?

nrhrjrjrjtntbt 6 hours ago | parent | next [-]

The pure (if you like) smart contacts do transactions. You give me 100 apple tokens and I give you 50 pear tokens. The contract ensures nothing else can happen.

They get more sophisticated e.g. automatic market makers. But same idea just swapping.

Voting is also possible e.g. release funds if there is a quorom. Who to release them to could be hard coded or part of the vote.

For external info from the real world e.g. "who got elected" you need an oracle. I.e. you trust someone not to lie and not to get hacked. You can fix the "someone" to a specific address but you still need to trust them.

wildzzz 6 hours ago | parent [-]

That's a great explanation. I'm sure it's a lot deeper than that but I've never really understood the purpose. I'm not a crypto guy at all so it's nice hearing real world applications rather than just "stock market babble".

packetlost 3 hours ago | parent [-]

Smart contracts are actually pretty cool, but the entire ecosystem is made dramatically worse by the tokens having speculative value. It’s necessary for the economics to work out, but it dampens the coolness of the technical aspects because it attracts sleazeballs and enables fraud/crime.

patrickaljord 7 hours ago | parent | prev | next [-]

Once a contract is deployed on the blockchain, its source code is immutable. So before using a contract, check if it gives permission to its deployer (or any address) to change any state at will.

Note that some contracts act as proxy to other contract and can be made to point to another code through a state change, if this is the case then you need to trust whoever can change the state to point to another contract. Such contract sometime have a timelock so that if such a change occurs, there's a delay before it is actually activated, which gives time to users to withdraw their funds if they do not trust the update.

If you are talking about Oracle contracts, if it's an oracle involving offchain data, then there will always be some trust involved, which is usually managed by having the offchain actors share the responsibility and staking some money with the risk to get slashed if they turn into bad actors. But again, offchain data oracles will always require some level of trust that would have to deal with in non-blockchain apps too.

Animats 2 hours ago | parent [-]

> Once a contract is deployed on the blockchain, its source code is immutable.

Maybe. Some smart contracts have calls to other contracts that can be changed.[1] This turns out to have significant legal consequences.

[1] https://news.bloomberglaw.com/us-law-week/smart-contracts-ru...

rcbdev 2 hours ago | parent [-]

Yes! When developing Smart Contracts this used to be a best practice, enabling us to fix security holes in worst case scenarios.

2 hours ago | parent [-]
[deleted]
pawelduda 6 hours ago | parent | prev | next [-]

Unless you know and trust person X, you don't want to authorize and interact with such contracts. Scammers will leave loopholes in code so they can, for example, grab all funds deposited to the contract.

Normal contracts that involve money operations would have safeguards that disallow the owner to touch balance that is not theirs. But there's billion of creative attack vectors to bypass that, either by that person X, or any 3rd party

momentmaker 7 hours ago | parent | prev | next [-]

blockchains are isolated environment where it can only know about data/states within itself.

if outside data is needed, then it needs something called an oracle, which delivers real-world and/or even other blockchain data to it.

you can learn more about oracle here: https://chain.link/education/blockchain-oracles

SV_BubbleTime 6 hours ago | parent [-]

I’m convinced that there is a reason from blockchain, but it was like 10 years too early - OR - we’ve already passed the problem it solves and didn’t notice.

PunchyHamster 6 hours ago | parent [-]

Well, technically DVCSes like git use "blockchain" (the repo, logically, is pretty much a chain of blocks that incorporate the hash of the previous blocks - just tree instead of linear dependency).

So we are already successfully using blockchain for decades just not as... currency provider.

Forward secure sealing (used in logging) also have similar idea

DennisP 5 hours ago | parent [-]

What makes it a block chain instead of a tree is that there's a way to form consensus on which block is the next in the chain.

What makes it different than database logging is that the consensus method is distributed and decentralized, and anyone can participate.

LikesPwsh 7 hours ago | parent | prev | next [-]

That's infamously known as the "Oracle Problem".

Blockchain can't handle external state.

Smart contracts abstract it a bit by having a trusted third party or an automated pricing mechanism, but both are fragile.

PunchyHamster 6 hours ago | parent [-]

It's funny that it just re-invented stuff already used for old world finances, and just invented escrow with more moving parts while still requiring non-compromised 3rd party.

TheRoque 7 hours ago | parent | prev | next [-]

Not sure what you mean that "input that X has happened". You don't directly input the changes, instead, you call a function that creates that state change (or not, if it's invalid), by running its code. This code can include checks on who is the caller, it can check if you're the contract owner, if you're someone who already interacted with the contract (by checking previous state), or any hardcoded address etc.

Philpax 7 hours ago | parent | prev | next [-]

Yes, this is a problem (look up "the oracle problem"). My understanding is that the conventional solution is to rely on trusted third-party oracles that are outside of the control of the contract's participants and/or require consensus over multiple oracles.

px43 7 hours ago | parent | prev | next [-]

State is globally distributed, and smart contract code executes state transitions on that state. When someone submits a transaction with certain function parameters, anyone can verify that those parameters will lead to that exact state transition.

dboreham 6 hours ago | parent | prev | next [-]

There's already many replies, but I'm not sure any of them answers your question directly:

You are somewhat correct that contracts take external inputs in some cases, but note that this isn't a given. For example you could have a contract that has the behavior "if someone deposits X scoin at escrow address A, send them Y gcoin from escrow address Y". That someone can only deposit scoins and get gcoins in exchange. They can't just take all the escrow account balances. So there are inputs, but they are subject to some sort of validation and contract logic that limits their power. Blockchain people call this an "on-chain event".

So short answer is: no smart contracts can't be trivially manipulated by someone, including their owner. But not being able to do that depends on there not being any bugs or back doors in the contract code.

If you are asking about a contract that has some bearing on an event in meat-space, such as someone buying a house, or depositing a bar of gold in a room somewhere, then that depends on someone telling the contract it happened. Blockchain people call this an "off-chain event". This is the "oracle problem" that you'll see mentioned in other replies. Anything off-chain is generally regarded by blockchain folks as sketchy, but sometimes unavoidable. E.g. betting markets need some way to be told that the event being bet on happened or didn't happen. The blockchain has no way to know if it snowed in Central London on December 25.

6 hours ago | parent | prev | next [-]
[deleted]
bgwalter 6 hours ago | parent | prev | next [-]

You can create hot air "organizations" with contract rules on the Ethereum blockchain. If the inner circle does not like a contract, they fork everything:

https://en.wikipedia.org/wiki/The_DAO

It's all a toy for rug pulls and speculation. "AI" attacking the blockchain is hilarious. I wish the blockchain could also attack "AI".

yieldcrv 4 hours ago | parent | prev [-]

they're like a Trust that self executes distributions

except that they cost a fraction of a cent to create instead of several thousand dollars in lawyer fees for the initial revision, and can be tested in infinite scenarios for free

to your theoretical reservation, the trust similarity continues, as the constraints around the X are also codified. The person that triggers it can only send sanitized information, isn't necessarily an administrator, admins/trustees can be relinquished for it to be completely orphaned, and so on