This repository has been archived by the owner on Jul 5, 2024. It is now read-only.
Consisntency between State circuit account updates and MPT #395
Labels
discussion
Discussion that may not have an action
Related to #354 and #259
The current design involves encoding non-existing accounts in the State Circuit as account with code_hash = 0.
Notice that the update proofs that the MPT circuit supports require that the leaf exists after the update (so they can be used as account field update proof or account creation proof with an initial account field value).
Using code_hash = 0 means that we can end up with a StateCircuit "merged" update of code_hash 0 -> 0. This is interpreted as account didn't exist before and doesn't exist afterwards, so the StateCircuit maps it to an AccountNonExisting proof of the MPT.
Nevertheless I found out that this is not enough. Even if we follow these rules:
We may encounter a Rw trace that is incompatible with the MPT proof types with the current State Circuit implementation, and this comes from the fact that a revert will delete an account.
Imagine the following scenario with account creation that is reverted:
Rw chronological trace:
RwTable:
State - MPT updates:
We end up with a Nonce update from 0->0 for an account that doesn't exist. The State Circuit currently doesn't support this scenario.
Here are the list of special cases we can encounter:
Account.CodeHash 0->0
Account.Nonce 0->0
nonce=0
doesn't tell us anything about account existence (for example, after a transfer to a non-existing account, the account is created with positive balance but nonce is still 0).Account.Balance 0->0
balance=0
doesn't tell us anything about account existence.Thoughts and possible solutions.
Account.Nonce 0->0
andAccount.Balance 0->0
to non-existing proofs conditionally.code_hash
before doing anything with a possibly non-existing account, and create accounts by settingcode_hash != 0
as the first account write lookup.Account.CodeHash
in RwTable beforeAccount.Nonce
,Account.Balance
,AccountStorage
, we know that the StateTrie Root at after allAccount.CodeHash
updates has a leaf for each account that will exist by the end of the block.Account.Nonce 0->0
orAccount.Balance 0->0
we don't care if the account exists or not, only that one of these is true: either the account exists, or it has the account field value at 0. The reason why we don't care, is because in the EVM Circuit we previously performed aCodeHash
read to determine account existence and proceeded with constraints using that information.The text was updated successfully, but these errors were encountered: