kkrt-labs / kakarot

Kakarot is a zkEVM written in Cairo, leveraging the STARK proof system.
https://kakarot.org
MIT License
936 stars 274 forks source link

feat: add code hash to the Account storage #1267

Closed ClementWalter closed 1 month ago

ClementWalter commented 1 month ago

Feature Request

Describe the Feature Request

Currently the EXTCODEHASH opcode computes the hash of the deployed account.

We should cache this value so not to do it again and again.

obatirou commented 1 month ago

@ClementWalter An other solution instead of adding it to the Account storage and having to do a read of storage would be to store it in the state hence modify the model.Account with a new field codeHash It will allow to retrieve the cached value (computed at creation) directly with let account = State.get_account(evm_address); here
The codehash is also necessary for the account trie computation hence will need to be added anyway

https://ethereum.org/en/developers/docs/data-structures-and-encoding/patricia-merkle-trie/#state-trie

State Trie There is one global state trie, and it is updated every time a client processes a block. In it, a path is always: keccak256(ethereumAddress) and a value is always: rlp(ethereumAccount). More specifically an ethereum account is a 4 item array of [nonce,balance,storageRoot,codeHash]. At this point, it's worth noting that this storageRoot is the root of another patricia trie

Though this solution would mean compute the codeHash at each execution. So this might not be ideal for starknet. It seems both will need to be implemented at some point.

Update: working on the first solution as it makes more sense for starknet