Skip to content

Commit

Permalink
cargo fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Mason Liang committed Oct 30, 2023
1 parent 4874955 commit 8739325
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 49 deletions.
56 changes: 9 additions & 47 deletions src/gadgets/mpt_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ pub use path::PathType;
use segment::SegmentType;

use super::{
byte_representation::{BytesLookup, RlcLookup},
byte_representation::BytesLookup,
canonical_representation::{FrHiLoLookup, FrRlcLookup},
is_zero::IsZeroGadget,
key_bit::KeyBitLookup,
one_hot::OneHot,
poseidon::PoseidonLookup,
rlc_randomness::RlcRandomness,
};
use crate::{
constraint_builder::{
Expand All @@ -23,8 +22,7 @@ use crate::{
ClaimKind, HashDomain, Proof,
},
util::{
account_key, domain_hash, fr_to_u256, lagrange_polynomial, rlc, u256_hi_lo,
u256_to_big_endian, u256_to_fr,
account_key, domain_hash, fr_to_u256, lagrange_polynomial, rlc, u256_hi_lo, u256_to_fr,
},
MPTProofType,
};
Expand Down Expand Up @@ -115,9 +113,7 @@ impl MptUpdateConfig {
cb: &mut ConstraintBuilder<F>,
poseidon: &impl PoseidonLookup,
key_bit: &impl KeyBitLookup,
rlc: &impl RlcLookup,
bytes: &impl BytesLookup,
rlc_randomness: &RlcRandomness,
fr_rlc: &impl FrRlcLookup,
fr_hi_lo: &impl FrHiLoLookup,
) -> Self {
Expand Down Expand Up @@ -326,17 +322,10 @@ impl MptUpdateConfig {
MPTProofType::CodeHashExists => {
configure_keccak_code_hash(cb, &config, poseidon)
}
MPTProofType::StorageChanged => {
configure_storage(cb, &config, poseidon, bytes, rlc, rlc_randomness.query())
MPTProofType::StorageChanged => configure_storage(cb, &config, poseidon),
MPTProofType::StorageDoesNotExist => {
configure_empty_storage(cb, &config, poseidon)
}
MPTProofType::StorageDoesNotExist => configure_empty_storage(
cb,
&config,
poseidon,
bytes,
rlc,
rlc_randomness.query(),
),
MPTProofType::AccountDestructed => cb.assert_unreachable("unimplemented!"),
}
};
Expand Down Expand Up @@ -369,9 +358,6 @@ impl MptUpdateConfig {
let mut offset = 1; // selector on first row is disabled.
for proof in proofs {
let proof_type = MPTProofType::from(proof.claim);
let storage_key =
randomness.map(|r| rlc(&u256_to_big_endian(&proof.claim.storage_key()), r));

for i in 0..proof.n_rows() {
self.proof_type.assign(region, offset + i, proof_type);
self.storage_key
Expand Down Expand Up @@ -546,14 +532,11 @@ impl MptUpdateConfig {
other_leaf_data_hash_column.assign(region, offset, other_leaf_data_hash);
}
SegmentType::AccountLeaf3 => {
if let ClaimKind::Storage { key, .. } | ClaimKind::IsEmpty(Some(key)) =
if let ClaimKind::Storage { .. } | ClaimKind::IsEmpty(Some(_)) =
proof.claim.kind
{
let [_, _, new_domain, ..] = self.intermediate_values;
self.key.assign(region, offset + 3, proof.storage.key());
let [storage_key_high, storage_key_low, new_domain, ..] =
self.intermediate_values;
let [rlc_storage_key_high, rlc_storage_key_low, ..] =
self.second_phase_intermediate_values;
self.other_key
.assign(region, offset + 3, proof.storage.other_key());
new_domain.assign(region, offset + 3, HashDomain::AccountFields);
Expand All @@ -565,12 +548,7 @@ impl MptUpdateConfig {
self.key.assign(region, offset, key);
self.other_key.assign(region, offset, other_key);
self.is_zero_gadgets[2].assign_value_and_inverse(region, offset, key - other_key);
if let ClaimKind::CodeHash { old, new } = proof.claim.kind {
let [old_high, old_low, new_high, new_low, ..] = self.intermediate_values;
let [old_rlc_high, old_rlc_low, new_rlc_high, new_rlc_low, ..] =
self.second_phase_intermediate_values;
};
self.assign_storage(region, next_offset, &proof.storage, randomness);
self.assign_storage(region, next_offset, &proof.storage);
n_rows += proof.n_rows();
offset = 1 + n_rows;
}
Expand Down Expand Up @@ -658,7 +636,6 @@ impl MptUpdateConfig {
region: &mut Region<'_, Fr>,
offset: usize,
storage: &StorageProof,
randomness: Value<Fr>,
) -> usize {
match storage {
StorageProof::Root(_) => 0,
Expand All @@ -678,7 +655,6 @@ impl MptUpdateConfig {
other_key,
old_leaf,
new_leaf,
randomness,
);
let n_rows = n_trie_rows + n_leaf_rows;

Expand Down Expand Up @@ -749,7 +725,6 @@ impl MptUpdateConfig {
other_key: Fr,
old: &StorageLeaf,
new: &StorageLeaf,
randomness: Value<Fr>,
) -> usize {
let path_type = match (old, new) {
(StorageLeaf::Entry { .. }, StorageLeaf::Entry { .. }) => PathType::Common,
Expand Down Expand Up @@ -788,10 +763,6 @@ impl MptUpdateConfig {
self.old_hash.assign(region, offset, old_hash);
self.new_hash.assign(region, offset, new_hash);

let [old_high, old_low, new_high, new_low, ..] = self.intermediate_values;
let [old_rlc_high, old_rlc_low, new_rlc_high, new_rlc_low, ..] =
self.second_phase_intermediate_values;

let [old_hash_is_zero_storage_hash, new_hash_is_zero_storage_hash, ..] =
self.is_zero_gadgets;
old_hash_is_zero_storage_hash.assign_value_and_inverse(
Expand Down Expand Up @@ -1748,9 +1719,6 @@ fn configure_storage<F: FieldExt>(
cb: &mut ConstraintBuilder<F>,
config: &MptUpdateConfig,
poseidon: &impl PoseidonLookup,
bytes: &impl BytesLookup,
rlc: &impl RlcLookup,
randomness: Query<F>,
) {
for variant in SegmentType::iter() {
let conditional_constraints = |cb: &mut ConstraintBuilder<F>| match variant {
Expand All @@ -1769,8 +1737,6 @@ fn configure_storage<F: FieldExt>(
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;
let [storage_key_hi, storage_key_lo] = config.storage_key.current();
cb.poseidon_lookup(
"key = poseidon(storage key hi, storage key lo)",
Expand Down Expand Up @@ -1856,12 +1822,8 @@ fn configure_empty_storage<F: FieldExt>(
cb: &mut ConstraintBuilder<F>,
config: &MptUpdateConfig,
poseidon: &impl PoseidonLookup,
bytes: &impl BytesLookup,
rlc: &impl RlcLookup,
randomness: Query<F>,
) {
let [key_high, key_low, _, other_leaf_data_hash, ..] = config.intermediate_values;
let [rlc_key_high, rlc_key_low, ..] = config.second_phase_intermediate_values;
let [_, _, _, other_leaf_data_hash, ..] = config.intermediate_values;
let [.., key_equals_other_key, hash_is_zero] = config.is_zero_gadgets;

cb.assert_zero(
Expand Down
2 changes: 0 additions & 2 deletions src/mpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ impl MptCircuitConfig {
poseidon,
&key_bit,
&byte_representation,
&byte_representation,
&rlc_randomness,
&canonical_representation,
&canonical_representation,
);
Expand Down

0 comments on commit 8739325

Please sign in to comment.