Skip to content

Commit

Permalink
Several bug fixes for the Type-2 (#1353)
Browse files Browse the repository at this point in the history
* Squashed commit of the following:

commit 4f854e6
Author: wborgeaud <[email protected]>
Date:   Fri Nov 3 13:48:23 2023 +0100

    Minor

commit fbd4c78
Merge: ad580c2 c70a785
Author: wborgeaud <[email protected]>
Date:   Fri Nov 3 13:42:45 2023 +0100

    Merge branch 'feat/type2' into type2/smt_deletion

    # Conflicts:
    #	evm/src/cpu/kernel/aggregator.rs
    #	evm/src/cpu/kernel/asm/mpt/storage/storage_write.asm
    #	evm/src/cpu/kernel/asm/smt/insert.asm
    #	evm/src/cpu/kernel/asm/smt/utils.asm
    #	evm/src/cpu/kernel/constants/mod.rs
    #	evm/src/cpu/kernel/tests/smt/mod.rs
    #	evm/tests/selfdestruct.rs

commit c70a785
Author: wborgeaud <[email protected]>
Date:   Fri Nov 3 13:37:19 2023 +0100

    Start of SMT implementation for Type 2 zkEVM (#1315)

    * Add SMT types

    * Progress

    * Progress

    * Working smt hashing

    * Minor

    * Fix hash

    * Working insert

    * Minor

    * Add insert test for storage trie

    * Add missing constraints for DUP/SWAP (#1310)

    * Refactor wcopy syscalls

    * Refactor memcpy

    * Working test_simple_transfer

    * Modify add11_yml.rs

    * Refactor codecopy

    * Fix

    * Fix calldatacopy

    * Fix test on interpreter side

    * Remove new_stack_top_channel from StackBehavior (#1296)

    * Working add11_yml.rs

    * All tests compile

    * Working test_balance

    * Minor

    * Working test_extcodesize

    * All non-ignored tests pass

    * Fix test_empty_txn_list

    * Clippy

    * smt_utils point to github

    * Comments

    * Fix kexit_info in test

    * Review

    * Update Cargo.toml

    * Move empty check inside final iteration

    * Remerge context flags (#1292)

    * Remerge context flags

    * Apply comments and revert some unwanted changes

    * Merge NOT and POP flags. (#1257)

    * Merge NOT and POP flags

    * Add comments

    * Disable remaining memory channels for POP

    * Apply comments

    * Fix stack

    * More of memcpy_bytes

    * Add some documentation in EVM crate (#1295)

    Co-authored-by: Linda Guiga <[email protected]>

    * Combine PUSH0 and PC flags. (#1256)

    * PR feedback

    * Add context constraints (#1260)

    * Combine JUMPDEST and KECCAK_GENERAL flags. (#1259)

    * Combine JUMPDEST and KECCAK_GENERAL flags.

    * Apply comments

    * Fix merging of jumpdest and keccak_general.

    * Add test for selfdestruct (#1321)

    * Add test for selfdestruct

    * Comment

    * Fix test

    ---------

    Co-authored-by: Hamy Ratoanina <[email protected]>
    Co-authored-by: Robin Salen <[email protected]>
    Co-authored-by: Linda Guiga <[email protected]>
    Co-authored-by: Robin Salen <[email protected]>
    Co-authored-by: Linda Guiga <[email protected]>
    Co-authored-by: Linda Guiga <[email protected]>

commit ad580c2
Author: wborgeaud <[email protected]>
Date:   Thu Nov 2 08:40:46 2023 +0100

    Clippy

commit fe5b8fd
Author: wborgeaud <[email protected]>
Date:   Thu Nov 2 08:39:26 2023 +0100

    s/mpt/smt in a bunch of places

commit 73dc262
Author: wborgeaud <[email protected]>
Date:   Thu Nov 2 08:15:56 2023 +0100

    Selfdestruct test passes

commit 539190f
Merge: e110941 f71f227
Author: wborgeaud <[email protected]>
Date:   Thu Nov 2 07:58:15 2023 +0100

    Merge branch 'main' into type2/smt_deletion

commit e110941
Author: wborgeaud <[email protected]>
Date:   Wed Nov 1 17:04:38 2023 +0100

    Minor

commit f7fba35
Author: wborgeaud <[email protected]>
Date:   Wed Nov 1 12:24:13 2023 +0100

    PR feedback

commit e528b89
Author: wborgeaud <[email protected]>
Date:   Mon Oct 30 09:11:25 2023 +0100

    Update Cargo.toml

commit 5eaf83e
Author: wborgeaud <[email protected]>
Date:   Fri Oct 27 12:34:52 2023 +0200

    Comments

commit ae9c443
Author: wborgeaud <[email protected]>
Date:   Fri Oct 27 11:51:16 2023 +0200

    smt_utils point to github

commit b3d61b7
Author: wborgeaud <[email protected]>
Date:   Fri Oct 27 11:49:33 2023 +0200

    Clippy

commit ccb3d7e
Author: wborgeaud <[email protected]>
Date:   Fri Oct 27 10:00:20 2023 +0200

    Fix test_empty_txn_list

commit 986b010
Author: wborgeaud <[email protected]>
Date:   Fri Oct 27 09:48:14 2023 +0200

    All non-ignored tests pass

commit 7bb0c02
Author: wborgeaud <[email protected]>
Date:   Fri Oct 27 09:44:40 2023 +0200

    Working test_extcodesize

commit b8a85d4
Author: wborgeaud <[email protected]>
Date:   Fri Oct 27 09:38:08 2023 +0200

    Minor

commit 2c01b05
Author: wborgeaud <[email protected]>
Date:   Fri Oct 27 09:37:05 2023 +0200

    Working test_balance

commit e370b62
Author: wborgeaud <[email protected]>
Date:   Fri Oct 27 09:13:36 2023 +0200

    All tests compile

commit f21bc5c
Author: wborgeaud <[email protected]>
Date:   Fri Oct 27 08:31:04 2023 +0200

    Working add11_yml.rs

commit 4e2b3f3
Author: wborgeaud <[email protected]>
Date:   Thu Oct 26 18:50:32 2023 +0200

    Modify add11_yml.rs

commit c324412
Author: wborgeaud <[email protected]>
Date:   Thu Oct 26 18:28:21 2023 +0200

    Working test_simple_transfer

commit df55e45
Author: wborgeaud <[email protected]>
Date:   Thu Oct 26 08:54:24 2023 +0200

    Add insert test for storage trie

commit ca0102f
Author: wborgeaud <[email protected]>
Date:   Thu Oct 26 08:42:03 2023 +0200

    Minor

commit dc27351
Author: wborgeaud <[email protected]>
Date:   Thu Oct 26 08:40:57 2023 +0200

    Working insert

commit f6c4067
Author: wborgeaud <[email protected]>
Date:   Wed Oct 25 08:07:31 2023 +0200

    Fix hash

commit c6e85eb
Author: wborgeaud <[email protected]>
Date:   Wed Oct 18 18:46:32 2023 +0200

    Minor

commit d95c430
Author: wborgeaud <[email protected]>
Date:   Wed Oct 18 18:32:05 2023 +0200

    Working smt hashing

commit fd09915
Author: wborgeaud <[email protected]>
Date:   Wed Oct 18 14:32:38 2023 +0200

    Progress

commit a706cda
Author: wborgeaud <[email protected]>
Date:   Wed Oct 18 07:37:26 2023 +0200

    Progress

commit 95e5cc1
Author: wborgeaud <[email protected]>
Date:   Fri Oct 13 09:19:45 2023 +0200

    Add SMT types

* Constrain uninitialized memory to 0 (#1318)

* Fix typos in comments

* Fix typos in comments

* Add test for ERC20 transfer (#1331)

* Working test

* Minor

* Cleaning

* Implement storage SMT

* Working ERC20 test

* Cleaning

* Remove `len` column in `KeccakSpongeStark` (#1334)

* Remove len column in KeccakSpongeStark

* Apply comment

Co-authored-by: Robin Salen <[email protected]>

---------

Co-authored-by: Robin Salen <[email protected]>

* Add withdrawals (#1322)

* Withdrawals

* Remove AllRecursiveCircuits in withdrawals test

* Fix ERC20 test

* Add memory checks for prover_input, as well as range_checks for prover_input, syscalls/exceptions (#1168)

* Add memory checks for prover_input and range_checks for prover_input, syscalls and exceptions

* Replace u32 by U256, and remove extra CTLs

* Add column in ArithmeticStark to use ctl_arithmetic_base_rows for is_range_check

* Fix CTLs and circuit constraint.

* Fix CTLs

* restore `no-std` support (#1335)

* perform test action on `x86_64-unknown-linux-gnu` and `wasm32-unknown-unknown`

Signed-off-by: muraca <[email protected]>

* make `plonky2` build on `wasm32-unknown-unknown`

Signed-off-by: muraca <[email protected]>

* make `starky` build on `wasm32-unknown-unknown`
small oversight on `plonky2` fixed

Signed-off-by: muraca <[email protected]>

* skip `evm` folder if target is `wasm32-unknown-unknown`

Signed-off-by: muraca <[email protected]>

* add `default: true` to toolchain

Signed-off-by: muraca <[email protected]>

* skip `test` if target is `wasm32-unknown-unknown`

Signed-off-by: muraca <[email protected]>

* single ticks instead of double

Signed-off-by: muraca <[email protected]>

* explicit target

Signed-off-by: muraca <[email protected]>

* wasm32 job

Signed-off-by: muraca <[email protected]>

* added `--no-default-features` to checks

Signed-off-by: muraca <[email protected]>

---------

Signed-off-by: muraca <[email protected]>

* Fix create_contract_account

* Fixes

* More fixes

* More fixes

* Minor

---------

Signed-off-by: muraca <[email protected]>
Co-authored-by: Paul Gebheim <[email protected]>
Co-authored-by: Hamy Ratoanina <[email protected]>
Co-authored-by: shuoer86 <[email protected]>
Co-authored-by: Robin Salen <[email protected]>
Co-authored-by: Linda Guiga <[email protected]>
Co-authored-by: Matteo Muraca <[email protected]>
  • Loading branch information
7 people authored Nov 27, 2023
1 parent 3099c50 commit 5025647
Show file tree
Hide file tree
Showing 82 changed files with 839 additions and 143 deletions.
53 changes: 52 additions & 1 deletion .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
branches:
- "**"

jobs:
jobs:
test:
name: Test Suite
runs-on: ubuntu-latest
Expand Down Expand Up @@ -82,6 +82,57 @@ jobs:
CARGO_INCREMENTAL: 1
RUST_BACKTRACE: 1

wasm32:
name: wasm32 compatibility
runs-on: ubuntu-latest
if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')"
steps:
- name: Checkout sources
uses: actions/checkout@v2

- name: Install nightly wasm32 toolchain
id: rustc-toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly
target: wasm32-unknown-unknown
default: true
override: true

- name: rust-cache
uses: actions/cache@v3
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: rustc-wasm32-${{ steps.rustc-toolchain.outputs.rustc_hash }}-cargo-${{ hashFiles('**/Cargo.toml') }}

- name: Check in plonky2 subdirectory
uses: actions-rs/cargo@v1
with:
command: check
args: --manifest-path plonky2/Cargo.toml --target wasm32-unknown-unknown --no-default-features
env:
RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0
RUST_LOG: 1
CARGO_INCREMENTAL: 1
RUST_BACKTRACE: 1

- name: Check in starky subdirectory
uses: actions-rs/cargo@v1
with:
command: check
args: --manifest-path starky/Cargo.toml --target wasm32-unknown-unknown --no-default-features
env:
RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0
RUST_LOG: 1
CARGO_INCREMENTAL: 1
RUST_BACKTRACE: 1

lints:
name: Formatting and Clippy
runs-on: ubuntu-latest
Expand Down
31 changes: 28 additions & 3 deletions evm/src/arithmetic/arithmetic_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ pub(crate) fn ctl_arithmetic_rows<F: Field>() -> TableWithColumns<F> {
// If an arithmetic operation is happening on the CPU side,
// the CTL will enforce that the reconstructed opcode value
// from the opcode bits matches.
// These opcodes are missing the syscall and prover_input opcodes,
// since `IS_RANGE_CHECK` can be associated to multiple opcodes.
// For `IS_RANGE_CHECK`, the opcodes are written in OPCODE_COL,
// and we use that column for scaling and the CTL checks.
// Note that we ensure in the STARK's constraints that the
// value in `OPCODE_COL` is 0 if `IS_RANGE_CHECK` = 0.
const COMBINED_OPS: [(usize, u8); 16] = [
(columns::IS_ADD, 0x01),
(columns::IS_MUL, 0x02),
Expand All @@ -89,16 +95,21 @@ pub(crate) fn ctl_arithmetic_rows<F: Field>() -> TableWithColumns<F> {
columns::OUTPUT_REGISTER,
];

let filter_column = Some(Column::sum(COMBINED_OPS.iter().map(|(c, _v)| *c)));
let mut filter_cols = COMBINED_OPS.to_vec();
filter_cols.push((columns::IS_RANGE_CHECK, 0x01));

let filter_column = Some(Column::sum(filter_cols.iter().map(|(c, _v)| *c)));

let mut all_combined_cols = COMBINED_OPS.to_vec();
all_combined_cols.push((columns::OPCODE_COL, 0x01));
// Create the Arithmetic Table whose columns are those of the
// operations listed in `ops` whose inputs and outputs are given
// by `regs`, where each element of `regs` is a range of columns
// corresponding to a 256-bit input or output register (also `ops`
// is used as the operation filter).
TableWithColumns::new(
Table::Arithmetic,
cpu_arith_data_link(&COMBINED_OPS, &REGISTER_MAP),
cpu_arith_data_link(&all_combined_cols, &REGISTER_MAP),
filter_column,
)
}
Expand All @@ -109,7 +120,7 @@ pub struct ArithmeticStark<F, const D: usize> {
pub f: PhantomData<F>,
}

const RANGE_MAX: usize = 1usize << 16; // Range check strict upper bound
pub(crate) const RANGE_MAX: usize = 1usize << 16; // Range check strict upper bound

impl<F: RichField, const D: usize> ArithmeticStark<F, D> {
/// Expects input in *column*-major layout
Expand Down Expand Up @@ -195,6 +206,10 @@ impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for ArithmeticSta
let lv: &[P; NUM_ARITH_COLUMNS] = vars.get_local_values().try_into().unwrap();
let nv: &[P; NUM_ARITH_COLUMNS] = vars.get_next_values().try_into().unwrap();

// Check that `OPCODE_COL` holds 0 if the operation is not a range_check.
let opcode_constraint = (P::ONES - lv[columns::IS_RANGE_CHECK]) * lv[columns::OPCODE_COL];
yield_constr.constraint(opcode_constraint);

// Check the range column: First value must be 0, last row
// must be 2^16-1, and intermediate rows must increment by 0
// or 1.
Expand Down Expand Up @@ -231,6 +246,16 @@ impl<F: RichField + Extendable<D>, const D: usize> Stark<F, D> for ArithmeticSta
let nv: &[ExtensionTarget<D>; NUM_ARITH_COLUMNS] =
vars.get_next_values().try_into().unwrap();

// Check that `OPCODE_COL` holds 0 if the operation is not a range_check.
let opcode_constraint = builder.arithmetic_extension(
F::NEG_ONE,
F::ONE,
lv[columns::IS_RANGE_CHECK],
lv[columns::OPCODE_COL],
lv[columns::OPCODE_COL],
);
yield_constr.constraint(builder, opcode_constraint);

// Check the range column: First value must be 0, last row
// must be 2^16-1, and intermediate rows must increment by 0
// or 1.
Expand Down
6 changes: 4 additions & 2 deletions evm/src/arithmetic/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ pub(crate) const IS_GT: usize = IS_LT + 1;
pub(crate) const IS_BYTE: usize = IS_GT + 1;
pub(crate) const IS_SHL: usize = IS_BYTE + 1;
pub(crate) const IS_SHR: usize = IS_SHL + 1;

pub(crate) const START_SHARED_COLS: usize = IS_SHR + 1;
pub(crate) const IS_RANGE_CHECK: usize = IS_SHR + 1;
/// Column that stores the opcode if the operation is a range check.
pub(crate) const OPCODE_COL: usize = IS_RANGE_CHECK + 1;
pub(crate) const START_SHARED_COLS: usize = OPCODE_COL + 1;

/// Within the Arithmetic Unit, there are shared columns which can be
/// used by any arithmetic circuit, depending on which one is active
Expand Down
55 changes: 55 additions & 0 deletions evm/src/arithmetic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use ethereum_types::U256;
use plonky2::field::types::PrimeField64;

use self::columns::{
INPUT_REGISTER_0, INPUT_REGISTER_1, INPUT_REGISTER_2, OPCODE_COL, OUTPUT_REGISTER,
};
use self::utils::u256_to_array;
use crate::arithmetic::columns::IS_RANGE_CHECK;
use crate::extension_tower::BN_BASE;
use crate::util::{addmod, mulmod, submod};

Expand Down Expand Up @@ -135,6 +140,7 @@ impl TernaryOperator {
}

/// An enum representing arithmetic operations that can be either binary or ternary.
#[allow(clippy::enum_variant_names)]
#[derive(Debug)]
pub(crate) enum Operation {
BinaryOperation {
Expand All @@ -150,6 +156,13 @@ pub(crate) enum Operation {
input2: U256,
result: U256,
},
RangeCheckOperation {
input0: U256,
input1: U256,
input2: U256,
opcode: U256,
result: U256,
},
}

impl Operation {
Expand Down Expand Up @@ -195,11 +208,28 @@ impl Operation {
}
}

pub(crate) fn range_check(
input0: U256,
input1: U256,
input2: U256,
opcode: U256,
result: U256,
) -> Self {
Self::RangeCheckOperation {
input0,
input1,
input2,
opcode,
result,
}
}

/// Gets the result of an arithmetic operation.
pub(crate) fn result(&self) -> U256 {
match self {
Operation::BinaryOperation { result, .. } => *result,
Operation::TernaryOperation { result, .. } => *result,
_ => panic!("This function should not be called for range checks."),
}
}

Expand Down Expand Up @@ -228,6 +258,13 @@ impl Operation {
input2,
result,
} => ternary_op_to_rows(operator.row_filter(), input0, input1, input2, result),
Operation::RangeCheckOperation {
input0,
input1,
input2,
opcode,
result,
} => range_check_to_rows(input0, input1, input2, opcode, result),
}
}
}
Expand Down Expand Up @@ -293,3 +330,21 @@ fn binary_op_to_rows<F: PrimeField64>(
}
}
}

fn range_check_to_rows<F: PrimeField64>(
input0: U256,
input1: U256,
input2: U256,
opcode: U256,
result: U256,
) -> (Vec<F>, Option<Vec<F>>) {
let mut row = vec![F::ZERO; columns::NUM_ARITH_COLUMNS];
row[IS_RANGE_CHECK] = F::ONE;
row[OPCODE_COL] = F::from_canonical_u64(opcode.as_u64());
u256_to_array(&mut row[INPUT_REGISTER_0], input0);
u256_to_array(&mut row[INPUT_REGISTER_1], input1);
u256_to_array(&mut row[INPUT_REGISTER_2], input2);
u256_to_array(&mut row[OUTPUT_REGISTER], result);

(row, None)
}
2 changes: 1 addition & 1 deletion evm/src/byte_packing/columns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) const TIMESTAMP: usize = ADDR_VIRTUAL + 1;
// 32 byte limbs hold a total of 256 bits.
const BYTES_VALUES_START: usize = TIMESTAMP + 1;
// There are `NUM_BYTES` columns used to store the values of the bytes
// that are beeing read/written for an (un)packing operation.
// that are being read/written for an (un)packing operation.
// If `index_bytes(i) == 1`, then all `value_bytes(j) for j <= i` may be non-zero.
pub(crate) const fn value_bytes(i: usize) -> usize {
debug_assert!(i < NUM_BYTES);
Expand Down
7 changes: 5 additions & 2 deletions evm/src/cpu/cpu_stark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ fn ctl_data_binops<F: Field>() -> Vec<Column<F>> {

/// Creates the vector of `Columns` corresponding to the three inputs and
/// one output of a ternary operation. By default, ternary operations use
/// the first three memory channels, and the last one for the result (binary
/// operations do not use the third inputs).
/// the first three memory channels, and the next top of the stack for the
/// result (binary operations do not use the third inputs).
fn ctl_data_ternops<F: Field>() -> Vec<Column<F>> {
let mut res = Column::singles(COL_MAP.mem_channels[0].value).collect_vec();
res.extend(Column::singles(COL_MAP.mem_channels[1].value));
Expand Down Expand Up @@ -115,6 +115,9 @@ pub fn ctl_arithmetic_base_rows<F: Field>() -> TableWithColumns<F> {
COL_MAP.op.fp254_op,
COL_MAP.op.ternary_op,
COL_MAP.op.shift,
COL_MAP.op.prover_input,
COL_MAP.op.syscall,
COL_MAP.op.exception,
])),
)
}
Expand Down
2 changes: 1 addition & 1 deletion evm/src/cpu/docs/out-of-gas.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ When a native instruction (one that is not a syscall) is executed, a constraint

If everything goes smoothly and we have not run out of gas, `gas` should be no more than the gas allowance at the point that we `STOP`, `REVERT`, stack overflow, or whatever. Indeed, because we assume that the gas overflow handler is invoked _as soon as_ we've run out of gas, all these termination methods must verify that `gas` <= allowance, and `PANIC` if this is not the case. This is also true for the out-of-gas handler, which should check that (a) we have not yet run out of gas and (b) we are about to run out of gas, `PANIC`king if either of those does not hold.

When we do run out of gas, however, this event must be handled. Syscalls are responsible for checking that their execution would not cause the transaction to run out of gas. If the syscall detects that it would need to charge more gas than available, it must abort the transaction by jumping to `exc_out_of_gas`, which in turn verifies that the out-of-gas hasn't _already_ occured.
When we do run out of gas, however, this event must be handled. Syscalls are responsible for checking that their execution would not cause the transaction to run out of gas. If the syscall detects that it would need to charge more gas than available, it must abort the transaction by jumping to `exc_out_of_gas`, which in turn verifies that the out-of-gas hasn't _already_ occurred.

Native instructions do this differently. If the prover notices that execution of the instruction would cause an out-of-gas error, it must jump to the appropriate handler instead of executing the instruction. (The handler contains special code that `PANIC`s if the prover invoked it incorrectly.)

Expand Down
1 change: 1 addition & 0 deletions evm/src/cpu/kernel/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub(crate) fn combined_kernel() -> Kernel {
include_str!("asm/core/log.asm"),
include_str!("asm/core/selfdestruct_list.asm"),
include_str!("asm/core/touched_addresses.asm"),
include_str!("asm/core/withdrawals.asm"),
include_str!("asm/core/precompiles/main.asm"),
include_str!("asm/core/precompiles/ecrec.asm"),
include_str!("asm/core/precompiles/sha256.asm"),
Expand Down
15 changes: 13 additions & 2 deletions evm/src/cpu/kernel/asm/core/create_contract_account.asm
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@
DUP1 %mload_trie_data // codehash = account[3]
%eq_const(@EMPTY_STRING_HASH) ISZERO %jumpi(%%error_collision)
// stack: existing_codehash_ptr, address
%sub_const(2) %mload_trie_data // balance = account[1]
%jump(%%do_insert)
%sub_const(1)
%stack (storage_root_ptr, address) -> (storage_root_ptr, 0, storage_root_ptr, 2, address)
// Set the storage root to 0.
%mstore_trie_data
// stack: storage_root_ptr, 2, address
SUB
// stack: nonce_ptr, address
PUSH 1 SWAP1 %mstore_trie_data
// stack: address
PUSH 0 SWAP1 %journal_add_nonce_change
PUSH 0 // success
%jump(%%end)

%%add_account:
// stack: existing_balance, address
Expand All @@ -34,6 +44,7 @@
%get_trie_data_size
// stack: account_ptr, new_acct_value, address
PUSH 0 DUP4 %journal_add_nonce_change
PUSH 0 %append_to_trie_data // key placeholder
PUSH 1 %append_to_trie_data // nonce = 1
// stack: account_ptr, new_acct_value, address
SWAP1 %append_to_trie_data // balance = new_acct_value
Expand Down
2 changes: 1 addition & 1 deletion evm/src/cpu/kernel/asm/core/exception.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// These exception codes are arbitary and assigned by us.
// These exception codes are arbitrary and assigned by us.
global exception_jumptable:
// exception 0: out of gas
JUMPTABLE exc_out_of_gas
Expand Down
25 changes: 25 additions & 0 deletions evm/src/cpu/kernel/asm/core/withdrawals.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
%macro withdrawals
// stack: (empty)
PUSH %%after
%jump(withdrawals)
%%after:
// stack: (empty)
%endmacro

global withdrawals:
// stack: retdest
PROVER_INPUT(withdrawal)
// stack: address, retdest
PROVER_INPUT(withdrawal)
// stack: amount, address, retdest
DUP2 %eq_const(@U256_MAX) %jumpi(withdrawals_end)
SWAP1
// stack: address, amount, retdest
%add_eth
// stack: retdest
%jump(withdrawals)

withdrawals_end:
// stack: amount, address, retdest
%pop2
JUMP
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Returns reverse order divison y/x, modulo N
// Returns reverse order division y/x, modulo N
%macro divr_fp254
// stack: x , y
%inv_fp254
Expand Down
19 changes: 10 additions & 9 deletions evm/src/cpu/kernel/asm/journal/storage_change.asm
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ global revert_storage_change:
// stack: address, slot, prev_value, retdest
SWAP1 %slot_to_storage_key
// stack: storage_key, address, prev_value, retdest
PUSH 64 // storage_key has 64 nibbles
// stack: 64, storage_key, address, prev_value, retdest
DUP3 %smt_read_state
DUP2 %smt_read_state
DUP1 ISZERO %jumpi(panic)
// stack: account_ptr, 64, storage_key, address, prev_value, retdest
// stack: account_ptr, storage_key, address, prev_value, retdest
%add_const(2)
// stack: storage_root_ptr_ptr, 64, storage_key, address, prev_value, retdest
// stack: storage_root_ptr_ptr, storage_key, address, prev_value, retdest
%mload_trie_data
// stack: storage_root_ptr, storage_key, address, prev_value, retdest
%get_trie_data_size
DUP6 %append_to_trie_data
%stack (prev_value_ptr, storage_root_ptr, num_nibbles, storage_key, address, prev_value, retdest) ->
(storage_root_ptr, num_nibbles, storage_key, prev_value_ptr, new_storage_root, address, retdest)
%jump(mpt_insert)
// stack: prev_value_ptr, storage_root_ptr, storage_key, address, prev_value, retdest
PUSH 0 %append_to_trie_data
DUP5 %append_to_trie_data
%stack (prev_value_ptr, storage_root_ptr, storage_key, address, prev_value, retdest) ->
(storage_root_ptr, storage_key, prev_value_ptr, new_storage_root, address, retdest)
%jump(smt_insert)

delete:
// stack: address, slot, prev_value, retdest
Expand Down
Loading

0 comments on commit 5025647

Please sign in to comment.