From 82c59820defb838679032de41a7b81ca9f14a7b2 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Thu, 26 Sep 2024 21:25:03 -0400 Subject: [PATCH 01/12] Add increment WIP --- .../src/cpu/columns/general.rs | 25 ++++ evm_arithmetization/src/cpu/columns/ops.rs | 2 + evm_arithmetization/src/cpu/contextops.rs | 1 + evm_arithmetization/src/cpu/cpu_stark.rs | 7 +- evm_arithmetization/src/cpu/decode.rs | 5 +- evm_arithmetization/src/cpu/gas.rs | 1 + evm_arithmetization/src/cpu/incr.rs | 117 ++++++++++++++++++ .../src/cpu/kernel/asm/balance.asm | 2 +- .../src/cpu/kernel/asm/bignum/add.asm | 6 +- .../src/cpu/kernel/asm/bignum/addmul.asm | 4 +- .../src/cpu/kernel/asm/bignum/isone.asm | 4 +- .../src/cpu/kernel/asm/bignum/iszero.asm | 2 +- .../src/cpu/kernel/asm/bignum/modmul.asm | 13 +- .../src/cpu/kernel/asm/bignum/mul.asm | 4 +- .../src/cpu/kernel/asm/bloom_filter.asm | 10 +- .../src/cpu/kernel/asm/core/access_lists.asm | 34 ++--- .../cpu/kernel/asm/core/create_addresses.asm | 2 +- .../asm/core/create_contract_account.asm | 2 +- .../cpu/kernel/asm/core/create_receipt.asm | 14 +-- .../src/cpu/kernel/asm/core/exception.asm | 11 +- .../src/cpu/kernel/asm/core/intrinsic_gas.asm | 3 +- .../src/cpu/kernel/asm/core/log.asm | 22 ++-- .../src/cpu/kernel/asm/core/nonce.asm | 2 +- .../kernel/asm/core/precompiles/expmod.asm | 2 +- .../kernel/asm/core/precompiles/snarkv.asm | 4 +- .../cpu/kernel/asm/core/selfdestruct_list.asm | 8 +- .../src/cpu/kernel/asm/core/syscall.asm | 11 +- .../src/cpu/kernel/asm/core/terminate.asm | 4 +- .../cpu/kernel/asm/core/touched_addresses.asm | 10 +- .../src/cpu/kernel/asm/core/transfer.asm | 4 +- .../src/cpu/kernel/asm/core/util.asm | 6 +- .../bn254/curve_arithmetic/miller_loop.asm | 10 +- .../asm/curve/bn254/curve_arithmetic/msm.asm | 2 +- .../curve/bn254/curve_arithmetic/pairing.asm | 2 +- .../bn254/field_arithmetic/degree_12_mul.asm | 4 +- .../asm/curve/bn254/field_arithmetic/util.asm | 40 +++--- .../kernel/asm/curve/secp256k1/ecrecover.asm | 2 +- .../asm/curve/secp256k1/precomputation.asm | 4 +- .../src/cpu/kernel/asm/curve/wnaf.asm | 2 +- .../cpu/kernel/asm/hash/blake2/addresses.asm | 2 +- .../cpu/kernel/asm/hash/blake2/blake2_f.asm | 18 ++- .../cpu/kernel/asm/hash/blake2/blake2b.asm | 2 +- .../kernel/asm/hash/blake2/compression.asm | 24 ++-- .../kernel/asm/hash/blake2/g_functions.asm | 2 +- .../src/cpu/kernel/asm/hash/ripemd/update.asm | 4 +- .../cpu/kernel/asm/hash/sha2/compression.asm | 4 +- .../src/cpu/kernel/asm/hash/sha2/main.asm | 4 +- .../kernel/asm/hash/sha2/message_schedule.asm | 4 +- .../kernel/asm/journal/account_destroyed.asm | 4 +- .../src/cpu/kernel/asm/journal/journal.asm | 22 ++-- .../asm/journal/transient_storage_change.asm | 2 +- .../src/cpu/kernel/asm/main.asm | 8 +- .../src/cpu/kernel/asm/memory/core.asm | 4 +- .../src/cpu/kernel/asm/memory/memcpy.asm | 6 +- .../src/cpu/kernel/asm/memory/metadata.asm | 4 +- .../src/cpu/kernel/asm/memory/packing.asm | 8 +- .../src/cpu/kernel/asm/memory/syscalls.asm | 2 +- .../kernel/asm/memory/transient_storage.asm | 12 +- .../src/cpu/kernel/asm/mpt/accounts.asm | 8 +- .../src/cpu/kernel/asm/mpt/delete/delete.asm | 2 +- .../kernel/asm/mpt/delete/delete_branch.asm | 16 +-- .../asm/mpt/delete/delete_extension.asm | 22 ++-- .../src/cpu/kernel/asm/mpt/hash/hash.asm | 25 ++-- .../asm/mpt/hash/hash_trie_specific.asm | 44 +++---- .../src/cpu/kernel/asm/mpt/hex_prefix.asm | 10 +- .../src/cpu/kernel/asm/mpt/insert/insert.asm | 2 +- .../asm/mpt/insert/insert_extension.asm | 10 +- .../cpu/kernel/asm/mpt/insert/insert_leaf.asm | 10 +- .../asm/mpt/linked_list/final_tries.asm | 20 +-- .../asm/mpt/linked_list/initial_tries.asm | 9 +- .../asm/mpt/linked_list/linked_list.asm | 68 +++++----- .../src/cpu/kernel/asm/mpt/read.asm | 10 +- .../src/cpu/kernel/asm/mpt/util.asm | 4 +- .../src/cpu/kernel/asm/rlp/decode.asm | 13 +- .../src/cpu/kernel/asm/rlp/encode.asm | 36 +++--- .../cpu/kernel/asm/rlp/encode_rlp_scalar.asm | 8 +- .../cpu/kernel/asm/rlp/encode_rlp_string.asm | 6 +- .../kernel/asm/rlp/increment_bounded_rlp.asm | 2 +- .../src/cpu/kernel/asm/shift.asm | 2 +- .../src/cpu/kernel/asm/signed.asm | 2 +- .../asm/transactions/common_decoding.asm | 3 +- .../cpu/kernel/asm/transactions/router.asm | 2 +- .../cpu/kernel/asm/transactions/type_1.asm | 4 +- .../cpu/kernel/asm/transactions/type_2.asm | 4 +- .../cpu/kernel/asm/transactions/type_3.asm | 4 +- .../src/cpu/kernel/asm/util/basic_macros.asm | 4 +- .../src/cpu/kernel/asm/util/math.asm | 4 +- evm_arithmetization/src/cpu/kernel/opcodes.rs | 4 + evm_arithmetization/src/cpu/mod.rs | 1 + evm_arithmetization/src/cpu/stack.rs | 2 + evm_arithmetization/src/generation/mod.rs | 4 +- evm_arithmetization/src/generation/state.rs | 7 +- evm_arithmetization/src/witness/gas.rs | 1 + evm_arithmetization/src/witness/operation.rs | 85 ++++++++++++- evm_arithmetization/src/witness/transition.rs | 5 + 95 files changed, 624 insertions(+), 383 deletions(-) create mode 100644 evm_arithmetization/src/cpu/incr.rs diff --git a/evm_arithmetization/src/cpu/columns/general.rs b/evm_arithmetization/src/cpu/columns/general.rs index 97f8b8f49..067a810b9 100644 --- a/evm_arithmetization/src/cpu/columns/general.rs +++ b/evm_arithmetization/src/cpu/columns/general.rs @@ -15,6 +15,7 @@ pub(crate) union CpuGeneralColumnsView { shift: CpuShiftView, stack: CpuStackView, push: CpuPushView, + incr: CpuIncrView, context_pruning: CpuContextPruningView, } @@ -93,6 +94,18 @@ impl CpuGeneralColumnsView { unsafe { &mut self.push } } + /// View of the columns required for the incr operation. + /// SAFETY: Each view is a valid interpretation of the underlying array. + pub(crate) const fn incr(&self) -> &CpuIncrView { + unsafe { &self.incr } + } + + /// Mutable view of the columns required for the incr operation. + /// SAFETY: Each view is a valid interpretation of the underlying array. + pub(crate) fn incr_mut(&mut self) -> &mut CpuIncrView { + unsafe { &mut self.incr } + } + /// View of the column for context pruning. /// SAFETY: Each view is a valid interpretation of the underlying array. pub(crate) const fn context_pruning(&self) -> &CpuContextPruningView { @@ -217,6 +230,17 @@ pub(crate) struct CpuPushView { _padding_columns: [T; NUM_SHARED_COLUMNS - 1], } +/// View of all `CpuGeneralColumn`s, helping to detect any limb overflow +/// when incrementing by 1. +#[repr(C)] +#[derive(Copy, Clone)] +pub(crate) struct CpuIncrView { + /// If limb `i` is 1, then we overflowed the first `i-1` limbs when adding + /// 1 (i.e. they are now 0). This means limb `1` is incremented by 1, and + /// higher limbs remain unchanged. + pub(crate) limbs: [T; NUM_SHARED_COLUMNS], +} + /// View of the first `CpuGeneralColumn` storing a flag for context pruning. #[derive(Copy, Clone)] pub(crate) struct CpuContextPruningView { @@ -243,4 +267,5 @@ const_assert!(size_of::>() == NUM_SHARED_COLUMNS); const_assert!(size_of::>() == NUM_SHARED_COLUMNS); const_assert!(size_of::>() == NUM_SHARED_COLUMNS); const_assert!(size_of::>() == NUM_SHARED_COLUMNS); +const_assert!(size_of::>() == NUM_SHARED_COLUMNS); const_assert!(size_of::>() == NUM_SHARED_COLUMNS); diff --git a/evm_arithmetization/src/cpu/columns/ops.rs b/evm_arithmetization/src/cpu/columns/ops.rs index 5e91457e9..bf2082b69 100644 --- a/evm_arithmetization/src/cpu/columns/ops.rs +++ b/evm_arithmetization/src/cpu/columns/ops.rs @@ -39,6 +39,8 @@ pub(crate) struct OpsColumnsView { pub m_op_general: T, /// Combines PC and PUSH0 pub pc_push0: T, + /// Flag for INCR_N instructions. + pub incr: T, /// Flag for syscalls. pub syscall: T, diff --git a/evm_arithmetization/src/cpu/contextops.rs b/evm_arithmetization/src/cpu/contextops.rs index 11ffe0da3..7f6d3bf31 100644 --- a/evm_arithmetization/src/cpu/contextops.rs +++ b/evm_arithmetization/src/cpu/contextops.rs @@ -33,6 +33,7 @@ const KEEPS_CONTEXT: OpsColumnsView = OpsColumnsView { m_op_32bytes: true, exit_kernel: true, m_op_general: true, + incr: true, syscall: true, exception: true, }; diff --git a/evm_arithmetization/src/cpu/cpu_stark.rs b/evm_arithmetization/src/cpu/cpu_stark.rs index a0dd45e1e..74cbd97ae 100644 --- a/evm_arithmetization/src/cpu/cpu_stark.rs +++ b/evm_arithmetization/src/cpu/cpu_stark.rs @@ -15,14 +15,13 @@ use starky::lookup::{Column, Filter}; use starky::stark::Stark; use super::columns::CpuColumnsView; -use super::halt; use super::kernel::constants::context_metadata::ContextMetadata; use super::membus::{NUM_CHANNELS, NUM_GP_CHANNELS}; use crate::all_stark::{EvmStarkFrame, Table}; use crate::cpu::columns::{COL_MAP, NUM_CPU_COLUMNS}; use crate::cpu::{ - byte_unpacking, clock, contextops, control_flow, decode, dup_swap, gas, jumps, membus, memio, - modfp254, pc, push0, shift, simple_logic, stack, syscalls_exceptions, + byte_unpacking, clock, contextops, control_flow, decode, dup_swap, gas, halt, incr, jumps, + membus, memio, modfp254, pc, push0, shift, simple_logic, stack, syscalls_exceptions, }; use crate::memory::segments::Segment; use crate::memory::VALUE_LIMBS; @@ -612,6 +611,7 @@ impl, const D: usize> Stark for CpuStark, const D: usize> Stark for CpuStark> = OpsColumnsView { m_op_32bytes: KERNEL_ONLY_INSTR, exit_kernel: None, m_op_general: KERNEL_ONLY_INSTR, + incr: KERNEL_ONLY_INSTR, syscall: None, exception: None, }; diff --git a/evm_arithmetization/src/cpu/incr.rs b/evm_arithmetization/src/cpu/incr.rs new file mode 100644 index 000000000..9a6ae551e --- /dev/null +++ b/evm_arithmetization/src/cpu/incr.rs @@ -0,0 +1,117 @@ +use itertools::izip; +use plonky2::field::extension::Extendable; +use plonky2::field::packed::PackedField; +use plonky2::hash::hash_types::RichField; +use plonky2::iop::ext_target::ExtensionTarget; +use plonky2::plonk::circuit_builder::CircuitBuilder; +use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; + +use crate::cpu::columns::{CpuColumnsView, MemoryChannelView}; +use crate::memory::VALUE_LIMBS; + +/// Constrain two channels such that their values `A` and `B` satisfy +/// `B = A + 1`, by using the `CpuIncrView` helper limbs. +fn channels_incremented_packed( + filter: P, + ch_a: &MemoryChannelView

, + ch_b: &MemoryChannelView

, + helper_limbs: [P; VALUE_LIMBS], + yield_constr: &mut ConstraintConsumer

