From afb6f27618dbefc12a12f5a91924aa847128ce28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20P=C3=A9rez?= <37264926+CPerezz@users.noreply.github.com> Date: Thu, 5 Jan 2023 17:59:24 +0100 Subject: [PATCH] Fix/super circuit double assign (#1024) * 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: #987 * fix: Add empty row in MPT table to prevent testing panics As pointed by @lispc in https://github.com/privacy-scaling-explorations/zkevm-circuits/pull/1024#issuecomment-1372217747, 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 https://github.com/privacy-scaling-explorations/halo2/issues/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 https://github.com/privacy-scaling-explorations/zkevm-circuits/issues/1032 --- zkevm-circuits/src/state_circuit.rs | 7 +++---- zkevm-circuits/src/super_circuit.rs | 1 - zkevm-circuits/src/table.rs | 3 ++- zkevm-circuits/src/witness/mpt.rs | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/zkevm-circuits/src/state_circuit.rs b/zkevm-circuits/src/state_circuit.rs index f4b67b0837..f015e6ae77 100644 --- a/zkevm-circuits/src/state_circuit.rs +++ b/zkevm-circuits/src/state_circuit.rs @@ -407,10 +407,6 @@ impl SubCircuit for StateCircuit { randomness, )?; - config - .mpt_table - .load_with_region(&mut region, &self.updates, randomness)?; - config.assign_with_region( &mut region, &self.rows, @@ -484,6 +480,9 @@ where mut layouter: impl Layouter, ) -> 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) } } diff --git a/zkevm-circuits/src/super_circuit.rs b/zkevm-circuits/src/super_circuit.rs index 8396f3e645..6af4a80ba3 100644 --- a/zkevm-circuits/src/super_circuit.rs +++ b/zkevm-circuits/src/super_circuit.rs @@ -297,7 +297,6 @@ impl, ) -> 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(()) } diff --git a/zkevm-circuits/src/witness/mpt.rs b/zkevm-circuits/src/witness/mpt.rs index 2ea84372c5..8a7fcfdd05 100644 --- a/zkevm-circuits/src/witness/mpt.rs +++ b/zkevm-circuits/src/witness/mpt.rs @@ -37,7 +37,7 @@ pub struct MptUpdates(HashMap); /// The field element encoding of an MPT update, which is used by the MptTable #[derive(Debug, Clone, Copy)] -pub struct MptUpdateRow([F; 7]); +pub struct MptUpdateRow(pub(crate) [F; 7]); impl MptUpdates { pub(crate) fn get(&self, row: &Rw) -> Option {