Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discuss: spanned AST #678

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
816 changes: 518 additions & 298 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions evm_arithmetization/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ keywords.workspace = true
[dependencies]
anyhow.workspace = true
bytes.workspace = true
derive-quote-to-tokens = "0.1.1"
derive-syn-parse = "0.2.0"
env_logger.workspace = true
ethereum-types.workspace = true
hashbrown.workspace = true
Expand All @@ -35,6 +37,8 @@ pest_derive.workspace = true
plonky2 = { workspace = true, features = ["parallel"] }
plonky2_maybe_rayon = { workspace = true, features = ["parallel"] }
plonky2_util.workspace = true
proc-macro2.workspace = true
quote.workspace = true
rand.workspace = true
rand_chacha.workspace = true
rlp.workspace = true
Expand All @@ -46,6 +50,7 @@ sha2.workspace = true
smt_trie = { workspace = true, optional = true }
starky = { workspace = true, features = ["parallel"] }
static_assertions.workspace = true
syn.workspace = true
thiserror.workspace = true
tiny-keccak.workspace = true
tokio.workspace = true
Expand All @@ -56,9 +61,14 @@ zk_evm_common.workspace = true
zk_evm_proc_macro.workspace = true

[dev-dependencies]
camino = "1.1.9"
criterion.workspace = true
glob = "0.3.1"
hex.workspace = true
libtest-mimic = "0.7.3"
pretty_assertions = "1.4.1"
ripemd.workspace = true
syn-miette = "0.3.0"

[features]
default = ["eth_mainnet"]
Expand All @@ -79,6 +89,9 @@ harness = false
name = "fibonacci_25m_gas"
harness = false

[[test]]
name = "parse"
harness = false

# Display math equations properly in documentation
[package.metadata.docs.rs]
Expand Down
12 changes: 6 additions & 6 deletions evm_arithmetization/src/cpu/kernel/asm/beacon_roots.asm
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// EIP-4788: Beacon block root in the EVM
/// <https://eips.ethereum.org/EIPS/eip-4788#pseudocode>
///
/// *NOTE*: This will panic if one of the provided timestamps is zero.
// EIP-4788: Beacon block root in the EVM
// <https://eips.ethereum.org/EIPS/eip-4788#pseudocode>
//
// *NOTE*: This will panic if one of the provided timestamps is zero.

/// Pre-stack: (empty)
/// Post-stack: (empty)
// Pre-stack: (empty)
// Post-stack: (empty)
global set_beacon_root:
// stack: (empty)
PUSH txn_loop
Expand Down
2 changes: 1 addition & 1 deletion evm_arithmetization/src/cpu/kernel/asm/bloom_filter.asm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Implementation of Bloom filters for logs.
// Implementation of Bloom filters for logs.

// Adds a Bloom entry to the transaction Bloom filter and the block Bloom filter.
//
Expand Down
10 changes: 5 additions & 5 deletions evm_arithmetization/src/cpu/kernel/asm/cdk_pre_execution.asm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// CDK-Erigon pre-block execution logic.
/// Reference implementation: `cdk-erigon/core/state/intra_block_state_zkevm.go`.
/// This currently supports the Etrog upgrade.
// CDK-Erigon pre-block execution logic.
// Reference implementation: `cdk-erigon/core/state/intra_block_state_zkevm.go`.
// This currently supports the Etrog upgrade.

/// Pre-stack: (empty)
/// Post-stack: (empty)
// Pre-stack: (empty)
// Post-stack: (empty)
global pre_block_execution:
// stack: (empty)
PUSH txn_loop
Expand Down
42 changes: 21 additions & 21 deletions evm_arithmetization/src/cpu/kernel/asm/core/access_lists.asm
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/// Access lists for addresses and storage keys.
/// The access list is stored in a sorted linked list in SEGMENT_ACCESSED_ADDRESSES for addresses and
/// SEGMENT_ACCESSED_STORAGE_KEYS segment for storage keys. The length of
/// the segments is stored in the global metadata.
/// Both arrays are stored in the kernel memory (context=0).
/// Searching and inserting is done by guessing the predecessor in the list.
/// If the address/storage key isn't found in the array, it is inserted at the end.
// Access lists for addresses and storage keys.
// The access list is stored in a sorted linked list in SEGMENT_ACCESSED_ADDRESSES for addresses and
// SEGMENT_ACCESSED_STORAGE_KEYS segment for storage keys. The length of
// the segments is stored in the global metadata.
// Both arrays are stored in the kernel memory (context=0).
// Searching and inserting is done by guessing the predecessor in the list.
// If the address/storage key isn't found in the array, it is inserted at the end.

// Initialize the set of accessed addresses and storage keys with an empty list of the form (@U256_MAX)⮌
// which is written as [@U256_MAX, @SEGMENT_ACCESSED_ADDRESSES] in SEGMENT_ACCESSED_ADDRESSES
Expand Down Expand Up @@ -89,8 +89,8 @@ global init_access_lists:
%endmacro


/// Inserts the address into the access list if it is not already present.
/// Return 1 if the address was inserted, 0 if it was already present.
// Inserts the address into the access list if it is not already present.
// Return 1 if the address was inserted, 0 if it was already present.
global insert_accessed_addresses:
// stack: addr, retdest
PROVER_INPUT(access_lists::address_insert)
Expand Down Expand Up @@ -172,13 +172,13 @@ insert_new_address:
SWAP1
JUMP

