Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.

Commit dab1767

Browse files
z2trillionMason Liang
andauthored
wip (#957)
Co-authored-by: Mason Liang <mason@scroll.io>
1 parent 828cf3c commit dab1767

File tree

5 files changed

+60
-20
lines changed

5 files changed

+60
-20
lines changed

zkevm-circuits/src/evm_circuit/execution/callop.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,7 +1599,11 @@ mod test {
15991599
.handle_block(&block.eth_block, &block.geth_traces)
16001600
.unwrap();
16011601
let block = block_convert::<Fr>(&builder.block, &builder.code_db).unwrap();
1602+
dbg!(block.mpt_updates.clone());
1603+
panic!();
16021604
let mpt_circuit = MptCircuit::new_from_block(&block);
1605+
// dbg!(mpt_circuit.proofs);
1606+
panic!();
16031607
let prover = MockProver::<Fr>::run(12, &mpt_circuit, vec![]).unwrap();
16041608
println!("prover result: {:?}", prover.verify());
16051609
assert!(prover.verify().is_ok());

zkevm-circuits/src/mpt_circuit.rs

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ use halo2_proofs::{
1212
plonk::{Advice, Circuit, Column, ConstraintSystem, Error, Fixed},
1313
};
1414
use itertools::Itertools;
15-
use mpt_zktrie::mpt_circuits::{gadgets::poseidon::PoseidonLookup, mpt, types::Proof};
15+
use mpt_zktrie::mpt_circuits::{
16+
gadgets::{mpt_update::hash_traces, poseidon::PoseidonLookup},
17+
mpt,
18+
types::Proof,
19+
};
1620

1721
impl PoseidonLookup for PoseidonTable {
1822
fn lookup_columns_generic(&self) -> (Column<Fixed>, [Column<Advice>; 6]) {
@@ -94,6 +98,9 @@ impl SubCircuit<Fr> for MptCircuit<Fr> {
9498
.zip_eq(block.mpt_updates.smt_traces.iter().cloned())
9599
.collect();
96100

101+
dbg!(traces.clone());
102+
panic!();
103+
97104
Self {
98105
proofs: traces.into_iter().map(Proof::from).collect(),
99106
row_limit: block.circuits_params.max_mpt_rows,
@@ -137,7 +144,7 @@ impl SubCircuit<Fr> for MptCircuit<Fr> {
137144

138145
#[cfg(any(feature = "test", test))]
139146
impl Circuit<Fr> for MptCircuit<Fr> {
140-
type Config = (MptCircuitConfig<Fr>, Challenges);
147+
type Config = (MptCircuitConfig<Fr>, PoseidonTable, Challenges);
141148
type FloorPlanner = SimpleFloorPlanner;
142149

143150
fn without_witnesses(&self) -> Self {
@@ -149,7 +156,7 @@ impl Circuit<Fr> for MptCircuit<Fr> {
149156

150157
fn configure(meta: &mut ConstraintSystem<Fr>) -> Self::Config {
151158
let challenges = Challenges::construct(meta);
152-
let poseidon_table = PoseidonTable::dev_construct(meta);
159+
let poseidon_table = PoseidonTable::construct(meta);
153160
let mpt_table = MptTable::construct(meta);
154161

155162
let config = {
@@ -163,15 +170,46 @@ impl Circuit<Fr> for MptCircuit<Fr> {
163170
)
164171
};
165172

166-
(config, challenges)
173+
(config, poseidon_table, challenges)
167174
}
168175

169176
fn synthesize(
170177
&self,
171-
(config, challenges): Self::Config,
178+
(mpt_config, poseidon_table, challenges): Self::Config,
172179
mut layouter: impl Layouter<Fr>,
173180
) -> Result<(), Error> {
181+
// let hashes_traces =
182+
// mpt_zktrie::mpt_circuits::gadgets::mpt_update::hash_traces(&self.proofs);
183+
184+
// q_enable: meta.fixed_column(),
185+
// hash_id: meta.advice_column(),
186+
// input0: meta.advice_column(),
187+
// input1: meta.advice_column(),
188+
// control: meta.advice_column(),
189+
// domain_spec: meta.advice_column(),
190+
// heading_mark: meta.advice_column(),
191+
192+
dbg!(self.proofs.clone());
193+
dbg!(hash_traces(&self.proofs));
194+
// panic!();
195+
196+
let poseidon_table_rows: Vec<_> = hash_traces(&self.proofs)
197+
.iter()
198+
.map(|([left, right], domain, hash)| {
199+
// dbg!(left, right, hash, domain);
200+
[
201+
*hash,
202+
*left,
203+
*right,
204+
Fr::zero(),
205+
*domain,
206+
Fr::one(),
207+
]
208+
.map(Value::known)
209+
})
210+
.collect();
211+
poseidon_table.load(&mut layouter, &poseidon_table_rows)?;
174212
let challenges = challenges.values(&layouter);
175-
self.synthesize_sub(&config, &challenges, &mut layouter)
213+
self.synthesize_sub(&mpt_config, &challenges, &mut layouter)
176214
}
177215
}

zkevm-circuits/src/table.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -891,16 +891,11 @@ impl PoseidonTable {
891891
}
892892
}
893893

894-
/// Construct a new PoseidonTable for dev
895-
pub(crate) fn dev_construct<F: FieldExt>(meta: &mut ConstraintSystem<F>) -> Self {
896-
Self::construct(meta)
897-
}
898-
899894
pub(crate) fn assign<F: Field>(
900895
&self,
901896
region: &mut Region<'_, F>,
902897
offset: usize,
903-
row: &[Value<F>],
898+
row: [Value<F>; 6],
904899
) -> Result<(), Error> {
905900
region.assign_fixed(
906901
|| "assign poseidon table row value",
@@ -914,32 +909,31 @@ impl PoseidonTable {
914909
|| "assign poseidon table row value",
915910
*column,
916911
offset,
917-
|| *value,
912+
|| value,
918913
)?;
919914
}
920915
Ok(())
921916
}
922917

923-
// Is this method used anyhwhere?
924918
pub(crate) fn load<'d, F: Field>(
925919
&self,
926920
layouter: &mut impl Layouter<F>,
927-
hashes: impl Iterator<Item = &'d [Value<F>]> + Clone,
921+
hashes: &[[Value<F>; 6]],
928922
) -> Result<(), Error> {
929923
layouter.assign_region(
930924
|| "poseidon table",
931-
|mut region| self.load_with_region(&mut region, hashes.clone()),
925+
|mut region| self.load_with_region(&mut region, hashes),
932926
)
933927
}
934928

935929
pub(crate) fn load_with_region<'d, F: Field>(
936930
&self,
937931
region: &mut Region<'_, F>,
938-
hashes: impl Iterator<Item = &'d [Value<F>]>,
932+
hashes: &[[Value<F>; 6]],
939933
) -> Result<(), Error> {
940-
self.assign(region, 0, [Value::known(F::zero()); 6].as_slice())?;
941-
for (offset, row) in hashes.enumerate() {
942-
self.assign(region, offset + 1, row)?;
934+
self.assign(region, 0, [Value::known(F::zero()); 6])?;
935+
for (offset, row) in hashes.iter().enumerate() {
936+
self.assign(region, offset + 1, *row)?;
943937
}
944938
Ok(())
945939
}

zkevm-circuits/src/witness/block.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,8 @@ pub fn block_convert<F: Field>(
518518
log::error!("withdraw root is not avaliable");
519519
}
520520

521+
dbg!(mpt_updates.len());
522+
521523
Ok(Block {
522524
randomness: F::from_u128(DEFAULT_RAND),
523525
context: block.into(),

zkevm-circuits/src/witness/mpt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ impl MptUpdates {
233233
)
234234
})
235235
.collect();
236+
dbg!(rows_len, updates.len());
237+
// panic!();
236238
MptUpdates {
237239
updates,
238240
old_root,

0 commit comments

Comments
 (0)