17

More technically speaking, what does it mean to "run code on the blockchain"? Does it mean that

  1. we store the source code and then every full node runs that source code several times?

If, for Bitcoin, which merely stores transactions, there is already an overwhelming scaling issue due to blockchain size and the CPU time it takes to verify all the blocks, then how can Ethereum scale while also having to store arbitrary code on the blockchain?

1
  • I am also curious to find out the answer.
    – niksmac
    Jan 24, 2016 at 3:16

1 Answer 1

21

Code is run on the blockchain through the use of smart contracts. Each smart contract has an address, storage, and code. When a transaction is sent to a contract's address, it's code is run on every node, inside the Ethereum Virtual Machine (EVM), and the contract can send Ether, call other contracts, and write to it's own storage.

Scaling is handled through the use of gas. Every computational step, even sending a regular transaction or creating a contract, requires some amount of gas (which can be negative for operations like deleting stored data). This gas is sent along with the transaction, and is paid to the miner, and if insufficient gas is provided, all state changes are rolled back.

When a transaction is sent, the user specifies the maximum gas that they are willing to spend, and the price (in Ether per gas) that they are willing to pay for it. Miners are then able to choose to process transactions that provide the highest gas price.

Miners also get to choose the block gas limit

The gas limit determines how much computation and storage can be used per block. On each block, the miner gets to set the new gas limit, but may only increase or decrease the limit by 1/1024th of the previous limit.

This means that miners are able to vote to keep the block sizes small enough to process, and the price of computation is flexible, depending on supply and demand.

Other scaling techniques

  1. Off-chain computation:

    • By using computation markets, code execution can be done off-chain by default, and only verified on-chain if there is a dispute.
  2. State Channels:

    • Similar to payment channels, parties lock some part of the state into a contract that requires signatures from all parties to edit. Parties transact amongst themselves and only submit the updated state if there is a dispute.
  3. More theoreticall stuff:

3
  • That is a very informative answer and makes a lot of sense in a broader level. I'd still need to do some math before believing the whole thing works and nothing is off, such as gas converging to be too expensive for anything to work. Nether less, if I could just have a whole book as informative as this answer covering everything about Ethereum, that's something I'd gladly spend a few dollars on. Or Ether.
    – MaiaVictor
    Jan 24, 2016 at 3:48
  • I am personally of the opinion that as little computation should be done on-chain as possible, and that gas will become somewhat expensive in the future, but that miners will also compete to make the system more efficient. Jan 24, 2016 at 3:52
  • 1
    And indeed, the high price of gas relative any other real-world computation gives strong incentives for application developers to make absolutely minimal use of on-chain computation, via techniques such as state channels and deposit-challenge-verify mechanisms. Jan 24, 2016 at 6:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.