Skip to content

Commit

Permalink
Fix/super circuit double assign (privacy-scaling-explorations#1024)
Browse files Browse the repository at this point in the history
* fix: Remove duplicate assignment of evm circuit

* fix: Remove mpt table load from StateCircuit

The table is loaded now in the SuperCircuit and the double-assignment is
removed by removing the assignment from the StateCircuit `synthesize_sub` method.

Resolves: privacy-scaling-explorations#987

* fix: Add empty row in MPT table to prevent testing panics

As pointed by @lispc in
privacy-scaling-explorations#1024 (comment),
Halo2 currently has a bug which prevents it to render correctly the
errors for an empty region with a `ConstraintError` on it.

An issue has been filled for this so that we can fix it in
privacy-scaling-explorations/halo2#117.

Meanwhile a new tag is not released for Halo2 with a fix, this fix will
temporarily be needed and a reminder to remove it has been created in privacy-scaling-explorations#1032
  • Loading branch information
CPerezz authored Jan 5, 2023
1 parent 878e5e6 commit afb6f27
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions zkevm-circuits/src/state_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,6 @@ impl<F: Field> SubCircuit<F> for StateCircuit<F> {
randomness,
)?;

config
.mpt_table
.load_with_region(&mut region, &self.updates, randomness)?;

config.assign_with_region(
&mut region,
&self.rows,
Expand Down Expand Up @@ -484,6 +480,9 @@ where
mut layouter: impl Layouter<F>,
) -> Result<(), Error> {
let challenges = challenges.values(&mut layouter);
config
.mpt_table
.load(&mut layouter, &self.updates, challenges.evm_word())?;
self.synthesize_sub(&config, &challenges, &mut layouter)
}
}
Expand Down
1 change: 0 additions & 1 deletion zkevm-circuits/src/super_circuit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ impl<F: Field, const MAX_TXS: usize, const MAX_CALLDATA: usize, const MAX_RWS: u
.synthesize_sub(&config.evm_circuit, &challenges, &mut layouter)?;
self.pi_circuit
.synthesize_sub(&config.pi_circuit, &challenges, &mut layouter)?;
self.evm_circuit.synthesize(config.evm_circuit, layouter)?;
Ok(())
}
}
Expand Down
3 changes: 2 additions & 1 deletion zkevm-circuits/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,9 @@ impl MptTable {
updates: &MptUpdates,
randomness: Value<F>,
) -> Result<(), Error> {
self.assign(region, 0, &MptUpdateRow([Value::known(F::zero()); 7]))?;
for (offset, row) in updates.table_assignments(randomness).iter().enumerate() {
self.assign(region, offset, row)?;
self.assign(region, offset + 1, row)?;
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/witness/mpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub struct MptUpdates(HashMap<Key, MptUpdate>);

/// The field element encoding of an MPT update, which is used by the MptTable
#[derive(Debug, Clone, Copy)]
pub struct MptUpdateRow<F>([F; 7]);
pub struct MptUpdateRow<F>(pub(crate) [F; 7]);

impl MptUpdates {
pub(crate) fn get(&self, row: &Rw) -> Option<MptUpdate> {
Expand Down

0 comments on commit afb6f27

Please sign in to comment.