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

[ZK 37] only check path_type in configure_extension_old and configure_extension_new #79

Merged
merged 9 commits into from
Nov 14, 2023
87 changes: 10 additions & 77 deletions src/gadgets/mpt_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -975,10 +975,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",
Expand Down Expand Up @@ -1256,20 +1261,6 @@ fn configure_nonce<F: FieldExt>(
);
},
);
cb.condition(
config.path_type.current_matches(&[PathType::ExtensionOld]),
|cb| {
cb.add_lookup(
"old nonce is 8 bytes",
[config.old_value.current(), Query::from(7)],
bytes.lookup(),
);
cb.assert_zero(
"code size is 0 for ExtensionOld nonce update",
old_code_size,
);
},
);
}
_ => {}
};
Expand All @@ -1286,12 +1277,6 @@ fn configure_code_size<F: FieldExt>(
bytes: &impl BytesLookup,
poseidon: &impl PoseidonLookup,
) {
cb.assert(
Copy link
Contributor Author

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).

"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::AccountTrie => {
Expand Down Expand Up @@ -1385,20 +1370,6 @@ fn configure_code_size<F: FieldExt>(
);
},
);
cb.condition(
config.path_type.current_matches(&[PathType::ExtensionOld]),
|cb| {
cb.add_lookup(
"old code size is 8 bytes",
[config.old_value.current(), Query::from(7)],
bytes.lookup(),
);
cb.assert_zero(
"old nonce is 0 for ExtensionOld code size update",
old_nonce,
);
},
);
}
_ => {}
};
Expand Down Expand Up @@ -1480,9 +1451,7 @@ fn configure_balance<F: FieldExt>(
SegmentType::AccountLeaf3 => {
cb.assert_equal("direction is 1", config.direction.current(), Query::one());
cb.condition(
config
.path_type
.current_matches(&[PathType::Common, PathType::ExtensionOld]),
config.path_type.current_matches(&[PathType::Common]),
|cb| {
cb.add_lookup(
"old balance is rlc(old_hash) and fits into 31 bytes",
Expand Down Expand Up @@ -1525,12 +1494,6 @@ fn configure_poseidon_code_hash<F: FieldExt>(
cb: &mut ConstraintBuilder<F>,
config: &MptUpdateConfig,
) {
cb.assert(
Copy link
Contributor Author

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 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 => {
Expand All @@ -1539,9 +1502,7 @@ fn configure_poseidon_code_hash<F: FieldExt>(
SegmentType::AccountLeaf1 => {
cb.assert_equal("direction is 1", config.direction.current(), Query::one());
cb.condition(
config
.path_type
.current_matches(&[PathType::Common, PathType::ExtensionOld]),
config.path_type.current_matches(&[PathType::Common]),
|cb| {
cb.assert_equal(
"old_hash is old poseidon code hash",
Expand Down Expand Up @@ -1580,12 +1541,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::AccountTrie => {
Expand Down Expand Up @@ -1706,11 +1661,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,
Expand All @@ -1721,13 +1673,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],
Expand Down Expand Up @@ -1790,12 +1735,6 @@ fn configure_empty_storage<F: FieldExt>(
"new value is 0 for empty storage",
config.new_value.current(),
);
cb.assert(
"empty storage proof does not extend trie",
config
.path_type
.current_matches(&[PathType::Start, PathType::Common]),
);

let is_final_segment = config.segment_type.next_matches(&[SegmentType::Start]);
cb.condition(is_final_segment, |cb| {
Expand Down Expand Up @@ -1860,12 +1799,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(
Expand Down