use super::table::Table;
use crate::evm_circuit::{step::ExecutionState, EvmCircuit};
use bus_mapping::circuit_input_builder::FeatureConfig;
use halo2_proofs::{
halo2curves::bn256::Fr,
plonk::{Circuit, ConstraintSystem},
};
use std::collections::HashMap;
pub(crate) const STEP_WIDTH: usize = 140;
pub const MAX_STEP_HEIGHT: usize = 19;
pub(crate) const STEP_STATE_HEIGHT: usize = 1;
pub const N_PHASE2_COLUMNS: usize = 1;
pub const N_PHASE1_COLUMNS: usize =
STEP_WIDTH - EVM_LOOKUP_COLS - N_PHASE2_COLUMNS - N_COPY_COLUMNS - N_U8_LOOKUPS - N_U16_LOOKUPS;
pub const N_COPY_COLUMNS: usize = 2;
pub const N_U8_LOOKUPS: usize = 24;
pub const N_U16_LOOKUPS: usize = 0;
pub(crate) const EVM_LOOKUP_COLS: usize = FIXED_TABLE_LOOKUPS
+ TX_TABLE_LOOKUPS
+ RW_TABLE_LOOKUPS
+ BYTECODE_TABLE_LOOKUPS
+ BLOCK_TABLE_LOOKUPS
+ COPY_TABLE_LOOKUPS
+ KECCAK_TABLE_LOOKUPS
+ EXP_TABLE_LOOKUPS
+ SIG_TABLE_LOOKUPS
+ CHUNK_CTX_TABLE_LOOKUPS;
pub const LOOKUP_CONFIG: &[(Table, usize)] = &[
(Table::Fixed, FIXED_TABLE_LOOKUPS),
(Table::Tx, TX_TABLE_LOOKUPS),
(Table::Rw, RW_TABLE_LOOKUPS),
(Table::Bytecode, BYTECODE_TABLE_LOOKUPS),
(Table::Block, BLOCK_TABLE_LOOKUPS),
(Table::Copy, COPY_TABLE_LOOKUPS),
(Table::Keccak, KECCAK_TABLE_LOOKUPS),
(Table::Exp, EXP_TABLE_LOOKUPS),
(Table::Sig, SIG_TABLE_LOOKUPS),
(Table::ChunkCtx, CHUNK_CTX_TABLE_LOOKUPS),
];
pub const FIXED_TABLE_LOOKUPS: usize = 8;
pub const TX_TABLE_LOOKUPS: usize = 4;
pub const RW_TABLE_LOOKUPS: usize = 13;
pub const BYTECODE_TABLE_LOOKUPS: usize = 4;
pub const BLOCK_TABLE_LOOKUPS: usize = 1;
pub const COPY_TABLE_LOOKUPS: usize = 1;
pub const KECCAK_TABLE_LOOKUPS: usize = 1;
pub const EXP_TABLE_LOOKUPS: usize = 1;
pub const SIG_TABLE_LOOKUPS: usize = 1;
pub const CHUNK_CTX_TABLE_LOOKUPS: usize = 1;
pub(crate) const MAX_N_BYTES_INTEGER: usize = 31;
pub(crate) const N_BYTES_WORD: usize = 32;
pub(crate) const N_BYTES_HALF_WORD: usize = N_BYTES_WORD / 2;
pub(crate) const N_BYTES_U64: usize = 8;
pub(crate) const N_BYTES_ACCOUNT_ADDRESS: usize = 20;
pub(crate) const N_BYTES_MEMORY_ADDRESS: usize = 5;
pub(crate) const N_BYTES_MEMORY_WORD_SIZE: usize = 4;
pub(crate) const STACK_CAPACITY: usize = 1024;
pub(crate) const N_BYTES_PROGRAM_COUNTER: usize = N_BYTES_U64;
pub(crate) const N_BYTES_GAS: usize = N_BYTES_U64;
pub(crate) const N_BYTES_CALLDATASIZE: usize = N_BYTES_U64;
pub(crate) const N_BYTES_COINBASE: usize = N_BYTES_ACCOUNT_ADDRESS;
pub(crate) const N_BYTES_GAS_LIMIT: usize = N_BYTES_U64;
pub(crate) const N_BYTES_NUMBER: usize = N_BYTES_U64;
pub(crate) const N_BYTES_TIMESTAMP: usize = N_BYTES_U64;
pub(crate) const N_BYTES_DIFFICULTY: usize = N_BYTES_WORD;
pub(crate) const N_BYTES_BASE_FEE: usize = N_BYTES_WORD;
pub(crate) const N_BYTES_CHAIN_ID: usize = N_BYTES_U64;
pub(crate) const N_BYTES_PREV_HASH: usize = 256 * N_BYTES_WORD;
pub(crate) const N_BYTES_WITHDRAWAL_ROOT: usize = N_BYTES_WORD;
pub(crate) const N_BYTES_BLOCK: usize = N_BYTES_COINBASE
+ N_BYTES_GAS_LIMIT
+ N_BYTES_NUMBER
+ N_BYTES_TIMESTAMP
+ N_BYTES_DIFFICULTY
+ N_BYTES_BASE_FEE
+ N_BYTES_CHAIN_ID
+ N_BYTES_PREV_HASH
+ N_BYTES_WITHDRAWAL_ROOT;
pub(crate) const N_BYTES_EXTRA_VALUE: usize = N_BYTES_WORD + N_BYTES_WORD + N_BYTES_WORD; pub(crate) const N_BYTES_TX_NONCE: usize = N_BYTES_U64;
pub(crate) const N_BYTES_TX_GAS_LIMIT: usize = N_BYTES_U64; pub(crate) const N_BYTES_TX_GASPRICE: usize = N_BYTES_WORD;
pub(crate) const N_BYTES_TX_FROM: usize = N_BYTES_ACCOUNT_ADDRESS;
pub(crate) const N_BYTES_TX_TO: usize = N_BYTES_ACCOUNT_ADDRESS;
pub(crate) const N_BYTES_TX_IS_CREATE: usize = N_BYTES_U64;
pub(crate) const N_BYTES_TX_VALUE: usize = N_BYTES_WORD;
pub(crate) const N_BYTES_TX_CALLDATA_LEN: usize = N_BYTES_CALLDATASIZE;
pub(crate) const N_BYTES_TX_CALLDATA_GASCOST: usize = N_BYTES_U64;
pub(crate) const N_BYTES_TX_TXSIGNHASH: usize = N_BYTES_WORD;
pub(crate) const N_BYTES_TX: usize = N_BYTES_TX_NONCE
+ N_BYTES_TX_GAS_LIMIT
+ N_BYTES_TX_GASPRICE
+ N_BYTES_TX_FROM
+ N_BYTES_TX_TO
+ N_BYTES_TX_IS_CREATE
+ N_BYTES_TX_VALUE
+ N_BYTES_TX_CALLDATA_LEN
+ N_BYTES_TX_CALLDATA_GASCOST
+ N_BYTES_TX_TXSIGNHASH;
pub(crate) const N_BYTES_WITHDRAWAL: usize = N_BYTES_U64 + N_BYTES_U64 + N_BYTES_ACCOUNT_ADDRESS + N_BYTES_U64; lazy_static::lazy_static! {
static ref INVALID_TX_CONFIG: FeatureConfig = FeatureConfig {
invalid_tx: true,
..Default::default()
};
pub(crate) static ref EXECUTION_STATE_HEIGHT_MAP : HashMap<ExecutionState, usize> = get_step_height_map(*INVALID_TX_CONFIG);
}
fn get_step_height_map(feature_config: FeatureConfig) -> HashMap<ExecutionState, usize> {
let mut meta = ConstraintSystem::<Fr>::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
};
assert_eq!(map_invalid_tx, map_mainnet);
}
}