Skip to content

Commit

Permalink
Add fixed column to lookup_exprs for mpt circuit
Browse files Browse the repository at this point in the history
  • Loading branch information
Mason Liang committed Nov 6, 2023
1 parent 6232ff4 commit 6a2e7d2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/gadgets/mpt_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ lazy_static! {
}

pub trait MptUpdateLookup<F: FieldExt> {
fn lookup(&self) -> [Query<F>; 8];
fn lookup(&self) -> [Query<F>; 7];
}

#[derive(Clone)]
Expand Down Expand Up @@ -77,8 +77,10 @@ pub struct MptUpdateConfig {
}

impl<F: FieldExt> MptUpdateLookup<F> for MptUpdateConfig {
fn lookup(&self) -> [Query<F>; 8] {
fn lookup(&self) -> [Query<F>; 7] {
let is_start = || self.segment_type.current_matches(&[SegmentType::Start]);
// Note that one non-start rows, all 7 queries will be 0. This corresponds to a valid
// mpt proof in that in an empty trie, the zero address has nonce = 0.
let old_root_rlc = self.second_phase_intermediate_values[0].current() * is_start();
let new_root_rlc = self.second_phase_intermediate_values[1].current() * is_start();
let proof_type = self.proof_type.current() * is_start();
Expand All @@ -90,7 +92,6 @@ impl<F: FieldExt> MptUpdateLookup<F> for MptUpdateConfig {
* is_start();
let storage_key_rlc = self.storage_key_rlc.current() * is_start();
[
is_start().into(),
address,
storage_key_rlc,
proof_type,
Expand Down
10 changes: 7 additions & 3 deletions src/mpt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
constraint_builder::{ConstraintBuilder, SelectorColumn},
constraint_builder::{ConstraintBuilder, Query, SelectorColumn},
gadgets::{
byte_bit::ByteBitGadget,
byte_representation::ByteRepresentationConfig,
Expand Down Expand Up @@ -76,7 +76,6 @@ impl MptCircuitConfig {
// exist in an mpt with root = 0 (i.e. the mpt is empty).
let is_final_row = SelectorColumn(cs.fixed_column());
let padding_row_expressions = [
1.into(),
0.into(),
0.into(),
(MPTProofType::AccountDoesNotExist as u64).into(),
Expand Down Expand Up @@ -173,7 +172,12 @@ impl MptCircuitConfig {
}

pub fn lookup_exprs<F: FieldExt>(&self, meta: &mut VirtualCells<'_, F>) -> [Expression<F>; 8] {
self.mpt_update.lookup().map(|q| q.run(meta))
std::iter::once(Query::from(self.selector.current()))
.chain(self.mpt_update.lookup().into_iter())
.map(|q| q.run(meta))
.collect::<Vec<_>>()
.try_into()
.unwrap()
}

/// The number of minimum number of rows required for the mpt circuit.
Expand Down

0 comments on commit 6a2e7d2

Please sign in to comment.