Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
fix ide caused refactor error
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed May 9, 2023
1 parent 088f583 commit 0e3e310
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 40 deletions.
6 changes: 3 additions & 3 deletions zkevm-circuits/src/evm_circuit/execution/addmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<F: Field> ExecutionGadget<F> for AddModGadget<F> {

cb.require_equal(
"check a_reduced + b 512 bit carry if n != 0",
sum_areduced_b_overflow.word_expr(),
sum_areduced_b_overflow.expr(),
sum_areduced_b.carry().clone().unwrap().expr() * not::expr(n_is_zero.expr()),
);

Expand All @@ -104,10 +104,10 @@ impl<F: Field> ExecutionGadget<F> for AddModGadget<F> {

// pop/push values
// take care that if n==0 pushed value for r should be zero also
cb.stack_pop(a.word_expr());
cb.stack_pop(a.expr());
cb.stack_pop(b.expr());
cb.stack_pop(n.expr());
cb.stack_push(r.word_expr() * not::expr(n_is_zero.expr()));
cb.stack_push(r.expr() * not::expr(n_is_zero.expr()));

// State transition
let step_state_transition = StepStateTransition {
Expand Down
16 changes: 8 additions & 8 deletions zkevm-circuits/src/evm_circuit/execution/begin_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use crate::{
ContractCreateGadget, IsEqualGadget, IsZeroGadget, MulWordByU64Gadget,
RangeCheckGadget,
},
not, or, select, CachedRegion, Cell, StepRws, Word,
not, or, select, CachedRegion, Cell, StepRws,
},
witness::{Block, Call, ExecStep, Transaction},
},
table::{AccountFieldTag, CallContextFieldTag, TxFieldTag as TxContextFieldTag},
util::Expr,
util::{word::Word32Cell, Expr},
};
use eth_types::{evm_types::GasCost, Field, ToLittleEndian, ToScalar};
use ethers_core::utils::{get_contract_address, keccak256};
Expand All @@ -32,14 +32,14 @@ pub(crate) struct BeginTxGadget<F> {
tx_id: Cell<F>,
tx_nonce: Cell<F>,
tx_gas: Cell<F>,
tx_gas_price: Word<F>,
tx_gas_price: Word32Cell<F>,
mul_gas_fee_by_gas: MulWordByU64Gadget<F>,
tx_caller_address: Cell<F>,
tx_caller_address_is_zero: IsZeroGadget<F>,
tx_callee_address: Cell<F>,
call_callee_address: Cell<F>,
tx_is_create: Cell<F>,
tx_value: Word<F>,
tx_value: Word32Cell<F>,
tx_call_data_length: Cell<F>,
tx_call_data_gas_cost: Cell<F>,
reversion_info: ReversionInfo<F>,
Expand Down Expand Up @@ -67,14 +67,14 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
1.expr(),
Some(call_id.expr()),
CallContextFieldTag::TxId,
Word::from_lo(tx_id.expr()),
tx_id.expr(),
); // rwc_delta += 1
let mut reversion_info = cb.reversion_info_write(None); // rwc_delta += 2
cb.call_context_lookup(
1.expr(),
Some(call_id.expr()),
CallContextFieldTag::IsSuccess,
Word::from_lo(reversion_info.is_persistent()),
reversion_info.is_persistent(),
); // rwc_delta += 1

