2

Newbie here. I've been reading through the (excellent) Ethereum whitepaper and had the following question:

If gas is used every time the program is executed, and the program is executed on multiple nodes (presumably, simultaneously) — what's to prevent all of the gas from getting consumed each time (i.e. gas consumed = STARTGAS every time)?

0

1 Answer 1

3

"Executing the program" means validating the transaction that calls a function. Every node that validates the transaction "applies" the transaction over the same state (See block validation algorithm below). So if the initial system state is S[0], the transactions in the block will be applied to that state and the final state S[n] will be computed. Each node will do the same when validating a block, starting with the same S[0] and ending with the same S[n]. The amount of ether in an account (to pay for the gas) is part of the system state. So gas used for execution on multiple nodes does not add up.

Here is an extract from https://github.com/ethereum/wiki/wiki/White-Paper#code-execution, explaining the basic block validation

  1. Check if the previous block referenced exists and is valid.
  2. Check that the timestamp of the block is greater than that of the referenced previous block and less than 15 minutes into the future
  3. Check that the block number, difficulty, transaction root, uncle root and gas limit (various low-level Ethereum-specific concepts) are valid.
  4. Check that the proof of work on the block is valid.
  5. Let S[0] be the state at the end of the previous block.
  6. Let TX be the block's transaction list, with n transactions. For all i in 0...n-1, set S[i+1] = APPLY(S[i],TX[i]). If any application returns an error, or if the total gas consumed in the block up until this point exceeds the GASLIMIT, return an error.
  7. Let S_FINAL be S[n], but adding the block reward paid to the miner.
  8. Check if the Merkle tree root of the state S_FINAL is equal to the final state root provided in the block header. If it is, the block is valid; otherwise, it is not valid.
0

Your Answer

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

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