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

Commit

Permalink
clean up function/variable workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Jun 22, 2023
1 parent 6a5d0c5 commit 8805276
Show file tree
Hide file tree
Showing 73 changed files with 264 additions and 305 deletions.
6 changes: 3 additions & 3 deletions zkevm-circuits/src/evm_circuit/execution/add_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ impl<F: Field> ExecutionGadget<F> for AddSubGadget<F> {
// 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(Word::select(is_sub.expr().0, c.to_word(), a.to_word()));
cb.stack_pop_word(b.to_word());
cb.stack_push_word(Word::select(is_sub.expr().0, a.to_word(), c.to_word()));
cb.stack_pop(Word::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()));

// State transition
let step_state_transition = StepStateTransition {
Expand Down
8 changes: 4 additions & 4 deletions zkevm-circuits/src/evm_circuit/execution/addmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,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_word(a.to_word());
cb.stack_pop_word(b.to_word());
cb.stack_pop_word(n.clone().to_word());
cb.stack_push_word(
cb.stack_pop(a.to_word());
cb.stack_pop(b.to_word());
cb.stack_pop(n.clone().to_word());
cb.stack_push(
r.clone()
.to_word()
.mul_selector(not::expr(n_is_zero.expr())),
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl<F: Field> ExecutionGadget<F> for AddressGadget<F> {
// Lookup callee address in call context.
cb.call_context_lookup_read(None, CallContextFieldTag::CalleeAddress, address.to_word());

cb.stack_push_word(address.to_word());
cb.stack_push(address.to_word());

let step_state_transition = StepStateTransition {
rw_counter: Delta(2.expr()),
Expand Down
8 changes: 4 additions & 4 deletions zkevm-circuits/src/evm_circuit/execution/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<F: Field> ExecutionGadget<F> for BalanceGadget<F> {

fn configure(cb: &mut EVMConstraintBuilder<F>) -> Self {
let address = cb.query_account_address();
cb.stack_pop_word(address.to_word());
cb.stack_pop(address.to_word());

let tx_id = cb.call_context(None, CallContextFieldTag::TxId);
let mut reversion_info = cb.reversion_info_read(None);
Expand All @@ -55,7 +55,7 @@ impl<F: Field> ExecutionGadget<F> for BalanceGadget<F> {
);
let code_hash = cb.query_word_unchecked();
// For non-existing accounts the code_hash must be 0 in the rw_table.
cb.account_read_word(
cb.account_read(
address.to_word(),
AccountFieldTag::CodeHash,
code_hash.to_word(),
Expand All @@ -64,7 +64,7 @@ impl<F: Field> ExecutionGadget<F> for BalanceGadget<F> {
let exists = not::expr(not_exists.expr());
let balance = cb.query_word32();
cb.condition(exists.expr(), |cb| {
cb.account_read_word(
cb.account_read(
address.to_word(),
AccountFieldTag::Balance,
balance.to_word(),
Expand All @@ -74,7 +74,7 @@ impl<F: Field> ExecutionGadget<F> for BalanceGadget<F> {
cb.require_zero_word("balance is zero when non_exists", balance.to_word());
});

cb.stack_push_word(balance.to_word());
cb.stack_push(balance.to_word());

let gas_cost = select::expr(
is_warm.expr(),
Expand Down
14 changes: 7 additions & 7 deletions zkevm-circuits/src/evm_circuit/execution/begin_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {

// Increase caller's nonce.
// (tx caller's nonce always increases even tx ends with error)
cb.account_write_word(
cb.account_write(
tx_caller_address.to_word(),
AccountFieldTag::Nonce,
Word::from_lo_unchecked(tx_nonce.expr() + 1.expr()),
Expand Down Expand Up @@ -191,7 +191,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
// Query coinbase address.
let coinbase = cb.query_word_unchecked();
let is_coinbase_warm = cb.query_bool();
cb.block_lookup_word(
cb.block_lookup(
BlockContextFieldTag::Coinbase.expr(),
None,
coinbase.to_word(),
Expand All @@ -207,7 +207,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
// Read code_hash of callee
let code_hash = cb.query_word_unchecked();
let is_empty_code_hash =
IsEqualWordGadget::construct(cb, &code_hash.to_word(), &cb.empty_code_hash_word());
IsEqualWordGadget::construct(cb, &code_hash.to_word(), &cb.empty_code_hash());
let callee_not_exists = IsZeroWordGadget::construct(cb, &code_hash);
// no_callee_code is true when the account exists and has empty
// code hash, or when the account doesn't exist (which we encode with
Expand All @@ -216,7 +216,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {

// TODO: And not precompile
cb.condition(not::expr(tx_is_create.expr()), |cb| {
cb.account_read_word(
cb.account_read(
tx_callee_address.to_word(),
AccountFieldTag::CodeHash,
code_hash.to_word(),
Expand All @@ -240,7 +240,7 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {
cb.require_equal_word(
"tx caller address equivalence",
tx_caller_address.to_word(),
create.caller_address_word(),
create.caller_address(),
);
cb.condition(tx_is_create.expr(), |cb| {
cb.require_equal_word(
Expand All @@ -263,13 +263,13 @@ impl<F: Field> ExecutionGadget<F> for BeginTxGadget<F> {

// 1. Handle contract creation transaction.
cb.condition(tx_is_create.expr(), |cb| {
cb.keccak_table_lookup_word(
cb.keccak_table_lookup(
create.input_rlc(cb),
create.input_length(),
caller_nonce_hash_bytes.to_word(),
);

cb.account_write_word(
cb.account_write(
call_callee_address.to_word(),
AccountFieldTag::Nonce,
Word::one(),
Expand Down
6 changes: 3 additions & 3 deletions zkevm-circuits/src/evm_circuit/execution/bitwise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ impl<F: Field> ExecutionGadget<F> for BitwiseGadget<F> {
let b = cb.query_word32();
let c = cb.query_word32();

cb.stack_pop_word(a.to_word());
cb.stack_pop_word(b.to_word());
cb.stack_push_word(c.to_word());
cb.stack_pop(a.to_word());
cb.stack_pop(b.to_word());
cb.stack_push(c.to_word());

// Because opcode AND, OR, and XOR are continuous, so we can make the
// FixedTableTag of them also continuous, and use the opcode delta from
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/block_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<F: Field> ExecutionGadget<F> for BlockCtxGadget<F> {
fn configure(cb: &mut EVMConstraintBuilder<F>) -> Self {
let value = cb.query_word_unchecked(); // block table lookup below

cb.stack_push_word(value.to_word());
cb.stack_push(value.to_word());

// Get op's FieldTag
let opcode = cb.query_cell();
Expand All @@ -43,7 +43,7 @@ impl<F: Field> ExecutionGadget<F> for BlockCtxGadget<F> {

// Lookup block table with block context ops
// TIMESTAMP/NUMBER/GASLIMIT, COINBASE and DIFFICULTY/BASEFEE
cb.block_lookup_word(blockctx_tag, None, value.to_word());
cb.block_lookup(blockctx_tag, None, value.to_word());

// State transition
let step_state_transition = StepStateTransition {
Expand Down
8 changes: 4 additions & 4 deletions zkevm-circuits/src/evm_circuit/execution/blockhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ impl<F: Field> ExecutionGadget<F> for BlockHashGadget<F> {

fn configure(cb: &mut EVMConstraintBuilder<F>) -> Self {
let current_block_number = cb.query_cell();
cb.block_lookup_word(
cb.block_lookup(
BlockContextFieldTag::Number.expr(),
None,
Word::from_lo_unchecked(current_block_number.expr()),
);

let block_number = WordByteCapGadget::construct(cb, current_block_number.expr());
cb.stack_pop_word(block_number.original_word_new().to_word());
cb.stack_pop(block_number.original_word().to_word());

let block_hash = cb.query_word_unchecked();

Expand All @@ -59,7 +59,7 @@ impl<F: Field> ExecutionGadget<F> for BlockHashGadget<F> {
let is_valid = and::expr([block_number.lt_cap(), diff_lt.expr()]);

cb.condition(is_valid.expr(), |cb| {
cb.block_lookup_word(
cb.block_lookup(
BlockContextFieldTag::BlockHash.expr(),
Some(block_number.valid_value()),
block_hash.to_word(),
Expand All @@ -73,7 +73,7 @@ impl<F: Field> ExecutionGadget<F> for BlockHashGadget<F> {
);
});

cb.stack_push_word(block_hash.to_word());
cb.stack_push(block_hash.to_word());

let step_state_transition = StepStateTransition {
rw_counter: Delta(2.expr()),
Expand Down
6 changes: 3 additions & 3 deletions zkevm-circuits/src/evm_circuit/execution/byte.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ impl<F: Field> ExecutionGadget<F> for ByteGadget<F> {
// push the selected byte on the stack
// We can push the selected byte here directly because
// it only uses the LSB of a word.
cb.stack_pop_word(index.to_word());
cb.stack_pop_word(value.to_word());
cb.stack_push_word(Word::from_lo_unchecked(selected_byte));
cb.stack_pop(index.to_word());
cb.stack_pop(value.to_word());
cb.stack_push(Word::from_lo_unchecked(selected_byte));

// State transition
let step_state_transition = StepStateTransition {
Expand Down
6 changes: 3 additions & 3 deletions zkevm-circuits/src/evm_circuit/execution/calldatacopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ impl<F: Field> ExecutionGadget<F> for CallDataCopyGadget<F> {
let data_offset = WordByteCapGadget::construct(cb, call_data_length.expr());

// Pop memory_offset, data_offset, length from stack
cb.stack_pop_word(memory_offset.to_word());
cb.stack_pop_word(data_offset.original_word_new().to_word());
cb.stack_pop_word(length.to_word());
cb.stack_pop(memory_offset.to_word());
cb.stack_pop(data_offset.original_word().to_word());
cb.stack_pop(length.to_word());

// Lookup the calldata_length and caller_address in Tx context table or
// Call context table
Expand Down
6 changes: 3 additions & 3 deletions zkevm-circuits/src/evm_circuit/execution/calldataload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<F: Field> ExecutionGadget<F> for CallDataLoadGadget<F> {
let call_data_offset = cb.query_cell();

let data_offset = WordByteCapGadget::construct(cb, call_data_length.expr());
cb.stack_pop_word(data_offset.original_word_new().to_word());
cb.stack_pop(data_offset.original_word().to_word());

cb.condition(
and::expr([data_offset.not_overflow(), cb.curr.state.is_root.expr()]),
Expand Down Expand Up @@ -137,7 +137,7 @@ impl<F: Field> ExecutionGadget<F> for CallDataLoadGadget<F> {
cb.curr.state.is_root.expr(),
]),
|cb| {
cb.tx_context_lookup_word(
cb.tx_context_lookup(
src_id.expr(),
TxContextFieldTag::CallData,
Some(src_addr.expr() + idx.expr()),
Expand Down Expand Up @@ -178,7 +178,7 @@ impl<F: Field> ExecutionGadget<F> for CallDataLoadGadget<F> {
calldata_word.to_word().mul_selector(data_offset.overflow()),
);

cb.stack_push_word(calldata_word.to_word());
cb.stack_push(calldata_word.to_word());

let step_state_transition = StepStateTransition {
rw_counter: Delta(cb.rw_counter_offset()),
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/calldatasize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<F: Field> ExecutionGadget<F> for CallDataSizeGadget<F> {
);

// The calldatasize should be pushed to the top of the stack.
cb.stack_push_word(call_data_size.to_word());
cb.stack_push(call_data_size.to_word());

let step_state_transition = StepStateTransition {
rw_counter: Delta(2.expr()),
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/caller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl<F: Field> ExecutionGadget<F> for CallerGadget<F> {
);

// Push the value to the stack
cb.stack_push_word(caller_address.to_word());
cb.stack_push(caller_address.to_word());

// State transition
let opcode = cb.query_cell();
Expand Down
6 changes: 3 additions & 3 deletions zkevm-circuits/src/evm_circuit/execution/callop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ impl<F: Field> ExecutionGadget<F> for CallOpGadget<F> {
let callee_address = Word::select(
is_callcode.expr() + is_delegatecall.expr(),
current_callee_address.to_word(),
call_gadget.callee_address_word(),
call_gadget.callee_address(),
);

// Add callee to access list
let is_warm = cb.query_bool();
let is_warm_prev = cb.query_bool();
cb.account_access_list_write_unchecked(
tx_id.expr(),
call_gadget.callee_address_word(),
call_gadget.callee_address(),
is_warm.expr(),
is_warm_prev.expr(),
Some(&mut reversion_info),
Expand Down Expand Up @@ -152,7 +152,7 @@ impl<F: Field> ExecutionGadget<F> for CallOpGadget<F> {
});

let caller_balance_word = cb.query_word_unchecked();
cb.account_read_word(
cb.account_read(
caller_address.to_word(),
AccountFieldTag::Balance,
caller_balance_word.to_word(),
Expand Down
2 changes: 1 addition & 1 deletion zkevm-circuits/src/evm_circuit/execution/callvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<F: Field> ExecutionGadget<F> for CallValueGadget<F> {
);

// Push the value to the stack
cb.stack_push_word(call_value.to_word());
cb.stack_push(call_value.to_word());

// State transition
let opcode = cb.query_cell();
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/chainid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ impl<F: Field> ExecutionGadget<F> for ChainIdGadget<F> {
let chain_id = cb.query_word_unchecked();

// Push the value to the stack
cb.stack_push_word(chain_id.to_word());
cb.stack_push(chain_id.to_word());

// Lookup block table with chain_id
cb.block_lookup_word(
cb.block_lookup(
BlockContextFieldTag::ChainId.expr(),
None,
chain_id.to_word(),
Expand Down
8 changes: 4 additions & 4 deletions zkevm-circuits/src/evm_circuit/execution/codecopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ impl<F: Field> ExecutionGadget<F> for CodeCopyGadget<F> {
let code_offset = WordByteCapGadget::construct(cb, code_size.expr());

// Pop items from stack.
cb.stack_pop_word(dst_memory_offset.to_word());
cb.stack_pop_word(code_offset.original_word_new().to_word());
cb.stack_pop_word(Word::from_lo_unchecked(length.expr()));
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()));

// Construct memory address in the destionation (memory) to which we copy code.
let dst_memory_addr = MemoryAddressGadget::construct(cb, dst_memory_offset, length);
Expand All @@ -72,7 +72,7 @@ impl<F: Field> ExecutionGadget<F> for CodeCopyGadget<F> {
let code_hash = cb.curr.state.code_hash.clone();

// Fetch the bytecode length from the bytecode table.
cb.bytecode_length_word(code_hash.to_word(), code_size.expr());
cb.bytecode_length(code_hash.to_word(), code_size.expr());

// Calculate the next memory size and the gas cost for this memory
// access. This also accounts for the dynamic gas required to copy bytes to
Expand Down
4 changes: 2 additions & 2 deletions zkevm-circuits/src/evm_circuit/execution/codesize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ impl<F: Field> ExecutionGadget<F> for CodesizeGadget<F> {

let code_hash = cb.curr.state.code_hash.clone();
let codesize = cb.query_cell();
cb.bytecode_length_word(code_hash.to_word(), codesize.expr());
cb.bytecode_length(code_hash.to_word(), codesize.expr());

cb.require_equal(
"Constraint: bytecode length lookup == codesize",
codesize_bytes.expr(),
codesize.expr(),
);

cb.stack_push_word(codesize_bytes.to_word());
cb.stack_push(codesize_bytes.to_word());

let step_state_transition = StepStateTransition {
gas_left: Transition::Delta(-OpcodeId::CODESIZE.constant_gas_cost().expr()),
Expand Down
6 changes: 3 additions & 3 deletions zkevm-circuits/src/evm_circuit/execution/comparator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ impl<F: Field> ExecutionGadget<F> for ComparatorGadget<F> {
// 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(Word::select(is_gt.expr(), b.to_word(), a.to_word()));
cb.stack_pop_word(Word::select(is_gt.expr(), a.to_word(), b.to_word()));
cb.stack_push_word(Word::from_lo_unchecked(result.expr()));
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()));

// State transition
let step_state_transition = StepStateTransition {
Expand Down
Loading

0 comments on commit 8805276

Please sign in to comment.