Skip to content

Commit

Permalink
Merge branch 'v0.7' into feat/inv_bench
Browse files Browse the repository at this point in the history
  • Loading branch information
z2trillion authored Nov 27, 2023
2 parents ea58bdd + 9325879 commit ad1ffeb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 48 deletions.
42 changes: 0 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
6 changes: 6 additions & 0 deletions src/gadgets/poseidon.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::constraint_builder::{AdviceColumn, FixedColumn};
use halo2_proofs::plonk::{Advice, Column, Fixed};
#[cfg(any(test, feature = "bench"))]
use halo2_proofs::{
arithmetic::FieldExt, circuit::Region, halo2curves::bn256::Fr, plonk::ConstraintSystem,
};
#[cfg(any(test, feature = "bench"))]
use hash_circuit::hash::Hashable;

#[cfg(any(test, feature = "bench"))]
const MAX_POSEIDON_ROWS: usize = 200;

/// Lookup represent the poseidon table in zkevm circuit
Expand All @@ -19,6 +22,7 @@ pub trait PoseidonLookup {
}
}

#[cfg(any(test, feature = "bench"))]
#[derive(Clone, Copy)]
pub struct PoseidonTable {
q_enable: FixedColumn,
Expand All @@ -30,6 +34,7 @@ pub struct PoseidonTable {
head_mark: AdviceColumn,
}

#[cfg(any(test, feature = "bench"))]
impl PoseidonTable {
pub fn configure<F: FieldExt>(cs: &mut ConstraintSystem<F>) -> Self {
let [hash, left, right, control, domain_spec, head_mark] =
Expand Down Expand Up @@ -77,6 +82,7 @@ impl PoseidonTable {
}
}

#[cfg(any(test, feature = "bench"))]
impl PoseidonLookup for PoseidonTable {
fn lookup_columns(&self) -> (FixedColumn, [AdviceColumn; 6]) {
(
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 @@ -183,7 +182,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 ad1ffeb

Please sign in to comment.