[Ethereum] What does it mean to “run code on the blockchain”? Wouldn’t blockchain become huge

blockchainscalabilityturing-completeness

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?

Best Answer

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:

Related Topic