From 16fd0684a55703f622a42b883ae9299cbe8f95f6 Mon Sep 17 00:00:00 2001 From: Soham Zemse <22412996+zemse@users.noreply.github.com> Date: Wed, 31 Jan 2024 18:52:40 +0530 Subject: [PATCH 1/3] Replace word::Word with WordLoHi --- light-client-poc/src/circuit/equal_words.rs | 14 +- light-client-poc/src/circuit/state_update.rs | 12 +- light-client-poc/src/circuit/witness.rs | 20 +- zkevm-circuits/src/bytecode_circuit.rs | 18 +- .../src/circuit_tools/cell_manager.rs | 10 +- .../src/circuit_tools/constraint_builder.rs | 10 +- zkevm-circuits/src/circuit_tools/gadgets.rs | 16 +- zkevm-circuits/src/copy_circuit/util.rs | 8 +- .../src/evm_circuit/execution/add_sub.rs | 6 +- .../src/evm_circuit/execution/addmod.rs | 6 +- .../src/evm_circuit/execution/address.rs | 4 +- .../src/evm_circuit/execution/balance.rs | 8 +- .../src/evm_circuit/execution/begin_tx.rs | 60 ++--- .../src/evm_circuit/execution/block_ctx.rs | 4 +- .../src/evm_circuit/execution/blockhash.rs | 6 +- .../src/evm_circuit/execution/byte.rs | 4 +- .../src/evm_circuit/execution/calldatacopy.rs | 16 +- .../src/evm_circuit/execution/calldataload.rs | 14 +- .../src/evm_circuit/execution/calldatasize.rs | 4 +- .../src/evm_circuit/execution/caller.rs | 4 +- .../src/evm_circuit/execution/callop.rs | 85 +++---- .../src/evm_circuit/execution/callvalue.rs | 4 +- .../src/evm_circuit/execution/chainid.rs | 4 +- .../src/evm_circuit/execution/codecopy.rs | 6 +- .../src/evm_circuit/execution/comparator.rs | 14 +- .../src/evm_circuit/execution/create.rs | 70 +++--- .../src/evm_circuit/execution/dummy.rs | 10 +- .../src/evm_circuit/execution/dup.rs | 4 +- .../src/evm_circuit/execution/end_block.rs | 6 +- .../src/evm_circuit/execution/end_tx.rs | 12 +- .../execution/error_invalid_jump.rs | 13 +- .../execution/error_oog_memory_copy.rs | 6 +- .../execution/error_oog_sload_sstore.rs | 16 +- .../execution/error_oog_static_memory.rs | 4 +- .../execution/error_precompile_failed.rs | 8 +- .../execution/error_return_data_oo_bound.rs | 4 +- .../execution/error_write_protection.rs | 12 +- .../src/evm_circuit/execution/extcodecopy.rs | 6 +- .../src/evm_circuit/execution/extcodehash.rs | 4 +- .../src/evm_circuit/execution/extcodesize.rs | 8 +- .../src/evm_circuit/execution/gasprice.rs | 4 +- .../src/evm_circuit/execution/invalid_tx.rs | 6 +- .../src/evm_circuit/execution/is_zero.rs | 10 +- .../src/evm_circuit/execution/jumpi.rs | 13 +- .../src/evm_circuit/execution/logs.rs | 8 +- .../src/evm_circuit/execution/msize.rs | 4 +- .../src/evm_circuit/execution/mul_div_mod.rs | 7 +- .../src/evm_circuit/execution/mulmod.rs | 4 +- .../src/evm_circuit/execution/pop.rs | 4 +- .../evm_circuit/execution/return_revert.rs | 12 +- .../evm_circuit/execution/returndatacopy.rs | 16 +- .../evm_circuit/execution/returndatasize.rs | 4 +- .../src/evm_circuit/execution/sdiv_smod.rs | 10 +- .../src/evm_circuit/execution/selfbalance.rs | 6 +- .../src/evm_circuit/execution/sha3.rs | 8 +- .../src/evm_circuit/execution/shl_shr.rs | 8 +- .../execution/signed_comparator.rs | 8 +- .../src/evm_circuit/execution/sload.rs | 16 +- .../src/evm_circuit/execution/sstore.rs | 51 ++--- .../src/evm_circuit/execution/stop.rs | 4 +- .../src/evm_circuit/execution/swap.rs | 4 +- zkevm-circuits/src/evm_circuit/step.rs | 6 +- zkevm-circuits/src/evm_circuit/table.rs | 30 +-- zkevm-circuits/src/evm_circuit/util.rs | 6 +- .../src/evm_circuit/util/common_gadget.rs | 66 +++--- .../evm_circuit/util/constraint_builder.rs | 209 +++++++++--------- .../evm_circuit/util/math_gadget/cmp_words.rs | 8 +- .../util/math_gadget/is_equal_word.rs | 12 +- .../util/math_gadget/is_zero_word.rs | 8 +- .../evm_circuit/util/math_gadget/lt_word.rs | 6 +- .../evm_circuit/util/math_gadget/modulo.rs | 10 +- .../util/math_gadget/mul_add_words.rs | 6 +- .../util/math_gadget/mul_add_words512.rs | 16 +- .../src/evm_circuit/util/math_gadget/rlp.rs | 14 +- .../src/evm_circuit/util/memory_gadget.rs | 20 +- zkevm-circuits/src/evm_circuit/util/tx.rs | 12 +- zkevm-circuits/src/instance.rs | 6 +- zkevm-circuits/src/keccak_circuit.rs | 4 +- .../src/keccak_circuit/keccak_packed_multi.rs | 12 +- zkevm-circuits/src/keccak_circuit/test.rs | 7 +- .../src/mpt_circuit/account_leaf.rs | 52 ++--- zkevm-circuits/src/mpt_circuit/branch.rs | 14 +- zkevm-circuits/src/mpt_circuit/extension.rs | 6 +- .../src/mpt_circuit/extension_branch.rs | 10 +- zkevm-circuits/src/mpt_circuit/helpers.rs | 67 +++--- zkevm-circuits/src/mpt_circuit/rlp_gadgets.rs | 8 +- zkevm-circuits/src/mpt_circuit/start.rs | 6 +- .../src/mpt_circuit/storage_leaf.rs | 38 ++-- zkevm-circuits/src/pi_circuit.rs | 52 ++--- zkevm-circuits/src/pi_circuit/param.rs | 4 +- zkevm-circuits/src/state_circuit.rs | 48 ++-- .../src/state_circuit/constraint_builder.rs | 49 ++-- zkevm-circuits/src/table.rs | 6 +- zkevm-circuits/src/table/block_table.rs | 6 +- zkevm-circuits/src/table/bytecode_table.rs | 7 +- zkevm-circuits/src/table/copy_table.rs | 4 +- zkevm-circuits/src/table/keccak_table.rs | 8 +- zkevm-circuits/src/table/mpt_table.rs | 30 +-- zkevm-circuits/src/table/rw_table.rs | 16 +- zkevm-circuits/src/table/tx_table.rs | 28 +-- zkevm-circuits/src/table/wd_table.rs | 6 +- zkevm-circuits/src/test_util.rs | 2 +- zkevm-circuits/src/tx_circuit.rs | 38 ++-- zkevm-circuits/src/tx_circuit/sign_verify.rs | 14 +- zkevm-circuits/src/util/int_decomposition.rs | 6 +- zkevm-circuits/src/util/word.rs | 104 ++++----- zkevm-circuits/src/witness/block.rs | 26 +-- zkevm-circuits/src/witness/mpt.rs | 22 +- zkevm-circuits/src/witness/rw.rs | 22 +- 109 files changed, 968 insertions(+), 936 deletions(-) diff --git a/light-client-poc/src/circuit/equal_words.rs b/light-client-poc/src/circuit/equal_words.rs index c085fa41f6..e03e9dc486 100644 --- a/light-client-poc/src/circuit/equal_words.rs +++ b/light-client-poc/src/circuit/equal_words.rs @@ -9,16 +9,16 @@ use halo2_proofs::{ plonk::{Advice, Column, ConstraintSystem, Error, Expression, Selector}, poly::Rotation, }; -use zkevm_circuits::util::word::Word; +use zkevm_circuits::util::word::WordLoHi; #[derive(Clone, Debug)] -pub struct EqualWordsConfig(Word>); +pub struct EqualWordsConfig(WordLoHi>); impl EqualWordsConfig { pub fn configure( meta: &mut ConstraintSystem, q_enable: Selector, - first: (Word>, Rotation), - second: (Word>, Rotation), + first: (WordLoHi>, Rotation), + second: (WordLoHi>, Rotation), ) -> Self { let lo_inv = meta.advice_column(); let lo = IsZeroChip::configure( @@ -42,7 +42,7 @@ impl EqualWordsConfig { hi_inv, ); - Self(Word::new([lo, hi])) + Self(WordLoHi::new([lo, hi])) } pub fn expr(&self) -> Expression { @@ -54,8 +54,8 @@ impl EqualWordsConfig { region: &mut Region<'_, F>, offset: usize, name: &str, - first: &Word, - second: &Word, + first: &WordLoHi, + second: &WordLoHi, ) -> Result<(), Error> { region.name_column(|| format!("{}_lo_inv", name), self.0.lo().value_inv); region.name_column(|| format!("{}_hi_inv", name), self.0.hi().value_inv); diff --git a/light-client-poc/src/circuit/state_update.rs b/light-client-poc/src/circuit/state_update.rs index 15464e311b..09d750c941 100644 --- a/light-client-poc/src/circuit/state_update.rs +++ b/light-client-poc/src/circuit/state_update.rs @@ -21,7 +21,7 @@ use halo2_proofs::{ use zkevm_circuits::{ mpt_circuit::{MPTCircuit, MPTCircuitParams, MPTConfig}, table::{KeccakTable, MptTable}, - util::{word, Challenges}, + util::{word::WordLoHi, Challenges}, }; use super::witness::{ @@ -117,12 +117,12 @@ impl Circuit for StateUpdateCircuit { let pi_instance = meta.instance_column(); let pi_mpt = MptTable { address: meta.advice_column(), - storage_key: word::Word::new([meta.advice_column(), meta.advice_column()]), + storage_key: WordLoHi::new([meta.advice_column(), meta.advice_column()]), proof_type: meta.advice_column(), - new_root: word::Word::new([meta.advice_column(), meta.advice_column()]), - old_root: word::Word::new([meta.advice_column(), meta.advice_column()]), - new_value: word::Word::new([meta.advice_column(), meta.advice_column()]), - old_value: word::Word::new([meta.advice_column(), meta.advice_column()]), + new_root: WordLoHi::new([meta.advice_column(), meta.advice_column()]), + old_root: WordLoHi::new([meta.advice_column(), meta.advice_column()]), + new_value: WordLoHi::new([meta.advice_column(), meta.advice_column()]), + old_value: WordLoHi::new([meta.advice_column(), meta.advice_column()]), }; for col in [ diff --git a/light-client-poc/src/circuit/witness.rs b/light-client-poc/src/circuit/witness.rs index f667abf467..acab1f6b65 100644 --- a/light-client-poc/src/circuit/witness.rs +++ b/light-client-poc/src/circuit/witness.rs @@ -15,9 +15,7 @@ use eyre::Result; use mpt_witness_generator::{ProofType, TrieModification}; use zkevm_circuits::{ - mpt_circuit::witness_row::Node, - table::mpt_table::MPTProofType, - util::word::{self, Word}, + mpt_circuit::witness_row::Node, table::mpt_table::MPTProofType, util::word::WordLoHi, }; #[derive(Default, Debug, Clone)] @@ -82,10 +80,10 @@ pub struct StateUpdateWitness { pub struct SingleTrieModification { pub typ: F, pub address: F, - pub value: word::Word, - pub key: word::Word, - pub old_root: word::Word, - pub new_root: word::Word, + pub value: WordLoHi, + pub key: WordLoHi, + pub old_root: WordLoHi, + pub new_root: WordLoHi, } #[derive(Default, Clone)] @@ -350,10 +348,10 @@ impl StateUpdateWitness { let lc_proof = SingleTrieModification:: { typ: F::from(proof_type as u64), address: address.to_scalar().unwrap(), - value: Word::::from(value), - key: Word::::from(key), - old_root: Word::::from(from_root), - new_root: Word::::from(to_root), + value: WordLoHi::::from(value), + key: WordLoHi::::from(key), + old_root: WordLoHi::::from(from_root), + new_root: WordLoHi::::from(to_root), }; lc_proofs.push(lc_proof); } diff --git a/zkevm-circuits/src/bytecode_circuit.rs b/zkevm-circuits/src/bytecode_circuit.rs index e84afb4a91..5cd71e9b72 100644 --- a/zkevm-circuits/src/bytecode_circuit.rs +++ b/zkevm-circuits/src/bytecode_circuit.rs @@ -16,8 +16,8 @@ use crate::{ }, table::{BytecodeFieldTag, BytecodeTable, KeccakTable, LookupTable}, util::{ - self, get_push_size, - word::{empty_code_hash_word_value, Word, Word32, WordExpr}, + get_push_size, + word::{empty_code_hash_word_value, Word32, WordExpr, WordLoHi}, Challenges, Expr, SubCircuit, SubCircuitConfig, }, witness::{self}, @@ -40,7 +40,7 @@ const PUSH_TABLE_WIDTH: usize = 2; #[derive(Debug, Clone, Default)] /// Row for assignment pub(crate) struct BytecodeCircuitRow { - pub(crate) code_hash: Word>, + pub(crate) code_hash: WordLoHi>, tag: F, pub(crate) index: F, pub(crate) is_code: F, @@ -52,7 +52,13 @@ pub(crate) struct BytecodeCircuitRow { } impl BytecodeCircuitRow { #[cfg(test)] - pub(crate) fn new(code_hash: Word>, tag: F, index: F, is_code: F, value: F) -> Self { + pub(crate) fn new( + code_hash: WordLoHi>, + tag: F, + index: F, + is_code: F, + value: F, + ) -> Self { Self { code_hash, tag, @@ -89,7 +95,7 @@ impl From> for BytecodeCircuitAssignment { fn from(codes: Vec) -> Self { let mut rows = vec![]; for bytecode in codes.iter() { - let code_hash = util::word::Word::from(bytecode.hash()).into_value(); + let code_hash = WordLoHi::from(bytecode.hash()).into_value(); let code_size = bytecode.codesize(); let head = BytecodeCircuitRow { code_hash, @@ -366,7 +372,7 @@ impl SubCircuitConfig for BytecodeCircuitConfig { meta.query_advice(length, Rotation::cur()), ); - let empty_hash_word: Word> = + let empty_hash_word: WordLoHi> = Word32::new(*EMPTY_CODE_HASH_LE).to_expr().to_word(); cb.require_equal_word( diff --git a/zkevm-circuits/src/circuit_tools/cell_manager.rs b/zkevm-circuits/src/circuit_tools/cell_manager.rs index 468c07e9fa..4063e24ca1 100644 --- a/zkevm-circuits/src/circuit_tools/cell_manager.rs +++ b/zkevm-circuits/src/circuit_tools/cell_manager.rs @@ -4,7 +4,7 @@ use crate::{ circuit_tools::cached_region::CachedRegion, evm_circuit::util::rlc, table::LookupTable, - util::{query_expression, word::Word, Expr}, + util::{query_expression, word::WordLoHi, Expr}, }; use eth_types::Field; use halo2_proofs::{ @@ -103,11 +103,11 @@ impl Expr for &Cell { } } -pub(crate) type WordCell = Word>; +pub(crate) type WordLoHiCell = WordLoHi>; -impl WordCell { - pub fn expr(&self) -> Word> { - Word::new([self.lo().expr(), self.hi().expr()]) +impl WordLoHiCell { + pub fn expr(&self) -> WordLoHi> { + WordLoHi::new([self.lo().expr(), self.hi().expr()]) } } diff --git a/zkevm-circuits/src/circuit_tools/constraint_builder.rs b/zkevm-circuits/src/circuit_tools/constraint_builder.rs index 62bb78bdb2..3c1e8126e6 100644 --- a/zkevm-circuits/src/circuit_tools/constraint_builder.rs +++ b/zkevm-circuits/src/circuit_tools/constraint_builder.rs @@ -9,7 +9,7 @@ use std::{ use crate::{ evm_circuit::util::rlc, table::LookupTable, - util::{query_expression, word::Word, Expr}, + util::{query_expression, word::WordLoHi, Expr}, }; use eth_types::Field; use gadgets::util::{and, sum, Scalar}; @@ -18,7 +18,7 @@ use itertools::Itertools; use super::{ cached_region::StoredExpression, - cell_manager::{Cell, CellManager, CellType, WordCell}, + cell_manager::{Cell, CellManager, CellType, WordLoHiCell}, }; fn get_condition_expr(conditions: &Vec>) -> Expression { @@ -352,8 +352,8 @@ impl ConstraintBuilder { } // default query_word is 2 limbs. Each limb is not guaranteed to be 128 bits. - pub(crate) fn query_word_unchecked(&mut self) -> WordCell { - Word::new(self.query_cells_dyn(C::default(), 2).try_into().unwrap()) + pub(crate) fn query_word_unchecked(&mut self) -> WordLoHiCell { + WordLoHi::new(self.query_cells_dyn(C::default(), 2).try_into().unwrap()) } pub(crate) fn validate_degree(&self, degree: usize, name: &'static str) { @@ -718,7 +718,7 @@ impl> ExprVec for &[E] { } } -impl + Clone> ExprVec for Word { +impl + Clone> ExprVec for WordLoHi { fn to_expr_vec(&self) -> Vec> { vec![self.lo().expr(), self.hi().expr()] } diff --git a/zkevm-circuits/src/circuit_tools/gadgets.rs b/zkevm-circuits/src/circuit_tools/gadgets.rs index 8d95bd9701..906f1c0a7c 100644 --- a/zkevm-circuits/src/circuit_tools/gadgets.rs +++ b/zkevm-circuits/src/circuit_tools/gadgets.rs @@ -8,7 +8,7 @@ use halo2_proofs::{ use crate::{ evm_circuit::util::{from_bytes, pow_of_two, transpose_val_ret}, - util::word::{Word, WordExpr}, + util::word::{WordExpr, WordLoHi}, }; use super::{ @@ -107,8 +107,8 @@ pub struct IsEqualWordGadget { impl IsEqualWordGadget { pub(crate) fn construct( cb: &mut ConstraintBuilder, - lhs: &Word>, - rhs: &Word>, + lhs: &WordLoHi>, + rhs: &WordLoHi>, ) -> Self { let (lhs_lo, lhs_hi) = lhs.to_word().to_lo_hi(); let (rhs_lo, rhs_hi) = rhs.to_word().to_lo_hi(); @@ -129,8 +129,8 @@ impl IsEqualWordGadget { &self, region: &mut CachedRegion<'_, '_, F>, offset: usize, - lhs: Word, - rhs: Word, + lhs: WordLoHi, + rhs: WordLoHi, ) -> Result { let (lhs_lo, lhs_hi) = lhs.to_lo_hi(); let (rhs_lo, rhs_hi) = rhs.to_lo_hi(); @@ -143,8 +143,8 @@ impl IsEqualWordGadget { &self, region: &mut CachedRegion<'_, '_, F>, offset: usize, - lhs: Value>, - rhs: Value>, + lhs: Value>, + rhs: Value>, ) -> Result, Error> { transpose_val_ret( lhs.zip(rhs) @@ -159,7 +159,7 @@ impl IsEqualWordGadget { lhs: eth_types::Word, rhs: eth_types::Word, ) -> Result { - self.assign(region, offset, Word::from(lhs), Word::from(rhs)) + self.assign(region, offset, WordLoHi::from(lhs), WordLoHi::from(rhs)) } } diff --git a/zkevm-circuits/src/copy_circuit/util.rs b/zkevm-circuits/src/copy_circuit/util.rs index 24cce0f3f4..464d3f0e24 100644 --- a/zkevm-circuits/src/copy_circuit/util.rs +++ b/zkevm-circuits/src/copy_circuit/util.rs @@ -1,12 +1,12 @@ -use crate::util::word::Word; +use crate::util::word::WordLoHi; use bus_mapping::circuit_input_builder::NumberOrHash; use eth_types::Field; use halo2_proofs::circuit::Value; /// Encode the type `NumberOrHash` into a field element -pub fn number_or_hash_to_word(v: &NumberOrHash) -> Word> { +pub fn number_or_hash_to_word(v: &NumberOrHash) -> WordLoHi> { match v { - NumberOrHash::Number(n) => Word::from(*n as u64).into_value(), - NumberOrHash::Hash(h) => Word::from(*h).into_value(), + NumberOrHash::Number(n) => WordLoHi::from(*n as u64).into_value(), + NumberOrHash::Hash(h) => WordLoHi::from(*h).into_value(), } } diff --git a/zkevm-circuits/src/evm_circuit/execution/add_sub.rs b/zkevm-circuits/src/evm_circuit/execution/add_sub.rs index 3f58266d58..5355bed337 100644 --- a/zkevm-circuits/src/evm_circuit/execution/add_sub.rs +++ b/zkevm-circuits/src/evm_circuit/execution/add_sub.rs @@ -11,7 +11,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{Word, WordExpr}, + word::{WordExpr, WordLoHi}, Expr, }, }; @@ -54,9 +54,9 @@ impl ExecutionGadget for AddSubGadget { // ADD: Pop a and b from the stack, push c on the stack // SUB: Pop c and b from the stack, push a on the stack - cb.stack_pop(Word::select(is_sub.expr().0, c.to_word(), a.to_word())); + cb.stack_pop(WordLoHi::select(is_sub.expr().0, c.to_word(), a.to_word())); cb.stack_pop(b.to_word()); - cb.stack_push(Word::select(is_sub.expr().0, a.to_word(), c.to_word())); + cb.stack_push(WordLoHi::select(is_sub.expr().0, a.to_word(), c.to_word())); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/addmod.rs b/zkevm-circuits/src/evm_circuit/execution/addmod.rs index 7c918efa5f..c8def073eb 100644 --- a/zkevm-circuits/src/evm_circuit/execution/addmod.rs +++ b/zkevm-circuits/src/evm_circuit/execution/addmod.rs @@ -17,7 +17,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{Word, Word32Cell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi}, Expr, }, }; @@ -94,7 +94,7 @@ impl ExecutionGadget for AddModGadget { cb.require_equal_word( "check a_reduced + b 512 bit carry if n != 0", sum_areduced_b_overflow.to_word(), - Word::from_lo_unchecked(sum_areduced_b.carry().clone().unwrap().expr()) + WordLoHi::from_lo_unchecked(sum_areduced_b.carry().clone().unwrap().expr()) .mul_selector(not::expr(n_is_zero.expr())), ); @@ -220,7 +220,7 @@ impl ExecutionGadget for AddModGadget { self.cmp_areduced_n.assign(region, offset, a_reduced, n)?; self.n_is_zero - .assign_value(region, offset, Value::known(Word::from(n)))?; + .assign_value(region, offset, Value::known(WordLoHi::from(n)))?; Ok(()) } diff --git a/zkevm-circuits/src/evm_circuit/execution/address.rs b/zkevm-circuits/src/evm_circuit/execution/address.rs index 95e9ecf8fc..0a98827638 100644 --- a/zkevm-circuits/src/evm_circuit/execution/address.rs +++ b/zkevm-circuits/src/evm_circuit/execution/address.rs @@ -11,7 +11,7 @@ use crate::{ }, table::CallContextFieldTag, util::{ - word::{WordCell, WordExpr}, + word::{WordExpr, WordLoHiCell}, Expr, }, }; @@ -22,7 +22,7 @@ use halo2_proofs::plonk::Error; #[derive(Clone, Debug)] pub(crate) struct AddressGadget { same_context: SameContextGadget, - address: WordCell, + address: WordLoHiCell, } impl ExecutionGadget for AddressGadget { diff --git a/zkevm-circuits/src/evm_circuit/execution/balance.rs b/zkevm-circuits/src/evm_circuit/execution/balance.rs index cefc1e8a78..ccc4809cc8 100644 --- a/zkevm-circuits/src/evm_circuit/execution/balance.rs +++ b/zkevm-circuits/src/evm_circuit/execution/balance.rs @@ -15,7 +15,7 @@ use crate::{ }, table::{AccountFieldTag, CallContextFieldTag}, util::{ - word::{Word, Word32Cell, WordCell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -29,8 +29,8 @@ pub(crate) struct BalanceGadget { reversion_info: ReversionInfo, tx_id: Cell, is_warm: Cell, - code_hash: WordCell, - not_exists: IsZeroWordGadget>, + code_hash: WordLoHiCell, + not_exists: IsZeroWordGadget>, balance: Word32Cell, } @@ -139,7 +139,7 @@ impl ExecutionGadget for BalanceGadget { self.code_hash .assign_u256(region, offset, code_hash.to_word())?; self.not_exists - .assign_value(region, offset, Value::known(Word::from(code_hash)))?; + .assign_value(region, offset, Value::known(WordLoHi::from(code_hash)))?; let balance = if code_hash.is_zero() { eth_types::Word::zero() } else { diff --git a/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs b/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs index 9f8106159f..fc4e2f321b 100644 --- a/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs +++ b/zkevm-circuits/src/evm_circuit/execution/begin_tx.rs @@ -22,7 +22,7 @@ use crate::{ }, table::{AccountFieldTag, BlockContextFieldTag, CallContextFieldTag}, util::{ - word::{Word, Word32Cell, WordCell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -37,19 +37,19 @@ use halo2_proofs::{ pub(crate) struct BeginTxGadget { begin_tx: BeginTxHelperGadget, tx: TxDataGadget, - tx_caller_address_is_zero: IsZeroWordGadget>, + tx_caller_address_is_zero: IsZeroWordGadget>, call_callee_address: AccountAddress, reversion_info: ReversionInfo, sufficient_gas_left: RangeCheckGadget, transfer_with_gas_fee: TransferWithGasFeeGadget, - code_hash: WordCell, - is_empty_code_hash: IsEqualWordGadget>, Word>>, + code_hash: WordLoHiCell, + is_empty_code_hash: IsEqualWordGadget>, WordLoHi>>, caller_nonce_hash_bytes: Word32Cell, create: ContractCreateGadget, - callee_not_exists: IsZeroWordGadget>, + callee_not_exists: IsZeroWordGadget>, is_caller_callee_equal: Cell, // EIP-3651 (Warm COINBASE) - coinbase: WordCell, + coinbase: WordLoHiCell, // Caller, callee and a list addresses are added to the access list before // coinbase, and may be duplicate. // @@ -74,7 +74,7 @@ impl ExecutionGadget for BeginTxGadget { cb.call_context_lookup_write( Some(call_id.expr()), CallContextFieldTag::IsSuccess, - Word::from_lo_unchecked(reversion_info.is_persistent()), + WordLoHi::from_lo_unchecked(reversion_info.is_persistent()), ); // rwc_delta += 1 // Check gas_left is sufficient @@ -102,8 +102,8 @@ impl ExecutionGadget for BeginTxGadget { cb.account_write( tx.caller_address.to_word(), AccountFieldTag::Nonce, - Word::from_lo_unchecked(tx.nonce.expr() + 1.expr()), - Word::from_lo_unchecked(tx.nonce.expr()), + WordLoHi::from_lo_unchecked(tx.nonce.expr() + 1.expr()), + WordLoHi::from_lo_unchecked(tx.nonce.expr()), None, ); // rwc_delta += 1 @@ -111,7 +111,7 @@ impl ExecutionGadget for BeginTxGadget { for addr in 1..=PRECOMPILE_COUNT { cb.account_access_list_write_unchecked( tx_id.expr(), - Word::new([addr.expr(), 0.expr()]), + WordLoHi::new([addr.expr(), 0.expr()]), 1.expr(), 0.expr(), None, @@ -221,12 +221,12 @@ impl ExecutionGadget for BeginTxGadget { cb.account_write( call_callee_address.to_word(), AccountFieldTag::Nonce, - Word::one(), - Word::zero(), + WordLoHi::one(), + WordLoHi::zero(), Some(&mut reversion_info), ); for (field_tag, value) in [ - (CallContextFieldTag::Depth, Word::one()), + (CallContextFieldTag::Depth, WordLoHi::one()), ( CallContextFieldTag::CallerAddress, tx.caller_address.to_word(), @@ -235,24 +235,24 @@ impl ExecutionGadget for BeginTxGadget { CallContextFieldTag::CalleeAddress, call_callee_address.to_word(), ), - (CallContextFieldTag::CallDataOffset, Word::zero()), + (CallContextFieldTag::CallDataOffset, WordLoHi::zero()), ( CallContextFieldTag::CallDataLength, - Word::from_lo_unchecked(tx.call_data_length.expr()), + WordLoHi::from_lo_unchecked(tx.call_data_length.expr()), ), (CallContextFieldTag::Value, tx.value.to_word()), - (CallContextFieldTag::IsStatic, Word::zero()), - (CallContextFieldTag::LastCalleeId, Word::zero()), + (CallContextFieldTag::IsStatic, WordLoHi::zero()), + (CallContextFieldTag::LastCalleeId, WordLoHi::zero()), ( CallContextFieldTag::LastCalleeReturnDataOffset, - Word::zero(), + WordLoHi::zero(), ), ( CallContextFieldTag::LastCalleeReturnDataLength, - Word::zero(), + WordLoHi::zero(), ), - (CallContextFieldTag::IsRoot, Word::one()), - (CallContextFieldTag::IsCreate, Word::one()), + (CallContextFieldTag::IsRoot, WordLoHi::one()), + (CallContextFieldTag::IsCreate, WordLoHi::one()), ( CallContextFieldTag::CodeHash, cb.curr.state.code_hash.to_word(), @@ -349,7 +349,7 @@ impl ExecutionGadget for BeginTxGadget { |cb| { // Setup first call's context. for (field_tag, value) in [ - (CallContextFieldTag::Depth, Word::one()), + (CallContextFieldTag::Depth, WordLoHi::one()), ( CallContextFieldTag::CallerAddress, tx.caller_address.to_word(), @@ -358,26 +358,26 @@ impl ExecutionGadget for BeginTxGadget { CallContextFieldTag::CalleeAddress, tx.callee_address.to_word(), ), - (CallContextFieldTag::CallDataOffset, Word::zero()), + (CallContextFieldTag::CallDataOffset, WordLoHi::zero()), ( CallContextFieldTag::CallDataLength, - Word::from_lo_unchecked(tx.call_data_length.expr()), + WordLoHi::from_lo_unchecked(tx.call_data_length.expr()), ), (CallContextFieldTag::Value, tx.value.to_word()), - (CallContextFieldTag::IsStatic, Word::zero()), - (CallContextFieldTag::LastCalleeId, Word::zero()), + (CallContextFieldTag::IsStatic, WordLoHi::zero()), + (CallContextFieldTag::LastCalleeId, WordLoHi::zero()), ( CallContextFieldTag::LastCalleeReturnDataOffset, - Word::zero(), + WordLoHi::zero(), ), ( CallContextFieldTag::LastCalleeReturnDataLength, - Word::zero(), + WordLoHi::zero(), ), - (CallContextFieldTag::IsRoot, Word::one()), + (CallContextFieldTag::IsRoot, WordLoHi::one()), ( CallContextFieldTag::IsCreate, - Word::from_lo_unchecked(tx.is_create.expr()), + WordLoHi::from_lo_unchecked(tx.is_create.expr()), ), (CallContextFieldTag::CodeHash, code_hash.to_word()), ] { diff --git a/zkevm-circuits/src/evm_circuit/execution/block_ctx.rs b/zkevm-circuits/src/evm_circuit/execution/block_ctx.rs index f3026c5202..b247438a2d 100644 --- a/zkevm-circuits/src/evm_circuit/execution/block_ctx.rs +++ b/zkevm-circuits/src/evm_circuit/execution/block_ctx.rs @@ -10,7 +10,7 @@ use crate::{ }, table::BlockContextFieldTag, util::{ - word::{WordCell, WordExpr}, + word::{WordExpr, WordLoHiCell}, Expr, }, }; @@ -23,7 +23,7 @@ use super::ExecutionGadget; #[derive(Clone, Debug)] pub(crate) struct BlockCtxGadget { same_context: SameContextGadget, - value: WordCell, + value: WordLoHiCell, } impl ExecutionGadget for BlockCtxGadget { diff --git a/zkevm-circuits/src/evm_circuit/execution/blockhash.rs b/zkevm-circuits/src/evm_circuit/execution/blockhash.rs index 8097169646..ea37a199b7 100644 --- a/zkevm-circuits/src/evm_circuit/execution/blockhash.rs +++ b/zkevm-circuits/src/evm_circuit/execution/blockhash.rs @@ -11,7 +11,7 @@ use crate::{ Transition::Delta, }, math_gadget::LtGadget, - CachedRegion, Cell, Word, + CachedRegion, Cell, WordLoHi, }, witness::{Block, Call, ExecStep, Transaction}, }, @@ -28,7 +28,7 @@ pub(crate) struct BlockHashGadget { same_context: SameContextGadget, block_number: WordByteCapGadget, current_block_number: Cell, - block_hash: Word>, + block_hash: WordLoHi>, diff_lt: LtGadget, } @@ -42,7 +42,7 @@ impl ExecutionGadget for BlockHashGadget { cb.block_lookup( BlockContextFieldTag::Number.expr(), None, - Word::from_lo_unchecked(current_block_number.expr()), + WordLoHi::from_lo_unchecked(current_block_number.expr()), ); let block_number = WordByteCapGadget::construct(cb, current_block_number.expr()); diff --git a/zkevm-circuits/src/evm_circuit/execution/byte.rs b/zkevm-circuits/src/evm_circuit/execution/byte.rs index 532c7c61da..dd3b89ac68 100644 --- a/zkevm-circuits/src/evm_circuit/execution/byte.rs +++ b/zkevm-circuits/src/evm_circuit/execution/byte.rs @@ -11,7 +11,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{Word, Word32Cell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi}, Expr, }, }; @@ -70,7 +70,7 @@ impl ExecutionGadget for ByteGadget { // it only uses the LSB of a word. cb.stack_pop(index.to_word()); cb.stack_pop(value.to_word()); - cb.stack_push(Word::from_lo_unchecked(selected_byte)); + cb.stack_push(WordLoHi::from_lo_unchecked(selected_byte)); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs b/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs index f7d9a76240..f0d5155cac 100644 --- a/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs @@ -19,7 +19,7 @@ use crate::{ }, table::CallContextFieldTag, util::{ - word::{Word, WordExpr}, + word::{WordExpr, WordLoHi}, Expr, }, }; @@ -69,12 +69,12 @@ impl ExecutionGadget for CallDataCopyGadget { cb.call_context_lookup_read( None, CallContextFieldTag::TxId, - Word::from_lo_unchecked(src_id.expr()), + WordLoHi::from_lo_unchecked(src_id.expr()), ); cb.call_context_lookup_read( None, CallContextFieldTag::CallDataLength, - Word::from_lo_unchecked(call_data_length.expr()), + WordLoHi::from_lo_unchecked(call_data_length.expr()), ); cb.require_zero( "call_data_offset == 0 in the root call", @@ -85,17 +85,17 @@ impl ExecutionGadget for CallDataCopyGadget { cb.call_context_lookup_read( None, CallContextFieldTag::CallerId, - Word::from_lo_unchecked(src_id.expr()), + WordLoHi::from_lo_unchecked(src_id.expr()), ); cb.call_context_lookup_read( None, CallContextFieldTag::CallDataLength, - Word::from_lo_unchecked(call_data_length.expr()), + WordLoHi::from_lo_unchecked(call_data_length.expr()), ); cb.call_context_lookup_read( None, CallContextFieldTag::CallDataOffset, - Word::from_lo_unchecked(call_data_offset.expr()), + WordLoHi::from_lo_unchecked(call_data_offset.expr()), ); }); @@ -127,9 +127,9 @@ impl ExecutionGadget for CallDataCopyGadget { let src_addr_end = call_data_offset.expr() + call_data_length.expr(); cb.copy_table_lookup( - Word::from_lo_unchecked(src_id.expr()), + WordLoHi::from_lo_unchecked(src_id.expr()), src_tag, - Word::from_lo_unchecked(cb.curr.state.call_id.expr()), + WordLoHi::from_lo_unchecked(cb.curr.state.call_id.expr()), CopyDataType::Memory.expr(), src_addr, src_addr_end, diff --git a/zkevm-circuits/src/evm_circuit/execution/calldataload.rs b/zkevm-circuits/src/evm_circuit/execution/calldataload.rs index ff0890bb8f..bc133db5c2 100644 --- a/zkevm-circuits/src/evm_circuit/execution/calldataload.rs +++ b/zkevm-circuits/src/evm_circuit/execution/calldataload.rs @@ -23,7 +23,7 @@ use crate::{ }, table::{CallContextFieldTag, TxContextFieldTag}, util::{ - word::{Word, Word32, WordExpr}, + word::{Word32, WordExpr, WordLoHi}, Expr, }, }; @@ -76,12 +76,12 @@ impl ExecutionGadget for CallDataLoadGadget { cb.call_context_lookup_read( None, CallContextFieldTag::TxId, - Word::from_lo_unchecked(src_id.expr()), + WordLoHi::from_lo_unchecked(src_id.expr()), ); cb.call_context_lookup_read( None, CallContextFieldTag::CallDataLength, - Word::from_lo_unchecked(call_data_length.expr()), + WordLoHi::from_lo_unchecked(call_data_length.expr()), ); cb.require_equal( "if is_root then call_data_offset == 0", @@ -100,17 +100,17 @@ impl ExecutionGadget for CallDataLoadGadget { cb.call_context_lookup_read( None, CallContextFieldTag::CallerId, - Word::from_lo_unchecked(src_id.expr()), + WordLoHi::from_lo_unchecked(src_id.expr()), ); cb.call_context_lookup_read( None, CallContextFieldTag::CallDataLength, - Word::from_lo_unchecked(call_data_length.expr()), + WordLoHi::from_lo_unchecked(call_data_length.expr()), ); cb.call_context_lookup_read( None, CallContextFieldTag::CallDataOffset, - Word::from_lo_unchecked(call_data_offset.expr()), + WordLoHi::from_lo_unchecked(call_data_offset.expr()), ); }, ); @@ -141,7 +141,7 @@ impl ExecutionGadget for CallDataLoadGadget { src_id.expr(), TxContextFieldTag::CallData, Some(src_addr.expr() + idx.expr()), - Word::from_lo_unchecked(buffer_reader.byte(idx)), + WordLoHi::from_lo_unchecked(buffer_reader.byte(idx)), ); }, ); diff --git a/zkevm-circuits/src/evm_circuit/execution/calldatasize.rs b/zkevm-circuits/src/evm_circuit/execution/calldatasize.rs index 311365feb3..1ead801063 100644 --- a/zkevm-circuits/src/evm_circuit/execution/calldatasize.rs +++ b/zkevm-circuits/src/evm_circuit/execution/calldatasize.rs @@ -11,7 +11,7 @@ use crate::{ }, table::CallContextFieldTag, util::{ - word::{WordCell, WordExpr}, + word::{WordExpr, WordLoHiCell}, Expr, }, }; @@ -22,7 +22,7 @@ use halo2_proofs::plonk::Error; #[derive(Clone, Debug)] pub(crate) struct CallDataSizeGadget { same_context: SameContextGadget, - call_data_size: WordCell, + call_data_size: WordLoHiCell, } impl ExecutionGadget for CallDataSizeGadget { diff --git a/zkevm-circuits/src/evm_circuit/execution/caller.rs b/zkevm-circuits/src/evm_circuit/execution/caller.rs index d1c6819e5e..6a3839ab34 100644 --- a/zkevm-circuits/src/evm_circuit/execution/caller.rs +++ b/zkevm-circuits/src/evm_circuit/execution/caller.rs @@ -11,7 +11,7 @@ use crate::{ }, table::CallContextFieldTag, util::{ - word::{WordCell, WordExpr}, + word::{WordExpr, WordLoHiCell}, Expr, }, }; @@ -22,7 +22,7 @@ use halo2_proofs::plonk::Error; #[derive(Clone, Debug)] pub(crate) struct CallerGadget { same_context: SameContextGadget, - caller_address: WordCell, + caller_address: WordLoHiCell, } impl ExecutionGadget for CallerGadget { diff --git a/zkevm-circuits/src/evm_circuit/execution/callop.rs b/zkevm-circuits/src/evm_circuit/execution/callop.rs index f6b6829293..4af82c36bb 100644 --- a/zkevm-circuits/src/evm_circuit/execution/callop.rs +++ b/zkevm-circuits/src/evm_circuit/execution/callop.rs @@ -16,13 +16,13 @@ use crate::{ memory_gadget::{CommonMemoryAddressGadget, MemoryAddressGadget}, not, or, precompile_gadget::PrecompileGadget, - rlc, select, CachedRegion, Cell, StepRws, Word, + rlc, select, CachedRegion, Cell, StepRws, }, witness::{Block, Call, ExecStep, Transaction}, }, table::{AccountFieldTag, CallContextFieldTag}, util::{ - word::{WordCell, WordExpr}, + word::{WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -50,18 +50,18 @@ pub(crate) struct CallOpGadget { is_staticcall: IsZeroGadget, tx_id: Cell, reversion_info: ReversionInfo, - current_callee_address: WordCell, - current_caller_address: WordCell, + current_callee_address: WordLoHiCell, + current_caller_address: WordLoHiCell, is_static: Cell, depth: Cell, call: CommonCallGadget, true>, - current_value: Word>, + current_value: WordLoHi>, is_warm: Cell, is_warm_prev: Cell, callee_reversion_info: ReversionInfo, transfer: TransferGadget, // current handling Call* opcode's caller balance - caller_balance: Word>, + caller_balance: WordLoHi>, // check if insufficient balance case is_insufficient_balance: LtWordGadget, is_depth_ok: LtGadget, @@ -138,12 +138,12 @@ impl ExecutionGadget for CallOpGadget { ); }); - let caller_address = Word::select( + let caller_address = WordLoHi::select( is_delegatecall.expr(), current_caller_address.to_word(), current_callee_address.to_word(), ); - let callee_address = Word::select( + let callee_address = WordLoHi::select( is_callcode.expr() + is_delegatecall.expr(), current_callee_address.to_word(), call_gadget.callee_address.to_word(), @@ -323,7 +323,7 @@ impl ExecutionGadget for CallOpGadget { cb.call_context_lookup_write( Some(callee_call_id.expr()), CallContextFieldTag::IsSuccess, - Word::from_lo_unchecked(call_gadget.is_success.expr()), + WordLoHi::from_lo_unchecked(call_gadget.is_success.expr()), ); cb.call_context_lookup_write( Some(callee_call_id.expr()), @@ -352,7 +352,7 @@ impl ExecutionGadget for CallOpGadget { cb.call_context_lookup_write( Some(callee_call_id.expr()), field_tag, - Word::from_lo_unchecked(value), + WordLoHi::from_lo_unchecked(value), ); } @@ -386,7 +386,11 @@ impl ExecutionGadget for CallOpGadget { precompile_return_length.expr(), ), ] { - cb.call_context_lookup_write(None, field_tag, Word::from_lo_unchecked(value)); + cb.call_context_lookup_write( + None, + field_tag, + WordLoHi::from_lo_unchecked(value), + ); } // copy table lookup to verify the copying of bytes: @@ -396,9 +400,9 @@ impl ExecutionGadget for CallOpGadget { cb.condition(call_gadget.cd_address.has_length(), |cb| { let precompile_input_bytes_rlc = cb.query_cell_phase2(); cb.copy_table_lookup( - Word::from_lo_unchecked(cb.curr.state.call_id.expr()), + WordLoHi::from_lo_unchecked(cb.curr.state.call_id.expr()), CopyDataType::Memory.expr(), - Word::from_lo_unchecked(callee_call_id.expr()), + WordLoHi::from_lo_unchecked(callee_call_id.expr()), CopyDataType::RlcAcc.expr(), call_gadget.cd_address.offset(), call_gadget.cd_address.offset() + precompile_input_len.expr(), @@ -421,9 +425,9 @@ impl ExecutionGadget for CallOpGadget { |cb| { let precompile_output_bytes_rlc = cb.query_cell_phase2(); cb.copy_table_lookup( - Word::from_lo_unchecked(callee_call_id.expr()), + WordLoHi::from_lo_unchecked(callee_call_id.expr()), CopyDataType::RlcAcc.expr(), - Word::from_lo_unchecked(callee_call_id.expr()), + WordLoHi::from_lo_unchecked(callee_call_id.expr()), CopyDataType::Memory.expr(), 0.expr(), precompile_return_length.expr(), @@ -450,9 +454,9 @@ impl ExecutionGadget for CallOpGadget { |cb| { let precompile_return_bytes_rlc = cb.query_cell_phase2(); cb.copy_table_lookup( - Word::from_lo_unchecked(callee_call_id.expr()), + WordLoHi::from_lo_unchecked(callee_call_id.expr()), CopyDataType::Memory.expr(), // refer u64::from(CopyDataType) - Word::from_lo_unchecked(cb.curr.state.call_id.expr()), + WordLoHi::from_lo_unchecked(cb.curr.state.call_id.expr()), CopyDataType::Memory.expr(), 0.expr(), precompile_return_data_copy_size.min(), @@ -536,13 +540,13 @@ impl ExecutionGadget for CallOpGadget { cb.call_context_lookup_write( None, CallContextFieldTag::LastCalleeId, - Word::from_lo_unchecked(callee_call_id.expr()), + WordLoHi::from_lo_unchecked(callee_call_id.expr()), ); for field_tag in [ CallContextFieldTag::LastCalleeReturnDataOffset, CallContextFieldTag::LastCalleeReturnDataLength, ] { - cb.call_context_lookup_write(None, field_tag, Word::zero()); + cb.call_context_lookup_write(None, field_tag, WordLoHi::zero()); } // For CALL opcode, it has an extra stack pop `value` (+1) and if the value is @@ -584,13 +588,13 @@ impl ExecutionGadget for CallOpGadget { cb.call_context_lookup_write( None, CallContextFieldTag::LastCalleeId, - Word::from_lo_unchecked(callee_call_id.expr()), + WordLoHi::from_lo_unchecked(callee_call_id.expr()), ); for field_tag in [ CallContextFieldTag::LastCalleeReturnDataOffset, CallContextFieldTag::LastCalleeReturnDataLength, ] { - cb.call_context_lookup_write(None, field_tag, Word::zero()); + cb.call_context_lookup_write(None, field_tag, WordLoHi::zero()); } cb.require_step_state_transition(StepStateTransition { @@ -638,7 +642,11 @@ impl ExecutionGadget for CallOpGadget { cb.curr.state.reversible_write_counter.expr() + 1.expr(), ), ] { - cb.call_context_lookup_write(None, field_tag, Word::from_lo_unchecked(value)); + cb.call_context_lookup_write( + None, + field_tag, + WordLoHi::from_lo_unchecked(value), + ); } // Setup next call's context. @@ -647,37 +655,37 @@ impl ExecutionGadget for CallOpGadget { for (field_tag, value) in [ ( CallContextFieldTag::CallerId, - Word::from_lo_unchecked(cb.curr.state.call_id.expr()), + WordLoHi::from_lo_unchecked(cb.curr.state.call_id.expr()), ), ( CallContextFieldTag::TxId, - Word::from_lo_unchecked(tx_id.expr()), + WordLoHi::from_lo_unchecked(tx_id.expr()), ), ( CallContextFieldTag::Depth, - Word::from_lo_unchecked(depth.expr() + 1.expr()), + WordLoHi::from_lo_unchecked(depth.expr() + 1.expr()), ), (CallContextFieldTag::CallerAddress, caller_address), (CallContextFieldTag::CalleeAddress, callee_address), ( CallContextFieldTag::CallDataOffset, - Word::from_lo_unchecked(cd_address.offset()), + WordLoHi::from_lo_unchecked(cd_address.offset()), ), ( CallContextFieldTag::CallDataLength, - Word::from_lo_unchecked(cd_address.length()), + WordLoHi::from_lo_unchecked(cd_address.length()), ), ( CallContextFieldTag::ReturnDataOffset, - Word::from_lo_unchecked(rd_address.offset()), + WordLoHi::from_lo_unchecked(rd_address.offset()), ), ( CallContextFieldTag::ReturnDataLength, - Word::from_lo_unchecked(rd_address.length()), + WordLoHi::from_lo_unchecked(rd_address.length()), ), ( CallContextFieldTag::Value, - Word::select( + WordLoHi::select( is_delegatecall.expr(), current_value.to_word(), call_gadget.value.to_word(), @@ -685,23 +693,26 @@ impl ExecutionGadget for CallOpGadget { ), ( CallContextFieldTag::IsSuccess, - Word::from_lo_unchecked(call_gadget.is_success.expr()), + WordLoHi::from_lo_unchecked(call_gadget.is_success.expr()), ), ( CallContextFieldTag::IsStatic, - Word::from_lo_unchecked(or::expr([is_static.expr(), is_staticcall.expr()])), + WordLoHi::from_lo_unchecked(or::expr([ + is_static.expr(), + is_staticcall.expr(), + ])), ), - (CallContextFieldTag::LastCalleeId, Word::zero()), + (CallContextFieldTag::LastCalleeId, WordLoHi::zero()), ( CallContextFieldTag::LastCalleeReturnDataOffset, - Word::zero(), + WordLoHi::zero(), ), ( CallContextFieldTag::LastCalleeReturnDataLength, - Word::zero(), + WordLoHi::zero(), ), - (CallContextFieldTag::IsRoot, Word::zero()), - (CallContextFieldTag::IsCreate, Word::zero()), + (CallContextFieldTag::IsRoot, WordLoHi::zero()), + (CallContextFieldTag::IsCreate, WordLoHi::zero()), ( CallContextFieldTag::CodeHash, call_gadget.callee_code_hash.to_word(), diff --git a/zkevm-circuits/src/evm_circuit/execution/callvalue.rs b/zkevm-circuits/src/evm_circuit/execution/callvalue.rs index 978452a58d..f590984d77 100644 --- a/zkevm-circuits/src/evm_circuit/execution/callvalue.rs +++ b/zkevm-circuits/src/evm_circuit/execution/callvalue.rs @@ -11,7 +11,7 @@ use crate::{ }, table::CallContextFieldTag, util::{ - word::{WordCell, WordExpr}, + word::{WordExpr, WordLoHiCell}, Expr, }, }; @@ -24,7 +24,7 @@ pub(crate) struct CallValueGadget { same_context: SameContextGadget, // Value in rw_table->stack_op and call_context->call_value are both RLC // encoded, so no need to decode. - call_value: WordCell, + call_value: WordLoHiCell, } impl ExecutionGadget for CallValueGadget { diff --git a/zkevm-circuits/src/evm_circuit/execution/chainid.rs b/zkevm-circuits/src/evm_circuit/execution/chainid.rs index 920877f017..c355c47c47 100644 --- a/zkevm-circuits/src/evm_circuit/execution/chainid.rs +++ b/zkevm-circuits/src/evm_circuit/execution/chainid.rs @@ -11,7 +11,7 @@ use crate::{ }, table::BlockContextFieldTag, util::{ - word::{WordCell, WordExpr}, + word::{WordExpr, WordLoHiCell}, Expr, }, }; @@ -22,7 +22,7 @@ use halo2_proofs::plonk::Error; #[derive(Clone, Debug)] pub(crate) struct ChainIdGadget { same_context: SameContextGadget, - chain_id: WordCell, + chain_id: WordLoHiCell, } impl ExecutionGadget for ChainIdGadget { diff --git a/zkevm-circuits/src/evm_circuit/execution/codecopy.rs b/zkevm-circuits/src/evm_circuit/execution/codecopy.rs index c310e11281..45c2fc0360 100644 --- a/zkevm-circuits/src/evm_circuit/execution/codecopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/codecopy.rs @@ -20,7 +20,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{Word, WordExpr}, + word::{WordExpr, WordLoHi}, Expr, }, }; @@ -66,7 +66,7 @@ impl ExecutionGadget for CodeCopyGadget { // Pop items from stack. cb.stack_pop(dst_memory_offset.to_word()); cb.stack_pop(code_offset.original_word().to_word()); - cb.stack_pop(Word::from_lo_unchecked(length.expr())); + cb.stack_pop(WordLoHi::from_lo_unchecked(length.expr())); // Construct memory address in the destionation (memory) to which we copy code. let dst_memory_addr = MemoryAddressGadget::construct(cb, dst_memory_offset, length); @@ -99,7 +99,7 @@ impl ExecutionGadget for CodeCopyGadget { cb.copy_table_lookup( code_hash.to_word(), CopyDataType::Bytecode.expr(), - Word::from_lo_unchecked(cb.curr.state.call_id.expr()), + WordLoHi::from_lo_unchecked(cb.curr.state.call_id.expr()), CopyDataType::Memory.expr(), src_addr, code_size.expr(), diff --git a/zkevm-circuits/src/evm_circuit/execution/comparator.rs b/zkevm-circuits/src/evm_circuit/execution/comparator.rs index efcb877992..5dcfbca0b8 100644 --- a/zkevm-circuits/src/evm_circuit/execution/comparator.rs +++ b/zkevm-circuits/src/evm_circuit/execution/comparator.rs @@ -11,7 +11,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{Word, WordCell, WordExpr}, + word::{WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -21,12 +21,12 @@ use halo2_proofs::{circuit::Value, plonk::Error}; #[derive(Clone, Debug)] pub(crate) struct ComparatorGadget { same_context: SameContextGadget, - a: WordCell, - b: WordCell, + a: WordLoHiCell, + b: WordLoHiCell, result: Cell, is_eq: IsEqualGadget, is_gt: IsEqualGadget, - word_comparison: CmpWordsGadget, WordCell>, + word_comparison: CmpWordsGadget, WordLoHiCell>, } impl ExecutionGadget for ComparatorGadget { @@ -62,9 +62,9 @@ impl ExecutionGadget for ComparatorGadget { // When swap is enabled we swap stack places between a and b. // We can push result here directly because // it only uses the LSB of a word. - cb.stack_pop(Word::select(is_gt.expr(), b.to_word(), a.to_word())); - cb.stack_pop(Word::select(is_gt.expr(), a.to_word(), b.to_word())); - cb.stack_push(Word::from_lo_unchecked(result.expr())); + cb.stack_pop(WordLoHi::select(is_gt.expr(), b.to_word(), a.to_word())); + cb.stack_pop(WordLoHi::select(is_gt.expr(), a.to_word(), b.to_word())); + cb.stack_push(WordLoHi::from_lo_unchecked(result.expr())); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/create.rs b/zkevm-circuits/src/evm_circuit/execution/create.rs index b70c3a088e..61b842308d 100644 --- a/zkevm-circuits/src/evm_circuit/execution/create.rs +++ b/zkevm-circuits/src/evm_circuit/execution/create.rs @@ -19,13 +19,13 @@ use crate::{ memory_gadget::{ CommonMemoryAddressGadget, MemoryAddressGadget, MemoryExpansionGadget, }, - not, AccountAddress, CachedRegion, Cell, StepRws, Word, WordExpr, + not, AccountAddress, CachedRegion, Cell, StepRws, }, witness::{Block, Call, ExecStep, Transaction}, }, table::{AccountFieldTag, CallContextFieldTag}, util::{ - word::{Word32Cell, WordCell}, + word::{Word32Cell, WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -58,11 +58,11 @@ pub(crate) struct CreateGadget, value: Word32Cell, - caller_balance: WordCell, + caller_balance: WordLoHiCell, callee_reversion_info: ReversionInfo, callee_nonce: Cell, - prev_code_hash: WordCell, - prev_code_hash_is_zero: IsZeroWordGadget>>, + prev_code_hash: WordLoHiCell, + prev_code_hash_is_zero: IsZeroWordGadget>>, transfer: TransferGadget, create: ContractCreateGadget, @@ -74,7 +74,7 @@ pub(crate) struct CreateGadget, is_insufficient_balance: LtWordGadget, is_nonce_in_range: LtGadget, - not_address_collision: IsZeroWordGadget>>, + not_address_collision: IsZeroWordGadget>>, memory_expansion: MemoryExpansionGadget, gas_left: ConstantDivisionGadget, @@ -139,7 +139,7 @@ impl ExecutionGadget< cb.account_read( create.caller_address(), AccountFieldTag::Nonce, - Word::from_lo_unchecked(caller_nonce.expr()), + WordLoHi::from_lo_unchecked(caller_nonce.expr()), ); // Pre-check: call depth, user's nonce and user's balance @@ -182,8 +182,8 @@ impl ExecutionGadget< cb.account_write( create.caller_address(), AccountFieldTag::Nonce, - Word::from_lo_unchecked(caller_nonce.expr() + 1.expr()), - Word::from_lo_unchecked(caller_nonce.expr()), + WordLoHi::from_lo_unchecked(caller_nonce.expr() + 1.expr()), + WordLoHi::from_lo_unchecked(caller_nonce.expr()), Some(&mut reversion_info), ); @@ -214,14 +214,14 @@ impl ExecutionGadget< cb.account_read( contract_addr.to_word(), AccountFieldTag::Nonce, - Word::from_lo_unchecked(callee_nonce.expr()), + WordLoHi::from_lo_unchecked(callee_nonce.expr()), ); }); ( prev_code_hash_is_zero, IsZeroWordGadget::construct( cb, - &Word::from_lo_unchecked(callee_nonce.expr()).add_unchecked( + &WordLoHi::from_lo_unchecked(callee_nonce.expr()).add_unchecked( prev_code_hash_word.clone().mul_unchecked( prev_code_hash_word.sub_unchecked(cb.empty_code_hash()), ), @@ -233,25 +233,27 @@ impl ExecutionGadget< for (field_tag, value) in [ ( CallContextFieldTag::ProgramCounter, - Word::from_lo_unchecked(cb.curr.state.program_counter.expr() + 1.expr()), + WordLoHi::from_lo_unchecked(cb.curr.state.program_counter.expr() + 1.expr()), ), ( CallContextFieldTag::StackPointer, - Word::from_lo_unchecked( + WordLoHi::from_lo_unchecked( cb.curr.state.stack_pointer.expr() + 2.expr() + is_create2.expr(), ), ), ( CallContextFieldTag::GasLeft, - Word::from_lo_unchecked(gas_left.quotient()), + WordLoHi::from_lo_unchecked(gas_left.quotient()), ), ( CallContextFieldTag::MemorySize, - Word::from_lo_unchecked(memory_expansion.next_memory_word_size()), + WordLoHi::from_lo_unchecked(memory_expansion.next_memory_word_size()), ), ( CallContextFieldTag::ReversibleWriteCounter, - Word::from_lo_unchecked(cb.curr.state.reversible_write_counter.expr() + 2.expr()), + WordLoHi::from_lo_unchecked( + cb.curr.state.reversible_write_counter.expr() + 2.expr(), + ), ), ] { cb.call_context_lookup_write(None, field_tag, value); @@ -266,7 +268,7 @@ impl ExecutionGadget< // the init code is being copied from memory to bytecode, so a copy table lookup // to verify that the associated fields for the copy event. cb.copy_table_lookup( - Word::from_lo_unchecked(current_call_id.expr()), + WordLoHi::from_lo_unchecked(current_call_id.expr()), CopyDataType::Memory.expr(), create.code_hash(), CopyDataType::Bytecode.expr(), @@ -290,13 +292,13 @@ impl ExecutionGadget< cb.call_context_lookup_write( None, CallContextFieldTag::LastCalleeId, - Word::from_lo_unchecked(callee_call_id.expr()), + WordLoHi::from_lo_unchecked(callee_call_id.expr()), ); for field_tag in [ CallContextFieldTag::LastCalleeReturnDataOffset, CallContextFieldTag::LastCalleeReturnDataLength, ] { - cb.call_context_lookup_write(None, field_tag, Word::zero()); + cb.call_context_lookup_write(None, field_tag, WordLoHi::zero()); } cb.require_step_state_transition(StepStateTransition { @@ -342,8 +344,8 @@ impl ExecutionGadget< cb.account_write( contract_addr.to_word(), AccountFieldTag::Nonce, - Word::one(), - Word::zero(), + WordLoHi::one(), + WordLoHi::zero(), Some(&mut callee_reversion_info), ); @@ -351,43 +353,43 @@ impl ExecutionGadget< for (field_tag, value) in [ ( CallContextFieldTag::CallerId, - Word::from_lo_unchecked(current_call_id.expr()), + WordLoHi::from_lo_unchecked(current_call_id.expr()), ), ( CallContextFieldTag::IsSuccess, - Word::from_lo_unchecked(is_success.expr()), + WordLoHi::from_lo_unchecked(is_success.expr()), ), ( CallContextFieldTag::IsPersistent, - Word::from_lo_unchecked(callee_reversion_info.is_persistent()), + WordLoHi::from_lo_unchecked(callee_reversion_info.is_persistent()), ), ( CallContextFieldTag::TxId, - Word::from_lo_unchecked(tx_id.expr()), + WordLoHi::from_lo_unchecked(tx_id.expr()), ), (CallContextFieldTag::CallerAddress, create.caller_address()), (CallContextFieldTag::CalleeAddress, contract_addr.to_word()), ( CallContextFieldTag::RwCounterEndOfReversion, - Word::from_lo_unchecked( + WordLoHi::from_lo_unchecked( callee_reversion_info.rw_counter_end_of_reversion(), ), ), ( CallContextFieldTag::Depth, - Word::from_lo_unchecked(depth.expr() + 1.expr()), + WordLoHi::from_lo_unchecked(depth.expr() + 1.expr()), ), ( CallContextFieldTag::IsRoot, - Word::from_lo_unchecked(false.expr()), + WordLoHi::from_lo_unchecked(false.expr()), ), ( CallContextFieldTag::IsStatic, - Word::from_lo_unchecked(false.expr()), + WordLoHi::from_lo_unchecked(false.expr()), ), ( CallContextFieldTag::IsCreate, - Word::from_lo_unchecked(true.expr()), + WordLoHi::from_lo_unchecked(true.expr()), ), (CallContextFieldTag::CodeHash, create.code_hash()), (CallContextFieldTag::Value, value.to_word()), @@ -414,13 +416,13 @@ impl ExecutionGadget< cb.call_context_lookup_write( None, CallContextFieldTag::LastCalleeId, - Word::from_lo_unchecked(callee_call_id.expr()), + WordLoHi::from_lo_unchecked(callee_call_id.expr()), ); for field_tag in [ CallContextFieldTag::LastCalleeReturnDataOffset, CallContextFieldTag::LastCalleeReturnDataLength, ] { - cb.call_context_lookup_write(None, field_tag, Word::zero()); + cb.call_context_lookup_write(None, field_tag, WordLoHi::zero()); } cb.require_step_state_transition(StepStateTransition { rw_counter: Delta(cb.rw_counter_offset()), @@ -457,13 +459,13 @@ impl ExecutionGadget< cb.call_context_lookup_write( None, CallContextFieldTag::LastCalleeId, - Word::from_lo_unchecked(callee_call_id.expr()), + WordLoHi::from_lo_unchecked(callee_call_id.expr()), ); for field_tag in [ CallContextFieldTag::LastCalleeReturnDataOffset, CallContextFieldTag::LastCalleeReturnDataLength, ] { - cb.call_context_lookup_write(None, field_tag, Word::zero()); + cb.call_context_lookup_write(None, field_tag, WordLoHi::zero()); } cb.require_step_state_transition(StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/dummy.rs b/zkevm-circuits/src/evm_circuit/execution/dummy.rs index 425aa1a443..ad85b35bc4 100644 --- a/zkevm-circuits/src/evm_circuit/execution/dummy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/dummy.rs @@ -7,15 +7,15 @@ use crate::{ util::{constraint_builder::EVMConstraintBuilder, CachedRegion}, witness::{Block, Call, ExecStep, Transaction}, }, - util::word::{WordCell, WordExpr}, + util::word::{WordExpr, WordLoHiCell}, }; use eth_types::Field; use halo2_proofs::plonk::Error; #[derive(Clone, Debug)] pub(crate) struct DummyGadget { - pops: [WordCell; N_POP], - pushes: [WordCell; N_PUSH], + pops: [WordLoHiCell; N_POP], + pushes: [WordLoHiCell; N_PUSH], _marker: PhantomData, } @@ -27,8 +27,8 @@ impl const EXECUTION_STATE: ExecutionState = S; fn configure(cb: &mut EVMConstraintBuilder) -> Self { - let pops: [WordCell; N_POP] = [(); N_POP].map(|_| cb.query_word_unchecked()); - let pushes: [WordCell; N_PUSH] = [(); N_PUSH].map(|_| cb.query_word_unchecked()); + let pops: [WordLoHiCell; N_POP] = [(); N_POP].map(|_| cb.query_word_unchecked()); + let pushes: [WordLoHiCell; N_PUSH] = [(); N_PUSH].map(|_| cb.query_word_unchecked()); for pop in pops.iter() { cb.stack_pop(pop.to_word()); } diff --git a/zkevm-circuits/src/evm_circuit/execution/dup.rs b/zkevm-circuits/src/evm_circuit/execution/dup.rs index 49c2a58a0a..71a8c8d7e8 100644 --- a/zkevm-circuits/src/evm_circuit/execution/dup.rs +++ b/zkevm-circuits/src/evm_circuit/execution/dup.rs @@ -10,7 +10,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{WordCell, WordExpr}, + word::{WordExpr, WordLoHiCell}, Expr, }, }; @@ -20,7 +20,7 @@ use halo2_proofs::plonk::Error; #[derive(Clone, Debug)] pub(crate) struct DupGadget { same_context: SameContextGadget, - value: WordCell, + value: WordLoHiCell, } impl ExecutionGadget for DupGadget { diff --git a/zkevm-circuits/src/evm_circuit/execution/end_block.rs b/zkevm-circuits/src/evm_circuit/execution/end_block.rs index 848f58685c..51e35e2d5e 100644 --- a/zkevm-circuits/src/evm_circuit/execution/end_block.rs +++ b/zkevm-circuits/src/evm_circuit/execution/end_block.rs @@ -12,7 +12,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, table::{CallContextFieldTag, TxContextFieldTag}, - util::{word::Word, Expr}, + util::{word::WordLoHi, Expr}, }; use eth_types::{Field, OpsIdentity}; use gadgets::util::select; @@ -59,7 +59,7 @@ impl ExecutionGadget for EndBlockGadget { cb.call_context_lookup_read( None, CallContextFieldTag::TxId, - Word::from_lo_unchecked(total_txs.expr()), + WordLoHi::from_lo_unchecked(total_txs.expr()), ); }); @@ -74,7 +74,7 @@ impl ExecutionGadget for EndBlockGadget { total_txs.expr() + 1.expr(), TxContextFieldTag::CallerAddress, None, - Word::zero(), + WordLoHi::zero(), ); // Since every tx lookup done in the EVM circuit must succeed // and uses a unique tx_id, we know that at diff --git a/zkevm-circuits/src/evm_circuit/execution/end_tx.rs b/zkevm-circuits/src/evm_circuit/execution/end_tx.rs index 3e9a38150e..e8bfc5b779 100644 --- a/zkevm-circuits/src/evm_circuit/execution/end_tx.rs +++ b/zkevm-circuits/src/evm_circuit/execution/end_tx.rs @@ -17,7 +17,7 @@ use crate::{ }, table::{AccountFieldTag, BlockContextFieldTag, CallContextFieldTag, TxContextFieldTag}, util::{ - word::{Word, WordCell, WordExpr}, + word::{WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -32,13 +32,13 @@ pub(crate) struct EndTxGadget { refund: Cell, effective_refund: MinMaxGadget, mul_gas_price_by_refund: MulWordByU64Gadget, - tx_caller_address: WordCell, + tx_caller_address: WordLoHiCell, gas_fee_refund: UpdateBalanceGadget, sub_gas_price_by_base_fee: AddWordsGadget, mul_effective_tip_by_gas_used: MulWordByU64Gadget, - coinbase: WordCell, - coinbase_code_hash: WordCell, - coinbase_code_hash_is_zero: IsZeroWordGadget>, + coinbase: WordLoHiCell, + coinbase_code_hash: WordLoHiCell, + coinbase_code_hash_is_zero: IsZeroWordGadget>, coinbase_reward: TransferToGadget, is_persistent: Cell, end_tx: EndTxHelperGadget, @@ -66,7 +66,7 @@ impl ExecutionGadget for EndTxGadget { MAX_REFUND_QUOTIENT_OF_GAS_USED as u64, ); let refund = cb.query_cell(); - cb.tx_refund_read(tx_id.expr(), Word::from_lo_unchecked(refund.expr())); + cb.tx_refund_read(tx_id.expr(), WordLoHi::from_lo_unchecked(refund.expr())); let effective_refund = MinMaxGadget::construct(cb, max_refund.quotient(), refund.expr()); // Add effective_refund * tx_gas_price back to caller's balance diff --git a/zkevm-circuits/src/evm_circuit/execution/error_invalid_jump.rs b/zkevm-circuits/src/evm_circuit/execution/error_invalid_jump.rs index 65e81e8fc6..e5b40f5f71 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_invalid_jump.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_invalid_jump.rs @@ -12,7 +12,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{Word, WordCell, WordExpr}, + word::{WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -29,8 +29,8 @@ pub(crate) struct ErrorInvalidJumpGadget { is_code: Cell, is_jump_dest: IsEqualGadget, is_jumpi: IsEqualGadget, - condition: WordCell, - is_condition_zero: IsZeroWordGadget>, + condition: WordLoHiCell, + is_condition_zero: IsZeroWordGadget>, common_error_gadget: CommonErrorGadget, } @@ -160,8 +160,11 @@ impl ExecutionGadget for ErrorInvalidJumpGadget { )?; self.condition.assign_u256(region, offset, condition)?; - self.is_condition_zero - .assign_value(region, offset, Value::known(Word::from(condition)))?; + self.is_condition_zero.assign_value( + region, + offset, + Value::known(WordLoHi::from(condition)), + )?; self.common_error_gadget.assign( region, diff --git a/zkevm-circuits/src/evm_circuit/execution/error_oog_memory_copy.rs b/zkevm-circuits/src/evm_circuit/execution/error_oog_memory_copy.rs index 4a3b28ac96..697279a626 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_oog_memory_copy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_oog_memory_copy.rs @@ -17,7 +17,7 @@ use crate::{ }, table::CallContextFieldTag, util::{ - word::{Word, WordCell, WordExpr}, + word::{WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -39,7 +39,7 @@ pub(crate) struct ErrorOOGMemoryCopyGadget { /// Extra stack pop for `EXTCODECOPY` external_address: AccountAddress, /// Source offset - src_offset: WordCell, + src_offset: WordLoHiCell, /// Destination offset and size to copy dst_memory_addr: MemoryExpandedAddressGadget, memory_expansion: MemoryExpansionGadget, @@ -79,7 +79,7 @@ impl ExecutionGadget for ErrorOOGMemoryCopyGadget { cb.call_context_lookup_read( None, CallContextFieldTag::TxId, - Word::from_lo_unchecked(tx_id.expr()), + WordLoHi::from_lo_unchecked(tx_id.expr()), ); // Check if EXTCODECOPY external address is warm. diff --git a/zkevm-circuits/src/evm_circuit/execution/error_oog_sload_sstore.rs b/zkevm-circuits/src/evm_circuit/execution/error_oog_sload_sstore.rs index 44a6d47bf5..b0b8bc97dc 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_oog_sload_sstore.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_oog_sload_sstore.rs @@ -17,7 +17,7 @@ use crate::{ }, table::CallContextFieldTag, util::{ - word::{Word, WordCell, WordExpr}, + word::{WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -34,14 +34,14 @@ pub(crate) struct ErrorOOGSloadSstoreGadget { opcode: Cell, tx_id: Cell, is_static: Cell, - callee_address: WordCell, - key: WordCell, - value: WordCell, - value_prev: WordCell, - original_value: WordCell, + callee_address: WordLoHiCell, + key: WordLoHiCell, + value: WordLoHiCell, + value_prev: WordLoHiCell, + original_value: WordLoHiCell, is_warm: Cell, is_sstore: PairSelectGadget, - sstore_gas_cost: SstoreGasGadget>, + sstore_gas_cost: SstoreGasGadget>, insufficient_gas_cost: LtGadget, // Constrain for SSTORE reentrancy sentry. insufficient_gas_sentry: LtGadget, @@ -81,7 +81,7 @@ impl ExecutionGadget for ErrorOOGSloadSstoreGadget { tx_id.expr(), callee_address.to_word(), key.to_word(), - Word::from_lo_unchecked(is_warm.expr()), + WordLoHi::from_lo_unchecked(is_warm.expr()), ); let sload_gas_cost = SloadGasGadget::construct(cb, is_warm.expr()); diff --git a/zkevm-circuits/src/evm_circuit/execution/error_oog_static_memory.rs b/zkevm-circuits/src/evm_circuit/execution/error_oog_static_memory.rs index 1e1ced35de..588d8c4cc4 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_oog_static_memory.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_oog_static_memory.rs @@ -14,7 +14,7 @@ use crate::{ }, witness::{Block, Call, ExecStep, Transaction}, }, - util::{word::Word, Expr}, + util::{word::WordLoHi, Expr}, }; use eth_types::{evm_types::OpcodeId, Field, ToWord}; use gadgets::util::or; @@ -65,7 +65,7 @@ impl ExecutionGadget for ErrorOOGStaticMemoryGadget { cb.require_equal_word( "Memory length must be 32 for MLOAD and MSTORE, and 1 for MSTORE8", memory_address.length_word(), - Word::from_lo_unchecked(select::expr(is_mstore8.expr(), 1.expr(), 32.expr())), + WordLoHi::from_lo_unchecked(select::expr(is_mstore8.expr(), 1.expr(), 32.expr())), ); let memory_expansion = MemoryExpansionGadget::construct(cb, [memory_address.address()]); diff --git a/zkevm-circuits/src/evm_circuit/execution/error_precompile_failed.rs b/zkevm-circuits/src/evm_circuit/execution/error_precompile_failed.rs index 662394c7c6..7eb8f82813 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_precompile_failed.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_precompile_failed.rs @@ -6,12 +6,12 @@ use crate::{ constraint_builder::{ConstrainBuilderCommon, EVMConstraintBuilder}, math_gadget::IsZeroGadget, memory_gadget::{CommonMemoryAddressGadget, MemoryAddressGadget}, - sum, CachedRegion, Cell, Word, + sum, CachedRegion, Cell, }, }, table::CallContextFieldTag, util::{ - word::{Word32Cell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi}, Expr, }, witness::{Block, Call, ExecStep, Transaction}, @@ -87,14 +87,14 @@ impl ExecutionGadget for ErrorPrecompileFailedGadget { cb.stack_pop(cd_length.to_word()); cb.stack_pop(rd_offset.to_word()); cb.stack_pop(rd_length.to_word()); - cb.stack_push(Word::zero()); + cb.stack_push(WordLoHi::zero()); for (field_tag, value) in [ (CallContextFieldTag::LastCalleeId, callee_call_id.expr()), (CallContextFieldTag::LastCalleeReturnDataOffset, 0.expr()), (CallContextFieldTag::LastCalleeReturnDataLength, 0.expr()), ] { - cb.call_context_lookup_write(None, field_tag, Word::from_lo_unchecked(value)); + cb.call_context_lookup_write(None, field_tag, WordLoHi::from_lo_unchecked(value)); } let cd_address = MemoryAddressGadget::construct(cb, cd_offset, cd_length); diff --git a/zkevm-circuits/src/evm_circuit/execution/error_return_data_oo_bound.rs b/zkevm-circuits/src/evm_circuit/execution/error_return_data_oo_bound.rs index 63436d8e30..a20954ef5f 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_return_data_oo_bound.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_return_data_oo_bound.rs @@ -14,7 +14,7 @@ use crate::{ }, table::CallContextFieldTag, util::{ - word::{Word, WordExpr}, + word::{WordExpr, WordLoHi}, Expr, }, }; @@ -64,7 +64,7 @@ impl ExecutionGadget for ErrorReturnDataOutOfBoundGadget { cb.call_context_lookup_read( None, CallContextFieldTag::LastCalleeReturnDataLength, - Word::from_lo_unchecked(return_data_length.expr()), + WordLoHi::from_lo_unchecked(return_data_length.expr()), ); // Check if `data_offset` is Uint64 overflow. diff --git a/zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs b/zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs index 293c7cea57..9e148bc6d3 100644 --- a/zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs +++ b/zkevm-circuits/src/evm_circuit/execution/error_write_protection.rs @@ -12,7 +12,7 @@ use crate::{ }, table::CallContextFieldTag, util::{ - word::{Word, WordCell, WordExpr}, + word::{WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -23,10 +23,10 @@ use halo2_proofs::{circuit::Value, plonk::Error}; pub(crate) struct ErrorWriteProtectionGadget { opcode: Cell, is_call: IsZeroGadget, - gas: WordCell, + gas: WordLoHiCell, code_address: AccountAddress, - value: WordCell, - is_value_zero: IsZeroWordGadget>, + value: WordLoHiCell, + is_value_zero: IsZeroWordGadget>, common_error_gadget: CommonErrorGadget, } @@ -73,7 +73,7 @@ impl ExecutionGadget for ErrorWriteProtectionGadget { }); // current call context is readonly - cb.call_context_lookup_read(None, CallContextFieldTag::IsStatic, Word::one()); + cb.call_context_lookup_read(None, CallContextFieldTag::IsStatic, WordLoHi::one()); // constrain not root call as at least one previous staticcall preset. cb.require_zero( @@ -125,7 +125,7 @@ impl ExecutionGadget for ErrorWriteProtectionGadget { F::from(opcode.as_u64()) - F::from(OpcodeId::CALL.as_u64()), )?; self.is_value_zero - .assign(region, offset, Word::from(value))?; + .assign(region, offset, WordLoHi::from(value))?; self.common_error_gadget.assign( region, diff --git a/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs b/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs index bb22ee2723..f7e8ba4793 100644 --- a/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/extcodecopy.rs @@ -18,7 +18,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, table::{AccountFieldTag, CallContextFieldTag}, - util::word::{Word, Word32Cell, WordExpr}, + util::word::{Word32Cell, WordExpr, WordLoHi}, }; use bus_mapping::circuit_input_builder::CopyDataType; use eth_types::{evm_types::GasCost, Field, ToScalar}; @@ -40,7 +40,7 @@ pub(crate) struct ExtcodecopyGadget { reversion_info: ReversionInfo, is_warm: Cell, code_hash: Word32Cell, - not_exists: IsZeroWordGadget>>, + not_exists: IsZeroWordGadget>>, code_size: Cell, copy_rwc_inc: Cell, memory_expansion: MemoryExpansionGadget, @@ -126,7 +126,7 @@ impl ExecutionGadget for ExtcodecopyGadget { cb.copy_table_lookup( code_hash.to_word(), CopyDataType::Bytecode.expr(), - Word::from_lo_unchecked(cb.curr.state.call_id.expr()), + WordLoHi::from_lo_unchecked(cb.curr.state.call_id.expr()), CopyDataType::Memory.expr(), src_addr, code_size.expr(), diff --git a/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs b/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs index 226e734893..99cd8b5b6a 100644 --- a/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs +++ b/zkevm-circuits/src/evm_circuit/execution/extcodehash.rs @@ -14,7 +14,7 @@ use crate::{ }, table::{AccountFieldTag, CallContextFieldTag}, util::{ - word::{Word32Cell, WordCell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHiCell}, Expr, }, }; @@ -28,7 +28,7 @@ pub(crate) struct ExtcodehashGadget { tx_id: Cell, reversion_info: ReversionInfo, is_warm: Cell, - code_hash: WordCell, + code_hash: WordLoHiCell, } impl ExecutionGadget for ExtcodehashGadget { diff --git a/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs b/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs index ee6d540722..631f75cf85 100644 --- a/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs +++ b/zkevm-circuits/src/evm_circuit/execution/extcodesize.rs @@ -16,7 +16,7 @@ use crate::{ }, table::{AccountFieldTag, CallContextFieldTag}, util::{ - word::{Word, Word32Cell, WordCell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -30,8 +30,8 @@ pub(crate) struct ExtcodesizeGadget { reversion_info: ReversionInfo, tx_id: Cell, is_warm: Cell, - code_hash: WordCell, - not_exists: IsZeroWordGadget>, + code_hash: WordLoHiCell, + not_exists: IsZeroWordGadget>, code_size: U64Cell, } @@ -143,7 +143,7 @@ impl ExecutionGadget for ExtcodesizeGadget { let code_hash = block.get_rws(step, 5).account_codehash_pair().0; self.code_hash.assign_u256(region, offset, code_hash)?; self.not_exists - .assign(region, offset, Word::from(code_hash))?; + .assign(region, offset, WordLoHi::from(code_hash))?; let code_size = block.get_rws(step, 6).stack_value().as_u64(); self.code_size diff --git a/zkevm-circuits/src/evm_circuit/execution/gasprice.rs b/zkevm-circuits/src/evm_circuit/execution/gasprice.rs index cf01885460..53ff2ab71f 100644 --- a/zkevm-circuits/src/evm_circuit/execution/gasprice.rs +++ b/zkevm-circuits/src/evm_circuit/execution/gasprice.rs @@ -11,7 +11,7 @@ use crate::{ }, table::{CallContextFieldTag, TxContextFieldTag}, util::{ - word::{WordCell, WordExpr}, + word::{WordExpr, WordLoHiCell}, Expr, }, }; @@ -22,7 +22,7 @@ use halo2_proofs::{circuit::Value, plonk::Error}; #[derive(Clone, Debug)] pub(crate) struct GasPriceGadget { tx_id: Cell, - gas_price: WordCell, + gas_price: WordLoHiCell, same_context: SameContextGadget, } diff --git a/zkevm-circuits/src/evm_circuit/execution/invalid_tx.rs b/zkevm-circuits/src/evm_circuit/execution/invalid_tx.rs index 69a50a0de0..a87dc847e6 100644 --- a/zkevm-circuits/src/evm_circuit/execution/invalid_tx.rs +++ b/zkevm-circuits/src/evm_circuit/execution/invalid_tx.rs @@ -7,12 +7,12 @@ use crate::{ constraint_builder::{ConstrainBuilderCommon, EVMConstraintBuilder}, math_gadget::{IsEqualGadget, LtGadget, LtWordGadget}, tx::{BeginTxHelperGadget, EndTxHelperGadget, TxDataGadget}, - CachedRegion, Cell, StepRws, Word, + CachedRegion, Cell, StepRws, }, witness::{Block, Call, ExecStep, Transaction}, }, table::AccountFieldTag, - util::word::{Word32Cell, WordExpr}, + util::word::{Word32Cell, WordExpr, WordLoHi}, }; use eth_types::{Field, ToScalar}; use gadgets::util::{not, or, Expr, Scalar}; @@ -45,7 +45,7 @@ impl ExecutionGadget for InvalidTxGadget { cb.account_read( tx.caller_address.to_word(), AccountFieldTag::Nonce, - Word::from_lo_unchecked(account_nonce.expr()), + WordLoHi::from_lo_unchecked(account_nonce.expr()), ); let is_nonce_match = IsEqualGadget::construct(cb, account_nonce.expr(), tx.nonce.expr()); diff --git a/zkevm-circuits/src/evm_circuit/execution/is_zero.rs b/zkevm-circuits/src/evm_circuit/execution/is_zero.rs index ec8b7334e6..1c9b189808 100644 --- a/zkevm-circuits/src/evm_circuit/execution/is_zero.rs +++ b/zkevm-circuits/src/evm_circuit/execution/is_zero.rs @@ -10,7 +10,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{Word, WordCell, WordExpr}, + word::{WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -21,8 +21,8 @@ use halo2_proofs::{circuit::Value, plonk::Error}; #[derive(Clone, Debug)] pub(crate) struct IsZeroGadget { same_context: SameContextGadget, - value: WordCell, - is_zero_word: math_gadget::IsZeroWordGadget>, + value: WordLoHiCell, + is_zero_word: math_gadget::IsZeroWordGadget>, } impl ExecutionGadget for IsZeroGadget { @@ -37,7 +37,7 @@ impl ExecutionGadget for IsZeroGadget { let is_zero_word = math_gadget::IsZeroWordGadget::construct(cb, &value); cb.stack_pop(value.to_word()); - cb.stack_push(Word::from_lo_unchecked(is_zero_word.expr())); + cb.stack_push(WordLoHi::from_lo_unchecked(is_zero_word.expr())); // State transition let step_state_transition = StepStateTransition { @@ -70,7 +70,7 @@ impl ExecutionGadget for IsZeroGadget { let value = block.get_rws(step, 0).stack_value(); self.value.assign_u256(region, offset, value)?; self.is_zero_word - .assign_value(region, offset, Value::known(Word::from(value)))?; + .assign_value(region, offset, Value::known(WordLoHi::from(value)))?; Ok(()) } diff --git a/zkevm-circuits/src/evm_circuit/execution/jumpi.rs b/zkevm-circuits/src/evm_circuit/execution/jumpi.rs index 5697e8f0e2..67e7b343c7 100644 --- a/zkevm-circuits/src/evm_circuit/execution/jumpi.rs +++ b/zkevm-circuits/src/evm_circuit/execution/jumpi.rs @@ -15,7 +15,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{Word, WordCell, WordExpr}, + word::{WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -26,8 +26,8 @@ use halo2_proofs::{circuit::Value, plonk::Error}; pub(crate) struct JumpiGadget { same_context: SameContextGadget, dest: WordByteRangeGadget, - condition: WordCell, - is_condition_zero: IsZeroWordGadget>, + condition: WordLoHiCell, + is_condition_zero: IsZeroWordGadget>, } impl ExecutionGadget for JumpiGadget { @@ -100,8 +100,11 @@ impl ExecutionGadget for JumpiGadget { self.dest.assign(region, offset, destination)?; self.condition.assign_u256(region, offset, condition)?; - self.is_condition_zero - .assign_value(region, offset, Value::known(Word::from(condition)))?; + self.is_condition_zero.assign_value( + region, + offset, + Value::known(WordLoHi::from(condition)), + )?; Ok(()) } diff --git a/zkevm-circuits/src/evm_circuit/execution/logs.rs b/zkevm-circuits/src/evm_circuit/execution/logs.rs index 23c63bc0f2..47456bcafc 100644 --- a/zkevm-circuits/src/evm_circuit/execution/logs.rs +++ b/zkevm-circuits/src/evm_circuit/execution/logs.rs @@ -19,7 +19,7 @@ use crate::{ table::{CallContextFieldTag, TxLogFieldTag}, util::{ build_tx_log_expression, - word::{Word, Word32Cell, WordCell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -39,7 +39,7 @@ pub(crate) struct LogGadget { topics: [Word32Cell; 4], topic_selectors: [Cell; 4], - contract_address: WordCell, + contract_address: WordLoHiCell, is_static_call: Cell, is_persistent: Cell, tx_id: Cell, @@ -139,9 +139,9 @@ impl ExecutionGadget for LogGadget { let cond = memory_address.has_length() * is_persistent.expr(); cb.condition(cond.clone(), |cb| { cb.copy_table_lookup( - Word::from_lo_unchecked(cb.curr.state.call_id.expr()), + WordLoHi::from_lo_unchecked(cb.curr.state.call_id.expr()), CopyDataType::Memory.expr(), - Word::from_lo_unchecked(tx_id.expr()), + WordLoHi::from_lo_unchecked(tx_id.expr()), CopyDataType::TxLog.expr(), memory_address.offset(), memory_address.address(), diff --git a/zkevm-circuits/src/evm_circuit/execution/msize.rs b/zkevm-circuits/src/evm_circuit/execution/msize.rs index 2c34f0d958..b3c2274b44 100644 --- a/zkevm-circuits/src/evm_circuit/execution/msize.rs +++ b/zkevm-circuits/src/evm_circuit/execution/msize.rs @@ -13,7 +13,7 @@ use crate::{ }, witness::{Block, Call, ExecStep, Transaction}, }, - util::{word::Word, Expr}, + util::{word::WordLoHi, Expr}, }; use bus_mapping::evm::OpcodeId; use eth_types::Field; @@ -42,7 +42,7 @@ impl ExecutionGadget for MsizeGadget { ); // Push the value on the stack - cb.stack_push(Word::from_lo_unchecked(value.expr())); + cb.stack_push(WordLoHi::from_lo_unchecked(value.expr())); // State transition let step_state_transition = StepStateTransition { diff --git a/zkevm-circuits/src/evm_circuit/execution/mul_div_mod.rs b/zkevm-circuits/src/evm_circuit/execution/mul_div_mod.rs index bef4c22c26..84290e6bf3 100644 --- a/zkevm-circuits/src/evm_circuit/execution/mul_div_mod.rs +++ b/zkevm-circuits/src/evm_circuit/execution/mul_div_mod.rs @@ -14,7 +14,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{Word, Word32Cell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi}, Expr, }, }; @@ -71,7 +71,7 @@ impl ExecutionGadget for MulDivModGadget { // The second pop is multiplicand for MUL and divisor for DIV/MOD // The push is product for MUL, quotient for DIV, and residue for MOD // Note that for DIV/MOD, when divisor == 0, the push value is also 0. - cb.stack_pop(Word::select(is_mul.clone(), a.to_word(), d.to_word())); + cb.stack_pop(WordLoHi::select(is_mul.clone(), a.to_word(), d.to_word())); cb.stack_pop(b.to_word()); cb.stack_push( d.to_word() @@ -152,7 +152,8 @@ impl ExecutionGadget for MulDivModGadget { self.words[3].assign_u256(region, offset, d)?; self.mul_add_words.assign(region, offset, [a, b, c, d])?; self.lt_word.assign(region, offset, c, b)?; - self.divisor_is_zero.assign(region, offset, Word::from(b))?; + self.divisor_is_zero + .assign(region, offset, WordLoHi::from(b))?; Ok(()) } } diff --git a/zkevm-circuits/src/evm_circuit/execution/mulmod.rs b/zkevm-circuits/src/evm_circuit/execution/mulmod.rs index 13d23b4bf0..6b6f7299d2 100644 --- a/zkevm-circuits/src/evm_circuit/execution/mulmod.rs +++ b/zkevm-circuits/src/evm_circuit/execution/mulmod.rs @@ -14,7 +14,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{Word, Word32Cell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi}, Expr, }, }; @@ -157,7 +157,7 @@ impl ExecutionGadget for MulModGadget { self.lt.assign(region, offset, r, n)?; - self.n_is_zero.assign(region, offset, Word::from(n))?; + self.n_is_zero.assign(region, offset, WordLoHi::from(n))?; Ok(()) } } diff --git a/zkevm-circuits/src/evm_circuit/execution/pop.rs b/zkevm-circuits/src/evm_circuit/execution/pop.rs index bb69d8f13b..59d0ac32dd 100644 --- a/zkevm-circuits/src/evm_circuit/execution/pop.rs +++ b/zkevm-circuits/src/evm_circuit/execution/pop.rs @@ -10,7 +10,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{WordCell, WordExpr}, + word::{WordExpr, WordLoHiCell}, Expr, }, }; @@ -21,7 +21,7 @@ use halo2_proofs::plonk::Error; #[derive(Clone, Debug)] pub(crate) struct PopGadget { same_context: SameContextGadget, - value: WordCell, + value: WordLoHiCell, } impl ExecutionGadget for PopGadget { diff --git a/zkevm-circuits/src/evm_circuit/execution/return_revert.rs b/zkevm-circuits/src/evm_circuit/execution/return_revert.rs index 0df3467253..d0b7bd1dcb 100644 --- a/zkevm-circuits/src/evm_circuit/execution/return_revert.rs +++ b/zkevm-circuits/src/evm_circuit/execution/return_revert.rs @@ -19,7 +19,7 @@ use crate::{ }, table::{AccountFieldTag, CallContextFieldTag}, util::{ - word::{Word, Word32Cell, WordCell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -55,7 +55,7 @@ pub(crate) struct ReturnRevertGadget { code_hash: Word32Cell, caller_id: Cell, - address: WordCell, + address: WordLoHiCell, reversion_info: ReversionInfo, } @@ -137,7 +137,7 @@ impl ExecutionGadget for ReturnRevertGadget { let code_hash = cb.query_word32(); let deployed_code_rlc = cb.query_cell_phase2(); cb.copy_table_lookup( - Word::from_lo_unchecked(cb.curr.state.call_id.expr()), + WordLoHi::from_lo_unchecked(cb.curr.state.call_id.expr()), CopyDataType::Memory.expr(), code_hash.to_word(), CopyDataType::Bytecode.expr(), @@ -179,7 +179,7 @@ impl ExecutionGadget for ReturnRevertGadget { cb.call_context_lookup_read( None, CallContextFieldTag::IsPersistent, - Word::from_lo_unchecked(is_success.expr()), + WordLoHi::from_lo_unchecked(is_success.expr()), ); cb.require_step_state_transition(StepStateTransition { program_counter: To(0.expr()), @@ -234,9 +234,9 @@ impl ExecutionGadget for ReturnRevertGadget { * not::expr(copy_rw_increase_is_zero.expr()), |cb| { cb.copy_table_lookup( - Word::from_lo_unchecked(cb.curr.state.call_id.expr()), + WordLoHi::from_lo_unchecked(cb.curr.state.call_id.expr()), CopyDataType::Memory.expr(), - Word::from_lo_unchecked(cb.next.state.call_id.expr()), + WordLoHi::from_lo_unchecked(cb.next.state.call_id.expr()), CopyDataType::Memory.expr(), range.offset(), range.address(), diff --git a/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs b/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs index 615736859e..d84d324046 100644 --- a/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs +++ b/zkevm-circuits/src/evm_circuit/execution/returndatacopy.rs @@ -20,7 +20,7 @@ use crate::{ }, table::CallContextFieldTag, util::{ - word::{Word, WordExpr}, + word::{WordExpr, WordLoHi}, Expr, }, }; @@ -71,8 +71,8 @@ impl ExecutionGadget for ReturnDataCopyGadget { // 1. Pop dest_offset, offset, length from stack cb.stack_pop(dest_offset.to_word()); - cb.stack_pop(Word::from_lo_unchecked(data_offset.expr())); - cb.stack_pop(Word::from_lo_unchecked(size.expr())); + cb.stack_pop(WordLoHi::from_lo_unchecked(data_offset.expr())); + cb.stack_pop(WordLoHi::from_lo_unchecked(size.expr())); // 2. Add lookup constraint in the call context for the returndatacopy field. let last_callee_id = cb.query_cell(); @@ -81,17 +81,17 @@ impl ExecutionGadget for ReturnDataCopyGadget { cb.call_context_lookup_read( None, CallContextFieldTag::LastCalleeId, - Word::from_lo_unchecked(last_callee_id.expr()), + WordLoHi::from_lo_unchecked(last_callee_id.expr()), ); cb.call_context_lookup_read( None, CallContextFieldTag::LastCalleeReturnDataOffset, - Word::from_lo_unchecked(return_data_offset.expr()), + WordLoHi::from_lo_unchecked(return_data_offset.expr()), ); cb.call_context_lookup_read( None, CallContextFieldTag::LastCalleeReturnDataLength, - Word::from_lo_unchecked(return_data_size.expr()), + WordLoHi::from_lo_unchecked(return_data_size.expr()), ); // 3. contraints for copy: copy overflow check @@ -118,9 +118,9 @@ impl ExecutionGadget for ReturnDataCopyGadget { let copy_rwc_inc = cb.query_cell(); cb.condition(dst_memory_addr.has_length(), |cb| { cb.copy_table_lookup( - Word::from_lo_unchecked(last_callee_id.expr()), + WordLoHi::from_lo_unchecked(last_callee_id.expr()), CopyDataType::Memory.expr(), - Word::from_lo_unchecked(cb.curr.state.call_id.expr()), + WordLoHi::from_lo_unchecked(cb.curr.state.call_id.expr()), CopyDataType::Memory.expr(), return_data_offset.expr() + data_offset.expr(), return_data_offset.expr() + return_data_size.expr(), diff --git a/zkevm-circuits/src/evm_circuit/execution/returndatasize.rs b/zkevm-circuits/src/evm_circuit/execution/returndatasize.rs index 14144d3aec..dfd410e684 100644 --- a/zkevm-circuits/src/evm_circuit/execution/returndatasize.rs +++ b/zkevm-circuits/src/evm_circuit/execution/returndatasize.rs @@ -11,7 +11,7 @@ use crate::{ }, table::CallContextFieldTag, util::{ - word::{WordCell, WordExpr}, + word::{WordExpr, WordLoHiCell}, Expr, }, }; @@ -22,7 +22,7 @@ use halo2_proofs::plonk::Error; #[derive(Clone, Debug)] pub(crate) struct ReturnDataSizeGadget { same_context: SameContextGadget, - return_data_size: WordCell, + return_data_size: WordLoHiCell, } impl ExecutionGadget for ReturnDataSizeGadget { diff --git a/zkevm-circuits/src/evm_circuit/execution/sdiv_smod.rs b/zkevm-circuits/src/evm_circuit/execution/sdiv_smod.rs index 02866e7cb4..85a271661d 100644 --- a/zkevm-circuits/src/evm_circuit/execution/sdiv_smod.rs +++ b/zkevm-circuits/src/evm_circuit/execution/sdiv_smod.rs @@ -16,7 +16,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{Word, Word32Cell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi}, Expr, }, }; @@ -58,7 +58,7 @@ impl ExecutionGadget for SignedDivModGadget { cb.stack_pop(dividend_abs.x().to_word()); cb.stack_pop(divisor_abs.x().to_word()); - cb.stack_push(Word::select( + cb.stack_push(WordLoHi::select( is_sdiv, quotient_abs .x() @@ -218,11 +218,11 @@ impl ExecutionGadget for SignedDivModGadget { u64::from(dividend_abs.to_le_bytes()[31]).into(), )?; self.quotient_is_zero - .assign(region, offset, Word::from(quotient))?; + .assign(region, offset, WordLoHi::from(quotient))?; self.divisor_is_zero - .assign(region, offset, Word::from(divisor))?; + .assign(region, offset, WordLoHi::from(divisor))?; self.remainder_is_zero - .assign(region, offset, Word::from(remainder))?; + .assign(region, offset, WordLoHi::from(remainder))?; Ok(()) } } diff --git a/zkevm-circuits/src/evm_circuit/execution/selfbalance.rs b/zkevm-circuits/src/evm_circuit/execution/selfbalance.rs index a222299ca0..f6ec95b612 100644 --- a/zkevm-circuits/src/evm_circuit/execution/selfbalance.rs +++ b/zkevm-circuits/src/evm_circuit/execution/selfbalance.rs @@ -11,7 +11,7 @@ use crate::{ }, table::{AccountFieldTag, CallContextFieldTag}, util::{ - word::{WordCell, WordExpr}, + word::{WordExpr, WordLoHiCell}, Expr, }, }; @@ -22,8 +22,8 @@ use halo2_proofs::plonk::Error; #[derive(Clone, Debug)] pub(crate) struct SelfbalanceGadget { same_context: SameContextGadget, - callee_address: WordCell, - self_balance: WordCell, + callee_address: WordLoHiCell, + self_balance: WordLoHiCell, } impl ExecutionGadget for SelfbalanceGadget { diff --git a/zkevm-circuits/src/evm_circuit/execution/sha3.rs b/zkevm-circuits/src/evm_circuit/execution/sha3.rs index adffa2acbf..12cbac2ee4 100644 --- a/zkevm-circuits/src/evm_circuit/execution/sha3.rs +++ b/zkevm-circuits/src/evm_circuit/execution/sha3.rs @@ -20,7 +20,7 @@ use crate::{ }, witness::{Block, Call, ExecStep, Transaction}, }, - util::word::{Word, WordCell, WordExpr}, + util::word::{WordExpr, WordLoHi, WordLoHiCell}, }; use super::ExecutionGadget; @@ -29,7 +29,7 @@ use super::ExecutionGadget; pub(crate) struct Sha3Gadget { same_context: SameContextGadget, memory_address: MemoryAddressGadget, - sha3_digest: WordCell, + sha3_digest: WordLoHiCell, copy_rwc_inc: Cell, rlc_acc: Cell, memory_expansion: MemoryExpansionGadget, @@ -59,9 +59,9 @@ impl ExecutionGadget for Sha3Gadget { cb.condition(memory_address.has_length(), |cb| { cb.copy_table_lookup( - Word::from_lo_unchecked(cb.curr.state.call_id.expr()), + WordLoHi::from_lo_unchecked(cb.curr.state.call_id.expr()), CopyDataType::Memory.expr(), - Word::from_lo_unchecked(cb.curr.state.call_id.expr()), + WordLoHi::from_lo_unchecked(cb.curr.state.call_id.expr()), CopyDataType::RlcAcc.expr(), memory_address.offset(), memory_address.address(), diff --git a/zkevm-circuits/src/evm_circuit/execution/shl_shr.rs b/zkevm-circuits/src/evm_circuit/execution/shl_shr.rs index 60bf8622c2..92c614d861 100644 --- a/zkevm-circuits/src/evm_circuit/execution/shl_shr.rs +++ b/zkevm-circuits/src/evm_circuit/execution/shl_shr.rs @@ -15,7 +15,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{Word, Word32Cell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi}, Expr, }, }; @@ -102,7 +102,7 @@ impl ExecutionGadget for ShlShrGadget { "shift == shift.cells[0] when divisor != 0", shift .to_word() - .sub_unchecked(Word::from_lo_unchecked(shift.limbs[0].expr())) + .sub_unchecked(WordLoHi::from_lo_unchecked(shift.limbs[0].expr())) .mul_selector(1.expr() - divisor_is_zero.expr()), ); @@ -207,9 +207,9 @@ impl ExecutionGadget for ShlShrGadget { .assign(region, offset, [quotient, divisor, remainder, dividend])?; self.shf_lt256.assign(region, offset, F::from(shf_lt256))?; self.divisor_is_zero - .assign(region, offset, Word::from(divisor))?; + .assign(region, offset, WordLoHi::from(divisor))?; self.remainder_is_zero - .assign(region, offset, Word::from(remainder))?; + .assign(region, offset, WordLoHi::from(remainder))?; self.remainder_lt_divisor .assign(region, offset, remainder, divisor)?; Ok(()) diff --git a/zkevm-circuits/src/evm_circuit/execution/signed_comparator.rs b/zkevm-circuits/src/evm_circuit/execution/signed_comparator.rs index 3f910d10fa..c6ebfcfe35 100644 --- a/zkevm-circuits/src/evm_circuit/execution/signed_comparator.rs +++ b/zkevm-circuits/src/evm_circuit/execution/signed_comparator.rs @@ -12,7 +12,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{Word, Word32Cell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi}, Expr, }, }; @@ -109,9 +109,9 @@ impl ExecutionGadget for SignedComparatorGadget { let result = a_neg_b_pos.clone() + (1.expr() - a_neg_b_pos - b_neg_a_pos) * a_lt_b.expr(); // Pop a and b from the stack, push the result on the stack. - cb.stack_pop(Word::select(is_sgt.expr(), b.to_word(), a.to_word())); - cb.stack_pop(Word::select(is_sgt.expr(), a.to_word(), b.to_word())); - cb.stack_push(Word::from_lo_unchecked(result)); + cb.stack_pop(WordLoHi::select(is_sgt.expr(), b.to_word(), a.to_word())); + cb.stack_pop(WordLoHi::select(is_sgt.expr(), a.to_word(), b.to_word())); + cb.stack_push(WordLoHi::from_lo_unchecked(result)); // The read-write counter changes by three since we're reading two words // from stack and writing one. The program counter shifts only by one diff --git a/zkevm-circuits/src/evm_circuit/execution/sload.rs b/zkevm-circuits/src/evm_circuit/execution/sload.rs index 12ee777aa6..7a222c9b44 100644 --- a/zkevm-circuits/src/evm_circuit/execution/sload.rs +++ b/zkevm-circuits/src/evm_circuit/execution/sload.rs @@ -13,7 +13,7 @@ use crate::{ }, table::CallContextFieldTag, util::{ - word::{Word, WordCell, WordExpr}, + word::{WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -25,10 +25,10 @@ pub(crate) struct SloadGadget { same_context: SameContextGadget, tx_id: Cell, reversion_info: ReversionInfo, - callee_address: WordCell, - key: WordCell, - value: WordCell, - committed_value: WordCell, + callee_address: WordLoHiCell, + key: WordLoHiCell, + value: WordLoHiCell, + committed_value: WordLoHiCell, is_warm: Cell, } @@ -65,14 +65,14 @@ impl ExecutionGadget for SloadGadget { tx_id.expr(), callee_address.to_word(), key.to_word(), - Word::from_lo_unchecked(is_warm.expr()), + WordLoHi::from_lo_unchecked(is_warm.expr()), ); cb.account_storage_access_list_write( tx_id.expr(), callee_address.to_word(), key.to_word(), - Word::from_lo_unchecked(true.expr()), - Word::from_lo_unchecked(is_warm.expr()), + WordLoHi::from_lo_unchecked(true.expr()), + WordLoHi::from_lo_unchecked(is_warm.expr()), Some(&mut reversion_info), ); diff --git a/zkevm-circuits/src/evm_circuit/execution/sstore.rs b/zkevm-circuits/src/evm_circuit/execution/sstore.rs index fe1fd45f0b..244e1595c0 100644 --- a/zkevm-circuits/src/evm_circuit/execution/sstore.rs +++ b/zkevm-circuits/src/evm_circuit/execution/sstore.rs @@ -16,7 +16,7 @@ use crate::{ }, table::CallContextFieldTag, util::{ - word::{Word, Word32Cell, WordCell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi, WordLoHiCell}, Expr, }, }; @@ -33,7 +33,7 @@ pub(crate) struct SstoreGadget { tx_id: Cell, is_static: Cell, reversion_info: ReversionInfo, - callee_address: WordCell, + callee_address: WordLoHiCell, key: Word32Cell, value: Word32Cell, value_prev: Word32Cell, @@ -88,14 +88,14 @@ impl ExecutionGadget for SstoreGadget { tx_id.expr(), callee_address.to_word(), key.to_word(), - Word::from_lo_unchecked(is_warm.expr()), + WordLoHi::from_lo_unchecked(is_warm.expr()), ); cb.account_storage_access_list_write( tx_id.expr(), callee_address.to_word(), key.to_word(), - Word::from_lo_unchecked(true.expr()), - Word::from_lo_unchecked(is_warm.expr()), + WordLoHi::from_lo_unchecked(true.expr()), + WordLoHi::from_lo_unchecked(is_warm.expr()), Some(&mut reversion_info), ); @@ -129,7 +129,7 @@ impl ExecutionGadget for SstoreGadget { ); cb.tx_refund_write( tx_id.expr(), - Word::from_lo_unchecked(tx_refund.expr()), + WordLoHi::from_lo_unchecked(tx_refund.expr()), tx_refund_prev.to_word(), Some(&mut reversion_info), ); @@ -231,12 +231,13 @@ impl ExecutionGadget for SstoreGadget { pub(crate) struct SstoreTxRefundGadget { tx_refund_old: U64Cell, tx_refund_new: Expression, - value_prev_is_zero_gadget: IsZeroWordGadget>>, - value_is_zero_gadget: IsZeroWordGadget>>, - original_is_zero_gadget: IsZeroWordGadget>>, - original_eq_value_gadget: IsEqualWordGadget>, Word>>, - prev_eq_value_gadget: IsEqualWordGadget>, Word>>, - original_eq_prev_gadget: IsEqualWordGadget>, Word>>, + value_prev_is_zero_gadget: IsZeroWordGadget>>, + value_is_zero_gadget: IsZeroWordGadget>>, + original_is_zero_gadget: IsZeroWordGadget>>, + original_eq_value_gadget: + IsEqualWordGadget>, WordLoHi>>, + prev_eq_value_gadget: IsEqualWordGadget>, WordLoHi>>, + original_eq_prev_gadget: IsEqualWordGadget>, WordLoHi>>, } impl SstoreTxRefundGadget { @@ -267,20 +268,20 @@ impl SstoreTxRefundGadget { let original_eq_prev = original_eq_prev_gadget.expr(); // (value_prev != value) && (original_value != value) && (value == - // Word::from(0)) + // WordLoHi::from(0)) let delete_slot = not::expr(prev_eq_value.clone()) * not::expr(original_is_zero.clone()) * value_is_zero; // (value_prev != value) && (original_value == value) && (original_value != - // Word::from(0)) + // WordLoHi::from(0)) let reset_existing = not::expr(prev_eq_value.clone()) * original_eq_value.clone() * not::expr(original_is_zero.clone()); // (value_prev != value) && (original_value == value) && (original_value == - // Word::from(0)) + // WordLoHi::from(0)) let reset_inexistent = not::expr(prev_eq_value.clone()) * original_eq_value * (original_is_zero); // (value_prev != value) && (original_value != value_prev) && (value_prev == - // Word::from(0)) + // WordLoHi::from(0)) let recreate_slot = not::expr(prev_eq_value) * not::expr(original_eq_prev) * (value_prev_is_zero); @@ -321,28 +322,28 @@ impl SstoreTxRefundGadget { self.tx_refund_old .assign(region, offset, Some(tx_refund_old.to_le_bytes()))?; self.value_prev_is_zero_gadget - .assign(region, offset, Word::from(value_prev))?; + .assign(region, offset, WordLoHi::from(value_prev))?; self.value_is_zero_gadget - .assign(region, offset, Word::from(value))?; + .assign(region, offset, WordLoHi::from(value))?; self.original_is_zero_gadget - .assign(region, offset, Word::from(original_value))?; + .assign(region, offset, WordLoHi::from(original_value))?; self.original_eq_value_gadget.assign( region, offset, - Word::from(original_value), - Word::from(value), + WordLoHi::from(original_value), + WordLoHi::from(value), )?; self.prev_eq_value_gadget.assign( region, offset, - Word::from(value_prev), - Word::from(value), + WordLoHi::from(value_prev), + WordLoHi::from(value), )?; self.original_eq_prev_gadget.assign( region, offset, - Word::from(original_value), - Word::from(value_prev), + WordLoHi::from(original_value), + WordLoHi::from(value_prev), )?; debug_assert_eq!( calc_expected_tx_refund(tx_refund_old, value, value_prev, original_value), diff --git a/zkevm-circuits/src/evm_circuit/execution/stop.rs b/zkevm-circuits/src/evm_circuit/execution/stop.rs index 53fd730b4e..8ce8ca02ec 100644 --- a/zkevm-circuits/src/evm_circuit/execution/stop.rs +++ b/zkevm-circuits/src/evm_circuit/execution/stop.rs @@ -16,7 +16,7 @@ use crate::{ }, table::CallContextFieldTag, util::{ - word::{Word, WordExpr}, + word::{WordExpr, WordLoHi}, Expr, }, }; @@ -63,7 +63,7 @@ impl ExecutionGadget for StopGadget { ); // Call ends with STOP must be successful - cb.call_context_lookup_read(None, CallContextFieldTag::IsSuccess, Word::one()); + cb.call_context_lookup_read(None, CallContextFieldTag::IsSuccess, WordLoHi::one()); let is_to_end_tx = cb.next.execution_state_selector([ExecutionState::EndTx]); cb.require_equal( diff --git a/zkevm-circuits/src/evm_circuit/execution/swap.rs b/zkevm-circuits/src/evm_circuit/execution/swap.rs index b9722f6e45..5bbd27df22 100644 --- a/zkevm-circuits/src/evm_circuit/execution/swap.rs +++ b/zkevm-circuits/src/evm_circuit/execution/swap.rs @@ -10,7 +10,7 @@ use crate::{ witness::{Block, Call, ExecStep, Transaction}, }, util::{ - word::{WordCell, WordExpr}, + word::{WordExpr, WordLoHiCell}, Expr, }, }; @@ -20,7 +20,7 @@ use halo2_proofs::plonk::Error; #[derive(Clone, Debug)] pub(crate) struct SwapGadget { same_context: SameContextGadget, - values: [WordCell; 2], + values: [WordLoHiCell; 2], } impl ExecutionGadget for SwapGadget { diff --git a/zkevm-circuits/src/evm_circuit/step.rs b/zkevm-circuits/src/evm_circuit/step.rs index ec77d9e996..bc301f2076 100644 --- a/zkevm-circuits/src/evm_circuit/step.rs +++ b/zkevm-circuits/src/evm_circuit/step.rs @@ -14,7 +14,7 @@ use crate::{ }, util::{ cell_manager::{CMFixedWidthStrategy, CellManager}, - word::{Word, WordCell}, + word::{WordLoHi, WordLoHiCell}, Expr, }, }; @@ -751,7 +751,7 @@ pub(crate) struct StepState { /// In the case of a contract creation internal call, this denotes the hash /// of the chunk of bytes from caller's memory that represent the /// contract init code. - pub(crate) code_hash: WordCell, + pub(crate) code_hash: WordLoHiCell, /// The program counter pub(crate) program_counter: Cell, /// The stack pointer @@ -795,7 +795,7 @@ impl Step { call_id: cell_manager.query_cell(meta, CellType::StoragePhase1), is_root: cell_manager.query_cell(meta, CellType::StoragePhase1), is_create: cell_manager.query_cell(meta, CellType::StoragePhase1), - code_hash: Word::new([ + code_hash: WordLoHi::new([ cell_manager.query_cell(meta, CellType::StoragePhase1), cell_manager.query_cell(meta, CellType::StoragePhase1), ]), diff --git a/zkevm-circuits/src/evm_circuit/table.rs b/zkevm-circuits/src/evm_circuit/table.rs index 67997c673e..a42b2c0e0c 100644 --- a/zkevm-circuits/src/evm_circuit/table.rs +++ b/zkevm-circuits/src/evm_circuit/table.rs @@ -3,7 +3,7 @@ use crate::{ evm_circuit::step::{ExecutionState, ResponsibleOp}, impl_expr, - util::word::Word, + util::word::WordLoHi, }; use bus_mapping::{evm::OpcodeId, precompile::PrecompileCalls}; use eth_types::Field; @@ -207,13 +207,13 @@ pub(crate) struct RwValues { /// the cell value of the [`bus_mapping::operation::Target`] field_tag: Expression, /// Storage key of two limbs - storage_key: Word>, + storage_key: WordLoHi>, /// The current storage value - value: Word>, + value: WordLoHi>, /// The previous storage value - value_prev: Word>, + value_prev: WordLoHi>, /// The initial storage value before the current transaction - init_val: Word>, + init_val: WordLoHi>, } impl RwValues { @@ -223,10 +223,10 @@ impl RwValues { id: Expression, address: Expression, field_tag: Expression, - storage_key: Word>, - value: Word>, - value_prev: Word>, - init_val: Word>, + storage_key: WordLoHi>, + value: WordLoHi>, + value_prev: WordLoHi>, + init_val: WordLoHi>, ) -> Self { Self { id, @@ -269,7 +269,7 @@ pub(crate) enum Lookup { /// field_tag is Calldata, otherwise should be set to 0. index: Expression, /// Value of the field. - value: Word>, + value: WordLoHi>, }, /// Lookup to read-write table, which contains read-write access records of /// time-aware data. @@ -289,7 +289,7 @@ pub(crate) enum Lookup { /// contract code. Bytecode { /// Hash to specify which code to read. - hash: Word>, + hash: WordLoHi>, /// Tag to specify whether its the bytecode length or byte value in the /// bytecode. tag: Expression, @@ -309,18 +309,18 @@ pub(crate) enum Lookup { /// should be set to 0. number: Expression, /// Value of the field. - value: Word>, + value: WordLoHi>, }, /// Lookup to copy table. CopyTable { /// Whether the row is the first row of the copy event. is_first: Expression, /// The source ID for the copy event. - src_id: Word>, + src_id: WordLoHi>, /// The source tag for the copy event. src_tag: Expression, /// The destination ID for the copy event. - dst_id: Word>, + dst_id: WordLoHi>, /// The destination tag for the copy event. dst_tag: Expression, /// The source address where bytes are copied from. @@ -349,7 +349,7 @@ pub(crate) enum Lookup { input_len: Expression, /// Output (hash) until this state. hash will be split into multiple expression in little /// endian. - output: Word>, + output: WordLoHi>, }, /// Lookup to exponentiation table. ExpTable { diff --git a/zkevm-circuits/src/evm_circuit/util.rs b/zkevm-circuits/src/evm_circuit/util.rs index f5202ad9f1..1b58790914 100644 --- a/zkevm-circuits/src/evm_circuit/util.rs +++ b/zkevm-circuits/src/evm_circuit/util.rs @@ -1,5 +1,5 @@ pub use crate::util::{ - word::{Word, WordExpr}, + word::{WordExpr, WordLoHi}, Challenges, Expr, }; use crate::{ @@ -145,8 +145,8 @@ impl<'r, 'b, F: Field> CachedRegion<'r, 'b, F> { .map(|r| rlc::value(le_bytes, r)) } - pub fn code_hash(&self, n: U256) -> Word> { - Word::from(n).into_value() + pub fn code_hash(&self, n: U256) -> WordLoHi> { + WordLoHi::from(n).into_value() } /// Constrains a cell to have a constant value. diff --git a/zkevm-circuits/src/evm_circuit/util/common_gadget.rs b/zkevm-circuits/src/evm_circuit/util/common_gadget.rs index d55c6f7538..420051b90c 100644 --- a/zkevm-circuits/src/evm_circuit/util/common_gadget.rs +++ b/zkevm-circuits/src/evm_circuit/util/common_gadget.rs @@ -22,7 +22,7 @@ use crate::{ }, table::{AccountFieldTag, CallContextFieldTag}, util::{ - word::{Word, Word32, Word32Cell, WordCell, WordExpr}, + word::{Word32, Word32Cell, WordExpr, WordLoHi, WordLoHiCell}, Expr, }, witness::{Block, Call, ExecStep}, @@ -100,7 +100,7 @@ pub(crate) struct RestoreContextGadget { caller_id: Cell, caller_is_root: Cell, caller_is_create: Cell, - caller_code_hash: WordCell, + caller_code_hash: WordLoHiCell, caller_program_counter: Cell, caller_stack_pointer: Cell, caller_gas_left: Cell, @@ -191,7 +191,7 @@ impl RestoreContextGadget { cb.call_context_lookup_write( Some(caller_id.expr()), field_tag, - Word::from_lo_unchecked(value), + WordLoHi::from_lo_unchecked(value), ); } @@ -308,7 +308,7 @@ impl { pub(crate) fn construct( cb: &mut EVMConstraintBuilder, - address: Word>, + address: WordLoHi>, updates: Vec>, reversion_info: Option<&mut ReversionInfo>, ) -> Self { @@ -378,7 +378,7 @@ impl TransferToGadget { #[allow(clippy::too_many_arguments)] pub(crate) fn construct( cb: &mut EVMConstraintBuilder, - receiver_address: Word>, + receiver_address: WordLoHi>, receiver_exists: Expression, must_create: Expression, value: Word32Cell, @@ -415,7 +415,7 @@ impl TransferToGadget { pub(crate) fn create_account( cb: &mut EVMConstraintBuilder, - receiver_address: Word>, + receiver_address: WordLoHi>, receiver_exists: Expression, must_create: Expression, value_is_zero: Expression, @@ -431,7 +431,7 @@ impl TransferToGadget { receiver_address.clone(), AccountFieldTag::CodeHash, cb.empty_code_hash(), - Word::zero(), + WordLoHi::zero(), reversion_info, ); }, @@ -453,7 +453,7 @@ impl TransferToGadget { receiver_balance, )?; self.value_is_zero - .assign_value(region, offset, Value::known(Word::from(value)))?; + .assign_value(region, offset, Value::known(WordLoHi::from(value)))?; Ok(()) } @@ -487,8 +487,8 @@ impl TransferWithGasFeeGadget { #[allow(clippy::too_many_arguments)] pub(crate) fn construct( cb: &mut EVMConstraintBuilder, - sender_address: Word>, - receiver_address: Word>, + sender_address: WordLoHi>, + receiver_address: WordLoHi>, receiver_exists: Expression, must_create: Expression, value: Word32Cell, @@ -591,7 +591,7 @@ impl TransferWithGasFeeGadget { value, )?; self.value_is_zero - .assign_value(region, offset, Value::known(Word::from(value)))?; + .assign_value(region, offset, Value::known(WordLoHi::from(value)))?; Ok(()) } } @@ -610,11 +610,11 @@ pub(crate) struct TransferGadget { impl TransferGadget { pub(crate) fn construct( cb: &mut EVMConstraintBuilder, - sender_address: Word>, - receiver_address: Word>, + sender_address: WordLoHi>, + receiver_address: WordLoHi>, receiver_exists: Expression, must_create: Expression, - // _prev_code_hash: Word>, + // _prev_code_hash: WordLoHi>, value: Word32Cell, reversion_info: &mut ReversionInfo, ) -> Self { @@ -687,7 +687,7 @@ impl TransferGadget { value, )?; self.value_is_zero - .assign_value(region, offset, Value::known(Word::from(value)))?; + .assign_value(region, offset, Value::known(WordLoHi::from(value)))?; Ok(()) } @@ -711,10 +711,10 @@ pub(crate) struct CommonCallGadget>, pub has_value: Expression, - pub callee_code_hash: WordCell, - pub is_empty_code_hash: IsEqualWordGadget, Word>>, + pub callee_code_hash: WordLoHiCell, + pub is_empty_code_hash: IsEqualWordGadget, WordLoHi>>, - pub callee_not_exists: IsZeroWordGadget>, + pub callee_not_exists: IsZeroWordGadget>, // save information is_call: Expression, @@ -767,9 +767,9 @@ impl, const IS_SUCCESS_CAL cb.stack_pop(rd_address.offset_word()); cb.stack_pop(rd_address.length_word()); cb.stack_push(if IS_SUCCESS_CALL { - Word::from_lo_unchecked(is_success.expr()) // is_success is bool + WordLoHi::from_lo_unchecked(is_success.expr()) // is_success is bool } else { - Word::zero() + WordLoHi::zero() }); // Recomposition of random linear combination to integer @@ -816,7 +816,7 @@ impl, const IS_SUCCESS_CAL } } - pub fn callee_address(&self) -> Word> { + pub fn callee_address(&self) -> WordLoHi> { self.callee_address.to_word() } @@ -883,19 +883,19 @@ impl, const IS_SUCCESS_CAL )?; self.value_is_zero - .assign(region, offset, Word::from(value))?; + .assign(region, offset, WordLoHi::from(value))?; self.callee_code_hash .assign_u256(region, offset, callee_code_hash)?; self.is_empty_code_hash.assign_value( region, offset, - Value::known(Word::from(callee_code_hash)), - Value::known(Word::from(CodeDB::empty_code_hash().to_word())), + Value::known(WordLoHi::from(callee_code_hash)), + Value::known(WordLoHi::from(CodeDB::empty_code_hash().to_word())), )?; self.callee_not_exists.assign_value( region, offset, - Value::known(Word::from(callee_code_hash)), + Value::known(WordLoHi::from(callee_code_hash)), )?; Ok(memory_expansion_gas_cost) } @@ -1022,19 +1022,19 @@ impl + Clone> SstoreGasGadget { self.value_eq_prev.assign_value( region, offset, - Value::known(Word::from(value)), - Value::known(Word::from(value_prev)), + Value::known(WordLoHi::from(value)), + Value::known(WordLoHi::from(value_prev)), )?; self.original_eq_prev.assign_value( region, offset, - Value::known(Word::from(original_value)), - Value::known(Word::from(value_prev)), + Value::known(WordLoHi::from(original_value)), + Value::known(WordLoHi::from(value_prev)), )?; self.original_is_zero.assign_value( region, offset, - Value::known(Word::from(original_value)), + Value::known(WordLoHi::from(original_value)), )?; Ok(()) } @@ -1074,7 +1074,7 @@ pub(crate) fn cal_sstore_gas_cost_for_assignment( #[derive(Clone, Debug)] pub(crate) struct CommonErrorGadget { - rw_counter_end_of_reversion: WordCell, + rw_counter_end_of_reversion: WordLoHiCell, restore_context: RestoreContextGadget, } @@ -1099,7 +1099,7 @@ impl CommonErrorGadget { let rw_counter_end_of_reversion = cb.query_word_unchecked(); // rw_counter_end_of_reversion just used for read lookup, therefore skip range check // current call must be failed. - cb.call_context_lookup_read(None, CallContextFieldTag::IsSuccess, Word::zero()); + cb.call_context_lookup_read(None, CallContextFieldTag::IsSuccess, WordLoHi::zero()); cb.call_context_lookup_read( None, @@ -1285,7 +1285,7 @@ impl WordByteRangeGadget { not::expr(self.not_overflow()) } - pub(crate) fn original(&self) -> Word> { + pub(crate) fn original(&self) -> WordLoHi> { self.original.to_word() } diff --git a/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs b/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs index 47bcc616cc..a38026c1ab 100644 --- a/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs +++ b/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs @@ -11,7 +11,7 @@ use crate::{ }, util::{ build_tx_log_expression, query_expression, - word::{Word, Word32, Word32Cell, WordCell, WordExpr}, + word::{Word32, Word32Cell, WordExpr, WordLoHi, WordLoHiCell}, Challenges, Expr, }, }; @@ -59,7 +59,7 @@ pub(crate) struct StepStateTransition { pub(crate) call_id: Transition>, pub(crate) is_root: Transition>, pub(crate) is_create: Transition>, - pub(crate) code_hash: Transition>>, + pub(crate) code_hash: Transition>>, pub(crate) program_counter: Transition>, pub(crate) stack_pointer: Transition>, pub(crate) gas_left: Transition>, @@ -164,15 +164,15 @@ pub(crate) trait ConstrainBuilderCommon { self.add_constraint(name, constraint); } - fn require_zero_word(&mut self, name: &'static str, word: Word>) { - self.require_equal_word(name, word, Word::zero()); + fn require_zero_word(&mut self, name: &'static str, word: WordLoHi>) { + self.require_equal_word(name, word, WordLoHi::zero()); } fn require_equal_word( &mut self, name: &'static str, - lhs: Word>, - rhs: Word>, + lhs: WordLoHi>, + rhs: WordLoHi>, ) { let (lhs_lo, lhs_hi) = lhs.to_lo_hi(); let (rhs_lo, rhs_hi) = rhs.to_lo_hi(); @@ -443,8 +443,8 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { } // default query_word is 2 limbs. Each limb is not guaranteed to be 128 bits. - pub fn query_word_unchecked(&mut self) -> WordCell { - Word::new( + pub fn query_word_unchecked(&mut self) -> WordLoHiCell { + WordLoHi::new( self.query_cells(CellType::StoragePhase1, 2) .try_into() .unwrap(), @@ -511,7 +511,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { rlc::expr(&bytes, self.challenges.keccak_input()) } - pub(crate) fn empty_code_hash(&self) -> Word> { + pub(crate) fn empty_code_hash(&self) -> WordLoHi> { Word32::new(EMPTY_CODE_HASH_LE.map(|byte| byte.expr())).to_word() } @@ -664,7 +664,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { pub(crate) fn bytecode_lookup( &mut self, - code_hash: Word>, + code_hash: WordLoHi>, index: Expression, is_code: Expression, value: Expression, @@ -681,7 +681,11 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { ) } - pub(crate) fn bytecode_length(&mut self, code_hash: Word>, value: Expression) { + pub(crate) fn bytecode_length( + &mut self, + code_hash: WordLoHi>, + value: Expression, + ) { self.add_lookup( "Bytecode (length)", Lookup::Bytecode { @@ -704,7 +708,12 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { ) -> Cell { let cell = self.query_cell(); // lookup read, unchecked is safe - self.tx_context_lookup(id, field_tag, index, Word::from_lo_unchecked(cell.expr())); + self.tx_context_lookup( + id, + field_tag, + index, + WordLoHi::from_lo_unchecked(cell.expr()), + ); cell } pub(crate) fn tx_context_as_word32( @@ -723,7 +732,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { id: Expression, field_tag: TxContextFieldTag, index: Option>, - ) -> WordCell { + ) -> WordLoHiCell { let word = self.query_word_unchecked(); self.tx_context_lookup(id, field_tag, index, word.to_word()); word @@ -734,7 +743,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { id: Expression, field_tag: TxContextFieldTag, index: Option>, - value: Word>, + value: WordLoHi>, ) { self.add_lookup( "Tx lookup", @@ -752,7 +761,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { &mut self, tag: Expression, number: Option>, - val: Word>, + val: WordLoHi>, ) { self.add_lookup( "Block lookup", @@ -853,7 +862,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { pub(crate) fn account_access_list_write_unchecked( &mut self, tx_id: Expression, - account_address: Word>, + account_address: WordLoHi>, value: Expression, value_prev: Expression, reversion_info: Option<&mut ReversionInfo>, @@ -865,10 +874,10 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { tx_id, account_address.compress(), 0.expr(), - Word::zero(), - Word::from_lo_unchecked(value), - Word::from_lo_unchecked(value_prev), - Word::zero(), + WordLoHi::zero(), + WordLoHi::from_lo_unchecked(value), + WordLoHi::from_lo_unchecked(value_prev), + WordLoHi::zero(), ), reversion_info, ); @@ -877,7 +886,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { pub(crate) fn account_access_list_read( &mut self, tx_id: Expression, - account_address: Word>, + account_address: WordLoHi>, value: Expression, ) { self.rw_lookup( @@ -888,20 +897,20 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { tx_id, account_address.compress(), 0.expr(), - Word::zero(), - Word::from_lo_unchecked(value.clone()), - Word::from_lo_unchecked(value), - Word::zero(), + WordLoHi::zero(), + WordLoHi::from_lo_unchecked(value.clone()), + WordLoHi::from_lo_unchecked(value), + WordLoHi::zero(), ), ); } pub(crate) fn account_storage_access_list_write( &mut self, tx_id: Expression, - account_address: Word>, - storage_key: Word>, - value: Word>, - value_prev: Word>, + account_address: WordLoHi>, + storage_key: WordLoHi>, + value: WordLoHi>, + value_prev: WordLoHi>, reversion_info: Option<&mut ReversionInfo>, ) { self.reversible_write( @@ -914,7 +923,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { storage_key, value, value_prev, - Word::zero(), + WordLoHi::zero(), ), reversion_info, ); @@ -923,9 +932,9 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { pub(crate) fn account_storage_access_list_read( &mut self, tx_id: Expression, - account_address: Word>, - storage_key: Word>, - value: Word>, + account_address: WordLoHi>, + storage_key: WordLoHi>, + value: WordLoHi>, ) { self.rw_lookup( "TxAccessListAccountStorage read", @@ -938,14 +947,14 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { storage_key, value.clone(), value, - Word::zero(), + WordLoHi::zero(), ), ); } // Tx Refund - pub(crate) fn tx_refund_read(&mut self, tx_id: Expression, value: Word>) { + pub(crate) fn tx_refund_read(&mut self, tx_id: Expression, value: WordLoHi>) { self.rw_lookup( "TxRefund read", false.expr(), @@ -954,10 +963,10 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { tx_id, 0.expr(), 0.expr(), - Word::zero(), + WordLoHi::zero(), value.clone(), value, - Word::zero(), + WordLoHi::zero(), ), ); } @@ -965,8 +974,8 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { pub(crate) fn tx_refund_write( &mut self, tx_id: Expression, - value: Word>, - value_prev: Word>, + value: WordLoHi>, + value_prev: WordLoHi>, reversion_info: Option<&mut ReversionInfo>, ) { self.reversible_write( @@ -976,10 +985,10 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { tx_id, 0.expr(), 0.expr(), - Word::zero(), + WordLoHi::zero(), value, value_prev, - Word::zero(), + WordLoHi::zero(), ), reversion_info, ); @@ -988,9 +997,9 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { // Account pub(crate) fn account_read( &mut self, - account_address: Word>, + account_address: WordLoHi>, field_tag: AccountFieldTag, - value: Word>, + value: WordLoHi>, ) { self.rw_lookup( "Account read", @@ -1000,20 +1009,20 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { 0.expr(), account_address.compress(), field_tag.expr(), - Word::zero(), + WordLoHi::zero(), value.clone(), value, - Word::zero(), + WordLoHi::zero(), ), ); } pub(crate) fn account_write( &mut self, - account_address: Word>, + account_address: WordLoHi>, field_tag: AccountFieldTag, - value: Word>, - value_prev: Word>, + value: WordLoHi>, + value_prev: WordLoHi>, reversion_info: Option<&mut ReversionInfo>, ) { self.reversible_write( @@ -1023,10 +1032,10 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { 0.expr(), account_address.compress(), field_tag.expr(), - Word::zero(), + WordLoHi::zero(), value, value_prev, - Word::zero(), + WordLoHi::zero(), ), reversion_info, ); @@ -1035,11 +1044,11 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { // Account Storage pub(crate) fn account_storage_read( &mut self, - account_address: Word>, - key: Word>, - value: Word>, + account_address: WordLoHi>, + key: WordLoHi>, + value: WordLoHi>, tx_id: Expression, - committed_value: Word>, + committed_value: WordLoHi>, ) { self.rw_lookup( "account_storage_read", @@ -1060,12 +1069,12 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { #[allow(clippy::too_many_arguments)] pub(crate) fn account_storage_write( &mut self, - account_address: Word>, - key: Word>, - value: Word>, - value_prev: Word>, + account_address: WordLoHi>, + key: WordLoHi>, + value: WordLoHi>, + value_prev: WordLoHi>, tx_id: Expression, - committed_value: Word>, + committed_value: WordLoHi>, reversion_info: Option<&mut ReversionInfo>, ) { self.reversible_write( @@ -1098,7 +1107,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { self.call_context_lookup_read( call_id, field_tag, - Word::from_lo_unchecked(cell.expr()), // lookup read, unchecked is safe + WordLoHi::from_lo_unchecked(cell.expr()), // lookup read, unchecked is safe ); cell } @@ -1107,7 +1116,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { &mut self, call_id: Option>, field_tag: CallContextFieldTag, - ) -> Word> { + ) -> WordLoHi> { let word = self.query_word_unchecked(); self.call_context_lookup_read(call_id, field_tag, word.to_word()); word @@ -1117,7 +1126,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { &mut self, call_id: Option>, field_tag: CallContextFieldTag, - value: Word>, + value: WordLoHi>, ) { self.rw_lookup( "CallContext lookup", @@ -1127,10 +1136,10 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { call_id.unwrap_or_else(|| self.curr.state.call_id.expr()), 0.expr(), field_tag.expr(), - Word::zero(), + WordLoHi::zero(), value, - Word::zero(), - Word::zero(), + WordLoHi::zero(), + WordLoHi::zero(), ), ); } @@ -1142,7 +1151,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { rw_counter: Expression, call_id: Option>, field_tag: CallContextFieldTag, - value: Word>, + value: WordLoHi>, ) { self.rw_lookup_with_counter( "CallContext lookup", @@ -1153,10 +1162,10 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { call_id.unwrap_or_else(|| self.curr.state.call_id.expr()), 0.expr(), field_tag.expr(), - Word::zero(), + WordLoHi::zero(), value, - Word::zero(), - Word::zero(), + WordLoHi::zero(), + WordLoHi::zero(), ), ); } @@ -1165,7 +1174,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { &mut self, call_id: Option>, field_tag: CallContextFieldTag, - value: Word>, + value: WordLoHi>, ) { self.rw_lookup( "CallContext lookup", @@ -1175,10 +1184,10 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { call_id.unwrap_or_else(|| self.curr.state.call_id.expr()), 0.expr(), field_tag.expr(), - Word::zero(), + WordLoHi::zero(), value, - Word::zero(), - Word::zero(), + WordLoHi::zero(), + WordLoHi::zero(), ), ); } @@ -1198,13 +1207,13 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { self.call_context_lookup_write( call_id.clone(), field_tag, - Word::from_lo_unchecked(cell.expr()), + WordLoHi::from_lo_unchecked(cell.expr()), ); } else { self.call_context_lookup_read( call_id.clone(), field_tag, - Word::from_lo_unchecked(cell.expr()), + WordLoHi::from_lo_unchecked(cell.expr()), ); } @@ -1237,12 +1246,12 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { } // Stack - pub(crate) fn stack_pop(&mut self, value: Word>) { + pub(crate) fn stack_pop(&mut self, value: WordLoHi>) { self.stack_lookup(false.expr(), self.stack_pointer_offset.clone(), value); self.stack_pointer_offset = self.stack_pointer_offset.clone() + self.condition_expr(); } - pub(crate) fn stack_push(&mut self, value: Word>) { + pub(crate) fn stack_push(&mut self, value: WordLoHi>) { self.stack_pointer_offset = self.stack_pointer_offset.clone() - self.condition_expr(); self.stack_lookup(true.expr(), self.stack_pointer_offset.expr(), value); } @@ -1251,7 +1260,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { &mut self, is_write: Expression, stack_pointer_offset: Expression, - value: Word>, + value: WordLoHi>, ) { self.rw_lookup( "Stack lookup", @@ -1261,10 +1270,10 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { self.curr.state.call_id.expr(), self.curr.state.stack_pointer.expr() + stack_pointer_offset, 0.expr(), - Word::zero(), + WordLoHi::zero(), value, - Word::zero(), - Word::zero(), + WordLoHi::zero(), + WordLoHi::zero(), ), ); } @@ -1286,11 +1295,11 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { call_id.unwrap_or_else(|| self.curr.state.call_id.expr()), memory_address, 0.expr(), - Word::zero(), + WordLoHi::zero(), // TODO assure range check since write=true also possible - Word::from_lo_unchecked(byte), - Word::zero(), - Word::zero(), + WordLoHi::from_lo_unchecked(byte), + WordLoHi::zero(), + WordLoHi::zero(), ), ); } @@ -1301,7 +1310,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { log_id: Expression, field_tag: TxLogFieldTag, index: Expression, - value: Word>, + value: WordLoHi>, ) { self.rw_lookup( "log data lookup", @@ -1311,10 +1320,10 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { tx_id, build_tx_log_expression(index, field_tag.expr(), log_id), 0.expr(), - Word::zero(), + WordLoHi::zero(), value, - Word::zero(), - Word::zero(), + WordLoHi::zero(), + WordLoHi::zero(), ), ); } @@ -1335,11 +1344,11 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { tx_id, 0.expr(), tag.expr(), - Word::zero(), + WordLoHi::zero(), // TODO assure range check since write=true also possible - Word::from_lo_unchecked(value), - Word::zero(), - Word::zero(), + WordLoHi::from_lo_unchecked(value), + WordLoHi::zero(), + WordLoHi::zero(), ), ); } @@ -1356,10 +1365,10 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { 0.expr(), 0.expr(), 0.expr(), - Word::zero(), - Word::zero(), - Word::zero(), - Word::zero(), + WordLoHi::zero(), + WordLoHi::zero(), + WordLoHi::zero(), + WordLoHi::zero(), ), ); } @@ -1369,9 +1378,9 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { #[allow(clippy::too_many_arguments)] pub(crate) fn copy_table_lookup( &mut self, - src_id: Word>, + src_id: WordLoHi>, src_tag: Expression, - dst_id: Word>, + dst_id: WordLoHi>, dst_tag: Expression, src_addr: Expression, src_addr_end: Expression, @@ -1428,7 +1437,7 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { &mut self, input_rlc: Expression, input_len: Expression, - output: Word>, + output: WordLoHi>, ) { self.add_lookup( "keccak lookup", diff --git a/zkevm-circuits/src/evm_circuit/util/math_gadget/cmp_words.rs b/zkevm-circuits/src/evm_circuit/util/math_gadget/cmp_words.rs index ed170d9c64..44fc4248b0 100644 --- a/zkevm-circuits/src/evm_circuit/util/math_gadget/cmp_words.rs +++ b/zkevm-circuits/src/evm_circuit/util/math_gadget/cmp_words.rs @@ -80,7 +80,7 @@ impl, T2: WordExpr> CmpWordsGadget { mod tests { use super::{test_util::*, *}; use crate::{ - evm_circuit::util::constraint_builder::ConstrainBuilderCommon, util::word::WordCell, + evm_circuit::util::constraint_builder::ConstrainBuilderCommon, util::word::WordLoHiCell, }; use eth_types::Word; use halo2_proofs::{halo2curves::bn256::Fr, plonk::Error}; @@ -88,9 +88,9 @@ mod tests { #[derive(Clone)] /// CmpWordGadgetTestContainer: require(a == b if CHECK_EQ else a < b) struct CmpWordGadgetTestContainer { - cmp_gadget: CmpWordsGadget, WordCell>, - a_word: WordCell, - b_word: WordCell, + cmp_gadget: CmpWordsGadget, WordLoHiCell>, + a_word: WordLoHiCell, + b_word: WordLoHiCell, } impl MathGadgetContainer diff --git a/zkevm-circuits/src/evm_circuit/util/math_gadget/is_equal_word.rs b/zkevm-circuits/src/evm_circuit/util/math_gadget/is_equal_word.rs index 5109d47061..75ebc05f85 100644 --- a/zkevm-circuits/src/evm_circuit/util/math_gadget/is_equal_word.rs +++ b/zkevm-circuits/src/evm_circuit/util/math_gadget/is_equal_word.rs @@ -11,7 +11,7 @@ use crate::{ evm_circuit::util::{ constraint_builder::EVMConstraintBuilder, transpose_val_ret, CachedRegion, }, - util::word::{Word, WordExpr}, + util::word::{WordExpr, WordLoHi}, }; use super::IsZeroGadget; @@ -46,8 +46,8 @@ impl, T2: WordExpr> IsEqualWordGadget { &self, region: &mut CachedRegion<'_, '_, F>, offset: usize, - lhs: Word, - rhs: Word, + lhs: WordLoHi, + rhs: WordLoHi, ) -> Result { let (lhs_lo, lhs_hi) = lhs.to_lo_hi(); let (rhs_lo, rhs_hi) = rhs.to_lo_hi(); @@ -60,8 +60,8 @@ impl, T2: WordExpr> IsEqualWordGadget { &self, region: &mut CachedRegion<'_, '_, F>, offset: usize, - lhs: Value>, - rhs: Value>, + lhs: Value>, + rhs: Value>, ) -> Result, Error> { transpose_val_ret( lhs.zip(rhs) @@ -76,7 +76,7 @@ impl, T2: WordExpr> IsEqualWordGadget { lhs: eth_types::Word, rhs: eth_types::Word, ) -> Result { - self.assign(region, offset, Word::from(lhs), Word::from(rhs)) + self.assign(region, offset, WordLoHi::from(lhs), WordLoHi::from(rhs)) } } diff --git a/zkevm-circuits/src/evm_circuit/util/math_gadget/is_zero_word.rs b/zkevm-circuits/src/evm_circuit/util/math_gadget/is_zero_word.rs index f74ccf6a96..47ee7c9ce0 100644 --- a/zkevm-circuits/src/evm_circuit/util/math_gadget/is_zero_word.rs +++ b/zkevm-circuits/src/evm_circuit/util/math_gadget/is_zero_word.rs @@ -12,7 +12,7 @@ use crate::{ constraint_builder::{ConstrainBuilderCommon, EVMConstraintBuilder}, transpose_val_ret, CachedRegion, Cell, CellType, }, - util::word::{Word, WordExpr}, + util::word::{WordExpr, WordLoHi}, }; /// Returns `1` when `word == 0`, and returns `0` otherwise. @@ -69,7 +69,7 @@ impl> IsZeroWordGadget { &self, region: &mut CachedRegion<'_, '_, F>, offset: usize, - value: Word, + value: WordLoHi, ) -> Result { let (value_lo, value_hi) = value.to_lo_hi(); let inverse_lo = value_lo.invert().unwrap_or(F::from(0)); @@ -91,14 +91,14 @@ impl> IsZeroWordGadget { offset: usize, value: eth_types::Word, ) -> Result { - self.assign(region, offset, Word::from(value)) + self.assign(region, offset, WordLoHi::from(value)) } pub(crate) fn assign_value( &self, region: &mut CachedRegion<'_, '_, F>, offset: usize, - value: Value>, + value: Value>, ) -> Result, Error> { transpose_val_ret(value.map(|value| self.assign(region, offset, value))) } diff --git a/zkevm-circuits/src/evm_circuit/util/math_gadget/lt_word.rs b/zkevm-circuits/src/evm_circuit/util/math_gadget/lt_word.rs index 37899253b8..c27825aa4a 100644 --- a/zkevm-circuits/src/evm_circuit/util/math_gadget/lt_word.rs +++ b/zkevm-circuits/src/evm_circuit/util/math_gadget/lt_word.rs @@ -2,7 +2,7 @@ use crate::{ evm_circuit::util::{ constraint_builder::EVMConstraintBuilder, math_gadget::*, split_u256, CachedRegion, }, - util::word::{self}, + util::word::WordLoHi, }; use eth_types::{Field, Word}; use halo2_proofs::plonk::{Error, Expression}; @@ -18,8 +18,8 @@ pub struct LtWordGadget { impl LtWordGadget { pub(crate) fn construct + Clone>( cb: &mut EVMConstraintBuilder, - lhs: &word::Word, - rhs: &word::Word, + lhs: &WordLoHi, + rhs: &WordLoHi, ) -> Self { let (lhs_lo, lhs_hi) = lhs.to_lo_hi(); let (rhs_lo, rhs_hi) = rhs.to_lo_hi(); diff --git a/zkevm-circuits/src/evm_circuit/util/math_gadget/modulo.rs b/zkevm-circuits/src/evm_circuit/util/math_gadget/modulo.rs index 4a8fa8726e..3409c4861d 100644 --- a/zkevm-circuits/src/evm_circuit/util/math_gadget/modulo.rs +++ b/zkevm-circuits/src/evm_circuit/util/math_gadget/modulo.rs @@ -5,7 +5,7 @@ use crate::{ CachedRegion, }, util::{ - word::{self, Word32Cell, WordExpr}, + word::{Word32Cell, WordExpr, WordLoHi}, Expr, }, }; @@ -82,17 +82,17 @@ impl ModGadget { self.k.assign_u256(region, offset, k)?; self.a_or_zero.assign_u256(region, offset, a_or_zero)?; - self.n_is_zero.assign(region, offset, word::Word::from(n))?; + self.n_is_zero.assign(region, offset, WordLoHi::from(n))?; self.a_or_is_zero - .assign(region, offset, word::Word::from(a_or_zero))?; + .assign(region, offset, WordLoHi::from(a_or_zero))?; self.mul_add_words .assign(region, offset, [k, n, r, a_or_zero])?; self.lt.assign(region, offset, r, n)?; self.eq.assign_value( region, offset, - Value::known(word::Word::from(a)), - Value::known(word::Word::from(a_or_zero)), + Value::known(WordLoHi::from(a)), + Value::known(WordLoHi::from(a_or_zero)), )?; Ok(()) diff --git a/zkevm-circuits/src/evm_circuit/util/math_gadget/mul_add_words.rs b/zkevm-circuits/src/evm_circuit/util/math_gadget/mul_add_words.rs index 85b9ee0b7c..e94d49897b 100644 --- a/zkevm-circuits/src/evm_circuit/util/math_gadget/mul_add_words.rs +++ b/zkevm-circuits/src/evm_circuit/util/math_gadget/mul_add_words.rs @@ -4,7 +4,7 @@ use crate::{ from_bytes, pow_of_two_expr, split_u256, split_u256_limb64, CachedRegion, Cell, }, util::{ - word::{Word, Word32Cell, Word4, WordExpr}, + word::{Word32Cell, Word4, WordExpr, WordLoHi}, Expr, }, }; @@ -68,8 +68,8 @@ impl MulAddWordsGadget { b_limbs.push(word4_b.limbs[i].expr()); } - let word_c: Word> = c.to_word(); - let word_d: Word> = d.to_word(); + let word_c: WordLoHi> = c.to_word(); + let word_d: WordLoHi> = d.to_word(); let t0 = a_limbs[0].clone() * b_limbs[0].clone(); let t1 = a_limbs[0].clone() * b_limbs[1].clone() + a_limbs[1].clone() * b_limbs[0].clone(); diff --git a/zkevm-circuits/src/evm_circuit/util/math_gadget/mul_add_words512.rs b/zkevm-circuits/src/evm_circuit/util/math_gadget/mul_add_words512.rs index c4becb836e..27562c961b 100644 --- a/zkevm-circuits/src/evm_circuit/util/math_gadget/mul_add_words512.rs +++ b/zkevm-circuits/src/evm_circuit/util/math_gadget/mul_add_words512.rs @@ -4,7 +4,7 @@ use crate::{ from_bytes, pow_of_two_expr, split_u256, split_u256_limb64, CachedRegion, Cell, }, util::{ - word::{self, Word4, WordExpr}, + word::{Word32Cell, Word4, WordExpr}, Expr, }, }; @@ -57,8 +57,8 @@ impl MulAddWords512Gadget { /// Addend is the optional c. pub(crate) fn construct( cb: &mut EVMConstraintBuilder, - words: [&word::Word32Cell; 4], - addend: Option<&word::Word32Cell>, + words: [&Word32Cell; 4], + addend: Option<&Word32Cell>, ) -> Self { let carry_0 = cb.query_bytes(); let carry_1 = cb.query_bytes(); @@ -207,11 +207,11 @@ mod tests { /// MulAddWords512GadgetContainer: require(a * b + c == d * 2**256 + e) struct MulAddWords512GadgetContainer { math_gadget: MulAddWords512Gadget, - a: word::Word32Cell, - b: word::Word32Cell, - d: word::Word32Cell, - e: word::Word32Cell, - addend: word::Word32Cell, + a: Word32Cell, + b: Word32Cell, + d: Word32Cell, + e: Word32Cell, + addend: Word32Cell, } impl MathGadgetContainer for MulAddWords512GadgetContainer { diff --git a/zkevm-circuits/src/evm_circuit/util/math_gadget/rlp.rs b/zkevm-circuits/src/evm_circuit/util/math_gadget/rlp.rs index 4b6419b881..6883049b48 100644 --- a/zkevm-circuits/src/evm_circuit/util/math_gadget/rlp.rs +++ b/zkevm-circuits/src/evm_circuit/util/math_gadget/rlp.rs @@ -1,7 +1,3 @@ -use crate::{ - evm_circuit::util::rlc, - util::word::{Word32Cell, WordExpr}, -}; use eth_types::{Address, Field, ToScalar, Word}; use gadgets::util::{and, expr_from_bytes, not, select, sum, Expr}; use halo2_proofs::{ @@ -14,10 +10,10 @@ use crate::{ param::{N_BYTES_U64, N_BYTES_WORD}, util::{ constraint_builder::{ConstrainBuilderCommon, EVMConstraintBuilder}, - AccountAddress, CachedRegion, Cell, RandomLinearCombination, + rlc, AccountAddress, CachedRegion, Cell, RandomLinearCombination, }, }, - util::word, + util::word::{Word32Cell, WordExpr, WordLoHi}, }; use super::IsZeroGadget; @@ -260,7 +256,7 @@ impl ContractCreateGadget { } /// Caller address' value. - pub(crate) fn caller_address(&self) -> word::Word> { + pub(crate) fn caller_address(&self) -> WordLoHi> { self.caller_address.to_word() } @@ -270,7 +266,7 @@ impl ContractCreateGadget { } /// Code hash word RLC. - pub(crate) fn code_hash(&self) -> word::Word> { + pub(crate) fn code_hash(&self) -> WordLoHi> { self.code_hash.to_word() } @@ -287,7 +283,7 @@ impl ContractCreateGadget { ) } - pub(crate) fn salt(&self) -> word::Word> { + pub(crate) fn salt(&self) -> WordLoHi> { self.salt.to_word() } diff --git a/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs b/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs index d9bf830820..eef9446fe3 100644 --- a/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs +++ b/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs @@ -14,7 +14,7 @@ use crate::{ }, }, util::{ - word::{Word, WordCell}, + word::{WordLoHi, WordLoHiCell}, Expr, }, }; @@ -55,10 +55,10 @@ pub(crate) trait CommonMemoryAddressGadget { ) -> Result; /// Return original word of memory offset. - fn offset_word(&self) -> Word>; + fn offset_word(&self) -> WordLoHi>; /// Return original word of memory length. - fn length_word(&self) -> Word>; + fn length_word(&self) -> WordLoHi>; /// Return valid memory length of Uint64. fn length(&self) -> Expression; @@ -74,7 +74,7 @@ pub(crate) trait CommonMemoryAddressGadget { #[derive(Clone, Debug)] pub(crate) struct MemoryAddressGadget { memory_offset_bytes: MemoryAddress, - memory_offset: WordCell, + memory_offset: WordLoHiCell, memory_length: MemoryAddress, memory_length_is_zero: IsZeroGadget, } @@ -82,7 +82,7 @@ pub(crate) struct MemoryAddressGadget { impl MemoryAddressGadget { pub(crate) fn construct( cb: &mut EVMConstraintBuilder, - memory_offset: WordCell, + memory_offset: WordLoHiCell, memory_length: MemoryAddress, ) -> Self { let memory_length_is_zero = IsZeroGadget::construct(cb, memory_length.sum_expr()); @@ -92,7 +92,7 @@ impl MemoryAddressGadget { cb.condition(has_length, |cb| { cb.require_equal_word( "Offset decomposition into 5 bytes", - Word::from_lo_unchecked(memory_offset_bytes.expr()), + WordLoHi::from_lo_unchecked(memory_offset_bytes.expr()), memory_offset.to_word(), ); }); @@ -157,11 +157,11 @@ impl CommonMemoryAddressGadget for MemoryAddressGadget { }) } - fn offset_word(&self) -> Word> { + fn offset_word(&self) -> WordLoHi> { self.memory_offset.to_word() } - fn length_word(&self) -> Word> { + fn length_word(&self) -> WordLoHi> { self.memory_length.to_word() } @@ -260,12 +260,12 @@ impl CommonMemoryAddressGadget for MemoryExpandedAddressGadget { Ok(address) } - fn offset_word(&self) -> Word> { + fn offset_word(&self) -> WordLoHi> { let addends = self.offset_length_sum.addends(); addends[0].to_word() } - fn length_word(&self) -> Word> { + fn length_word(&self) -> WordLoHi> { let addends = self.offset_length_sum.addends(); addends[1].to_word() } diff --git a/zkevm-circuits/src/evm_circuit/util/tx.rs b/zkevm-circuits/src/evm_circuit/util/tx.rs index d3987300ed..0ac5cc4a01 100644 --- a/zkevm-circuits/src/evm_circuit/util/tx.rs +++ b/zkevm-circuits/src/evm_circuit/util/tx.rs @@ -9,12 +9,12 @@ use crate::{ math_gadget::{ AddWordsGadget, ConstantDivisionGadget, IsEqualGadget, MulWordByU64Gadget, }, - CachedRegion, Cell, Word, + CachedRegion, Cell, }, witness::{Block, Transaction}, }, table::{CallContextFieldTag, TxContextFieldTag, TxReceiptFieldTag}, - util::word::{Word32Cell, WordCell}, + util::word::{Word32Cell, WordLoHi, WordLoHiCell}, }; use bus_mapping::operation::Target; use eth_types::{evm_types::GasCost, Field}; @@ -42,7 +42,7 @@ impl BeginTxHelperGadget { cb.call_context_lookup_write( Some(call_id.expr()), CallContextFieldTag::TxId, - Word::from_lo_unchecked(tx_id.expr()), + WordLoHi::from_lo_unchecked(tx_id.expr()), ); // rwc_delta += 1 // Add first BeginTx step constraint to have id == 1 @@ -133,7 +133,7 @@ impl EndTxHelperGadget { Some(next_step_rwc), CallContextFieldTag::TxId, // tx_id has been lookup and range_check above - Word::from_lo_unchecked(tx_id.expr() + 1.expr()), + WordLoHi::from_lo_unchecked(tx_id.expr() + 1.expr()), ); // minus 1.expr() because `call_context_lookup_write_with_counter` do not bump // rwc @@ -196,8 +196,8 @@ impl EndTxHelperGadget { #[derive(Clone, Debug)] pub(crate) struct TxDataGadget { pub(crate) nonce: Cell, - pub(crate) caller_address: WordCell, - pub(crate) callee_address: WordCell, + pub(crate) caller_address: WordLoHiCell, + pub(crate) callee_address: WordLoHiCell, pub(crate) is_create: Cell, pub(crate) gas: Cell, pub(crate) call_data_length: Cell, diff --git a/zkevm-circuits/src/instance.rs b/zkevm-circuits/src/instance.rs index fd3f67510b..a1ecc1cf92 100644 --- a/zkevm-circuits/src/instance.rs +++ b/zkevm-circuits/src/instance.rs @@ -7,7 +7,7 @@ use std::{iter, ops::Deref}; use eth_types::{geth_types::Transaction, Address, ToBigEndian, Word, H256}; use itertools::Itertools; -use crate::{util::word, witness::Block}; +use crate::{util::word::WordLoHi, witness::Block}; pub(super) const ZERO_BYTE_GAS_COST: u64 = 4; pub(super) const NONZERO_BYTE_GAS_COST: u64 = 16; @@ -289,11 +289,11 @@ impl PublicData { max_txs: usize, max_withdrawals: usize, max_calldata: usize, - ) -> word::Word { + ) -> WordLoHi { let mut keccak = Keccak::default(); keccak.update(&self.get_pi_bytes(max_txs, max_withdrawals, max_calldata)); let digest = keccak.digest(); - word::Word::from(Word::from_big_endian(&digest)) + WordLoHi::from(Word::from_big_endian(&digest)) } } diff --git a/zkevm-circuits/src/keccak_circuit.rs b/zkevm-circuits/src/keccak_circuit.rs index 64a4a27aa5..b02544fec5 100644 --- a/zkevm-circuits/src/keccak_circuit.rs +++ b/zkevm-circuits/src/keccak_circuit.rs @@ -32,7 +32,7 @@ use crate::{ table::{KeccakTable, LookupTable}, util::{ cell_manager::{CMFixedHeightStrategy, Cell, CellManager, CellType}, - word::{self, WordExpr}, + word::{Word32, WordExpr}, Challenges, SubCircuit, SubCircuitConfig, }, witness, @@ -580,7 +580,7 @@ impl SubCircuitConfig for KeccakCircuitConfig { cb.condition(start_new_hash, |cb| { cb.require_equal_word( "output check", - word::Word32::new(hash_bytes_le.try_into().expect("32 limbs")).to_word(), + Word32::new(hash_bytes_le.try_into().expect("32 limbs")).to_word(), hash_word.map(|col| meta.query_advice(col, Rotation::cur())), ); }); diff --git a/zkevm-circuits/src/keccak_circuit/keccak_packed_multi.rs b/zkevm-circuits/src/keccak_circuit/keccak_packed_multi.rs index 7d90ebc8d2..26a4aea374 100644 --- a/zkevm-circuits/src/keccak_circuit/keccak_packed_multi.rs +++ b/zkevm-circuits/src/keccak_circuit/keccak_packed_multi.rs @@ -1,7 +1,7 @@ use super::{param::*, util::*, DEFAULT_CELL_TYPE}; use crate::util::{ cell_manager::{CMFixedHeightStrategy, Cell, CellManager}, - word::Word, + word::WordLoHi, Challenges, }; use eth_types::Field; @@ -81,7 +81,7 @@ pub(crate) struct KeccakRow { pub(crate) cell_values: Vec, pub(crate) length: usize, pub(crate) data_rlc: Value, - pub(crate) hash: Word>, + pub(crate) hash: WordLoHi>, } /// Part @@ -562,7 +562,7 @@ pub(crate) fn keccak( let mut cell_managers = Vec::new(); let mut regions = Vec::new(); - let mut hash = Word::default(); + let mut hash = WordLoHi::default(); let mut round_lengths = Vec::new(); let mut round_data_rlcs = Vec::new(); for round in 0..NUM_ROUNDS + 1 { @@ -795,13 +795,13 @@ pub(crate) fn keccak( .rev() .collect::>(); - let word: Word> = Word::from(eth_types::Word::from_little_endian( + let word: WordLoHi> = WordLoHi::from(eth_types::Word::from_little_endian( hash_bytes_le.as_slice(), )) .map(Value::known); word } else { - Word::default().into_value() + WordLoHi::default().into_value() }; // The words to squeeze out @@ -888,7 +888,7 @@ pub(crate) fn multi_keccak( is_final: false, length: 0usize, data_rlc: Value::known(F::ZERO), - hash: Word::default().into_value(), + hash: WordLoHi::default().into_value(), cell_values: Vec::new(), }); } diff --git a/zkevm-circuits/src/keccak_circuit/test.rs b/zkevm-circuits/src/keccak_circuit/test.rs index aeb57474b4..90e163b1e9 100644 --- a/zkevm-circuits/src/keccak_circuit/test.rs +++ b/zkevm-circuits/src/keccak_circuit/test.rs @@ -1,7 +1,7 @@ use super::*; use crate::{ evm_circuit::util::rlc, - util::{unusable_rows, word::Word}, + util::{unusable_rows, word::WordLoHi}, }; use bus_mapping::state_db::EMPTY_CODE_HASH_LE; use eth_types::{Field, H256, U256}; @@ -86,7 +86,7 @@ fn verify(k: u32, inputs: Vec>, digests: Vec, success: for (input, digest, hash) in izip!(&inputs, &digests, &hash_lookup_table) { let len = F::from(input.len() as u64); let digest_slice: [u8; 32] = hex::decode(digest).unwrap().try_into().unwrap(); - let (lo, hi): (F, F) = Word::from(H256::from(digest_slice)).to_lo_hi(); + let (lo, hi): (F, F) = WordLoHi::from(H256::from(digest_slice)).to_lo_hi(); let expected = (rlc_input(input), len, lo, hi); @@ -95,7 +95,8 @@ fn verify(k: u32, inputs: Vec>, digests: Vec, success: assert_eq!(hash.2, expected.2); assert_eq!(hash.3, expected.3); } - let (lo, hi) = Word::from(U256::from_little_endian(EMPTY_CODE_HASH_LE.as_slice())).to_lo_hi(); + let (lo, hi) = + WordLoHi::from(U256::from_little_endian(EMPTY_CODE_HASH_LE.as_slice())).to_lo_hi(); // Check that other digests are the digest of the empty message. let empty_hash = (F::ZERO, F::ZERO, lo, hi); diff --git a/zkevm-circuits/src/mpt_circuit/account_leaf.rs b/zkevm-circuits/src/mpt_circuit/account_leaf.rs index 73f805cdbe..35d27bc4c6 100644 --- a/zkevm-circuits/src/mpt_circuit/account_leaf.rs +++ b/zkevm-circuits/src/mpt_circuit/account_leaf.rs @@ -30,7 +30,7 @@ use crate::{ MPTConfig, MPTContext, MptMemory, RlpItemType, }, table::MPTProofType, - util::word::{self, Word}, + util::word::WordLoHi, witness::MptUpdateRow, }; @@ -149,10 +149,10 @@ impl AccountLeafConfig { require!(config.main_data.is_below_account => false); let mut key_rlc = vec![0.expr(); 2]; - let mut nonce = vec![Word::zero(); 2]; - let mut balance = vec![Word::zero(); 2]; - let mut storage = vec![Word::zero(); 2]; - let mut codehash = vec![Word::zero(); 2]; + let mut nonce = vec![WordLoHi::zero(); 2]; + let mut balance = vec![WordLoHi::zero(); 2]; + let mut storage = vec![WordLoHi::zero(); 2]; + let mut codehash = vec![WordLoHi::zero(); 2]; let mut leaf_no_key_rlc = vec![0.expr(); 2]; let mut leaf_no_key_rlc_mult = vec![0.expr(); 2]; let mut value_list_num_bytes = vec![0.expr(); 2]; @@ -292,7 +292,7 @@ impl AccountLeafConfig { ifx! {parent_data[is_s.idx()].is_root.expr() => { // If leaf is placeholder and the parent is root (no branch above leaf) and the proof is NonExistingStorageProof, // the trie needs to be empty. - let empty_hash = Word::::from(U256::from_big_endian(&EMPTY_TRIE_HASH)); + let empty_hash = WordLoHi::::from(U256::from_big_endian(&EMPTY_TRIE_HASH)); let hash = parent_data[is_s.idx()].hash.expr(); require!(hash.lo() => Expression::Constant(empty_hash.lo())); require!(hash.hi() => Expression::Constant(empty_hash.hi())); @@ -467,11 +467,11 @@ impl AccountLeafConfig { &mut cb.base, address.clone(), proof_type.clone(), - Word::zero(), + WordLoHi::zero(), config.main_data.new_root.expr(), config.main_data.old_root.expr(), - Word::>::new([new_value_lo, new_value_hi]), - Word::>::new([old_value_lo.clone(), old_value_hi.clone()]), + WordLoHi::>::new([new_value_lo, new_value_hi]), + WordLoHi::>::new([old_value_lo.clone(), old_value_hi.clone()]), ); } elsex { // Non-existing proof doesn't have the value set to 0 in the case of a wrong leaf - we set it to 0 @@ -481,11 +481,11 @@ impl AccountLeafConfig { &mut cb.base, address.clone(), proof_type.clone(), - Word::zero(), + WordLoHi::zero(), config.main_data.new_root.expr(), config.main_data.old_root.expr(), - Word::zero(), - Word::zero(), + WordLoHi::zero(), + WordLoHi::zero(), ); }}; } elsex { @@ -499,11 +499,11 @@ impl AccountLeafConfig { &mut cb.base, address, proof_type, - Word::zero(), + WordLoHi::zero(), config.main_data.new_root.expr(), config.main_data.old_root.expr(), - Word::zero(), - Word::>::new([old_value_lo, old_value_hi]), + WordLoHi::zero(), + WordLoHi::>::new([old_value_lo, old_value_hi]), ); }}; }); @@ -554,10 +554,10 @@ impl AccountLeafConfig { // Key let mut key_rlc = vec![0.scalar(); 2]; - let mut nonce = vec![Word::zero(); 2]; - let mut balance = vec![Word::zero(); 2]; - let mut storage = vec![Word::zero(); 2]; - let mut codehash = vec![Word::zero(); 2]; + let mut nonce = vec![WordLoHi::zero(); 2]; + let mut balance = vec![WordLoHi::zero(); 2]; + let mut storage = vec![WordLoHi::zero(); 2]; + let mut codehash = vec![WordLoHi::zero(); 2]; let mut key_data = vec![KeyDataWitness::default(); 2]; let mut parent_data = vec![ParentDataWitness::default(); 2]; for is_s in [true, false] { @@ -727,11 +727,11 @@ impl AccountLeafConfig { } else if is_codehash_mod { (MPTProofType::CodeHashChanged, codehash) } else if is_account_delete_mod { - (MPTProofType::AccountDestructed, vec![Word::zero(); 2]) + (MPTProofType::AccountDestructed, vec![WordLoHi::zero(); 2]) } else if is_non_existing_proof { - (MPTProofType::AccountDoesNotExist, vec![Word::zero(); 2]) + (MPTProofType::AccountDoesNotExist, vec![WordLoHi::zero(); 2]) } else { - (MPTProofType::Disabled, vec![Word::zero(); 2]) + (MPTProofType::Disabled, vec![WordLoHi::zero(); 2]) }; if account.is_mod_extension[0] || account.is_mod_extension[1] { @@ -746,10 +746,10 @@ impl AccountLeafConfig { let mut new_value = value[false.idx()]; let mut old_value = value[true.idx()]; if parent_data[false.idx()].is_placeholder { - new_value = word::Word::zero(); + new_value = WordLoHi::zero(); } else if is_non_existing_proof { - new_value = word::Word::zero(); - old_value = word::Word::zero(); + new_value = WordLoHi::zero(); + old_value = WordLoHi::zero(); } mpt_config.mpt_table.assign_cached( region, @@ -758,7 +758,7 @@ impl AccountLeafConfig { address: Value::known(from_bytes::value( &account.address.iter().cloned().rev().collect::>(), )), - storage_key: word::Word::zero().into_value(), + storage_key: WordLoHi::zero().into_value(), proof_type: Value::known(proof_type.scalar()), new_root: main_data.new_root.into_value(), old_root: main_data.old_root.into_value(), diff --git a/zkevm-circuits/src/mpt_circuit/branch.rs b/zkevm-circuits/src/mpt_circuit/branch.rs index 8aeae402dd..56ba3e8312 100644 --- a/zkevm-circuits/src/mpt_circuit/branch.rs +++ b/zkevm-circuits/src/mpt_circuit/branch.rs @@ -13,7 +13,7 @@ use crate::{ circuit, circuit_tools::{ cached_region::CachedRegion, - cell_manager::{Cell, WordCell}, + cell_manager::{Cell, WordLoHiCell}, constraint_builder::RLCChainableRev, gadgets::LtGadget, }, @@ -22,7 +22,7 @@ use crate::{ param::{HASH_WIDTH, RLP_NIL}, MPTConfig, MptMemory, RlpItemType, }, - util::word::{self, Word}, + util::word::WordLoHi, }; #[derive(Clone, Debug)] @@ -33,7 +33,7 @@ pub(crate) struct BranchState { pub(crate) key_mult_post_drifted: Expression, pub(crate) num_nibbles: Expression, pub(crate) is_key_odd: Expression, - pub(crate) mod_word: [Word>; 2], + pub(crate) mod_word: [WordLoHi>; 2], pub(crate) mod_rlc: [Expression; 2], } @@ -42,7 +42,7 @@ pub(crate) struct BranchGadget { rlp_list: [RLPListDataGadget; 2], is_modified: [Cell; ARITY], is_drifted: [Cell; ARITY], - mod_word: [WordCell; 2], + mod_word: [WordLoHiCell; 2], mod_rlc: [Cell; 2], is_not_hashed: [LtGadget; 2], @@ -57,7 +57,7 @@ impl BranchGadget { cb: &mut MPTConstraintBuilder, ctx: MPTContext, is_placeholder: &[Cell; 2], - parent_hash: &[word::Word>; 2], + parent_hash: &[WordLoHi>; 2], parent_rlc: &[Expression; 2], is_root: &[Expression; 2], key_rlc: Expression, @@ -299,7 +299,7 @@ impl BranchGadget { is_key_odd: &mut bool, node: &Node, rlp_values: &[RLPItemWitness], - ) -> Result<(F, F, F, [word::Word; 2], [F; 2]), Error> { + ) -> Result<(F, F, F, [WordLoHi; 2], [F; 2]), Error> { let branch = &node.extension_branch.clone().unwrap().branch; for is_s in [true, false] { @@ -351,7 +351,7 @@ impl BranchGadget { let key_mult_post_branch = *key_mult * mult; // Set the branch we'll take - let mut mod_node_hash_word = [word::Word::zero(); 2]; + let mut mod_node_hash_word = [WordLoHi::zero(); 2]; let mut mod_node_hash_rlc = [0.scalar(); 2]; for is_s in [true, false] { ( diff --git a/zkevm-circuits/src/mpt_circuit/extension.rs b/zkevm-circuits/src/mpt_circuit/extension.rs index 7dd2125b86..6552eeeb71 100644 --- a/zkevm-circuits/src/mpt_circuit/extension.rs +++ b/zkevm-circuits/src/mpt_circuit/extension.rs @@ -22,7 +22,7 @@ use crate::{ param::HASH_WIDTH, FixedTableTag, MPTConfig, MptMemory, RlpItemType, }, - util::word::Word, + util::word::WordLoHi, }; #[derive(Clone, Debug)] @@ -32,7 +32,7 @@ pub(crate) struct ExtState { pub(crate) num_nibbles: Expression, pub(crate) is_key_odd: Expression, - pub(crate) branch_rlp_word: [Word>; 2], + pub(crate) branch_rlp_word: [WordLoHi>; 2], pub(crate) branch_rlp_rlc: [Expression; 2], } @@ -100,7 +100,7 @@ impl ExtensionGadget { require!((FixedTableTag::ExtOddKey.expr(), first_byte, config.is_key_part_odd.expr()) =>> @FIXED); let mut branch_rlp_rlc = vec![0.expr(); 2]; - let mut branch_rlp_word = vec![Word::zero(); 2]; + let mut branch_rlp_word = vec![WordLoHi::zero(); 2]; for is_s in [true, false] { // In C we have the key nibbles, we check below only for S. if is_s { diff --git a/zkevm-circuits/src/mpt_circuit/extension_branch.rs b/zkevm-circuits/src/mpt_circuit/extension_branch.rs index 0a3ff39498..920136e550 100644 --- a/zkevm-circuits/src/mpt_circuit/extension_branch.rs +++ b/zkevm-circuits/src/mpt_circuit/extension_branch.rs @@ -17,7 +17,7 @@ use crate::{ helpers::{key_memory, parent_memory, Indexable, KeyData, ParentData}, MPTConfig, MptMemory, }, - util::word::Word, + util::word::WordLoHi, }; #[derive(Clone, Debug, Default)] @@ -114,8 +114,8 @@ impl ExtensionBranchConfig { ) }}; let parent_word = [ - Word::>::new([parent_word_s_lo, parent_word_s_hi]), - Word::>::new([parent_word_c_lo, parent_word_c_hi]), + WordLoHi::>::new([parent_word_s_lo, parent_word_s_hi]), + WordLoHi::>::new([parent_word_c_lo, parent_word_c_hi]), ]; let parent_rlc = [parent_rlc_s, parent_rlc_c]; let is_root = [is_root_s, is_root_c]; @@ -158,7 +158,7 @@ impl ExtensionBranchConfig { branch.mod_rlc[is_s.idx()].expr(), false.expr(), false.expr(), - Word::zero(), + WordLoHi::zero(), ); } elsex { // For the placeholder branch / extension node the values did not change, we reuse @@ -291,7 +291,7 @@ impl ExtensionBranchConfig { mod_node_hash_rlc[is_s.idx()], false, false, - Word::zero(), + WordLoHi::zero(), )?; } else { KeyData::witness_store( diff --git a/zkevm-circuits/src/mpt_circuit/helpers.rs b/zkevm-circuits/src/mpt_circuit/helpers.rs index b8a85955a3..2504f30a6d 100644 --- a/zkevm-circuits/src/mpt_circuit/helpers.rs +++ b/zkevm-circuits/src/mpt_circuit/helpers.rs @@ -2,7 +2,7 @@ use crate::{ assign, circuit, circuit_tools::{ cached_region::{CachedRegion, ChallengeSet}, - cell_manager::{Cell, CellManager, CellType, WordCell}, + cell_manager::{Cell, CellManager, CellType, WordLoHiCell}, constraint_builder::{ ConstraintBuilder, RLCChainable, RLCChainableRev, RLCChainableValue, RLCable, }, @@ -22,10 +22,7 @@ use crate::{ rlp_gadgets::{get_ext_odd_nibble, get_terminal_odd_nibble}, }, table::LookupTable, - util::{ - word::{self, Word}, - Challenges, Expr, - }, + util::{word::WordLoHi, Challenges, Expr}, }; use eth_types::{Field, OpsIdentity, Word as U256}; use gadgets::util::{not, or, pow, xor, Scalar}; @@ -557,20 +554,20 @@ impl KeyData { #[derive(Clone, Debug, Default)] pub(crate) struct ParentData { - pub(crate) hash: WordCell, + pub(crate) hash: WordLoHiCell, pub(crate) rlc: Cell, pub(crate) is_root: Cell, pub(crate) is_placeholder: Cell, - pub(crate) drifted_parent_hash: WordCell, + pub(crate) drifted_parent_hash: WordLoHiCell, } #[derive(Clone, Debug, Default)] pub(crate) struct ParentDataWitness { - pub(crate) hash: word::Word, + pub(crate) hash: WordLoHi, pub(crate) rlc: F, pub(crate) is_root: bool, pub(crate) is_placeholder: bool, - pub(crate) drifted_parent_hash: word::Word, + pub(crate) drifted_parent_hash: WordLoHi, } impl ParentData { @@ -607,11 +604,11 @@ impl ParentData { pub(crate) fn store>( cb: &mut MPTConstraintBuilder, memory: &mut MB, - hash: word::Word>, + hash: WordLoHi>, rlc: Expression, is_root: Expression, is_placeholder: Expression, - drifted_parent_hash: word::Word>, + drifted_parent_hash: WordLoHi>, ) { memory.store( &mut cb.base, @@ -632,11 +629,11 @@ impl ParentData { _region: &mut CachedRegion<'_, '_, F>, offset: usize, memory: &mut MB, - hash: word::Word, + hash: WordLoHi, rlc: F, force_hashed: bool, is_placeholder: bool, - drifted_parent_hash: word::Word, + drifted_parent_hash: WordLoHi, ) -> Result<(), Error> { memory.witness_store( offset, @@ -675,11 +672,11 @@ impl ParentData { .assign(region, offset, values[6])?; Ok(ParentDataWitness { - hash: word::Word::new([values[0], values[1]]), + hash: WordLoHi::new([values[0], values[1]]), rlc: values[2], is_root: values[3] == 1.scalar(), is_placeholder: values[4] == 1.scalar(), - drifted_parent_hash: word::Word::new([values[5], values[6]]), + drifted_parent_hash: WordLoHi::new([values[5], values[6]]), }) } } @@ -689,8 +686,8 @@ pub(crate) struct MainData { pub(crate) proof_type: Cell, pub(crate) is_below_account: Cell, pub(crate) address: Cell, - pub(crate) new_root: WordCell, - pub(crate) old_root: WordCell, + pub(crate) new_root: WordLoHiCell, + pub(crate) old_root: WordLoHiCell, } #[derive(Clone, Debug, Default)] @@ -698,8 +695,8 @@ pub(crate) struct MainDataWitness { pub(crate) proof_type: usize, pub(crate) is_below_account: bool, pub(crate) address: F, - pub(crate) new_root: word::Word, - pub(crate) old_root: word::Word, + pub(crate) new_root: WordLoHi, + pub(crate) old_root: WordLoHi, } impl MainData { @@ -749,8 +746,8 @@ impl MainData { proof_type: usize, is_below_account: bool, address: F, - new_root: word::Word, - old_root: word::Word, + new_root: WordLoHi, + old_root: WordLoHi, ) -> Result<(), Error> { let values = [ proof_type.scalar(), @@ -787,8 +784,8 @@ impl MainData { proof_type: values[0].get_lower_32() as usize, is_below_account: values[1] == 1.scalar(), address: values[2], - new_root: word::Word::new([values[3], values[4]]), - old_root: word::Word::new([values[5], values[6]]), + new_root: WordLoHi::new([values[3], values[4]]), + old_root: WordLoHi::new([values[5], values[6]]), }) } } @@ -992,7 +989,7 @@ impl MPTConstraintBuilder { } // default query_word is 2 limbs. Each limb is not guaranteed to be 128 bits. - pub(crate) fn query_word_unchecked(&mut self) -> WordCell { + pub(crate) fn query_word_unchecked(&mut self) -> WordLoHiCell { self.base.query_word_unchecked() } @@ -1069,20 +1066,20 @@ pub struct IsPlaceholderLeafGadget { impl IsPlaceholderLeafGadget { pub(crate) fn construct( cb: &mut MPTConstraintBuilder, - parent_word: Word>, + parent_word: WordLoHi>, ) -> Self { circuit!([meta, cb.base], { - let empty_hash = Word::::from(U256::from_big_endian(&EMPTY_TRIE_HASH)); + let empty_hash = WordLoHi::::from(U256::from_big_endian(&EMPTY_TRIE_HASH)); let is_empty_trie = IsEqualWordGadget::construct( &mut cb.base, &parent_word, - &Word::>::new([ + &WordLoHi::>::new([ Expression::Constant(empty_hash.lo()), Expression::Constant(empty_hash.hi()), ]), ); let is_nil_in_branch_at_mod_index = - IsEqualWordGadget::construct(&mut cb.base, &parent_word, &Word::zero()); + IsEqualWordGadget::construct(&mut cb.base, &parent_word, &WordLoHi::zero()); Self { is_empty_trie, @@ -1102,16 +1099,16 @@ impl IsPlaceholderLeafGadget { &self, region: &mut CachedRegion<'_, '_, F>, offset: usize, - hash: Word, + hash: WordLoHi, ) -> Result<(), Error> { - let empty_hash = Word::::from(U256::from_big_endian(&EMPTY_TRIE_HASH)); + let empty_hash = WordLoHi::::from(U256::from_big_endian(&EMPTY_TRIE_HASH)); self.is_empty_trie .assign(region, offset, hash, empty_hash)?; self.is_nil_in_branch_at_mod_index.assign( region, offset, hash, - Word::::from(U256::zero()), + WordLoHi::::from(U256::zero()), )?; Ok(()) } @@ -1309,7 +1306,7 @@ pub struct MainRLPGadget { mult_diff: Cell, hash_rlc: Cell, rlc_rlp: Cell, - word: WordCell, + word: WordLoHiCell, tag: Cell, max_len: Cell, is_rlp: Cell, @@ -1587,7 +1584,7 @@ impl MainRLPGadget { .collect(), is_short: Some(self.rlp.value.is_short.rot(meta, rot)), is_long: Some(self.rlp.value.is_long.rot(meta, rot)), - word: Some(Word::new([ + word: Some(WordLoHi::new([ self.word.lo().rot(meta, rot), self.word.hi().rot(meta, rot), ])), @@ -1635,7 +1632,7 @@ pub struct RLPItemView { rlc_rlp: Option>, is_short: Option>, is_long: Option>, - word: Option>>, + word: Option>>, } impl RLPItemView { @@ -1685,7 +1682,7 @@ impl RLPItemView { not::expr(self.is_short() + self.is_long()) } - pub(crate) fn word(&self) -> Word> { + pub(crate) fn word(&self) -> WordLoHi> { assert!(self.can_use_word); self.word.clone().unwrap() } diff --git a/zkevm-circuits/src/mpt_circuit/rlp_gadgets.rs b/zkevm-circuits/src/mpt_circuit/rlp_gadgets.rs index d86f0b1c02..b1218c7994 100644 --- a/zkevm-circuits/src/mpt_circuit/rlp_gadgets.rs +++ b/zkevm-circuits/src/mpt_circuit/rlp_gadgets.rs @@ -12,7 +12,7 @@ use crate::{ param::{RLP_LIST_LONG, RLP_LIST_SHORT, RLP_SHORT}, FixedTableTag, }, - util::{word, Expr}, + util::{word::WordLoHi, Expr}, }; use eth_types::Field; use gadgets::util::{not, pow, Scalar}; @@ -833,8 +833,8 @@ impl RLPItemWitness { } } - pub(crate) fn word(&self) -> word::Word { - // word::Word::from(Word::from_big_endian(&self.bytes[1..33])) + pub(crate) fn word(&self) -> WordLoHi { + // WordLoHi::from(WordLoHi::from_big_endian(&self.bytes[1..33])) let (lo, hi) = if self.is_string() { if self.is_short() { let lo: F = self.bytes[0].scalar(); @@ -890,6 +890,6 @@ impl RLPItemWitness { ); (lo, hi) }; - word::Word::new([lo, hi]) + WordLoHi::new([lo, hi]) } } diff --git a/zkevm-circuits/src/mpt_circuit/start.rs b/zkevm-circuits/src/mpt_circuit/start.rs index ee9d60fc7a..0e1fce33b6 100644 --- a/zkevm-circuits/src/mpt_circuit/start.rs +++ b/zkevm-circuits/src/mpt_circuit/start.rs @@ -13,7 +13,7 @@ use crate::{ }, MPTConfig, MPTContext, MptMemory, RlpItemType, }, - util::word::Word, + util::word::WordLoHi, }; use eth_types::{Field, OpsIdentity}; use gadgets::util::Scalar; @@ -40,7 +40,7 @@ impl StartConfig { config.proof_type = cb.query_cell(); - let mut root = vec![Word::zero(); 2]; + let mut root = vec![WordLoHi::zero(); 2]; for is_s in [true, false] { root[is_s.idx()] = root_items[is_s.idx()].word(); } @@ -96,7 +96,7 @@ impl StartConfig { self.proof_type .assign(region, offset, start.proof_type.scalar())?; - let mut root = vec![Word::zero(); 2]; + let mut root = vec![WordLoHi::zero(); 2]; for is_s in [true, false] { root[is_s.idx()] = rlp_values[is_s.idx()].word(); } diff --git a/zkevm-circuits/src/mpt_circuit/storage_leaf.rs b/zkevm-circuits/src/mpt_circuit/storage_leaf.rs index 5e4c9b1dd1..5fb89eaffd 100644 --- a/zkevm-circuits/src/mpt_circuit/storage_leaf.rs +++ b/zkevm-circuits/src/mpt_circuit/storage_leaf.rs @@ -24,7 +24,7 @@ use crate::{ MPTConfig, MPTContext, MptMemory, RlpItemType, }, table::MPTProofType, - util::word::{self, Word}, + util::word::WordLoHi, witness::MptUpdateRow, }; @@ -104,7 +104,7 @@ impl StorageLeafConfig { require!(config.main_data.is_below_account => true); let mut key_rlc = vec![0.expr(); 2]; - let mut value_word = vec![Word::zero(); 2]; + let mut value_word = vec![WordLoHi::zero(); 2]; let mut value_rlp_rlc = vec![0.expr(); 2]; let mut value_rlp_rlc_mult = vec![0.expr(); 2]; @@ -168,7 +168,7 @@ impl StorageLeafConfig { require!(config.rlp_value[is_s.idx()].num_bytes() => value_item[is_s.idx()].num_bytes() + 1.expr()); (value.lo(), value.hi(), value_rlp_rlc, rlp_value_rlc_mult.1 * value_item[is_s.idx()].mult()) }}; - value_word[is_s.idx()] = Word::>::new([value_lo, value_hi]); + value_word[is_s.idx()] = WordLoHi::>::new([value_lo, value_hi]); let leaf_rlc = rlp_key.rlc2(&cb.keccak_r).rlc_chain_rev(( value_rlp_rlc[is_s.idx()].expr(), @@ -191,7 +191,7 @@ impl StorageLeafConfig { // Placeholder leaves default to value `0`. ifx! {is_placeholder_leaf => { - require!(value_word[is_s.idx()] => Word::>::zero()); + require!(value_word[is_s.idx()] => WordLoHi::>::zero()); }} // Make sure the RLP encoding is correct. @@ -223,7 +223,7 @@ impl StorageLeafConfig { ifx! {parent_data[is_s.idx()].is_root.expr() => { // If leaf is placeholder and the parent is root (no branch above leaf) and the proof is NonExistingStorageProof, // the trie needs to be empty. - let empty_hash = Word::::from(U256::from_big_endian(&EMPTY_TRIE_HASH)); + let empty_hash = WordLoHi::::from(U256::from_big_endian(&EMPTY_TRIE_HASH)); let hash = parent_data[is_s.idx()].hash.expr(); require!(hash.lo() => Expression::Constant(empty_hash.lo())); require!(hash.hi() => Expression::Constant(empty_hash.hi())); @@ -246,11 +246,11 @@ impl StorageLeafConfig { ParentData::store( cb, &mut ctx.memory[parent_memory(is_s)], - word::Word::zero(), + WordLoHi::zero(), 0.expr(), true.expr(), false.expr(), - word::Word::zero(), + WordLoHi::zero(), ); } @@ -377,8 +377,8 @@ impl StorageLeafConfig { address_item.word(), config.main_data.new_root.expr(), config.main_data.old_root.expr(), - Word::>::new([0.expr(), 0.expr()]), - Word::>::new([0.expr(), 0.expr()]), + WordLoHi::>::new([0.expr(), 0.expr()]), + WordLoHi::>::new([0.expr(), 0.expr()]), ); }}; } elsex { @@ -395,7 +395,7 @@ impl StorageLeafConfig { address_item.word(), config.main_data.new_root.expr(), config.main_data.old_root.expr(), - Word::zero(), + WordLoHi::zero(), value_word[true.idx()].clone(), ); }}; @@ -436,7 +436,7 @@ impl StorageLeafConfig { let mut key_data = vec![KeyDataWitness::default(); 2]; let mut parent_data = vec![ParentDataWitness::default(); 2]; let mut key_rlc = vec![0.scalar(); 2]; - let mut value_word = vec![Word::zero(); 2]; + let mut value_word = vec![WordLoHi::zero(); 2]; for is_s in [true, false] { self.is_mod_extension[is_s.idx()].assign( region, @@ -504,7 +504,7 @@ impl StorageLeafConfig { &storage.value_rlp_bytes[is_s.idx()], )?; value_word[is_s.idx()] = if value_witness.is_short() { - Word::::new([value_witness.rlc_value(region.key_r), 0.scalar()]) + WordLoHi::::new([value_witness.rlc_value(region.key_r), 0.scalar()]) } else { value_item[is_s.idx()].word() }; @@ -513,11 +513,11 @@ impl StorageLeafConfig { region, offset, &mut memory[parent_memory(is_s)], - word::Word::::new([F::ZERO, F::ZERO]), + WordLoHi::::new([F::ZERO, F::ZERO]), F::ZERO, true, false, - word::Word::::new([F::ZERO, F::ZERO]), + WordLoHi::::new([F::ZERO, F::ZERO]), )?; self.is_placeholder_leaf[is_s.idx()].assign( @@ -571,8 +571,8 @@ impl StorageLeafConfig { MPTProofType::Disabled as usize, false, F::ZERO, - Word::new([F::ZERO, F::ZERO]), - Word::new([F::ZERO, F::ZERO]), + WordLoHi::new([F::ZERO, F::ZERO]), + WordLoHi::new([F::ZERO, F::ZERO]), )?; // Put the data in the lookup table @@ -596,10 +596,10 @@ impl StorageLeafConfig { let mut new_value = value_word[false.idx()]; let mut old_value = value_word[true.idx()]; if parent_data[false.idx()].is_placeholder { - new_value = word::Word::zero(); + new_value = WordLoHi::zero(); } else if is_non_existing_proof { - new_value = word::Word::zero(); - old_value = word::Word::zero(); + new_value = WordLoHi::zero(); + old_value = WordLoHi::zero(); } mpt_config.mpt_table.assign_cached( region, diff --git a/zkevm-circuits/src/pi_circuit.rs b/zkevm-circuits/src/pi_circuit.rs index 89e6ae5051..548b339f0b 100644 --- a/zkevm-circuits/src/pi_circuit.rs +++ b/zkevm-circuits/src/pi_circuit.rs @@ -33,7 +33,7 @@ use crate::{ }, table::{BlockTable, KeccakTable, LookupTable, TxFieldTag, TxTable, WdTable}, tx_circuit::TX_LEN, - util::{word::Word, Challenges, SubCircuit, SubCircuitConfig}, + util::{word::WordLoHi, Challenges, SubCircuit, SubCircuitConfig}, witness, }; use gadgets::{ @@ -617,7 +617,7 @@ impl PiCircuitConfig { offset, || Value::known(F::ZERO), )?; - Word::default().into_value().assign_advice( + WordLoHi::default().into_value().assign_advice( region, || "tx_value", self.tx_table.value, @@ -698,7 +698,7 @@ impl PiCircuitConfig { F::ZERO }; let tag = F::from(tag as u64); - let tx_value = Word::new([ + let tx_value = WordLoHi::new([ from_bytes::value( &tx_value_bytes_le[..min(N_BYTES_HALF_WORD, tx_value_bytes_le.len())], ), @@ -811,7 +811,7 @@ impl PiCircuitConfig { let tx_id_diff_inv = tx_id_diff.invert().unwrap_or(F::ZERO); let tag = F::from(TxFieldTag::CallData as u64); let index = F::from(index as u64); - let tx_value: Word> = Word::from(tx_value_byte).into_value(); + let tx_value: WordLoHi> = WordLoHi::from(tx_value_byte).into_value(); let tx_value_inv = tx_value.map(|t| t.map(|x| x.invert().unwrap_or(F::ZERO))); let is_final = if is_final { F::ONE } else { F::ZERO }; @@ -910,7 +910,7 @@ impl PiCircuitConfig { offset, || Value::known(F::from(wd.validator_id)), )?; - let address_assigned_cell = Word::::from(wd.address).into_value().assign_advice( + let address_assigned_cell = WordLoHi::::from(wd.address).into_value().assign_advice( region, || "address", self.wd_table.address, @@ -1095,7 +1095,7 @@ impl PiCircuitConfig { Ok(( rpi_bytes_keccakrlc_cells[0].clone(), - Word::new( + WordLoHi::new( (0..2) // padding rpi_value_lc_cells to 2 limbs if less then 2 .map(|i| rpi_value_lc_cells.get(i).unwrap_or(&zero_cell).clone()) .collect_vec() @@ -1123,7 +1123,7 @@ impl PiCircuitConfig { let mut block_copy_cells = vec![]; // coinbase - let block_value = Word::from(block_values.coinbase) + let block_value = WordLoHi::from(block_values.coinbase) .into_value() .assign_advice( region, @@ -1150,7 +1150,7 @@ impl PiCircuitConfig { *block_table_offset += 1; // gas_limit - let block_value = Word::from(block_values.gas_limit) + let block_value = WordLoHi::from(block_values.gas_limit) .into_value() .assign_advice( region, @@ -1171,12 +1171,14 @@ impl PiCircuitConfig { *block_table_offset += 1; // number - let block_value = Word::from(block_values.number).into_value().assign_advice( - region, - || "number", - self.block_table.value, - *block_table_offset, - )?; + let block_value = WordLoHi::from(block_values.number) + .into_value() + .assign_advice( + region, + || "number", + self.block_table.value, + *block_table_offset, + )?; let (_, word) = self.assign_raw_bytes( region, &block_values.number.to_le_bytes(), @@ -1190,7 +1192,7 @@ impl PiCircuitConfig { *block_table_offset += 1; // timestamp - let block_value = Word::from(block_values.timestamp) + let block_value = WordLoHi::from(block_values.timestamp) .into_value() .assign_advice( region, @@ -1211,7 +1213,7 @@ impl PiCircuitConfig { *block_table_offset += 1; // difficulty - let block_value = Word::from(block_values.difficulty) + let block_value = WordLoHi::from(block_values.difficulty) .into_value() .assign_advice( region, @@ -1232,7 +1234,7 @@ impl PiCircuitConfig { *block_table_offset += 1; // base_fee - let block_value = Word::from(block_values.base_fee) + let block_value = WordLoHi::from(block_values.base_fee) .into_value() .assign_advice( region, @@ -1253,7 +1255,7 @@ impl PiCircuitConfig { *block_table_offset += 1; // chain_id - let block_value = Word::from(block_values.chain_id) + let block_value = WordLoHi::from(block_values.chain_id) .into_value() .assign_advice( region, @@ -1274,7 +1276,7 @@ impl PiCircuitConfig { *block_table_offset += 1; // withdrawals_root - let block_value = Word::from(block_values.withdrawals_root) + let block_value = WordLoHi::from(block_values.withdrawals_root) .into_value() .assign_advice( region, @@ -1295,7 +1297,7 @@ impl PiCircuitConfig { *block_table_offset += 1; for prev_hash in block_values.history_hashes { - let block_value = Word::from(prev_hash).into_value().assign_advice( + let block_value = WordLoHi::from(prev_hash).into_value().assign_advice( region, || "prev_hash", self.block_table.value, @@ -1402,8 +1404,8 @@ impl PiCircuitConfig { fn assign_rpi_digest_word( &self, region: &mut Region<'_, F>, - digest_word: Word, - ) -> Result>, Error> { + digest_word: WordLoHi, + ) -> Result>, Error> { let lo_assigned_cell = region.assign_advice( || "rpi_digest_bytes_limbs_lo", self.rpi_digest_bytes_limbs, @@ -1416,7 +1418,7 @@ impl PiCircuitConfig { 1, || digest_word.into_value().hi(), )?; - Ok(Word::new([lo_assigned_cell, hi_assigned_cell])) + Ok(WordLoHi::new([lo_assigned_cell, hi_assigned_cell])) } } @@ -1562,7 +1564,7 @@ impl SubCircuit for PiCircuit { let mut block_table_offset = 0; // assign empty row in block table - let zero_word = Word::default().into_value().assign_advice( + let zero_word = WordLoHi::default().into_value().assign_advice( &mut region, || "zero", config.block_table.value, @@ -1619,7 +1621,7 @@ impl SubCircuit for PiCircuit { // Add empty row // assign first tx_value empty row, and to obtain zero cell via hi() part. // we use hi() part to copy-constrains other tx_table value `hi` cells. - let zero_cell = Word::default() + let zero_cell = WordLoHi::default() .into_value() .assign_advice(&mut region, || "tx_value", config.tx_table.value, 0)? .hi(); diff --git a/zkevm-circuits/src/pi_circuit/param.rs b/zkevm-circuits/src/pi_circuit/param.rs index fff7391e76..044e63c92e 100644 --- a/zkevm-circuits/src/pi_circuit/param.rs +++ b/zkevm-circuits/src/pi_circuit/param.rs @@ -1,10 +1,10 @@ use halo2_proofs::circuit::AssignedCell; -use crate::util::word::Word; +use crate::util::word::WordLoHi; /// Fixed by the spec pub(super) const BYTE_POW_BASE: u64 = 256; pub(super) const EMPTY_TX_ROW_COUNT: usize = 1; pub(super) const N_BYTES_ONE: usize = 1; -pub(super) type AssignedByteCells = (AssignedCell, Word>); +pub(super) type AssignedByteCells = (AssignedCell, WordLoHi>); diff --git a/zkevm-circuits/src/state_circuit.rs b/zkevm-circuits/src/state_circuit.rs index d48d836b77..4dcbda633f 100644 --- a/zkevm-circuits/src/state_circuit.rs +++ b/zkevm-circuits/src/state_circuit.rs @@ -19,7 +19,7 @@ use self::{ }; use crate::{ table::{AccountFieldTag, LookupTable, MPTProofType, MptTable, RwTable, UXTable}, - util::{word, Challenges, Expr, SubCircuit, SubCircuitConfig}, + util::{word::WordLoHi, Challenges, Expr, SubCircuit, SubCircuitConfig}, witness::{self, MptUpdates, Rw, RwMap}, }; use constraint_builder::{ConstraintBuilder, Queries}; @@ -56,14 +56,14 @@ pub struct StateCircuitConfig { // Assigned value at the start of the block. For Rw::Account and // Rw::AccountStorage rows this is the committed value in the MPT, for // others, it is 0. - initial_value: word::Word>, + initial_value: WordLoHi>, // For Rw::AccountStorage, identify non-existing if both committed value and // new value are zero. Will do lookup for MPTProofType::StorageDoesNotExist if // non-existing, otherwise do lookup for MPTProofType::StorageChanged. is_non_exist: BatchedIsZeroConfig, // Intermediary witness used to reduce mpt lookup expression degree mpt_proof_type: Column, - state_root: word::Word>, + state_root: WordLoHi>, lexicographic_ordering: LexicographicOrderingConfig, not_first_access: Column, lookups: LookupsConfig, @@ -118,7 +118,7 @@ impl SubCircuitConfig for StateCircuitConfig { [rw_table.storage_key.lo(), rw_table.storage_key.hi()], lookups, ); - let initial_value = word::Word::new([meta.advice_column(), meta.advice_column()]); + let initial_value = WordLoHi::new([meta.advice_column(), meta.advice_column()]); let is_non_exist = BatchedIsZeroChip::configure( meta, @@ -134,7 +134,7 @@ impl SubCircuitConfig for StateCircuitConfig { }, ); let mpt_proof_type = meta.advice_column_in(SecondPhase); - let state_root = word::Word::new([meta.advice_column(), meta.advice_column()]); + let state_root = WordLoHi::new([meta.advice_column(), meta.advice_column()]); let sort_keys = SortKeysConfig { tag, @@ -283,7 +283,7 @@ impl StateCircuitConfig { } // The initial value can be determined from the mpt updates or is 0. - let initial_value = word::Word::::from( + let initial_value = WordLoHi::::from( updates .get(row) .map(|u| u.value_assignments().1) @@ -305,8 +305,8 @@ impl StateCircuitConfig { .unwrap_or_default(); let value = row.value_assignment(); ( - word::Word::::from(committed_value), - word::Word::::from(value), + WordLoHi::::from(committed_value), + WordLoHi::::from(value), ) }; @@ -353,9 +353,12 @@ impl StateCircuitConfig { // State root assignment is at previous row (offset - 1) because the state root // changes on the last access row. if offset != 0 { - word::Word::::from(state_root) - .into_value() - .assign_advice(region, || "state root", self.state_root, offset - 1)?; + WordLoHi::::from(state_root).into_value().assign_advice( + region, + || "state root", + self.state_root, + offset - 1, + )?; } if offset == rows_len - 1 { @@ -368,9 +371,12 @@ impl StateCircuitConfig { new_root }; } - word::Word::::from(state_root) - .into_value() - .assign_advice(region, || "last row state_root", self.state_root, offset)?; + WordLoHi::::from(state_root).into_value().assign_advice( + region, + || "last row state_root", + self.state_root, + offset, + )?; } } @@ -529,8 +535,8 @@ fn queries(meta: &mut VirtualCells<'_, F>, c: &StateCircuitConfig) assert_eq!(mpt_update_table_expressions.len(), 12); let meta_query_word = - |metap: &mut VirtualCells<'_, F>, word_column: word::Word>, at: Rotation| { - word::Word::new([ + |metap: &mut VirtualCells<'_, F>, word_column: WordLoHi>, at: Rotation| { + WordLoHi::new([ metap.query_advice(word_column.lo(), at), metap.query_advice(word_column.hi(), at), ]) @@ -557,24 +563,24 @@ fn queries(meta: &mut VirtualCells<'_, F>, c: &StateCircuitConfig) // TODO: clean this up mpt_update_table: MptUpdateTableQueries { address: mpt_update_table_expressions[0].clone(), - storage_key: word::Word::new([ + storage_key: WordLoHi::new([ mpt_update_table_expressions[1].clone(), mpt_update_table_expressions[2].clone(), ]), proof_type: mpt_update_table_expressions[3].clone(), - new_root: word::Word::new([ + new_root: WordLoHi::new([ mpt_update_table_expressions[4].clone(), mpt_update_table_expressions[5].clone(), ]), - old_root: word::Word::new([ + old_root: WordLoHi::new([ mpt_update_table_expressions[6].clone(), mpt_update_table_expressions[7].clone(), ]), - new_value: word::Word::new([ + new_value: WordLoHi::new([ mpt_update_table_expressions[8].clone(), mpt_update_table_expressions[9].clone(), ]), - old_value: word::Word::new([ + old_value: WordLoHi::new([ mpt_update_table_expressions[10].clone(), mpt_update_table_expressions[11].clone(), ]), diff --git a/zkevm-circuits/src/state_circuit/constraint_builder.rs b/zkevm-circuits/src/state_circuit/constraint_builder.rs index 1fb866cc0e..f2abbd6faf 100644 --- a/zkevm-circuits/src/state_circuit/constraint_builder.rs +++ b/zkevm-circuits/src/state_circuit/constraint_builder.rs @@ -11,6 +11,7 @@ use eth_types::Field; use gadgets::binary_number::BinaryNumberConfig; use halo2_proofs::plonk::Expression; use strum::IntoEnumIterator; +use word::WordLoHi; #[derive(Clone)] pub struct RwTableQueries { @@ -23,21 +24,21 @@ pub struct RwTableQueries { pub address: Expression, pub prev_address: Expression, pub field_tag: Expression, - pub storage_key: word::Word>, - pub value: word::Word>, - pub value_prev: word::Word>, // meta.query(value, Rotation::prev()) - pub value_prev_column: word::Word>, // meta.query(prev_value, Rotation::cur()) + pub storage_key: WordLoHi>, + pub value: WordLoHi>, + pub value_prev: WordLoHi>, // meta.query(value, Rotation::prev()) + pub value_prev_column: WordLoHi>, // meta.query(prev_value, Rotation::cur()) } #[derive(Clone)] pub struct MptUpdateTableQueries { pub address: Expression, - pub storage_key: word::Word>, + pub storage_key: WordLoHi>, pub proof_type: Expression, - pub new_root: word::Word>, - pub old_root: word::Word>, - pub new_value: word::Word>, - pub old_value: word::Word>, + pub new_root: WordLoHi>, + pub old_root: WordLoHi>, + pub new_value: WordLoHi>, + pub old_value: WordLoHi>, } #[derive(Clone)] @@ -52,16 +53,16 @@ pub struct Queries { pub is_tag_and_id_unchanged: Expression, pub address: MpiQueries, pub storage_key: MpiQueries, - pub initial_value: word::Word>, - pub initial_value_prev: word::Word>, + pub initial_value: WordLoHi>, + pub initial_value_prev: WordLoHi>, pub is_non_exist: Expression, pub mpt_proof_type: Expression, pub lookups: LookupsQueries, pub first_different_limb: [Expression; 4], pub not_first_access: Expression, pub last_access: Expression, - pub state_root: word::Word>, - pub state_root_prev: word::Word>, + pub state_root: WordLoHi>, + pub state_root_prev: WordLoHi>, } type Constraint = (&'static str, Expression); @@ -82,7 +83,7 @@ impl LookupBuilder { self.0.push((e1.clone(), e2.clone())); self } - fn add_word(mut self, e1: &word::Word>, e2: &word::Word>) -> Self { + fn add_word(mut self, e1: &WordLoHi>, e2: &WordLoHi>) -> Self { self.0.push((e1.lo(), e2.lo())); self.0.push((e1.hi(), e2.hi())); self @@ -532,7 +533,7 @@ impl ConstraintBuilder { self.constraints.push((name, self.condition.clone() * e)); } - fn require_word_zero(&mut self, name: &'static str, e: word::Word>) { + fn require_word_zero(&mut self, name: &'static str, e: WordLoHi>) { let (lo, hi) = e.into_lo_hi(); self.constraints.push((name, self.condition.clone() * hi)); self.constraints.push((name, self.condition.clone() * lo)); @@ -545,8 +546,8 @@ impl ConstraintBuilder { fn require_word_equal( &mut self, name: &'static str, - left: word::Word>, - right: word::Word>, + left: WordLoHi>, + right: WordLoHi>, ) { let (left_lo, left_hi) = left.into_lo_hi(); let (right_lo, right_hi) = right.into_lo_hi(); @@ -558,7 +559,7 @@ impl ConstraintBuilder { self.require_zero(name, e.clone() * (1.expr() - e)) } - fn require_word_boolean(&mut self, name: &'static str, e: word::Word>) { + fn require_word_boolean(&mut self, name: &'static str, e: WordLoHi>) { let (lo, hi) = e.into_lo_hi(); self.require_zero(name, hi); self.require_zero(name, lo.clone() * (1.expr() - lo)); @@ -606,15 +607,15 @@ impl Queries { self.rw_table.field_tag.clone() } - fn value(&self) -> word::Word> { + fn value(&self) -> WordLoHi> { self.rw_table.value.clone() } - fn initial_value(&self) -> word::Word> { + fn initial_value(&self) -> WordLoHi> { self.initial_value.clone() } - fn initial_value_prev(&self) -> word::Word> { + fn initial_value_prev(&self) -> WordLoHi> { self.initial_value_prev.clone() } @@ -646,15 +647,15 @@ impl Queries { self.last_access.clone() } - fn state_root(&self) -> word::Word> { + fn state_root(&self) -> WordLoHi> { self.state_root.clone() } - fn state_root_prev(&self) -> word::Word> { + fn state_root_prev(&self) -> WordLoHi> { self.state_root_prev.clone() } - fn value_prev_column(&self) -> word::Word> { + fn value_prev_column(&self) -> WordLoHi> { self.rw_table.value_prev_column.clone() } } diff --git a/zkevm-circuits/src/table.rs b/zkevm-circuits/src/table.rs index a92364351a..fde4ef38e1 100644 --- a/zkevm-circuits/src/table.rs +++ b/zkevm-circuits/src/table.rs @@ -4,11 +4,7 @@ use crate::{ copy_circuit::util::number_or_hash_to_word, evm_circuit::util::rlc, impl_expr, - util::{ - build_tx_log_address, keccak, - word::{self, Word}, - Challenges, - }, + util::{build_tx_log_address, keccak, word::WordLoHi, Challenges}, witness::{Block, BlockContext, MptUpdateRow, MptUpdates, Rw, RwMap, RwRow, Transaction}, }; use bus_mapping::circuit_input_builder::{CopyDataType, CopyEvent, CopyStep}; diff --git a/zkevm-circuits/src/table/block_table.rs b/zkevm-circuits/src/table/block_table.rs index b697ff42f3..0d7cc0dfce 100644 --- a/zkevm-circuits/src/table/block_table.rs +++ b/zkevm-circuits/src/table/block_table.rs @@ -36,7 +36,7 @@ pub struct BlockTable { /// Index pub index: Column, /// Value - pub value: word::Word>, + pub value: WordLoHi>, } impl BlockTable { @@ -45,7 +45,7 @@ impl BlockTable { Self { tag: meta.fixed_column(), index: meta.fixed_column(), - value: word::Word::new([meta.advice_column(), meta.advice_column()]), + value: WordLoHi::new([meta.advice_column(), meta.advice_column()]), } } @@ -75,7 +75,7 @@ impl BlockTable { || row[1], )?; - word::Word::new([row[2], row[3]]).assign_advice( + WordLoHi::new([row[2], row[3]]).assign_advice( &mut region, || format!("block table value {}", offset), self.value, diff --git a/zkevm-circuits/src/table/bytecode_table.rs b/zkevm-circuits/src/table/bytecode_table.rs index 3599180297..f433a2a777 100644 --- a/zkevm-circuits/src/table/bytecode_table.rs +++ b/zkevm-circuits/src/table/bytecode_table.rs @@ -1,5 +1,4 @@ use super::*; -use crate::util; use bus_mapping::state_db::CodeDB; /// Tag to identify the field in a Bytecode Table row @@ -16,7 +15,7 @@ impl_expr!(BytecodeFieldTag); #[derive(Clone, Debug)] pub struct BytecodeTable { /// Code Hash - pub code_hash: word::Word>, + pub code_hash: WordLoHi>, /// Tag pub tag: Column, /// Index @@ -31,7 +30,7 @@ impl BytecodeTable { /// Construct a new BytecodeTable pub fn construct(meta: &mut ConstraintSystem) -> Self { let [tag, index, is_code, value] = array::from_fn(|_| meta.advice_column()); - let code_hash = word::Word::new([meta.advice_column(), meta.advice_column()]); + let code_hash = WordLoHi::new([meta.advice_column(), meta.advice_column()]); Self { code_hash, tag, @@ -66,7 +65,7 @@ impl BytecodeTable { >::advice_columns(self); for bytecode in bytecodes.clone().into_iter() { let rows = { - let code_hash = util::word::Word::from(bytecode.hash()); + let code_hash = WordLoHi::from(bytecode.hash()); std::iter::once([ code_hash.lo(), code_hash.hi(), diff --git a/zkevm-circuits/src/table/copy_table.rs b/zkevm-circuits/src/table/copy_table.rs index 9fc4dab9a8..cbd9cbbdb2 100644 --- a/zkevm-circuits/src/table/copy_table.rs +++ b/zkevm-circuits/src/table/copy_table.rs @@ -14,7 +14,7 @@ pub struct CopyTable { /// 1. Call ID/Caller ID for CopyDataType::Memory /// 2. The hi/lo limbs of bytecode hash for CopyDataType::Bytecode /// 3. Transaction ID for CopyDataType::TxCalldata, CopyDataType::TxLog - pub id: word::Word>, + pub id: WordLoHi>, /// The source/destination address for this copy step. Can be memory /// address, byte index in the bytecode, tx call data, and tx log data. pub addr: Column, @@ -45,7 +45,7 @@ impl CopyTable { pub fn construct(meta: &mut ConstraintSystem, q_enable: Column) -> Self { Self { is_first: meta.advice_column(), - id: word::Word::new([meta.advice_column(), meta.advice_column()]), + id: WordLoHi::new([meta.advice_column(), meta.advice_column()]), q_enable, tag: BinaryNumberChip::configure(meta, q_enable, None), addr: meta.advice_column(), diff --git a/zkevm-circuits/src/table/keccak_table.rs b/zkevm-circuits/src/table/keccak_table.rs index 7f36be98a1..6957a09e98 100644 --- a/zkevm-circuits/src/table/keccak_table.rs +++ b/zkevm-circuits/src/table/keccak_table.rs @@ -10,7 +10,7 @@ pub struct KeccakTable { /// Byte array input length pub input_len: Column, /// Output hash word - pub output: word::Word>, + pub output: WordLoHi>, } impl LookupTable for KeccakTable { @@ -42,7 +42,7 @@ impl KeccakTable { is_enabled: meta.advice_column(), input_rlc: meta.advice_column_in(SecondPhase), input_len: meta.advice_column(), - output: word::Word::new([meta.advice_column(), meta.advice_column()]), + output: WordLoHi::new([meta.advice_column(), meta.advice_column()]), } } @@ -55,7 +55,7 @@ impl KeccakTable { .keccak_input() .map(|challenge| rlc::value(input.iter().rev(), challenge)); let input_len = F::from(input.len() as u64); - let output = word::Word::from(keccak(input)); + let output = WordLoHi::from(keccak(input)); vec![[ Value::known(F::ONE), @@ -130,7 +130,7 @@ impl KeccakTable { &self, value_rlc: Column, length: Column, - code_hash: Word>, + code_hash: WordLoHi>, ) -> Vec<(Column, Column)> { vec![ (value_rlc, self.input_rlc), diff --git a/zkevm-circuits/src/table/mpt_table.rs b/zkevm-circuits/src/table/mpt_table.rs index 87a30a5cba..2e24e0fef7 100644 --- a/zkevm-circuits/src/table/mpt_table.rs +++ b/zkevm-circuits/src/table/mpt_table.rs @@ -46,17 +46,17 @@ pub struct MptTable { /// Account address pub address: Column, /// Storage address - pub storage_key: word::Word>, + pub storage_key: WordLoHi>, /// Proof type pub proof_type: Column, /// New MPT root - pub new_root: word::Word>, + pub new_root: WordLoHi>, /// Previous MPT root - pub old_root: word::Word>, + pub old_root: WordLoHi>, /// New value - pub new_value: word::Word>, + pub new_value: WordLoHi>, /// Old value - pub old_value: word::Word>, + pub old_value: WordLoHi>, } impl LookupTable for MptTable { @@ -103,12 +103,12 @@ impl MptTable { pub(crate) fn construct(meta: &mut ConstraintSystem) -> Self { Self { address: meta.advice_column(), - storage_key: word::Word::new([meta.advice_column(), meta.advice_column()]), + storage_key: WordLoHi::new([meta.advice_column(), meta.advice_column()]), proof_type: meta.advice_column(), - new_root: word::Word::new([meta.advice_column(), meta.advice_column()]), - old_root: word::Word::new([meta.advice_column(), meta.advice_column()]), - new_value: word::Word::new([meta.advice_column(), meta.advice_column()]), - old_value: word::Word::new([meta.advice_column(), meta.advice_column()]), + new_root: WordLoHi::new([meta.advice_column(), meta.advice_column()]), + old_root: WordLoHi::new([meta.advice_column(), meta.advice_column()]), + new_value: WordLoHi::new([meta.advice_column(), meta.advice_column()]), + old_value: WordLoHi::new([meta.advice_column(), meta.advice_column()]), } } @@ -119,11 +119,11 @@ impl MptTable { cb: &mut ConstraintBuilder, address: Expression, proof_type: Expression, - storage_key: word::Word>, - new_root: word::Word>, - old_root: word::Word>, - new_value: word::Word>, - old_value: word::Word>, + storage_key: WordLoHi>, + new_root: WordLoHi>, + old_root: WordLoHi>, + new_value: WordLoHi>, + old_value: WordLoHi>, ) { circuit!([meta, cb], { require!(a!(self.address) => address); diff --git a/zkevm-circuits/src/table/rw_table.rs b/zkevm-circuits/src/table/rw_table.rs index ddf1a83a27..6ade04d386 100644 --- a/zkevm-circuits/src/table/rw_table.rs +++ b/zkevm-circuits/src/table/rw_table.rs @@ -17,13 +17,13 @@ pub struct RwTable { /// Key3 (FieldTag) pub field_tag: Column, /// Key3 (StorageKey) - pub storage_key: word::Word>, + pub storage_key: WordLoHi>, /// Value - pub value: word::Word>, + pub value: WordLoHi>, /// Value Previous - pub value_prev: word::Word>, + pub value_prev: WordLoHi>, /// InitVal (Committed Value) - pub init_val: word::Word>, + pub init_val: WordLoHi>, } impl LookupTable for RwTable { @@ -75,10 +75,10 @@ impl RwTable { id: meta.advice_column(), address: meta.advice_column(), field_tag: meta.advice_column(), - storage_key: word::Word::new([meta.advice_column(), meta.advice_column()]), - value: word::Word::new([meta.advice_column(), meta.advice_column()]), - value_prev: word::Word::new([meta.advice_column(), meta.advice_column()]), - init_val: word::Word::new([meta.advice_column(), meta.advice_column()]), + storage_key: WordLoHi::new([meta.advice_column(), meta.advice_column()]), + value: WordLoHi::new([meta.advice_column(), meta.advice_column()]), + value_prev: WordLoHi::new([meta.advice_column(), meta.advice_column()]), + init_val: WordLoHi::new([meta.advice_column(), meta.advice_column()]), } } fn assign( diff --git a/zkevm-circuits/src/table/tx_table.rs b/zkevm-circuits/src/table/tx_table.rs index 0c36548579..6e2777d52c 100644 --- a/zkevm-circuits/src/table/tx_table.rs +++ b/zkevm-circuits/src/table/tx_table.rs @@ -69,7 +69,7 @@ pub struct TxTable { /// Index for Tag = CallData pub index: Column, /// Value - pub value: word::Word>, + pub value: WordLoHi>, } impl TxTable { @@ -79,7 +79,7 @@ impl TxTable { tx_id: meta.advice_column(), tag: meta.fixed_column(), index: meta.advice_column(), - value: word::Word::new([meta.advice_column(), meta.advice_column()]), + value: WordLoHi::new([meta.advice_column(), meta.advice_column()]), } } @@ -159,29 +159,23 @@ impl TxTable { for tx in txs.iter().chain(padding_txs.iter()) { let tx_id = Value::known(F::from(tx.id)); let tx_data = vec![ - ( - TxContextFieldTag::Nonce, - word::Word::from(tx.nonce.as_u64()), - ), - (TxContextFieldTag::Gas, word::Word::from(tx.gas())), - (TxContextFieldTag::GasPrice, word::Word::from(tx.gas_price)), - (TxContextFieldTag::CallerAddress, word::Word::from(tx.from)), + (TxContextFieldTag::Nonce, WordLoHi::from(tx.nonce.as_u64())), + (TxContextFieldTag::Gas, WordLoHi::from(tx.gas())), + (TxContextFieldTag::GasPrice, WordLoHi::from(tx.gas_price)), + (TxContextFieldTag::CallerAddress, WordLoHi::from(tx.from)), ( TxContextFieldTag::CalleeAddress, - word::Word::from(tx.to_or_contract_addr()), - ), - ( - TxContextFieldTag::IsCreate, - word::Word::from(tx.is_create()), + WordLoHi::from(tx.to_or_contract_addr()), ), - (TxContextFieldTag::Value, word::Word::from(tx.value)), + (TxContextFieldTag::IsCreate, WordLoHi::from(tx.is_create())), + (TxContextFieldTag::Value, WordLoHi::from(tx.value)), ( TxContextFieldTag::CallDataLength, - word::Word::from(tx.call_data.len() as u64), + WordLoHi::from(tx.call_data.len() as u64), ), ( TxContextFieldTag::CallDataGasCost, - word::Word::from(tx.call_data_gas_cost()), + WordLoHi::from(tx.call_data_gas_cost()), ), ] .iter() diff --git a/zkevm-circuits/src/table/wd_table.rs b/zkevm-circuits/src/table/wd_table.rs index 93c8d293cd..622e37a1f2 100644 --- a/zkevm-circuits/src/table/wd_table.rs +++ b/zkevm-circuits/src/table/wd_table.rs @@ -10,7 +10,7 @@ pub struct WdTable { /// validator id pub validator_id: Column, /// withdrawal address - pub address: Word>, + pub address: WordLoHi>, /// validator withdrawal amount in Gwei pub amount: Column, } @@ -21,7 +21,7 @@ impl WdTable { Self { id: meta.advice_column(), validator_id: meta.advice_column(), - address: Word::new([meta.advice_column(), meta.advice_column()]), + address: WordLoHi::new([meta.advice_column(), meta.advice_column()]), amount: meta.advice_column(), } } @@ -78,7 +78,7 @@ impl WdTable { .chain(padding_withdrawals.iter()) .enumerate() { - let address_word = Word::from(wd.address); + let address_word = WordLoHi::from(wd.address); let row = [ Value::known(F::from(wd.id)), Value::known(F::from(wd.validator_id)), diff --git a/zkevm-circuits/src/test_util.rs b/zkevm-circuits/src/test_util.rs index e73b5d18e7..f35e1ce7bf 100644 --- a/zkevm-circuits/src/test_util.rs +++ b/zkevm-circuits/src/test_util.rs @@ -69,7 +69,7 @@ const NUM_BLINDING_ROWS: usize = 64; /// txs[0] /// .from(MOCK_ACCOUNTS[0]) /// .gas_price(gwei(2)) -/// .gas(Word::from(0x10000)) +/// .gas(WordLoHi::from(0x10000)) /// .value(eth(2)) /// .input(code.into()); /// }, diff --git a/zkevm-circuits/src/tx_circuit.rs b/zkevm-circuits/src/tx_circuit.rs index a13020f5af..4ea61edfcc 100644 --- a/zkevm-circuits/src/tx_circuit.rs +++ b/zkevm-circuits/src/tx_circuit.rs @@ -15,7 +15,7 @@ pub use dev::TxCircuit as TestTxCircuit; use crate::{ table::{KeccakTable, TxFieldTag, TxTable}, - util::{word::Word, Challenges, SubCircuit, SubCircuitConfig}, + util::{word::WordLoHi, Challenges, SubCircuit, SubCircuitConfig}, witness, }; use eth_types::{geth_types::Transaction, sign_types::SignData, Field}; @@ -41,7 +41,7 @@ pub struct TxCircuitConfig { tx_id: Column, tag: Column, index: Column, - value: Word>, + value: WordLoHi>, sign_verify: SignVerifyConfig, _marker: PhantomData, } @@ -103,8 +103,8 @@ impl TxCircuitConfig { tx_id: usize, tag: TxFieldTag, index: usize, - value: Word>, - ) -> Result>, Error> { + value: WordLoHi>, + ) -> Result>, Error> { region.assign_advice( || "tx_id", self.tx_id, @@ -186,7 +186,7 @@ impl TxCircuit { 0, TxFieldTag::Null, 0, - Word::default().into_value(), + WordLoHi::default().into_value(), )?; offset += 1; // Assign all Tx fields except for call data @@ -201,27 +201,33 @@ impl TxCircuit { for (tag, value) in [ ( TxFieldTag::Nonce, - Word::from(tx.nonce.as_u64()).into_value(), + WordLoHi::from(tx.nonce.as_u64()).into_value(), + ), + (TxFieldTag::Gas, WordLoHi::from(tx.gas()).into_value()), + ( + TxFieldTag::GasPrice, + WordLoHi::from(tx.gas_price).into_value(), + ), + ( + TxFieldTag::CallerAddress, + WordLoHi::from(tx.from).into_value(), ), - (TxFieldTag::Gas, Word::from(tx.gas()).into_value()), - (TxFieldTag::GasPrice, Word::from(tx.gas_price).into_value()), - (TxFieldTag::CallerAddress, Word::from(tx.from).into_value()), ( TxFieldTag::CalleeAddress, - Word::from(tx.to_or_zero()).into_value(), + WordLoHi::from(tx.to_or_zero()).into_value(), ), ( TxFieldTag::IsCreate, - Word::from(tx.is_create() as u64).into_value(), + WordLoHi::from(tx.is_create() as u64).into_value(), ), - (TxFieldTag::Value, Word::from(tx.value).into_value()), + (TxFieldTag::Value, WordLoHi::from(tx.value).into_value()), ( TxFieldTag::CallDataLength, - Word::from(tx.call_data.0.len() as u64).into_value(), + WordLoHi::from(tx.call_data.0.len() as u64).into_value(), ), ( TxFieldTag::CallDataGasCost, - Word::from(tx.call_data_gas_cost()).into_value(), + WordLoHi::from(tx.call_data_gas_cost()).into_value(), ), ( TxFieldTag::TxSignHash, @@ -271,7 +277,7 @@ impl TxCircuit { i + 1, // tx_id TxFieldTag::CallData, index, - Word::from(*byte as u64).into_value(), + WordLoHi::from(*byte as u64).into_value(), )?; offset += 1; calldata_count += 1; @@ -284,7 +290,7 @@ impl TxCircuit { 0, // tx_id TxFieldTag::CallData, 0, - Word::default().into_value(), + WordLoHi::default().into_value(), )?; offset += 1; } diff --git a/zkevm-circuits/src/tx_circuit/sign_verify.rs b/zkevm-circuits/src/tx_circuit/sign_verify.rs index fe4d2f3513..9ff41cc2f8 100644 --- a/zkevm-circuits/src/tx_circuit/sign_verify.rs +++ b/zkevm-circuits/src/tx_circuit/sign_verify.rs @@ -10,7 +10,7 @@ use crate::{ util::{from_bytes, not, rlc}, }, table::KeccakTable, - util::{word::Word, Challenges, Expr}, + util::{word::WordLoHi, Challenges, Expr}, }; use ecc::{maingate, EccConfig, GeneralEccChip}; use ecdsa::ecdsa::{AssignedEcdsaSig, AssignedPublicKey, EcdsaChip}; @@ -292,8 +292,8 @@ pub(crate) struct AssignedECDSA { #[derive(Debug)] pub(crate) struct AssignedSignatureVerify { - pub(crate) address: Word>, - pub(crate) msg_hash: Word>, + pub(crate) address: WordLoHi>, + pub(crate) msg_hash: WordLoHi>, } // Return an array of bytes that corresponds to the little endian representation @@ -451,7 +451,7 @@ impl SignVerifyChip { ctx: &mut RegionCtx, is_address_zero: &AssignedCell, pk_rlc: &AssignedCell, - pk_hash: &Word>, + pk_hash: &WordLoHi>, ) -> Result<(), Error> { let copy = |ctx: &mut RegionCtx, name, column, assigned: &AssignedCell| { let copied = ctx.assign_advice(|| name, column, assigned.value().copied())?; @@ -559,8 +559,8 @@ impl SignVerifyChip { )?; ( - Word::new([address_cell_lo, address_cell_hi]), - Word::new([pk_hash_cell_lo, pk_hash_cell_hi]), + WordLoHi::new([address_cell_lo, address_cell_hi]), + WordLoHi::new([pk_hash_cell_lo, pk_hash_cell_hi]), ) }; @@ -594,7 +594,7 @@ impl SignVerifyChip { |_, _| Ok(()), )?; - Word::new([msg_hash_cell_lo, msg_hash_cell_hi]) + WordLoHi::new([msg_hash_cell_lo, msg_hash_cell_hi]) }; let pk_rlc = { diff --git a/zkevm-circuits/src/util/int_decomposition.rs b/zkevm-circuits/src/util/int_decomposition.rs index 8f0950537d..90ad08f355 100644 --- a/zkevm-circuits/src/util/int_decomposition.rs +++ b/zkevm-circuits/src/util/int_decomposition.rs @@ -12,7 +12,7 @@ use crate::evm_circuit::{ util::{rlc, CachedRegion, Cell}, }; -use super::word::{Word, WordExpr}; +use super::word::{WordExpr, WordLoHi}; #[derive(Clone, Debug)] /// IntDecomposition decompose integer into byte limbs @@ -89,7 +89,7 @@ impl Expr for IntDecomposition { } impl WordExpr for IntDecomposition { - fn to_word(&self) -> Word> { + fn to_word(&self) -> WordLoHi> { let exprs = self .limbs .clone() @@ -97,7 +97,7 @@ impl WordExpr for IntDecomposition>>(); - Word::new( + WordLoHi::new( (0..2) .map(|id| exprs.get(id).unwrap_or(&0.expr()).clone()) .collect_vec() diff --git a/zkevm-circuits/src/util/word.rs b/zkevm-circuits/src/util/word.rs index 936b298531..c2e3e381a8 100644 --- a/zkevm-circuits/src/util/word.rs +++ b/zkevm-circuits/src/util/word.rs @@ -35,7 +35,7 @@ pub(crate) type Word4 = WordLimbs; pub(crate) type Word32 = WordLimbs; -pub(crate) type WordCell = Word>; +pub(crate) type WordLoHiCell = WordLoHi>; pub(crate) type Word32Cell = Word32>; @@ -79,7 +79,7 @@ impl Default for WordLimbs { /// Get the word expression pub trait WordExpr { /// Get the word expression - fn to_word(&self) -> Word>; + fn to_word(&self) -> WordLoHi>; } impl WordLimbs, N> { @@ -186,8 +186,8 @@ impl WordLimbs, N> { } impl WordExpr for WordLimbs, N> { - fn to_word(&self) -> Word> { - Word(self.word_expr().to_word_n()) + fn to_word(&self) -> WordLoHi> { + WordLoHi(self.word_expr().to_word_n()) } } @@ -200,9 +200,9 @@ impl WordLimbs { /// `Word`, special alias for Word2. #[derive(Clone, Debug, Copy, Default)] -pub struct Word(Word2); +pub struct WordLoHi(Word2); -impl Word { +impl WordLoHi { /// Construct the word from 2 limbs pub fn new(limbs: [T; 2]) -> Self { Self(WordLimbs::::new(limbs)) @@ -230,19 +230,19 @@ impl Word { (lo, hi) } - /// Wrap `Word` into `Word` - pub fn into_value(self) -> Word> { + /// Wrap `Word` into `WordLoHi` + pub fn into_value(self) -> WordLoHi> { let [lo, hi] = self.0.limbs; - Word::new([Value::known(lo), Value::known(hi)]) + WordLoHi::new([Value::known(lo), Value::known(hi)]) } /// Map the word to other types - pub fn map(&self, mut func: impl FnMut(T) -> T2) -> Word { - Word(WordLimbs::::new([func(self.lo()), func(self.hi())])) + pub fn map(&self, mut func: impl FnMut(T) -> T2) -> WordLoHi { + WordLoHi(WordLimbs::::new([func(self.lo()), func(self.hi())])) } } -impl std::ops::Deref for Word { +impl std::ops::Deref for WordLoHi { type Target = WordLimbs; fn deref(&self) -> &Self::Target { @@ -250,35 +250,35 @@ impl std::ops::Deref for Word { } } -impl PartialEq for Word { +impl PartialEq for WordLoHi { fn eq(&self, other: &Self) -> bool { self.lo() == other.lo() && self.hi() == other.hi() } } -impl From for Word { +impl From for WordLoHi { /// Construct the word from u256 fn from(value: eth_types::Word) -> Self { let bytes = value.to_le_bytes(); - Word::new([ + WordLoHi::new([ from_bytes::value(&bytes[..N_BYTES_HALF_WORD]), from_bytes::value(&bytes[N_BYTES_HALF_WORD..]), ]) } } -impl> OpsIdentity for Word { +impl> OpsIdentity for WordLoHi { /// output type - type Output = Word; + type Output = WordLoHi; fn zero() -> Self::Output { - Word::new([T::zero(), T::zero()]) + WordLoHi::new([T::zero(), T::zero()]) } fn one() -> Self::Output { - Word::new([T::one(), T::zero()]) + WordLoHi::new([T::one(), T::zero()]) } } -impl From for Word { +impl From for WordLoHi { /// Construct the word from H256 fn from(h: H256) -> Self { let le_bytes = { @@ -286,55 +286,55 @@ impl From for Word { b.reverse(); b }; - Word::new([ + WordLoHi::new([ from_bytes::value(&le_bytes[..N_BYTES_HALF_WORD]), from_bytes::value(&le_bytes[N_BYTES_HALF_WORD..]), ]) } } -impl From for Word { +impl From for WordLoHi { /// Construct the word from u64 fn from(value: u64) -> Self { let bytes = value.to_le_bytes(); - Word::new([from_bytes::value(&bytes), F::from(0)]) + WordLoHi::new([from_bytes::value(&bytes), F::from(0)]) } } -impl From for Word { +impl From for WordLoHi { /// Construct the word from u8 fn from(value: u8) -> Self { - Word::new([F::from(value as u64), F::from(0)]) + WordLoHi::new([F::from(value as u64), F::from(0)]) } } -impl From for Word { +impl From for WordLoHi { fn from(value: bool) -> Self { - Word::new([F::from(value as u64), F::from(0)]) + WordLoHi::new([F::from(value as u64), F::from(0)]) } } -impl From for Word { +impl From for WordLoHi { /// Construct the word from h160 fn from(value: H160) -> Self { let mut bytes = *value.as_fixed_bytes(); bytes.reverse(); - Word::new([ + WordLoHi::new([ from_bytes::value(&bytes[..N_BYTES_HALF_WORD]), from_bytes::value(&bytes[N_BYTES_HALF_WORD..]), ]) } } -impl Word> { +impl WordLoHi> { /// Assign advice pub fn assign_advice( &self, region: &mut Region<'_, F>, annotation: A, - column: Word>, + column: WordLoHi>, offset: usize, - ) -> Result>, Error> + ) -> Result>, Error> where A: Fn() -> AR, AR: Into, @@ -343,28 +343,28 @@ impl Word> { let lo = region.assign_advice(|| &annotation, column.lo(), offset, || self.lo())?; let hi = region.assign_advice(|| &annotation, column.hi(), offset, || self.hi())?; - Ok(Word::new([lo, hi])) + Ok(WordLoHi::new([lo, hi])) } } -impl Word> { +impl WordLoHi> { /// Query advice of Word of columns advice pub fn query_advice( &self, meta: &mut VirtualCells, at: Rotation, - ) -> Word> { + ) -> WordLoHi> { self.0.query_advice(meta, at).to_word() } } -impl + Clone> WordExpr for Word { - fn to_word(&self) -> Word> { +impl + Clone> WordExpr for WordLoHi { + fn to_word(&self) -> WordLoHi> { self.map(|limb| limb.expr()) } } -impl Word { +impl WordLoHi { /// Convert address (h160) to single field element. /// This method is Address specific pub fn compress_f(&self) -> F { @@ -372,7 +372,7 @@ impl Word { } } -impl Word> { +impl WordLoHi> { /// create word from lo limb with hi limb as 0. caller need to guaranteed to be 128 bits. pub fn from_lo_unchecked(lo: Expression) -> Self { Self::new([lo, 0.expr()]) @@ -381,13 +381,13 @@ impl Word> { /// select based on selector. Here assume selector is 1/0 therefore no overflow check pub fn select + Clone>( selector: T, - when_true: Word, - when_false: Word, - ) -> Word> { + when_true: WordLoHi, + when_false: WordLoHi, + ) -> WordLoHi> { let (true_lo, true_hi) = when_true.to_lo_hi(); let (false_lo, false_hi) = when_false.to_lo_hi(); - Word::new([ + WordLoHi::new([ selector.expr() * true_lo.expr() + (1.expr() - selector.expr()) * false_lo.expr(), selector.expr() * true_hi.expr() + (1.expr() - selector.expr()) * false_hi.expr(), ]) @@ -395,22 +395,22 @@ impl Word> { /// Assume selector is 1/0 therefore no overflow check pub fn mul_selector(&self, selector: Expression) -> Self { - Word::new([self.lo() * selector.clone(), self.hi() * selector]) + WordLoHi::new([self.lo() * selector.clone(), self.hi() * selector]) } /// No overflow check on lo/hi limbs pub fn add_unchecked(self, rhs: Self) -> Self { - Word::new([self.lo() + rhs.lo(), self.hi() + rhs.hi()]) + WordLoHi::new([self.lo() + rhs.lo(), self.hi() + rhs.hi()]) } /// No underflow check on lo/hi limbs pub fn sub_unchecked(self, rhs: Self) -> Self { - Word::new([self.lo() - rhs.lo(), self.hi() - rhs.hi()]) + WordLoHi::new([self.lo() - rhs.lo(), self.hi() - rhs.hi()]) } /// No overflow check on lo/hi limbs pub fn mul_unchecked(self, rhs: Self) -> Self { - Word::new([self.lo() * rhs.lo(), self.hi() * rhs.hi()]) + WordLoHi::new([self.lo() * rhs.lo(), self.hi() * rhs.hi()]) } /// Convert address (h160) to single expression. @@ -454,14 +454,14 @@ impl WordLimbs, N1> { } impl WordExpr for WordLimbs, N1> { - fn to_word(&self) -> Word> { - Word(self.to_word_n()) + fn to_word(&self) -> WordLoHi> { + WordLoHi(self.to_word_n()) } } -/// Return the hash of the empty code as a `Word>` in little-endian. -pub fn empty_code_hash_word_value() -> Word> { - Word::from(CodeDB::empty_code_hash()).into_value() +/// Return the hash of the empty code as a `WordLoHi>` in little-endian. +pub fn empty_code_hash_word_value() -> WordLoHi> { + WordLoHi::from(CodeDB::empty_code_hash()).into_value() } // TODO unittest diff --git a/zkevm-circuits/src/witness/block.rs b/zkevm-circuits/src/witness/block.rs index 5c839601e6..1628534093 100644 --- a/zkevm-circuits/src/witness/block.rs +++ b/zkevm-circuits/src/witness/block.rs @@ -4,7 +4,7 @@ use crate::{ exp_circuit::param::OFFSET_INCREMENT, instance::public_data_convert, table::BlockContextFieldTag, - util::{log2_ceil, word, SubCircuit}, + util::{log2_ceil, word::WordLoHi, SubCircuit}, }; use bus_mapping::{ circuit_input_builder::{self, CopyEvent, ExpEvent, FeatureConfig, FixedCParams, Withdrawal}, @@ -187,8 +187,8 @@ impl BlockContext { [ Value::known(F::from(BlockContextFieldTag::Coinbase as u64)), Value::known(F::ZERO), - Value::known(word::Word::from(self.coinbase).lo()), - Value::known(word::Word::from(self.coinbase).hi()), + Value::known(WordLoHi::from(self.coinbase).lo()), + Value::known(WordLoHi::from(self.coinbase).hi()), ], [ Value::known(F::from(BlockContextFieldTag::Timestamp as u64)), @@ -205,8 +205,8 @@ impl BlockContext { [ Value::known(F::from(BlockContextFieldTag::Difficulty as u64)), Value::known(F::ZERO), - Value::known(word::Word::from(self.difficulty).lo()), - Value::known(word::Word::from(self.difficulty).hi()), + Value::known(WordLoHi::from(self.difficulty).lo()), + Value::known(WordLoHi::from(self.difficulty).hi()), ], [ Value::known(F::from(BlockContextFieldTag::GasLimit as u64)), @@ -217,20 +217,20 @@ impl BlockContext { [ Value::known(F::from(BlockContextFieldTag::BaseFee as u64)), Value::known(F::ZERO), - Value::known(word::Word::from(self.base_fee).lo()), - Value::known(word::Word::from(self.base_fee).hi()), + Value::known(WordLoHi::from(self.base_fee).lo()), + Value::known(WordLoHi::from(self.base_fee).hi()), ], [ Value::known(F::from(BlockContextFieldTag::ChainId as u64)), Value::known(F::ZERO), - Value::known(word::Word::from(self.chain_id).lo()), - Value::known(word::Word::from(self.chain_id).hi()), + Value::known(WordLoHi::from(self.chain_id).lo()), + Value::known(WordLoHi::from(self.chain_id).hi()), ], [ Value::known(F::from(BlockContextFieldTag::WithdrawalRoot as u64)), Value::known(F::ZERO), - Value::known(word::Word::from(self.withdrawals_root).lo()), - Value::known(word::Word::from(self.withdrawals_root).hi()), + Value::known(WordLoHi::from(self.withdrawals_root).lo()), + Value::known(WordLoHi::from(self.withdrawals_root).hi()), ], ], { @@ -242,8 +242,8 @@ impl BlockContext { [ Value::known(F::from(BlockContextFieldTag::BlockHash as u64)), Value::known((self.number - len_history + idx).to_scalar().unwrap()), - Value::known(word::Word::from(*hash).lo()), - Value::known(word::Word::from(*hash).hi()), + Value::known(WordLoHi::from(*hash).lo()), + Value::known(WordLoHi::from(*hash).hi()), ] }) .collect() diff --git a/zkevm-circuits/src/witness/mpt.rs b/zkevm-circuits/src/witness/mpt.rs index df7b1ddebb..f2005ddb76 100644 --- a/zkevm-circuits/src/witness/mpt.rs +++ b/zkevm-circuits/src/witness/mpt.rs @@ -1,7 +1,7 @@ use crate::{ evm_circuit::witness::Rw, table::{AccountFieldTag, MPTProofType}, - util::word, + util::word::WordLoHi, }; use eth_types::{Address, Field, ToScalar, Word}; use halo2_proofs::circuit::Value; @@ -45,12 +45,12 @@ pub struct MptUpdates { #[derive(Default, Clone, Copy, Debug)] pub struct MptUpdateRow { pub(crate) address: F, - pub(crate) storage_key: word::Word, + pub(crate) storage_key: WordLoHi, pub(crate) proof_type: F, - pub(crate) new_root: word::Word, - pub(crate) old_root: word::Word, - pub(crate) new_value: word::Word, - pub(crate) old_value: word::Word, + pub(crate) new_root: WordLoHi, + pub(crate) old_root: WordLoHi, + pub(crate) new_value: WordLoHi, + pub(crate) old_value: WordLoHi, } impl MptUpdates { @@ -101,12 +101,12 @@ impl MptUpdates { let (new_value, old_value) = update.value_assignments(); MptUpdateRow { address: Value::known(update.key.address().to_scalar().unwrap()), - storage_key: word::Word::::from(update.key.storage_key()).into_value(), + storage_key: WordLoHi::::from(update.key.storage_key()).into_value(), proof_type: Value::known(update.proof_type()), - new_root: word::Word::::from(new_root).into_value(), - old_root: word::Word::::from(old_root).into_value(), - new_value: word::Word::::from(new_value).into_value(), - old_value: word::Word::::from(old_value).into_value(), + new_root: WordLoHi::::from(new_root).into_value(), + old_root: WordLoHi::::from(old_root).into_value(), + new_value: WordLoHi::::from(new_value).into_value(), + old_value: WordLoHi::::from(old_value).into_value(), } }) .collect() diff --git a/zkevm-circuits/src/witness/rw.rs b/zkevm-circuits/src/witness/rw.rs index 6399c3baef..5004848c6c 100644 --- a/zkevm-circuits/src/witness/rw.rs +++ b/zkevm-circuits/src/witness/rw.rs @@ -11,7 +11,7 @@ use itertools::Itertools; use crate::{ table::{AccountFieldTag, CallContextFieldTag, TxLogFieldTag, TxReceiptFieldTag}, - util::{build_tx_log_address, word}, + util::{build_tx_log_address, word::WordLoHi}, }; use super::MptUpdates; @@ -267,10 +267,10 @@ pub struct RwRow { pub(crate) id: F, pub(crate) address: F, pub(crate) field_tag: F, - pub(crate) storage_key: word::Word, - pub(crate) value: word::Word, - pub(crate) value_prev: word::Word, - pub(crate) init_val: word::Word, + pub(crate) storage_key: WordLoHi, + pub(crate) value: WordLoHi, + pub(crate) value_prev: WordLoHi, + pub(crate) init_val: WordLoHi, } impl RwRow { @@ -311,9 +311,9 @@ impl RwRow> { }); inner.unwrap() }; - let unwrap_w = |f: word::Word>| { + let unwrap_w = |f: WordLoHi>| { let (lo, hi) = f.into_lo_hi(); - word::Word::new([unwrap_f(lo), unwrap_f(hi)]) + WordLoHi::new([unwrap_f(lo), unwrap_f(hi)]) }; RwRow { @@ -462,11 +462,11 @@ impl Rw { id: Value::known(F::from(self.id().unwrap_or_default() as u64)), address: Value::known(self.address().unwrap_or_default().to_scalar().unwrap()), field_tag: Value::known(F::from(self.field_tag().unwrap_or_default())), - storage_key: word::Word::from(self.storage_key().unwrap_or_default()).into_value(), - value: word::Word::from(self.value_assignment()).into_value(), - value_prev: word::Word::from(self.value_prev_assignment().unwrap_or_default()) + storage_key: WordLoHi::from(self.storage_key().unwrap_or_default()).into_value(), + value: WordLoHi::from(self.value_assignment()).into_value(), + value_prev: WordLoHi::from(self.value_prev_assignment().unwrap_or_default()) .into_value(), - init_val: word::Word::from(self.committed_value_assignment().unwrap_or_default()) + init_val: WordLoHi::from(self.committed_value_assignment().unwrap_or_default()) .into_value(), } } From 0fa3f56adcee9a4d4090dd3dbb34effd12e7d27b Mon Sep 17 00:00:00 2001 From: Soham Zemse <22412996+zemse@users.noreply.github.com> Date: Wed, 31 Jan 2024 19:09:34 +0530 Subject: [PATCH 2/3] Add refactor as an option to the pull request template --- .github/pull_request_template.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index cbdf4b11bd..13e0dd793e 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -12,6 +12,7 @@ - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update +- [ ] Refactor (no updates to logic) ### Contents From 24139edc864e2541f9f3dfb6a98bf818fd0d1096 Mon Sep 17 00:00:00 2001 From: Soham Zemse <22412996+zemse@users.noreply.github.com> Date: Wed, 7 Feb 2024 15:03:31 +0530 Subject: [PATCH 3/3] Attempt fixing the failing light test --- zkevm-circuits/src/test_util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zkevm-circuits/src/test_util.rs b/zkevm-circuits/src/test_util.rs index f35e1ce7bf..e73b5d18e7 100644 --- a/zkevm-circuits/src/test_util.rs +++ b/zkevm-circuits/src/test_util.rs @@ -69,7 +69,7 @@ const NUM_BLINDING_ROWS: usize = 64; /// txs[0] /// .from(MOCK_ACCOUNTS[0]) /// .gas_price(gwei(2)) -/// .gas(WordLoHi::from(0x10000)) +/// .gas(Word::from(0x10000)) /// .value(eth(2)) /// .input(code.into()); /// },