I'm trying to get my head around how computation in the EVM works in this example.

``````PC: 3 STACK:  MEM: [], STORAGE: {}
``````

SLOAD pops one from the stack, and pushes the value in contract storage at that index onto the stack. Since the contract is used for the first time, it has nothing there, so zero.

``````PC: 4 STACK:  MEM: [], STORAGE: {}
``````

Can someone explain what SLOAD did? It says "pops one from the stack", ok that would be 54. "And pushes the value in contract storage" Which value? The one popped (i.e, the key?) or the message value? and then nothing is added to storage.. no idea whats going on :S

This is the state before the `SLOAD`:

``````PC: 3 STACK:  MEM: [], STORAGE: {}
``````

The phrase "SLOAD pops one from the stack" means it takes the top item from the stack, in this case 54. This is the operand for SLOAD.

So `SLOAD` then looks up the value of key 54 in contract storage and pushes the value it finds there to the stack. In this case the value of storage at key 54 is zero (since the contract is being run for the first time), so the value pushed to the stack is `0`.

Hence the final state (just zero on the stack).

``````PC: 4 STACK:  MEM: [], STORAGE: {}
``````

I think you were misled by the phrase, "pushes the value in contract storage" - this is very lazily worded. It would be clearer to say "takes the value from contract storage and pushes it to the stack".

• to further clarify this, SLOAD pops the key 54 from the stack and checks in storage what is the value with key 54. Since the storage is empty, zero will be added to the stack. This wasn't clear for me either, one might think that since the key is missing we shouldn't add anything to the stack but SLOAD decides to set the value to 0. Dec 8, 2017 at 6:49
• Yes, non-present storage values are defined to be zero in the EVM, and vice-versa. Dec 8, 2017 at 6:58