From c9a1695c5a532ee423f1cf5b44882b1876b42595 Mon Sep 17 00:00:00 2001 From: "sm.wu" Date: Fri, 20 Oct 2023 16:25:35 +0800 Subject: [PATCH] address comments by fixing gamme position bug --- .../circuit_input_builder/input_state_ref.rs | 2 +- gadgets/src/permutation.rs | 20 ++++++++++--------- .../src/evm_circuit/execution/begin_tx.rs | 4 ++-- zkevm-circuits/src/witness/block.rs | 4 ++-- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/bus-mapping/src/circuit_input_builder/input_state_ref.rs b/bus-mapping/src/circuit_input_builder/input_state_ref.rs index 60f035de0d..35678bb055 100644 --- a/bus-mapping/src/circuit_input_builder/input_state_ref.rs +++ b/bus-mapping/src/circuit_input_builder/input_state_ref.rs @@ -36,7 +36,7 @@ pub struct CircuitInputStateRef<'a> { pub block: &'a mut Block, /// Block Context pub block_ctx: &'a mut BlockContext, - /// Block Context + /// Chunk Context pub chunk_ctx: &'a mut ChunkContext, /// Transaction pub tx: &'a mut Transaction, diff --git a/gadgets/src/permutation.rs b/gadgets/src/permutation.rs index 1bf96a7916..3c6e7dcbc5 100644 --- a/gadgets/src/permutation.rs +++ b/gadgets/src/permutation.rs @@ -35,6 +35,7 @@ pub struct PermutationChipConfig { _phantom: PhantomData, } +/// (alpha, gamma, prev_acc_fingerprints, next_acc_fingerprints) type PermutationAssignedCells = ( AssignedCell, AssignedCell, @@ -59,10 +60,11 @@ impl PermutationChipConfig { let fingerprints = get_permutation_fingerprints(col_values, alpha, gamma, acc_fingerprints_prev); + // power_of_gamma start from gamma**1 let power_of_gamma = { let num_of_col = col_values.get(0).map(|row| row.len()).unwrap_or_default(); - std::iter::successors(Some(Value::known(F::ONE)), |prev| (*prev * gamma).into()) - .take(num_of_col) + std::iter::successors(Some(gamma), |prev| (*prev * gamma).into()) + .take(num_of_col.saturating_sub(1)) .collect::>>() }; @@ -101,7 +103,7 @@ impl PermutationChipConfig { let gamma_cells = self .power_of_gamma .iter() - .zip(power_of_gamma.iter()) + .zip_eq(power_of_gamma.iter()) .map(|(col, value)| { region.assign_advice( || format!("gamma at index {}", offset), @@ -149,12 +151,12 @@ impl PermutationChipConfig { ] .iter() .cloned() - .chain( - self.power_of_gamma - .iter() - .enumerate() - .map(|(i, col)| (*col, format!("GADGETS_PermutationChipConfig_gamma_{}", i))), - ) + .chain(self.power_of_gamma.iter().enumerate().map(|(i, col)| { + ( + *col, + format!("GADGETS_PermutationChipConfig_gamma_{}", i + 1), + ) + })) .for_each(|(col, ann)| region.name_column(|| format!("{}_{}", prefix, ann), col)); } } diff --git a/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs b/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs index 9f0c56c418..3e3124e4b5 100644 --- a/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs +++ b/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs @@ -73,8 +73,8 @@ impl ExecutionGadget for BeginTxGadget { const EXECUTION_STATE: ExecutionState = ExecutionState::BeginTx; fn configure(cb: &mut EVMConstraintBuilder) -> Self { - // constraint rwc at step first - cb.step_first_constraint_rwc(); + // TODO constraint rwc at step first + // cb.step_first_constraint_rwc(); // Use rw_counter of the step which triggers next call as its call_id. let call_id = cb.curr.state.rw_counter.clone(); diff --git a/zkevm-circuits/src/witness/block.rs b/zkevm-circuits/src/witness/block.rs index 195c25ace2..cbe0c01520 100644 --- a/zkevm-circuits/src/witness/block.rs +++ b/zkevm-circuits/src/witness/block.rs @@ -281,8 +281,8 @@ pub fn block_convert( eth_block: block.eth_block.clone(), // TODO get permutation fingerprint & challenges - permu_alpha: F::from(1), - permu_gamma: F::from(1), + permu_alpha: F::from(103), + permu_gamma: F::from(101), permu_rwtable_prev_continuous_fingerprint: F::from(1), permu_rwtable_next_continuous_fingerprint: F::from(1), permu_chronological_rwtable_prev_continuous_fingerprint: F::from(1),