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

Add selector column to lookup_exprs for mpt circuit #102

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading