From a00acda4293c3d35f9041dd4834ee23e4c52bbce Mon Sep 17 00:00:00 2001 From: Robin Salen <30937548+Nashtare@users.noreply.github.com> Date: Thu, 27 Jun 2024 20:15:25 +0900 Subject: [PATCH 01/10] fix: add recipient to touched_addresses even when skipping empty transfer (#336) --- evm_arithmetization/src/cpu/kernel/asm/core/transfer.asm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/evm_arithmetization/src/cpu/kernel/asm/core/transfer.asm b/evm_arithmetization/src/cpu/kernel/asm/core/transfer.asm index 6960bf07e..986c4f991 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/core/transfer.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/core/transfer.asm @@ -63,10 +63,11 @@ global deduct_eth_insufficient_balance: // Pre stack: addr, amount, redest // Post stack: (empty) global add_eth: + // stack: addr, amount, retdest + DUP1 %insert_touched_addresses // stack: addr, amount, retdest DUP2 ISZERO %jumpi(add_eth_zero_amount) // stack: addr, amount, retdest - DUP1 %insert_touched_addresses 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. From 1cba914463df2a669c0c740eeee22bc0d25b1157 Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Thu, 27 Jun 2024 08:41:06 -0400 Subject: [PATCH 02/10] fix: Fix PR checking file --- .github/workflows/pr_checking.yml | 62 ++++++++++++++++++++++++------- 1 file changed, 48 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pr_checking.yml b/.github/workflows/pr_checking.yml index 5bed881a3..7799b94cc 100644 --- a/.github/workflows/pr_checking.yml +++ b/.github/workflows/pr_checking.yml @@ -1,22 +1,56 @@ name: PR check on: - pull_request_target: - types: - - opened - - edited - - synchronize + pull_request: + types: [opened, reopened, synchronize] + +permissions: + pull-requests: write jobs: - title: + pr_check: name: Validate PR runs-on: ubuntu-latest - if: ${{ - github.event.pull_request.author_association != 'CONTRIBUTOR' && - github.event.pull_request.author_association != 'MEMBER' && - ( - contains(fromJSON(secrets.RESTRICTED_KEYWORDS), github.event.pull_request.title) || - contains(fromJSON(secrets.RESTRICTED_KEYWORDS), github.event.pull_request.description - ) }} steps: - - run: gh pr close + - name: Set up keywords + id: setup_keywords + run: echo "RESTRICTED_KEYWORDS=$(echo '${{ secrets.RESTRICTED_KEYWORDS }}' | jq -r '.[]' | tr '\n' ' ')" >> $GITHUB_ENV + + - name: Check for spam PR + id: check + run: | + # Initialize variables to track spam presence + title_is_spam=false + description_is_spam=false + + # Check title for spam + for keyword in $RESTRICTED_KEYWORDS; do + if echo "${{ github.event.pull_request.title }}" | grep -i -q "$keyword"; then + title_is_spam=true + break + fi + done + + # Check description for spam + for keyword in $RESTRICTED_KEYWORDS; do + if echo "${{ github.event.pull_request.body }}" | grep -i -q "$keyword"; then + description_is_spam=true + break + fi + done + + # Set the output based on the presence of spam + if [ "$title_is_spam" = true ] || [ "$description_is_spam" = true ]; then + echo "is_spam=true" >> $GITHUB_ENV + else + echo "is_spam=false" >> $GITHUB_ENV + fi + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Close PR if spam are found and author is not a contributor or member + if: ${{ env.is_spam == 'true' && github.event.pull_request.author_association != 'CONTRIBUTOR' && github.event.pull_request.author_association != 'MEMBER' && github.event.pull_request.author_association != 'OWNER' }} + run: gh pr close ${{ github.event.pull_request.number }} --comment "Spam detected" + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 9fd656e216951749be5052fce16871d507910199 Mon Sep 17 00:00:00 2001 From: BGluth Date: Thu, 27 Jun 2024 07:43:42 -0600 Subject: [PATCH 03/10] Fixed leader crashing when `.env` not present (#335) * Fixed crashing when `.env` not present - Was crashing if attempting to run when the `.env` was not present, which is a situation that we probably should not be crashing in. This commit now treats any IO error as the file missing and in these cases continues to run the program. * Requested PR changes for #335 - Also made the error contain the internal error. --- zero_bin/leader/src/main.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/zero_bin/leader/src/main.rs b/zero_bin/leader/src/main.rs index f136f4dbf..74229c1b3 100644 --- a/zero_bin/leader/src/main.rs +++ b/zero_bin/leader/src/main.rs @@ -1,4 +1,4 @@ -use std::env; +use std::{env, io}; use std::{fs::File, path::PathBuf}; use anyhow::Result; @@ -9,7 +9,7 @@ use dotenvy::dotenv; use ops::register; use paladin::runtime::Runtime; use proof_gen::proof_types::GeneratedBlockProof; -use tracing::info; +use tracing::{info, warn}; use zero_bin_common::block_interval::BlockInterval; use crate::client::{client_main, ProofParams}; @@ -36,7 +36,7 @@ fn get_previous_proof(path: Option) -> Result Result<()> { - dotenv().ok(); + load_dotenvy_vars_if_present(); init::tracing(); if env::var("EVM_ARITHMETIZATION_PKG_VER").is_err() { @@ -141,3 +141,18 @@ async fn main() -> Result<()> { Ok(()) } + +/// Attempt to load in the local `.env` if present and set any environment +/// variables specified inside of it. +/// +/// To keep things simple, any IO error we will treat as the file not existing +/// and continue moving on without the `env` variables set. +fn load_dotenvy_vars_if_present() { + match dotenv() { + Ok(_) | Err(dotenvy::Error::Io(io::Error { .. })) => (), + Err(e) => warn!( + "Found local `.env` file but was unable to parse it! (err: {})", + e.to_string() + ), + } +} From 6ed5a784a037e65c0d520e9f0d1e540ed445312a Mon Sep 17 00:00:00 2001 From: Robin Salen <30937548+Nashtare@users.noreply.github.com> Date: Fri, 28 Jun 2024 01:48:30 +0900 Subject: [PATCH 04/10] perf: reduce overhead in final iteration of memset (#339) --- evm_arithmetization/src/cpu/kernel/asm/memory/memset.asm | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/evm_arithmetization/src/cpu/kernel/asm/memory/memset.asm b/evm_arithmetization/src/cpu/kernel/asm/memory/memset.asm index 792aeabc6..2cd50e85a 100644 --- a/evm_arithmetization/src/cpu/kernel/asm/memory/memset.asm +++ b/evm_arithmetization/src/cpu/kernel/asm/memory/memset.asm @@ -32,13 +32,12 @@ memset_finish: %jumpi(memset_bytes_empty) // stack: DST, final_count, retdest - DUP2 PUSH 0 - DUP3 - // stack: DST, 0, final_count, DST, final_count, retdest + SWAP1 + // stack: DST, 0, final_count, retdest %mstore_unpacking - // stack: DST, final_count, retdest - %pop3 + // stack: DST', retdest + POP // stack: retdest JUMP From 65b849f705f6cdec6414c8b2e117892a704f4c1f Mon Sep 17 00:00:00 2001 From: BGluth Date: Thu, 27 Jun 2024 12:06:32 -0600 Subject: [PATCH 05/10] Make leader work no matter what the CWD is (#307) * `prove_rpc.sh` now outputs to a constant dir - Previously took into account the directory that the script was executed from. * `prove_stdio.sh` now works when used from any directory - Previously only worked when executed from the `tools` directory. * Now always uses `tools/circuits` in workspace - Previously, we always looked for the `circuits` directory directly inside our current working directory. Now if we are running within the workspace, we always will look in `zk_evm/zero_bin/tools` instead. - Also note that `zero_bin/.cargo/config.toml` is only read when we are interacting with `cargo` directly (eg. the scripts in `tools/` do not invoke it). * Now also writes other artifacts in `tools/` - Also made sense to write `verify.out`, `leader.out` and `proofs.json` into `zero_bin/tools`. * Made a few other artifacts also get written to `tools/` - Also removed some duplication by moving them to variables. --- zero_bin/.cargo/config.toml | 4 +++ .../common/src/prover_state/persistence.rs | 26 ++++++++++++++----- zero_bin/tools/prove_rpc.sh | 9 +++++-- zero_bin/tools/prove_stdio.sh | 25 +++++++++++++----- 4 files changed, 48 insertions(+), 16 deletions(-) diff --git a/zero_bin/.cargo/config.toml b/zero_bin/.cargo/config.toml index 6859b6af7..b9c0d3375 100644 --- a/zero_bin/.cargo/config.toml +++ b/zero_bin/.cargo/config.toml @@ -2,3 +2,7 @@ # https://github.com/rust-lang/rust/pull/124129 # https://github.com/dtolnay/linkme/pull/88 rustflags = ["-Zlinker-features=-lld"] + +[env] +# If we're running in the project workspace, then we should set the workspace env var so we read/write to/from files relative to the workspace. +CARGO_WORKSPACE_DIR = { value = "", relative = true } diff --git a/zero_bin/common/src/prover_state/persistence.rs b/zero_bin/common/src/prover_state/persistence.rs index cd33b04e0..87eb7d1ae 100644 --- a/zero_bin/common/src/prover_state/persistence.rs +++ b/zero_bin/common/src/prover_state/persistence.rs @@ -17,9 +17,10 @@ use super::{ Config, RecursiveCircuitsForTableSize, SIZE, }; -const CIRCUITS_FOLDER: &str = "./circuits"; +const CIRCUITS_DIR: &str = "circuits/"; const PROVER_STATE_FILE_PREFIX: &str = "prover_state"; const VERIFIER_STATE_FILE_PREFIX: &str = "verifier_state"; +const CARGO_WORKSPACE_DIR_ENV: &str = "CARGO_WORKSPACE_DIR"; fn get_serializers() -> ( DefaultGateSerializer, @@ -72,9 +73,11 @@ pub(crate) trait DiskResource { p: &Self::PathConstrutor, r: &Self::Resource, ) -> Result<(), DiskResourceError> { + let circuits_dir = relative_circuit_dir_path(); + // Create the base folder if non-existent. - if std::fs::metadata(CIRCUITS_FOLDER).is_err() { - std::fs::create_dir(CIRCUITS_FOLDER).map_err(|_| { + if std::fs::metadata(&circuits_dir).is_err() { + std::fs::create_dir(&circuits_dir).map_err(|_| { DiskResourceError::IoError::(std::io::Error::other( "Could not create circuits folder", )) @@ -104,7 +107,7 @@ impl DiskResource for BaseProverResource { fn path(p: &Self::PathConstrutor) -> impl AsRef { format!( "{}/{}_base_{}_{}", - CIRCUITS_FOLDER, + &relative_circuit_dir_path(), PROVER_STATE_FILE_PREFIX, env::var("EVM_ARITHMETIZATION_PKG_VER").unwrap_or("NA".to_string()), p.get_configuration_digest() @@ -140,7 +143,7 @@ impl DiskResource for MonolithicProverResource { fn path(p: &Self::PathConstrutor) -> impl AsRef { format!( "{}/{}_monolithic_{}_{}", - CIRCUITS_FOLDER, + &relative_circuit_dir_path(), PROVER_STATE_FILE_PREFIX, env::var("EVM_ARITHMETIZATION_PKG_VER").unwrap_or("NA".to_string()), p.get_configuration_digest() @@ -175,7 +178,7 @@ impl DiskResource for RecursiveCircuitResource { fn path((circuit_type, size): &Self::PathConstrutor) -> impl AsRef { format!( "{}/{}_{}_{}_{}", - CIRCUITS_FOLDER, + &relative_circuit_dir_path(), PROVER_STATE_FILE_PREFIX, env::var("EVM_ARITHMETIZATION_PKG_VER").unwrap_or("NA".to_string()), circuit_type.as_short_str(), @@ -219,7 +222,7 @@ impl DiskResource for VerifierResource { fn path(p: &Self::PathConstrutor) -> impl AsRef { format!( "{}/{}_{}_{}", - CIRCUITS_FOLDER, + &relative_circuit_dir_path(), VERIFIER_STATE_FILE_PREFIX, env::var("EVM_ARITHMETIZATION_PKG_VER").unwrap_or("NA".to_string()), p.get_configuration_digest() @@ -273,3 +276,12 @@ fn prover_to_disk( Ok(()) } + +/// If we're running in the cargo workspace, then always use the `circuits` +/// directory that lives in `tools/`. Otherwise, just use `circuits` in the +/// current directory. +fn relative_circuit_dir_path() -> String { + env::var(CARGO_WORKSPACE_DIR_ENV) + .map(|p| format!("{}/{}", p, CIRCUITS_DIR)) + .unwrap_or_else(|_| CIRCUITS_DIR.to_string()) +} diff --git a/zero_bin/tools/prove_rpc.sh b/zero_bin/tools/prove_rpc.sh index 971e3b41a..9a0700f22 100755 --- a/zero_bin/tools/prove_rpc.sh +++ b/zero_bin/tools/prove_rpc.sh @@ -37,7 +37,13 @@ else export MEMORY_CIRCUIT_SIZE="17..28" fi -PROOF_OUTPUT_DIR="proofs" +# Force the working directory to always be the `tools/` directory. +TOOLS_DIR=$(dirname $(realpath "$0")) + +# Set the environment variable to let the binary know that we're running in the project workspace. +export CARGO_WORKSPACE_DIR="${TOOLS_DIR}/../" + +PROOF_OUTPUT_DIR="${TOOLS_DIR}/proofs" OUT_LOG_PATH="${PROOF_OUTPUT_DIR}/b$1_$2.log" ALWAYS_WRITE_LOGS=0 # Change this to `1` if you always want logs to be written. TOT_BLOCKS=$(($2-$1+1)) @@ -57,7 +63,6 @@ RUN_VERIFICATION="${RUN_VERIFICATION:-false}" mkdir -p $PROOF_OUTPUT_DIR - if [ $IGNORE_PREVIOUS_PROOFS ]; then # Set checkpoint height to previous block number for the first block in range prev_proof_num=$(($1-1)) diff --git a/zero_bin/tools/prove_stdio.sh b/zero_bin/tools/prove_stdio.sh index b16dd4e5f..43f62dd59 100755 --- a/zero_bin/tools/prove_stdio.sh +++ b/zero_bin/tools/prove_stdio.sh @@ -11,6 +11,17 @@ # We're going to set the parallelism in line with the total cpu count num_procs=$(nproc) +# Force the working directory to always be the `tools/` directory. +TOOLS_DIR=$(dirname $(realpath "$0")) + +LEADER_OUT_PATH="${TOOLS_DIR}/leader.out" +PROOFS_JSON_PATH="${TOOLS_DIR}/proofs.json" +VERIFY_OUT_PATH="${TOOLS_DIR}/verify.out" +TEST_OUT_PATH="${TOOLS_DIR}/test.out" + +# Set the environment variable to let the binary know that we're running in the project workspace. +export CARGO_WORKSPACE_DIR="${TOOLS_DIR}/../" + # Configured Rayon and Tokio with rough defaults export RAYON_NUM_THREADS=$num_procs export TOKIO_WORKER_THREADS=$num_procs @@ -67,12 +78,12 @@ fi # proof. This is useful for quickly testing decoding and all of the # other non-proving code. if [[ $TEST_ONLY == "test_only" ]]; then - cargo run --release --features test_only --bin leader -- --runtime in-memory --load-strategy on-demand stdio < $INPUT_FILE | tee test.out - if grep -q 'All proof witnesses have been generated successfully.' test.out; then + cargo run --release --features test_only --bin leader -- --runtime in-memory --load-strategy on-demand stdio < $INPUT_FILE | tee $TEST_OUT_PATH + if grep -q 'All proof witnesses have been generated successfully.' $TEST_OUT_PATH; then echo -e "\n\nSuccess - Note this was just a test, not a proof" exit else - echo "Failed to create proof witnesses. See test.out for more details." + echo "Failed to create proof witnesses. See \"zk_evm/tools/test.out\" for more details." exit 1 fi fi @@ -80,14 +91,14 @@ fi cargo build --release --jobs "$num_procs" start_time=$(date +%s%N) -../../target/release/leader --runtime in-memory --load-strategy on-demand stdio < $INPUT_FILE | tee leader.out +"${TOOLS_DIR}/../../target/release/leader" --runtime in-memory --load-strategy on-demand stdio < $INPUT_FILE | tee $LEADER_OUT_PATH end_time=$(date +%s%N) -tail -n 1 leader.out > proofs.json +tail -n 1 $LEADER_OUT_PATH > $PROOFS_JSON_PATH -../../target/release/verifier -f proofs.json | tee verify.out +"${TOOLS_DIR}/../../target/release/verifier" -f $PROOFS_JSON_PATH | tee $VERIFY_OUT_PATH -if grep -q 'All proofs verified successfully!' verify.out; then +if grep -q 'All proofs verified successfully!' $VERIFY_OUT_PATH; then duration_ns=$((end_time - start_time)) duration_sec=$(echo "$duration_ns / 1000000000" | bc -l) echo "Success!" From 7351da556d64326efef8de2f685fdfed8f584d33 Mon Sep 17 00:00:00 2001 From: BGluth Date: Thu, 27 Jun 2024 15:05:44 -0600 Subject: [PATCH 06/10] Cleanup/clippy and update pass (#341) * Ran `cargo update` * Ran `cargo upgrade --incompatible --recursive` * `Cargo machete` pass * Added in missed cleanup request from PR #335 * Requested PR changes for #341 --- Cargo.lock | 486 ++++++++++------------------------- Cargo.toml | 56 ++-- mpt_trie/Cargo.toml | 3 +- proof_gen/Cargo.toml | 1 - smt_trie/Cargo.toml | 18 -- trace_decoder/Cargo.toml | 4 - zero_bin/leader/src/main.rs | 5 +- zero_bin/rpc/Cargo.toml | 5 - zero_bin/verifier/Cargo.toml | 1 - zero_bin/worker/Cargo.toml | 3 +- 10 files changed, 169 insertions(+), 413 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4ef8e1ef3..57cc03db3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -74,9 +74,9 @@ dependencies = [ [[package]] name = "alloy-chains" -version = "0.1.21" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd47e5f8545bdf53beb545d3c039b4afa16040bdf69c50100581579b08776afd" +checksum = "1752d7d62e2665da650a36d84abbf239f812534475d51f072a49a533513b7cdd" dependencies = [ "num_enum", "strum", @@ -223,7 +223,7 @@ checksum = "8037e03c7f462a063f28daec9fda285a9a89da003c552f8637a80b9c8fd96241" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -319,7 +319,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -335,7 +335,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", "syn-solidity", "tiny-keccak", ] @@ -351,7 +351,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", "syn-solidity", ] @@ -678,7 +678,7 @@ checksum = "7378575ff571966e99a744addeff0bff98b8ada0dedf1956d59e634db95eaac1" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", "synstructure", ] @@ -690,7 +690,7 @@ checksum = "7b18050c2cd6fe86c3a76584ef5e0baf286d038cda203eb6223df2cc413565f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -834,7 +834,7 @@ checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -851,7 +851,7 @@ checksum = "c6fa2087f2753a7da8cc1c0dbfcf89579dd57458e36769de5ac750b4671737ca" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -877,7 +877,7 @@ checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -888,9 +888,9 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "aws-lc-rs" -version = "1.7.3" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7d844e282b4b56750b2d4e893b2205581ded8709fddd2b6aa5418c150ca877" +checksum = "a8a47f2fb521b70c11ce7369a6c5fa4bd6af7e5d62ec06303875bafe7c6ba245" dependencies = [ "aws-lc-sys", "mirai-annotations", @@ -900,9 +900,9 @@ dependencies = [ [[package]] name = "aws-lc-sys" -version = "0.18.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3a2c29203f6bf296d01141cc8bb9dbd5ecd4c27843f2ee0767bcd5985a927da" +checksum = "2927c7af777b460b7ccd95f8b67acd7b4c04ec8896bf0c8e80ba30523cffc057" dependencies = [ "bindgen", "cc", @@ -1021,10 +1021,10 @@ version = "0.69.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "cexpr", "clang-sys", - "itertools 0.12.1", + "itertools 0.11.0", "lazy_static", "lazycell", "log", @@ -1034,7 +1034,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.66", + "syn 2.0.68", "which", ] @@ -1061,9 +1061,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "bitvec" @@ -1178,9 +1178,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.99" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" +checksum = "ac367972e516d45567c7eafc73d24e1c193dcf200a8d94e9db7b3d38b349572d" dependencies = [ "jobserver", "libc", @@ -1294,7 +1294,7 @@ dependencies = [ "heck 0.5.0", "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -1578,7 +1578,7 @@ dependencies = [ "proc-macro2", "quote", "strsim", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -1589,7 +1589,7 @@ checksum = "733cabb43482b1a1b53eee8583c2b9e8684d592215ea83efd305dd31bc2f0178" dependencies = [ "darling_core", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -1646,7 +1646,7 @@ checksum = "5fe87ce4529967e0ba1dcf8450bab64d97dfd5010a6256187ffe2e43e6f0e049" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -1680,7 +1680,7 @@ dependencies = [ "proc-macro2", "quote", "rustc_version 0.4.0", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -1715,13 +1715,13 @@ dependencies = [ [[package]] name = "displaydoc" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "487585f4d0c6655fe74905e2504d8ad6908e4db67f744eb140876906c2f3175d" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -1758,9 +1758,9 @@ dependencies = [ [[package]] name = "either" -version = "1.12.0" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "elliptic-curve" @@ -1796,7 +1796,7 @@ dependencies = [ "heck 0.4.1", "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -1807,7 +1807,17 @@ checksum = "6fd000fd6988e73bbe993ea3db9b1aa64906ab88766d654973924340c8cddb42" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", +] + +[[package]] +name = "env_filter" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea" +dependencies = [ + "log", + "regex", ] [[package]] @@ -1823,6 +1833,19 @@ dependencies = [ "termcolor", ] +[[package]] +name = "env_logger" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "humantime", + "log", +] + [[package]] name = "equivalent" version = "1.0.1" @@ -1914,7 +1937,7 @@ dependencies = [ "anyhow", "bytes", "criterion", - "env_logger", + "env_logger 0.11.3", "ethereum-types", "hashbrown 0.14.5", "hex", @@ -2153,7 +2176,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -2478,124 +2501,6 @@ dependencies = [ "cc", ] -[[package]] -name = "icu_collections" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" -dependencies = [ - "displaydoc", - "yoke", - "zerofrom", - "zerovec", -] - -[[package]] -name = "icu_locid" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" -dependencies = [ - "displaydoc", - "litemap", - "tinystr", - "writeable", - "zerovec", -] - -[[package]] -name = "icu_locid_transform" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" -dependencies = [ - "displaydoc", - "icu_locid", - "icu_locid_transform_data", - "icu_provider", - "tinystr", - "zerovec", -] - -[[package]] -name = "icu_locid_transform_data" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" - -[[package]] -name = "icu_normalizer" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" -dependencies = [ - "displaydoc", - "icu_collections", - "icu_normalizer_data", - "icu_properties", - "icu_provider", - "smallvec", - "utf16_iter", - "utf8_iter", - "write16", - "zerovec", -] - -[[package]] -name = "icu_normalizer_data" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" - -[[package]] -name = "icu_properties" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f8ac670d7422d7f76b32e17a5db556510825b29ec9154f235977c9caba61036" -dependencies = [ - "displaydoc", - "icu_collections", - "icu_locid_transform", - "icu_properties_data", - "icu_provider", - "tinystr", - "zerovec", -] - -[[package]] -name = "icu_properties_data" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" - -[[package]] -name = "icu_provider" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" -dependencies = [ - "displaydoc", - "icu_locid", - "icu_provider_macros", - "stable_deref_trait", - "tinystr", - "writeable", - "yoke", - "zerofrom", - "zerovec", -] - -[[package]] -name = "icu_provider_macros" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] - [[package]] name = "ident_case" version = "1.0.1" @@ -2604,14 +2509,12 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "1.0.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4716a3a0933a1d01c2f72450e89596eb51dd34ef3c211ccd875acdf1f8fe47ed" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ - "icu_normalizer", - "icu_properties", - "smallvec", - "utf8_iter", + "unicode-bidi", + "unicode-normalization", ] [[package]] @@ -2765,15 +2668,6 @@ dependencies = [ "either", ] -[[package]] -name = "itertools" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" -dependencies = [ - "either", -] - [[package]] name = "itertools" version = "0.13.0" @@ -2894,9 +2788,9 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "lazycell" @@ -2937,9 +2831,9 @@ checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libloading" -version = "0.8.3" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" +checksum = "e310b3a6b5907f99202fcdb4960ff45b93735d7c7d96b760fcff8db2dc0e103d" dependencies = [ "cfg-if", "windows-targets 0.52.5", @@ -2968,7 +2862,7 @@ checksum = "f8dccda732e04fa3baf2e17cf835bfe2601c7c2edafd64417c627dabae3a8cda" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -2983,12 +2877,6 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" -[[package]] -name = "litemap" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "643cb0b8d4fcc284004d5fd0d67ccf61dfffadb7f75e1e71bc420f4688a3a704" - [[package]] name = "lock_api" version = "0.4.12" @@ -3089,7 +2977,6 @@ dependencies = [ "impl-serde", "keccak-hash 0.10.0", "log", - "num", "num-traits", "parking_lot", "pretty_env_logger", @@ -3248,7 +3135,7 @@ checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -3287,7 +3174,7 @@ version = "0.10.64" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "cfg-if", "foreign-types", "libc", @@ -3304,7 +3191,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -3406,7 +3293,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af25dcb10b7c0ce99abee8694e2e79e4787d7f778b9339dc5a50ba6fc45e5cc9" dependencies = [ "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -3526,7 +3413,7 @@ dependencies = [ "pest_meta", "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -3557,7 +3444,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -3786,7 +3673,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "865724d4dbe39d9f3dd3b52b88d859d66bcb2d6a0acfd5ea68a65fb66d4bdc1c" dependencies = [ - "env_logger", + "env_logger 0.10.2", "log", ] @@ -3797,7 +3684,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -3858,9 +3745,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.85" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] @@ -3869,7 +3756,6 @@ dependencies = [ name = "proof_gen" version = "0.2.0" dependencies = [ - "ethereum-types", "evm_arithmetization", "log", "paste", @@ -3879,13 +3765,13 @@ dependencies = [ [[package]] name = "proptest" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" +checksum = "b4c2511913b88df1637da85cc8d96ec8e43a3f8bb8ccb71ee1ac240d6f3df58d" dependencies = [ "bit-set", "bit-vec", - "bitflags 2.5.0", + "bitflags 2.6.0", "lazy_static", "num-traits", "rand", @@ -4023,7 +3909,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c82cf8cff14456045f55ec4241383baeff27af886adb72ffb2162f99911de0fd" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", ] [[package]] @@ -4173,19 +4059,14 @@ dependencies = [ "clap", "evm_arithmetization", "futures", - "hex", - "hex-literal", - "itertools 0.13.0", "mpt_trie", "primitive-types 0.12.2", "prover", "serde", "serde_json", - "thiserror", "tokio", "tower", "trace_decoder", - "tracing", "tracing-subscriber", "url", "zero_bin_common", @@ -4286,7 +4167,7 @@ version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "errno", "libc", "linux-raw-sys 0.4.14", @@ -4450,7 +4331,7 @@ version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "core-foundation", "core-foundation-sys", "libc", @@ -4508,14 +4389,14 @@ checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.118" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "d947f6b3163d8857ea16c4fa0dd4840d52f3041039a85decd46867eb1abef2e4" dependencies = [ "itoa", "ryu", @@ -4580,7 +4461,7 @@ dependencies = [ "darling", "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -4668,25 +4549,11 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" name = "smt_trie" version = "0.1.0" dependencies = [ - "bytes", - "enum-as-inner", - "eth_trie", "ethereum-types", - "hex", "hex-literal", - "keccak-hash 0.10.0", - "log", - "num-traits", - "parking_lot", "plonky2", - "pretty_env_logger", "rand", - "rlp", - "rlp-derive", "serde", - "serde_json", - "thiserror", - "uint", ] [[package]] @@ -4765,9 +4632,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "strum" -version = "0.26.2" +version = "0.26.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d8cec3501a5194c432b2b7976db6b7d10ec95c253208b45f83f7136aa985e29" +checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" dependencies = [ "strum_macros", ] @@ -4782,14 +4649,14 @@ dependencies = [ "proc-macro2", "quote", "rustversion", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" @@ -4804,9 +4671,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.66" +version = "2.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "901fa70d88b9d6c98022e23b4136f9f3e54e4662c3bc1bd1d84a42a9a0f0c1e9" dependencies = [ "proc-macro2", "quote", @@ -4822,7 +4689,7 @@ dependencies = [ "paste", "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -4845,7 +4712,7 @@ checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -4904,7 +4771,7 @@ checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -4966,16 +4833,6 @@ dependencies = [ "crunchy", ] -[[package]] -name = "tinystr" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" -dependencies = [ - "displaydoc", - "zerovec", -] - [[package]] name = "tinytemplate" version = "1.2.1" @@ -4986,6 +4843,21 @@ dependencies = [ "serde_json", ] +[[package]] +name = "tinyvec" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c55115c6fbe2d2bef26eb09ad74bde02d8255476fc0c7b515ef09fbb35742d82" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.38.0" @@ -5024,7 +4896,7 @@ checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -5153,22 +5025,18 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" name = "trace_decoder" version = "0.4.0" dependencies = [ - "bytes", "ciborium", - "ciborium-io", "criterion", "enum-as-inner", "enumn", "ethereum-types", "evm_arithmetization", "hex", - "hex-literal", "keccak-hash 0.10.0", "log", "mpt_trie", "pretty_env_logger", "rlp", - "rlp-derive", "serde", "serde_json", "serde_with", @@ -5195,7 +5063,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", ] [[package]] @@ -5273,12 +5141,27 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "unicode-normalization" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" +dependencies = [ + "tinyvec", +] + [[package]] name = "unroll" version = "0.1.5" @@ -5297,27 +5180,15 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.1" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7c25da092f0a868cdf09e8674cd3b7ef3a7d92a24253e663a2fb85e2496de56" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna", "percent-encoding", ] -[[package]] -name = "utf16_iter" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" - -[[package]] -name = "utf8_iter" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" - [[package]] name = "utf8parse" version = "0.2.2" @@ -5326,9 +5197,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.8.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" +checksum = "5de17fd2f7da591098415cff336e12965a28061ddace43b59cb3c430179c9439" dependencies = [ "getrandom", "rand", @@ -5355,7 +5226,6 @@ dependencies = [ "clap", "dotenvy", "proof_gen", - "serde", "serde_json", "serde_path_to_error", "tracing", @@ -5430,7 +5300,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", "wasm-bindgen-shared", ] @@ -5464,7 +5334,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -5725,23 +5595,10 @@ dependencies = [ "ops", "paladin-core", "tokio", - "tracing", "tracing-subscriber", "zero_bin_common", ] -[[package]] -name = "write16" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" - -[[package]] -name = "writeable" -version = "0.5.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" - [[package]] name = "wyz" version = "0.5.1" @@ -5779,30 +5636,6 @@ dependencies = [ "time", ] -[[package]] -name = "yoke" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c5b1314b079b0930c31e3af543d8ee1757b1951ae1e1565ec704403a7240ca5" -dependencies = [ - "serde", - "stable_deref_trait", - "yoke-derive", - "zerofrom", -] - -[[package]] -name = "yoke-derive" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28cc31741b18cb6f1d5ff12f5b7523e3d6eb0852bbbad19d73905511d9849b95" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", - "synstructure", -] - [[package]] name = "zero_bin_common" version = "0.1.0" @@ -5839,28 +5672,7 @@ checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", -] - -[[package]] -name = "zerofrom" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ec111ce797d0e0784a1116d0ddcdbea84322cd79e5d5ad173daeba4f93ab55" -dependencies = [ - "zerofrom-derive", -] - -[[package]] -name = "zerofrom-derive" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ea7b4a3637ea8669cedf0f1fd5c286a17f3de97b8dd5a70a6c167a1730e63a5" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", - "synstructure", + "syn 2.0.68", ] [[package]] @@ -5880,27 +5692,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", -] - -[[package]] -name = "zerovec" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb2cc8827d6c0994478a15c53f374f46fbd41bea663d809b14744bc42e6b109c" -dependencies = [ - "yoke", - "zerofrom", - "zerovec-derive", -] - -[[package]] -name = "zerovec-derive" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97cf56601ee5052b4417d90c8755c6683473c926039908196cf35d99f893ebe7" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", + "syn 2.0.68", ] diff --git a/Cargo.toml b/Cargo.toml index 5f254ba8a..0bd84a714 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,23 +36,23 @@ alloy = { git = "https://github.com/alloy-rs/alloy", tag='v0.1.1', default-featu "transport-http", "rpc-types-debug" ] } -anyhow = "1.0.40" +anyhow = "1.0.86" async-stream = "0.3.5" -axum = "0.7.4" -bytes = "1.5.0" -ciborium = "0.2.1" -ciborium-io = "0.2.1" -clap = { version = "4.4.6", features = ["derive", "env"] } +axum = "0.7.5" +bytes = "1.6.0" +ciborium = "0.2.2" +ciborium-io = "0.2.2" +clap = { version = "4.5.7", features = ["derive", "env"] } criterion = "0.5.1" dotenvy = "0.15.7" enum-as-inner = "0.6.0" -enumn = "0.1.12" -env_logger = "0.10.0" +enumn = "0.1.13" +env_logger = "0.11.3" ethereum-types = "0.14.1" eth_trie = "0.4.0" evm_arithmetization = { path = "evm_arithmetization", version = "0.2.0" } -futures = "0.3.29" -hashbrown = "0.14.0" +futures = "0.3.30" +hashbrown = "0.14.5" hex = "0.4.3" hex-literal = "0.4.1" impl-codec = "0.6.0" @@ -61,17 +61,17 @@ impl-rlp = "0.3.0" impl-serde = "0.4.0" itertools = "0.13.0" keccak-hash = "0.10.0" -log = "0.4.20" +log = "0.4.21" mpt_trie = { path = "mpt_trie", version = "0.3.0" } -num = "0.4.1" -num-bigint = "0.4.3" +num = "0.4.3" +num-bigint = "0.4.5" num-traits = "0.2.19" -once_cell = "1.13.0" +once_cell = "1.19.0" paladin-core = "0.4.2" -parking_lot = "0.12.1" -paste = "1.0.14" -pest = "2.1.3" -pest_derive = "2.1.0" +parking_lot = "0.12.3" +paste = "1.0.15" +pest = "2.7.10" +pest_derive = "2.7.10" pretty_env_logger = "0.5.0" proof_gen = { path = "proof_gen", version = "0.2.0" } rand = "0.8.5" @@ -79,24 +79,24 @@ rand_chacha = "0.3.1" ripemd = "0.1.3" rlp = "0.5.2" rlp-derive = "0.1.0" -ruint = "1.12.1" -serde = "1.0.166" -serde_json = "1.0.96" -serde_path_to_error = "0.1.14" -serde_with = "3.4.0" +ruint = "1.12.3" +serde = "1.0.203" +serde_json = "1.0.118" +serde_path_to_error = "0.1.16" +serde_with = "3.8.1" smt_trie = { path = "smt_trie", version = "0.1.0" } -sha2 = "0.10.6" +sha2 = "0.10.8" static_assertions = "1.1.0" -thiserror = "1.0.49" +thiserror = "1.0.61" tiny-keccak = "2.0.2" -tokio = { version = "1.33.0", features = ["full"] } -toml = "0.8.12" +tokio = { version = "1.38.0", features = ["full"] } +toml = "0.8.14" tower = "0.4" trace_decoder = { path = "trace_decoder", version = "0.4.0" } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } uint = "0.9.5" -url = "2.5.0" +url = "2.5.2" # zero-bin related dependencies ops = { path = "zero_bin/ops" } diff --git a/mpt_trie/Cargo.toml b/mpt_trie/Cargo.toml index a2038fc86..46a14df26 100644 --- a/mpt_trie/Cargo.toml +++ b/mpt_trie/Cargo.toml @@ -22,7 +22,6 @@ keccak-hash = { workspace = true } parking_lot = { workspace = true, features = ["serde"] } thiserror = { workspace = true } log = { workspace = true } -num = { workspace = true, optional = true } num-traits = { workspace = true } uint = { workspace = true } rlp = { workspace = true } @@ -41,7 +40,7 @@ serde_json = { workspace = true } [features] default = ["trie_debug"] -trie_debug = ["num"] +trie_debug = [] [lib] doc-scrape-examples = true diff --git a/proof_gen/Cargo.toml b/proof_gen/Cargo.toml index 11f5fe319..b5c9169c7 100644 --- a/proof_gen/Cargo.toml +++ b/proof_gen/Cargo.toml @@ -10,7 +10,6 @@ homepage.workspace = true keywords.workspace = true [dependencies] -ethereum-types = { workspace = true } log = { workspace = true } paste = { workspace = true } plonky2 = { workspace = true } diff --git a/smt_trie/Cargo.toml b/smt_trie/Cargo.toml index fb1335350..f3008c5f7 100644 --- a/smt_trie/Cargo.toml +++ b/smt_trie/Cargo.toml @@ -14,26 +14,8 @@ keywords.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bytes = { workspace = true } -enum-as-inner = { workspace = true } ethereum-types = { workspace = true } -hex = { workspace = true } hex-literal = { workspace = true } -keccak-hash = { workspace = true } -log = { workspace = true } -num-traits = { workspace = true } -parking_lot = { workspace = true, features = ["serde"] } plonky2 = { workspace = true } rand = { workspace = true } -rlp = { workspace = true } serde = { workspace = true, features = ["derive", "rc"] } -thiserror = { workspace = true } -uint = { workspace = true } - - -[dev-dependencies] -eth_trie = "0.4.0" -pretty_env_logger = "0.5.0" -rlp-derive = { workspace = true } -serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true } diff --git a/trace_decoder/Cargo.toml b/trace_decoder/Cargo.toml index d4a3629b3..0155e8126 100644 --- a/trace_decoder/Cargo.toml +++ b/trace_decoder/Cargo.toml @@ -10,18 +10,14 @@ homepage.workspace = true keywords.workspace = true [dependencies] -bytes = { workspace = true } ciborium = { workspace = true } -ciborium-io = { workspace = true } enum-as-inner = { workspace = true } enumn = { workspace = true } ethereum-types = { workspace = true } hex = { workspace = true } -hex-literal = { workspace = true } keccak-hash = { workspace = true } log = { workspace = true } rlp = { workspace = true } -rlp-derive = { workspace = true } serde = { workspace = true } serde_with = { workspace = true } thiserror = { workspace = true } diff --git a/zero_bin/leader/src/main.rs b/zero_bin/leader/src/main.rs index 74229c1b3..a2c7020f1 100644 --- a/zero_bin/leader/src/main.rs +++ b/zero_bin/leader/src/main.rs @@ -150,9 +150,6 @@ async fn main() -> Result<()> { fn load_dotenvy_vars_if_present() { match dotenv() { Ok(_) | Err(dotenvy::Error::Io(io::Error { .. })) => (), - Err(e) => warn!( - "Found local `.env` file but was unable to parse it! (err: {})", - e.to_string() - ), + Err(e) => warn!("Found local `.env` file but was unable to parse it! (err: {e})",), } } diff --git a/zero_bin/rpc/Cargo.toml b/zero_bin/rpc/Cargo.toml index 9551348b8..f52ccde62 100644 --- a/zero_bin/rpc/Cargo.toml +++ b/zero_bin/rpc/Cargo.toml @@ -10,7 +10,6 @@ categories.workspace = true [dependencies] tokio = { workspace = true } -tracing = { workspace = true } tracing-subscriber = { workspace = true } anyhow = { workspace = true } serde = { workspace = true } @@ -19,12 +18,8 @@ serde_json = { workspace = true } clap = { workspace = true } evm_arithmetization = { workspace = true } mpt_trie = { workspace = true } -thiserror = { workspace = true } alloy.workspace = true futures = { workspace = true } -hex = { workspace = true } -hex-literal = { workspace = true } -itertools = { workspace = true } url = { workspace = true } __compat_primitive_types = { version = "0.12.2", package = "primitive-types" } tower = { workspace = true, features = ["retry"] } diff --git a/zero_bin/verifier/Cargo.toml b/zero_bin/verifier/Cargo.toml index cbfb0123c..40dd297b7 100644 --- a/zero_bin/verifier/Cargo.toml +++ b/zero_bin/verifier/Cargo.toml @@ -10,7 +10,6 @@ tracing = { workspace = true } tracing-subscriber = { workspace = true } dotenvy = { workspace = true } anyhow = { workspace = true } -serde = { workspace = true } serde_json = { workspace = true } serde_path_to_error = { workspace = true } proof_gen = { workspace = true } diff --git a/zero_bin/worker/Cargo.toml b/zero_bin/worker/Cargo.toml index 90f13bd14..16d55ef29 100644 --- a/zero_bin/worker/Cargo.toml +++ b/zero_bin/worker/Cargo.toml @@ -12,7 +12,6 @@ categories.workspace = true paladin-core = { workspace = true } anyhow = { workspace = true } dotenvy = { workspace = true } -tracing = { workspace = true } tracing-subscriber = { workspace = true } clap = { workspace = true } tokio = { workspace = true } @@ -22,4 +21,4 @@ ops = { workspace = true } zero_bin_common = { workspace = true } [target.'cfg(not(target_env = "msvc"))'.dependencies] -jemallocator = "0.5.0" +jemallocator = "0.5.4" From 39f4d8f5d6f5ca91aafe86d5663aa3240fd0d77e Mon Sep 17 00:00:00 2001 From: Robin Salen Date: Fri, 28 Jun 2024 15:56:18 -0400 Subject: [PATCH 07/10] fix: get PR check workflow to work properly --- .github/workflows/pr_checking.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr_checking.yml b/.github/workflows/pr_checking.yml index 7799b94cc..497a17208 100644 --- a/.github/workflows/pr_checking.yml +++ b/.github/workflows/pr_checking.yml @@ -50,7 +50,7 @@ jobs: uses: actions/checkout@v4 - name: Close PR if spam are found and author is not a contributor or member - if: ${{ env.is_spam == 'true' && github.event.pull_request.author_association != 'CONTRIBUTOR' && github.event.pull_request.author_association != 'MEMBER' && github.event.pull_request.author_association != 'OWNER' }} + if: ${{ env.is_spam == 'true' && github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' }} run: gh pr close ${{ github.event.pull_request.number }} --comment "Spam detected" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} From d81d68380e1209030c91508adcb9007c47441fdb Mon Sep 17 00:00:00 2001 From: Gio <102917377+gio256@users.noreply.github.com> Date: Fri, 28 Jun 2024 20:07:11 -0600 Subject: [PATCH 08/10] Add `Columns` and `DerefColumns` derive macros (#315) * Add Columns and DerefColumns derive macros * Remove derive from workspace members * Add publish=false for derive * Add tests for derive macros * Update comments for derive macros * Add derive tests to CI * rename derive to proc_macro * Clarify comments --- .github/workflows/ci.yml | 25 ++++ Cargo.lock | 25 ++++ Cargo.toml | 8 ++ evm_arithmetization/Cargo.toml | 1 + evm_arithmetization/src/cpu/columns/mod.rs | 69 +-------- evm_arithmetization/src/cpu/columns/ops.rs | 41 +----- .../src/keccak_sponge/columns.rs | 48 +------ evm_arithmetization/src/util.rs | 8 -- proc_macro/Cargo.toml | 22 +++ proc_macro/src/common.rs | 41 ++++++ proc_macro/src/impls/columns.rs | 133 ++++++++++++++++++ proc_macro/src/impls/deref_columns.rs | 43 ++++++ proc_macro/src/impls/mod.rs | 2 + proc_macro/src/lib.rs | 47 +++++++ proc_macro/tests/compile/mod.rs | 26 ++++ proc_macro/tests/compile/test_impls.rs | 34 +++++ proc_macro/tests/compile_fail/not_repr_c.rs | 9 ++ .../tests/compile_fail/not_repr_c.stderr | 8 ++ .../tests/compile_fail/not_repr_c_deref.rs | 9 ++ .../compile_fail/not_repr_c_deref.stderr | 8 ++ proc_macro/tests/compile_fail/not_struct.rs | 10 ++ .../tests/compile_fail/not_struct.stderr | 10 ++ .../tests/compile_fail/not_struct_deref.rs | 10 ++ .../compile_fail/not_struct_deref.stderr | 10 ++ proc_macro/tests/compiletest.rs | 14 ++ 25 files changed, 504 insertions(+), 157 deletions(-) create mode 100644 proc_macro/Cargo.toml create mode 100644 proc_macro/src/common.rs create mode 100644 proc_macro/src/impls/columns.rs create mode 100644 proc_macro/src/impls/deref_columns.rs create mode 100644 proc_macro/src/impls/mod.rs create mode 100644 proc_macro/src/lib.rs create mode 100644 proc_macro/tests/compile/mod.rs create mode 100644 proc_macro/tests/compile/test_impls.rs create mode 100644 proc_macro/tests/compile_fail/not_repr_c.rs create mode 100644 proc_macro/tests/compile_fail/not_repr_c.stderr create mode 100644 proc_macro/tests/compile_fail/not_repr_c_deref.rs create mode 100644 proc_macro/tests/compile_fail/not_repr_c_deref.stderr create mode 100644 proc_macro/tests/compile_fail/not_struct.rs create mode 100644 proc_macro/tests/compile_fail/not_struct.stderr create mode 100644 proc_macro/tests/compile_fail/not_struct_deref.rs create mode 100644 proc_macro/tests/compile_fail/not_struct_deref.stderr create mode 100644 proc_macro/tests/compiletest.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c55c157d..da2a3d615 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -151,6 +151,31 @@ jobs: CARGO_INCREMENTAL: 1 RUST_BACKTRACE: 1 + test_zk_evm_proc_macro: + name: Test zk_evm_proc_macro + runs-on: ubuntu-latest + timeout-minutes: 30 + if: "! contains(toJSON(github.event.commits.*.message), '[skip-ci]')" + steps: + - name: Checkout sources + uses: actions/checkout@v4 + + - name: Install nightly toolchain + uses: dtolnay/rust-toolchain@nightly + + - name: Set up rust cache + uses: Swatinem/rust-cache@v2 + with: + cache-on-failure: true + + - name: Test in proc_macro subdirectory + run: cargo test --manifest-path proc_macro/Cargo.toml + env: + RUSTFLAGS: -Copt-level=3 -Cdebug-assertions -Coverflow-checks=y -Cdebuginfo=0 + RUST_LOG: 1 + CARGO_INCREMENTAL: 1 + RUST_BACKTRACE: 1 + simple_proof_regular: name: Execute bash script to generate and verify a proof for a small block. runs-on: zero-ci diff --git a/Cargo.lock b/Cargo.lock index 57cc03db3..977623c01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1965,6 +1965,7 @@ dependencies = [ "starky", "static_assertions", "tiny-keccak", + "zk_evm_proc_macro", ] [[package]] @@ -5111,6 +5112,20 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" +[[package]] +name = "trybuild" +version = "1.0.96" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33a5f13f11071020bb12de7a16b925d2d58636175c20c11dc5f96cb64bb6c9b3" +dependencies = [ + "glob", + "serde", + "serde_derive", + "serde_json", + "termcolor", + "toml", +] + [[package]] name = "typenum" version = "1.17.0" @@ -5694,3 +5709,13 @@ dependencies = [ "quote", "syn 2.0.68", ] + +[[package]] +name = "zk_evm_proc_macro" +version = "0.1.0" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.66", + "trybuild", +] diff --git a/Cargo.toml b/Cargo.toml index 0bd84a714..0d0f0d4a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ members = ["mpt_trie", "proof_gen", "trace_decoder", "evm_arithmetization", + "proc_macro", "zero_bin/leader", "zero_bin/worker", "zero_bin/common", @@ -109,3 +110,10 @@ plonky2 = "0.2.2" plonky2_maybe_rayon = "0.2.0" plonky2_util = "0.2.0" starky = "0.4.0" + +# proc macro related dependencies +proc-macro2 = "1.0" +quote = "1.0" +syn = "2.0" +trybuild = "1.0" +zk_evm_proc_macro = { path = "proc_macro" } diff --git a/evm_arithmetization/Cargo.toml b/evm_arithmetization/Cargo.toml index 9ae67e0f0..8d98c214b 100644 --- a/evm_arithmetization/Cargo.toml +++ b/evm_arithmetization/Cargo.toml @@ -45,6 +45,7 @@ serde_json = { workspace = true } # Local dependencies mpt_trie = { workspace = true } +zk_evm_proc_macro = { workspace = true } [dev-dependencies] criterion = { workspace = true } diff --git a/evm_arithmetization/src/cpu/columns/mod.rs b/evm_arithmetization/src/cpu/columns/mod.rs index d4abd71d9..661c4d18f 100644 --- a/evm_arithmetization/src/cpu/columns/mod.rs +++ b/evm_arithmetization/src/cpu/columns/mod.rs @@ -4,12 +4,13 @@ use core::mem::{size_of, transmute}; use core::ops::{Index, IndexMut}; use plonky2::field::types::Field; +use zk_evm_proc_macro::Columns; use crate::cpu::columns::general::CpuGeneralColumnsView; use crate::cpu::columns::ops::OpsColumnsView; use crate::cpu::membus::NUM_GP_CHANNELS; use crate::memory; -use crate::util::{indices_arr, transmute_no_compile_time_size_checks}; +use crate::util::indices_arr; mod general; /// Cpu operation flags. @@ -54,7 +55,7 @@ pub(crate) struct PartialMemoryChannelView { } #[repr(C)] -#[derive(Clone, Copy, Eq, PartialEq, Debug)] +#[derive(Columns, Clone, Copy, Eq, PartialEq, Debug)] pub(crate) struct CpuColumnsView { /// If CPU cycle: Current context. pub context: T, @@ -98,70 +99,6 @@ pub(crate) struct CpuColumnsView { /// `u8` is guaranteed to have a `size_of` of 1. pub(crate) const NUM_CPU_COLUMNS: usize = size_of::>(); -impl Default for CpuColumnsView { - fn default() -> Self { - Self::from([F::ZERO; NUM_CPU_COLUMNS]) - } -} - -impl From<[T; NUM_CPU_COLUMNS]> for CpuColumnsView { - fn from(value: [T; NUM_CPU_COLUMNS]) -> Self { - unsafe { transmute_no_compile_time_size_checks(value) } - } -} - -impl From> for [T; NUM_CPU_COLUMNS] { - fn from(value: CpuColumnsView) -> Self { - unsafe { transmute_no_compile_time_size_checks(value) } - } -} - -impl Borrow> for [T; NUM_CPU_COLUMNS] { - fn borrow(&self) -> &CpuColumnsView { - unsafe { transmute(self) } - } -} - -impl BorrowMut> for [T; NUM_CPU_COLUMNS] { - fn borrow_mut(&mut self) -> &mut CpuColumnsView { - unsafe { transmute(self) } - } -} - -impl Borrow<[T; NUM_CPU_COLUMNS]> for CpuColumnsView { - fn borrow(&self) -> &[T; NUM_CPU_COLUMNS] { - unsafe { transmute(self) } - } -} - -impl BorrowMut<[T; NUM_CPU_COLUMNS]> for CpuColumnsView { - fn borrow_mut(&mut self) -> &mut [T; NUM_CPU_COLUMNS] { - unsafe { transmute(self) } - } -} - -impl Index for CpuColumnsView -where - [T]: Index, -{ - type Output = <[T] as Index>::Output; - - fn index(&self, index: I) -> &Self::Output { - let arr: &[T; NUM_CPU_COLUMNS] = self.borrow(); - <[T] as Index>::index(arr, index) - } -} - -impl IndexMut for CpuColumnsView -where - [T]: IndexMut, -{ - fn index_mut(&mut self, index: I) -> &mut Self::Output { - let arr: &mut [T; NUM_CPU_COLUMNS] = self.borrow_mut(); - <[T] as IndexMut>::index_mut(arr, index) - } -} - const fn make_col_map() -> CpuColumnsView { let indices_arr = indices_arr::(); unsafe { transmute::<[usize; NUM_CPU_COLUMNS], CpuColumnsView>(indices_arr) } diff --git a/evm_arithmetization/src/cpu/columns/ops.rs b/evm_arithmetization/src/cpu/columns/ops.rs index c15d65722..9963215f6 100644 --- a/evm_arithmetization/src/cpu/columns/ops.rs +++ b/evm_arithmetization/src/cpu/columns/ops.rs @@ -2,11 +2,11 @@ use core::borrow::{Borrow, BorrowMut}; use core::mem::{size_of, transmute}; use core::ops::{Deref, DerefMut}; -use crate::util::transmute_no_compile_time_size_checks; +use zk_evm_proc_macro::{Columns, DerefColumns}; /// Structure representing the flags for the various opcodes. #[repr(C)] -#[derive(Clone, Copy, Eq, PartialEq, Debug)] +#[derive(Columns, DerefColumns, Clone, Copy, Eq, PartialEq, Debug)] pub(crate) struct OpsColumnsView { /// Combines ADD, MUL, SUB, DIV, MOD, LT, GT and BYTE flags. pub binary_op: T, @@ -50,40 +50,3 @@ pub(crate) struct OpsColumnsView { /// Number of columns in Cpu Stark. /// `u8` is guaranteed to have a `size_of` of 1. pub(crate) const NUM_OPS_COLUMNS: usize = size_of::>(); - -impl From<[T; NUM_OPS_COLUMNS]> for OpsColumnsView { - fn from(value: [T; NUM_OPS_COLUMNS]) -> Self { - unsafe { transmute_no_compile_time_size_checks(value) } - } -} - -impl From> for [T; NUM_OPS_COLUMNS] { - fn from(value: OpsColumnsView) -> Self { - unsafe { transmute_no_compile_time_size_checks(value) } - } -} - -impl Borrow> for [T; NUM_OPS_COLUMNS] { - fn borrow(&self) -> &OpsColumnsView { - unsafe { transmute(self) } - } -} - -impl BorrowMut> for [T; NUM_OPS_COLUMNS] { - fn borrow_mut(&mut self) -> &mut OpsColumnsView { - unsafe { transmute(self) } - } -} - -impl Deref for OpsColumnsView { - type Target = [T; NUM_OPS_COLUMNS]; - fn deref(&self) -> &Self::Target { - unsafe { transmute(self) } - } -} - -impl DerefMut for OpsColumnsView { - fn deref_mut(&mut self) -> &mut Self::Target { - unsafe { transmute(self) } - } -} diff --git a/evm_arithmetization/src/keccak_sponge/columns.rs b/evm_arithmetization/src/keccak_sponge/columns.rs index 44c707bf2..ce35c0867 100644 --- a/evm_arithmetization/src/keccak_sponge/columns.rs +++ b/evm_arithmetization/src/keccak_sponge/columns.rs @@ -2,7 +2,9 @@ use core::borrow::{Borrow, BorrowMut}; use core::mem::{size_of, transmute}; use core::ops::Range; -use crate::util::{indices_arr, transmute_no_compile_time_size_checks}; +use zk_evm_proc_macro::Columns; + +use crate::util::indices_arr; /// Total number of sponge bytes: number of rate bytes + number of capacity /// bytes. @@ -27,7 +29,7 @@ pub(crate) const KECCAK_DIGEST_U32S: usize = KECCAK_DIGEST_BYTES / 4; /// A view of `KeccakSpongeStark`'s columns. #[repr(C)] -#[derive(Eq, PartialEq, Debug)] +#[derive(Columns, Eq, PartialEq, Debug)] pub(crate) struct KeccakSpongeColumnsView { /// 1 if this row represents a full input block, i.e. one in which each byte /// is an input byte, not a padding byte; 0 otherwise. @@ -113,48 +115,6 @@ pub(crate) const fn get_single_block_bytes_value(i: usize) -> usize { get_block_bytes_range().start + i } -impl From<[T; NUM_KECCAK_SPONGE_COLUMNS]> for KeccakSpongeColumnsView { - fn from(value: [T; NUM_KECCAK_SPONGE_COLUMNS]) -> Self { - unsafe { transmute_no_compile_time_size_checks(value) } - } -} - -impl From> for [T; NUM_KECCAK_SPONGE_COLUMNS] { - fn from(value: KeccakSpongeColumnsView) -> Self { - unsafe { transmute_no_compile_time_size_checks(value) } - } -} - -impl Borrow> for [T; NUM_KECCAK_SPONGE_COLUMNS] { - fn borrow(&self) -> &KeccakSpongeColumnsView { - unsafe { transmute(self) } - } -} - -impl BorrowMut> for [T; NUM_KECCAK_SPONGE_COLUMNS] { - fn borrow_mut(&mut self) -> &mut KeccakSpongeColumnsView { - unsafe { transmute(self) } - } -} - -impl Borrow<[T; NUM_KECCAK_SPONGE_COLUMNS]> for KeccakSpongeColumnsView { - fn borrow(&self) -> &[T; NUM_KECCAK_SPONGE_COLUMNS] { - unsafe { transmute(self) } - } -} - -impl BorrowMut<[T; NUM_KECCAK_SPONGE_COLUMNS]> for KeccakSpongeColumnsView { - fn borrow_mut(&mut self) -> &mut [T; NUM_KECCAK_SPONGE_COLUMNS] { - unsafe { transmute(self) } - } -} - -impl Default for KeccakSpongeColumnsView { - fn default() -> Self { - [T::default(); NUM_KECCAK_SPONGE_COLUMNS].into() - } -} - const fn make_col_map() -> KeccakSpongeColumnsView { let indices_arr = indices_arr::(); unsafe { diff --git a/evm_arithmetization/src/util.rs b/evm_arithmetization/src/util.rs index 15a93c0af..373339cdd 100644 --- a/evm_arithmetization/src/util.rs +++ b/evm_arithmetization/src/util.rs @@ -147,14 +147,6 @@ pub(crate) const fn indices_arr() -> [usize; N] { indices_arr } -pub(crate) unsafe fn transmute_no_compile_time_size_checks(value: T) -> U { - debug_assert_eq!(size_of::(), size_of::()); - // Need ManuallyDrop so that `value` is not dropped by this function. - let value = ManuallyDrop::new(value); - // Copy the bit pattern. The original value is no longer safe to use. - transmute_copy(&value) -} - pub(crate) fn addmod(x: U256, y: U256, m: U256) -> U256 { if m.is_zero() { return m; diff --git a/proc_macro/Cargo.toml b/proc_macro/Cargo.toml new file mode 100644 index 000000000..d2deca37f --- /dev/null +++ b/proc_macro/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "zk_evm_proc_macro" +version = "0.1.0" +publish = false +edition.workspace = true +license.workspace = true +repository.workspace = true + +[lib] +proc-macro = true + +[[test]] +name = "tests" +path = "tests/compiletest.rs" + +[dependencies] +proc-macro2 = { workspace = true } +quote = { workspace = true } +syn = { workspace = true } + +[dev-dependencies] +trybuild = { workspace = true } diff --git a/proc_macro/src/common.rs b/proc_macro/src/common.rs new file mode 100644 index 000000000..b8c96ed92 --- /dev/null +++ b/proc_macro/src/common.rs @@ -0,0 +1,41 @@ +use syn::punctuated::Punctuated; +use syn::{token, Attribute, Meta}; + +/// Prefixes an error message and generates a `syn::Error` from the message. +macro_rules! span_err { + ($ast:expr, $msg:literal $(,)?) => { + ::syn::Error::new_spanned($ast, ::core::concat!("zk_evm_proc_macro error: ", $msg)) + }; +} +pub(crate) use span_err; + +/// Checks the condition and returns early with a prefixed error message if +/// false. +macro_rules! ensure { + ($cond:expr, $ast:expr, $msg:literal $(,)?) => { + if !$cond { + return Err($crate::common::span_err!($ast, $msg)); + } + }; +} +pub(crate) use ensure; + +/// Parses the `Meta` of a `repr` attribute and returns true if one of the +/// elements is "C". +fn is_meta_c(outer: &Meta) -> bool { + if let Meta::List(inner) = outer { + let parsed: Punctuated = inner + .parse_args_with(Punctuated::parse_terminated) + .unwrap_or_default(); + parsed.iter().any(|meta| meta.path().is_ident("C")) + } else { + false + } +} + +/// Returns true if `#[repr(C)]` is contained in the attributes. +pub(crate) fn is_repr_c<'a>(attrs: impl IntoIterator) -> bool { + attrs + .into_iter() + .any(|attr| attr.path().is_ident("repr") && is_meta_c(&attr.meta)) +} diff --git a/proc_macro/src/impls/columns.rs b/proc_macro/src/impls/columns.rs new file mode 100644 index 000000000..f4f42a1d8 --- /dev/null +++ b/proc_macro/src/impls/columns.rs @@ -0,0 +1,133 @@ +use quote::quote; +use syn::{Data, DeriveInput, Result}; + +use crate::common::{ensure, is_repr_c}; + +/// Implements `Borrow`, `BorrowMut`, `From`, `Index`, `IndexMut`, and +/// `Default`. +pub(crate) fn try_derive(ast: DeriveInput) -> Result { + let is_struct = matches!(ast.data, Data::Struct(_)); + ensure!(is_struct, &ast, "expected `struct`"); + + // Check that the struct is `#[repr(C)]`. + let repr_c = is_repr_c(&ast.attrs); + ensure!(repr_c, &ast, "column struct must be `#[repr(C)]`"); + + // The name of the struct. + let name = &ast.ident; + + // SAFETY: `u8` is guaranteed to have a `size_of` of 1. + // https://doc.rust-lang.org/reference/type-layout.html#primitive-data-layout + let num_columns = quote!(::core::mem::size_of::<#name>()); + + // SAFETY: A struct generic over T has the same layout as an array [T; N] if: + // - The struct is `#[repr(C)]`. + // - Every field is one of T, [T; M], or a type with the same layout as [T; M], + // - The total number of elements of type T is N. + // https://doc.rust-lang.org/reference/type-layout.html#reprc-structs + // https://doc.rust-lang.org/reference/type-layout.html#array-layout + Ok(quote! { + impl ::core::borrow::Borrow<#name> for [T; #num_columns] + where + T: ::core::marker::Copy, + { + fn borrow(&self) -> &#name { + unsafe { ::core::mem::transmute(self) } + } + } + + impl ::core::borrow::BorrowMut<#name> for [T; #num_columns] + where + T: ::core::marker::Copy, + { + fn borrow_mut(&mut self) -> &mut #name { + unsafe { ::core::mem::transmute(self) } + } + } + + impl ::core::borrow::Borrow<[T; #num_columns]> for #name + where + T: ::core::marker::Copy, + { + fn borrow(&self) -> &[T; #num_columns] { + unsafe { ::core::mem::transmute(self) } + } + } + + impl ::core::borrow::BorrowMut<[T; #num_columns]> for #name + where + T: ::core::marker::Copy, + { + fn borrow_mut(&mut self) -> &mut [T; #num_columns] { + unsafe { ::core::mem::transmute(self) } + } + } + + impl From<[T; #num_columns]> for #name + where + T: ::core::marker::Copy, + { + fn from(value: [T; #num_columns]) -> Self { + debug_assert_eq!( + ::core::mem::size_of::<#name>(), + ::core::mem::size_of::<[T; #num_columns]>() + ); + // Need ManuallyDrop so that `value` is not dropped by this function. + let value = ::core::mem::ManuallyDrop::new(value); + // Copy the bit pattern. The original value is no longer safe to use. + unsafe { ::core::mem::transmute_copy(&value) } + } + } + + impl From<#name> for [T; #num_columns] + where + T: ::core::marker::Copy, + { + fn from(value: #name) -> Self { + debug_assert_eq!( + ::core::mem::size_of::<#name>(), + ::core::mem::size_of::<[T; #num_columns]>() + ); + // Need ManuallyDrop so that `value` is not dropped by this function. + let value = ::core::mem::ManuallyDrop::new(value); + // Copy the bit pattern. The original value is no longer safe to use. + unsafe { ::core::mem::transmute_copy(&value) } + } + } + + impl ::core::ops::Index for #name + where + T: ::core::marker::Copy, + [T]: ::core::ops::Index, + { + type Output = <[T] as ::core::ops::Index>::Output; + + fn index(&self, index: I) -> &>::Output { + let arr = ::core::borrow::Borrow::<[T; #num_columns]>::borrow(self); + <[T] as ::core::ops::Index>::index(arr, index) + } + } + + impl ::core::ops::IndexMut for #name + where + T: ::core::marker::Copy, + [T]: ::core::ops::IndexMut, + { + fn index_mut(&mut self, index: I) -> &mut >::Output { + let arr = ::core::borrow::BorrowMut::<[T; #num_columns]>::borrow_mut(self); + <[T] as ::core::ops::IndexMut>::index_mut(arr, index) + } + } + + impl ::core::default::Default for #name + where + T: ::core::marker::Copy + ::core::default::Default, + { + fn default() -> Self { + ::core::convert::Into::::into( + [::default(); #num_columns] + ) + } + } + }) +} diff --git a/proc_macro/src/impls/deref_columns.rs b/proc_macro/src/impls/deref_columns.rs new file mode 100644 index 000000000..534ab09c2 --- /dev/null +++ b/proc_macro/src/impls/deref_columns.rs @@ -0,0 +1,43 @@ +use quote::quote; +use syn::{Data, DeriveInput, Result}; + +use crate::common::{ensure, is_repr_c}; + +/// Implements `Deref` and `DerefMut`. +pub(crate) fn try_derive(ast: DeriveInput) -> Result { + let is_struct = matches!(ast.data, Data::Struct(_)); + ensure!(is_struct, &ast, "expected `struct`"); + + // Check that the struct is `#[repr(C)]`. + let repr_c = is_repr_c(&ast.attrs); + ensure!(repr_c, &ast, "column struct must be `#[repr(C)]`"); + + // The name of the struct. + let name = &ast.ident; + + // SAFETY: `u8` is guaranteed to have a `size_of` of 1. + // https://doc.rust-lang.org/reference/type-layout.html#primitive-data-layout + let num_columns = quote!(::core::mem::size_of::<#name>()); + + // SAFETY: A struct generic over T has the same layout as an array [T; N] if: + // - The struct is `#[repr(C)]`. + // - Every field is one of T, [T; M], or a type with the same layout as [T; M], + // - The total number of elements of type T is N. + // https://doc.rust-lang.org/reference/type-layout.html#reprc-structs + // https://doc.rust-lang.org/reference/type-layout.html#array-layout + Ok(quote! { + impl ::core::ops::Deref for #name { + type Target = [T; #num_columns]; + + fn deref(&self) -> &::Target { + unsafe { ::core::mem::transmute(self) } + } + } + + impl ::core::ops::DerefMut for #name { + fn deref_mut(&mut self) -> &mut ::Target { + unsafe { ::core::mem::transmute(self) } + } + } + }) +} diff --git a/proc_macro/src/impls/mod.rs b/proc_macro/src/impls/mod.rs new file mode 100644 index 000000000..2e0de48ac --- /dev/null +++ b/proc_macro/src/impls/mod.rs @@ -0,0 +1,2 @@ +pub(crate) mod columns; +pub(crate) mod deref_columns; diff --git a/proc_macro/src/lib.rs b/proc_macro/src/lib.rs new file mode 100644 index 000000000..d0a9d8225 --- /dev/null +++ b/proc_macro/src/lib.rs @@ -0,0 +1,47 @@ +//! This library provides two convenient derive macros for interpreting arrays +//! of field elements as structs representing an AIR. +//! +//! Deriving [`Columns`] on a struct `Struct` implements the following +//! conversion traits between `Struct` and arrays `[T; N]` where `N` is the +//! number of fields in the struct: [`Borrow`], [`BorrowMut`], and [`From`]. +//! Additionally, the traits [`Index`], [`IndexMut`], and [`Default`] are +//! implemented for `Struct`. +//! +//! Deriving [`DerefColumns`] for a struct generic over `T` implements [`Deref`] +//! and [`DerefMut`] with target `[T; N]` where `N` is the number of fields in +//! the struct. +//! +//! These implementations employ unsafe code and place a burden on the user to +//! ensure their safe usage. Please see the respective macro implementations to +//! understand the conditions that should be upheld by any struct deriving +//! [`Columns`] or [`DerefColumns`]. In short, the struct must be `#[repr(C)]` +//! and all fields must be one of `T`, `[T; M]`, or a type with the same layout +//! as `[T; M]`. +//! +//! [`Borrow`]: ::core::borrow::Borrow +//! [`BorrowMut`]: ::core::borrow::BorrowMut +//! [`Index`]: ::core::ops::Index +//! [`IndexMut`]: ::core::ops::IndexMut +//! [`Deref`]: ::core::ops::Deref +//! [`DerefMut`]: ::core::ops::DerefMut + +pub(crate) mod common; +mod impls; + +use impls::{columns, deref_columns}; + +#[proc_macro_derive(Columns)] +pub fn derive_columns(input: proc_macro::TokenStream) -> proc_macro::TokenStream { + let ast = syn::parse_macro_input!(input as syn::DeriveInput); + columns::try_derive(ast) + .unwrap_or_else(syn::Error::into_compile_error) + .into() +} + +#[proc_macro_derive(DerefColumns)] +pub fn derive_deref_columns(input: proc_macro::TokenStream) -> proc_macro::TokenStream { + let ast = syn::parse_macro_input!(input as syn::DeriveInput); + deref_columns::try_derive(ast) + .unwrap_or_else(syn::Error::into_compile_error) + .into() +} diff --git a/proc_macro/tests/compile/mod.rs b/proc_macro/tests/compile/mod.rs new file mode 100644 index 000000000..838146ec9 --- /dev/null +++ b/proc_macro/tests/compile/mod.rs @@ -0,0 +1,26 @@ +mod test_impls; + +use zk_evm_proc_macro::{Columns, DerefColumns}; + +#[repr(C)] +pub struct NestedColumns { + x: T, + y: [T; 3], +} + +#[repr(C)] +#[derive(DerefColumns)] +pub struct OpColumns { + is_op_a: T, + is_op_b: T, + is_op_c: T, +} + +#[repr(C)] +#[derive(Columns)] +pub struct AllColumns { + a: T, + b: [T; 4], + c: [NestedColumns; 5], + op: OpColumns, +} diff --git a/proc_macro/tests/compile/test_impls.rs b/proc_macro/tests/compile/test_impls.rs new file mode 100644 index 000000000..69e0c28db --- /dev/null +++ b/proc_macro/tests/compile/test_impls.rs @@ -0,0 +1,34 @@ +use core::borrow::{Borrow, BorrowMut}; +use core::ops::{Deref, DerefMut, Index, IndexMut}; + +use super::*; + +const NUM_OP_COLUMNS: usize = core::mem::size_of::>(); + +#[allow(unused)] +trait TestDerefColumns: Deref + DerefMut {} +impl TestDerefColumns for OpColumns {} + +const NUM_COLUMNS: usize = core::mem::size_of::>(); + +#[allow(unused)] +trait TestColumns: + Borrow<[T; NUM_COLUMNS]> + + BorrowMut<[T; NUM_COLUMNS]> + + From<[T; NUM_COLUMNS]> + + Index>::Output> + + IndexMut + + Default +where + [T]: Index + IndexMut, + [T; NUM_COLUMNS]: Borrow, + [T; NUM_COLUMNS]: BorrowMut, + [T; NUM_COLUMNS]: From, +{ +} +impl TestColumns for AllColumns +where + T: Copy + Default, + [T]: Index + IndexMut, +{ +} diff --git a/proc_macro/tests/compile_fail/not_repr_c.rs b/proc_macro/tests/compile_fail/not_repr_c.rs new file mode 100644 index 000000000..c3d8ed11b --- /dev/null +++ b/proc_macro/tests/compile_fail/not_repr_c.rs @@ -0,0 +1,9 @@ +use zk_evm_proc_macro::Columns; + +#[derive(Columns)] +struct Columns { + a: T, + b: [T; 3], +} + +fn main() {} diff --git a/proc_macro/tests/compile_fail/not_repr_c.stderr b/proc_macro/tests/compile_fail/not_repr_c.stderr new file mode 100644 index 000000000..71e4cc26b --- /dev/null +++ b/proc_macro/tests/compile_fail/not_repr_c.stderr @@ -0,0 +1,8 @@ +error: zk_evm_proc_macro error: column struct must be `#[repr(C)]` + --> tests/compile_fail/not_repr_c.rs:4:1 + | +4 | / struct Columns { +5 | | a: T, +6 | | b: [T; 3], +7 | | } + | |_^ diff --git a/proc_macro/tests/compile_fail/not_repr_c_deref.rs b/proc_macro/tests/compile_fail/not_repr_c_deref.rs new file mode 100644 index 000000000..cac29f0df --- /dev/null +++ b/proc_macro/tests/compile_fail/not_repr_c_deref.rs @@ -0,0 +1,9 @@ +use zk_evm_proc_macro::DerefColumns; + +#[derive(DerefColumns)] +struct Columns { + a: T, + b: [T; 3], +} + +fn main() {} diff --git a/proc_macro/tests/compile_fail/not_repr_c_deref.stderr b/proc_macro/tests/compile_fail/not_repr_c_deref.stderr new file mode 100644 index 000000000..26ed6ba0f --- /dev/null +++ b/proc_macro/tests/compile_fail/not_repr_c_deref.stderr @@ -0,0 +1,8 @@ +error: zk_evm_proc_macro error: column struct must be `#[repr(C)]` + --> tests/compile_fail/not_repr_c_deref.rs:4:1 + | +4 | / struct Columns { +5 | | a: T, +6 | | b: [T; 3], +7 | | } + | |_^ diff --git a/proc_macro/tests/compile_fail/not_struct.rs b/proc_macro/tests/compile_fail/not_struct.rs new file mode 100644 index 000000000..42be545a4 --- /dev/null +++ b/proc_macro/tests/compile_fail/not_struct.rs @@ -0,0 +1,10 @@ +use zk_evm_proc_macro::Columns; + +#[repr(C)] +#[derive(Columns)] +enum Maybe { + Nothing, + Just(T), +} + +fn main() {} diff --git a/proc_macro/tests/compile_fail/not_struct.stderr b/proc_macro/tests/compile_fail/not_struct.stderr new file mode 100644 index 000000000..b7a18ddd7 --- /dev/null +++ b/proc_macro/tests/compile_fail/not_struct.stderr @@ -0,0 +1,10 @@ +error: zk_evm_proc_macro error: expected `struct` + --> tests/compile_fail/not_struct.rs:3:1 + | +3 | / #[repr(C)] +4 | | #[derive(Columns)] +5 | | enum Maybe { +6 | | Nothing, +7 | | Just(T), +8 | | } + | |_^ diff --git a/proc_macro/tests/compile_fail/not_struct_deref.rs b/proc_macro/tests/compile_fail/not_struct_deref.rs new file mode 100644 index 000000000..be429e6b2 --- /dev/null +++ b/proc_macro/tests/compile_fail/not_struct_deref.rs @@ -0,0 +1,10 @@ +use zk_evm_proc_macro::DerefColumns; + +#[repr(C)] +#[derive(DerefColumns)] +enum Maybe { + Nothing, + Just(T), +} + +fn main() {} diff --git a/proc_macro/tests/compile_fail/not_struct_deref.stderr b/proc_macro/tests/compile_fail/not_struct_deref.stderr new file mode 100644 index 000000000..0337c2102 --- /dev/null +++ b/proc_macro/tests/compile_fail/not_struct_deref.stderr @@ -0,0 +1,10 @@ +error: zk_evm_proc_macro error: expected `struct` + --> tests/compile_fail/not_struct_deref.rs:3:1 + | +3 | / #[repr(C)] +4 | | #[derive(DerefColumns)] +5 | | enum Maybe { +6 | | Nothing, +7 | | Just(T), +8 | | } + | |_^ diff --git a/proc_macro/tests/compiletest.rs b/proc_macro/tests/compiletest.rs new file mode 100644 index 000000000..1e9d73b78 --- /dev/null +++ b/proc_macro/tests/compiletest.rs @@ -0,0 +1,14 @@ +mod compile; + +/// The `compile_fail` tests in `tests/compile_fail/` are inherently fragile, +/// as small changes in output from rustc or from the trybuild crate may cause +/// them to fail. To regenerate the `*.stderr` files, run: +/// `TRYBUILD=overwrite cargo test -p zk_evm_proc_macro -- test_compile_fail`. +/// Then, check the git diff to ensure that the new `*.stderr` files are what +/// you would expect (most importantly, make sure they actually contain errors). +#[cfg_attr(miri, ignore = "incompatible with miri")] +#[test] +fn test_compile_fail() { + let t = trybuild::TestCases::new(); + t.compile_fail("tests/compile_fail/*.rs"); +} From 439b8c227cb7fd837fdfa850dbe8ec13669eb78c Mon Sep 17 00:00:00 2001 From: frisitano <35734660+frisitano@users.noreply.github.com> Date: Sat, 29 Jun 2024 20:06:57 +0800 Subject: [PATCH 09/10] migrate compat to micro crate (#308) --- Cargo.lock | 11 ++++++++++- Cargo.toml | 5 ++++- compat/Cargo.toml | 14 ++++++++++++++ zero_bin/rpc/src/compat.rs => compat/src/lib.rs | 2 ++ zero_bin/rpc/Cargo.toml | 5 +++-- zero_bin/rpc/src/lib.rs | 4 +--- zero_bin/rpc/src/native/state.rs | 2 +- zero_bin/rpc/src/native/txn.rs | 2 +- 8 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 compat/Cargo.toml rename zero_bin/rpc/src/compat.rs => compat/src/lib.rs (95%) diff --git a/Cargo.lock b/Cargo.lock index 977623c01..dd96f5146 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1336,6 +1336,14 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +[[package]] +name = "compat" +version = "0.1.0" +dependencies = [ + "alloy", + "primitive-types 0.12.2", +] + [[package]] name = "concurrent-queue" version = "2.5.0" @@ -4058,6 +4066,7 @@ dependencies = [ "alloy", "anyhow", "clap", + "compat", "evm_arithmetization", "futures", "mpt_trie", @@ -5716,6 +5725,6 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 2.0.68", "trybuild", ] diff --git a/Cargo.toml b/Cargo.toml index 0d0f0d4a8..aff00a946 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,8 @@ members = ["mpt_trie", "zero_bin/ops", "zero_bin/verifier", "zero_bin/rpc", - "zero_bin/prover"] + "zero_bin/prover", + "compat"] resolver = "2" [workspace.package] @@ -44,6 +45,8 @@ bytes = "1.6.0" ciborium = "0.2.2" ciborium-io = "0.2.2" clap = { version = "4.5.7", features = ["derive", "env"] } +compat = { path = "compat" } +__compat_primitive_types = { version = "0.12.2", package = "primitive-types" } criterion = "0.5.1" dotenvy = "0.15.7" enum-as-inner = "0.6.0" diff --git a/compat/Cargo.toml b/compat/Cargo.toml new file mode 100644 index 000000000..69ff77eb7 --- /dev/null +++ b/compat/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "compat" +version = "0.1.0" +publish = false # TODO(): https://github.com/0xPolygonZero/zk_evm/issues/314 find a better place for this +edition.workspace = true +license.workspace = true +repository.workspace = true +homepage.workspace = true +keywords.workspace = true +categories.workspace = true + +[dependencies] +alloy = {workspace = true } +__compat_primitive_types = { workspace = true } diff --git a/zero_bin/rpc/src/compat.rs b/compat/src/lib.rs similarity index 95% rename from zero_bin/rpc/src/compat.rs rename to compat/src/lib.rs index 7fb0a1563..e83eb6eaf 100644 --- a/zero_bin/rpc/src/compat.rs +++ b/compat/src/lib.rs @@ -1,4 +1,6 @@ +/// A trait to convert between alloy and ethereum types. pub trait Compat { + /// Convert the type to another type fn compat(self) -> Out; } diff --git a/zero_bin/rpc/Cargo.toml b/zero_bin/rpc/Cargo.toml index f52ccde62..0cf1a2d6c 100644 --- a/zero_bin/rpc/Cargo.toml +++ b/zero_bin/rpc/Cargo.toml @@ -21,10 +21,11 @@ mpt_trie = { workspace = true } alloy.workspace = true futures = { workspace = true } url = { workspace = true } -__compat_primitive_types = { version = "0.12.2", package = "primitive-types" } +__compat_primitive_types = { workspace = true } tower = { workspace = true, features = ["retry"] } # Local dependencies -zero_bin_common ={ workspace = true } +compat = { workspace = true } +zero_bin_common = { workspace = true } prover = { workspace = true } diff --git a/zero_bin/rpc/src/lib.rs b/zero_bin/rpc/src/lib.rs index 1a6d6eb57..130b791e1 100644 --- a/zero_bin/rpc/src/lib.rs +++ b/zero_bin/rpc/src/lib.rs @@ -6,19 +6,17 @@ use alloy::{ }; use anyhow::Context as _; use clap::ValueEnum; +use compat::Compat; use evm_arithmetization::proof::{BlockHashes, BlockMetadata}; use futures::{StreamExt as _, TryStreamExt as _}; use prover::ProverInput; use trace_decoder::types::{BlockLevelData, OtherBlockData}; use zero_bin_common::block_interval::BlockInterval; -mod compat; pub mod jerigon; pub mod native; pub mod retry; -use compat::Compat; - const PREVIOUS_HASHES_COUNT: usize = 256; /// The RPC type. diff --git a/zero_bin/rpc/src/native/state.rs b/zero_bin/rpc/src/native/state.rs index b4992848f..d69b48cb9 100644 --- a/zero_bin/rpc/src/native/state.rs +++ b/zero_bin/rpc/src/native/state.rs @@ -14,7 +14,7 @@ use trace_decoder::trace_protocol::{ SeparateTriePreImages, TrieDirect, TxnInfo, }; -use crate::compat::Compat; +use crate::Compat; /// Processes the state witness for the given block. pub async fn process_state_witness( diff --git a/zero_bin/rpc/src/native/txn.rs b/zero_bin/rpc/src/native/txn.rs index 7c55e1fb7..9e1e8721a 100644 --- a/zero_bin/rpc/src/native/txn.rs +++ b/zero_bin/rpc/src/native/txn.rs @@ -24,7 +24,7 @@ use futures::stream::{FuturesOrdered, TryStreamExt}; use trace_decoder::trace_protocol::{ContractCodeUsage, TxnInfo, TxnMeta, TxnTrace}; use super::CodeDb; -use crate::compat::Compat; +use crate::Compat; /// Processes the transactions in the given block and updates the code db. pub(super) async fn process_transactions( From 15c9cf631f536baf6ed68d91e097298136225aad Mon Sep 17 00:00:00 2001 From: Marko Atanasievski Date: Mon, 1 Jul 2024 20:26:45 +0200 Subject: [PATCH 10/10] fix: docker build for worker and leader (#329) * fix: docker build for worker and leader * fix: missing env and cargo lock search path * add: build and push leader and worker docker images to ghcr.io * feat: add docker build test * fix: change image names * fix: remove debug build and push * fix: add eof line * fix: comment * fix: build --- .github/workflows/docker_build.yml | 35 +++++++++++ .github/workflows/docker_build_push.yml | 83 +++++++++++++++++++++++++ leader.Dockerfile | 60 ++++++++++++++++++ worker.Dockerfile | 40 ++++++++++++ zero_bin/leader.Dockerfile | 43 ------------- zero_bin/worker.Dockerfile | 35 ----------- 6 files changed, 218 insertions(+), 78 deletions(-) create mode 100644 .github/workflows/docker_build.yml create mode 100644 .github/workflows/docker_build_push.yml create mode 100644 leader.Dockerfile create mode 100644 worker.Dockerfile delete mode 100644 zero_bin/leader.Dockerfile delete mode 100644 zero_bin/worker.Dockerfile diff --git a/.github/workflows/docker_build.yml b/.github/workflows/docker_build.yml new file mode 100644 index 000000000..8d74a2fa4 --- /dev/null +++ b/.github/workflows/docker_build.yml @@ -0,0 +1,35 @@ +name: Docker Build & Run + +on: + push: + branches: [develop, main] + pull_request: + branches: + - "**" + workflow_dispatch: + branches: + - "**" + +jobs: + docker: + name: Build and run leader and worker docker images for regression check + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Build leader docker container + run: | + docker build --progress plain -t leader:${{ github.ref_name }} -f leader.Dockerfile . + + - name: Run leader docker container + run: | + docker run --rm leader:${{ github.ref_name }} --help + + - name: Build worker docker container + run: | + docker build --progress plain -t worker:${{ github.ref_name }} -f worker.Dockerfile . + + - name: Run worker docker container + run: | + docker run --rm worker:${{ github.ref_name }} --help diff --git a/.github/workflows/docker_build_push.yml b/.github/workflows/docker_build_push.yml new file mode 100644 index 000000000..112ea158e --- /dev/null +++ b/.github/workflows/docker_build_push.yml @@ -0,0 +1,83 @@ +name: Docker Build & Push + +on: + push: + branches: [develop, main] + release: + types: [created] + +env: + REGISTRY: ghcr.io + IMAGE_NAME_LEADER: ${{ github.repository }}-leader + IMAGE_NAME_WORKER: ${{ github.repository }}-worker + +jobs: + docker: + name: Build and push leader and worker docker images to GitHub Container Registry + runs-on: ubuntu-latest + permissions: + packages: write + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Leader Docker + id: meta_leader + uses: docker/metadata-action@v5 + with: + images: | + name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LEADER }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - name: Push to GitHub Container Registry - Leader + uses: docker/build-push-action@v3 + with: + context: . + file: ./leader.Dockerfile + push: true + # platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta_leader.outputs.tags }} + labels: ${{ steps.meta_leader.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Extract metadata (tags, labels) for Worker Docker + id: meta_worker + uses: docker/metadata-action@v5 + with: + images: | + name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME_WORKER }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + + - name: Push to GitHub Container Registry - Worker + uses: docker/build-push-action@v3 + with: + context: . + file: ./worker.Dockerfile + push: true + # platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta_worker.outputs.tags }} + labels: ${{ steps.meta_worker.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/leader.Dockerfile b/leader.Dockerfile new file mode 100644 index 000000000..ef69a430f --- /dev/null +++ b/leader.Dockerfile @@ -0,0 +1,60 @@ +FROM rustlang/rust:nightly-bullseye-slim as builder + +RUN apt-get update && apt-get install -y libjemalloc2 libjemalloc-dev make libssl-dev pkg-config + +RUN mkdir -p zero_bin +COPY Cargo.toml . +# Cleanup all workspace members and add selected crates again +RUN sed -i '/members =/{:a;N;/]/!ba};//d' Cargo.toml +RUN sed -i 's#\[workspace\]#\[workspace\]\nmembers = \["zero_bin\/leader", "zero_bin\/prover", "zero_bin\/rpc", "zero_bin\/common", \ + "zero_bin\/ops"\, "evm_arithmetization", "trace_decoder", "mpt_trie", "proc_macro", "compat"\]#' Cargo.toml +COPY Cargo.lock . +COPY ./rust-toolchain.toml ./ +RUN cat ./Cargo.toml +COPY ./.env ./.env + +COPY proof_gen proof_gen +COPY mpt_trie mpt_trie +COPY proc_macro proc_macro +COPY compat compat +COPY trace_decoder trace_decoder +COPY evm_arithmetization evm_arithmetization +COPY zero_bin/common zero_bin/common +COPY zero_bin/ops zero_bin/ops +COPY zero_bin/rpc zero_bin/rpc +COPY zero_bin/prover zero_bin/prover +COPY zero_bin/leader zero_bin/leader + + +RUN \ + touch zero_bin/common/src/lib.rs && \ + touch zero_bin/ops/src/lib.rs && \ + touch zero_bin/leader/src/main.rs && \ + touch zero_bin/rpc/src/lib.rs && \ + touch zero_bin/prover/src/lib.rs && \ + touch evm_arithmetization/src/lib.rs && \ + touch trace_decoder/src/lib.rs && \ + touch mpt_trie/src/lib.rs && \ + touch proc_macro/src/lib.rs && \ + touch compat/src/lib.rs + +# Disable the lld linker for now, as it's causing issues with the linkme package. +# https://github.com/rust-lang/rust/pull/124129 +# https://github.com/dtolnay/linkme/pull/88 +ENV RUSTFLAGS='-C target-cpu=native -Zlinker-features=-lld' + +RUN cargo build --release --bin leader +RUN cargo build --release --bin rpc + + +FROM debian:bullseye-slim +RUN apt-get update && apt-get install -y ca-certificates libjemalloc2 +COPY --from=builder ./target/release/leader /usr/local/bin/leader +COPY --from=builder ./target/release/rpc /usr/local/bin/rpc +COPY --from=builder ./.env /.env + +# Workaround for the issue with the Cargo.lock search path +# Related to issue https://github.com/0xPolygonZero/zk_evm/issues/311 +RUN mkdir -p zero_bin/leader + +ENTRYPOINT ["/usr/local/bin/leader"] diff --git a/worker.Dockerfile b/worker.Dockerfile new file mode 100644 index 000000000..865fb7bb6 --- /dev/null +++ b/worker.Dockerfile @@ -0,0 +1,40 @@ +FROM rustlang/rust:nightly-bullseye-slim as builder + +RUN apt-get update && apt-get install -y libjemalloc2 libjemalloc-dev make libssl-dev pkg-config + +RUN mkdir -p zero_bin +COPY Cargo.toml . +# Cleanup all workspace members and add selected crates again +RUN sed -i '/members =/{:a;N;/]/!ba};//d' Cargo.toml +RUN sed -i 's#\[workspace\]#\[workspace\]\nmembers = \["zero_bin\/worker", "zero_bin\/common", "zero_bin\/ops"\, "evm_arithmetization", "mpt_trie", "proc_macro"\]#' Cargo.toml +COPY Cargo.lock . +COPY ./rust-toolchain.toml ./ + +COPY proof_gen proof_gen +COPY mpt_trie mpt_trie +COPY evm_arithmetization evm_arithmetization +COPY proc_macro proc_macro +COPY zero_bin/common zero_bin/common +COPY zero_bin/ops zero_bin/ops +COPY zero_bin/worker zero_bin/worker + +RUN \ + touch zero_bin/common/src/lib.rs && \ + touch zero_bin/ops/src/lib.rs && \ + touch zero_bin/worker/src/main.rs && \ + touch evm_arithmetization/src/lib.rs && \ + touch mpt_trie/src/lib.rs && \ + touch proc_macro/src/lib.rs + +# Disable the lld linker for now, as it's causing issues with the linkme package. +# https://github.com/rust-lang/rust/pull/124129 +# https://github.com/dtolnay/linkme/pull/88 +ENV RUSTFLAGS='-C target-cpu=native -Zlinker-features=-lld' + +RUN cargo build --release --bin worker + +FROM debian:bullseye-slim +RUN apt-get update && apt-get install -y ca-certificates libjemalloc2 +COPY --from=builder ./target/release/worker /usr/local/bin/worker +ENTRYPOINT ["/usr/local/bin/worker"] + diff --git a/zero_bin/leader.Dockerfile b/zero_bin/leader.Dockerfile deleted file mode 100644 index 7e0eb6e8c..000000000 --- a/zero_bin/leader.Dockerfile +++ /dev/null @@ -1,43 +0,0 @@ -FROM rustlang/rust:nightly-bullseye-slim as builder - -RUN apt-get update && apt-get install -y libjemalloc2 libjemalloc-dev make libssl-dev pkg-config - -RUN \ - mkdir -p ops/src && touch ops/src/lib.rs && \ - mkdir -p common/src && touch common/src/lib.rs && \ - mkdir -p rpc/src && touch rpc/src/lib.rs && \ - mkdir -p prover/src && touch prover/src/lib.rs && \ - mkdir -p leader/src && echo "fn main() {println!(\"YO!\");}" > leader/src/main.rs - -COPY Cargo.toml . -RUN sed -i "2s/.*/members = [\"ops\", \"leader\", \"common\", \"rpc\", \"prover\"]/" Cargo.toml -COPY Cargo.lock . - -COPY ops/Cargo.toml ./ops/Cargo.toml -COPY common/Cargo.toml ./common/Cargo.toml -COPY rpc/Cargo.toml ./rpc/Cargo.toml -COPY prover/Cargo.toml ./prover/Cargo.toml -COPY leader/Cargo.toml ./leader/Cargo.toml - -COPY ./rust-toolchain.toml ./ - -RUN cargo build --release --bin leader - -COPY ops ./ops -COPY common ./common -COPY rpc ./rpc -COPY prover ./prover -COPY leader ./leader -RUN \ - touch ops/src/lib.rs && \ - touch common/src/lib.rs && \ - touch rpc/src/lib.rs && \ - touch prover/src/lib.rs && \ - touch leader/src/main.rs - -RUN cargo build --release --bin leader - -FROM debian:bullseye-slim -RUN apt-get update && apt-get install -y ca-certificates libjemalloc2 -COPY --from=builder ./target/release/leader /usr/local/bin/leader -CMD ["leader"] diff --git a/zero_bin/worker.Dockerfile b/zero_bin/worker.Dockerfile deleted file mode 100644 index 39036aa2c..000000000 --- a/zero_bin/worker.Dockerfile +++ /dev/null @@ -1,35 +0,0 @@ -FROM rustlang/rust:nightly-bullseye-slim as builder - -RUN apt-get update && apt-get install -y libjemalloc2 libjemalloc-dev make libssl-dev - -RUN \ - mkdir -p common/src && touch common/src/lib.rs && \ - mkdir -p ops/src && touch ops/src/lib.rs && \ - mkdir -p worker/src && echo "fn main() {println!(\"YO!\");}" > worker/src/main.rs - -COPY Cargo.toml . -RUN sed -i "2s/.*/members = [\"common\", \"ops\", \"worker\"]/" Cargo.toml -COPY Cargo.lock . - -COPY common/Cargo.toml ./common/Cargo.toml -COPY ops/Cargo.toml ./ops/Cargo.toml -COPY worker/Cargo.toml ./worker/Cargo.toml - -COPY ./rust-toolchain.toml ./ - -RUN cargo build --release --bin worker - -COPY common ./common -COPY ops ./ops -COPY worker ./worker -RUN \ - touch common/src/lib.rs && \ - touch ops/src/lib.rs && \ - touch worker/src/main.rs - -RUN cargo build --release --bin worker - -FROM debian:bullseye-slim -RUN apt-get update && apt-get install -y ca-certificates libjemalloc2 -COPY --from=builder ./target/release/worker /usr/local/bin/worker -CMD ["worker"]