let [tx_nonce, tx_gas, tx_caller_address, tx_callee_address, tx_is_create, tx_call_data_length, tx_call_data_gas_cost] =
Expand Down Expand Up @@ -240,7 +240,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
CallContextFieldTag::CallDataLength,
tx_call_data_length.expr(),
),
(CallContextFieldTag::Value, tx_value.word_expr()),
(CallContextFieldTag::Value, tx_value.expr()),
(CallContextFieldTag::IsStatic, 0.expr()),
(CallContextFieldTag::LastCalleeId, 0.expr()),
(CallContextFieldTag::LastCalleeReturnDataOffset, 0.expr()),
Expand Down Expand Up @@ -343,7 +343,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
CallContextFieldTag::CallDataLength,
tx_call_data_length.expr(),
),
(CallContextFieldTag::Value, tx_value.word_expr()),
(CallContextFieldTag::Value, tx_value.expr()),
(CallContextFieldTag::IsStatic, 0.expr()),
(CallContextFieldTag::LastCalleeId, 0.expr()),
(CallContextFieldTag::LastCalleeReturnDataOffset, 0.expr()),
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/callop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ impl<F: Field> ExecutionGadget<F> for CallOpGadget<F> {
CallContextFieldTag::Value,
select::expr(
is_delegatecall.expr(),
current_value.word_expr(),
current_value.expr(),
call_gadget.value.expr(),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
constraint_builder::EVMConstraintBuilder,
math_gadget::{IsEqualGadget, IsZeroGadget, RangeCheckGadget},
memory_gadget::{address_high, address_low, MemoryExpansionGadget},
CachedRegion, Cell, Word,
CachedRegion, Cell,
},
witness::{Block, Call, ExecStep, Transaction},
},
Expand Down Expand Up @@ -71,7 +71,7 @@ impl<F: Field> ExecutionGadget<F> for ErrorOOGStaticMemoryGadget<F> {

// Pop the address from the stack
// We still have to do this to verify the correctness of `address`
cb.stack_pop(address.word_expr());
cb.stack_pop(address.expr());

// TODO: Use ContextSwitchGadget to switch call context to caller's and
// consume all gas_left.
Expand Down
10 changes: 5 additions & 5 deletions zkevm-circuits/src/evm_circuit/execution/mul_div_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ impl<F: Field> ExecutionGadget<F> for MulDivModGadget<F> {
// 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(select::expr(is_mul.clone(), a.word_expr(), d.word_expr()));
cb.stack_pop(b.word_expr());
cb.stack_pop(select::expr(is_mul.clone(), a.expr(), d.expr()));
cb.stack_pop(b.expr());
cb.stack_push(
is_mul.clone() * d.word_expr()
+ is_div * a.word_expr() * (1.expr() - divisor_is_zero.expr())
+ is_mod * c.word_expr() * (1.expr() - divisor_is_zero.expr()),
is_mul.clone() * d.expr()
+ is_div * a.expr() * (1.expr() - divisor_is_zero.expr())
+ is_mod * c.expr() * (1.expr() - divisor_is_zero.expr()),
);

// Constraint for MUL case
Expand Down
26 changes: 11 additions & 15 deletions zkevm-circuits/src/evm_circuit/execution/mulmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@ use crate::{
execution::ExecutionGadget,
step::ExecutionState,
util::{
self,
common_gadget::SameContextGadget,
constraint_builder::{
ConstrainBuilderCommon, EVMConstraintBuilder, StepStateTransition,
Transition::Delta,
},
constraint_builder::{EVMConstraintBuilder, StepStateTransition, Transition::Delta},
math_gadget::{IsZeroGadget, LtWordGadget, ModGadget, MulAddWords512Gadget},
sum, CachedRegion,
},
witness::{Block, Call, ExecStep, Transaction},
},
util::Expr,
util::{word::Word32Cell, Expr},
};
use bus_mapping::evm::OpcodeId;
use eth_types::{Field, ToLittleEndian, U256};
Expand All @@ -27,11 +23,11 @@ use halo2_proofs::plonk::Error;
pub(crate) struct MulModGadget<F> {
same_context: SameContextGadget<F>,
// a, b, n, r
pub words: [util::Word<F>; 4],
k: util::Word<F>,
a_reduced: util::Word<F>,
d: util::Word<F>,
e: util::Word<F>,
pub words: [Word32Cell<F>; 4],
k: Word32Cell<F>,
a_reduced: Word32Cell<F>,
d: Word32Cell<F>,
e: Word32Cell<F>,
modword: ModGadget<F>,
mul512_left: MulAddWords512Gadget<F>,
mul512_right: MulAddWords512Gadget<F>,
Expand Down Expand Up @@ -75,10 +71,10 @@ impl<F: Field> ExecutionGadget<F> for MulModGadget<F> {
1.expr() - lt.expr() - n_is_zero.expr(),
);

cb.stack_pop(a.word_expr());
cb.stack_pop(b.word_expr());
cb.stack_pop(n.word_expr());
cb.stack_push(r.word_expr());
cb.stack_pop(a.expr());
cb.stack_pop(b.expr());
cb.stack_pop(n.expr());
cb.stack_push(r.expr());

// State transition
let step_state_transition = StepStateTransition {
Expand Down
8 changes: 4 additions & 4 deletions zkevm-circuits/src/evm_circuit/execution/sdiv_smod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ impl<F: Field> ExecutionGadget<F> for SignedDivModGadget<F> {
let remainder_is_zero =
IsZeroGadget::construct(cb, sum::expr(&remainder_abs_word.x().cells));

cb.stack_pop(dividend_abs_word.x().word_expr());
cb.stack_pop(divisor_abs_word.x().word_expr());
cb.stack_pop(dividend_abs_word.x().expr());
cb.stack_pop(divisor_abs_word.x().expr());
cb.stack_push(select::expr(
is_sdiv,
quotient_abs_word.x().word_expr() * (1.expr() - divisor_is_zero.expr()),
remainder_abs_word.x().word_expr() * (1.expr() - divisor_is_zero.expr()),
quotient_abs_word.x().expr() * (1.expr() - divisor_is_zero.expr()),
remainder_abs_word.x().expr() * (1.expr() - divisor_is_zero.expr()),
));

// Constrain `|quotient| * |divisor| + |remainder| = |dividend|`.
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/shl_shr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ impl<F: Field> ExecutionGadget<F> for ShlShrGadget<F> {
// - for SHL, two pops are shift and quotient, and push is dividend.
// - for SHR, two pops are shift and dividend, and push is quotient.
cb.stack_pop(shift.expr());
cb.stack_pop(is_shl.expr() * quotient.word_expr() + is_shr.expr() * dividend.word_expr());
cb.stack_pop(is_shl.expr() * quotient.expr() + is_shr.expr() * dividend.expr());
cb.stack_push(
(is_shl.expr() * dividend.word_expr() + is_shr.expr() * quotient.word_expr())
(is_shl.expr() * dividend.expr() + is_shr.expr() * quotient.expr())
* (1.expr() - divisor_is_zero.expr()),
);

Expand Down

0 comments on commit 0e3e310

Please sign in to comment.