Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circuit tools #12

Draft
wants to merge 357 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
357 commits
Select commit Hold shift + click to select a range
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
11953e5
Merge branch 'main' into mpt2
Brechtpd Apr 8, 2023
31a0b83
Add back keccak endianess option
Brechtpd Apr 26, 2023
e6096ca
state machine constraints & dev-graph plots
CeciliaZ030 Apr 28, 2023
7abf752
circuit tools updated, still need to make mpt_circuit compatible
CeciliaZ030 May 3, 2023
16f4e16
use new circuit tools including CachecdRegion
CeciliaZ030 May 3, 2023
a04940c
updates, still needs to fix CM
CeciliaZ030 May 4, 2023
82c7942
LookupTable
CeciliaZ030 May 5, 2023
a43f688
cargo fix
CeciliaZ030 May 5, 2023
6d0e84f
change to TableType, dynamically generate phase config according to L…
CeciliaZ030 May 6, 2023
4ee4a27
circuit tools & test:
CeciliaZ030 May 9, 2023
32d81d9
trait ChallengeSet
CeciliaZ030 May 11, 2023
bfdf4d4
compiled ChallengeSet
CeciliaZ030 May 12, 2023
156f847
clippy
CeciliaZ030 May 12, 2023
d6923a9
example 1 phase error
CeciliaZ030 May 12, 2023
244fe70
updates
CeciliaZ030 May 19, 2023
bcfd2d5
refactor CellManager
CeciliaZ030 May 20, 2023
2c5f3c5
moved things around
CeciliaZ030 May 20, 2023
5508767
compiled in mpt
CeciliaZ030 May 23, 2023
c498841
Fix best_index for CM cell query
CeciliaZ030 May 23, 2023
7bfe635
CachedRegion init & descrption
CeciliaZ030 May 30, 2023
bc1d2e1
CachedRegion included & debugged CM
CeciliaZ030 May 31, 2023
9488ddd
seperate dynamic lookup from static lookup
CeciliaZ030 May 31, 2023
1ec2fe8
StoredExpression equality constraint failed, static lookup failed
CeciliaZ030 Jun 1, 2023
439a389
Sync MPT to main (#1444)
Brechtpd Jun 1, 2023
c95cd91
static lookup work!
CeciliaZ030 Jun 1, 2023
47b46f8
WIP fixes
Brechtpd Jun 1, 2023
f09702a
Most things work
Brechtpd Jun 2, 2023
64a0d81
State machine step constraints
Brechtpd Jun 3, 2023
80d97b9
Add ext key odd check
Brechtpd Jun 3, 2023
03f0f74
Better mocked randomness
Brechtpd Jun 3, 2023
5f8c754
Add RLP decoding lookups
Brechtpd Jun 4, 2023
40dc38e
simple switch between static and dynamic lookups
Brechtpd Jun 4, 2023
7346463
small improvements
Brechtpd Jun 4, 2023
53c8cdb
Merge branch 'main' into mpt2
Brechtpd Jun 5, 2023
f4f33a1
Merge branch 'main' into mpt2
Brechtpd Jun 5, 2023
76b69bd
Merge remote-tracking branch 'upstream/mpt2' into circuit-tools-wip
Brechtpd Jun 5, 2023
3a59b4c
misc cleanup
Brechtpd Jun 5, 2023
8ec4362
more cleanup
Brechtpd Jun 6, 2023
d3ed9ce
some more cleanup
Brechtpd Jun 7, 2023
71ff2c2
Do away with strings as lookup names
Brechtpd Jun 7, 2023
6dad45a
some more cleanup
Brechtpd Jun 8, 2023
4abbbe5
Working keccak input endianess change
Brechtpd Jun 16, 2023
101be36
enable fixed and split in dyanimic lookup
CeciliaZ030 Jun 17, 2023
709c923
is_fixed=true, is_combined=true, is_split still not working
CeciliaZ030 Jun 17, 2023
15b3794
remove use_dynamic_lookup
CeciliaZ030 Jun 17, 2023
d330654
rename to celltype_lookups
CeciliaZ030 Jun 17, 2023
4f7790e
is_split implemented from spliting at insertion time
CeciliaZ030 Jun 18, 2023
7e141c4
Enable keccak input challenge
Brechtpd Jun 26, 2023
0ebd57f
mult_inv & mult_diff_be
CeciliaZ030 Jun 28, 2023
51ef3f9
adds challenge
CeciliaZ030 Jun 28, 2023
502eb86
change some names
CeciliaZ030 Jun 28, 2023
4fdd8e7
clean up
CeciliaZ030 Jun 28, 2023
0fe1e7d
clean up
CeciliaZ030 Jun 28, 2023
487f570
fix & fmt
CeciliaZ030 Jun 28, 2023
626ca59
clean up & comments
CeciliaZ030 Jun 28, 2023
0632daf
cleanup
CeciliaZ030 Jun 28, 2023
b8ae87c
cm with ctx
CeciliaZ030 Jun 29, 2023
0e43ed9
cm with ctx
CeciliaZ030 Jun 29, 2023
3632f83
fix & fmt
CeciliaZ030 Jun 29, 2023
97e7c2a
Merge branch 'circuit-tools' into challenge-api
CeciliaZ030 Jun 29, 2023
f9dc002
fix
CeciliaZ030 Jun 29, 2023
d58d793
Merge pull request #14 from CeciliaZ030/challenge-api
CeciliaZ030 Jun 29, 2023
531a020
permutable
CeciliaZ030 Jun 29, 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
27 changes: 26 additions & 1 deletion Cargo.lock

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

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
1 change: 1 addition & 0 deletions zkevm-circuits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ 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"

[dev-dependencies]
bus-mapping = { path = "../bus-mapping", features = ["test"] }
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