freecoding.school100% FREE · NO SIGNUP
The EVM CoreISSUE #22 of 48

the yellow paper · formal evm semantics

SoliaVSThe Reentrancy Reaper
Solia saysThe Yellow Paper formalizes the EVM as σ’ = Y(σ, T): the world state σ transitions to σ’ by applying transaction T through the state-transition function Y.

The Ethereum Yellow Paper defines the EVM as a formal state machine. The world state σ is a mapping from addresses to accounts (balance, nonce, storage root, code hash). The transaction T carries fields like from, to, value, data, gas. The transition function Y produces σ’: it checks preconditions (signature, nonce, balance), executes T, meters gas, and returns the new world state.

The formalism is intimidating but it pays off: every implementation (Geth, Reth, Nethermind, Erigon) must agree on σ’ byte-for-byte. The demo runs a tiny Y on a toy state with a simple transfer and shows the formal pre and post conditions.

Power-ups you unlock

The Reentrancy Reaper attacks — common mistakes

Boss battleApply Y to a toy state for a simple transfer and verify the pre-conditions (nonce, balance) are checked.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>
// Y: σ × T → σ' with formal pre-conditions.
function Y(sigma, T){
  const sp = JSON.parse(JSON.stringify(sigma));     // copy
  const a = sp.accounts[T.from], b = sp.accounts[T.to];
  if(!a)                  throw new Error('precondition fail: from has no account');
  if(a.nonce !== T.nonce) throw new Error('precondition fail: nonce ' + a.nonce + ' ≠ ' + T.nonce);
  if(a.balance < T.value) throw new Error('precondition fail: balance ' + a.balance + ' < value ' + T.value);
  a.balance -= T.value;
  b.balance += T.value;
  a.nonce   += 1;
  return sp;
}
const sigma = { accounts:{ alice:{ balance:100, nonce:5 }, bob:{ balance:50, nonce:0 } } };
const T = { from:'alice', to:'bob', value:30, gas:21000, nonce:5 };
const sigmaPrime = Y(sigma, T);
document.getElementById('o').textContent = [
  'σ  (before): ' + JSON.stringify(sigma.accounts),
  'T          : ' + JSON.stringify(T),
  'σ’ (after) : ' + JSON.stringify(sigmaPrime.accounts),
  '',
  'all clients must produce IDENTICAL σ’ → consensus on state'
].join('\n');
</script></body></html>
▶ Open the interactive comic issue
‹ Access Lists · Warm Vs Cold · Eip-2929/2930Eof · Evm Object Format ›