From d72656a75c4e90aa0cd01c2c87bf98ed3decc140 Mon Sep 17 00:00:00 2001 From: ChihChengLiang Date: Wed, 31 Jan 2024 16:49:17 +0800 Subject: [PATCH] add test to address the execution state height concern --- zkevm-circuits/src/evm_circuit/param.rs | 38 ++++++++++++++++++------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/zkevm-circuits/src/evm_circuit/param.rs b/zkevm-circuits/src/evm_circuit/param.rs index 74bcdbace7..4a06970258 100644 --- a/zkevm-circuits/src/evm_circuit/param.rs +++ b/zkevm-circuits/src/evm_circuit/param.rs @@ -169,19 +169,35 @@ pub(crate) const N_BYTES_WITHDRAWAL: usize = N_BYTES_U64 //id + N_BYTES_U64; // amount lazy_static::lazy_static! { + static ref INVALID_TX_CONFIG: FeatureConfig = FeatureConfig { + invalid_tx: true, + ..Default::default() + }; // Step slot height in evm circuit - pub(crate) static ref EXECUTION_STATE_HEIGHT_MAP : HashMap = get_step_height_map(); + // We enable the invalid_tx feature to get invalid tx's ExecutionState height + // We garentee the heights of other ExecutionStates remains unchanged in the following test + pub(crate) static ref EXECUTION_STATE_HEIGHT_MAP : HashMap = get_step_height_map(*INVALID_TX_CONFIG); } -fn get_step_height_map() -> HashMap { +fn get_step_height_map(feature_config: FeatureConfig) -> HashMap { let mut meta = ConstraintSystem::::default(); - let circuit = EvmCircuit::configure_with_params( - &mut meta, - FeatureConfig { - // Enable invalid_tx to get ExecutionState height - invalid_tx: true, - ..Default::default() - }, - ); - + let circuit = EvmCircuit::configure_with_params(&mut meta, feature_config); circuit.0.execution.height_map } +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_get_step_height_map() { + let mainnet_config = FeatureConfig::default(); + let map_mainnet = get_step_height_map(mainnet_config); + + let map_invalid_tx = { + let mut map = EXECUTION_STATE_HEIGHT_MAP.clone(); + map.remove(&ExecutionState::InvalidTx); + map + }; + // We show that the invalid tx feature affects none of the other execution state heights + assert_eq!(map_invalid_tx, map_mainnet); + } +}