Verify Ethereum Smart Contract State with Proof

Leo Zhang
7 min readJul 24, 2022

In previous blog post, we introduced how to verify account state with state proof.

In this blog post, I will introduce how data is stored in Ethereum smart contract, and how to verify the storage state with proof.

What to store in smart contract storage

Ethereum smart contract is also an account, which has its own account state, such as account balance, nonce. In addition to that, it also has code and extra storage.

The storage of a smart contract is essentially a key-value pair store. In order to generate and store proof for the existence of a key-value pair, a Merkle Patricia Trie is constructed to store the key value pairs.

What is the actual key value pairs to be stored in storage?

In order to explain that, let’s use a smart contract as an example. For simplicity, I will use the default Migration contract from truffle:

// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
contract Migrations {
address public owner = msg.sender;
uint public last_completed_migration;
modifier restricted() {
require(
msg.sender == owner,
"This function is restricted to the contract's owner"
);
_;
}
function setCompleted(uint completed) public restricted {
last_completed_migration = completed;
}
}

--

--