Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Add MPT table lookup to state circuit #200

Merged
merged 4 commits into from
May 23, 2022
Merged

Conversation

ed255
Copy link
Member

@ed255 ed255 commented May 17, 2022

Introduce MPT table lookups from the state circuit for Storage and Account operations.

@ed255 ed255 requested a review from a team as a code owner May 17, 2022 10:42
@ed255 ed255 requested a review from han0110 May 17, 2022 10:42
src/zkevm_specs/state.py Outdated Show resolved Hide resolved
src/zkevm_specs/state.py Outdated Show resolved Hide resolved
@ed255 ed255 force-pushed the feature/state-circuit-update branch from d8f9dbf to 7f5edba Compare May 18, 2022 11:23
Copy link
Collaborator

@han0110 han0110 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice work!

@ed255
Copy link
Member Author

ed255 commented May 19, 2022

@z2trillion could you help as a second reviewer for this PR?

@lispc
Copy link
Collaborator

lispc commented Jun 2, 2022

@noel2004 have a question on the mpt_counter. In the current code, the mpt_counter increases with keys lexicographic ordering.
But in the mpt side, the counter should be in wall clock time order?

So we have two option
(1) adjust mpt_counter in state circuit using wallet clock time order(or similar with rw_counter) too. EVM circuit can have constraints like if storage_related_rw() { rwc++; mpt_counter++; } else { rwc++} We may have to add mpt_counter into rw table?
(2) let mpt circuit update state root in the same order with current state circuit mpt counter, lexicographic ordering. It can get the same final root, but it is very counter intuitive.. And not easy to debug.

@ed255

@ed255
Copy link
Member Author

ed255 commented Jun 2, 2022

@noel2004 have a question on the mpt_counter. In the current code, the mpt_counter increases with keys lexicographic ordering. But in the mpt side, the counter should be in wall clock time order?

So we have two option (1) adjust mpt_counter in state circuit using wallet clock time order(or similar with rw_counter) too. EVM circuit can have constraints like if storage_related_rw() { rwc++; mpt_counter++; } else { rwc++} We may have to add mpt_counter into rw table?
(2) let mpt circuit update state root in the same order with current state circuit mpt counter, lexicographic ordering. It can get the same final root, but it is very counter intuitive.. And not easy to debug.

From my point of view, option 2 has always been the one considered for the design, because it's simpler. We already process stack and memory in key order instead of chronological order (in the state circuit), and we know that the result is equivalent to processing the updates chronologically (in terms of read consistency). So it doesn't seem strange to me that we do the same for state/storage updates.

Why do you think approach 2 is not easy to debug?

Here's a rough description of the witness generation process, taken from privacy-scaling-explorations/zkevm-circuits#222:

Generate intermediate proofs for StorageOps and AccountOps (Blocked by inputs / witness spec of MPT Circuit https://github.com/appliedzkp/zkevm-circuits/tree/mpt2)

  • Sort all StorageOps, AccountOps, AccountDeletedOps by (address, key, rwc)
  • Use wrapper over MPT witness generation https://github.com/miha-stopar/mpt
  • For each unique (address, key), get a "before" proof, apply last write, get "after" proof
  • Sort all AccountOps by (address, rwc)
  • For each unique (address), get "before" proof, apply write with final values, get "after" proof

Following approach (2) we will encounter intermediate state roots that never happened in geth (because of the reordering), so we'll have a partial mpt which we will be updating following the lexicographic ordering, to get the intermediate proofs between updates.

@lispc
Copy link
Collaborator

lispc commented Jun 2, 2022

ok i understand the design. "we will encounter intermediate state roots that never happened in geth" is what i think as "counter intuitive". For the "uneasy to debug", i thought of bug case where the replay final root is not same with real final root, yeah, it is only bug after it is fixed it will be ok later. No problem~ Thanks for the explanation

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants