Transactions and Messages
Ethereum transactions correspond to data packages that are signed by the private key of the issuing EOA. Transactions contain the recipient, a signature identifying the sender, the amount of Ether to be transferred along with the transaction, and an optional data field.
Resources used for transaction execution are subject to fees. The corresponding unit is gas. Transactions include two further fields, which are related to gas. The startGas value specifies the maximal amount of gas that the execution of the transaction may consume. The gasPrice value indicates how to convert between Ether and gas.
Finally, transactions comprise a nonce field, whose value has to match the sender’s account current nonce. This is necessary to prevent replay attacks.
Figure 9.2 Transaction execution in Ethereum.
Note that in Ethereum, messages are constructed similarly to transactions, but are sent from contract accounts.
State and Transaction Execution
Ethereum is a state machine where transaction execution triggers a state transition. The Ethereum state is a mapping between account addresses and account states. The state is not stored within the blockchain, but maintained by the clients.
An exemplary transaction execution is depicted in Figure 9.2. Note that transaction execution is completely deterministic.
In this example, the transaction limits the amount of gas available for its execution to 2,000. The corresponding amount of Ether is then subtracted from the sender's balance up front. The sender has to pay for each byte in the transaction. We assume that this consumes 1,000 gas. In the next step, 10 Ether are transferred from the sender's balance to the receiver's balance. Since the receiving account is a contract, its associated code is triggered. Here, the account’s storage is modified. Assuming that the code execution costs 200 gas, the remaining 800 gas are then refunded to the sender (in Ether).
Making all resource consumption subject to fees and limiting the amount of gas that can be spent during the execution of a transaction prevents infinite loops, which are necessary to prevent DoS attacks.