An optional data field
A STARTGAS value
Essentially, a message is like a transaction, except it is produced by a contract and not an
external actor. A message is produced when a contract currently executing code executes
the CALL opcode, which produces and executes a message. Like a transaction, a
message leads to the recipient account running its code. Thus, contracts can have
relationships with other contracts in exactly the same way that external actors can.
Note that the gas allowance assigned by a transaction or contract applies to the total gas
consumed by that transaction and all sub-executions. For example, if an external actor A
sends a transaction to B with 1000 gas, and B consumes 600 gas before sending a
message to C, and the internal execution of C consumes 300 gas before returning, then B
can spend another 100 gas before running out of gas.
Ethereum State Transition Function
The Ethereum state transition function, APPLY(S,TX) -> S' can be defined as follows:
1. Check if the transaction is well-formed (ie. has the right number of values), the
signature is valid, and the nonce matches the nonce in the sender's account. If not,
return an error.
2. Calculate the transaction fee as STARTGAS * GASPRICE , and determine the sending
address from the signature. Subtract the fee from the sender's account balance and
increment the sender's nonce. If there is not enough balance to spend, return an error.
3. Initialize GAS = STARTGAS , and take off a certain quantity of gas per byte to pay for
the bytes in the transaction.
4. Transfer the transaction value from the sender's account to the receiving account. If
the receiving account does not yet exist, create it. If the receiving account is a
contract, run the contract's code either to completion or until the execution runs out of
gas.
5. If the value transfer failed because the sender did not have enough money, or the code
execution ran out of gas, revert all state changes except the payment of the fees, and
add the fees to the miner's account.
6. Otherwise, refund the fees for all remaining gas to the sender, and send the fees paid
for gas consumed to the miner.
For example, suppose that the contract's code is:
if !self.storage[calldataload(0)]:
self.storage[calldataload(0)] = calldataload(32)
Note that in reality the contract code is written in the low-level EVM code; this example is
written in Serpent, one of our high-level languages, for clarity, and can be compiled down
to EVM code. Suppose that the contract's storage starts off empty, and a transaction is
sent with 10 ether value, 2000 gas, 0.001 ether gasprice, and 64 bytes of data, with bytes
0-31 representing the number 2 and bytes 32-63 representing the string CHARLIE .
The process for the state transition function in this case is as follows:
1. Check that the transaction is valid and well formed.
2. Check that the transaction sender has at least 2000 * 0.001 = 2 ether. If it is, then
subtract 2 ether from the sender's account.
3. Initialize gas = 2000; assuming the transaction is 170 bytes long and the byte-fee is 5,
subtract 850 so that there is 1150 gas left.
fn. 6