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

Inserted extension node #1548

Closed
wants to merge 304 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
304 commits
Select commit Hold shift + click to select a range
b29ac5f
account drifted leaf RLC computation now takes into account new nonce…
miha-stopar May 30, 2022
5922091
fix
miha-stopar May 30, 2022
3e37a24
account_leaf_key after placeholder branch fix
miha-stopar Jun 1, 2022
b48d6f5
drifted leaf constraints when account deleted
miha-stopar Jun 1, 2022
7fc9cf6
PoisonedConstraint fix
miha-stopar Jun 2, 2022
9e99227
not_first_level doubling removing from drifted leaf
miha-stopar Jun 2, 2022
929fb58
missing branch init constraints
miha-stopar Jun 2, 2022
47f8b76
extension node missing constraints: range 256 lookups & RLP; two test…
miha-stopar Jun 2, 2022
ed278e1
extension_node_key: constraints to avoid PoisonedConstraint removed
miha-stopar Jun 3, 2022
2046dad
account delete selector
miha-stopar Jun 3, 2022
faa751b
account delete constraint
miha-stopar Jun 3, 2022
486d607
non_existing_account selector
miha-stopar Jun 6, 2022
63f02ec
non-existing account proof row added
miha-stopar Jun 7, 2022
4d30838
AccountNonExisting chip
miha-stopar Jun 8, 2022
9f08026
NonExistingAccount test
miha-stopar Jun 8, 2022
25d7904
non_existing_account proof: constraint for the two addresses being di…
miha-stopar Jun 9, 2022
367d855
account leaf key in first level fixed
miha-stopar Jun 9, 2022
a540205
NonExistingAccount tests regenerated
miha-stopar Jun 9, 2022
ca1d4d1
non_existing_account proof constraints (missing subcase: when only on…
miha-stopar Jun 10, 2022
aa15352
tests regenerated
miha-stopar Jun 10, 2022
73d9054
account_leaf_key fix; test for non existing account in trie first level
miha-stopar Jun 13, 2022
b6f97ee
PoisonedConstraint fixed
miha-stopar Jun 13, 2022
e3d6320
test for non_existing_account after first level; bug fixed
miha-stopar Jun 13, 2022
bafe228
tests with account in/after the first level
miha-stopar Jun 15, 2022
a40dbd9
ProofVariables now uses default
miha-stopar Jun 16, 2022
882842a
account in first level fixed
miha-stopar Jun 16, 2022
9ae9c4f
account in first level / storage in first storage level test and fixing
miha-stopar Jun 17, 2022
92a18d4
storage leaf in first level test & fix
miha-stopar Jun 20, 2022
19fd6b9
account after placeholder branch test & fix
miha-stopar Jun 21, 2022
cd5a06c
Account branch placeholder in first level test added; tests regenerated
miha-stopar Jun 21, 2022
bd5e184
account with placeholder branch in first level test and fix
miha-stopar Jun 22, 2022
cae87f0
account address rlc fixed not to go in negative rows when account lea…
miha-stopar Jun 24, 2022
85127bb
cleaning non existing account proof
miha-stopar Jun 24, 2022
6518b9c
non_existing_account test for the case when there is only one account…
miha-stopar Jun 27, 2022
e8a6c68
extension node in account proof first level test & fix
miha-stopar Jun 28, 2022
d330e19
Extension node with three nibbles tests and fix
miha-stopar Jun 29, 2022
d067443
fix in account_non_existing proof
miha-stopar Jul 1, 2022
992a8fc
generalizing for non-hashed nodes
miha-stopar Jul 5, 2022
a014d1b
branch RLP length and RLC for branches that contain non-hashed nodes
miha-stopar Jul 6, 2022
0f93028
branch_rlc generalized for non-hashed nodes
miha-stopar Jul 7, 2022
c3ad4c0
initial work on extension_node generalization for non-hashed branches
miha-stopar Jul 8, 2022
3ba1abe
non-hashed nodes; descriptions for constants in param.rs
miha-stopar Jul 25, 2022
745e670
storage leaf in last level: leaf RLC
miha-stopar Jul 26, 2022
f689442
addressing Adria comments
miha-stopar Jul 26, 2022
78c740f
storage leaf in last level missing constraints added
miha-stopar Jul 27, 2022
a3a1638
started on non-hashed leaf in parent
miha-stopar Jul 27, 2022
1a06f4f
storage leaf last level RLP constraints; leaf hash in parent for non-…
miha-stopar Jul 28, 2022
893aa50
non-hashed node move for one position to the right in branch children…
miha-stopar Jul 28, 2022
ffed1dd
checking there are 0s after non-hashed RLP ends
miha-stopar Jul 28, 2022
5a9acfc
non-hashed branch in extension node moved for one position to the right
miha-stopar Jul 29, 2022
26ba5c8
extension node non-hashed branch fix
miha-stopar Jul 29, 2022
1a0b3b8
MainCols struct introduced instead of rlp1, rlp2, advices
miha-stopar Aug 1, 2022
f01d6e3
missing selector in for drifted leaf when leaf in first storage level
miha-stopar Aug 1, 2022
176bb5f
removed is_codehash_mod as it is not possible to directly change the …
miha-stopar Aug 1, 2022
444504f
Started adding documentation to account_leaf_nonce_balance
miha-stopar Aug 1, 2022
6b6fde5
ProofTypeCols struct introduced
miha-stopar Aug 2, 2022
16e7ccc
non-hashed branch in extension node
miha-stopar Aug 2, 2022
2972199
documenting account_leaf_nonce_balance
miha-stopar Aug 2, 2022
8b3b0a1
AccountLeafCols
miha-stopar Aug 3, 2022
6c2f15e
AccountLeaf struct
miha-stopar Aug 3, 2022
590dbd5
extension node RLP for non-hashed branch
miha-stopar Aug 3, 2022
a7cbe22
documenting account_leaf_nonce_balance
miha-stopar Aug 3, 2022
1d2b90e
StorageLeafCols struct
miha-stopar Aug 4, 2022
94c5b6b
StorageLeaf struct
miha-stopar Aug 4, 2022
94e230f
extension_node non-hashed branch RLP constraints; non-hashed node loo…
miha-stopar Aug 4, 2022
f3e458f
documenting nonce balance chip
miha-stopar Aug 4, 2022
4f8bf15
minor update to account_leaf_nonce_balance
miha-stopar Aug 4, 2022
d2e8e09
BranchCols struct
miha-stopar Aug 5, 2022
13e98fb
added TODO in extension_node_key
miha-stopar Aug 5, 2022
29f57d7
account leaf nonce balance chip removed (only config)
miha-stopar Aug 5, 2022
e60e041
AccountLeafNonceBalance assign function
miha-stopar Aug 5, 2022
b5aa7a2
Branch struct
miha-stopar Aug 8, 2022
7447592
assign_row takes branch struct
miha-stopar Aug 8, 2022
dc8754d
non-hashed nodes tests changed
miha-stopar Aug 8, 2022
c88837e
AccountLeafStorageCodehash chip -> config; some docs
miha-stopar Aug 8, 2022
147c3bb
account leaf storage codehash docs
miha-stopar Aug 8, 2022
d471895
AccumulatorCols and AccumulatorPair structs
miha-stopar Aug 9, 2022
b98957e
storage leaf with one nibble (one level above last level)
miha-stopar Aug 9, 2022
50667ee
notes about non-hashed nodes in first level
miha-stopar Aug 9, 2022
4fabe1b
assign function for account_leaf_storage_codehash
miha-stopar Aug 9, 2022
7724084
started documenting account leaf key
miha-stopar Aug 9, 2022
8fb68ca
DenoteCols struct
miha-stopar Aug 10, 2022
9fc4d0a
account key leaf removed redundancy; added comments
miha-stopar Aug 10, 2022
392d382
key_rlc/key_rlc_mult moved to AccumulatorCols
miha-stopar Aug 11, 2022
2569013
non-hashed branch in parent check
miha-stopar Aug 11, 2022
0b5245d
Account leaf key constraints reintroduced (were not redundant); comme…
miha-stopar Aug 11, 2022
2041956
removed unneccessary arguments in some configs
miha-stopar Aug 12, 2022
e9ba552
fix
miha-stopar Aug 12, 2022
dc21830
fixed extension node assignment; extension node key constraints for s…
miha-stopar Aug 12, 2022
7f67553
account_key_leaf comments
miha-stopar Aug 12, 2022
8a04a44
account key leaf assign function
miha-stopar Aug 12, 2022
ed8aece
node_mult_diff_s/node_mult_diff_c now part of AccumulatorCols struct
miha-stopar Aug 16, 2022
20b1973
mult_diff moved into AccumulatorCols struct
miha-stopar Aug 16, 2022
f9eb9eb
Non-hashed extension node in parent branch constraint
miha-stopar Aug 16, 2022
15bf4ea
s_mod_node_rlc/c_mod_node_rlc moved to AccumulatorCols
miha-stopar Aug 17, 2022
71ea722
account leaf key in added branch documentation
miha-stopar Aug 17, 2022
5a5564e
account leaf key in added branch assign function
miha-stopar Aug 18, 2022
e8b8a07
Account leaf comments
miha-stopar Aug 18, 2022
5356ebf
MptWitnessRow & MptWitnessRowType introduced as proposed by Adria
miha-stopar Aug 19, 2022
5a95d73
Documenting account_non_existing
miha-stopar Aug 19, 2022
892118c
branch init assignment simplification as proposed by Adria
miha-stopar Aug 22, 2022
86620f2
branch init assignment refactored
miha-stopar Aug 22, 2022
acfa07a
number of nibbles used assignment
miha-stopar Aug 22, 2022
a9407f4
key_len_lookup for account_non_existing
miha-stopar Aug 22, 2022
09d055d
Documenting account_non_existing
miha-stopar Aug 22, 2022
188fefb
account_non_existing assign function
miha-stopar Aug 22, 2022
4952c02
account leaf structs in separate file
miha-stopar Aug 23, 2022
f6185d6
storage leaf structs in a separate file
miha-stopar Aug 23, 2022
6614794
account_leaf folder
miha-stopar Aug 23, 2022
c99cf82
assignment of nibbles_count
miha-stopar Aug 23, 2022
63a2f26
branch folder
miha-stopar Aug 23, 2022
986c261
storage_leaf folder
miha-stopar Aug 23, 2022
6bc3b8e
chips -> configs
miha-stopar Aug 23, 2022
b05471d
WitnessRow in a separate file
miha-stopar Aug 24, 2022
2fd267d
extension node nibbles count constraint
miha-stopar Aug 24, 2022
49efdec
documenting branch.rs
miha-stopar Aug 24, 2022
010cca9
assign_branch_init moved into branch.rs
miha-stopar Aug 25, 2022
6a76826
assing_branch_child into branch.rs
miha-stopar Aug 25, 2022
4b469f5
branch and extension node number of nibbles constraints fixed
miha-stopar Aug 25, 2022
57ab4fb
Only two nil-nodes when placeholder branch constraint fixed
miha-stopar Aug 25, 2022
ef4efa8
assign_row moved into witness_row
miha-stopar Aug 26, 2022
a51b002
assing_branch_row moved into witness_row
miha-stopar Aug 26, 2022
b1017fb
Account address has 64 nibbles constraint
miha-stopar Aug 26, 2022
e24108e
Documenting branch
miha-stopar Aug 26, 2022
92e6fef
BranchCols, ProofTypeCols structs moved
miha-stopar Aug 29, 2022
2606b72
MainCols moved
miha-stopar Aug 29, 2022
8744e76
AccumulatorPair and AccumulatorCols moved
miha-stopar Aug 29, 2022
df1c81b
DenoteCols moved
miha-stopar Aug 29, 2022
8945a95
storage leaf key nibbles count constraint
miha-stopar Aug 29, 2022
692d798
Fixing comments
miha-stopar Aug 29, 2022
f474e3c
proof_type assignment moved to witness_row
miha-stopar Aug 30, 2022
b8abe33
assign_lookup_columns
miha-stopar Aug 30, 2022
c35f219
nibbles_count = 64 for storage leaf all constraints implemented
miha-stopar Aug 30, 2022
31aadbf
fixing drifted_pos related constraints (placeholder branch)
miha-stopar Aug 30, 2022
dd7f5d4
branch is_drifted_pos/modified_node constraints fixed
miha-stopar Aug 31, 2022
7b6e181
branch modified_node/drifted_pos comments; cleaning
miha-stopar Sep 1, 2022
3faf2c6
branch.rs comments finished
miha-stopar Sep 1, 2022
5a1b512
comments for branch_hash_in_parent
miha-stopar Sep 1, 2022
67aa0d2
branch_init documented
miha-stopar Sep 1, 2022
a1375de
is_codehash_proof reintroduced - but only read op, not modification
miha-stopar Sep 2, 2022
b152e95
branch_key comments
miha-stopar Sep 2, 2022
1c0f2b8
Branch parallel docs
miha-stopar Sep 5, 2022
717ed1b
branch_rlc docs
miha-stopar Sep 5, 2022
34a8ce0
extension node assign function
miha-stopar Sep 6, 2022
127569d
removed constraints for key_rlc & mult_diff being set in all branch c…
miha-stopar Sep 6, 2022
58dab7a
documenting extension_node_key
miha-stopar Sep 6, 2022
5b5a87b
extension node key docs
miha-stopar Sep 7, 2022
fdab583
documenting extension node key
miha-stopar Sep 8, 2022
0ff1381
documenting extension node
miha-stopar Sep 9, 2022
bdab0f7
extension_node comments and simplification
miha-stopar Sep 12, 2022
08c999f
storage leaf key comments
miha-stopar Sep 12, 2022
f242309
documenting storage leaf key
miha-stopar Sep 13, 2022
7fee76d
storage leaf key constraints simplification
miha-stopar Sep 13, 2022
1f0bb22
account leaf key simplification
miha-stopar Sep 13, 2022
9bc5f52
storage leaf key assign function added
miha-stopar Sep 13, 2022
61423fe
storage leaf value assign function
miha-stopar Sep 13, 2022
08c87d9
storage leaf key in added branch assign function
miha-stopar Sep 13, 2022
724a5a9
fixed bug in leaf/account key in added branch (introduced when cleari…
miha-stopar Sep 14, 2022
f2ed663
mostly renaming
miha-stopar Sep 14, 2022
545cc22
Previous key RLC in branches removed (no PoisonedConstraints anymore)
miha-stopar Sep 14, 2022
36bd1ad
Account leaf added in new branch simplified
miha-stopar Sep 15, 2022
e641c12
storage leaf in added branch simplified
miha-stopar Sep 15, 2022
93ead38
get_type used in account leaf assign functions
miha-stopar Sep 16, 2022
bc2f6ac
codehash modification enabled
miha-stopar Sep 16, 2022
4606b63
Storage leaf key documented
miha-stopar Sep 16, 2022
2068f17
documenting leaf_value
miha-stopar Sep 16, 2022
0ae12ed
leaf_value.rs documented
miha-stopar Sep 19, 2022
c087af2
Documenting and refactoring leaf_key_in_added_branch
miha-stopar Sep 19, 2022
61e762e
leaf_key_in_added_branch documented; missing constraints added
miha-stopar Sep 20, 2022
b5caf6c
Branch hash in first storage trie level lookup moved to branch_hash_i…
miha-stopar Sep 20, 2022
ffcc7f4
Extension node in first storage trie level lookup moved to extension_…
miha-stopar Sep 20, 2022
f0b5588
Only storage leaf hash is storage trie root
miha-stopar Sep 20, 2022
7d49f52
leaf value fix
miha-stopar Sep 20, 2022
5ac391a
Constraints for the only storage leaf which is also a placeholder mov…
miha-stopar Sep 21, 2022
5e760c0
storage_root_in_account_leaf.rs removed, all constraints moved to oth…
miha-stopar Sep 21, 2022
46f7d47
counter removed: lookups will use start_root/end_root instead
miha-stopar Sep 21, 2022
ad121bc
not_first_level constraints
miha-stopar Sep 21, 2022
fd991b4
start_root, final_root constraints refactored
miha-stopar Sep 21, 2022
8734fea
ensuring there is account proof before storage proof: documented and …
miha-stopar Sep 22, 2022
eae9937
Selectors documented and missing constraint added
miha-stopar Sep 22, 2022
8e693db
formatting
miha-stopar Sep 23, 2022
328421d
formatting leaf_value.rs
miha-stopar Sep 23, 2022
74ebb45
PositionCols (q_enabled, q_not_first, not_first_level)
miha-stopar Sep 23, 2022
6af81e4
leaf_key_in_added_branch formatting
miha-stopar Sep 23, 2022
b826f60
leaf_key clones removed
miha-stopar Sep 23, 2022
7190da1
selectores redundant clones removed
miha-stopar Sep 23, 2022
1e874d2
proof_chain redundant clones
miha-stopar Sep 23, 2022
6e6706b
Pointers to constraints for the first level; ProofVariables renamed
miha-stopar Sep 26, 2022
9c77144
resolving clippy warnings
miha-stopar Sep 26, 2022
9acdae7
resolving clippy warnings
miha-stopar Sep 26, 2022
2359598
resolving clippy warnings
miha-stopar Sep 26, 2022
3022ea5
resolved clippy warnings in extension_node.rs
miha-stopar Sep 26, 2022
f903674
resolved clippy warnings in branch configs
miha-stopar Sep 26, 2022
01e6f39
clippy warnings resolved in account configs
miha-stopar Sep 26, 2022
628580d
last clippy warnings resolved (mostly related to visibility)
miha-stopar Sep 27, 2022
b47da91
long value RLP check fixed
miha-stopar Sep 27, 2022
3278743
rotation fixed (hash of the empty storage trie)
miha-stopar Sep 27, 2022
9bf1def
leaf key in added branch fix
miha-stopar Sep 28, 2022
8c1ffcb
tests regenerated
miha-stopar Sep 28, 2022
eef0acf
mpt moved into zkevm-circuits
miha-stopar Sep 29, 2022
201f373
println removed
miha-stopar Sep 29, 2022
82c27c3
power_of_randomness as instance
miha-stopar Oct 4, 2022
4b2e691
cleaning related to power_of_randomness
miha-stopar Oct 4, 2022
c14e99f
switching to kecccak_circuit (branch_hash_in_parent.rs ported)
miha-stopar Oct 6, 2022
9c61ea4
account_leaf_storage_codehash.rs ported to keccak circuit
miha-stopar Oct 7, 2022
297528a
account_leaf_key_in_added_branch.rs ported to keccak circuit
miha-stopar Oct 7, 2022
4f5a60e
extension_node ported to keccak circuit
miha-stopar Oct 7, 2022
57973a7
storage leaf ported to keccak circuit
miha-stopar Oct 7, 2022
5e2a1f0
is_big_endian added to dev_load for keccak table construction
miha-stopar Oct 7, 2022
1d24772
fix in keccak assignments
miha-stopar Oct 10, 2022
c281eff
power_of_randomness moved
miha-stopar Oct 10, 2022
869da24
randomness now assign parameter
miha-stopar Oct 10, 2022
08c66be
fix in get_branch_len
miha-stopar Oct 11, 2022
ea293d3
proof_type column added; constraints for proof_type properly correspo…
miha-stopar Oct 11, 2022
067a051
enabling all lookups in the same set of columns
miha-stopar Oct 11, 2022
39d5b25
lookup selector constraints (to prevent lookups in wrong rows)
miha-stopar Oct 12, 2022
ae3b772
enabling lookups
miha-stopar Oct 13, 2022
86e1ff9
storage mod lookup enabled in leaf value row
miha-stopar Oct 14, 2022
fd3a048
mpt_table exposed
miha-stopar Oct 14, 2022
bdccc82
codehash lookup fix
miha-stopar Oct 14, 2022
9bfc1f4
clippy warnings resolved
miha-stopar Oct 14, 2022
e2f36bc
key_len_lookup enabled; tests passed
miha-stopar Oct 18, 2022
6406a2a
check_zeros parameter to enable/disable 2^13 fixed table
miha-stopar Oct 19, 2022
b7b0443
row added to the storage leaf for non existing storage proof
miha-stopar Oct 19, 2022
6cdb2c7
non_existing_storage skeleton prepared
miha-stopar Oct 21, 2022
948531a
non-existing-storage proof now works for short (one RLP byte) leaves
miha-stopar Oct 24, 2022
b6f1b2d
storage-non-existing long (two RLP bytes) key enabled
miha-stopar Oct 25, 2022
13f106e
key_len_lookups and number of nibbles enabled for long keys (non exis…
miha-stopar Oct 25, 2022
f451f99
storage-non-existing long key fixed; test added
miha-stopar Oct 25, 2022
3ef3a7d
non-existing-storage fix; tests added
miha-stopar Oct 25, 2022
1c49fcc
Non-existing-storage for proofs with nil in branch
miha-stopar Oct 26, 2022
c1d2e96
order of rows constraints fixed (after non-existing-row for storage w…
miha-stopar Oct 27, 2022
2479b1b
non-existing-storage docs
miha-stopar Oct 27, 2022
8aeac55
tests updated
miha-stopar Oct 27, 2022
0ae1b6d
cargo fmt applied
miha-stopar Oct 28, 2022
02cda5a
formatting
miha-stopar Oct 28, 2022
ce776e8
tests regenerated
miha-stopar Oct 28, 2022
29f8f6a
clippy
miha-stopar Oct 28, 2022
8b2f66d
cargo fmt
miha-stopar Oct 28, 2022
3ac930f
[MPT] Misc refactoring (#972)
Brechtpd Apr 5, 2023
439a389
Sync MPT to main (#1444)
Brechtpd Jun 1, 2023
53c8cdb
Merge branch 'main' into mpt2
Brechtpd Jun 5, 2023
f4f33a1
Merge branch 'main' into mpt2
Brechtpd Jun 5, 2023
5944d34
MPT improvements (#1462)
Brechtpd Jun 14, 2023
d341d7a
MPT new descriptors & benchmark (#1492)
miha-stopar Jun 26, 2023
9fb4668
Added is_mod_extension
miha-stopar Aug 1, 2023
9a76442
Parent data is_mod_extension witness store fix; constraint added.
miha-stopar Aug 2, 2023
18f0b13
is_mod_extension taken out of ParentData and added to both leaves
miha-stopar Aug 4, 2023
06965a0
Introduced ModExtensionNode
miha-stopar Aug 9, 2023
5525c85
ModExtensionNode skeleton fixed
miha-stopar Aug 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ evm_bench: ## Run Evm Circuit benchmarks
state_bench: ## Run State Circuit benchmarks
@cargo test --profile bench bench_state_circuit_prover -p circuit-benchmarks --features benches -- --nocapture

mpt_bench: ## Run MPT Circuit benchmarks
@cargo test --profile bench bench_mpt_circuit_prover -p circuit-benchmarks --features benches -- --nocapture

packed_multi_keccak_bench: ## Run Packed Multi Keccak Circuit benchmarks
@cargo test --profile bench bench_packed_multi_keccak_circuit_prover -p circuit-benchmarks --features benches -- --nocapture

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ to use for your circuit in the bench process.
- Keccak Circuit prover benches. -> `DEGREE=16 make packed_multi_keccak_bench`
- EVM Circuit prover benches. -> `DEGREE=18 make evm_bench`.
- State Circuit prover benches. -> `DEGREE=18 make state_bench`
- MPT Circuit prover benches. -> `DEGREE=14 make mpt_bench`

You can also run all benchmarks by running: `make circuit_benches DEGREE=18`.

Expand Down
2 changes: 2 additions & 0 deletions circuit-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ env_logger = "0.9"
ethers-signers = "0.17.0"
mock = { path="../mock" }
rand_chacha = "0.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

[features]
default = []
Expand Down
4 changes: 4 additions & 0 deletions circuit-benchmarks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,7 @@ pub mod exp_circuit;
#[cfg(test)]
#[cfg(feature = "benches")]
pub mod constants;

#[cfg(test)]
#[cfg(feature = "benches")]
pub mod mpt_circuit;
126 changes: 126 additions & 0 deletions circuit-benchmarks/src/mpt_circuit.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//! MPT circuit benchmarks

#[cfg(test)]
mod tests {
use ark_std::{end_timer, start_timer};
use halo2_proofs::{
halo2curves::bn256::{Bn256, Fr, G1Affine},
plonk::{create_proof, keygen_pk, keygen_vk, verify_proof},
poly::{
commitment::ParamsProver,
kzg::{
commitment::{KZGCommitmentScheme, ParamsKZG, ParamsVerifierKZG},
multiopen::{ProverSHPLONK, VerifierSHPLONK},
strategy::SingleStrategy,
},
},
transcript::{
Blake2bRead, Blake2bWrite, Challenge255, TranscriptReadBuffer, TranscriptWriterBuffer,
},
};
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
use std::env::var;
use zkevm_circuits::mpt_circuit::{witness_row::Node, MPTCircuit};

#[cfg_attr(not(feature = "benches"), ignore)]
#[test]
fn bench_mpt_circuit_prover() {
let setup_prfx = crate::constants::SETUP_PREFIX;
let proof_gen_prfx = crate::constants::PROOFGEN_PREFIX;
let proof_ver_prfx = crate::constants::PROOFVER_PREFIX;
// Unique string used by bench results module for parsing the result
const BENCHMARK_ID: &str = "MPT Circuit";

let degree: u32 = var("DEGREE")
.expect("No DEGREE env var was provided")
.parse()
.expect("Cannot parse DEGREE env var as u32");

let path = "../zkevm-circuits/src/mpt_circuit/tests/UpdateOneLevel.json";
let file = std::fs::File::open(path);
let reader = std::io::BufReader::new(file.unwrap());

let randomness = Fr::from(123456u64);
let nodes: Vec<Node> = serde_json::from_reader(reader).unwrap();

let mut keccak_data = vec![];
for node in nodes.iter() {
for k in node.keccak_data.iter() {
keccak_data.push(k.clone());
}
}

let circuit = MPTCircuit::<Fr> {
nodes,
keccak_data,
randomness,
};

// Initialize the polynomial commitment parameters
let mut rng = XorShiftRng::from_seed([
0x59, 0x62, 0xbe, 0x5d, 0x76, 0x3d, 0x31, 0x8d, 0x17, 0xdb, 0x37, 0x32, 0x54, 0x06,
0xbc, 0xe5,
]);

// Bench setup generation
let setup_message = format!("{} {} with degree = {}", BENCHMARK_ID, setup_prfx, degree);
let start1 = start_timer!(|| setup_message);
let general_params = ParamsKZG::<Bn256>::setup(degree, &mut rng);
let verifier_params: ParamsVerifierKZG<Bn256> = general_params.verifier_params().clone();
end_timer!(start1);

// Initialize the proving key
let vk = keygen_vk(&general_params, &circuit).expect("keygen_vk should not fail");
let pk = keygen_pk(&general_params, vk, &circuit).expect("keygen_pk should not fail");
// Create a proof
let mut transcript = Blake2bWrite::<_, G1Affine, Challenge255<_>>::init(vec![]);

// Bench proof generation time
let proof_message = format!(
"{} {} with degree = {}",
BENCHMARK_ID, proof_gen_prfx, degree
);
let start2 = start_timer!(|| proof_message);

create_proof::<
KZGCommitmentScheme<Bn256>,
ProverSHPLONK<'_, Bn256>,
Challenge255<G1Affine>,
XorShiftRng,
Blake2bWrite<Vec<u8>, G1Affine, Challenge255<G1Affine>>,
MPTCircuit<Fr>,
>(
&general_params,
&pk,
&[circuit],
&[&[]],
rng,
&mut transcript,
)
.expect("proof generation should not fail");
let proof = transcript.finalize();
end_timer!(start2);

// Bench verification time
let start3 = start_timer!(|| format!("{} {}", BENCHMARK_ID, proof_ver_prfx));
let mut verifier_transcript = Blake2bRead::<_, G1Affine, Challenge255<_>>::init(&proof[..]);
let strategy = SingleStrategy::new(&general_params);

verify_proof::<
KZGCommitmentScheme<Bn256>,
VerifierSHPLONK<'_, Bn256>,
Challenge255<G1Affine>,
Blake2bRead<&[u8], G1Affine, Challenge255<G1Affine>>,
SingleStrategy<'_, Bn256>,
>(
&verifier_params,
pk.get_vk(),
strategy,
&[&[]],
&mut verifier_transcript,
)
.expect("failed to verify bench circuit");
end_timer!(start3);
}
}
88 changes: 80 additions & 8 deletions gadgets/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,63 @@ pub mod select {
}
}

/// Returns the power of number using straigtforward multiplications
pub mod pow {
use crate::util::Expr;
use eth_types::Field;
use halo2_proofs::plonk::Expression;

use super::Scalar;

/// Returns the `when_true` expression when the selector is true, else
/// returns the `when_false` expression.
pub fn expr<F: Field>(value: Expression<F>, exponent: usize) -> Expression<F> {
let mut result = 1.expr();
for _ in 0..exponent {
result = result * value.expr();
}
result
}

/// Returns the `when_true` value when the selector is true, else returns
/// the `when_false` value.
pub fn value<F: Field>(value: F, exponent: usize) -> F {
let mut result = 1.scalar();
for _ in 0..exponent {
result *= value;
}
result
}
}

/// Trait that implements functionality to get a scalar from
/// commonly used types.
pub trait Scalar<F: Field> {
/// Returns a scalar for the type.
fn scalar(&self) -> F;
}

/// Implementation trait `Scalar` for type able to be casted to u64
#[macro_export]
macro_rules! impl_scalar {
($type:ty) => {
impl<F: eth_types::Field> $crate::util::Scalar<F> for $type {
#[inline]
fn scalar(&self) -> F {
F::from(*self as u64)
}
}
};
($type:ty, $method:path) => {
impl<F: eth_types::Field> $crate::util::Scalar<F> for $type {
#[inline]
fn scalar(&self) -> F {
F::from($method(self) as u64)
}
}
};
}

/// Trait that implements functionality to get a constant expression from
/// commonly used types.
pub trait Expr<F: Field> {
Expand All @@ -149,6 +206,7 @@ pub trait Expr<F: Field> {
#[macro_export]
macro_rules! impl_expr {
($type:ty) => {
$crate::impl_scalar!($type);
impl<F: eth_types::Field> $crate::util::Expr<F> for $type {
#[inline]
fn expr(&self) -> Expression<F> {
Expand All @@ -157,6 +215,7 @@ macro_rules! impl_expr {
}
};
($type:ty, $method:path) => {
$crate::impl_scalar!($type, $method);
impl<F: eth_types::Field> $crate::util::Expr<F> for $type {
#[inline]
fn expr(&self) -> Expression<F> {
Expand All @@ -170,28 +229,41 @@ impl_expr!(bool);
impl_expr!(u8);
impl_expr!(u64);
impl_expr!(usize);
impl_expr!(isize);
impl_expr!(OpcodeId, OpcodeId::as_u8);

impl<F: Field> Expr<F> for Expression<F> {
impl<F: Field> Scalar<F> for i32 {
#[inline]
fn scalar(&self) -> F {
F::from(self.unsigned_abs() as u64) * if self.is_negative() { -F::ONE } else { F::ONE }
}
}

impl<F: Field> Scalar<F> for &F {
#[inline]
fn scalar(&self) -> F {
*(*self)
}
}

impl<F: Field> Expr<F> for i32 {
#[inline]
fn expr(&self) -> Expression<F> {
self.clone()
Expression::Constant(self.scalar())
}
}

impl<F: Field> Expr<F> for &Expression<F> {
impl<F: Field> Expr<F> for Expression<F> {
#[inline]
fn expr(&self) -> Expression<F> {
(*self).clone()
self.clone()
}
}

impl<F: Field> Expr<F> for i32 {
impl<F: Field> Expr<F> for &Expression<F> {
#[inline]
fn expr(&self) -> Expression<F> {
Expression::Constant(
F::from(self.unsigned_abs() as u64) * if self.is_negative() { -F::ONE } else { F::ONE },
)
(*self).clone()
}
}

Expand Down
5 changes: 3 additions & 2 deletions zkevm-circuits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ num-bigint = { version = "0.4" }
rand_chacha = "0.3"
snark-verifier = { git = "https://github.com/privacy-scaling-explorations/snark-verifier", tag = "v2023_04_20", default-features = false, features = ["loader_halo2", "system_halo2"] }
cli-table = { version = "0.4", optional = true }
num_enum = "0.5.7"
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.78"

[dev-dependencies]
bus-mapping = { path = "../bus-mapping", features = ["test"] }
Expand All @@ -44,8 +47,6 @@ hex = "0.4.3"
itertools = "0.10.1"
mock = { path = "../mock" }
pretty_assertions = "1.0.0"
serde = { version = "1.0.130", features = ["derive"] }
serde_json = "1.0.78"

[features]
default = []
Expand Down
1 change: 1 addition & 0 deletions zkevm-circuits/src/bytecode_circuit/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl<F: Field> Circuit<F> for BytecodeCircuit<F> {
&mut layouter,
self.bytecodes.iter().map(|b| &b.bytes),
&challenges,
true,
)?;
self.synthesize_sub(&config, &challenges, &mut layouter)?;
Ok(())
Expand Down
8 changes: 8 additions & 0 deletions zkevm-circuits/src/circuit_tools.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//! Circuit utilities
#![allow(missing_docs)]
#[macro_use]
pub mod constraint_builder;
pub mod cached_region;
pub mod cell_manager;
pub mod gadgets;
pub mod memory;
Loading
Loading