diff --git a/zkevm-circuits/src/evm_circuit/execution/callop.rs b/zkevm-circuits/src/evm_circuit/execution/callop.rs index ca0809b8a6..66716640c1 100644 --- a/zkevm-circuits/src/evm_circuit/execution/callop.rs +++ b/zkevm-circuits/src/evm_circuit/execution/callop.rs @@ -271,7 +271,7 @@ impl ExecutionGadget for CallOpGadget { let gas_cost = call_gadget.gas_cost_expr(is_warm_prev.expr(), is_call.expr()); // Apply EIP 150 let gas_available = cb.curr.state.gas_left.expr() - gas_cost.clone(); - let one_64th_gas = ConstantDivisionGadget::construct(cb, gas_available.clone(), 64); + let one_64th_gas = cb.div_by_const(gas_available.clone(), 64); let all_but_one_64th_gas = gas_available - one_64th_gas.quotient(); let capped_callee_gas_left = cb.min_max(call_gadget.gas_expr(), all_but_one_64th_gas.clone()); @@ -476,8 +476,8 @@ impl ExecutionGadget for CallOpGadget { let callee_gas_left = callee_gas_left.expr() + call_gadget.has_value.clone() * GAS_STIPEND_CALL_WITH_VALUE.expr(); - let precompile_output_word_size_div: ConstantDivisionGadget = - ConstantDivisionGadget::construct(cb, precompile_output_rws.expr(), 32); + let precompile_output_word_size_div = + cb.div_by_const(precompile_output_rws.expr(), 32); let precompile_output_word_size_div_remainder_zero = cb.is_zero(precompile_output_word_size_div.remainder()); let precompile_output_word_size = precompile_output_word_size_div.quotient() diff --git a/zkevm-circuits/src/evm_circuit/execution/create.rs b/zkevm-circuits/src/evm_circuit/execution/create.rs index fe22ffe8bb..9b560a16ce 100644 --- a/zkevm-circuits/src/evm_circuit/execution/create.rs +++ b/zkevm-circuits/src/evm_circuit/execution/create.rs @@ -168,7 +168,7 @@ impl ExecutionGadget< ); let gas_cost = GasCost::CREATE.expr() + memory_expansion.gas_cost() + keccak_gas_cost; let gas_remaining = cb.curr.state.gas_left.expr() - gas_cost.clone(); - let gas_left = ConstantDivisionGadget::construct(cb, gas_remaining.clone(), 64); + let gas_left = cb.div_by_const(gas_remaining.clone(), 64); let callee_gas_left = gas_remaining - gas_left.quotient(); let was_warm = cb.query_bool(); diff --git a/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs b/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs index 42a3ff98aa..8d58c5b18e 100644 --- a/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs +++ b/zkevm-circuits/src/evm_circuit/util/constraint_builder.rs @@ -1,7 +1,7 @@ use super::{ math_gadget::{ - IsEqualGadget, IsEqualWordGadget, IsZeroGadget, IsZeroWordGadget, LtGadget, LtWordGadget, - MinMaxGadget, + ConstantDivisionGadget, IsEqualGadget, IsEqualWordGadget, IsZeroGadget, IsZeroWordGadget, + LtGadget, LtWordGadget, MinMaxGadget, }, rlc, AccountAddress, CachedRegion, CellType, MemoryAddress, StoredExpression, U64Cell, }; @@ -586,18 +586,6 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { // Math gadgets - // abs_word - // add_word - // binary_number - // byte_size - // cmp_words - // comparison - // constant_division - // modulo - // mul_add_words - // mul_add_words512 - // mul_word_u64 - pub(crate) fn is_zero(&mut self, value: Expression) -> IsZeroGadget { IsZeroGadget::construct(self, value) } @@ -642,6 +630,14 @@ impl<'a, F: Field> EVMConstraintBuilder<'a, F> { MinMaxGadget::construct(self, lhs, rhs) } + pub(crate) fn div_by_const( + &mut self, + numerator: Expression, + denominator: u64, + ) -> ConstantDivisionGadget { + ConstantDivisionGadget::construct(self, numerator, denominator) + } + // Fixed pub(crate) fn range_lookup(&mut self, value: Expression, range: u64) { diff --git a/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs b/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs index b917a57683..3d13fb37a6 100644 --- a/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs +++ b/zkevm-circuits/src/evm_circuit/util/memory_gadget.rs @@ -339,7 +339,7 @@ pub(crate) struct MemoryWordSizeGadget { impl MemoryWordSizeGadget { pub(crate) fn construct(cb: &mut EVMConstraintBuilder, address: Expression) -> Self { - let memory_word_size = ConstantDivisionGadget::construct(cb, address + 31.expr(), 32); + let memory_word_size = cb.div_by_const(address + 31.expr(), 32); Self { memory_word_size } } diff --git a/zkevm-circuits/src/evm_circuit/util/tx.rs b/zkevm-circuits/src/evm_circuit/util/tx.rs index 94e22407bb..d99b029ffd 100644 --- a/zkevm-circuits/src/evm_circuit/util/tx.rs +++ b/zkevm-circuits/src/evm_circuit/util/tx.rs @@ -240,8 +240,7 @@ impl TxDataGadget { // Calculate transaction gas fee let mul_gas_fee_by_gas = MulWordByU64Gadget::construct(cb, gas_price.clone(), gas.expr()); - let call_data_word_length = - ConstantDivisionGadget::construct(cb, call_data_length.expr() + 31.expr(), 32); + let call_data_word_length = cb.div_by_const(call_data_length.expr() + 31.expr(), 32); let (cost_sum, gas_mul_gas_price_plus_value) = if calculate_total_cost { let cost_sum = cb.query_word32();