/// Remove the address from the access list.
/// Panics if the address is not in the access list.
/// Otherwise it guesses the node before the address (pred)
/// such that (pred)->(next)->(next_next), where the (next) node
/// stores the address. It writes the link (pred)->(next_next)
/// and (next) is marked as deleted by writing U256_MAX in its
/// next node pointer.
// Remove the address from the access list.
// Panics if the address is not in the access list.
// Otherwise it guesses the node before the address (pred)
// such that (pred)->(next)->(next_next), where the (next) node
// stores the address. It writes the link (pred)->(next_next)
// and (next) is marked as deleted by writing U256_MAX in its
// next node pointer.
global remove_accessed_addresses:
// stack: addr, retdest
PROVER_INPUT(access_lists::address_remove)
Expand Down Expand Up @@ -232,9 +232,9 @@ global remove_accessed_addresses:
// stack: ptr
%endmacro

/// Inserts the storage key into the access list if it is not already present.
/// Return `1, value_ptr` if the storage key was inserted, `0, value_ptr` if it was already present.
/// Callers to this function must ensure the original storage value is stored at `value_ptr`.
// Inserts the storage key into the access list if it is not already present.
// Return `1, value_ptr` if the storage key was inserted, `0, value_ptr` if it was already present.
// Callers to this function must ensure the original storage value is stored at `value_ptr`.
global insert_accessed_storage_keys:
// stack: addr, key, retdest
PROVER_INPUT(access_lists::storage_insert)
Expand Down Expand Up @@ -351,8 +351,8 @@ insert_storage_key:
%journal_add_storage_loaded
JUMP

/// Remove the storage key and its value from the access list.
/// Panics if the key is not in the list.
// Remove the storage key and its value from the access list.
// Panics if the key is not in the list.
global remove_accessed_storage_keys:
// stack: addr, key, retdest
PROVER_INPUT(access_lists::storage_remove)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Self-destruct list.
/// Implemented as an array, with the length stored in the global metadata.
/// Note: This array allows duplicates.
// Self-destruct list.
// Implemented as an array, with the length stored in the global metadata.
// Note: This array allows duplicates.

%macro insert_selfdestruct_list
// stack: addr
Expand All @@ -13,8 +13,8 @@
%mstore_global_metadata(@GLOBAL_METADATA_SELFDESTRUCT_LIST_LEN) // Store new length.
%endmacro

/// Remove one occurrence of the address from the list.
/// No effect if the address is not in the list.
// Remove one occurrence of the address from the list.
// No effect if the address is not in the list.
global remove_selfdestruct_list:
// stack: addr, retdest
%mload_global_metadata(@GLOBAL_METADATA_SELFDESTRUCT_LIST_LEN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
POP
%endmacro

/// Inserts the address into the list if it is not already present.
// Inserts the address into the list if it is not already present.
global insert_touched_addresses:
// stack: addr, retdest
%mload_global_metadata(@GLOBAL_METADATA_TOUCHED_ADDRESSES_LEN)
Expand Down Expand Up @@ -45,8 +45,8 @@ insert_touched_addresses_found:
%stack (i, len, addr, retdest) -> (retdest)
JUMP

/// Remove the address from the list.
/// Panics if the address is not in the list.
// Remove the address from the list.
// Panics if the address is not in the list.
global remove_touched_addresses:
// stack: addr, retdest
%mload_global_metadata(@GLOBAL_METADATA_TOUCHED_ADDRESSES_LEN)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/// miller_data is defined by
/// (1) taking the binary expansion of N254, the order of the elliptic curve group
/// (2) popping the first and last elements, then appending a 0:
/// exp = bin(N254)[1:-1] + [0]
/// (3) counting the lengths of runs of 1s then 0s in exp, e.g.
/// if exp = 1100010011110, then EXP = [(2,3), (1,2), (4,1)]
/// (4) byte encoding each pair (n,m) as follows:
/// miller_data = [(0x20)n + m for (n,m) in EXP]
// miller_data is defined by
// (1) taking the binary expansion of N254, the order of the elliptic curve group
// (2) popping the first and last elements, then appending a 0:
// exp = bin(N254)[1:-1] + [0]
// (3) counting the lengths of runs of 1s then 0s in exp, e.g.
// if exp = 1100010011110, then EXP = [(2,3), (1,2), (4,1)]
// (4) byte encoding each pair (n,m) as follows:
// miller_data = [(0x20)n + m for (n,m) in EXP]

global miller_data:
BYTES 0xdc, 0x22, 0x42, 0x21
Expand All @@ -24,13 +24,13 @@ global miller_data:
BYTES 0x25


/// final_exp first computes y^a4, y^a2, y^a0
/// representing a4, a2, a0 in *little endian* binary, define
/// EXPS4 = [(a4[i], a2[i], a0[i]) for i in 0..len(a4)]
/// EXPS2 = [ (a2[i], a0[i]) for i in len(a4)..len(a2)]
/// EXPS0 = [ a0[i] for i in len(a2)..len(a0)]
/// power_data_n is simply a reverse-order byte encoding of EXPSn
/// where (i,j,k) is sent to (100)i + (10)j + k
// final_exp first computes y^a4, y^a2, y^a0
// representing a4, a2, a0 in *little endian* binary, define
// EXPS4 = [(a4[i], a2[i], a0[i]) for i in 0..len(a4)]
// EXPS2 = [ (a2[i], a0[i]) for i in len(a4)..len(a2)]
// EXPS0 = [ a0[i] for i in len(a2)..len(a0)]
// power_data_n is simply a reverse-order byte encoding of EXPSn
// where (i,j,k) is sent to (100)i + (10)j + k

global power_data_4:
BYTES 111, 010, 011, 111
Expand Down
Loading
Loading