, +) { + for (limb_a, limb_b, helper) in izip!(ch_a.value, ch_b.value, helper_limbs) { + // If there was an overflow on the current limb, `limb_b` will be 0, else + // we enforce proper increment. + yield_constr.constraint(filter * limb_b * (limb_b - limb_a - helper)); + } +} + +/// Constrain two channels such that their values `A` and `B` satisfy +/// `B = A + 1`, by using the `CpuIncrView` helper limbs. +fn channels_incremented_circuit, const D: usize>( + builder: &mut CircuitBuilder, + filter: ExtensionTarget, + ch_a: &MemoryChannelView>, + ch_b: &MemoryChannelView>, + helper_limbs: [ExtensionTarget; VALUE_LIMBS], + yield_constr: &mut RecursiveConstraintConsumer, +) { + for (limb_a, limb_b, helper) in izip!(ch_a.value, ch_b.value, helper_limbs) { + // If there was an overflow on the current limb, `limb_b` will be 0, else + // we enforce proper increment. + let diff = builder.sub_extension(limb_b, limb_a); + let diff = builder.sub_extension(diff, helper); + let constr = builder.mul_extension(limb_b, diff); + let constr = builder.mul_extension(filter, constr); + yield_constr.constraint(builder, constr); + } +} + +/// Evaluates the constraints for the DUP and SWAP opcodes. +pub(crate) fn eval_packed( + lv: &CpuColumnsView

, + yield_constr: &mut ConstraintConsumer

, +) { + // Constrain the helper columns. + { + // First limb is always 1. + yield_constr.constraint(lv.op.incr * (lv.general.incr().limbs[0] - P::ONES)); + + // 1s and 0s must be contiguous + for i in 1..VALUE_LIMBS - 1 { + yield_constr.constraint( + lv.op.incr + * (lv.general.incr().limbs[i] - P::ONES) + * lv.general.incr().limbs[i + 1], + ); + } + } + + channels_incremented_packed( + lv.op.incr, + &lv.mem_channels[1], + &lv.mem_channels[2], + lv.general.incr().limbs, + yield_constr, + ); + + // Disable the partial channel. + yield_constr.constraint(lv.op.incr * lv.partial_channel.used); +} + +/// Circuit version of `eval_packed`. +/// Evaluates the constraints for the DUP and SWAP opcodes. +pub(crate) fn eval_ext_circuit, const D: usize>( + builder: &mut CircuitBuilder, + lv: &CpuColumnsView>, + yield_constr: &mut RecursiveConstraintConsumer, +) { + // Constrain the helper columns. + { + // First limb is always 1. + let constr = builder.mul_sub_extension(lv.op.incr, lv.general.incr().limbs[0], lv.op.incr); + yield_constr.constraint(builder, constr); + + // 1s and 0s must be contiguous + for i in 1..VALUE_LIMBS - 1 { + let constr = + builder.mul_sub_extension(lv.op.incr, lv.general.incr().limbs[i], lv.op.incr); + let constr = builder.mul_extension(constr, lv.general.incr().limbs[i + 1]); + yield_constr.constraint(builder, constr); + } + } + + channels_incremented_circuit( + builder, + lv.op.incr, + &lv.mem_channels[1], + &lv.mem_channels[2], + lv.general.incr().limbs, + yield_constr, + ); + + // Disable the partial channel. + { + let constr = builder.mul_extension(lv.op.incr, lv.partial_channel.used); + yield_constr.constraint(builder, constr); + } +} diff --git a/evm_arithmetization/src/cpu/kernel/asm/balance.asm b/evm_arithmetization/src/cpu/kernel/asm/balance.asm index d39f66063..3774a5b24 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/balance.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/balance.asm @@ -30,7 +30,7 @@ global balance: %mpt_read_state_trie // stack: account_ptr, retdest DUP1 ISZERO %jumpi(retzero) // If the account pointer is null, return 0. - %add_const(1) + INCR1 // stack: balance_ptr, retdest %mload_trie_data // stack: balance, retdest diff --git a/evm_arithmetization/src/cpu/kernel/asm/bignum/add.asm b/evm_arithmetization/src/cpu/kernel/asm/bignum/add.asm index 4433ab224..3babfef95 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/bignum/add.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/bignum/add.asm @@ -40,12 +40,10 @@ add_loop: // stack: a_cur_addr, c[cur], carry_new, base_addr, i, a_cur_loc, b_cur_loc, retdest %swap_mstore // stack: carry_new, base_addr, i, a_cur_loc, b_cur_loc, retdest - SWAP3 - %increment - SWAP3 + INCR4 // stack: carry_new, base_addr, i, a_cur_loc + 1, b_cur_loc, retdest SWAP4 - %increment + INCR1 SWAP4 // stack: carry_new, base_addr, i, a_cur_loc + 1, b_cur_loc + 1, retdest SWAP2 diff --git a/evm_arithmetization/src/cpu/kernel/asm/bignum/addmul.asm b/evm_arithmetization/src/cpu/kernel/asm/bignum/addmul.asm index 9cdf904e1..44aeef826 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/bignum/addmul.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/bignum/addmul.asm @@ -87,11 +87,11 @@ addmul_loop: // stack: i-1, base_addr, carry_limb, a_cur_loc, b_cur_loc, val, retdest SWAP3 // stack: a_cur_loc, base_addr, carry_limb, i-1, b_cur_loc, val, retdest - %increment + INCR1 // stack: a_cur_loc+1, base_addr, carry_limb, i-1, b_cur_loc, val, retdest SWAP4 // stack: b_cur_loc, base_addr, carry_limb, i-1, a_cur_loc+1, val, retdest - %increment + INCR1 // stack: b_cur_loc+1, base_addr, carry_limb, i-1, a_cur_loc+1, val, retdest %stack (b, addr, c, i, a) -> (c, addr, i, a, b) // stack: carry_limb, base_addr, i-1, a_cur_loc+1, b_cur_loc+1, val, retdest diff --git a/evm_arithmetization/src/cpu/kernel/asm/bignum/isone.asm b/evm_arithmetization/src/cpu/kernel/asm/bignum/isone.asm index 7aaf32f45..fe36cf4dc 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/bignum/isone.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/bignum/isone.asm @@ -28,8 +28,6 @@ starts_with_one: // Starts with one, so check that the remaining limbs are zero. // stack: len, start_loc, retdest %decrement - SWAP1 - %increment - SWAP1 + INCR2 // stack: len-1, start_loc+1, retdest %jump(iszero_bignum) diff --git a/evm_arithmetization/src/cpu/kernel/asm/bignum/iszero.asm b/evm_arithmetization/src/cpu/kernel/asm/bignum/iszero.asm index a6027b611..3e2e81d70 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/bignum/iszero.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/bignum/iszero.asm @@ -21,7 +21,7 @@ iszero_loop: // stack: cur_val, cur_loc, end_loc, retdest %jumpi(neqzero) // stack: cur_loc, end_loc, retdest - %increment + INCR1 // stack: cur_loc + 1, end_loc, retdest %stack (vals: 2) -> (vals, vals) // stack: cur_loc + 1, end_loc, cur_loc + 1, end_loc, retdest diff --git a/evm_arithmetization/src/cpu/kernel/asm/bignum/modmul.asm b/evm_arithmetization/src/cpu/kernel/asm/bignum/modmul.asm index 9735f6108..17b770816 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/bignum/modmul.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/bignum/modmul.asm @@ -36,7 +36,7 @@ modmul_remainder_loop: DUP4 ADD // out_addr_i %swap_mstore // stack: i, base_addr, len, a_loc, b_loc, m_loc, out_loc, s1, s2, s3, retdest - %increment + INCR1 DUP3 DUP2 // stack: i+1, len, i+1, base_addr, len, a_loc, b_loc, m_loc, out_loc, s1, s2, s3, retdest @@ -89,7 +89,7 @@ modmul_quotient_loop: DUP4 ADD // s1_addr_i %swap_mstore // stack: i, base_addr, 2*len, len, a_loc, b_loc, m_loc, out_loc, s1, s2, s3, retdest - %increment + INCR1 DUP3 DUP2 // stack: i+1, 2*len, i+1, base_addr, 2*len, len, a_loc, b_loc, m_loc, out_loc, s1, s2, s3, retdest @@ -156,13 +156,12 @@ modmul_check_loop: SWAP1 %decrement // stack: n-1, base_addr, i, j, retdest + INCR3 SWAP2 - %increment // stack: i+1, base_addr, n-1, j, retdest - SWAP3 - %increment - // stack: j+1, base_addr, n-1, i+1, retdest - %stack (j, addr, n, i) -> (n, addr, n, i, j) + INCR4 + // stack: i+1, base_addr, n-1, j+1, retdest + %stack (i, addr, n) -> (n, addr, n, i) // stack: n-1, base_addr, n-1, i+1, j+1, retdest %jumpi(modmul_check_loop) // end of modmul_check_loop diff --git a/evm_arithmetization/src/cpu/kernel/asm/bignum/mul.asm b/evm_arithmetization/src/cpu/kernel/asm/bignum/mul.asm index b3269f73a..141d8a8b3 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/bignum/mul.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/bignum/mul.asm @@ -47,11 +47,11 @@ mul_addmul_return: %decrement // stack: n-1, base_addr, len, a_start_loc, bi, output_cur, retdest SWAP4 - %increment + INCR1 SWAP4 // stack: n-1, base_addr, len, a_start_loc, bi+1, output_cur, retdest SWAP5 - %increment + INCR1 SWAP5 // stack: n-1, base_addr, len, a_start_loc, bi+1, output_cur+1, retdest DUP1 diff --git a/evm_arithmetization/src/cpu/kernel/asm/bloom_filter.asm b/evm_arithmetization/src/cpu/kernel/asm/bloom_filter.asm index 35a4ebd76..c80a9fd99 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/bloom_filter.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/bloom_filter.asm @@ -53,7 +53,7 @@ logs_bloom_loop: // stack: log_payload_len_ptr, i, logs_len, retdest // Add address to bloom filter. - %increment + INCR1 // stack: addr_ptr, i, logs_len, retdest PUSH @SEGMENT_LOGS_DATA %build_kernel_address DUP1 @@ -63,12 +63,12 @@ logs_bloom_loop: // stack: is_topic, addr, full_addr_ptr, i, logs_len, retdest %add_to_bloom // stack: full_addr_ptr, i, logs_len, retdest - %increment + INCR1 // stack: full_num_topics_ptr, i, logs_len, retdest DUP1 MLOAD_GENERAL // stack: num_topics, full_num_topics_ptr, i, logs_len, retdest - SWAP1 %increment + INCR2 SWAP1 // stack: full_topics_ptr, num_topics, i, logs_len, retdest PUSH 0 @@ -85,13 +85,13 @@ logs_bloom_topic_loop: // stack: is_topic, topic, j, topics_ptr, num_topics, i, logs_len, retdest %add_to_bloom // stack: j, topics_ptr, num_topics, i, logs_len, retdest - %increment + INCR1 %jump(logs_bloom_topic_loop) logs_bloom_topic_end: // stack: num_topics, topics_ptr, num_topics, i, logs_len, retdest %pop3 - %increment + INCR1 %jump(logs_bloom_loop) logs_bloom_end: diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/access_lists.asm b/evm_arithmetization/src/cpu/kernel/asm/core/access_lists.asm index 84cc4077b..539334462 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/access_lists.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/access_lists.asm @@ -21,13 +21,13 @@ global init_access_lists: DUP1 %mstore_u256_max // Store @SEGMENT_ACCESSED_ADDRESSES at address 1 - %increment + INCR1 DUP1 PUSH @SEGMENT_ACCESSED_ADDRESSES MSTORE_GENERAL // Store the segment scaled length - %increment + INCR1 %mstore_global_metadata(@GLOBAL_METADATA_ACCESSED_ADDRESSES_LEN) // stack: (empty) @@ -43,7 +43,7 @@ global init_access_lists: MSTORE_GENERAL // Store the segment scaled length - %increment + INCR1 %mstore_global_metadata(@GLOBAL_METADATA_ACCESSED_STORAGE_KEYS_LEN) // Reset the access lists pointers in the `GenerationState` @@ -117,7 +117,7 @@ global insert_accessed_addresses: // stack: pred_ptr, addr, retdest // Check that this is not a deleted node - %increment + INCR1 MLOAD_GENERAL %jump_neq_const(@U256_MAX, address_found) // We should have found the address. @@ -131,7 +131,7 @@ insert_new_address: // stack: pred_addr, pred_ptr, addr, retdest POP // get the value of the next address - %increment + INCR1 // stack: next_ptr_ptr, addr, retdest %mload_global_metadata(@GLOBAL_METADATA_ACCESSED_ADDRESSES_LEN) DUP2 @@ -158,13 +158,13 @@ insert_new_address: DUP4 MSTORE_GENERAL // stack: new_ptr, next_ptr, addr, retdest - %increment + INCR1 DUP1 // stack: new_next_ptr, new_next_ptr, next_ptr, addr, retdest SWAP2 MSTORE_GENERAL // stack: new_next_ptr, addr, retdest - %increment + INCR1 %mstore_global_metadata(@GLOBAL_METADATA_ACCESSED_ADDRESSES_LEN) // stack: addr, retdest %journal_add_account_loaded @@ -185,7 +185,7 @@ global remove_accessed_addresses: // stack: pred_ptr/2, addr, retdest %get_valid_addr_ptr // stack: pred_ptr, addr, retdest - %increment + INCR1 // stack: next_ptr_ptr, addr, retdest DUP1 MLOAD_GENERAL @@ -196,7 +196,7 @@ global remove_accessed_addresses: DUP4 %assert_eq // stack: next_ptr, next_ptr_ptr, addr, retdest - %increment + INCR1 // stack: next_next_ptr_ptr, next_ptr_ptr, addr, retdest DUP1 MLOAD_GENERAL @@ -255,7 +255,7 @@ global insert_accessed_storage_keys: %assert_eq // stack: pred_ptr, addr, key, retdest DUP1 - %increment + INCR1 MLOAD_GENERAL // stack: pred_key, pred_ptr, addr, key, retdest DUP1 DUP5 @@ -277,7 +277,7 @@ global insert_accessed_storage_keys: storage_key_found: // The address was already in the list // stack: pred_ptr, addr, key, retdest - %add_const(2) + %increment_twice %stack (value_ptr, addr, key, retdest) -> (retdest, 0, value_ptr) // Return 0 to indicate that the address was already present. JUMP @@ -308,7 +308,7 @@ insert_storage_key: SWAP2 EQ // stack: next_val == addr, addr < next_val, next_ptr, new_ptr, next_ptr_ptr, addr, key, retdest - DUP3 %increment + DUP3 INCR1 MLOAD_GENERAL DUP8 LT @@ -325,17 +325,17 @@ insert_storage_key: DUP4 MSTORE_GENERAL // store addr // stack: new_ptr, next_ptr, addr, key, retdest - %increment + INCR1 DUP1 // stack: new_ptr+1, new_ptr+1, next_ptr, addr, key, retdest DUP5 // stack: key, new_ptr+1, new_ptr+1, next_ptr, addr, key, retdest MSTORE_GENERAL // store key // stack: new_ptr+1, next_ptr, addr, key, retdest - %increment + INCR1 DUP1 // stack: new_ptr+2, value_ptr, next_ptr, addr, key, retdest - %increment + INCR1 DUP1 // stack: new_next_ptr, new_next_ptr, value_ptr, next_ptr, addr, key, retdest SWAP3 @@ -344,7 +344,7 @@ insert_storage_key: // stack: value_ptr, new_next_ptr, addr, key, retdest SWAP1 // stack: new_next_ptr, value_ptr, addr, key, retdest - %increment + INCR1 %mstore_global_metadata(@GLOBAL_METADATA_ACCESSED_STORAGE_KEYS_LEN) // stack: value_ptr, addr, key, retdest %stack (value_ptr, addr, key, retdest) -> (addr, key, retdest, 1, value_ptr) @@ -365,7 +365,7 @@ global remove_accessed_storage_keys: MLOAD_GENERAL // stack: next_ptr, next_ptr_ptr, addr, key, retdest DUP1 - %increment + INCR1 MLOAD_GENERAL // stack: next_key, next_ptr, next_ptr_ptr, addr, key, retdest DUP5 diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/create_addresses.asm b/evm_arithmetization/src/cpu/kernel/asm/core/create_addresses.asm index cf7b97b28..40c00e833 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/create_addresses.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/create_addresses.asm @@ -43,7 +43,7 @@ global get_create2_address: PUSH 0xff MSTORE_GENERAL // stack: addr, sender, code_hash, salt, retdest - %increment + INCR1 %stack (addr, sender, code_hash, salt, retdest) -> (addr, sender, salt, code_hash, retdest) MSTORE_32BYTES_20 // stack: addr, salt, code_hash, retdest diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/create_contract_account.asm b/evm_arithmetization/src/cpu/kernel/asm/core/create_contract_account.asm index a614f9fa8..fb2d1409b 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/create_contract_account.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/create_contract_account.asm @@ -72,6 +72,6 @@ // stack: nb_created_contracts, address, nb_created_contracts %mstore_kernel(@SEGMENT_CREATED_CONTRACTS) // stack: nb_created_contracts - %increment + INCR1 %mstore_global_metadata(@GLOBAL_METADATA_CREATED_CONTRACTS_LEN) %endmacro diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/create_receipt.asm b/evm_arithmetization/src/cpu/kernel/asm/core/create_receipt.asm index edcd3f329..4fe059073 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/create_receipt.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/create_receipt.asm @@ -122,14 +122,14 @@ process_receipt_logs_loop: %append_to_trie_data // stack: log_ptr, i, num_logs, receipt_ptr, txn_nb, new_cum_gas, txn_nb, num_nibbles, retdest // Write address. - %increment + INCR1 // stack: addr_ptr, i, num_logs, receipt_ptr, txn_nb, new_cum_gas, txn_nb, num_nibbles, retdest DUP1 MLOAD_GENERAL %append_to_trie_data // stack: addr_ptr, i, num_logs, receipt_ptr, txn_nb, new_cum_gas, txn_nb, num_nibbles, retdest // Write num_topics. - %increment + INCR1 // stack: num_topics_ptr, i, num_logs, receipt_ptr, txn_nb, new_cum_gas, txn_nb, num_nibbles, retdest DUP1 MLOAD_GENERAL @@ -137,7 +137,7 @@ process_receipt_logs_loop: DUP1 %append_to_trie_data // stack: num_topics, num_topics_ptr, i, num_logs, receipt_ptr, txn_nb, new_cum_gas, txn_nb, num_nibbles, retdest - SWAP1 %increment SWAP1 + INCR2 // stack: num_topics, topics_ptr, i, num_logs, receipt_ptr, txn_nb, new_cum_gas, txn_nb, num_nibbles, retdest PUSH 0 @@ -155,7 +155,7 @@ process_receipt_topics_loop: MLOAD_GENERAL %append_to_trie_data // stack: j, num_topics, topics_ptr, i, num_logs, receipt_ptr, txn_nb, new_cum_gas, txn_nb, num_nibbles, retdest - %increment + INCR1 %jump(process_receipt_topics_loop) process_receipt_topics_end: @@ -170,7 +170,7 @@ process_receipt_topics_end: DUP1 %append_to_trie_data // stack: data_len, data_len_ptr, i, num_logs, receipt_ptr, txn_nb, new_cum_gas, txn_nb, num_nibbles, retdest - SWAP1 %increment SWAP1 + INCR2 // stack: data_len, data_ptr, i, num_logs, receipt_ptr, txn_nb, new_cum_gas, txn_nb, num_nibbles, retdest PUSH 0 @@ -188,13 +188,13 @@ process_receipt_data_loop: MLOAD_GENERAL %append_to_trie_data // stack: j, data_len, data_ptr, i, num_logs, receipt_ptr, txn_nb, new_cum_gas, txn_nb, num_nibbles, retdest - %increment + INCR1 %jump(process_receipt_data_loop) process_receipt_data_end: // stack: data_len, data_len, data_ptr, i, num_logs, receipt_ptr, txn_nb, new_cum_gas, txn_nb, num_nibbles, retdest + INCR4 %pop3 - %increment %jump(process_receipt_logs_loop) process_receipt_after_write: diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm b/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm index bea641c2e..e2f28fc4b 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm @@ -184,7 +184,7 @@ global exc_stop: SUB // First, check the stack length. // stack: stack_len-3 = stack_len_before_exc, addr_registers, trap_info - DUP2 %add_const(2) + DUP2 %increment_twice MLOAD_GENERAL // stack: stored_stack_length, stack_len_before_exc, addr_registers, trap_info DUP2 %assert_eq @@ -228,7 +228,7 @@ global exc_stop: DUP3 %shr_const(32) MOD // stack: is_kernel_mode, addr_registers, trap_info - DUP2 %increment + DUP2 INCR1 MLOAD_GENERAL %assert_eq @@ -415,7 +415,12 @@ min_stack_len_for_opcode: BYTES 4 %endrep - %rep 16 // 0xe0-0xef, invalid + BYTES 1 // 0xe0, INCR1 + BYTES 2 // 0xe1, INCR2 + BYTES 3 // 0xe2, INCR3 + BYTES 4 // 0xe3, INCR4 + + %rep 12 // 0xe5-0xef, invalid BYTES 0 %endrep diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/intrinsic_gas.asm b/evm_arithmetization/src/cpu/kernel/asm/core/intrinsic_gas.asm index bb7a21b5d..fba52aa0c 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/intrinsic_gas.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/intrinsic_gas.asm @@ -20,9 +20,8 @@ count_zeros_loop: %stack (data_i_is_zero, i, zeros) -> (data_i_is_zero, zeros, i) ADD // stack: zeros', i, retdest + INCR2 SWAP1 - // stack: i, zeros', retdest - %increment // stack: i', zeros', retdest %jump(count_zeros_loop) diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/log.asm b/evm_arithmetization/src/cpu/kernel/asm/core/log.asm index f23d5e174..c9466efe0 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/log.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/log.asm @@ -106,22 +106,22 @@ global log_n_entry: // stack: log_ptr, logs_len, log_ptr, logs_len, address, num_topics, topics, data_len, data_offset, retdest %mstore_kernel(@SEGMENT_LOGS) // stack: log_ptr, logs_len, address, num_topics, topics, data_len, data_offset, retdest - SWAP1 %increment + INCR2 SWAP1 %mstore_global_metadata(@GLOBAL_METADATA_LOGS_LEN) // stack: log_ptr, address, num_topics, topics, data_len, data_offset, retdest - %increment + INCR1 // stack: addr_ptr, address, num_topics, topics, data_len, data_offset, retdest // Store the address. DUP2 DUP2 %mstore_kernel(@SEGMENT_LOGS_DATA) - %increment + INCR1 // stack: num_topics_ptr, address, num_topics, topics, data_len, data_offset, retdest SWAP1 POP // stack: num_topics_ptr, num_topics, topics, data_len, data_offset, retdest // Store num_topics. DUP2 DUP2 %mstore_kernel(@SEGMENT_LOGS_DATA) - %increment + INCR1 // stack: topics_ptr, num_topics, topics, data_len, data_offset, retdest DUP2 // stack: num_topics, topics_ptr, num_topics, topics, data_len, data_offset, retdest @@ -131,7 +131,7 @@ global log_n_entry: // Store the first topic. DUP3 DUP2 %mstore_kernel(@SEGMENT_LOGS_DATA) - %increment + INCR1 %stack (curr_topic_ptr, num_topics, topic1) -> (curr_topic_ptr, num_topics) DUP2 %eq_const(1) %jumpi(log_after_topics) @@ -139,7 +139,7 @@ global log_n_entry: // Store the second topic. DUP3 DUP2 %mstore_kernel(@SEGMENT_LOGS_DATA) - %increment + INCR1 %stack (curr_topic_ptr, num_topics, topic2) -> (curr_topic_ptr, num_topics) DUP2 %eq_const(2) %jumpi(log_after_topics) @@ -147,7 +147,7 @@ global log_n_entry: // Store the third topic. DUP3 DUP2 %mstore_kernel(@SEGMENT_LOGS_DATA) - %increment + INCR1 %stack (curr_topic_ptr, num_topics, topic3) -> (curr_topic_ptr, num_topics) DUP2 %eq_const(3) %jumpi(log_after_topics) @@ -155,7 +155,7 @@ global log_n_entry: // Store the fourth topic. DUP3 DUP2 %mstore_kernel(@SEGMENT_LOGS_DATA) - %increment + INCR1 %stack (data_len_ptr, num_topics, topic4) -> (data_len_ptr, num_topics) DUP2 %eq_const(4) %jumpi(log_after_topics) @@ -196,7 +196,7 @@ log_after_topics: // Store data_len. DUP3 DUP2 %mstore_kernel(@SEGMENT_LOGS_DATA) - %increment + INCR1 // stack: data_ptr, num_topics, data_len, data_offset, retdest SWAP1 POP // stack: data_ptr, data_len, data_offset, retdest @@ -225,9 +225,9 @@ store_log_data_loop: DUP2 %mstore_kernel(@SEGMENT_LOGS_DATA) // stack: cur_data_ptr, next_log_ptr, cur_data_addr, retdest - SWAP2 %increment SWAP2 + INCR3 // stack: cur_data_ptr, next_log_ptr, next_data_addr, retdest - %increment + INCR1 %jump(store_log_data_loop) store_log_data_loop_end: diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/nonce.asm b/evm_arithmetization/src/cpu/kernel/asm/core/nonce.asm index 48486be9e..2372e4363 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/nonce.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/nonce.asm @@ -31,7 +31,7 @@ global increment_nonce: // stack: nonce, nonce_ptr, address, retdest DUP1 DUP4 %journal_add_nonce_change // stack: nonce, nonce_ptr, address, retdest - %increment + INCR1 SWAP1 // stack: nonce_ptr, nonce', address, retdest %mstore_trie_data diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/precompiles/expmod.asm b/evm_arithmetization/src/cpu/kernel/asm/core/precompiles/expmod.asm index 684c80810..e138134b8 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/precompiles/expmod.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/precompiles/expmod.asm @@ -63,7 +63,7 @@ store_limbs: // stack: offset, limb[num_limbs - 1], offset, retdest, num_limbs, limb[num_limbs - 2], ..limb[0] %mstore_current_general // stack: offset, retdest, num_limbs, limb[num_limbs - 2], ..limb[0] - %increment + INCR1 SWAP2 %decrement SWAP2 diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/precompiles/snarkv.asm b/evm_arithmetization/src/cpu/kernel/asm/core/precompiles/snarkv.asm index 295acd029..301dcee6d 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/precompiles/snarkv.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/precompiles/snarkv.asm @@ -103,7 +103,7 @@ loading_loop_contd6: DUP3 // stack: i, y, x, i, k, kexit_info %mul_const(6) %add_const(@SNARKV_INP) - %add_const(1) + INCR1 %mstore_bn254_pairing // stack: x, i, k, kexit_info DUP2 @@ -111,7 +111,7 @@ loading_loop_contd6: %mul_const(6) %add_const(@SNARKV_INP) %mstore_bn254_pairing // stack: i, k, kexit_info - %increment + INCR1 %jump(loading_loop) loading_done: diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/selfdestruct_list.asm b/evm_arithmetization/src/cpu/kernel/asm/core/selfdestruct_list.asm index 05e158c34..8c339bc13 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/selfdestruct_list.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/selfdestruct_list.asm @@ -9,7 +9,7 @@ %stack (write_addr, len, addr) -> (addr, write_addr, len) MSTORE_GENERAL // Store new address at the end of the array. // stack: len - %increment + INCR1 %mstore_global_metadata(@GLOBAL_METADATA_SELFDESTRUCT_LIST_LEN) // Store new length. %endmacro @@ -32,7 +32,7 @@ remove_selfdestruct_list_loop: // stack: addr, loaded_addr, i, len, addr, retdest EQ %jumpi(remove_selfdestruct_list_found) // stack: i, len, addr, retdest - %increment + INCR1 %jump(remove_selfdestruct_list_loop) remove_selfdestruct_list_found: %stack (i, len, addr, retdest) -> (len, 1, i, retdest) @@ -65,11 +65,11 @@ delete_all_selfdestructed_addresses_loop: // stack: loaded_addr, i, len, retdest DUP1 %is_non_existent ISZERO %jumpi(bingo) // stack: loaded_addr, i, len, retdest - POP %increment %jump(delete_all_selfdestructed_addresses_loop) + POP INCR1 %jump(delete_all_selfdestructed_addresses_loop) bingo: // stack: loaded_addr, i, len, retdest %delete_account - %increment %jump(delete_all_selfdestructed_addresses_loop) + INCR1 %jump(delete_all_selfdestructed_addresses_loop) delete_all_selfdestructed_addresses_done: // stack: i, len, retdest %pop2 JUMP diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/syscall.asm b/evm_arithmetization/src/cpu/kernel/asm/core/syscall.asm index 7677654e2..bde45e2e9 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/syscall.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/syscall.asm @@ -141,9 +141,14 @@ global syscall_jumptable: JUMPTABLE panic // mstore_32bytes_1-32 are implemented natively %endrep - // 0xe0-0xef - %rep 16 - JUMPTABLE panic // 0xe0-0xef are invalid opcodes + // 0xe0-0xe3 + %rep 4 + JUMPTABLE panic // incr1-incr4 are implemented natively + %endrep + + // 0xe4-0xef + %rep 12 + JUMPTABLE panic // 0xe4-0xef are invalid opcodes %endrep // 0xf0-0xff diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/terminate.asm b/evm_arithmetization/src/cpu/kernel/asm/core/terminate.asm index 2e3482ea3..4d9f19d64 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/terminate.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/terminate.asm @@ -91,7 +91,7 @@ global sys_selfdestruct: // stack: 0, balance, address, recipient, kexit_info DUP3 %mpt_read_state_trie // stack: account_ptr, 0, balance, address, recipient, kexit_info - %add_const(1) + INCR1 // stack: balance_ptr, 0, balance, address, recipient, kexit_info %mstore_trie_data @@ -287,7 +287,7 @@ global terminate_common: // stack: addr, addr_created_contract, i, nb_created_contracts, addr EQ %jumpi(%%contract_just_created_true) // stack: i, nb_created_contracts, addr - %increment + INCR1 %jump(%%contract_just_created_loop) %%contract_just_created_true: // stack: i, nb_created_contracts, addr diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/touched_addresses.asm b/evm_arithmetization/src/cpu/kernel/asm/core/touched_addresses.asm index a8e926e77..78161e2b5 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/touched_addresses.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/touched_addresses.asm @@ -28,7 +28,7 @@ insert_touched_addresses_loop: // stack: addr, loaded_addr, i, len, addr, retdest EQ %jumpi(insert_touched_addresses_found) // stack: i, len, addr, retdest - %increment + INCR1 %jump(insert_touched_addresses_loop) insert_address: @@ -37,7 +37,7 @@ insert_address: %swap_mstore // Store new address at the end of the array. // stack: len, segment, retdest SUB // unscale - %increment + INCR1 %mstore_global_metadata(@GLOBAL_METADATA_TOUCHED_ADDRESSES_LEN) // Store new length. JUMP @@ -64,7 +64,7 @@ remove_touched_addresses_loop: // stack: addr, loaded_addr, i, len, addr, retdest EQ %jumpi(remove_touched_addresses_found) // stack: i, len, addr, retdest - %increment + INCR1 %jump(remove_touched_addresses_loop) remove_touched_addresses_found: %stack (i, len, addr, retdest) -> (len, 1, i, retdest) @@ -94,11 +94,11 @@ delete_all_touched_addresses_loop: // stack: loaded_addr, i, len, retdest DUP1 %is_empty %jumpi(bingo) // stack: loaded_addr, i, len, retdest - POP %increment %jump(delete_all_touched_addresses_loop) + POP INCR1 %jump(delete_all_touched_addresses_loop) bingo: // stack: loaded_addr, i, len, retdest %delete_account - %increment %jump(delete_all_touched_addresses_loop) + INCR1 %jump(delete_all_touched_addresses_loop) delete_all_touched_addresses_done: // stack: i, len, retdest %pop2 JUMP diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/transfer.asm b/evm_arithmetization/src/cpu/kernel/asm/core/transfer.asm index b21828f5e..16b3d6a88 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/transfer.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/transfer.asm @@ -32,7 +32,7 @@ global deduct_eth: %mpt_read_state_trie // stack: account_ptr, amount, retdest DUP1 ISZERO %jumpi(deduct_eth_no_such_account) // If the account pointer is null, return 1. - %add_const(1) + INCR1 // stack: balance_ptr, amount, retdest DUP1 %mload_trie_data // stack: balance, balance_ptr, amount, retdest @@ -71,7 +71,7 @@ global add_eth: DUP1 %mpt_read_state_trie // stack: account_ptr, addr, amount, retdest DUP1 ISZERO %jumpi(add_eth_new_account) // If the account pointer is null, we need to create the account. - %add_const(1) + INCR1 // stack: balance_ptr, addr, amount, retdest DUP1 %mload_trie_data // stack: balance, balance_ptr, addr, amount, retdest diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/util.asm b/evm_arithmetization/src/cpu/kernel/asm/core/util.asm index 3a86d75fd..c8ad59b87 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/util.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/util.asm @@ -70,10 +70,10 @@ DUP1 %mload_trie_data // stack: nonce, account_ptr ISZERO %not_bit %jumpi(%%false) - %increment DUP1 %mload_trie_data + INCR1 DUP1 %mload_trie_data // stack: balance, balance_ptr ISZERO %not_bit %jumpi(%%false) - %add_const(2) %mload_trie_data + %increment_twice %mload_trie_data // stack: code_hash PUSH @EMPTY_STRING_HASH EQ @@ -112,7 +112,7 @@ %macro set_and_prune_ctx // stack: context - PUSH 1 ADD + INCR1 SET_CONTEXT // stack: (empty) %endmacro diff --git a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/miller_loop.asm b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/miller_loop.asm index 99cf24e71..890640e5c 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/miller_loop.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/miller_loop.asm @@ -198,7 +198,7 @@ after_add: // stack: py^2 - 9, addr12, addr12, px, py, qx, qx_, qy, qy_ MSTORE_GENERAL // stack: addr12, px, py, qx, qx_, qy, qy_ - %add_const(2) DUP1 + %increment_twice DUP1 SWAP2 DUP1 MULFP254 @@ -228,7 +228,7 @@ after_add: // stack: (2py)qy, addr20, addr14, -3px^2, qx_, 2py, qy_ MSTORE_GENERAL // stack: addr14, -3px^2, qx_, 2py, qy_ - %add_const(1) SWAP2 + SWAP2 INCR3 // stack: qx_, -3px^2, addr15, 2py, qy_ MULFP254 // stack: (-3px^2)*qx_, addr15, 2py, qy_ @@ -295,13 +295,13 @@ after_add: PUSH 12 %create_bn254_pairing_address // stack: addr12 - DUP1 %add_const(2) + DUP1 %increment_twice // stack: addr14, addr12 - DUP1 %add_const(1) + DUP1 INCR1 // stack: addr15, addr14, addr12 DUP1 %add_const(5) // stack: addr20, addr15, addr14, addr12 - DUP1 %add_const(1) + DUP1 INCR1 // stack: addr21, addr20, addr15, addr14, addr12 %rep 5 PUSH 0 MSTORE_GENERAL diff --git a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/msm.asm b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/msm.asm index af350dd8f..d7f2e2e6c 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/msm.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/msm.asm @@ -19,7 +19,7 @@ msm_loop_contd: %stack (accx, accy, i, retdest) -> (i, i, accx, accy, retdest) // TODO: the GLV scalars for the BN curve are 127-bit, so could use 127 here. But this would require modifying `wnaf.asm`. Not sure it's worth it... %eq_const(129) %jumpi(msm_end) - %increment + INCR1 // stack: i+1, accx, accy, retdest %stack (i, accx, accy, retdest) -> (accx, accy, bn_msm_loop, i, retdest) %jump(bn_double) diff --git a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/pairing.asm b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/pairing.asm index b1bd2f835..934840310 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/pairing.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/pairing.asm @@ -64,7 +64,7 @@ bn254_input_check: // stack: inp_j, j, k, inp DUP1 // stack: inp_j , inp_j, j, k, inp - %add_const(2) + %increment_twice // stack: inp_j', inp_j, j, k, inp %load_fp254_4 // stack: Q_j, inp_j, j, k, inp diff --git a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/degree_12_mul.asm b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/degree_12_mul.asm index 45016ed15..1975d396c 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/degree_12_mul.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/degree_12_mul.asm @@ -177,7 +177,7 @@ global mul_fp254_12_sparse: // stack: G2 * sh2(f') + g0 * f, inB, f, inB, f', out, f, inB, f', inA, inB, out %stack (f: 6, x, g: 6) -> (g, x, f) // stack: f , inB, G2 * sh2(f') + g0 * f, inB, f', out, f, inB, f', inA, inB, out - DUP7 %add_const(2) + DUP7 %increment_twice // stack: inB1, f , inB, G2 * sh2(f') + g0 * f, inB, f', out, f, inB, f', inA, inB, out %load_fp254_2 // stack: G1 , f , inB, G2 * sh2(f') + g0 * f, inB, f', out, f, inB, f', inA, inB, out @@ -207,7 +207,7 @@ global mul_fp254_12_sparse: %stack (f: 6, x, g: 6) -> (g, x, f) // stack: f' , inB, G2 * sh(f) + g0 * f', inA, inB, out DUP7 - %add_const(2) + %increment_twice // stack: inB1, f' , inB, G2 * sh(f) + g0 * f', inA, inB, out %load_fp254_2 // stack: G1 , f' , inB, G2 * sh(f) + g0 * f', inA, inB, out diff --git a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/util.asm b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/util.asm index ee9dd7ffa..4cd4499aa 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/util.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/util.asm @@ -52,7 +52,7 @@ // stack: ptr %create_bn254_pairing_address DUP1 - %add_const(1) + INCR1 // stack: addr1, addr MLOAD_GENERAL // stack: x1, addr @@ -180,12 +180,12 @@ // stack: ptr %create_bn254_pairing_address DUP1 - %add_const(2) + %increment_twice // stack: addr2, addr MLOAD_GENERAL // stack: x2, addr DUP2 - %add_const(1) + INCR1 // stack: addr1, x2, addr MLOAD_GENERAL // stack: x1, x2, addr @@ -216,12 +216,12 @@ MLOAD_GENERAL // stack: x3, x4, addr DUP3 - %add_const(2) + %increment_twice // stack: addr2, x3, x4, addr MLOAD_GENERAL // stack: x2, x3, x4, addr DUP4 - %add_const(1) + INCR1 // stack: addr1, x2, x3, x4, addr MLOAD_GENERAL // stack: x1, x2, x3, x4, addr @@ -258,12 +258,12 @@ %swap_mstore // stack: x1, x2, x3, addr, x5 DUP4 - %add_const(1) + INCR1 // stack: addr1, x1, x2, x3, addr, x5 %swap_mstore // stack: x2, x3, addr, x5 DUP3 - %add_const(2) + %increment_twice // stack: addr2, x2, x3, addr, x5 %swap_mstore // stack: x3, addr, x5 @@ -302,7 +302,7 @@ MULFP254 // stack: 2*x1, x2, x3, x4, addr DUP5 - %add_const(1) + INCR1 // stack: addr1, 2*x1, x2, x3, x4, addr %swap_mstore // stack: x2, x3, x4, addr @@ -310,7 +310,7 @@ MULFP254 // stack: 2*x2, x3, x4, addr DUP4 - %add_const(2) + %increment_twice // stack: addr2, 2*x2, x3, x4, addr %swap_mstore // stack: x3, x4, addr @@ -345,22 +345,22 @@ PUSH $ptr %create_bn254_pairing_address // stack: addr, x0, x1, x2, x3, x4, x5 - %add_const(2) + %increment_twice DUP1 // stack: addr2, addr2, x0, x1, x2, x3, x4, x5 SWAP2 MSTORE_GENERAL // stack: addr2, x1, x2, x3, x4, x5 - %add_const(1) + INCR1 DUP1 // stack: addr3, addr3, x1, x2, x3, x4, x5 SWAP2 MSTORE_GENERAL // stack: addr3, x2, x3, x4, x5 - %add_const(1) + INCR1 DUP1 // stack: addr4, addr4, x2, x3, x4, x5 SWAP2 MSTORE_GENERAL // stack: addr4, x3, x4, x5 - %add_const(1) + INCR1 // stack: addr5, x3, x4, x5 %swap_mstore // stack: x4, x5 @@ -369,7 +369,7 @@ PUSH $ptr %create_bn254_pairing_address DUP1 - %add_const(1) + INCR1 // stack: addr1, addr, y5, y4 SWAP3 MSTORE_GENERAL @@ -991,12 +991,12 @@ MLOAD_GENERAL // stack: x03, x04, x05, x06, x07, x08, x09, x10, addr DUP9 - %add_const(2) + %increment_twice // stack: addr02, x03, x04, x05, x06, x07, x08, x09, x10, addr MLOAD_GENERAL // stack: x02, x03, x04, x05, x06, x07, x08, x09, x10, addr DUP10 - %add_const(1) + INCR1 // stack: addr01, x02, x03, x04, x05, x06, x07, x08, x09, x10, addr MLOAD_GENERAL // stack: x01, x02, x03, x04, x05, x06, x07, x08, x09, x10, addr @@ -1098,22 +1098,22 @@ %swap_mstore // stack: SRC, DEST DUP1 - %add_const(1) + INCR1 // stack: addr01, SRC, DEST MLOAD_GENERAL // stack: x01, SRC, DEST DUP3 - %add_const(1) + INCR1 // stack: addr01', x01, SRC, DEST %swap_mstore // stack: SRC, DEST DUP1 - %add_const(2) + %increment_twice // stack: addr02, SRC, DEST MLOAD_GENERAL // stack: x02, SRC, DEST DUP3 - %add_const(2) + %increment_twice // stack: addr02', x02, SRC, DEST %swap_mstore // stack: SRC, DEST diff --git a/evm_arithmetization/src/cpu/kernel/asm/curve/secp256k1/ecrecover.asm b/evm_arithmetization/src/cpu/kernel/asm/curve/secp256k1/ecrecover.asm index b633feaeb..196891efc 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/curve/secp256k1/ecrecover.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/curve/secp256k1/ecrecover.asm @@ -86,7 +86,7 @@ ecdsa_after_precompute_loop: SHR MOD // mod 2 %mul_const(2) ADD %mul_const(2) ADD %mul_const(2) ADD %stack (index, i, accx, accy, a0, a1, b0, b1, retdest) -> (index, index, i, accx, accy, a0, a1, b0, b1, retdest) - %mul_const(2) %add_const(1) + %mul_const(2) INCR1 %mload_current(@SEGMENT_ECDSA_TABLE) SWAP1 %mul_const(2) %mload_current(@SEGMENT_ECDSA_TABLE) diff --git a/evm_arithmetization/src/cpu/kernel/asm/curve/secp256k1/precomputation.asm b/evm_arithmetization/src/cpu/kernel/asm/curve/secp256k1/precomputation.asm index b6bed1b0a..95843e855 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/curve/secp256k1/precomputation.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/curve/secp256k1/precomputation.asm @@ -38,7 +38,7 @@ precompute_table_contd: // Use a loop to store a*G ± b*phi(G) + c*Q ± d*phi(Q) for a,b,c,d in {0,1}^4. precompute_table_loop: // stack: i, retdest - DUP1 %increment %mload_current(@SEGMENT_ECDSA_TABLE) + DUP1 INCR1 %mload_current(@SEGMENT_ECDSA_TABLE) %stack (y, i, retdest) -> (i, y, i, retdest) %mload_current(@SEGMENT_ECDSA_TABLE) PUSH precompute_table_loop_contd @@ -65,7 +65,7 @@ precompute_table_loop_contd2: precompute_table_loop_contd3: %stack (Rx, Ry, i, retdest) -> (i, 24, Rx, i, 25, Ry, i, retdest) ADD %mstore_current(@SEGMENT_ECDSA_TABLE) ADD %mstore_current(@SEGMENT_ECDSA_TABLE) - %add_const(2) + %increment_twice DUP1 %eq_const(8) %jumpi(precompute_table_end) %jump(precompute_table_loop) diff --git a/evm_arithmetization/src/cpu/kernel/asm/curve/wnaf.asm b/evm_arithmetization/src/cpu/kernel/asm/curve/wnaf.asm index fb9d5e251..d6485402c 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/curve/wnaf.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/curve/wnaf.asm @@ -66,7 +66,7 @@ trailing_zeros_loop: // stack: x&1, count, x, retdest %jumpi(trailing_zeros_end) // stack: count, x, retdest - %increment SWAP1 PUSH 1 SHR SWAP1 + INCR1 SWAP1 PUSH 1 SHR SWAP1 // stack: count, x>>1, retdest %jump(trailing_zeros_loop) trailing_zeros_end: diff --git a/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/addresses.asm b/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/addresses.asm index 3244cfa1f..f2efa2b7c 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/addresses.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/addresses.asm @@ -7,7 +7,7 @@ MLOAD_GENERAL // stack: num_blocks, addr %block_size - %add_const(2) + %increment_twice // stack: num_bytes+2, addr ADD // stack: addr diff --git a/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/blake2_f.asm b/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/blake2_f.asm index aa9951997..7b298ec93 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/blake2_f.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/blake2_f.asm @@ -9,7 +9,7 @@ global blake2_f: %stack (addr, rounds, h_i) -> (h_i, addr, addr, rounds) // stack: h_i, addr, addr, rounds, ... MSTORE_GENERAL - %increment + INCR1 %endrep // stack: addr, rounds, m0...m15, t0, t1, flag, retdest @@ -24,7 +24,7 @@ global blake2_f: %stack (message_addr, rounds, m_i) -> (m_i, message_addr, message_addr, rounds) // stack: m_i, message_addr, message_addr, rounds, ... MSTORE_GENERAL - %increment + INCR1 %endrep // stack: message_addr, rounds, t0, t1, flag, retdest @@ -58,7 +58,7 @@ global blake2_f: DUP1 SWAP2 MSTORE_GENERAL - %increment + INCR1 %endrep // stack: start + 8, rounds, t0, t1, flag, retdest @@ -69,9 +69,7 @@ global blake2_f: // stack: i, addr, ... DUP2 // stack: addr, i, addr, ... - %increment - // stack: addr + 1, i, addr, ... - SWAP2 + INCR3 // stack: addr, i, addr + 1, ... DUP2 // stack: i, addr, i, addr + 1, ... @@ -79,7 +77,7 @@ global blake2_f: // stack: IV_i, addr, i, addr + 1, ... MSTORE_GENERAL // stack: i, addr + 1, ... - %increment + INCR1 // stack: i + 1, addr + 1,... %endrep // stack: 4, start + 12, rounds, t0, t1, flag, retdest @@ -107,15 +105,15 @@ global blake2_f: // stack: val ^ IV_i, addr, i, addr, val, next_val,... MSTORE_GENERAL // stack: i, addr, val, next_val,... - %increment + INCR1 // stack: i + 1, addr, val, next_val,... SWAP2 // stack: val, addr, i + 1, next_val,... POP // stack: addr, i + 1, next_val,... - %increment - // stack: addr + 1, i + 1, next_val,... SWAP1 + // stack: i + 1, addr, next_val,... + INCR2 // stack: i + 1, addr + 1, next_val,... %endrep // stack: 8, start + 16, rounds, retdest diff --git a/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/blake2b.asm b/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/blake2b.asm index e3daed263..8b6cc8593 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/blake2b.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/blake2b.asm @@ -8,7 +8,7 @@ global blake2b: // stack: virt, num_blocks, virt, num_bytes, retdest %mstore_current_general // stack: virt, num_bytes, retdest - %add_const(1) + INCR1 %mstore_current_general // stack: retdest %jump(blake2_compression) diff --git a/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/compression.asm b/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/compression.asm index ba9ffc134..a63901204 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/compression.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/compression.asm @@ -15,7 +15,7 @@ compression_loop: SWAP1 DUP2 %mstore_current_general - %increment + INCR1 %endrep // stack: addr, cur_block, retdest @@ -44,7 +44,7 @@ compression_loop: // stack: is_last_block * num_bytes, cur_block, is_last_block, retdest DUP2 // stack: cur_block, is_last_block * num_bytes, cur_block, is_last_block, retdest - %increment + INCR1 %block_size // stack: (cur_block + 1) * 128, is_last_block * num_bytes, cur_block, is_last_block, retdest DUP4 @@ -60,7 +60,7 @@ compression_loop: DUP1 // stack: cur_block, cur_block, t, is_last_block, retdest %block_size - %add_const(2) + %increment_twice // stack: cur_block_start_byte, t, cur_block, is_last_block, retdest // Copy the message from the input space to the message working space. @@ -76,7 +76,7 @@ compression_loop: // stack: cur_message_addr, m_i, cur_message_addr, cur_block_byte, ... %mstore_current_general // stack: cur_message_addr, cur_block_byte, ... - %increment + INCR1 // stack: cur_message_addr + 1, cur_block_byte, ... SWAP1 // stack: cur_block_byte, cur_message_addr + 1, ... @@ -119,7 +119,7 @@ compression_loop: SWAP1 DUP2 %mstore_current_general - %increment + INCR1 %endrep // stack: start + 8, invert_if_last_block, t, cur_block, retdest @@ -136,10 +136,8 @@ compression_loop: // stack: loc, IV_i, i, loc, ... %mstore_current_general // stack: i, loc, ... - %increment - SWAP1 - %increment - SWAP1 + INCR1 + INCR2 // stack: i + 1, loc + 1,... %endrep // stack: 4, start + 12, invert_if_last_block, t, cur_block, retdest @@ -170,13 +168,13 @@ compression_loop: // stack: loc, val ^ IV_i, i, loc, val, next_val,... %mstore_current_general // stack: i, loc, val, next_val,... - %increment + INCR1 // stack: i + 1, loc, val, next_val,... SWAP2 // stack: val, loc, i + 1, next_val,... POP // stack: loc, i + 1, next_val,... - %increment + INCR1 // stack: loc + 1, i + 1, next_val,... SWAP1 // stack: i + 1, loc + 1, next_val,... @@ -204,11 +202,11 @@ hash_generate_return: // stack: h_0', h_1', h_2', h_3', h_4', h_5', h_6', h_7', cur_block, retdest DUP9 // stack: cur_block, h_0', h_1', h_2', h_3', h_4', h_5', h_6', h_7', cur_block, retdest - %increment + INCR1 // stack: cur_block + 1, h_0', h_1', h_2', h_3', h_4', h_5', h_6', h_7', cur_block, retdest SWAP9 // stack: cur_block, h_0', h_1', h_2', h_3', h_4', h_5', h_6', h_7', cur_block + 1, retdest - %increment + INCR1 // stack: cur_block + 1, h_0', h_1', h_2', h_3', h_4', h_5', h_6', h_7', cur_block + 1, retdest PUSH 0 %mload_current_general diff --git a/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/g_functions.asm b/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/g_functions.asm index 33bf5cb1e..4e00b4d5f 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/g_functions.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/g_functions.asm @@ -150,7 +150,7 @@ global run_rounds_g_function: %call_blake2_g_function(2, 7, 8, 13, 12, 13) %call_blake2_g_function(3, 4, 9, 14, 14, 15) // stack: current_round, start, rounds, retdest - %increment + INCR1 // stack: current_round + 1, start, rounds, retdest %jump(run_rounds_g_function) run_rounds_g_function_end: diff --git a/evm_arithmetization/src/cpu/kernel/asm/hash/ripemd/update.asm b/evm_arithmetization/src/cpu/kernel/asm/hash/ripemd/update.asm index c5783cc71..a05a36d69 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/hash/ripemd/update.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/hash/ripemd/update.asm @@ -119,9 +119,9 @@ buffer_update: // stack: get, set, get , set , times , retdest %mupdate_current_general // stack: get , set , times , retdest - %increment + INCR1 + INCR2 SWAP1 - %increment SWAP1 SWAP2 %decrement diff --git a/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/compression.asm b/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/compression.asm index 6ff84301b..aaa50be61 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/compression.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/compression.asm @@ -3,7 +3,7 @@ %macro scratch_space_addr_from_num_blocks // stack: num_blocks %mul_const(320) - %add_const(2) + %increment_twice %build_current_general_address %endmacro @@ -92,7 +92,7 @@ compression_loop: // stack: a[i+1], b[i+1], c[i+1], d[i+1], e[i+1], f[i+1], g[i+1], h[i+1], num_blocks, scratch_space_addr, message_schedule_addr, i, a[0]..h[0], retdest DUP12 // stack: i, a[i+1], b[i+1], c[i+1], d[i+1], e[i+1], f[i+1], g[i+1], h[i+1], num_blocks, scratch_space_addr, message_schedule_addr, i, a[0]..h[0], retdest - %increment + INCR1 // stack: i+1, a[i+1], b[i+1], c[i+1], d[i+1], e[i+1], f[i+1], g[i+1], h[i+1], num_blocks, scratch_space_addr, message_schedule_addr, i, a[0]..h[0], retdest DUP1 // stack: i+1, i+1, a[i+1], b[i+1], c[i+1], d[i+1], e[i+1], f[i+1], g[i+1], h[i+1], num_blocks, scratch_space_addr, message_schedule_addr, i, a[0]..h[0], retdest diff --git a/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/main.asm b/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/main.asm index 53967f8a1..9aeb185a3 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/main.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/main.asm @@ -23,7 +23,7 @@ global sha2_pad: // stack: 128, num_bytes, retdest DUP2 // stack: num_bytes, 128, num_bytes, retdest - %increment + INCR1 // stack: num_bytes+1, 128, num_bytes, retdest %mstore_current_general // stack: num_bytes, retdest @@ -33,7 +33,7 @@ global sha2_pad: %add_const(8) %shr_const(6) - %increment + INCR1 // stack: num_blocks = (num_bytes+8)//64 + 1, num_bytes, retdest // STEP 3: calculate length := num_bytes*8 SWAP1 diff --git a/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/message_schedule.asm b/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/message_schedule.asm index 3bcd7dbfc..21f96e813 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/message_schedule.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/message_schedule.asm @@ -2,7 +2,7 @@ %macro message_schedule_addr_from_num_blocks // stack: num_blocks %mul_const(64) - %add_const(2) + %increment_twice %build_current_general_address %endmacro @@ -174,8 +174,8 @@ global sha2_gen_all_message_schedules: // stack: base_addr, base_addr, output_addr, output_addr, retdest MLOAD_GENERAL // stack: num_blocks, base_addr, output_addr, output_addr, retdest + INCR2 SWAP1 - %increment // stack: cur_addr (offset = 1), counter = num_blocks, output_addr, output_addr, retdest gen_all_message_schedules_loop: // stack: cur_addr, counter, cur_output_addr, output_addr, retdest diff --git a/evm_arithmetization/src/cpu/kernel/asm/journal/account_destroyed.asm b/evm_arithmetization/src/cpu/kernel/asm/journal/account_destroyed.asm index d62f3d422..ddbbf23c1 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/journal/account_destroyed.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/journal/account_destroyed.asm @@ -20,7 +20,7 @@ revert_account_destroyed_contd: // stack: target_payload_ptr, address, prev_balance, retdest DUP1 %assert_nonzero - %add_const(1) + INCR1 // stack: target_balance_ptr, address, prev_balance, retdest DUP3 DUP2 %mload_trie_data @@ -32,7 +32,7 @@ revert_account_destroyed_contd: // stack: account_payload_ptr, prev_balance, retdest DUP1 %assert_nonzero - %increment + INCR1 // stack: account_balance_payload_ptr, prev_balance, retdest %mstore_trie_data JUMP diff --git a/evm_arithmetization/src/cpu/kernel/asm/journal/journal.asm b/evm_arithmetization/src/cpu/kernel/asm/journal/journal.asm index 96fa8aae8..3d2951496 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/journal/journal.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/journal/journal.asm @@ -22,7 +22,7 @@ // stack: journal_size, pointer, journal_size %mstore_journal // stack: journal_size - %increment + INCR1 %mstore_global_metadata(@GLOBAL_METADATA_JOURNAL_LEN) // stack: (empty) %endmacro @@ -51,7 +51,7 @@ // stack: size, value, size %mstore_journal_data // stack: size - %increment + INCR1 %mstore_global_metadata(@GLOBAL_METADATA_JOURNAL_DATA_LEN) %endmacro @@ -119,7 +119,7 @@ %macro journal_load_1 // ptr - %add_const(1) + INCR1 %mload_journal_data // w %endmacro @@ -127,11 +127,11 @@ %macro journal_load_2 // ptr DUP1 - %add_const(2) + %increment_twice %mload_journal_data // x, ptr + INCR2 SWAP1 - %add_const(1) %mload_journal_data // w, x %endmacro @@ -145,11 +145,11 @@ SWAP1 DUP1 // ptr, ptr, y - %add_const(2) + %increment_twice %mload_journal_data // x, ptr, y + INCR2 SWAP1 - %add_const(1) %mload_journal_data // w, x, y %endmacro @@ -169,11 +169,11 @@ SWAP1 DUP1 // ptr, ptr, y, z - %add_const(2) + %increment_twice %mload_journal_data // x, ptr, y, z + INCR2 SWAP1 - %add_const(1) %mload_journal_data // w, x, y, z %endmacro @@ -197,10 +197,10 @@ // stack: i, current_checkpoint DUP2 DUP2 %mstore_current(@SEGMENT_CONTEXT_CHECKPOINTS) // stack: i, current_checkpoint - %increment + INCR1 %mstore_context_metadata(@CTX_METADATA_CHECKPOINTS_LEN) // stack: current_checkpoint - %increment + INCR1 %mstore_global_metadata(@GLOBAL_METADATA_CURRENT_CHECKPOINT) // stack: (empty) %endmacro diff --git a/evm_arithmetization/src/cpu/kernel/asm/journal/transient_storage_change.asm b/evm_arithmetization/src/cpu/kernel/asm/journal/transient_storage_change.asm index ce74df0a2..1555a9208 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/journal/transient_storage_change.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/journal/transient_storage_change.asm @@ -15,7 +15,7 @@ global revert_transient_storage_change: // The value must have been stored %assert_nonzero // stack: pos, addr, value, slot, prev_value, retdest - %add_const(2) + %increment_twice DUP5 // stack: prev_value, pos+2, addr, value, slot, prev_value, retdest MSTORE_GENERAL diff --git a/evm_arithmetization/src/cpu/kernel/asm/main.asm b/evm_arithmetization/src/cpu/kernel/asm/main.asm index cb170ef24..d2616f98f 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/main.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/main.asm @@ -7,7 +7,7 @@ global init: // stack: prev_stack_len, addr_registers // First, check the stack length. DUP1 - DUP3 %add_const(2) + DUP3 %increment_twice // stack: stack_len_addr, prev_stack_len, prev_stack_len, addr_registers MLOAD_GENERAL %assert_eq @@ -48,7 +48,7 @@ global init: // Construct `kexit_info`. DUP1 MLOAD_GENERAL // stack: program_counter, addr_registers - DUP2 %increment + DUP2 INCR1 MLOAD_GENERAL // stack: is_kernel, program_counter, addr_registers %shl_const(32) ADD @@ -102,7 +102,7 @@ global hash_initial_tries: // stack: actual_nb_accounts // The initial payloads are written twice, and each payload requires 4 elements. PUSH 8 MUL - %increment + INCR1 // stack: init_trie_data_len PUSH @INITIAL_RLP_ADDR // stack: rlp_start, init_trie_data_len @@ -170,7 +170,7 @@ global txn_loop_after: %process_receipt // stack: new_cum_gas, txn_counter, num_nibbles, txn_nb - SWAP3 %increment SWAP3 + INCR4 // Re-initialize memory values before processing the next txn. %reinitialize_memory_pre_txn diff --git a/evm_arithmetization/src/cpu/kernel/asm/memory/core.asm b/evm_arithmetization/src/cpu/kernel/asm/memory/core.asm index 9e18bc3e3..c06d33325 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/memory/core.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/memory/core.asm @@ -12,13 +12,13 @@ MLOAD_GENERAL // stack: c0, addr DUP2 - %increment + INCR1 MLOAD_GENERAL %shl_const(8) ADD // stack: c0 | (c1 << 8), addr DUP2 - %add_const(2) + %increment_twice MLOAD_GENERAL %shl_const(16) ADD diff --git a/evm_arithmetization/src/cpu/kernel/asm/memory/memcpy.asm b/evm_arithmetization/src/cpu/kernel/asm/memory/memcpy.asm index 09f686965..b61262ce4 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/memory/memcpy.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/memory/memcpy.asm @@ -18,11 +18,9 @@ global memcpy: // stack: DST, SRC, count, retdest // Increment dst_addr. - %increment + INCR1 // Increment src_addr. - SWAP1 - %increment - SWAP1 + INCR2 // Decrement count. PUSH 1 DUP4 SUB SWAP3 POP diff --git a/evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm b/evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm index 5ac85f1b3..89ddaccc5 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/memory/metadata.asm @@ -340,7 +340,7 @@ global blockhash: // Check for an overflow, since we're incrementing `block_number` afterwards. DUP2 %eq_const(@U256_MAX) %jumpi(zero_hash) // stack: cur_block_number, block_number, retdest - DUP1 DUP3 %increment GT %jumpi(zero_hash) // if block_number >= cur_block_number + DUP1 DUP3 INCR1 GT %jumpi(zero_hash) // if block_number >= cur_block_number // stack: cur_block_number, block_number, retdest DUP2 PUSH 256 ADD // stack: block_number+256, cur_block_number, block_number, retdest @@ -475,7 +475,7 @@ zero_hash: %macro increment_call_depth %mload_global_metadata(@GLOBAL_METADATA_CALL_STACK_DEPTH) - %increment + INCR1 %mstore_global_metadata(@GLOBAL_METADATA_CALL_STACK_DEPTH) %endmacro diff --git a/evm_arithmetization/src/cpu/kernel/asm/memory/packing.asm b/evm_arithmetization/src/cpu/kernel/asm/memory/packing.asm index a1bf5a09a..904fdbde4 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/memory/packing.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/memory/packing.asm @@ -4,8 +4,8 @@ global mload_packing_u64_LE: // stack: addr, retdest DUP1 MLOAD_GENERAL - DUP2 %add_const(1) MLOAD_GENERAL %shl_const( 8) ADD - DUP2 %add_const(2) MLOAD_GENERAL %shl_const(16) ADD + DUP2 INCR1 MLOAD_GENERAL %shl_const( 8) ADD + DUP2 %increment_twice MLOAD_GENERAL %shl_const(16) ADD DUP2 %add_const(3) MLOAD_GENERAL %shl_const(24) ADD DUP2 %add_const(4) MLOAD_GENERAL %shl_const(32) ADD DUP2 %add_const(5) MLOAD_GENERAL %shl_const(40) ADD @@ -284,11 +284,11 @@ global mstore_unpacking_u64_LE: %stack (addr, value) -> (0xff, value, addr, addr, value) AND MSTORE_GENERAL // First byte - DUP1 %add_const(1) + DUP1 INCR1 %stack (new_addr, addr, value) -> (0xff00, value, new_addr, addr, value) AND %shr_const(8) MSTORE_GENERAL // Second byte - DUP1 %add_const(2) + DUP1 %increment_twice %stack (new_addr, addr, value) -> (0xff0000, value, new_addr, addr, value) AND %shr_const(16) MSTORE_GENERAL // Third byte diff --git a/evm_arithmetization/src/cpu/kernel/asm/memory/syscalls.asm b/evm_arithmetization/src/cpu/kernel/asm/memory/syscalls.asm index d2148de91..41b40c37f 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/memory/syscalls.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/memory/syscalls.asm @@ -43,7 +43,7 @@ global sys_mstore8: // stack: kexit_info, offset, value %charge_gas_const(@GAS_VERYLOW) // stack: kexit_info, offset, value - DUP2 %increment + DUP2 INCR1 // stack: expanded_num_bytes, kexit_info, offset, value %update_mem_bytes // stack: kexit_info, offset, value diff --git a/evm_arithmetization/src/cpu/kernel/asm/memory/transient_storage.asm b/evm_arithmetization/src/cpu/kernel/asm/memory/transient_storage.asm index 8aa32c3e2..7ff09dea4 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/memory/transient_storage.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/memory/transient_storage.asm @@ -47,7 +47,7 @@ search_transient_storage_loop: // Addresses match, but we need to check for keys as well DUP1 - %increment + INCR1 MLOAD_GENERAL // stack: loaded_key, i, len, addr, key, retdest DUP5 @@ -56,7 +56,7 @@ search_transient_storage_loop: %jumpi(search_transient_storage_found) increment_and_loop: // stack: i, len, addr, key, retdest - %increment + INCR1 %jump(search_transient_storage_loop) search_transient_storage_not_found: @@ -65,7 +65,7 @@ search_transient_storage_not_found: search_transient_storage_found: // stack: i, len, addr, key, retdest - DUP1 %add_const(2) + DUP1 %increment_twice MLOAD_GENERAL %stack (val, i, len, addr, key, retdest) -> (retdest, 1, i, addr, val, key) // Return 1 to indicate that the address was already present. JUMP @@ -123,11 +123,11 @@ global sys_tstore: DUP1 DUP3 // stack: addr, pos, pos, addr, original_value, slot, value, kexit_info MSTORE_GENERAL - %increment DUP1 + INCR1 DUP1 DUP5 // stack: slot, pos', pos', addr, original_value, slot, value, kexit_info MSTORE_GENERAL - %increment DUP1 + INCR1 DUP1 DUP6 // stack: value, pos'', pos'', addr, original_value, slot, value, kexit_info MSTORE_GENERAL @@ -156,7 +156,7 @@ add_to_journal: new_transient_storage_len: // Store the new (unscaled) length. // stack: pos, addr, original_value, slot, value, kexit_info - %increment + INCR1 // stack: pos + 1, addr, original_value, slot, value, kexit_info %mstore_global_metadata(@GLOBAL_METADATA_TRANSIENT_STORAGE_LEN) // stack: addr, original_value, slot, value, kexit_info diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/accounts.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/accounts.asm index e1fa20c08..19d5eb45f 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/accounts.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/accounts.asm @@ -7,19 +7,19 @@ // Balance %mload_trie_data %append_to_trie_data - %increment + INCR1 // Nonce - %increment + INCR1 DUP1 %mload_trie_data %append_to_trie_data // Storage trie root - %increment + INCR1 DUP1 %mload_trie_data %append_to_trie_data // Codehash - %increment + INCR1 %mload_trie_data %append_to_trie_data // stack: cloned_account_ptr diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete.asm index c878ae812..b58ef3893 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete.asm @@ -8,7 +8,7 @@ global mpt_delete: DUP1 %mload_trie_data // stack: node_type, node_ptr, num_nibbles, key, retdest // Increment node_ptr, so it points to the node payload instead of its type. - SWAP1 %increment SWAP1 + INCR2 // stack: node_type, node_payload_ptr, num_nibbles, key, retdest DUP1 %eq_const(@MPT_NODE_BRANCH) %jumpi(mpt_delete_branch) diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_branch.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_branch.asm index f67861d6f..2ccd7d4ad 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_branch.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_branch.asm @@ -57,17 +57,17 @@ loop: DUP1 %eq_const(16) %jumpi(loop_end) DUP1 DUP5 ADD %mload_trie_data %mload_trie_data ISZERO ISZERO %jumpi(loop_non_empty) // stack: i, updated_child_ptr, first_nibble, node_payload_ptr, retdest - %increment %jump(loop) + INCR1 %jump(loop) loop_eq_first_nibble: // stack: i, updated_child_ptr, first_nibble, node_payload_ptr, retdest - %increment %jump(loop) + INCR1 %jump(loop) loop_non_empty: // stack: i, updated_child_ptr, first_nibble, node_payload_ptr, retdest - %mload_kernel_no_offset(@SEGMENT_KERNEL_GENERAL) %increment %mstore_kernel_no_offset(@SEGMENT_KERNEL_GENERAL) + %mload_kernel_no_offset(@SEGMENT_KERNEL_GENERAL) INCR1 %mstore_kernel_no_offset(@SEGMENT_KERNEL_GENERAL) PUSH 1 PUSH @SEGMENT_KERNEL_GENERAL %build_kernel_address DUP2 MSTORE_GENERAL - %increment %jump(loop) + INCR1 %jump(loop) loop_end: // stack: i, updated_child_ptr, first_nibble, node_payload_ptr, retdest POP @@ -109,9 +109,9 @@ maybe_normalize_branch_branchhash: // For that, return the modified child as the new node. maybe_normalize_branch_leafext: // stack: only_child_ptr, updated_child_ptr, first_nibble, node_payload_ptr, retdest - DUP1 %increment %mload_trie_data + DUP1 INCR1 %mload_trie_data // stack: child_len, only_child_ptr, updated_child_ptr, first_nibble, node_payload_ptr, retdest - DUP2 %add_const(2) %mload_trie_data + DUP2 %increment_twice %mload_trie_data // stack: child_key, child_len, only_child_ptr, updated_child_ptr, first_nibble, node_payload_ptr, retdest %mload_kernel_general(1) %stack (i, child_key, child_len, only_child_ptr, updated_child_ptr, first_nibble, node_payload_ptr) -> @@ -122,8 +122,8 @@ maybe_normalize_branch_leafext: // stack: node_ptr, len, key, only_child_ptr, retdest SWAP1 DUP2 // stack: node_ptr, len, node_ptr, key, only_child_ptr, retdest - %increment %mstore_trie_data // Change len in the child node + INCR1 %mstore_trie_data // Change len in the child node // stack: node_ptr, key, only_child_ptr, retdest - %add_const(2) %mstore_trie_data // Change key in the child node + %increment_twice %mstore_trie_data // Change key in the child node // stack: node_ptr, retdest SWAP1 JUMP diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_extension.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_extension.asm index 0627fcba6..dcd1789de 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_extension.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_extension.asm @@ -11,14 +11,14 @@ global mpt_delete_extension: // stack: node_payload_ptr, num_nibbles, key, retdest DUP1 %mload_trie_data // stack: node_len, node_payload_ptr, num_nibbles, key, retdest - DUP2 %increment %mload_trie_data + DUP2 INCR1 %mload_trie_data %stack (node_key, node_len, node_payload_ptr, num_nibbles, key, retdest) -> (node_len, num_nibbles, key, node_payload_ptr, node_len, node_key, retdest) %truncate_nibbles // stack: num_nibbles, key, node_payload_ptr, node_len, node_key, retdest SWAP2 // stack: node_payload_ptr, key, num_nibbles, node_len, node_key, retdest - DUP1 %add_const(2) %mload_trie_data + DUP1 %increment_twice %mload_trie_data %stack (node_child_ptr, node_payload_ptr, key, num_nibbles, node_len, node_key, retdest) -> (node_child_ptr, num_nibbles, key, after_mpt_delete_extension, node_payload_ptr, node_len, node_key, retdest) %jump(mpt_delete) @@ -37,7 +37,7 @@ after_mpt_delete_extension_branch: // stack: child_type, updated_child_node_ptr, node_payload_ptr, node_len, node_key, retdest POP // stack: updated_child_node_ptr, node_payload_ptr, node_len, node_key, retdest - DUP2 %add_const(2) %mstore_trie_data + DUP2 %increment_twice %mstore_trie_data // stack: node_payload_ptr, node_len, node_key, retdest %decrement %stack (extension_ptr, node_len, node_key, retdest) -> (retdest, extension_ptr) @@ -47,16 +47,16 @@ after_mpt_delete_extension_extension: // stack: child_type, updated_child_node_ptr, node_payload_ptr, node_len, node_key, retdest POP SWAP1 POP // stack: updated_child_node_ptr, node_len, node_key, retdest - DUP1 %increment %mload_trie_data + DUP1 INCR1 %mload_trie_data // stack: child_len, updated_child_node_ptr, node_len, node_key, retdest - DUP2 %add_const(2) %mload_trie_data + DUP2 %increment_twice %mload_trie_data // stack: child_key, child_len, updated_child_node_ptr, node_len, node_key, retdest %stack (child_key, child_len, updated_child_node_ptr, node_len, node_key) -> (node_len, node_key, child_len, child_key, updated_child_node_ptr) %merge_nibbles // stack: len, key, updated_child_node_ptr, retdest - DUP3 %increment %mstore_trie_data // Change len + DUP3 INCR1 %mstore_trie_data // Change len // stack: key, updated_child_node_ptr, retdest - DUP2 %add_const(2) %mstore_trie_data // Change key + DUP2 %increment_twice %mstore_trie_data // Change key // stack: extension_ptr, retdest SWAP1 JUMP @@ -65,15 +65,15 @@ after_mpt_delete_extension_leaf: // stack: child_type, updated_child_node_ptr, node_payload_ptr, node_len, node_key, retdest POP SWAP1 POP // stack: updated_child_node_ptr, node_len, node_key, retdest - DUP1 %increment %mload_trie_data + DUP1 INCR1 %mload_trie_data // stack: child_len, updated_child_node_ptr, node_len, node_key, retdest - DUP2 %add_const(2) %mload_trie_data + DUP2 %increment_twice %mload_trie_data // stack: child_key, child_len, updated_child_node_ptr, node_len, node_key, retdest %stack (child_key, child_len, updated_child_node_ptr, node_len, node_key) -> (node_len, node_key, child_len, child_key, updated_child_node_ptr) %merge_nibbles // stack: len, key, updated_child_node_ptr, retdest - DUP3 %increment %mstore_trie_data // Change len + DUP3 INCR1 %mstore_trie_data // Change len // stack: key, updated_child_node_ptr, retdest - DUP2 %add_const(2) %mstore_trie_data // Change key + DUP2 %increment_twice %mstore_trie_data // Change key // stack: updated_child_node_ptr, retdest SWAP1 JUMP diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash.asm index 37f9fc670..9e2339d7f 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash.asm @@ -62,17 +62,16 @@ global encode_or_hash_node: // If we got here, node_type == @MPT_NODE_HASH. // Load the hash and return (hash, 32). // stack: node_type, node_ptr, rlp_start, encode_value, cur_len, retdest + INCR2 // Skip over node type prefix POP - - // stack: node_ptr, rlp_start, encode_value, cur_len, retdest - %increment // Skip over node type prefix // stack: hash_ptr, rlp_start, encode_value, cur_len, retdest %mload_trie_data // stack: hash, rlp_start, encode_value, cur_len, retdest // Update the length of the `TrieData` segment: there are only two // elements in a hash node. - SWAP3 %add_const(2) - %stack (cur_len, rlp_start, encode_value, hash, retdest) -> (retdest, hash, 32, cur_len) + INCR4 + INCR4 + %stack (hash, rlp_start, encode_value, cur_len, retdest) -> (retdest, hash, 32, cur_len) JUMP encode_or_hash_concrete_node: %stack (node_type, node_ptr, rlp_start, encode_value, cur_len) -> (node_type, node_ptr, rlp_start, encode_value, cur_len, maybe_hash_node) @@ -104,7 +103,7 @@ after_packed_small_rlp: encode_node: // stack: node_type, node_ptr, rlp_start, encode_value, cur_len, retdest // Increment node_ptr, so it points to the node payload instead of its type. - SWAP1 %increment SWAP1 + INCR2 // stack: node_type, node_payload_ptr, rlp_start, encode_value, cur_len, retdest DUP1 %eq_const(@MPT_NODE_EMPTY) %jumpi(encode_node_empty) @@ -158,7 +157,7 @@ global encode_node_branch: %stack (value_ptr, rlp_pos, rlp_start, encode_value) -> (0x80, rlp_pos, rlp_pos, rlp_start) MSTORE_GENERAL // stack: rlp_pos', rlp_start, cur_len, retdest - %increment + INCR1 // stack: rlp_pos'', rlp_start, cur_len, retdest %jump(encode_node_branch_prepend_prefix) encode_node_branch_with_value: @@ -198,7 +197,7 @@ encode_node_branch_prepend_prefix: DUP4 // rlp_pos PUSH 160 MSTORE_GENERAL - SWAP3 %increment SWAP3 // rlp_pos += 1 + INCR4 // rlp_pos += 1 %%unpack: %stack (result_len, result, cur_len, rlp_pos, rlp_start, node_payload_ptr, encode_value, old_len, retdest) -> (rlp_pos, result, result_len, %%after_unpacking, @@ -213,7 +212,7 @@ global encode_node_extension: SWAP4 %add_const(4) SWAP4 %stack (node_type, node_payload_ptr, rlp_start, encode_value, cur_len) -> (node_payload_ptr, rlp_start, encode_value, cur_len, encode_node_extension_after_encode_child, rlp_start, node_payload_ptr) - %add_const(2) %mload_trie_data + %increment_twice %mload_trie_data // stack: child_ptr, rlp_start, encode_value, cur_len, encode_node_extension_after_encode_child, rlp_start, node_payload_ptr, retdest %jump(encode_or_hash_node) encode_node_extension_after_encode_child: @@ -225,7 +224,7 @@ encode_node_extension_after_encode_child: PUSH encode_node_extension_after_hex_prefix // retdest PUSH 0 // terminated // stack: terminated, encode_node_extension_after_hex_prefix, rlp_start, result, result_len, node_payload_ptr, cur_len, retdest - DUP6 %increment %mload_trie_data // Load the packed_nibbles field, which is at index 1. + DUP6 INCR1 %mload_trie_data // Load the packed_nibbles field, which is at index 1. // stack: packed_nibbles, terminated, encode_node_extension_after_hex_prefix, rlp_start, result, result_len, node_payload_ptr, cur_len, retdest DUP7 %mload_trie_data // Load the num_nibbles field, which is at index 0. // stack: num_nibbles, packed_nibbles, terminated, encode_node_extension_after_hex_prefix, rlp_start, result, result_len, node_payload_ptr, cur_len, retdest @@ -241,7 +240,7 @@ encode_node_extension_after_hex_prefix: DUP1 // rlp_pos PUSH 160 MSTORE_GENERAL - %increment // rlp_pos += 1 + INCR1 // rlp_pos += 1 encode_node_extension_unpack: %stack (rlp_pos, rlp_start, result, result_len, node_payload_ptr, cur_len) -> (rlp_pos, result, result_len, encode_node_extension_after_unpacking, rlp_start, cur_len) @@ -264,7 +263,7 @@ global encode_node_leaf: PUSH encode_node_leaf_after_hex_prefix // retdest PUSH 1 // terminated // stack: terminated, encode_node_leaf_after_hex_prefix, rlp_start, node_payload_ptr, encode_value, cur_len, retdest - DUP4 %increment %mload_trie_data // Load the packed_nibbles field, which is at index 1. + DUP4 INCR1 %mload_trie_data // Load the packed_nibbles field, which is at index 1. // stack: packed_nibbles, terminated, encode_node_leaf_after_hex_prefix, rlp_start, node_payload_ptr, encode_value, cur_len, retdest DUP5 %mload_trie_data // Load the num_nibbles field, which is at index 0. // stack: num_nibbles, packed_nibbles, terminated, encode_node_leaf_after_hex_prefix, rlp_start, node_payload_ptr, encode_value, cur_len, retdest @@ -274,7 +273,7 @@ global encode_node_leaf: encode_node_leaf_after_hex_prefix: // stack: rlp_pos, rlp_start, node_payload_ptr, encode_value, cur_len, retdest SWAP2 - %add_const(2) // The value pointer starts at index 3, after num_nibbles and packed_nibbles. + %increment_twice // The value pointer starts at index 3, after num_nibbles and packed_nibbles. // stack: value_ptr_ptr, rlp_start, rlp_pos, encode_value, cur_len, retdest %mload_trie_data // stack: value_ptr, rlp_start, rlp_pos, encode_value, cur_len, retdest diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash_trie_specific.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash_trie_specific.asm index 31fa192fa..f5649d837 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash_trie_specific.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash_trie_specific.asm @@ -80,7 +80,7 @@ global encode_account: DUP2 %mload_trie_data // nonce = value[0] %rlp_scalar_len // stack: nonce_rlp_len, rlp_addr, value_ptr, cur_len, retdest - DUP3 %increment %mload_trie_data // balance = value[1] + DUP3 INCR1 %mload_trie_data // balance = value[1] %rlp_scalar_len // stack: balance_rlp_len, nonce_rlp_len, rlp_addr, value_ptr, cur_len, retdest PUSH 66 // storage_root and code_hash fields each take 1 + 32 bytes @@ -100,12 +100,12 @@ global encode_account: // stack: nonce, rlp_pos_3, value_ptr, cur_len, retdest SWAP1 %encode_rlp_scalar // stack: rlp_pos_4, value_ptr, cur_len, retdest - DUP2 %increment %mload_trie_data // balance = value[1] + DUP2 INCR1 %mload_trie_data // balance = value[1] // stack: balance, rlp_pos_4, value_ptr, cur_len, retdest SWAP1 %encode_rlp_scalar // stack: rlp_pos_5, value_ptr, cur_len, retdest DUP3 - DUP3 %add_const(2) %mload_trie_data // storage_root_ptr = value[2] + DUP3 %increment_twice %mload_trie_data // storage_root_ptr = value[2] // stack: storage_root_ptr, cur_len, rlp_pos_5, value_ptr, cur_len, retdest DUP3 // stack: rlp_pos_5, storage_root_ptr, cur_len, rlp_pos_5, value_ptr, cur_len, retdest @@ -130,10 +130,10 @@ global encode_txn: DUP2 %mload_trie_data // stack: txn_rlp_len, rlp_addr, value_ptr, cur_len, retdest // We need to add 1+txn_rlp_len to the length of the trie data. - SWAP3 DUP4 %increment ADD + INCR4 SWAP3 DUP4 ADD // stack: new_len, rlp_addr, value_ptr, txn_rlp_len, retdest SWAP3 - SWAP2 %increment + INCR3 SWAP2 // stack: txn_rlp_ptr=value_ptr+1, rlp_addr, txn_rlp_len, new_len, retdest %stack (txn_rlp_ptr, rlp_addr, txn_rlp_len) -> (rlp_addr, txn_rlp_len, txn_rlp_len, txn_rlp_ptr) @@ -190,12 +190,12 @@ encode_receipt_after_type: SWAP1 %encode_rlp_list_prefix // stack: rlp_addr, payload_len_ptr, cur_len, retdest // Encode status. - DUP2 %increment %mload_trie_data + DUP2 INCR1 %mload_trie_data // stack: status, rlp_addr, payload_len_ptr, cur_len, retdest SWAP1 %encode_rlp_scalar // stack: rlp_addr, payload_len_ptr, cur_len, retdest // Encode cum_gas_used. - DUP2 %add_const(2) %mload_trie_data + DUP2 %increment_twice %mload_trie_data // stack: cum_gas_used, rlp_addr, payload_len_ptr, cur_len, retdest SWAP1 %encode_rlp_scalar // stack: rlp_addr, payload_len_ptr, cur_len, retdest @@ -235,11 +235,11 @@ encode_receipt_logs_loop: SWAP1 %encode_rlp_list_prefix // stack: rlp_addr, current_log_ptr, i, num_logs, current_log_ptr, old_rlp_pos, payload_len_ptr, cur_len, retdest // Encode address. - DUP2 %increment %mload_trie_data + DUP2 INCR1 %mload_trie_data // stack: address, rlp_addr, current_log_ptr, i, num_logs, current_log_ptr, old_rlp_pos, payload_len_ptr, cur_len, retdest SWAP1 %encode_rlp_160 // stack: rlp_addr, current_log_ptr, i, num_logs, current_log_ptr, old_rlp_pos, payload_len_ptr, cur_len, retdest - DUP2 %add_const(2) %mload_trie_data + DUP2 %increment_twice %mload_trie_data // stack: num_topics, rlp_addr, current_log_ptr, i, num_logs, current_log_ptr, old_rlp_pos, payload_len_ptr, cur_len, retdest // Encode topics prefix. DUP1 %mul_const(33) @@ -272,9 +272,10 @@ encode_receipt_topics_loop: // stack: rlp_addr, current_topic, j, topics_ptr, rlp_addr, num_topics, i, num_logs, current_log_ptr, old_rlp_pos, payload_len_ptr, cur_len', retdest %encode_rlp_256 // stack: new_rlp_pos, j, topics_ptr, rlp_addr, num_topics, i, num_logs, current_log_ptr, old_rlp_pos, payload_len_ptr, cur_len', retdest + INCR2 + // stack: new_rlp_pos, j', topics_ptr, rlp_addr, num_topics, i, num_logs, current_log_ptr, old_rlp_pos, payload_len_ptr, cur_len', retdest SWAP3 POP - // stack: j, topics_ptr, new_rlp_pos, num_topics, i, num_logs, current_log_ptr, old_rlp_pos, payload_len_ptr, cur_len', retdest - %increment + // stack: j', topics_ptr, new_rlp_pos, num_topics, i, num_logs, current_log_ptr, old_rlp_pos, payload_len_ptr, cur_len', retdest %jump(encode_receipt_topics_loop) encode_receipt_topics_end: @@ -295,9 +296,9 @@ encode_receipt_topics_end: DUP1 SWAP7 ADD SWAP6 // stack: data_len, i, num_logs, data_len_ptr, rlp_addr, payload_len_ptr, cur_len'', retdest - DUP4 %increment DUP2 ADD + DUP4 INCR1 DUP2 ADD // stack: next_log_ptr, data_len, i, num_logs, data_len_ptr, rlp_addr, payload_len_ptr, cur_len'', retdest - SWAP4 %increment + SWAP4 INCR1 // stack: data_ptr, data_len, i, num_logs, next_log_ptr, rlp_addr, payload_len_ptr, cur_len'', retdest PUSH @SEGMENT_TRIE_DATA %build_kernel_address // stack: SRC, data_len, i, num_logs, next_log_ptr, rlp_addr, payload_len_ptr, cur_len'', retdest @@ -305,9 +306,10 @@ encode_receipt_topics_end: // stack: rlp_addr, SRC, data_len, i, num_logs, next_log_ptr, rlp_addr, payload_len_ptr, cur_len'', retdest %encode_rlp_string // stack: new_rlp_pos, i, num_logs, next_log_ptr, rlp_addr, payload_len_ptr, cur_len'', retdest + INCR2 + // stack: new_rlp_pos, i', num_logs, next_log_ptr, rlp_addr, payload_len_ptr, cur_len'', retdest SWAP4 POP - // stack: i, num_logs, next_log_ptr, new_rlp_pos, payload_len_ptr, cur_len'', retdest - %increment + // stack: i', num_logs, next_log_ptr, new_rlp_pos, payload_len_ptr, cur_len'', retdest %jump(encode_receipt_logs_loop) encode_receipt_end: @@ -322,22 +324,22 @@ encode_receipt_end: encode_nonzero_receipt_type: // stack: txn_type, rlp_addr, value_ptr, cur_len, retdest // We have a nonlegacy receipt, so the type is also stored in the trie data segment. - SWAP3 %increment SWAP3 + INCR4 // stack: txn_type, rlp_addr, value_ptr, cur_len, retdest - DUP3 %increment %mload_trie_data + DUP3 INCR1 %mload_trie_data // stack: payload_len, txn_type, rlp_addr, value_ptr, retdest // The transaction type is encoded in 1 byte - %increment %rlp_list_len + INCR1 %rlp_list_len // stack: rlp_receipt_len, txn_type, rlp_addr, value_ptr, retdest DUP3 %encode_rlp_multi_byte_string_prefix // stack: rlp_addr, txn_type, old_rlp_addr, value_ptr, retdest DUP1 DUP3 MSTORE_GENERAL - %increment + INCR1 // stack: rlp_addr, txn_type, old_rlp_addr, value_ptr, retdest %stack (rlp_addr, txn_type, old_rlp_addr, value_ptr, retdest) -> (rlp_addr, value_ptr, retdest) // We replace `value_ptr` with `paylaod_len_ptr` so we can encode the rest of the data more easily - SWAP1 %increment SWAP1 + INCR2 // stack: rlp_addr, payload_len_ptr, retdest %jump(encode_receipt_after_type) @@ -346,7 +348,7 @@ global encode_storage_value: SWAP1 %mload_trie_data SWAP1 // A storage value is a scalar, so we only need to add 1 to the trie data length. - SWAP2 %increment SWAP2 + INCR3 // stack: rlp_addr, value, cur_len, retdest // The YP says storage trie is a map "... to the RLP-encoded 256-bit integer values" diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/hex_prefix.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/hex_prefix.asm index 3e8a783ab..86822d2a9 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/hex_prefix.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/hex_prefix.asm @@ -11,7 +11,7 @@ global hex_prefix_rlp: PUSH 2 DUP3 DIV // Compute the length of the hex-prefix string, in bytes: // hp_len = num_nibbles / 2 + 1 = i + 1 - %increment + INCR1 // stack: hp_len, rlp_addr, num_nibbles, packed_nibbles, terminated, retdest // Write the RLP header. @@ -51,7 +51,7 @@ first_byte: // stack: first_byte, rlp_addr, retdest DUP2 %swap_mstore - %increment + INCR1 // stack: rlp_addr', retdest SWAP1 JUMP @@ -91,7 +91,7 @@ rlp_header_medium: %swap_mstore // stack: rlp_addr, num_nibbles, packed_nibbles, terminated, retdest // rlp_addr += 1 - %increment + INCR1 // stack: rlp_addr, num_nibbles, packed_nibbles, terminated, retdest SWAP3 DUP3 DUP3 @@ -113,12 +113,12 @@ rlp_header_large: MSTORE_GENERAL // stack: hp_len, rlp_addr, num_nibbles, packed_nibbles, terminated, retdest - DUP2 %increment + DUP2 INCR1 %swap_mstore // stack: rlp_addr, num_nibbles, packed_nibbles, terminated, retdest // rlp_addr += 2 - %add_const(2) + %increment_twice // stack: rlp_addr, num_nibbles, packed_nibbles, terminated, retdest SWAP3 DUP3 DUP3 diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert.asm index 83a12b4b0..2553b3352 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert.asm @@ -7,7 +7,7 @@ global mpt_insert: DUP1 %mload_trie_data // stack: node_type, node_ptr, num_nibbles, key, value_ptr, retdest // Increment node_ptr, so it points to the node payload instead of its type. - SWAP1 %increment SWAP1 + INCR2 // stack: node_type, node_payload_ptr, num_nibbles, key, value_ptr, retdest DUP1 %eq_const(@MPT_NODE_EMPTY) %jumpi(mpt_insert_empty) diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_extension.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_extension.asm index 21a4b7558..5b7a3cdd3 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_extension.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_extension.asm @@ -40,12 +40,12 @@ global mpt_insert_extension: // stack: node_payload_ptr, insert_len, insert_key, insert_value_ptr, retdest // We start by loading the extension node's three fields: node_len, node_key, node_child_ptr - DUP1 %add_const(2) %mload_trie_data + DUP1 %increment_twice %mload_trie_data // stack: node_child_ptr, node_payload_ptr, insert_len, insert_key, insert_value_ptr, retdest %stack (node_child_ptr, node_payload_ptr, insert_len, insert_key) -> (node_payload_ptr, insert_len, insert_key, node_child_ptr) // stack: node_payload_ptr, insert_len, insert_key, node_child_ptr, insert_value_ptr, retdest - DUP1 %increment %mload_trie_data + DUP1 INCR1 %mload_trie_data // stack: node_key, node_payload_ptr, insert_len, insert_key, node_child_ptr, insert_value_ptr, retdest SWAP1 %mload_trie_data // stack: node_len, node_key, insert_len, insert_key, node_child_ptr, insert_value_ptr, retdest @@ -103,7 +103,7 @@ process_node_child: // stack: new_node_ptr, common_len, common_key, node_len, node_key, insert_len, insert_key, node_child_ptr, insert_value_ptr, retdest DUP8 // node_child_ptr DUP2 // new_node_ptr - %increment + INCR1 DUP7 // node_key ADD %mstore_trie_data @@ -135,7 +135,7 @@ node_key_continues_multiple_nibbles: // stack: node_key_first, ext_node_ptr, new_node_ptr, ... DUP3 // new_node_ptr ADD - %increment + INCR1 // stack: new_node_ptr + node_key_first + 1, ext_node_ptr, new_node_ptr, ... %mstore_trie_data %jump(process_inserted_entry) @@ -178,7 +178,7 @@ insert_key_continues: // stack: insert_key_first, leaf_node_ptr, new_node_ptr, ... DUP3 // new_node_ptr ADD - %increment + INCR1 // stack: new_node_ptr + insert_key_first + 1, leaf_node_ptr, new_node_ptr, ... %mstore_trie_data %jump(maybe_add_extension_for_common_key) diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_leaf.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_leaf.asm index 806fc0ddb..17f535094 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_leaf.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_leaf.asm @@ -37,7 +37,7 @@ global mpt_insert_leaf: // stack: node_payload_ptr, insert_len, insert_key, insert_value_ptr, retdest %stack (node_payload_ptr, insert_len, insert_key) -> (insert_len, insert_key, node_payload_ptr) // stack: insert_len, insert_key, node_payload_ptr, insert_value_ptr, retdest - DUP3 %increment %mload_trie_data + DUP3 INCR1 %mload_trie_data // stack: node_key, insert_len, insert_key, node_payload_ptr, insert_value_ptr, retdest DUP4 %mload_trie_data // stack: node_len, node_key, insert_len, insert_key, node_payload_ptr, insert_value_ptr, retdest @@ -55,7 +55,7 @@ global mpt_insert_leaf: // Replace node_payload_ptr with node_value, which is node_payload[2]. // stack: node_len, node_key, insert_len, insert_key, node_payload_ptr, insert_value_ptr, retdest SWAP4 - %add_const(2) + %increment_twice %mload_trie_data SWAP4 // stack: node_len, node_key, insert_len, insert_key, node_value_ptr, insert_value_ptr, retdest @@ -154,7 +154,7 @@ node_key_continues: // stack: leaf_ptr, node_key_first, node_len, node_key, branch_ptr, ... SWAP1 DUP5 // branch_ptr - %increment // Skip over node type field + INCR1 // Skip over node type field ADD // Add node_key_first %mstore_trie_data // stack: node_len, node_key, branch_ptr, ... @@ -178,7 +178,7 @@ insert_key_continues: // stack: leaf_ptr, insert_key_first, insert_len, insert_key, branch_ptr, ... SWAP1 DUP5 // branch_ptr - %increment // Skip over node type field + INCR1 // Skip over node type field ADD // Add insert_key_first %mstore_trie_data // stack: insert_len, insert_key, branch_ptr, ... @@ -196,7 +196,7 @@ keys_match: -> (node_payload_ptr, node_len, node_key, insert_value_ptr) // stack: node_payload_ptr, common_len, common_key, insert_value_ptr, retdest DUP4 DUP2 - %add_const(2) + %increment_twice %mstore_trie_data %stack (node_payload_ptr, common_len, common_key, insert_value_ptr, retdest) -> (node_payload_ptr, retdest) PUSH 1 SWAP1 SUB diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/final_tries.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/final_tries.asm index 53093f4f4..cc004d549 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/final_tries.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/final_tries.asm @@ -14,10 +14,10 @@ global insert_all_accounts: %jumpi(no_more_accounts) // stack: key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest DUP4 - %increment + INCR1 MLOAD_GENERAL // stack: account_ptr, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest - %add_const(2) + %increment_twice DUP1 %mload_trie_data // stack: storage_root_ptr, storage_root_ptr_ptr, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest @@ -32,7 +32,7 @@ after_insert_all_slots: %mstore_trie_data // stack: storage_ptr_ptr', key, root_ptr, account_ptr_ptr, retdest DUP4 - %increment + INCR1 MLOAD_GENERAL %stack (payload_ptr, storage_ptr_ptr_p, key, root_ptr, account_ptr_ptr) -> @@ -67,11 +67,11 @@ global insert_all_slots: insert_next_slot: // stack: addr, storage_ptr_ptr, root_ptr, retdest DUP2 - %increment + INCR1 MLOAD_GENERAL // stack: key, addr, storage_ptr_ptr, root_ptr, retdest DUP3 - %add_const(2) + %increment_twice MLOAD_GENERAL // stack: value, key, addr, storage_ptr_ptr, root_ptr, retdest // If the value is 0, then payload_ptr = 0, and we don't need to insert a value in the `TrieData` segment. @@ -116,15 +116,15 @@ global delete_removed_accounts: MLOAD_GENERAL // stack: key, account_ptr_ptr, root_ptr, storage_ptr_ptr, retdest DUP2 - %add_const(2) + %increment_twice MLOAD_GENERAL // get initial payload_ptr - %add_const(2) // storage_root_ptr_ptr = payload_ptr + 2 + %increment_twice // storage_root_ptr_ptr = payload_ptr + 2 %mload_trie_data // stack: storage_root_ptr, key, account_ptr_ptr, root_ptr, storage_ptr_ptr, retdest DUP3 - %increment + INCR1 MLOAD_GENERAL // get dynamic payload_ptr - %add_const(2) // storage_root_ptr_ptr = dyn_payload_ptr + 2 + %increment_twice // storage_root_ptr_ptr = dyn_payload_ptr + 2 %stack (storage_root_ptr_ptr, storage_root_ptr, key, account_ptr_ptr, root_ptr, storage_ptr_ptr) -> (key, storage_root_ptr, storage_ptr_ptr, after_delete_removed_slots, storage_root_ptr_ptr, account_ptr_ptr, root_ptr) @@ -196,7 +196,7 @@ maybe_delete_this_slot: delete_this_slot: // stack: addr, root_ptr, storage_ptr_ptr, retdest DUP3 - %increment + INCR1 MLOAD_GENERAL %stack (key, addr, root_ptr, storage_ptr_ptr) -> (root_ptr, 64, key, after_mpt_delete_slot, addr, storage_ptr_ptr) %jump(mpt_delete) diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/initial_tries.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/initial_tries.asm index df4762a51..f1c80939e 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/initial_tries.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/initial_tries.asm @@ -1,4 +1,3 @@ - global set_initial_state_trie: // stack: retdest PUSH set_initial_state_trie_after @@ -44,20 +43,20 @@ after_mpt_read: //stack: trie_account_ptr_ptr, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest DUP1 %mload_trie_data - %add_const(2) + %increment_twice %mload_trie_data // stack: trie_storage_root, trie_account_ptr_ptr, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest SWAP1 // stack: trie_account_ptr_ptr, trie_storage_root, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest DUP6 - %add_const(2) // intial account_ptr = account_ptr_ptr + 2 + %increment_twice // intial account_ptr = account_ptr_ptr + 2 MLOAD_GENERAL // stack: account_ptr, trie_account_ptr_ptr, trie_storage_root, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest DUP1 SWAP2 // stack: trie_account_ptr_ptr, account_ptr, account_ptr, trie_storage_root, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest %mstore_trie_data // The trie's account points to the linked list initial account // stack: account_ptr, trie_storage_root, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest - %add_const(2) + %increment_twice // stack: storage_root_ptr_ptr, trie_storage_root, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest %stack @@ -101,7 +100,7 @@ global insert_all_initial_slots: insert_next_slot: // stack: addr, storage_ptr_ptr, root_ptr, retdest DUP2 - %increment + INCR1 MLOAD_GENERAL // stack: key, addr, storage_ptr_ptr, root_ptr, retdest DUP3 diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/linked_list.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/linked_list.asm index 650d69db2..00330ec98 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/linked_list.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/linked_list.asm @@ -69,29 +69,29 @@ loop_store_initial_accounts: %get_trie_data_size // stack: cpy_ptr, current_node_ptr, cur_len, retdest DUP2 - %increment + INCR1 MLOAD_GENERAL // stack: nonce_ptr, cpy_ptr, current_node_ptr, cur_len, retdest DUP1 %mload_trie_data // nonce %append_to_trie_data - %increment + INCR1 // stack: balance_ptr, cpy_ptr, current_node_ptr, cur_len, retdest DUP1 %mload_trie_data // balance %append_to_trie_data - %increment // The storage_root_ptr is not really necessary + INCR1 // The storage_root_ptr is not really necessary // stack: storage_root_ptr_ptr, cpy_ptr, current_node_ptr, cur_len, retdest DUP1 %mload_trie_data // storage_root_ptr %append_to_trie_data - %increment + INCR1 // stack: code_hash_ptr, cpy_ptr, current_node_ptr, cur_len, retdest %mload_trie_data // code_hash %append_to_trie_data // stack: cpy_ptr, current_node_ptr, cur_len, retdest DUP2 - %add_const(2) + %increment_twice SWAP1 MSTORE_GENERAL // Store cpy_ptr // stack: current_node_ptr, cur_len, retdest @@ -148,7 +148,7 @@ store_initial_accounts_end: DUP2 %mul_const(4) // stack: ptr, @SEGMENT_ACCOUNTS_LINKED_LIST, ptr/4 - %increment %assert_gt + INCR1 %assert_gt // stack: ptr/4 DUP1 PUSH 4 @@ -196,7 +196,7 @@ account_found_with_overwrite: // The address was already in the list // stack: pred_ptr, addr_key, payload_ptr, retdest // Load the payload pointer - %increment + INCR1 // stack: payload_ptr_ptr, addr_key, payload_ptr, retdest DUP3 MSTORE_GENERAL %pop2 @@ -233,23 +233,23 @@ insert_new_account: DUP4 MSTORE_GENERAL // stack: new_ptr, next_ptr, addr_key, payload_ptr, retdest - %increment + INCR1 DUP1 DUP5 MSTORE_GENERAL // stack: new_ptr + 1, next_ptr, addr_key, payload_ptr, retdest - %increment + INCR1 DUP1 DUP5 %clone_account MSTORE_GENERAL - %increment + INCR1 DUP1 // stack: new_next_ptr, new_next_ptr, next_ptr, addr_key, payload_ptr, retdest SWAP2 MSTORE_GENERAL // stack: new_next_ptr, addr_key, payload_ptr, retdest - %increment + INCR1 %mstore_global_metadata(@GLOBAL_METADATA_ACCOUNTS_LINKED_LIST_NEXT_AVAILABLE) // stack: addr_key, payload_ptr, retdest %pop2 @@ -293,7 +293,7 @@ account_found: // The address was already in the list // stack: pred_ptr, addr_key, retdest // Load the payload pointer - %increment + INCR1 MLOAD_GENERAL // stack: orig_payload_ptr, addr_key, retdest %stack (orig_payload_ptr, addr_key, retdest) -> (retdest, orig_payload_ptr) @@ -390,7 +390,7 @@ global store_initial_slots: loop_store_initial_slots: // stack: current_node_ptr, cur_len, retdest DUP1 - %add_const(2) + %increment_twice MLOAD_GENERAL // stack: value, current_node_ptr, cur_len, retdest DUP2 @@ -408,7 +408,7 @@ loop_store_initial_slots: // stack: current_addr_key, current_node_ptr, cur_len', retdest SWAP1 DUP1 - %increment + INCR1 MLOAD_GENERAL // stack: current_slot_key, current_node_ptr, current_addr_key, cur_len', retdest SWAP1 @@ -422,7 +422,7 @@ loop_store_initial_slots: // stack: next_node_ptr, current_slot_key, current_addr_key, cur_len', retdest DUP1 DUP1 - %increment + INCR1 MLOAD_GENERAL // stack: next_node_slot_key, next_node_ptr, next_node_ptr, current_slot_key, current_addr_key, cur_len', retdest SWAP1 @@ -513,7 +513,7 @@ global insert_slot_with_value: %assert_eq // stack: pred_ptr, addr_key, key, value, retdest DUP1 - %increment + INCR1 MLOAD_GENERAL // stack: pred_key, pred_ptr, addr_key, key, value, retdest DUP1 DUP5 @@ -562,7 +562,7 @@ insert_new_slot_with_value: %assert_eq // stack: next_ptr, new_ptr, next_ptr_ptr, addr_key, key, value, retdest DUP1 - %increment + INCR1 MLOAD_GENERAL // stack: next_key, next_ptr, new_ptr, next_ptr_ptr, addr_key, key, value, retdest DUP1 // This is added just to have the correct stack in next_node_ok @@ -585,14 +585,14 @@ next_node_ok_with_value: MSTORE_GENERAL // stack: new_ptr, next_ptr, addr_key, key, value, retdest // Write the key in the new node - %increment + INCR1 DUP1 DUP5 MSTORE_GENERAL // stack: new_ptr + 1, next_ptr, addr_key, key, value, retdest // Write the value in the linked list. - %increment - DUP1 %increment + INCR1 + DUP1 INCR1 // stack: new_ptr+3, new_value_ptr, next_ptr, addr_key, key, value, retdest %stack (new_cloned_value_ptr, new_value_ptr, next_ptr, addr_key, key, value, retdest) -> (value, new_cloned_value_ptr, value, new_value_ptr, new_cloned_value_ptr, next_ptr, retdest) @@ -600,20 +600,20 @@ next_node_ok_with_value: MSTORE_GENERAL // Store value. // stack: new_ptr + 3, next_ptr, retdest - %increment + INCR1 DUP1 // stack: new_next_ptr_ptr, new_next_ptr_ptr, next_ptr, retdest SWAP2 MSTORE_GENERAL // stack: new_next_ptr_ptr, retdest - %increment + INCR1 %mstore_global_metadata(@GLOBAL_METADATA_STORAGE_LINKED_LIST_NEXT_AVAILABLE) // stack: retdest JUMP slot_found_write_value: // stack: pred_ptr, addr_key, key, value, retdest - %add_const(2) + %increment_twice %stack (payload_ptr, addr_key, key, value) -> (value, payload_ptr) MSTORE_GENERAL // stack: retdest @@ -666,7 +666,7 @@ global insert_slot: %assert_eq // stack: pred_ptr, addr_key, key, value, retdest DUP1 - %increment + INCR1 MLOAD_GENERAL // stack: pred_key, pred_ptr, addr_key, key, value, retdest DUP1 DUP5 @@ -691,7 +691,7 @@ slot_found_write: // The slot was already in the list // stack: pred_ptr, addr_key, key, value, retdest // Load the old value - %add_const(2) + %increment_twice DUP1 MLOAD_GENERAL // stack: old_value, pred_ptr + 2, addr_key, key, value, retdest @@ -729,7 +729,7 @@ insert_new_slot: %assert_eq // stack: next_ptr, new_ptr, next_ptr_ptr, addr_key, key, value, retdest DUP1 - %increment + INCR1 MLOAD_GENERAL // stack: next_key, next_ptr, new_ptr, next_ptr_ptr, addr_key, key, value, retdest DUP1 // This is added just to have the correct stack in next_node_ok @@ -751,32 +751,32 @@ next_node_ok: MSTORE_GENERAL // stack: new_ptr, next_ptr, addr_key, key, value, retdest // Write the key in the new node - %increment + INCR1 DUP1 DUP5 MSTORE_GENERAL // stack: new_ptr + 1, next_ptr, addr_key, key, value, retdest // Store value - %increment + INCR1 DUP1 DUP6 MSTORE_GENERAL // stack: new_ptr + 2, next_ptr, addr_key, key, value, retdest // Store the copy of value - %increment + INCR1 DUP1 DUP6 %clone_slot MSTORE_GENERAL // stack: new_ptr + 3, next_ptr, addr_key, key, value, retdest - %increment + INCR1 DUP1 // stack: new_next_ptr, new_next_ptr, next_ptr, addr_key, key, value, retdest SWAP2 MSTORE_GENERAL // stack: new_next_ptr, addr_key, key, value, retdest - %increment + INCR1 %mstore_global_metadata(@GLOBAL_METADATA_STORAGE_LINKED_LIST_NEXT_AVAILABLE) // stack: addr_key, key, value, retdest %stack (addr_key, key, value, retdest) -> (retdest, value) @@ -809,7 +809,7 @@ global search_slot: %assert_eq // stack: pred_ptr, addr_key, key, value, retdest DUP1 - %increment + INCR1 MLOAD_GENERAL // stack: pred_key, pred_ptr, addr_key, key, value, retdest DUP1 DUP5 @@ -839,7 +839,7 @@ slot_found_no_write: // The slot was already in the list // stack: pred_ptr, addr_key, key, value, retdest // Load the old value - %add_const(2) + %increment_twice MLOAD_GENERAL // stack: old_value, addr_key, key, value, retdest %stack (old_value, addr_key, key, value, retdest) -> (retdest, old_value) @@ -879,7 +879,7 @@ global remove_slot: %assert_eq // stack: next_ptr, next_ptr_ptr, addr_key, key, retdest DUP1 - %increment + INCR1 MLOAD_GENERAL // stack: next_key, next_ptr, next_ptr_ptr, addr_key, key, retdest DUP5 diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/read.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/read.asm index 86f8ae190..9920e8d0b 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/read.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/read.asm @@ -32,7 +32,7 @@ global mpt_read: %mload_trie_data // stack: node_type, node_ptr, num_nibbles, key, retdest // Increment node_ptr, so it points to the node payload instead of its type. - SWAP1 %increment SWAP1 + INCR2 // stack: node_type, node_payload_ptr, num_nibbles, key, retdest DUP1 %eq_const(@MPT_NODE_EMPTY) %jumpi(mpt_read_empty) @@ -98,7 +98,7 @@ global mpt_read_extension: %mul_const(4) SHR // key_part = key >> (future_nibbles * 4) DUP1 // stack: key_part, key_part, future_nibbles, key, node_payload_ptr, retdest - DUP5 %increment %mload_trie_data + DUP5 INCR1 %mload_trie_data // stack: node_key, key_part, key_part, future_nibbles, key, node_payload_ptr, retdest EQ // does the first part of our key match the node's key? %jumpi(mpt_read_extension_found) @@ -116,7 +116,7 @@ global mpt_read_extension_found: // stack: key, future_nibbles, node_payload_ptr, retdest SWAP2 // stack: node_payload_ptr, future_nibbles, key, retdest - %add_const(2) // child pointer is third field of extension node + %increment_twice // child pointer is third field of extension node %mload_trie_data // stack: child_ptr, future_nibbles, key, retdest %jump(mpt_read) // recurse @@ -127,7 +127,7 @@ global mpt_read_leaf: // stack: node_payload_ptr, num_nibbles, key, retdest DUP1 %mload_trie_data // stack: node_num_nibbles, node_payload_ptr, num_nibbles, key, retdest - DUP2 %increment %mload_trie_data + DUP2 INCR1 %mload_trie_data // stack: node_key, node_num_nibbles, node_payload_ptr, num_nibbles, key, retdest SWAP3 // stack: num_nibbles, node_num_nibbles, node_payload_ptr, node_key, key, retdest @@ -144,7 +144,7 @@ global mpt_read_leaf_not_found: JUMP global mpt_read_leaf_found: // stack: node_payload_ptr, retdest - %add_const(2) // The value pointer is located after num_nibbles and the key. + %increment_twice // The value pointer is located after num_nibbles and the key. // stack: value_ptr_ptr, retdest SWAP1 // For leaves, we return the pointer diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/util.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/util.asm index 64ed2599b..9c27ef4a8 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/util.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/util.asm @@ -34,7 +34,7 @@ %get_trie_data_size // stack: trie_data_size, value DUP1 - %increment + INCR1 // stack: trie_data_size', trie_data_size, value %set_trie_data_size // stack: trie_data_size, value @@ -151,7 +151,7 @@ DUP2 DUP2 SUB %jumpi(%%return_with_first_nibs) // len_common += 1 - SWAP2 %increment SWAP2 + INCR3 // key_common = key_common * 16 + first_nib_1 SWAP3 diff --git a/evm_arithmetization/src/cpu/kernel/asm/rlp/decode.asm b/evm_arithmetization/src/cpu/kernel/asm/rlp/decode.asm index 43c6627d6..d260b3a2b 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/rlp/decode.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/rlp/decode.asm @@ -35,10 +35,9 @@ decode_rlp_string_len_medium: // stack: first_byte, rlp_addr, retdest %sub_const(0x80) // stack: len, rlp_addr, retdest - SWAP1 - %increment - // stack: rlp_addr', len, retdest - %stack (rlp_addr, len, retdest) -> (retdest, rlp_addr, len) + INCR2 + // stack: len, rlp_addr', retdest + SWAP2 JUMP decode_rlp_string_len_large: @@ -46,8 +45,8 @@ decode_rlp_string_len_large: // stack: first_byte, rlp_addr, retdest %sub_const(0xb7) // stack: len_of_len, rlp_addr, retdest + INCR2 SWAP1 - %increment // stack: rlp_addr', len_of_len, retdest %jump(decode_int_given_len) @@ -91,9 +90,7 @@ global decode_rlp_list_len: DUP1 MLOAD_GENERAL // stack: first_byte, rlp_addr, retdest - SWAP1 - %increment // increment rlp_addr - SWAP1 + INCR2 // increment rlp_addr // stack: first_byte, rlp_addr', retdest // If first_byte is >= 0xf8, it's a > 55 byte list, and // first_byte - 0xf7 is the length of the length. diff --git a/evm_arithmetization/src/cpu/kernel/asm/rlp/encode.asm b/evm_arithmetization/src/cpu/kernel/asm/rlp/encode.asm index 9f6813ab1..a9c8e7b8f 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/rlp/encode.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/rlp/encode.asm @@ -27,10 +27,9 @@ global encode_rlp_fixed: // stack: first_byte, rlp_addr, len, rlp_addr, string, retdest MSTORE_GENERAL // stack: len, rlp_addr, string, retdest - SWAP1 - %increment // increment rlp_addr - // stack: rlp_addr, len, string, retdest - %stack (rlp_addr, len, string) -> (rlp_addr, string, len, encode_rlp_fixed_finish) + INCR2 // increment rlp_addr + // stack: len, rlp_addr', string, retdest + %stack (len, rlp_addr, string) -> (rlp_addr, string, len, encode_rlp_fixed_finish) // stack: rlp_addr, string, len, encode_rlp_fixed_finish, retdest %jump(mstore_unpacking) encode_rlp_fixed_finish: @@ -48,17 +47,16 @@ global doubly_encode_rlp_fixed: // stack: first_byte, rlp_addr, len, rlp_addr, string, retdest MSTORE_GENERAL // stack: len, rlp_addr, string, retdest - DUP2 %increment + DUP2 INCR1 DUP2 %add_const(0x80) // stack: second_byte, rlp_addr', len, original_rlp_addr, string, retdest MSTORE_GENERAL // stack: len, rlp_addr, string, retdest - SWAP1 - %add_const(2) // advance past the two prefix bytes - // stack: rlp_addr'', len, string, retdest - %stack (rlp_addr, len, string) -> (rlp_addr, string, len, encode_rlp_fixed_finish) - // stack: context, segment, rlp_addr'', string, len, encode_rlp_fixed_finish, retdest + INCR2 INCR2 // advance past the two prefix bytes + // stack: len, rlp_addr'', string, retdest + %stack (len, rlp_addr, string) -> (rlp_addr, string, len, encode_rlp_fixed_finish) + // stack: rlp_addr'', string, len, encode_rlp_fixed_finish, retdest %jump(mstore_unpacking) // Writes the RLP prefix for a string of the given length. This does not handle @@ -83,7 +81,7 @@ global encode_rlp_multi_byte_string_prefix: // stack: prefix, rlp_addr, rlp_addr, retdest MSTORE_GENERAL // stack: rlp_addr, retdest - %increment + INCR1 // stack: rlp_addr', retdest SWAP1 JUMP @@ -100,7 +98,7 @@ encode_rlp_multi_byte_string_prefix_large: // stack: first_byte, rlp_addr, rlp_addr, len_of_len, str_len, retdest MSTORE_GENERAL // stack: rlp_addr, len_of_len, str_len, retdest - %increment + INCR1 // stack: rlp_addr', len_of_len, str_len, retdest %stack (rlp_addr, len_of_len, str_len) -> (rlp_addr, str_len, len_of_len) %jump(mstore_unpacking) @@ -127,7 +125,7 @@ global encode_rlp_list_prefix: // stack: prefix, rlp_addr, rlp_addr, retdest MSTORE_GENERAL // stack: rlp_addr, retdest - %increment + INCR1 SWAP1 JUMP encode_rlp_list_prefix_large: @@ -140,7 +138,7 @@ encode_rlp_list_prefix_large: // stack: first_byte, rlp_addr, len_of_len, rlp_addr, payload_len, retdest MSTORE_GENERAL // stack: len_of_len, rlp_addr, payload_len, retdest - SWAP1 %increment + INCR2 SWAP1 // stack: rlp_addr', len_of_len, payload_len, retdest %stack (rlp_addr, len_of_len, payload_len) -> (rlp_addr, payload_len, len_of_len, @@ -177,7 +175,7 @@ global prepend_rlp_list_prefix: // stack: prefix_byte, start_rlp_addr-1, payload_len, end_rlp_addr, start_rlp_addr, retdest MSTORE_GENERAL // stack: payload_len, end_rlp_addr, start_rlp_addr, retdest - %increment + INCR1 // stack: rlp_len, end_rlp_addr, start_rlp_addr, retdest SWAP2 %decrement // stack: prefix_start_rlp_addr, end_rlp_addr, rlp_len, retdest @@ -198,7 +196,7 @@ prepend_rlp_list_prefix_big: DUP1 DUP3 %add_const(0xf7) MSTORE_GENERAL // rlp[prefix_start_rlp_addr] = 0xf7 + len_of_len // stack: prefix_start_rlp_addr, len_of_len, payload_len, end_rlp_addr, start_rlp_addr, retdest - DUP1 %increment // start_len_rlp_addr = prefix_start_rlp_addr + 1 + DUP1 INCR1 // start_len_rlp_addr = prefix_start_rlp_addr + 1 %stack (start_len_rlp_addr, prefix_start_rlp_addr, len_of_len, payload_len, end_rlp_addr, start_rlp_addr, retdest) -> (start_len_rlp_addr, payload_len, len_of_len, prepend_rlp_list_prefix_big_done_writing_len, @@ -237,7 +235,7 @@ prepend_rlp_list_prefix_big_done_writing_len: // stack: scalar %num_bytes // stack: scalar_bytes - %increment // Account for the length prefix. + INCR1 // Account for the length prefix. // stack: rlp_len %%finish: %endmacro @@ -250,7 +248,7 @@ prepend_rlp_list_prefix_big_done_writing_len: // stack: is_large, payload_len %jumpi(%%large) // Small case; prefix is a single byte. - %increment + INCR1 // stack: 1 + payload_len %jump(%%finish) %%large: @@ -258,7 +256,7 @@ prepend_rlp_list_prefix_big_done_writing_len: // stack: payload_len DUP1 %num_bytes // stack: len_of_len, payload_len - %increment + INCR1 // stack: prefix_len, payload_len ADD %%finish: diff --git a/evm_arithmetization/src/cpu/kernel/asm/rlp/encode_rlp_scalar.asm b/evm_arithmetization/src/cpu/kernel/asm/rlp/encode_rlp_scalar.asm index d311a57eb..1cda0c16c 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/rlp/encode_rlp_scalar.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/rlp/encode_rlp_scalar.asm @@ -16,7 +16,7 @@ global encode_rlp_scalar: %stack (rlp_addr, scalar) -> (0x80, rlp_addr, rlp_addr) MSTORE_GENERAL // stack: rlp_addr, retdest - %increment + INCR1 // stack: rlp_addr', retdest SWAP1 JUMP @@ -50,11 +50,11 @@ global doubly_encode_rlp_scalar: %stack (rlp_addr, scalar) -> (0x81, rlp_addr, rlp_addr) MSTORE_GENERAL // stack: rlp_addr, retdest - %increment + INCR1 DUP1 PUSH 0x80 MSTORE_GENERAL // stack: rlp_addr, retdest - %increment + INCR1 // stack: rlp_addr, retdest SWAP1 JUMP @@ -80,7 +80,7 @@ encode_rlp_scalar_small: // stack: scalar, rlp_addr, rlp_addr, retdest MSTORE_GENERAL // stack: rlp_addr, retdest - %increment + INCR1 // stack: rlp_addr', retdest SWAP1 JUMP diff --git a/evm_arithmetization/src/cpu/kernel/asm/rlp/encode_rlp_string.asm b/evm_arithmetization/src/cpu/kernel/asm/rlp/encode_rlp_string.asm index 60174a943..66fe129ad 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/rlp/encode_rlp_string.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/rlp/encode_rlp_string.asm @@ -26,7 +26,7 @@ global encode_rlp_string_small: // stack: first_byte, rlp_addr, rlp_addr, ADDR, len, retdest MSTORE_GENERAL // stack: rlp_addr, ADDR, len, retdest - %increment + INCR1 // stack: rlp_addr', ADDR, len, retdest DUP3 DUP2 ADD // rlp_addr'' = rlp_addr' + len // stack: rlp_addr'', rlp_addr', ADDR, len, retdest @@ -42,7 +42,7 @@ global encode_rlp_string_small_single_byte: DUP2 SWAP1 MSTORE_GENERAL // stack: rlp_addr, retdest - %increment + INCR1 SWAP1 // stack: retdest, rlp_addr' JUMP @@ -59,7 +59,7 @@ global encode_rlp_string_large: // stack: first_byte, rlp_addr, rlp_addr, len_of_len, ADDR, len, retdest MSTORE_GENERAL // stack: rlp_addr, len_of_len, ADDR, len, retdest - %increment + INCR1 // stack: rlp_addr', len_of_len, ADDR, len, retdest %stack (rlp_addr, len_of_len, ADDR, len) -> (rlp_addr, len, len_of_len, encode_rlp_string_large_after_writing_len, ADDR, len) diff --git a/evm_arithmetization/src/cpu/kernel/asm/rlp/increment_bounded_rlp.asm b/evm_arithmetization/src/cpu/kernel/asm/rlp/increment_bounded_rlp.asm index 2f5f07500..12dc633e6 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/rlp/increment_bounded_rlp.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/rlp/increment_bounded_rlp.asm @@ -14,7 +14,7 @@ global increment_bounded_rlp: %jumpi(case_0x81ff) // If rlp_index != 0x80 and rlp_index != 0x7f and rlp_index != 0x81ff // we only need to add one and keep the number of nibbles - %increment + INCR1 %stack (next_rlp_index, next_num_nibbles, retdest) -> (retdest, next_rlp_index, next_num_nibbles) JUMP diff --git a/evm_arithmetization/src/cpu/kernel/asm/shift.asm b/evm_arithmetization/src/cpu/kernel/asm/shift.asm index ee9ccbfae..228054621 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/shift.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/shift.asm @@ -7,7 +7,7 @@ %rep 255 // stack: 2^i, addr_i dup2 - %increment + INCR1 // stack: addr_(i+1), 2^i, addr_i dup2 dup1 diff --git a/evm_arithmetization/src/cpu/kernel/asm/signed.asm b/evm_arithmetization/src/cpu/kernel/asm/signed.asm index a9e9e3648..d08ca2c56 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/signed.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/signed.asm @@ -100,7 +100,7 @@ global _sys_signextend: PUSH 31 %min // Stack: min(31, N), value, return_info - %increment + INCR1 %mul_const(8) // Stack: 8*(N + 1), value, return_info PUSH 256 diff --git a/evm_arithmetization/src/cpu/kernel/asm/transactions/common_decoding.asm b/evm_arithmetization/src/cpu/kernel/asm/transactions/common_decoding.asm index 6ee92ca2b..01d616ab2 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/transactions/common_decoding.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/transactions/common_decoding.asm @@ -300,7 +300,8 @@ sload_with_addr: // stack: hash, store_addr, store_addr, end_rlp_addr, rlp_addr MSTORE_GENERAL // stack: store_addr, end_rlp_addr, rlp_addr - %increment SWAP2 + SWAP2 + INCR3 // stack: rlp_addr, end_rlp_addr, store_addr' %jump(decode_and_store_blob_versioned_hashes_loop) decode_and_store_blob_versioned_hashes_finish: diff --git a/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm b/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm index eaef7efd7..8b4e58471 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/transactions/router.asm @@ -57,7 +57,7 @@ global update_txn_trie: // First we write txn rlp length DUP1 %append_to_trie_data // stack: txn_rlp_len, value_ptr, txn_counter, num_nibbles, ret_dest - DUP2 %increment + DUP2 INCR1 // stack: rlp_start=value_ptr+1, txn_rlp_len, value_ptr, txn_counter, num_nibbles, retdest // and now copy txn_rlp to the new block diff --git a/evm_arithmetization/src/cpu/kernel/asm/transactions/type_1.asm b/evm_arithmetization/src/cpu/kernel/asm/transactions/type_1.asm index 4000221f4..90006e99b 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/transactions/type_1.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/transactions/type_1.asm @@ -14,7 +14,7 @@ global process_type_1_txn: // stack: rlp_addr, retdest // Initial rlp address offset of 1 (skipping over the 0x01 byte) - %add_const(1) + INCR1 // stack: rlp_addr, retdest %decode_rlp_list_len // We don't actually need the length. @@ -62,7 +62,7 @@ type_1_compute_signed_data: // stack: rlp_addr, rlp_len, retdest // Hash the RLP + the leading `1` - SWAP1 %increment SWAP1 + INCR2 // stack: ADDR, len, retdest KECCAK_GENERAL // stack: hash, retdest diff --git a/evm_arithmetization/src/cpu/kernel/asm/transactions/type_2.asm b/evm_arithmetization/src/cpu/kernel/asm/transactions/type_2.asm index ba35b1402..a8818baf7 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/transactions/type_2.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/transactions/type_2.asm @@ -15,7 +15,7 @@ global process_type_2_txn: // stack: rlp_addr, retdest // Initial rlp address offset of 1 (skipping over the 0x02 byte) - %add_const(1) + INCR1 // stack: rlp_addr, retdest %decode_rlp_list_len // We don't actually need the length. @@ -65,7 +65,7 @@ type_2_compute_signed_data: // stack: rlp_addr, rlp_len, retdest // Hash the RLP + the leading `2` - SWAP1 %increment SWAP1 + INCR2 // stack: ADDR, len, retdest KECCAK_GENERAL // stack: hash, retdest diff --git a/evm_arithmetization/src/cpu/kernel/asm/transactions/type_3.asm b/evm_arithmetization/src/cpu/kernel/asm/transactions/type_3.asm index f84f95c7d..613839210 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/transactions/type_3.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/transactions/type_3.asm @@ -14,7 +14,7 @@ global process_type_3_txn: // stack: rlp_addr, retdest // Initial rlp address offset of 1 (skipping over the 0x03 byte) - %add_const(1) + INCR1 // stack: rlp_addr, retdest %decode_rlp_list_len // We don't actually need the length. @@ -65,7 +65,7 @@ type_3_compute_signed_data: // stack: rlp_addr, rlp_len, retdest // Hash the RLP + the leading `3` - SWAP1 %increment SWAP1 + INCR2 // stack: ADDR, len, retdest KECCAK_GENERAL // stack: hash, retdest diff --git a/evm_arithmetization/src/cpu/kernel/asm/util/basic_macros.asm b/evm_arithmetization/src/cpu/kernel/asm/util/basic_macros.asm index 657ee9760..9b1a958db 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/util/basic_macros.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/util/basic_macros.asm @@ -347,8 +347,8 @@ %as_u32 %endmacro -%macro increment - %add_const(1) +%macro increment_twice + INCR1 INCR1 %endmacro %macro decrement diff --git a/evm_arithmetization/src/cpu/kernel/asm/util/math.asm b/evm_arithmetization/src/cpu/kernel/asm/util/math.asm index 4bdf69023..8d7c723f1 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/util/math.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/util/math.asm @@ -7,9 +7,7 @@ log2_floor_helper: // stack: val, counter, retdest %div2 // stack: val/2, counter, retdest - SWAP1 - %increment - SWAP1 + INCR2 // stack: val/2, counter + 1, retdest %jump(log2_floor_helper) end: diff --git a/evm_arithmetization/src/cpu/kernel/opcodes.rs b/evm_arithmetization/src/cpu/kernel/opcodes.rs index 6491003f1..93802cb54 100644 --- a/evm_arithmetization/src/cpu/kernel/opcodes.rs +++ b/evm_arithmetization/src/cpu/kernel/opcodes.rs @@ -149,6 +149,10 @@ pub fn get_opcode(mnemonic: &str) -> u8 { "MSTORE_32BYTES_30" => 0xdd, "MSTORE_32BYTES_31" => 0xde, "MSTORE_32BYTES_32" => 0xdf, + "INCR1" => 0xe0, + "INCR2" => 0xe1, + "INCR3" => 0xe2, + "INCR4" => 0xe3, "PROVER_INPUT" => 0xee, "CREATE" => 0xf0, "CALL" => 0xf1, diff --git a/evm_arithmetization/src/cpu/mod.rs b/evm_arithmetization/src/cpu/mod.rs index 3d5124ba2..cd4c236c8 100644 --- a/evm_arithmetization/src/cpu/mod.rs +++ b/evm_arithmetization/src/cpu/mod.rs @@ -8,6 +8,7 @@ pub(crate) mod decode; mod dup_swap; mod gas; mod halt; +mod incr; mod jumps; pub mod kernel; pub(crate) mod membus; diff --git a/evm_arithmetization/src/cpu/stack.rs b/evm_arithmetization/src/cpu/stack.rs index e5b1682ad..d5851c841 100644 --- a/evm_arithmetization/src/cpu/stack.rs +++ b/evm_arithmetization/src/cpu/stack.rs @@ -39,6 +39,7 @@ pub(crate) const MIGHT_OVERFLOW: OpsColumnsView = OpsColumnsView { m_op_32bytes: false, exit_kernel: true, // Doesn't directly push, but the syscall it's returning from might. m_op_general: false, + incr: false, syscall: false, exception: false, }; @@ -164,6 +165,7 @@ pub(crate) const STACK_BEHAVIORS: OpsColumnsView> = OpsCol disable_other_channels: true, }), m_op_general: None, + incr: None, syscall: Some(StackBehavior { num_pops: 0, pushes: true, diff --git a/evm_arithmetization/src/generation/mod.rs b/evm_arithmetization/src/generation/mod.rs index a4994f686..1d82a1f4c 100644 --- a/evm_arithmetization/src/generation/mod.rs +++ b/evm_arithmetization/src/generation/mod.rs @@ -45,10 +45,10 @@ use crate::witness::util::mem_write_log; /// Number of cycles to go after having reached the halting state. It is /// equal to the number of cycles in `exc_stop` + 1. -pub const NUM_EXTRA_CYCLES_AFTER: usize = 82; +pub const NUM_EXTRA_CYCLES_AFTER: usize = 81; /// Number of cycles to go before starting the execution: it is the number of /// cycles in `init`. -pub const NUM_EXTRA_CYCLES_BEFORE: usize = 64; +pub const NUM_EXTRA_CYCLES_BEFORE: usize = 63; /// Memory values used to initialize `MemBefore`. pub type MemBeforeValues = Vec<(MemoryAddress, U256)>; diff --git a/evm_arithmetization/src/generation/state.rs b/evm_arithmetization/src/generation/state.rs index abe4b4f1a..96fa0bc90 100644 --- a/evm_arithmetization/src/generation/state.rs +++ b/evm_arithmetization/src/generation/state.rs @@ -232,7 +232,12 @@ pub(crate) trait State { } } else { if !running { - debug_assert!(self.get_clock() - final_clock == NUM_EXTRA_CYCLES_AFTER - 1); + debug_assert!( + self.get_clock() - final_clock == NUM_EXTRA_CYCLES_AFTER - 1, + "Got {:?}, expected {:?}", + self.get_clock() - final_clock, + NUM_EXTRA_CYCLES_AFTER - 1 + ); } let final_mem = self.get_active_memory(); #[cfg(not(test))] diff --git a/evm_arithmetization/src/witness/gas.rs b/evm_arithmetization/src/witness/gas.rs index 3a184d3d0..dcf9a67c3 100644 --- a/evm_arithmetization/src/witness/gas.rs +++ b/evm_arithmetization/src/witness/gas.rs @@ -53,6 +53,7 @@ pub(crate) const fn gas_to_charge(op: Operation) -> u64 { SetContext => KERNEL_ONLY_INSTR, Mload32Bytes => KERNEL_ONLY_INSTR, Mstore32Bytes(_) => KERNEL_ONLY_INSTR, + Incr(_) => KERNEL_ONLY_INSTR, ExitKernel => KERNEL_ONLY_INSTR, MloadGeneral => KERNEL_ONLY_INSTR, MstoreGeneral => KERNEL_ONLY_INSTR, diff --git a/evm_arithmetization/src/witness/operation.rs b/evm_arithmetization/src/witness/operation.rs index c8e2a5376..2e095cf41 100644 --- a/evm_arithmetization/src/witness/operation.rs +++ b/evm_arithmetization/src/witness/operation.rs @@ -19,7 +19,7 @@ use crate::cpu::simple_logic::eq_iszero::generate_pinv_diff; use crate::cpu::stack::MAX_USER_STACK_SIZE; use crate::extension_tower::BN_BASE; use crate::memory::segments::Segment; -use crate::util::u256_to_usize; +use crate::util::{u256_limbs, u256_to_usize}; use crate::witness::errors::MemoryError::VirtTooLarge; use crate::witness::errors::ProgramError; use crate::witness::memory::{MemoryAddress, MemoryChannel, MemoryOp, MemoryOpKind}; @@ -58,6 +58,7 @@ pub(crate) enum Operation { SetContext, Mload32Bytes, Mstore32Bytes(u8), + Incr(u8), ExitKernel, MloadGeneral, MstoreGeneral, @@ -597,6 +598,88 @@ pub(crate) fn generate_swap>( Ok(()) } +pub(crate) fn generate_incr>( + n: u8, + state: &mut T, + mut row: CpuColumnsView, +) -> Result<(), ProgramError> { + let generation_state = state.get_mut_generation_state(); + let offset = generation_state + .registers + .stack_len + .checked_sub(1 + (n as usize)) + .ok_or(ProgramError::StackUnderflow)?; + let addr = MemoryAddress::new(generation_state.registers.context, Segment::Stack, offset); + + let (in0, log_in0) = if n == 0 { + let val = generation_state.registers.stack_top; + let op = MemoryOp::new( + MemoryChannel::GeneralPurpose(1), + generation_state.traces.clock(), + addr, + MemoryOpKind::Read, + val, + ); + + let channel = &mut row.mem_channels[1]; + assert_eq!(channel.used, F::ZERO); + channel.used = F::ONE; + channel.is_read = F::ONE; + channel.addr_context = F::from_canonical_usize(addr.context); + channel.addr_segment = F::from_canonical_usize(addr.segment); + channel.addr_virtual = F::from_canonical_usize(addr.virt); + for (i, limb) in val.0.into_iter().enumerate() { + channel.value[2 * i] = F::from_canonical_u32(limb as u32); + channel.value[2 * i + 1] = F::from_canonical_u32((limb >> 32) as u32); + } + + (val, op) + } else { + mem_read_gp_with_log_and_fill(1, addr, &generation_state, &mut row) + }; + + // Write the read value, incremented by 1. + let log_out0 = mem_write_gp_log_and_fill(2, addr, generation_state, &mut row, in0 + 1); + + // Manually increment the top of the stack if calling INCR1. + if n == 0 { + generation_state.registers.stack_top += 1.into(); + } + state.push_memory(log_out0); + state.push_memory(log_in0); + + let in0_limbs = u256_limbs::(in0); + let out0_limbs = u256_limbs::(in0 + 1); + // This is necessary to properly constrain the increment over limbs without + // relying on the Arithmetic table. + for (i, limb) in row.general.incr_mut().limbs.iter_mut().enumerate() { + *limb = if in0_limbs[i] != out0_limbs[i] { + F::ONE + } else { + F::ZERO + } + } + // if n == 0 { + // println!( + // "TOP OF THE STACK: {:?}\n\t{:?}\n\t{:?}\n", + // row.general.incr().limbs, + // row.mem_channels[1], + // row.mem_channels[2], + // ); + // } else { + // println!( + // "REGULAR CHANNEL: {:?}\n\t{:?}\n\t{:?}\n", + // row.general.incr().limbs, + // row.mem_channels[1], + // row.mem_channels[2] + // ); + // } + + state.push_cpu(row); + + Ok(()) +} + pub(crate) fn generate_not>( state: &mut T, mut row: CpuColumnsView, diff --git a/evm_arithmetization/src/witness/transition.rs b/evm_arithmetization/src/witness/transition.rs index fdcf9af65..c2c6600c5 100644 --- a/evm_arithmetization/src/witness/transition.rs +++ b/evm_arithmetization/src/witness/transition.rs @@ -156,6 +156,7 @@ pub(crate) fn decode(registers: RegistersState, opcode: u8) -> Result Ok(Operation::Mstore32Bytes(opcode - 0xc0 + 1)), + (0xe0..=0xe3, true) => Ok(Operation::Incr(opcode & 0x3)), (0xee, true) => Ok(Operation::ProverInput), (0xf0, _) => Ok(Operation::Syscall(opcode, 3, false)), // CREATE (0xf1, _) => Ok(Operation::Syscall(opcode, 7, false)), // CALL @@ -202,6 +203,7 @@ pub(crate) fn fill_op_flag(op: Operation, row: &mut CpuColumnsView) Operation::Pc | Operation::Push(0) => &mut flags.pc_push0, Operation::GetContext | Operation::SetContext => &mut flags.context_op, Operation::Mload32Bytes | Operation::Mstore32Bytes(_) => &mut flags.m_op_32bytes, + Operation::Incr(_) => &mut flags.incr, Operation::ExitKernel => &mut flags.exit_kernel, Operation::MloadGeneral | Operation::MstoreGeneral => &mut flags.m_op_general, } = F::ONE; @@ -235,6 +237,7 @@ pub(crate) const fn get_op_special_length(op: Operation) -> Option { Operation::Jumpi => JUMPI_OP, Operation::GetContext | Operation::SetContext => None, Operation::Mload32Bytes | Operation::Mstore32Bytes(_) => STACK_BEHAVIORS.m_op_32bytes, + Operation::Incr(_) => STACK_BEHAVIORS.incr, Operation::ExitKernel => STACK_BEHAVIORS.exit_kernel, Operation::MloadGeneral | Operation::MstoreGeneral => STACK_BEHAVIORS.m_op_general, }; @@ -276,6 +279,7 @@ pub(crate) const fn might_overflow_op(op: Operation) -> bool { Operation::Pc | Operation::Push(0) => MIGHT_OVERFLOW.pc_push0, Operation::GetContext | Operation::SetContext => MIGHT_OVERFLOW.context_op, Operation::Mload32Bytes | Operation::Mstore32Bytes(_) => MIGHT_OVERFLOW.m_op_32bytes, + Operation::Incr(_) => MIGHT_OVERFLOW.incr, Operation::ExitKernel => MIGHT_OVERFLOW.exit_kernel, Operation::MloadGeneral | Operation::MstoreGeneral => MIGHT_OVERFLOW.m_op_general, } @@ -571,6 +575,7 @@ where Operation::SetContext => generate_set_context(self, row), Operation::Mload32Bytes => generate_mload_32bytes(self, row), Operation::Mstore32Bytes(n) => generate_mstore_32bytes(n, self, row), + Operation::Incr(n) => generate_incr(n, self, row), Operation::ExitKernel => generate_exit_kernel(self, row), Operation::MloadGeneral => generate_mload_general(self, row), Operation::MstoreGeneral => generate_mstore_general(self, row), From cca978f43bc99093eea6aaeea69f540169cb7961 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Thu, 26 Sep 2024 21:36:23 -0400 Subject: [PATCH 02/12] Bring back arith op --- .../src/cpu/columns/general.rs | 25 ------ evm_arithmetization/src/cpu/incr.rs | 88 +------------------ evm_arithmetization/src/witness/operation.rs | 31 +------ 3 files changed, 4 insertions(+), 140 deletions(-) diff --git a/evm_arithmetization/src/cpu/columns/general.rs b/evm_arithmetization/src/cpu/columns/general.rs index 067a810b9..97f8b8f49 100644 --- a/evm_arithmetization/src/cpu/columns/general.rs +++ b/evm_arithmetization/src/cpu/columns/general.rs @@ -15,7 +15,6 @@ pub(crate) union CpuGeneralColumnsView { shift: CpuShiftView, stack: CpuStackView, push: CpuPushView, - incr: CpuIncrView, context_pruning: CpuContextPruningView, } @@ -94,18 +93,6 @@ impl CpuGeneralColumnsView { unsafe { &mut self.push } } - /// View of the columns required for the incr operation. - /// SAFETY: Each view is a valid interpretation of the underlying array. - pub(crate) const fn incr(&self) -> &CpuIncrView { - unsafe { &self.incr } - } - - /// Mutable view of the columns required for the incr operation. - /// SAFETY: Each view is a valid interpretation of the underlying array. - pub(crate) fn incr_mut(&mut self) -> &mut CpuIncrView { - unsafe { &mut self.incr } - } - /// View of the column for context pruning. /// SAFETY: Each view is a valid interpretation of the underlying array. pub(crate) const fn context_pruning(&self) -> &CpuContextPruningView { @@ -230,17 +217,6 @@ pub(crate) struct CpuPushView { _padding_columns: [T; NUM_SHARED_COLUMNS - 1], } -/// View of all `CpuGeneralColumn`s, helping to detect any limb overflow -/// when incrementing by 1. -#[repr(C)] -#[derive(Copy, Clone)] -pub(crate) struct CpuIncrView { - /// If limb `i` is 1, then we overflowed the first `i-1` limbs when adding - /// 1 (i.e. they are now 0). This means limb `1` is incremented by 1, and - /// higher limbs remain unchanged. - pub(crate) limbs: [T; NUM_SHARED_COLUMNS], -} - /// View of the first `CpuGeneralColumn` storing a flag for context pruning. #[derive(Copy, Clone)] pub(crate) struct CpuContextPruningView { @@ -267,5 +243,4 @@ const_assert!(size_of::>() == NUM_SHARED_COLUMNS); const_assert!(size_of::>() == NUM_SHARED_COLUMNS); const_assert!(size_of::>() == NUM_SHARED_COLUMNS); const_assert!(size_of::>() == NUM_SHARED_COLUMNS); -const_assert!(size_of::>() == NUM_SHARED_COLUMNS); const_assert!(size_of::>() == NUM_SHARED_COLUMNS); diff --git a/evm_arithmetization/src/cpu/incr.rs b/evm_arithmetization/src/cpu/incr.rs index 9a6ae551e..daeaddfd3 100644 --- a/evm_arithmetization/src/cpu/incr.rs +++ b/evm_arithmetization/src/cpu/incr.rs @@ -1,4 +1,3 @@ -use itertools::izip; use plonky2::field::extension::Extendable; use plonky2::field::packed::PackedField; use plonky2::hash::hash_types::RichField; @@ -6,74 +5,13 @@ use plonky2::iop::ext_target::ExtensionTarget; use plonky2::plonk::circuit_builder::CircuitBuilder; use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; -use crate::cpu::columns::{CpuColumnsView, MemoryChannelView}; -use crate::memory::VALUE_LIMBS; - -/// Constrain two channels such that their values `A` and `B` satisfy -/// `B = A + 1`, by using the `CpuIncrView` helper limbs. -fn channels_incremented_packed( - filter: P, - ch_a: &MemoryChannelView

, - ch_b: &MemoryChannelView

, - helper_limbs: [P; VALUE_LIMBS], - yield_constr: &mut ConstraintConsumer

, -) { - for (limb_a, limb_b, helper) in izip!(ch_a.value, ch_b.value, helper_limbs) { - // If there was an overflow on the current limb, `limb_b` will be 0, else - // we enforce proper increment. - yield_constr.constraint(filter * limb_b * (limb_b - limb_a - helper)); - } -} - -/// Constrain two channels such that their values `A` and `B` satisfy -/// `B = A + 1`, by using the `CpuIncrView` helper limbs. -fn channels_incremented_circuit, const D: usize>( - builder: &mut CircuitBuilder, - filter: ExtensionTarget, - ch_a: &MemoryChannelView>, - ch_b: &MemoryChannelView>, - helper_limbs: [ExtensionTarget; VALUE_LIMBS], - yield_constr: &mut RecursiveConstraintConsumer, -) { - for (limb_a, limb_b, helper) in izip!(ch_a.value, ch_b.value, helper_limbs) { - // If there was an overflow on the current limb, `limb_b` will be 0, else - // we enforce proper increment. - let diff = builder.sub_extension(limb_b, limb_a); - let diff = builder.sub_extension(diff, helper); - let constr = builder.mul_extension(limb_b, diff); - let constr = builder.mul_extension(filter, constr); - yield_constr.constraint(builder, constr); - } -} +use crate::cpu::columns::CpuColumnsView; /// Evaluates the constraints for the DUP and SWAP opcodes. pub(crate) fn eval_packed( lv: &CpuColumnsView

, yield_constr: &mut ConstraintConsumer

, ) { - // Constrain the helper columns. - { - // First limb is always 1. - yield_constr.constraint(lv.op.incr * (lv.general.incr().limbs[0] - P::ONES)); - - // 1s and 0s must be contiguous - for i in 1..VALUE_LIMBS - 1 { - yield_constr.constraint( - lv.op.incr - * (lv.general.incr().limbs[i] - P::ONES) - * lv.general.incr().limbs[i + 1], - ); - } - } - - channels_incremented_packed( - lv.op.incr, - &lv.mem_channels[1], - &lv.mem_channels[2], - lv.general.incr().limbs, - yield_constr, - ); - // Disable the partial channel. yield_constr.constraint(lv.op.incr * lv.partial_channel.used); } @@ -85,30 +23,6 @@ pub(crate) fn eval_ext_circuit, const D: usize>( lv: &CpuColumnsView>, yield_constr: &mut RecursiveConstraintConsumer, ) { - // Constrain the helper columns. - { - // First limb is always 1. - let constr = builder.mul_sub_extension(lv.op.incr, lv.general.incr().limbs[0], lv.op.incr); - yield_constr.constraint(builder, constr); - - // 1s and 0s must be contiguous - for i in 1..VALUE_LIMBS - 1 { - let constr = - builder.mul_sub_extension(lv.op.incr, lv.general.incr().limbs[i], lv.op.incr); - let constr = builder.mul_extension(constr, lv.general.incr().limbs[i + 1]); - yield_constr.constraint(builder, constr); - } - } - - channels_incremented_circuit( - builder, - lv.op.incr, - &lv.mem_channels[1], - &lv.mem_channels[2], - lv.general.incr().limbs, - yield_constr, - ); - // Disable the partial channel. { let constr = builder.mul_extension(lv.op.incr, lv.partial_channel.used); diff --git a/evm_arithmetization/src/witness/operation.rs b/evm_arithmetization/src/witness/operation.rs index 2e095cf41..d89c625c7 100644 --- a/evm_arithmetization/src/witness/operation.rs +++ b/evm_arithmetization/src/witness/operation.rs @@ -19,7 +19,7 @@ use crate::cpu::simple_logic::eq_iszero::generate_pinv_diff; use crate::cpu::stack::MAX_USER_STACK_SIZE; use crate::extension_tower::BN_BASE; use crate::memory::segments::Segment; -use crate::util::{u256_limbs, u256_to_usize}; +use crate::util::u256_to_usize; use crate::witness::errors::MemoryError::VirtTooLarge; use crate::witness::errors::ProgramError; use crate::witness::memory::{MemoryAddress, MemoryChannel, MemoryOp, MemoryOpKind}; @@ -648,33 +648,8 @@ pub(crate) fn generate_incr>( state.push_memory(log_out0); state.push_memory(log_in0); - let in0_limbs = u256_limbs::(in0); - let out0_limbs = u256_limbs::(in0 + 1); - // This is necessary to properly constrain the increment over limbs without - // relying on the Arithmetic table. - for (i, limb) in row.general.incr_mut().limbs.iter_mut().enumerate() { - *limb = if in0_limbs[i] != out0_limbs[i] { - F::ONE - } else { - F::ZERO - } - } - // if n == 0 { - // println!( - // "TOP OF THE STACK: {:?}\n\t{:?}\n\t{:?}\n", - // row.general.incr().limbs, - // row.mem_channels[1], - // row.mem_channels[2], - // ); - // } else { - // println!( - // "REGULAR CHANNEL: {:?}\n\t{:?}\n\t{:?}\n", - // row.general.incr().limbs, - // row.mem_channels[1], - // row.mem_channels[2] - // ); - // } - + let operation = arithmetic::Operation::binary(BinaryOperator::Add, in0, U256::one()); + state.push_arithmetic(operation); state.push_cpu(row); Ok(()) From 1270181cd5b41bb4624697435f3c6bcf6209aef9 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Thu, 17 Oct 2024 11:57:08 -0400 Subject: [PATCH 03/12] Tweak --- evm_arithmetization/src/witness/operation.rs | 37 ++++---------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/evm_arithmetization/src/witness/operation.rs b/evm_arithmetization/src/witness/operation.rs index d89c625c7..cd5fcf35b 100644 --- a/evm_arithmetization/src/witness/operation.rs +++ b/evm_arithmetization/src/witness/operation.rs @@ -562,6 +562,7 @@ pub(crate) fn generate_dup>( } else { mem_read_gp_with_log_and_fill(2, other_addr, generation_state, &mut row) }; + push_no_write(generation_state, val); state.push_memory(log_push); state.push_memory(log_read); @@ -611,44 +612,20 @@ pub(crate) fn generate_incr>( .ok_or(ProgramError::StackUnderflow)?; let addr = MemoryAddress::new(generation_state.registers.context, Segment::Stack, offset); - let (in0, log_in0) = if n == 0 { - let val = generation_state.registers.stack_top; - let op = MemoryOp::new( - MemoryChannel::GeneralPurpose(1), - generation_state.traces.clock(), - addr, - MemoryOpKind::Read, - val, - ); - - let channel = &mut row.mem_channels[1]; - assert_eq!(channel.used, F::ZERO); - channel.used = F::ONE; - channel.is_read = F::ONE; - channel.addr_context = F::from_canonical_usize(addr.context); - channel.addr_segment = F::from_canonical_usize(addr.segment); - channel.addr_virtual = F::from_canonical_usize(addr.virt); - for (i, limb) in val.0.into_iter().enumerate() { - channel.value[2 * i] = F::from_canonical_u32(limb as u32); - channel.value[2 * i + 1] = F::from_canonical_u32((limb >> 32) as u32); - } - - (val, op) - } else { - mem_read_gp_with_log_and_fill(1, addr, &generation_state, &mut row) - }; + let (val, log_in0) = mem_read_gp_with_log_and_fill(1, addr, &generation_state, &mut row); + let new_val = val.overflowing_add(1.into()).0; // Write the read value, incremented by 1. - let log_out0 = mem_write_gp_log_and_fill(2, addr, generation_state, &mut row, in0 + 1); + let log_out0 = mem_write_gp_log_and_fill(2, addr, generation_state, &mut row, new_val); // Manually increment the top of the stack if calling INCR1. if n == 0 { - generation_state.registers.stack_top += 1.into(); + generation_state.registers.stack_top += U256::one(); } - state.push_memory(log_out0); state.push_memory(log_in0); + state.push_memory(log_out0); - let operation = arithmetic::Operation::binary(BinaryOperator::Add, in0, U256::one()); + let operation = arithmetic::Operation::binary(BinaryOperator::Add, val, U256::one()); state.push_arithmetic(operation); state.push_cpu(row); From c69d9e93b961f9e19244ce62bf1f407bcd03011e Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Thu, 17 Oct 2024 13:32:07 -0400 Subject: [PATCH 04/12] Add CTLs --- evm_arithmetization/src/all_stark.rs | 4 ++- evm_arithmetization/src/cpu/cpu_stark.rs | 34 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/evm_arithmetization/src/all_stark.rs b/evm_arithmetization/src/all_stark.rs index 0be307db5..ac9dd2ff7 100644 --- a/evm_arithmetization/src/all_stark.rs +++ b/evm_arithmetization/src/all_stark.rs @@ -159,8 +159,10 @@ pub(crate) fn all_cross_table_lookups() -> Vec> { /// `CrossTableLookup` for `ArithmeticStark`, to connect it with the `Cpu` /// module. fn ctl_arithmetic() -> CrossTableLookup { + let cpu_arithmetic_looking = cpu_stark::ctl_arithmetic_base_rows(); + let cpu_increment_looking = cpu_stark::ctl_arithmetic_incr_op(); CrossTableLookup::new( - vec![cpu_stark::ctl_arithmetic_base_rows()], + vec![cpu_arithmetic_looking, cpu_increment_looking], arithmetic_stark::ctl_arithmetic_rows(), ) } diff --git a/evm_arithmetization/src/cpu/cpu_stark.rs b/evm_arithmetization/src/cpu/cpu_stark.rs index 74cbd97ae..43e73cec6 100644 --- a/evm_arithmetization/src/cpu/cpu_stark.rs +++ b/evm_arithmetization/src/cpu/cpu_stark.rs @@ -16,6 +16,7 @@ use starky::stark::Stark; use super::columns::CpuColumnsView; use super::kernel::constants::context_metadata::ContextMetadata; +use super::kernel::opcodes::get_opcode; use super::membus::{NUM_CHANNELS, NUM_GP_CHANNELS}; use crate::all_stark::{EvmStarkFrame, Table}; use crate::cpu::columns::{COL_MAP, NUM_CPU_COLUMNS}; @@ -130,6 +131,39 @@ pub(crate) fn ctl_arithmetic_base_rows() -> TableWithColumns { ) } +/// Returns the `TableWithColumns` for the CPU rows calling arithmetic +/// `ADD` operations through the `INCR` privileged instructions. +pub(crate) fn ctl_arithmetic_incr_op() -> TableWithColumns { + // Instead of taking single columns, we reconstruct the entire opcode value + // directly. + let mut columns = vec![Column::constant(F::from_canonical_u8(get_opcode("ADD")))]; + + // Read value + columns.extend(Column::singles(COL_MAP.mem_channels[1].value)); + + // Fixed second operand (`U256::one()`) + { + columns.push(Column::constant(F::ONE)); + for _ in 1..VALUE_LIMBS { + columns.push(Column::constant(F::ZERO)); + } + } + + // Ignored third operand, `ADD` is a binary operation + for _ in 0..VALUE_LIMBS { + columns.push(Column::constant(F::ZERO)); + } + + // Returned value + columns.extend(Column::singles(COL_MAP.mem_channels[2].value)); + + TableWithColumns::new( + *Table::Cpu, + columns, + Filter::new_simple(Column::single(COL_MAP.op.incr)), + ) +} + /// Returns a column containing stale contexts. pub(crate) fn ctl_context_pruning_looked() -> TableWithColumns { TableWithColumns::new( From b99ed9c0609a26122d22108a3352557f612feba3 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Thu, 17 Oct 2024 15:14:12 -0400 Subject: [PATCH 05/12] Reduce memory --- Cargo.toml | 3 +++ evm_arithmetization/src/cpu/kernel/asm/util/basic_macros.asm | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 3b038ff26..d816cdf99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,3 +118,6 @@ starky = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "2488cdac [workspace.lints.clippy] too_long_first_doc_paragraph = "allow" + +[profile.release] +debug-assertions = true \ No newline at end of file diff --git a/evm_arithmetization/src/cpu/kernel/asm/util/basic_macros.asm b/evm_arithmetization/src/cpu/kernel/asm/util/basic_macros.asm index 9b1a958db..c8ceb8df8 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/util/basic_macros.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/util/basic_macros.asm @@ -348,7 +348,7 @@ %endmacro %macro increment_twice - INCR1 INCR1 + %add_const(2) %endmacro %macro decrement From 89caabf62118239209b27790febb041ccb07a050 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Thu, 17 Oct 2024 15:28:33 -0400 Subject: [PATCH 06/12] Remove profile --- Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d816cdf99..3b038ff26 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,6 +118,3 @@ starky = { git = "https://github.com/0xPolygonZero/plonky2.git", rev = "2488cdac [workspace.lints.clippy] too_long_first_doc_paragraph = "allow" - -[profile.release] -debug-assertions = true \ No newline at end of file From a848075a635ce020442190f087bcf8bc7e8d1e2e Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Fri, 18 Oct 2024 11:25:34 -0400 Subject: [PATCH 07/12] Add CPU constraints --- evm_arithmetization/src/cpu/cpu_stark.rs | 4 +-- evm_arithmetization/src/cpu/dup_swap.rs | 4 +-- evm_arithmetization/src/cpu/incr.rs | 45 ++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/evm_arithmetization/src/cpu/cpu_stark.rs b/evm_arithmetization/src/cpu/cpu_stark.rs index 43e73cec6..33955eeaf 100644 --- a/evm_arithmetization/src/cpu/cpu_stark.rs +++ b/evm_arithmetization/src/cpu/cpu_stark.rs @@ -645,7 +645,7 @@ impl, const D: usize> Stark for CpuStark, const D: usize> Stark for CpuStark, const D: usize>( /// /// `offset` is the stack index before this instruction is executed, e.g. `0` /// for the top of the stack. -fn constrain_channel_packed( +pub(crate) fn constrain_channel_packed( is_read: bool, filter: P, offset: P, @@ -64,7 +64,7 @@ fn constrain_channel_packed( /// /// `offset` is the stack index before this instruction is executed, e.g. `0` /// for the top of the stack. -fn constrain_channel_ext_circuit, const D: usize>( +pub(crate) fn constrain_channel_ext_circuit, const D: usize>( builder: &mut CircuitBuilder, is_read: bool, filter: ExtensionTarget, diff --git a/evm_arithmetization/src/cpu/incr.rs b/evm_arithmetization/src/cpu/incr.rs index daeaddfd3..9104a7c62 100644 --- a/evm_arithmetization/src/cpu/incr.rs +++ b/evm_arithmetization/src/cpu/incr.rs @@ -1,19 +1,39 @@ use plonky2::field::extension::Extendable; use plonky2::field::packed::PackedField; +use plonky2::field::types::Field; use plonky2::hash::hash_types::RichField; use plonky2::iop::ext_target::ExtensionTarget; use plonky2::plonk::circuit_builder::CircuitBuilder; use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; +use super::dup_swap::{constrain_channel_ext_circuit, constrain_channel_packed}; use crate::cpu::columns::CpuColumnsView; /// Evaluates the constraints for the DUP and SWAP opcodes. pub(crate) fn eval_packed( lv: &CpuColumnsView

, + nv: &CpuColumnsView

, yield_constr: &mut ConstraintConsumer

, ) { + let filter = lv.op.incr; + + let n = lv.opcode_bits[0] + + lv.opcode_bits[1] * P::Scalar::from_canonical_u64(2) + + lv.opcode_bits[2] * P::Scalar::from_canonical_u64(4); + // Disable the partial channel. yield_constr.constraint(lv.op.incr * lv.partial_channel.used); + + // Constrain the input channel's address, `is_read` and `used` fields. + let read_channel = &lv.mem_channels[1]; + constrain_channel_packed(true, filter, n, read_channel, lv, yield_constr); + + // Constrain the output channel's address, `is_read` and `used` fields. + let write_channel = &lv.mem_channels[2]; + constrain_channel_packed(false, filter, n, write_channel, lv, yield_constr); + + // Constrain the unchanged stack len. + yield_constr.constraint_transition(filter * (nv.stack_len - lv.stack_len)); } /// Circuit version of `eval_packed`. @@ -21,11 +41,36 @@ pub(crate) fn eval_packed( pub(crate) fn eval_ext_circuit, const D: usize>( builder: &mut CircuitBuilder, lv: &CpuColumnsView>, + nv: &CpuColumnsView>, yield_constr: &mut RecursiveConstraintConsumer, ) { + let filter = lv.op.incr; + + let n = lv.opcode_bits[..3].iter().enumerate().fold( + builder.zero_extension(), + |cumul, (i, &bit)| { + builder.mul_const_add_extension(F::from_canonical_u64(1 << i), bit, cumul) + }, + ); + // Disable the partial channel. { let constr = builder.mul_extension(lv.op.incr, lv.partial_channel.used); yield_constr.constraint(builder, constr); } + + // Constrain the input channel's address, `is_read` and `used` fields. + let read_channel = &lv.mem_channels[1]; + constrain_channel_ext_circuit(builder, true, filter, n, read_channel, lv, yield_constr); + + // Constrain the output channel's address, `is_read` and `used` fields. + let write_channel = &lv.mem_channels[2]; + constrain_channel_ext_circuit(builder, false, filter, n, write_channel, lv, yield_constr); + + // Constrain the unchanged stack len. + { + let diff = builder.sub_extension(nv.stack_len, lv.stack_len); + let constr = builder.mul_extension(filter, diff); + yield_constr.constraint_transition(builder, constr); + } } From b45751c78f03a1d4e5ff75839fbe1f00045e4d24 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Fri, 18 Oct 2024 12:05:43 -0400 Subject: [PATCH 08/12] Update doc --- .../cpu_execution/privileged_instructions.md | 19 ++++++++++++------- evm_arithmetization/src/witness/operation.rs | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/book/src/cpu_execution/privileged_instructions.md b/book/src/cpu_execution/privileged_instructions.md index af613346c..8451e53cf 100644 --- a/book/src/cpu_execution/privileged_instructions.md +++ b/book/src/cpu_execution/privileged_instructions.md @@ -50,17 +50,22 @@ ecPairing precompiles. resetting memory sections (by calling MSTORE_32BYTES_32 with the value 0). -7. `PROVER_INPUT`. Pushes a single prover input onto the stack. +7. `INCR`. Reads the `N`th element of the stack, and increments it in-place + by one without pushing or popping. There are 4 INCR operations, namely + INCR1, INCR2, INCR3, INCR4 to increment respectively the 1st, 2nd, 3rd + and 4th stack elements. -8. `GET_CONTEXT`. Pushes the current context onto the stack. The kernel +8. `PROVER_INPUT`. Pushes a single prover input onto the stack. + +9. `GET_CONTEXT`. Pushes the current context onto the stack. The kernel always has context 0. -9. `SET_CONTEXT`. Pops the top element of the stack and updates the +10. `SET_CONTEXT`. Pops the top element of the stack and updates the current context to this value. It is usually used when calling another contract or precompile, to distinguish the caller from the callee. -10. `MLOAD_32BYTES`. Pops 2 elements from the stack (a Memory address, +11. `MLOAD_32BYTES`. Pops 2 elements from the stack (a Memory address, and then a length $\ell$), and pushes a value onto the stack. The pushed value corresponds to the U256 integer read from the big-endian sequence of length $\ell$ from the memory address being @@ -68,19 +73,19 @@ ecPairing precompiles. greater than 32 (as a U256 consists in at most 32 bytes). Missing these conditions will result in an unverifiable proof. -11. `EXIT_KERNEL`. Pops 1 element from the stack. This instruction is +12. `EXIT_KERNEL`. Pops 1 element from the stack. This instruction is used at the end of a syscall, before proceeding to the rest of the execution logic. The popped element, *kexit_info*, contains several pieces of information like the current program counter, the current amount of gas used, and whether we are in kernel (i.e. privileged) mode or not. -12. `MLOAD_GENERAL`. Pops 1 elements (a Memory address), and pushes the +13. `MLOAD_GENERAL`. Pops 1 elements (a Memory address), and pushes the value stored at this memory address onto the stack. It can read any memory location, general (similarly to MLOAD (0x51) instruction) or privileged. -13. `MSTORE_GENERAL`. Pops 2 elements (a value and a Memory address), +14. `MSTORE_GENERAL`. Pops 2 elements (a value and a Memory address), and writes the popped value from the stack at the fetched address. It can write to any memory location, general (similarly to MSTORE (0x52) / MSTORE8 (0x53) instructions) or privileged. diff --git a/evm_arithmetization/src/witness/operation.rs b/evm_arithmetization/src/witness/operation.rs index cd5fcf35b..7561a22c7 100644 --- a/evm_arithmetization/src/witness/operation.rs +++ b/evm_arithmetization/src/witness/operation.rs @@ -612,7 +612,7 @@ pub(crate) fn generate_incr>( .ok_or(ProgramError::StackUnderflow)?; let addr = MemoryAddress::new(generation_state.registers.context, Segment::Stack, offset); - let (val, log_in0) = mem_read_gp_with_log_and_fill(1, addr, &generation_state, &mut row); + let (val, log_in0) = mem_read_gp_with_log_and_fill(1, addr, generation_state, &mut row); let new_val = val.overflowing_add(1.into()).0; // Write the read value, incremented by 1. From f444249a32a7f74e204da113c6e9f931713973e2 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Fri, 18 Oct 2024 12:11:08 -0400 Subject: [PATCH 09/12] Remove macro --- .../src/cpu/kernel/asm/core/access_lists.asm | 2 +- .../src/cpu/kernel/asm/core/exception.asm | 2 +- .../src/cpu/kernel/asm/core/util.asm | 2 +- .../curve/bn254/curve_arithmetic/miller_loop.asm | 4 ++-- .../asm/curve/bn254/curve_arithmetic/pairing.asm | 2 +- .../bn254/field_arithmetic/degree_12_mul.asm | 4 ++-- .../asm/curve/bn254/field_arithmetic/util.asm | 16 ++++++++-------- .../asm/curve/secp256k1/precomputation.asm | 2 +- .../src/cpu/kernel/asm/hash/blake2/addresses.asm | 2 +- .../cpu/kernel/asm/hash/blake2/compression.asm | 2 +- .../src/cpu/kernel/asm/hash/sha2/compression.asm | 2 +- .../kernel/asm/hash/sha2/message_schedule.asm | 2 +- .../src/cpu/kernel/asm/journal/journal.asm | 6 +++--- .../asm/journal/transient_storage_change.asm | 2 +- evm_arithmetization/src/cpu/kernel/asm/main.asm | 2 +- .../src/cpu/kernel/asm/memory/core.asm | 2 +- .../src/cpu/kernel/asm/memory/packing.asm | 4 ++-- .../cpu/kernel/asm/memory/transient_storage.asm | 2 +- .../cpu/kernel/asm/mpt/delete/delete_branch.asm | 4 ++-- .../kernel/asm/mpt/delete/delete_extension.asm | 12 ++++++------ .../src/cpu/kernel/asm/mpt/hash/hash.asm | 4 ++-- .../kernel/asm/mpt/hash/hash_trie_specific.asm | 6 +++--- .../src/cpu/kernel/asm/mpt/hex_prefix.asm | 2 +- .../kernel/asm/mpt/insert/insert_extension.asm | 2 +- .../cpu/kernel/asm/mpt/insert/insert_leaf.asm | 4 ++-- .../kernel/asm/mpt/linked_list/final_tries.asm | 10 +++++----- .../kernel/asm/mpt/linked_list/initial_tries.asm | 6 +++--- .../kernel/asm/mpt/linked_list/linked_list.asm | 10 +++++----- .../src/cpu/kernel/asm/mpt/read.asm | 4 ++-- .../src/cpu/kernel/asm/util/basic_macros.asm | 4 ---- 30 files changed, 62 insertions(+), 66 deletions(-) diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/access_lists.asm b/evm_arithmetization/src/cpu/kernel/asm/core/access_lists.asm index 539334462..d884e3e10 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/access_lists.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/access_lists.asm @@ -277,7 +277,7 @@ global insert_accessed_storage_keys: storage_key_found: // The address was already in the list // stack: pred_ptr, addr, key, retdest - %increment_twice + %add_const(2) %stack (value_ptr, addr, key, retdest) -> (retdest, 0, value_ptr) // Return 0 to indicate that the address was already present. JUMP diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm b/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm index e2f28fc4b..1de3eac3f 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm @@ -184,7 +184,7 @@ global exc_stop: SUB // First, check the stack length. // stack: stack_len-3 = stack_len_before_exc, addr_registers, trap_info - DUP2 %increment_twice + DUP2 %add_const(2) MLOAD_GENERAL // stack: stored_stack_length, stack_len_before_exc, addr_registers, trap_info DUP2 %assert_eq diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/util.asm b/evm_arithmetization/src/cpu/kernel/asm/core/util.asm index c8ad59b87..17042786d 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/util.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/util.asm @@ -73,7 +73,7 @@ INCR1 DUP1 %mload_trie_data // stack: balance, balance_ptr ISZERO %not_bit %jumpi(%%false) - %increment_twice %mload_trie_data + %add_const(2) %mload_trie_data // stack: code_hash PUSH @EMPTY_STRING_HASH EQ diff --git a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/miller_loop.asm b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/miller_loop.asm index 890640e5c..70420bd8d 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/miller_loop.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/miller_loop.asm @@ -198,7 +198,7 @@ after_add: // stack: py^2 - 9, addr12, addr12, px, py, qx, qx_, qy, qy_ MSTORE_GENERAL // stack: addr12, px, py, qx, qx_, qy, qy_ - %increment_twice DUP1 + %add_const(2) DUP1 SWAP2 DUP1 MULFP254 @@ -295,7 +295,7 @@ after_add: PUSH 12 %create_bn254_pairing_address // stack: addr12 - DUP1 %increment_twice + DUP1 %add_const(2) // stack: addr14, addr12 DUP1 INCR1 // stack: addr15, addr14, addr12 diff --git a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/pairing.asm b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/pairing.asm index 934840310..b1bd2f835 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/pairing.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/pairing.asm @@ -64,7 +64,7 @@ bn254_input_check: // stack: inp_j, j, k, inp DUP1 // stack: inp_j , inp_j, j, k, inp - %increment_twice + %add_const(2) // stack: inp_j', inp_j, j, k, inp %load_fp254_4 // stack: Q_j, inp_j, j, k, inp diff --git a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/degree_12_mul.asm b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/degree_12_mul.asm index 1975d396c..45016ed15 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/degree_12_mul.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/degree_12_mul.asm @@ -177,7 +177,7 @@ global mul_fp254_12_sparse: // stack: G2 * sh2(f') + g0 * f, inB, f, inB, f', out, f, inB, f', inA, inB, out %stack (f: 6, x, g: 6) -> (g, x, f) // stack: f , inB, G2 * sh2(f') + g0 * f, inB, f', out, f, inB, f', inA, inB, out - DUP7 %increment_twice + DUP7 %add_const(2) // stack: inB1, f , inB, G2 * sh2(f') + g0 * f, inB, f', out, f, inB, f', inA, inB, out %load_fp254_2 // stack: G1 , f , inB, G2 * sh2(f') + g0 * f, inB, f', out, f, inB, f', inA, inB, out @@ -207,7 +207,7 @@ global mul_fp254_12_sparse: %stack (f: 6, x, g: 6) -> (g, x, f) // stack: f' , inB, G2 * sh(f) + g0 * f', inA, inB, out DUP7 - %increment_twice + %add_const(2) // stack: inB1, f' , inB, G2 * sh(f) + g0 * f', inA, inB, out %load_fp254_2 // stack: G1 , f' , inB, G2 * sh(f) + g0 * f', inA, inB, out diff --git a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/util.asm b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/util.asm index 4cd4499aa..cb261e735 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/util.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/curve/bn254/field_arithmetic/util.asm @@ -180,7 +180,7 @@ // stack: ptr %create_bn254_pairing_address DUP1 - %increment_twice + %add_const(2) // stack: addr2, addr MLOAD_GENERAL // stack: x2, addr @@ -216,7 +216,7 @@ MLOAD_GENERAL // stack: x3, x4, addr DUP3 - %increment_twice + %add_const(2) // stack: addr2, x3, x4, addr MLOAD_GENERAL // stack: x2, x3, x4, addr @@ -263,7 +263,7 @@ %swap_mstore // stack: x2, x3, addr, x5 DUP3 - %increment_twice + %add_const(2) // stack: addr2, x2, x3, addr, x5 %swap_mstore // stack: x3, addr, x5 @@ -310,7 +310,7 @@ MULFP254 // stack: 2*x2, x3, x4, addr DUP4 - %increment_twice + %add_const(2) // stack: addr2, 2*x2, x3, x4, addr %swap_mstore // stack: x3, x4, addr @@ -345,7 +345,7 @@ PUSH $ptr %create_bn254_pairing_address // stack: addr, x0, x1, x2, x3, x4, x5 - %increment_twice + %add_const(2) DUP1 // stack: addr2, addr2, x0, x1, x2, x3, x4, x5 SWAP2 MSTORE_GENERAL @@ -991,7 +991,7 @@ MLOAD_GENERAL // stack: x03, x04, x05, x06, x07, x08, x09, x10, addr DUP9 - %increment_twice + %add_const(2) // stack: addr02, x03, x04, x05, x06, x07, x08, x09, x10, addr MLOAD_GENERAL // stack: x02, x03, x04, x05, x06, x07, x08, x09, x10, addr @@ -1108,12 +1108,12 @@ %swap_mstore // stack: SRC, DEST DUP1 - %increment_twice + %add_const(2) // stack: addr02, SRC, DEST MLOAD_GENERAL // stack: x02, SRC, DEST DUP3 - %increment_twice + %add_const(2) // stack: addr02', x02, SRC, DEST %swap_mstore // stack: SRC, DEST diff --git a/evm_arithmetization/src/cpu/kernel/asm/curve/secp256k1/precomputation.asm b/evm_arithmetization/src/cpu/kernel/asm/curve/secp256k1/precomputation.asm index 95843e855..314c85e7c 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/curve/secp256k1/precomputation.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/curve/secp256k1/precomputation.asm @@ -65,7 +65,7 @@ precompute_table_loop_contd2: precompute_table_loop_contd3: %stack (Rx, Ry, i, retdest) -> (i, 24, Rx, i, 25, Ry, i, retdest) ADD %mstore_current(@SEGMENT_ECDSA_TABLE) ADD %mstore_current(@SEGMENT_ECDSA_TABLE) - %increment_twice + %add_const(2) DUP1 %eq_const(8) %jumpi(precompute_table_end) %jump(precompute_table_loop) diff --git a/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/addresses.asm b/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/addresses.asm index f2efa2b7c..3244cfa1f 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/addresses.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/addresses.asm @@ -7,7 +7,7 @@ MLOAD_GENERAL // stack: num_blocks, addr %block_size - %increment_twice + %add_const(2) // stack: num_bytes+2, addr ADD // stack: addr diff --git a/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/compression.asm b/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/compression.asm index a63901204..5f71c3c9c 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/compression.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/hash/blake2/compression.asm @@ -60,7 +60,7 @@ compression_loop: DUP1 // stack: cur_block, cur_block, t, is_last_block, retdest %block_size - %increment_twice + %add_const(2) // stack: cur_block_start_byte, t, cur_block, is_last_block, retdest // Copy the message from the input space to the message working space. diff --git a/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/compression.asm b/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/compression.asm index aaa50be61..5225a8623 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/compression.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/compression.asm @@ -3,7 +3,7 @@ %macro scratch_space_addr_from_num_blocks // stack: num_blocks %mul_const(320) - %increment_twice + %add_const(2) %build_current_general_address %endmacro diff --git a/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/message_schedule.asm b/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/message_schedule.asm index 21f96e813..ecbe0ab11 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/message_schedule.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/hash/sha2/message_schedule.asm @@ -2,7 +2,7 @@ %macro message_schedule_addr_from_num_blocks // stack: num_blocks %mul_const(64) - %increment_twice + %add_const(2) %build_current_general_address %endmacro diff --git a/evm_arithmetization/src/cpu/kernel/asm/journal/journal.asm b/evm_arithmetization/src/cpu/kernel/asm/journal/journal.asm index 3d2951496..057f94e7c 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/journal/journal.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/journal/journal.asm @@ -127,7 +127,7 @@ %macro journal_load_2 // ptr DUP1 - %increment_twice + %add_const(2) %mload_journal_data // x, ptr INCR2 @@ -145,7 +145,7 @@ SWAP1 DUP1 // ptr, ptr, y - %increment_twice + %add_const(2) %mload_journal_data // x, ptr, y INCR2 @@ -169,7 +169,7 @@ SWAP1 DUP1 // ptr, ptr, y, z - %increment_twice + %add_const(2) %mload_journal_data // x, ptr, y, z INCR2 diff --git a/evm_arithmetization/src/cpu/kernel/asm/journal/transient_storage_change.asm b/evm_arithmetization/src/cpu/kernel/asm/journal/transient_storage_change.asm index 1555a9208..ce74df0a2 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/journal/transient_storage_change.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/journal/transient_storage_change.asm @@ -15,7 +15,7 @@ global revert_transient_storage_change: // The value must have been stored %assert_nonzero // stack: pos, addr, value, slot, prev_value, retdest - %increment_twice + %add_const(2) DUP5 // stack: prev_value, pos+2, addr, value, slot, prev_value, retdest MSTORE_GENERAL diff --git a/evm_arithmetization/src/cpu/kernel/asm/main.asm b/evm_arithmetization/src/cpu/kernel/asm/main.asm index d2616f98f..2e8e7e5da 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/main.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/main.asm @@ -7,7 +7,7 @@ global init: // stack: prev_stack_len, addr_registers // First, check the stack length. DUP1 - DUP3 %increment_twice + DUP3 %add_const(2) // stack: stack_len_addr, prev_stack_len, prev_stack_len, addr_registers MLOAD_GENERAL %assert_eq diff --git a/evm_arithmetization/src/cpu/kernel/asm/memory/core.asm b/evm_arithmetization/src/cpu/kernel/asm/memory/core.asm index c06d33325..90ef4eab1 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/memory/core.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/memory/core.asm @@ -18,7 +18,7 @@ ADD // stack: c0 | (c1 << 8), addr DUP2 - %increment_twice + %add_const(2) MLOAD_GENERAL %shl_const(16) ADD diff --git a/evm_arithmetization/src/cpu/kernel/asm/memory/packing.asm b/evm_arithmetization/src/cpu/kernel/asm/memory/packing.asm index 904fdbde4..f3d0e5ce8 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/memory/packing.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/memory/packing.asm @@ -5,7 +5,7 @@ global mload_packing_u64_LE: // stack: addr, retdest DUP1 MLOAD_GENERAL DUP2 INCR1 MLOAD_GENERAL %shl_const( 8) ADD - DUP2 %increment_twice MLOAD_GENERAL %shl_const(16) ADD + DUP2 %add_const(2) MLOAD_GENERAL %shl_const(16) ADD DUP2 %add_const(3) MLOAD_GENERAL %shl_const(24) ADD DUP2 %add_const(4) MLOAD_GENERAL %shl_const(32) ADD DUP2 %add_const(5) MLOAD_GENERAL %shl_const(40) ADD @@ -288,7 +288,7 @@ global mstore_unpacking_u64_LE: %stack (new_addr, addr, value) -> (0xff00, value, new_addr, addr, value) AND %shr_const(8) MSTORE_GENERAL // Second byte - DUP1 %increment_twice + DUP1 %add_const(2) %stack (new_addr, addr, value) -> (0xff0000, value, new_addr, addr, value) AND %shr_const(16) MSTORE_GENERAL // Third byte diff --git a/evm_arithmetization/src/cpu/kernel/asm/memory/transient_storage.asm b/evm_arithmetization/src/cpu/kernel/asm/memory/transient_storage.asm index 7ff09dea4..54d79c244 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/memory/transient_storage.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/memory/transient_storage.asm @@ -65,7 +65,7 @@ search_transient_storage_not_found: search_transient_storage_found: // stack: i, len, addr, key, retdest - DUP1 %increment_twice + DUP1 %add_const(2) MLOAD_GENERAL %stack (val, i, len, addr, key, retdest) -> (retdest, 1, i, addr, val, key) // Return 1 to indicate that the address was already present. JUMP diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_branch.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_branch.asm index 2ccd7d4ad..e77e59b90 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_branch.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_branch.asm @@ -111,7 +111,7 @@ maybe_normalize_branch_leafext: // stack: only_child_ptr, updated_child_ptr, first_nibble, node_payload_ptr, retdest DUP1 INCR1 %mload_trie_data // stack: child_len, only_child_ptr, updated_child_ptr, first_nibble, node_payload_ptr, retdest - DUP2 %increment_twice %mload_trie_data + DUP2 %add_const(2) %mload_trie_data // stack: child_key, child_len, only_child_ptr, updated_child_ptr, first_nibble, node_payload_ptr, retdest %mload_kernel_general(1) %stack (i, child_key, child_len, only_child_ptr, updated_child_ptr, first_nibble, node_payload_ptr) -> @@ -124,6 +124,6 @@ maybe_normalize_branch_leafext: // stack: node_ptr, len, node_ptr, key, only_child_ptr, retdest INCR1 %mstore_trie_data // Change len in the child node // stack: node_ptr, key, only_child_ptr, retdest - %increment_twice %mstore_trie_data // Change key in the child node + %add_const(2) %mstore_trie_data // Change key in the child node // stack: node_ptr, retdest SWAP1 JUMP diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_extension.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_extension.asm index dcd1789de..17189f2eb 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_extension.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/delete/delete_extension.asm @@ -18,7 +18,7 @@ global mpt_delete_extension: // stack: num_nibbles, key, node_payload_ptr, node_len, node_key, retdest SWAP2 // stack: node_payload_ptr, key, num_nibbles, node_len, node_key, retdest - DUP1 %increment_twice %mload_trie_data + DUP1 %add_const(2) %mload_trie_data %stack (node_child_ptr, node_payload_ptr, key, num_nibbles, node_len, node_key, retdest) -> (node_child_ptr, num_nibbles, key, after_mpt_delete_extension, node_payload_ptr, node_len, node_key, retdest) %jump(mpt_delete) @@ -37,7 +37,7 @@ after_mpt_delete_extension_branch: // stack: child_type, updated_child_node_ptr, node_payload_ptr, node_len, node_key, retdest POP // stack: updated_child_node_ptr, node_payload_ptr, node_len, node_key, retdest - DUP2 %increment_twice %mstore_trie_data + DUP2 %add_const(2) %mstore_trie_data // stack: node_payload_ptr, node_len, node_key, retdest %decrement %stack (extension_ptr, node_len, node_key, retdest) -> (retdest, extension_ptr) @@ -49,14 +49,14 @@ after_mpt_delete_extension_extension: // stack: updated_child_node_ptr, node_len, node_key, retdest DUP1 INCR1 %mload_trie_data // stack: child_len, updated_child_node_ptr, node_len, node_key, retdest - DUP2 %increment_twice %mload_trie_data + DUP2 %add_const(2) %mload_trie_data // stack: child_key, child_len, updated_child_node_ptr, node_len, node_key, retdest %stack (child_key, child_len, updated_child_node_ptr, node_len, node_key) -> (node_len, node_key, child_len, child_key, updated_child_node_ptr) %merge_nibbles // stack: len, key, updated_child_node_ptr, retdest DUP3 INCR1 %mstore_trie_data // Change len // stack: key, updated_child_node_ptr, retdest - DUP2 %increment_twice %mstore_trie_data // Change key + DUP2 %add_const(2) %mstore_trie_data // Change key // stack: extension_ptr, retdest SWAP1 JUMP @@ -67,13 +67,13 @@ after_mpt_delete_extension_leaf: // stack: updated_child_node_ptr, node_len, node_key, retdest DUP1 INCR1 %mload_trie_data // stack: child_len, updated_child_node_ptr, node_len, node_key, retdest - DUP2 %increment_twice %mload_trie_data + DUP2 %add_const(2) %mload_trie_data // stack: child_key, child_len, updated_child_node_ptr, node_len, node_key, retdest %stack (child_key, child_len, updated_child_node_ptr, node_len, node_key) -> (node_len, node_key, child_len, child_key, updated_child_node_ptr) %merge_nibbles // stack: len, key, updated_child_node_ptr, retdest DUP3 INCR1 %mstore_trie_data // Change len // stack: key, updated_child_node_ptr, retdest - DUP2 %increment_twice %mstore_trie_data // Change key + DUP2 %add_const(2) %mstore_trie_data // Change key // stack: updated_child_node_ptr, retdest SWAP1 JUMP diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash.asm index 9e2339d7f..d06dbce76 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash.asm @@ -212,7 +212,7 @@ global encode_node_extension: SWAP4 %add_const(4) SWAP4 %stack (node_type, node_payload_ptr, rlp_start, encode_value, cur_len) -> (node_payload_ptr, rlp_start, encode_value, cur_len, encode_node_extension_after_encode_child, rlp_start, node_payload_ptr) - %increment_twice %mload_trie_data + %add_const(2) %mload_trie_data // stack: child_ptr, rlp_start, encode_value, cur_len, encode_node_extension_after_encode_child, rlp_start, node_payload_ptr, retdest %jump(encode_or_hash_node) encode_node_extension_after_encode_child: @@ -273,7 +273,7 @@ global encode_node_leaf: encode_node_leaf_after_hex_prefix: // stack: rlp_pos, rlp_start, node_payload_ptr, encode_value, cur_len, retdest SWAP2 - %increment_twice // The value pointer starts at index 3, after num_nibbles and packed_nibbles. + %add_const(2) // The value pointer starts at index 3, after num_nibbles and packed_nibbles. // stack: value_ptr_ptr, rlp_start, rlp_pos, encode_value, cur_len, retdest %mload_trie_data // stack: value_ptr, rlp_start, rlp_pos, encode_value, cur_len, retdest diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash_trie_specific.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash_trie_specific.asm index f5649d837..9b351e443 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash_trie_specific.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/hash/hash_trie_specific.asm @@ -105,7 +105,7 @@ global encode_account: SWAP1 %encode_rlp_scalar // stack: rlp_pos_5, value_ptr, cur_len, retdest DUP3 - DUP3 %increment_twice %mload_trie_data // storage_root_ptr = value[2] + DUP3 %add_const(2) %mload_trie_data // storage_root_ptr = value[2] // stack: storage_root_ptr, cur_len, rlp_pos_5, value_ptr, cur_len, retdest DUP3 // stack: rlp_pos_5, storage_root_ptr, cur_len, rlp_pos_5, value_ptr, cur_len, retdest @@ -195,7 +195,7 @@ encode_receipt_after_type: SWAP1 %encode_rlp_scalar // stack: rlp_addr, payload_len_ptr, cur_len, retdest // Encode cum_gas_used. - DUP2 %increment_twice %mload_trie_data + DUP2 %add_const(2) %mload_trie_data // stack: cum_gas_used, rlp_addr, payload_len_ptr, cur_len, retdest SWAP1 %encode_rlp_scalar // stack: rlp_addr, payload_len_ptr, cur_len, retdest @@ -239,7 +239,7 @@ encode_receipt_logs_loop: // stack: address, rlp_addr, current_log_ptr, i, num_logs, current_log_ptr, old_rlp_pos, payload_len_ptr, cur_len, retdest SWAP1 %encode_rlp_160 // stack: rlp_addr, current_log_ptr, i, num_logs, current_log_ptr, old_rlp_pos, payload_len_ptr, cur_len, retdest - DUP2 %increment_twice %mload_trie_data + DUP2 %add_const(2) %mload_trie_data // stack: num_topics, rlp_addr, current_log_ptr, i, num_logs, current_log_ptr, old_rlp_pos, payload_len_ptr, cur_len, retdest // Encode topics prefix. DUP1 %mul_const(33) diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/hex_prefix.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/hex_prefix.asm index 86822d2a9..9e9034304 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/hex_prefix.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/hex_prefix.asm @@ -118,7 +118,7 @@ rlp_header_large: // stack: rlp_addr, num_nibbles, packed_nibbles, terminated, retdest // rlp_addr += 2 - %increment_twice + %add_const(2) // stack: rlp_addr, num_nibbles, packed_nibbles, terminated, retdest SWAP3 DUP3 DUP3 diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_extension.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_extension.asm index 5b7a3cdd3..8de672984 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_extension.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_extension.asm @@ -40,7 +40,7 @@ global mpt_insert_extension: // stack: node_payload_ptr, insert_len, insert_key, insert_value_ptr, retdest // We start by loading the extension node's three fields: node_len, node_key, node_child_ptr - DUP1 %increment_twice %mload_trie_data + DUP1 %add_const(2) %mload_trie_data // stack: node_child_ptr, node_payload_ptr, insert_len, insert_key, insert_value_ptr, retdest %stack (node_child_ptr, node_payload_ptr, insert_len, insert_key) -> (node_payload_ptr, insert_len, insert_key, node_child_ptr) diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_leaf.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_leaf.asm index 17f535094..bcd77f27f 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_leaf.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/insert/insert_leaf.asm @@ -55,7 +55,7 @@ global mpt_insert_leaf: // Replace node_payload_ptr with node_value, which is node_payload[2]. // stack: node_len, node_key, insert_len, insert_key, node_payload_ptr, insert_value_ptr, retdest SWAP4 - %increment_twice + %add_const(2) %mload_trie_data SWAP4 // stack: node_len, node_key, insert_len, insert_key, node_value_ptr, insert_value_ptr, retdest @@ -196,7 +196,7 @@ keys_match: -> (node_payload_ptr, node_len, node_key, insert_value_ptr) // stack: node_payload_ptr, common_len, common_key, insert_value_ptr, retdest DUP4 DUP2 - %increment_twice + %add_const(2) %mstore_trie_data %stack (node_payload_ptr, common_len, common_key, insert_value_ptr, retdest) -> (node_payload_ptr, retdest) PUSH 1 SWAP1 SUB diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/final_tries.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/final_tries.asm index cc004d549..52d9cc2f3 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/final_tries.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/final_tries.asm @@ -17,7 +17,7 @@ global insert_all_accounts: INCR1 MLOAD_GENERAL // stack: account_ptr, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest - %increment_twice + %add_const(2) DUP1 %mload_trie_data // stack: storage_root_ptr, storage_root_ptr_ptr, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest @@ -71,7 +71,7 @@ insert_next_slot: MLOAD_GENERAL // stack: key, addr, storage_ptr_ptr, root_ptr, retdest DUP3 - %increment_twice + %add_const(2) MLOAD_GENERAL // stack: value, key, addr, storage_ptr_ptr, root_ptr, retdest // If the value is 0, then payload_ptr = 0, and we don't need to insert a value in the `TrieData` segment. @@ -116,15 +116,15 @@ global delete_removed_accounts: MLOAD_GENERAL // stack: key, account_ptr_ptr, root_ptr, storage_ptr_ptr, retdest DUP2 - %increment_twice + %add_const(2) MLOAD_GENERAL // get initial payload_ptr - %increment_twice // storage_root_ptr_ptr = payload_ptr + 2 + %add_const(2) // storage_root_ptr_ptr = payload_ptr + 2 %mload_trie_data // stack: storage_root_ptr, key, account_ptr_ptr, root_ptr, storage_ptr_ptr, retdest DUP3 INCR1 MLOAD_GENERAL // get dynamic payload_ptr - %increment_twice // storage_root_ptr_ptr = dyn_payload_ptr + 2 + %add_const(2) // storage_root_ptr_ptr = dyn_payload_ptr + 2 %stack (storage_root_ptr_ptr, storage_root_ptr, key, account_ptr_ptr, root_ptr, storage_ptr_ptr) -> (key, storage_root_ptr, storage_ptr_ptr, after_delete_removed_slots, storage_root_ptr_ptr, account_ptr_ptr, root_ptr) diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/initial_tries.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/initial_tries.asm index f1c80939e..2a41f9761 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/initial_tries.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/initial_tries.asm @@ -43,20 +43,20 @@ after_mpt_read: //stack: trie_account_ptr_ptr, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest DUP1 %mload_trie_data - %increment_twice + %add_const(2) %mload_trie_data // stack: trie_storage_root, trie_account_ptr_ptr, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest SWAP1 // stack: trie_account_ptr_ptr, trie_storage_root, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest DUP6 - %increment_twice // intial account_ptr = account_ptr_ptr + 2 + %add_const(2) // intial account_ptr = account_ptr_ptr + 2 MLOAD_GENERAL // stack: account_ptr, trie_account_ptr_ptr, trie_storage_root, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest DUP1 SWAP2 // stack: trie_account_ptr_ptr, account_ptr, account_ptr, trie_storage_root, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest %mstore_trie_data // The trie's account points to the linked list initial account // stack: account_ptr, trie_storage_root, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest - %increment_twice + %add_const(2) // stack: storage_root_ptr_ptr, trie_storage_root, key, storage_ptr_ptr, root_ptr, account_ptr_ptr, retdest %stack diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/linked_list.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/linked_list.asm index 00330ec98..876f3e341 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/linked_list.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/linked_list/linked_list.asm @@ -91,7 +91,7 @@ loop_store_initial_accounts: %append_to_trie_data // stack: cpy_ptr, current_node_ptr, cur_len, retdest DUP2 - %increment_twice + %add_const(2) SWAP1 MSTORE_GENERAL // Store cpy_ptr // stack: current_node_ptr, cur_len, retdest @@ -390,7 +390,7 @@ global store_initial_slots: loop_store_initial_slots: // stack: current_node_ptr, cur_len, retdest DUP1 - %increment_twice + %add_const(2) MLOAD_GENERAL // stack: value, current_node_ptr, cur_len, retdest DUP2 @@ -613,7 +613,7 @@ next_node_ok_with_value: slot_found_write_value: // stack: pred_ptr, addr_key, key, value, retdest - %increment_twice + %add_const(2) %stack (payload_ptr, addr_key, key, value) -> (value, payload_ptr) MSTORE_GENERAL // stack: retdest @@ -691,7 +691,7 @@ slot_found_write: // The slot was already in the list // stack: pred_ptr, addr_key, key, value, retdest // Load the old value - %increment_twice + %add_const(2) DUP1 MLOAD_GENERAL // stack: old_value, pred_ptr + 2, addr_key, key, value, retdest @@ -839,7 +839,7 @@ slot_found_no_write: // The slot was already in the list // stack: pred_ptr, addr_key, key, value, retdest // Load the old value - %increment_twice + %add_const(2) MLOAD_GENERAL // stack: old_value, addr_key, key, value, retdest %stack (old_value, addr_key, key, value, retdest) -> (retdest, old_value) diff --git a/evm_arithmetization/src/cpu/kernel/asm/mpt/read.asm b/evm_arithmetization/src/cpu/kernel/asm/mpt/read.asm index 9920e8d0b..c486f9586 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/mpt/read.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/mpt/read.asm @@ -116,7 +116,7 @@ global mpt_read_extension_found: // stack: key, future_nibbles, node_payload_ptr, retdest SWAP2 // stack: node_payload_ptr, future_nibbles, key, retdest - %increment_twice // child pointer is third field of extension node + %add_const(2) // child pointer is third field of extension node %mload_trie_data // stack: child_ptr, future_nibbles, key, retdest %jump(mpt_read) // recurse @@ -144,7 +144,7 @@ global mpt_read_leaf_not_found: JUMP global mpt_read_leaf_found: // stack: node_payload_ptr, retdest - %increment_twice // The value pointer is located after num_nibbles and the key. + %add_const(2) // The value pointer is located after num_nibbles and the key. // stack: value_ptr_ptr, retdest SWAP1 // For leaves, we return the pointer diff --git a/evm_arithmetization/src/cpu/kernel/asm/util/basic_macros.asm b/evm_arithmetization/src/cpu/kernel/asm/util/basic_macros.asm index c8ceb8df8..2bff83dc6 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/util/basic_macros.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/util/basic_macros.asm @@ -347,10 +347,6 @@ %as_u32 %endmacro -%macro increment_twice - %add_const(2) -%endmacro - %macro decrement %sub_const(1) %endmacro From 58cf5281459b5a4f3953db02f80d0978c6492df7 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Fri, 18 Oct 2024 12:35:29 -0400 Subject: [PATCH 10/12] Ranges --- .env | 2 +- scripts/prove_stdio.sh | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.env b/.env index 29111e064..8d0547a55 100644 --- a/.env +++ b/.env @@ -5,7 +5,7 @@ CPU_CIRCUIT_SIZE=8..21 KECCAK_CIRCUIT_SIZE=4..20 KECCAK_SPONGE_CIRCUIT_SIZE=8..17 LOGIC_CIRCUIT_SIZE=4..21 -MEMORY_CIRCUIT_SIZE=17..24 +MEMORY_CIRCUIT_SIZE=16..24 MEMORY_BEFORE_CIRCUIT_SIZE=16..23 MEMORY_AFTER_CIRCUIT_SIZE=7..23 POSEIDON_CIRCUIT_SIZE=4..25 diff --git a/scripts/prove_stdio.sh b/scripts/prove_stdio.sh index c3c794086..c38b5138e 100755 --- a/scripts/prove_stdio.sh +++ b/scripts/prove_stdio.sh @@ -72,7 +72,7 @@ if ! [[ $TEST_ONLY == "test_only" ]]; then export KECCAK_CIRCUIT_SIZE="4..13" export KECCAK_SPONGE_CIRCUIT_SIZE="8..9" export LOGIC_CIRCUIT_SIZE="4..14" - export MEMORY_CIRCUIT_SIZE="17..22" + export MEMORY_CIRCUIT_SIZE="16..22" export MEMORY_BEFORE_CIRCUIT_SIZE="16..18" export MEMORY_AFTER_CIRCUIT_SIZE="7..8" export POSEIDON_CIRCUIT_SIZE="4..8" @@ -102,8 +102,8 @@ if [[ $TEST_ONLY == "test_only" ]]; then exit else # Some error occurred, display the logs and exit. - cat $OUT_LOG_PATH - echo "Failed to create proof witnesses. See $OUT_LOG_PATH for more details." + cat $TEST_OUT_PATH + echo "Failed to create proof witnesses. See $TEST_OUT_PATH for more details." exit 1 fi fi From 7c765fd7070d778ac80064381e47730abf80b94a Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Fri, 18 Oct 2024 13:27:44 -0400 Subject: [PATCH 11/12] Fix --- scripts/prove_rpc.sh | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/scripts/prove_rpc.sh b/scripts/prove_rpc.sh index 49848fdfe..4ec17a9e0 100755 --- a/scripts/prove_rpc.sh +++ b/scripts/prove_rpc.sh @@ -20,19 +20,6 @@ export RUSTFLAGS='-C target-cpu=native -Zlinker-features=-lld' BLOCK_BATCH_SIZE="${BLOCK_BATCH_SIZE:-8}" echo "Block batch size: $BLOCK_BATCH_SIZE" -# Circuit sizes only matter in non test_only mode. -if ! [[ $8 == "test_only" ]]; then - export ARITHMETIC_CIRCUIT_SIZE="16..21" - export BYTE_PACKING_CIRCUIT_SIZE="8..21" - export CPU_CIRCUIT_SIZE="8..21" - export KECCAK_CIRCUIT_SIZE="4..20" - export KECCAK_SPONGE_CIRCUIT_SIZE="8..17" - export LOGIC_CIRCUIT_SIZE="4..21" - export MEMORY_CIRCUIT_SIZE="17..24" - export MEMORY_BEFORE_CIRCUIT_SIZE="16..23" - export MEMORY_AFTER_CIRCUIT_SIZE="7..23" -fi - REPO_ROOT=$(git rev-parse --show-toplevel) PROOF_OUTPUT_DIR="${REPO_ROOT}/proofs" From b7105bf6915d63ccd3b553929ebf55207aabc154 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Wed, 13 Nov 2024 18:55:56 -0500 Subject: [PATCH 12/12] Update --- evm_arithmetization/src/all_stark.rs | 9 +- .../src/cpu/columns/general.rs | 25 ++++++ evm_arithmetization/src/cpu/cpu_stark.rs | 55 +++++++++++- evm_arithmetization/src/cpu/dup_swap.rs | 4 +- evm_arithmetization/src/cpu/incr.rs | 85 +++++++++++++++---- .../src/cpu/kernel/asm/bignum/modmul.asm | 9 +- .../src/cpu/kernel/asm/core/exception.asm | 2 +- .../src/cpu/kernel/asm/hash/ripemd/update.asm | 2 - evm_arithmetization/src/witness/operation.rs | 43 ++++++---- 9 files changed, 186 insertions(+), 48 deletions(-) diff --git a/evm_arithmetization/src/all_stark.rs b/evm_arithmetization/src/all_stark.rs index 36157be75..64819ff03 100644 --- a/evm_arithmetization/src/all_stark.rs +++ b/evm_arithmetization/src/all_stark.rs @@ -175,9 +175,14 @@ pub(crate) fn all_cross_table_lookups() -> Vec> { /// module. fn ctl_arithmetic() -> CrossTableLookup { let cpu_arithmetic_looking = cpu_stark::ctl_arithmetic_base_rows(); - let cpu_increment_looking = cpu_stark::ctl_arithmetic_incr_op(); + let cpu_incr1_looking = cpu_stark::ctl_arithmetic_incr1_op(); + let cpu_incr_other_looking = cpu_stark::ctl_arithmetic_incr_op(); CrossTableLookup::new( - vec![cpu_arithmetic_looking, cpu_increment_looking], + vec![ + cpu_arithmetic_looking, + cpu_incr1_looking, + cpu_incr_other_looking, + ], arithmetic_stark::ctl_arithmetic_rows(), ) } diff --git a/evm_arithmetization/src/cpu/columns/general.rs b/evm_arithmetization/src/cpu/columns/general.rs index 97f8b8f49..0b7c18820 100644 --- a/evm_arithmetization/src/cpu/columns/general.rs +++ b/evm_arithmetization/src/cpu/columns/general.rs @@ -15,6 +15,7 @@ pub(crate) union CpuGeneralColumnsView { shift: CpuShiftView, stack: CpuStackView, push: CpuPushView, + incr: CpuIncrView, context_pruning: CpuContextPruningView, } @@ -93,6 +94,18 @@ impl CpuGeneralColumnsView { unsafe { &mut self.push } } + /// View of the columns required for the incr operation. + /// SAFETY: Each view is a valid interpretation of the underlying array. + pub(crate) const fn incr(&self) -> &CpuIncrView { + unsafe { &self.incr } + } + + /// Mutable view of the columns required for the incr operation. + /// SAFETY: Each view is a valid interpretation of the underlying array. + pub(crate) fn incr_mut(&mut self) -> &mut CpuIncrView { + unsafe { &mut self.incr } + } + /// View of the column for context pruning. /// SAFETY: Each view is a valid interpretation of the underlying array. pub(crate) const fn context_pruning(&self) -> &CpuContextPruningView { @@ -217,6 +230,17 @@ pub(crate) struct CpuPushView { _padding_columns: [T; NUM_SHARED_COLUMNS - 1], } +/// View of the first `CpuGeneralColumn` storing the sum of the first 2 opcode +/// bits to filter out `INCR1` instruction from the other ones (INCR2-INCR4). +#[repr(C)] +#[derive(Copy, Clone)] +pub(crate) struct CpuIncrView { + /// Product of `incr` flag with the sum of the first 2 opcode bits. + pub(crate) is_not_incr1: T, + /// Reserve the unused columns. + _padding_columns: [T; NUM_SHARED_COLUMNS - 1], +} + /// View of the first `CpuGeneralColumn` storing a flag for context pruning. #[derive(Copy, Clone)] pub(crate) struct CpuContextPruningView { @@ -243,4 +267,5 @@ const_assert!(size_of::>() == NUM_SHARED_COLUMNS); const_assert!(size_of::>() == NUM_SHARED_COLUMNS); const_assert!(size_of::>() == NUM_SHARED_COLUMNS); const_assert!(size_of::>() == NUM_SHARED_COLUMNS); +const_assert!(size_of::>() == NUM_SHARED_COLUMNS); const_assert!(size_of::>() == NUM_SHARED_COLUMNS); diff --git a/evm_arithmetization/src/cpu/cpu_stark.rs b/evm_arithmetization/src/cpu/cpu_stark.rs index 33955eeaf..a61616b32 100644 --- a/evm_arithmetization/src/cpu/cpu_stark.rs +++ b/evm_arithmetization/src/cpu/cpu_stark.rs @@ -132,7 +132,52 @@ pub(crate) fn ctl_arithmetic_base_rows() -> TableWithColumns { } /// Returns the `TableWithColumns` for the CPU rows calling arithmetic -/// `ADD` operations through the `INCR` privileged instructions. +/// `ADD` operations through the `INCR1` privileged instruction. +/// +/// It requires a different CTL than `INCR2`-`INCR4` as it does not incur any +/// memory reads. +pub(crate) fn ctl_arithmetic_incr1_op() -> TableWithColumns { + // Instead of taking single columns, we reconstruct the entire opcode value + // directly. + let mut columns = vec![Column::constant(F::from_canonical_u8(get_opcode("ADD")))]; + + // Read value: current top of the stack + columns.extend(Column::singles(COL_MAP.mem_channels[0].value)); + + // Fixed second operand (`U256::one()`) + { + columns.push(Column::constant(F::ONE)); + for _ in 1..VALUE_LIMBS { + columns.push(Column::constant(F::ZERO)); + } + } + + // Ignored third operand, `ADD` is a binary operation + for _ in 0..VALUE_LIMBS { + columns.push(Column::constant(F::ZERO)); + } + + // Returned value: next top of the stack + columns.extend(Column::singles_next_row(COL_MAP.mem_channels[0].value)); + + TableWithColumns::new( + *Table::Cpu, + columns, + Filter::new( + vec![( + Column::single(COL_MAP.op.incr), + Column::linear_combination_with_constant( + [(COL_MAP.general.incr().is_not_incr1, -F::ONE)], + F::ONE, + ), + )], + vec![], + ), + ) +} + +/// Returns the `TableWithColumns` for the CPU rows calling arithmetic +/// `ADD` operations through the `INCR2`-`INCR4` privileged instructions. pub(crate) fn ctl_arithmetic_incr_op() -> TableWithColumns { // Instead of taking single columns, we reconstruct the entire opcode value // directly. @@ -160,7 +205,13 @@ pub(crate) fn ctl_arithmetic_incr_op() -> TableWithColumns { TableWithColumns::new( *Table::Cpu, columns, - Filter::new_simple(Column::single(COL_MAP.op.incr)), + Filter::new( + vec![( + Column::single(COL_MAP.op.incr), + Column::single(COL_MAP.general.incr().is_not_incr1), + )], + vec![], + ), ) } diff --git a/evm_arithmetization/src/cpu/dup_swap.rs b/evm_arithmetization/src/cpu/dup_swap.rs index 90cbd5c9e..ab48cd320 100644 --- a/evm_arithmetization/src/cpu/dup_swap.rs +++ b/evm_arithmetization/src/cpu/dup_swap.rs @@ -11,7 +11,7 @@ use crate::cpu::columns::{CpuColumnsView, MemoryChannelView}; use crate::memory::segments::Segment; /// Constrain two channels to have equal values. -fn channels_equal_packed( +pub(crate) fn channels_equal_packed( filter: P, ch_a: &MemoryChannelView

, ch_b: &MemoryChannelView

, @@ -23,7 +23,7 @@ fn channels_equal_packed( } /// Constrain two channels to have equal values. -fn channels_equal_ext_circuit, const D: usize>( +pub(crate) fn channels_equal_ext_circuit, const D: usize>( builder: &mut CircuitBuilder, filter: ExtensionTarget, ch_a: &MemoryChannelView>, diff --git a/evm_arithmetization/src/cpu/incr.rs b/evm_arithmetization/src/cpu/incr.rs index 9104a7c62..6640235ca 100644 --- a/evm_arithmetization/src/cpu/incr.rs +++ b/evm_arithmetization/src/cpu/incr.rs @@ -6,23 +6,34 @@ use plonky2::iop::ext_target::ExtensionTarget; use plonky2::plonk::circuit_builder::CircuitBuilder; use starky::constraint_consumer::{ConstraintConsumer, RecursiveConstraintConsumer}; -use super::dup_swap::{constrain_channel_ext_circuit, constrain_channel_packed}; +use super::dup_swap::{ + channels_equal_ext_circuit, channels_equal_packed, constrain_channel_ext_circuit, + constrain_channel_packed, +}; use crate::cpu::columns::CpuColumnsView; -/// Evaluates the constraints for the DUP and SWAP opcodes. +/// Evaluates the constraints for the INCR opcodes. pub(crate) fn eval_packed( lv: &CpuColumnsView

, nv: &CpuColumnsView

, yield_constr: &mut ConstraintConsumer

, ) { - let filter = lv.op.incr; + let base_filter = lv.op.incr; - let n = lv.opcode_bits[0] - + lv.opcode_bits[1] * P::Scalar::from_canonical_u64(2) - + lv.opcode_bits[2] * P::Scalar::from_canonical_u64(4); + // Constrain the helper column + yield_constr.constraint( + base_filter + * (lv.general.incr().is_not_incr1 - lv.opcode_bits[0]) + * (lv.general.incr().is_not_incr1 - lv.opcode_bits[1]), + ); + + let filter = base_filter * lv.general.incr().is_not_incr1; + let filter_incr1 = base_filter * (lv.general.incr().is_not_incr1 - P::ONES); - // Disable the partial channel. - yield_constr.constraint(lv.op.incr * lv.partial_channel.used); + let n = lv.opcode_bits[0] + lv.opcode_bits[1] * P::Scalar::from_canonical_u64(2); + + // Disable the partial channel for all instructions. + yield_constr.constraint(base_filter * lv.partial_channel.used); // Constrain the input channel's address, `is_read` and `used` fields. let read_channel = &lv.mem_channels[1]; @@ -32,30 +43,55 @@ pub(crate) fn eval_packed( let write_channel = &lv.mem_channels[2]; constrain_channel_packed(false, filter, n, write_channel, lv, yield_constr); - // Constrain the unchanged stack len. - yield_constr.constraint_transition(filter * (nv.stack_len - lv.stack_len)); + // Constrain the unchanged stack len for all instructions. + yield_constr.constraint_transition(base_filter * (nv.stack_len - lv.stack_len)); + + // Constrain the unchanged stack top for INCR2-INCR4. + channels_equal_packed( + filter, + &lv.mem_channels[0], + &nv.mem_channels[0], + yield_constr, + ); + + // Disable regular read and write channels for INCR1. + yield_constr.constraint(filter_incr1 * lv.mem_channels[1].used); + yield_constr.constraint(filter_incr1 * lv.mem_channels[2].used); } /// Circuit version of `eval_packed`. -/// Evaluates the constraints for the DUP and SWAP opcodes. +/// Evaluates the constraints for the INCR opcodes. pub(crate) fn eval_ext_circuit, const D: usize>( builder: &mut CircuitBuilder, lv: &CpuColumnsView>, nv: &CpuColumnsView>, yield_constr: &mut RecursiveConstraintConsumer, ) { - let filter = lv.op.incr; + let base_filter = lv.op.incr; + + // Constrain the helper column + { + let diff_bit1 = builder.sub_extension(lv.general.incr().is_not_incr1, lv.opcode_bits[0]); + let diff_bit2 = builder.sub_extension(lv.general.incr().is_not_incr1, lv.opcode_bits[1]); + let constr = builder.mul_extension(base_filter, diff_bit1); + let constr = builder.mul_extension(constr, diff_bit2); + yield_constr.constraint(builder, constr); + } + + let filter = builder.mul_extension(base_filter, lv.general.incr().is_not_incr1); + let filter_incr1 = + builder.mul_sub_extension(base_filter, lv.general.incr().is_not_incr1, base_filter); - let n = lv.opcode_bits[..3].iter().enumerate().fold( + let n = lv.opcode_bits[..2].iter().enumerate().fold( builder.zero_extension(), |cumul, (i, &bit)| { builder.mul_const_add_extension(F::from_canonical_u64(1 << i), bit, cumul) }, ); - // Disable the partial channel. + // Disable the partial channel for all instructions. { - let constr = builder.mul_extension(lv.op.incr, lv.partial_channel.used); + let constr = builder.mul_extension(base_filter, lv.partial_channel.used); yield_constr.constraint(builder, constr); } @@ -67,10 +103,25 @@ pub(crate) fn eval_ext_circuit, const D: usize>( let write_channel = &lv.mem_channels[2]; constrain_channel_ext_circuit(builder, false, filter, n, write_channel, lv, yield_constr); - // Constrain the unchanged stack len. + // Constrain the unchanged stack len for all instructions. { let diff = builder.sub_extension(nv.stack_len, lv.stack_len); - let constr = builder.mul_extension(filter, diff); + let constr = builder.mul_extension(base_filter, diff); yield_constr.constraint_transition(builder, constr); } + + // Constrain the unchanged stack top for INCR2-INCR4. + channels_equal_ext_circuit( + builder, + filter, + &lv.mem_channels[0], + &nv.mem_channels[0], + yield_constr, + ); + + // Disable regular read and write channels for INCR1. + let constr = builder.mul_extension(filter_incr1, lv.mem_channels[1].used); + yield_constr.constraint(builder, constr); + let constr = builder.mul_extension(filter_incr1, lv.mem_channels[2].used); + yield_constr.constraint(builder, constr); } diff --git a/evm_arithmetization/src/cpu/kernel/asm/bignum/modmul.asm b/evm_arithmetization/src/cpu/kernel/asm/bignum/modmul.asm index 17b770816..901a0fc9e 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/bignum/modmul.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/bignum/modmul.asm @@ -156,12 +156,9 @@ modmul_check_loop: SWAP1 %decrement // stack: n-1, base_addr, i, j, retdest - INCR3 - SWAP2 - // stack: i+1, base_addr, n-1, j, retdest - INCR4 - // stack: i+1, base_addr, n-1, j+1, retdest - %stack (i, addr, n) -> (n, addr, n, i) + INCR3 INCR4 + // stack: n-1, base_addr, i+1, j+1, retdest + %stack (n, addr) -> (n, addr, n) // stack: n-1, base_addr, n-1, i+1, j+1, retdest %jumpi(modmul_check_loop) // end of modmul_check_loop diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm b/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm index 1de3eac3f..c95549a83 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/exception.asm @@ -420,7 +420,7 @@ min_stack_len_for_opcode: BYTES 3 // 0xe2, INCR3 BYTES 4 // 0xe3, INCR4 - %rep 12 // 0xe5-0xef, invalid + %rep 12 // 0xe4-0xef, invalid BYTES 0 %endrep diff --git a/evm_arithmetization/src/cpu/kernel/asm/hash/ripemd/update.asm b/evm_arithmetization/src/cpu/kernel/asm/hash/ripemd/update.asm index a05a36d69..20b8f469c 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/hash/ripemd/update.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/hash/ripemd/update.asm @@ -121,8 +121,6 @@ buffer_update: // stack: get , set , times , retdest INCR1 INCR2 - SWAP1 - SWAP1 SWAP2 %decrement SWAP2 diff --git a/evm_arithmetization/src/witness/operation.rs b/evm_arithmetization/src/witness/operation.rs index 7561a22c7..7b105901d 100644 --- a/evm_arithmetization/src/witness/operation.rs +++ b/evm_arithmetization/src/witness/operation.rs @@ -605,25 +605,36 @@ pub(crate) fn generate_incr>( mut row: CpuColumnsView, ) -> Result<(), ProgramError> { let generation_state = state.get_mut_generation_state(); - let offset = generation_state - .registers - .stack_len - .checked_sub(1 + (n as usize)) - .ok_or(ProgramError::StackUnderflow)?; - let addr = MemoryAddress::new(generation_state.registers.context, Segment::Stack, offset); - - let (val, log_in0) = mem_read_gp_with_log_and_fill(1, addr, generation_state, &mut row); - let new_val = val.overflowing_add(1.into()).0; - // Write the read value, incremented by 1. - let log_out0 = mem_write_gp_log_and_fill(2, addr, generation_state, &mut row, new_val); + let val = if n == 0 { + let val = generation_state.registers.stack_top; - // Manually increment the top of the stack if calling INCR1. - if n == 0 { + // Manually increment the top of the stack if calling INCR1. generation_state.registers.stack_top += U256::one(); - } - state.push_memory(log_in0); - state.push_memory(log_out0); + + val + } else { + let offset = generation_state + .registers + .stack_len + .checked_sub(1 + (n as usize)) + .ok_or(ProgramError::StackUnderflow)?; + let addr = MemoryAddress::new(generation_state.registers.context, Segment::Stack, offset); + + let (val, log_in0) = mem_read_gp_with_log_and_fill(1, addr, generation_state, &mut row); + let new_val = val.overflowing_add(1.into()).0; + + // Write the read value, incremented by 1. + let log_out0 = mem_write_gp_log_and_fill(2, addr, generation_state, &mut row, new_val); + + // Set the general helper column. + row.general.incr_mut().is_not_incr1 = F::ONE; + + state.push_memory(log_in0); + state.push_memory(log_out0); + + val + }; let operation = arithmetic::Operation::binary(BinaryOperator::Add, val, U256::one()); state.push_arithmetic(operation);