-
Notifications
You must be signed in to change notification settings - Fork 31
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
[ZK 37] only check path_type in configure_extension_old and configure_extension_new #79
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2f8a96b
Only check path_type in configure_extension_old and configure_extensi…
dbe617b
Remove always satisfied conditions for poseidon code hash updates
f6ada8c
Remove always satisfied condition for code size and delete unreachabl…
79376b7
Remove duplicated constraint
1bbab96
fmt
9621c40
Remove always satisfied condition
38ca6aa
Check that code size and nonce are 0 for new account
5b32c26
Merge branch 'v0.5' into zellic_kalos_37
z2trillion 2d2f473
Merge branch 'v0.7' into zellic_kalos_37
z2trillion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1134,10 +1134,15 @@ fn configure_extension_old<F: FieldExt>( | |
poseidon: &impl PoseidonLookup, | ||
) { | ||
cb.assert( | ||
"can only delete existing nodes for storage proofs", | ||
"can only delete existing storage trie nodes for storage proofs", | ||
config | ||
.proof_type | ||
.current_matches(&[MPTProofType::StorageChanged]), | ||
.current_matches(&[MPTProofType::StorageChanged]) | ||
.and( | ||
config | ||
.segment_type | ||
.current_matches(&[SegmentType::StorageTrie, SegmentType::StorageLeaf0]), | ||
), | ||
); | ||
cb.assert_zero( | ||
"new value is 0 when deleting node", | ||
|
@@ -1360,10 +1365,10 @@ fn configure_nonce<F: FieldExt>( | |
config.path_type.current_matches(&[PathType::ExtensionNew]), | ||
|cb| { | ||
cb.assert_equal( | ||
"sibling is hash(0, hash(0, 0)) for nonce extension new at AccountLeaf2", | ||
config.sibling.current(), | ||
Query::from(*ZERO_STORAGE_ROOT_KECCAK_CODEHASH_HASH), | ||
); | ||
"sibling is hash(0, hash(0, 0)) for nonce extension new at AccountLeaf2", | ||
config.sibling.current(), | ||
Query::from(*ZERO_STORAGE_ROOT_KECCAK_CODEHASH_HASH), | ||
); | ||
}, | ||
); | ||
} | ||
|
@@ -1433,12 +1438,6 @@ fn configure_code_size<F: FieldExt>( | |
bytes: &impl BytesLookup, | ||
poseidon: &impl PoseidonLookup, | ||
) { | ||
cb.assert( | ||
"new accounts have balance or nonce set first", | ||
config | ||
.path_type | ||
.current_matches(&[PathType::Start, PathType::Common]), | ||
); | ||
for variant in SegmentType::iter() { | ||
let conditional_constraints = |cb: &mut ConstraintBuilder<F>| match variant { | ||
SegmentType::Start | SegmentType::AccountTrie => { | ||
|
@@ -1609,19 +1608,21 @@ fn configure_balance<F: FieldExt>( | |
); | ||
}, | ||
); | ||
cb.add_lookup( | ||
"new balance is rlc(new_hash) and fits into 31 bytes", | ||
[ | ||
config.new_hash.current(), | ||
Query::from(30), | ||
config.new_value.current(), | ||
], | ||
rlc.lookup(), | ||
); | ||
cb.condition( | ||
config | ||
.path_type | ||
.current_matches(&[PathType::Common, PathType::ExtensionNew]), | ||
config.path_type.current_matches(&[PathType::ExtensionNew]), | ||
|cb| { | ||
cb.add_lookup( | ||
"new balance is rlc(new_hash) and fits into 31 bytes", | ||
[ | ||
config.new_hash.current(), | ||
Query::from(30), | ||
config.new_value.current(), | ||
], | ||
rlc.lookup(), | ||
cb.assert_zero( | ||
"sibling (code_size + nonce << 64) is 0 for new account)", | ||
config.sibling.current(), | ||
); | ||
}, | ||
); | ||
|
@@ -1648,42 +1649,22 @@ fn configure_poseidon_code_hash<F: FieldExt>( | |
cb: &mut ConstraintBuilder<F>, | ||
config: &MptUpdateConfig, | ||
) { | ||
cb.assert( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ExtensionNew(Old) are already disallowed for PoseidonCodeHashExists in configure_extension_new(old). |
||
"new accounts have balance or nonce set first", | ||
config | ||
.path_type | ||
.current_matches(&[PathType::Start, PathType::Common]), | ||
); | ||
for variant in SegmentType::iter() { | ||
let conditional_constraints = |cb: &mut ConstraintBuilder<F>| match variant { | ||
SegmentType::AccountLeaf0 => { | ||
cb.assert_equal("direction is 1", config.direction.current(), Query::one()); | ||
} | ||
SegmentType::AccountLeaf1 => { | ||
cb.assert_equal("direction is 1", config.direction.current(), Query::one()); | ||
cb.condition( | ||
config | ||
.path_type | ||
.current_matches(&[PathType::Common, PathType::ExtensionOld]), | ||
|cb| { | ||
cb.assert_equal( | ||
"old_hash is old poseidon code hash", | ||
config.old_value.current(), | ||
config.old_hash.current(), | ||
); | ||
}, | ||
cb.assert_equal( | ||
"old_hash is old poseidon code hash", | ||
config.old_value.current(), | ||
config.old_hash.current(), | ||
); | ||
cb.condition( | ||
config | ||
.path_type | ||
.current_matches(&[PathType::Common, PathType::ExtensionNew]), | ||
|cb| { | ||
cb.assert_equal( | ||
"new_hash is new poseidon code hash", | ||
config.new_value.current(), | ||
config.new_hash.current(), | ||
); | ||
}, | ||
cb.assert_equal( | ||
"new_hash is new poseidon code hash", | ||
config.new_value.current(), | ||
config.new_hash.current(), | ||
); | ||
} | ||
_ => {} | ||
|
@@ -1703,12 +1684,6 @@ fn configure_keccak_code_hash<F: FieldExt>( | |
rlc: &impl RlcLookup, | ||
randomness: Query<F>, | ||
) { | ||
cb.assert( | ||
"new accounts have balance or nonce set first", | ||
config | ||
.path_type | ||
.current_matches(&[PathType::Start, PathType::Common]), | ||
); | ||
for variant in SegmentType::iter() { | ||
let conditional_constraints = |cb: &mut ConstraintBuilder<F>| match variant { | ||
SegmentType::Start | SegmentType::AccountTrie => { | ||
|
@@ -1804,10 +1779,6 @@ fn configure_storage<F: FieldExt>( | |
cb.assert_equal("direction is 1", config.direction.current(), Query::one()); | ||
} | ||
SegmentType::AccountLeaf3 => { | ||
cb.assert( | ||
"storage modifications must be on an existing account", | ||
config.path_type.current_matches(&[PathType::Common]), | ||
); | ||
cb.assert_zero("direction is 0", config.direction.current()); | ||
let [key_high, key_low, ..] = config.intermediate_values; | ||
let [rlc_key_high, rlc_key_low, ..] = config.second_phase_intermediate_values; | ||
|
@@ -1827,11 +1798,8 @@ fn configure_storage<F: FieldExt>( | |
let [old_high, old_low, new_high, new_low, ..] = config.intermediate_values; | ||
let [rlc_old_high, rlc_old_low, rlc_new_high, rlc_new_low, ..] = | ||
config.second_phase_intermediate_values; | ||
|
||
cb.condition( | ||
config | ||
.path_type | ||
.current_matches(&[PathType::Common, PathType::ExtensionOld]), | ||
config.path_type.current_matches(&[PathType::Common]), | ||
|cb| { | ||
configure_word_rlc( | ||
cb, | ||
|
@@ -1842,13 +1810,6 @@ fn configure_storage<F: FieldExt>( | |
rlc, | ||
randomness.clone(), | ||
); | ||
}, | ||
); | ||
cb.condition( | ||
config | ||
.path_type | ||
.current_matches(&[PathType::Common, PathType::ExtensionNew]), | ||
|cb| { | ||
configure_word_rlc( | ||
cb, | ||
[config.new_hash, new_high, new_low], | ||
|
@@ -1977,12 +1938,6 @@ fn configure_empty_account<F: FieldExt>( | |
config: &MptUpdateConfig, | ||
poseidon: &impl PoseidonLookup, | ||
) { | ||
cb.assert( | ||
"path type is start or common for empty account proof", | ||
config | ||
.path_type | ||
.current_matches(&[PathType::Start, PathType::Common]), | ||
); | ||
cb.assert_zero("old value is 0", config.old_value.current()); | ||
cb.assert_zero("new value is 0", config.new_value.current()); | ||
cb.assert_equal( | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExtensionNew(Old) are already disallowed for CodeSizeExists in configure_extension_new(old).