Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Refactor StateCircuit + add lexicographic ordering constraints#135

Closed
z2trillion wants to merge 27 commits into
mainfrom
feat/state_circuit_refactor
Closed

Refactor StateCircuit + add lexicographic ordering constraints#135
z2trillion wants to merge 27 commits into
mainfrom
feat/state_circuit_refactor

Conversation

@z2trillion
Copy link
Copy Markdown

No description provided.

@z2trillion z2trillion force-pushed the feat/state_circuit_refactor branch 4 times, most recently from 0e0d3ba to 754f13c Compare April 7, 2022 02:03
@lispc
Copy link
Copy Markdown

lispc commented Apr 8, 2022

I noticed the CI testing time become much longer ( due to larger degree of state circuit).

I think in testing state circuti, we can use "active rows range" like evm circuit to speed up it?

Comment thread zkevm-circuits/src/state_circuit/constraint_builder.rs Outdated
Comment thread zkevm-circuits/src/state_circuit/state_tests.rs Outdated
Comment thread zkevm-circuits/src/state_circuit/lexicographic_ordering.rs
Comment thread zkevm-circuits/src/state_circuit/lexicographic_ordering.rs Outdated
@lispc
Copy link
Copy Markdown

lispc commented Apr 11, 2022

Fixed column should not be different between different circuit instances so pk/vk can be same.Although current state circuit before this PR also did not meet this requirement, we'd better fix this problem in this PR.

Comment thread zkevm-circuits/src/state_circuit/constraint_builder.rs Outdated
Comment thread zkevm-circuits/src/state_circuit/lexicographic_ordering.rs Outdated
// 30 limbs in total -> can fit into two field elements
#[derive(Clone)]
pub struct Config<F: Field> {
diff_1: Column<Advice>,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

could you rename diff_1 diff_2 more readable? such as diff + tag name or field name

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I can't think of better names for diff_1 and diff_2.

To explain what they are:
We want to show that X > Y, where A0, A1, ..., A29 are the 30 limbs of X and B0, B1, ..., B29 are the 30 limbs of Y, in big endian order. Let
C0 = A0 - B0,
C1 = C0 << 16 + A1 - B1,
C2 = C1 << 16 + A2 - B2,
...
C14 = C13 << 16 + A14 - B14,
and
C15 = A15 - B15,
...
C29 = C28 << 16 + A29 - B29.

X > Y iff one of the following is true:
1. one of C0, ..., C14 is non-zero and fits into 16 bits.
2. all of C0, ..., C14 are 0 and one of C15, ..., C29 is non-zero and fits into 16 bits.
(note that "all of C0, ..., C14 are 0" is equivalent to "C14 is 0")

The (diff_1, diff_2, diff_1_zero, diff_2_is zero) advice columns the constraints on them should be witnesses that prove that either 1. or 2. is true.

diff_2 is constrained to be one of the 15 values C15, ..., C29. The limbs involved are the 13 least significant limbs of the storage key and the 2 limbs of the rw_counter. The limbs involved indiff_1 are the remaining 15 (tag, field_tag, id, address, + 2 most significant limbs of the storage key).

I am open to suggestions for more descriptive names if you can think of any.

@z2trillion z2trillion force-pushed the feat/state_circuit_refactor branch from f6b97c6 to eb88bc4 Compare April 28, 2022 18:29
@lispc
Copy link
Copy Markdown

lispc commented May 4, 2022

replaced by privacy-ethereum#462

@lispc lispc closed this May 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants