diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65a2ffd96e..7b76529142 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,7 @@ jobs: echo "HOME=/home/CI" >> $GITHUB_ENV - uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2024-01-25 + toolchain: nightly-2024-07-07 - name: Setup golang uses: actions/setup-go@v3 with: @@ -96,7 +96,7 @@ jobs: echo "HOME=/home/CI" >> $GITHUB_ENV - uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2024-01-25 + toolchain: nightly-2024-07-07 - name: Setup golang uses: actions/setup-go@v3 with: @@ -147,7 +147,7 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2024-01-25 + toolchain: nightly-2024-07-07 - name: Add target run: rustup target add ${{ matrix.target }} # Go cache for building geth-utils @@ -184,7 +184,7 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2024-01-25 + toolchain: nightly-2024-07-07 # Go cache for building geth-utils - name: Go cache uses: actions/cache@v3 @@ -217,7 +217,7 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2024-01-25 + toolchain: nightly-2024-07-07 # Go cache for building geth-utils - name: Go cache uses: actions/cache@v3 @@ -254,7 +254,7 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2024-01-25 + toolchain: nightly-2024-07-07 components: rustfmt # Go cache for building geth-utils - name: Go cache diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index b879ef70fe..9797fa1f6f 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -61,7 +61,7 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2024-01-25 + toolchain: nightly-2024-07-07 - name: Setup golang uses: actions/setup-go@v3 with: diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index 1e2345ca12..1dc3de1baf 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -43,7 +43,7 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2024-01-25 + toolchain: nightly-2024-07-07 components: clippy # Go cache for building geth-utils - name: Go cache diff --git a/.github/workflows/test-features.yml b/.github/workflows/test-features.yml index f80f1f29f2..20b2b71839 100644 --- a/.github/workflows/test-features.yml +++ b/.github/workflows/test-features.yml @@ -42,7 +42,7 @@ jobs: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@master with: - toolchain: nightly-2024-01-25 + toolchain: nightly-2024-07-07 # Go cache for building geth-utils - name: Go cache diff --git a/Cargo.lock b/Cargo.lock index c5d749431d..72509f65b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,8 +61,8 @@ dependencies = [ "num-bigint", "once_cell", "rand", - "revm-precompile", - "revm-primitives", + "revm-precompile 9.2.0", + "revm-primitives 7.1.0", "serde", "serde_json", "snark-verifier", @@ -99,13 +99,37 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" +[[package]] +name = "alloy-eip2930" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0069cf0642457f87a01a014f6dc29d5d893cd4fd8fddf0c3cdfad1bb3ebafc41" +dependencies = [ + "alloy-primitives 0.8.10", + "alloy-rlp", + "serde", +] + +[[package]] +name = "alloy-eip7702" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64ffc577390ce50234e02d841214b3dc0bea6aaaae8e04bbf3cb82e9a45da9eb" +dependencies = [ + "alloy-primitives 0.8.10", + "alloy-rlp", + "derive_more 1.0.0", + "k256", + "serde", +] + [[package]] name = "alloy-eips" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9431c99a3b3fe606ede4b3d4043bdfbcb780c45b8d8d226c3804e2b75cfbe68" dependencies = [ - "alloy-primitives", + "alloy-primitives 0.7.7", "alloy-rlp", "c-kzg", "k256", @@ -123,7 +147,7 @@ dependencies = [ "bytes", "cfg-if 1.0.0", "const-hex", - "derive_more", + "derive_more 0.99.18", "hex-literal", "itoa", "k256", @@ -135,6 +159,34 @@ dependencies = [ "tiny-keccak", ] +[[package]] +name = "alloy-primitives" +version = "0.8.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8edae627382349b56cd6a7a2106f4fd69b243a9233e560c55c2e03cabb7e1d3c" +dependencies = [ + "alloy-rlp", + "bytes", + "cfg-if 1.0.0", + "const-hex", + "derive_more 1.0.0", + "foldhash", + "hashbrown 0.15.0", + "hex-literal", + "indexmap", + "itoa", + "k256", + "keccak-asm", + "paste", + "proptest", + "rand", + "ruint", + "rustc-hash 2.0.0", + "serde", + "sha3 0.10.8", + "tiny-keccak", +] + [[package]] name = "alloy-rlp" version = "0.3.8" @@ -642,7 +694,7 @@ dependencies = [ "pretty_assertions", "rand", "rayon", - "revm-precompile", + "revm-precompile 9.2.0", "serde", "serde_json", "strum 0.25.0", @@ -1233,6 +1285,27 @@ dependencies = [ "syn 2.0.77", ] +[[package]] +name = "derive_more" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.77", + "unicode-xid", +] + [[package]] name = "diff" version = "0.1.13" @@ -1473,8 +1546,8 @@ dependencies = [ "num-bigint", "poseidon-base", "regex", - "revm-precompile", - "revm-primitives", + "revm-precompile 9.2.0", + "revm-primitives 7.1.0", "serde", "serde_json", "serde_with", @@ -1853,6 +1926,12 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foldhash" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -2134,7 +2213,7 @@ dependencies = [ "num-integer", "num-traits", "rand_chacha", - "rustc-hash", + "rustc-hash 1.1.0", ] [[package]] @@ -2294,6 +2373,15 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +dependencies = [ + "foldhash", +] + [[package]] name = "hashers" version = "1.0.1" @@ -3433,7 +3521,7 @@ dependencies = [ [[package]] name = "poseidon-base" version = "0.1.0" -source = "git+https://github.com/scroll-tech/poseidon-circuit.git?branch=main#6cc36ab9dfa153f554ff7b84305f39838366a8df" +source = "git+https://github.com/scroll-tech/poseidon-circuit.git?branch=main#b978cee00aae1e0a1e79e0d74c4683b137f5ea2d" dependencies = [ "bitvec", "halo2curves", @@ -3444,7 +3532,7 @@ dependencies = [ [[package]] name = "poseidon-circuit" version = "0.1.0" -source = "git+https://github.com/scroll-tech/poseidon-circuit.git?branch=main#6cc36ab9dfa153f554ff7b84305f39838366a8df" +source = "git+https://github.com/scroll-tech/poseidon-circuit.git?branch=main#b978cee00aae1e0a1e79e0d74c4683b137f5ea2d" dependencies = [ "ff", "halo2_proofs", @@ -3604,6 +3692,7 @@ dependencies = [ "num-bigint", "rand", "rand_xorshift", + "revm 17.1.0", "serde", "serde_derive", "serde_json", @@ -3816,6 +3905,31 @@ dependencies = [ "sha3 0.10.8", ] +[[package]] +name = "revm" +version = "17.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "055bee6a81aaeee8c2389ae31f0d4de87f44df24f4444a1116f9755fd87a76ad" +dependencies = [ + "auto_impl", + "cfg-if 1.0.0", + "dyn-clone", + "revm-interpreter", + "revm-precompile 14.0.0", + "serde", + "serde_json", +] + +[[package]] +name = "revm-interpreter" +version = "13.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fac2034454f8bc69dc7d3c94cdb1b57559e27f5ef0518771f1787de543d7d6a1" +dependencies = [ + "revm-primitives 13.0.0", + "serde", +] + [[package]] name = "revm-precompile" version = "9.2.0" @@ -3826,7 +3940,25 @@ dependencies = [ "cfg-if 1.0.0", "k256", "once_cell", - "revm-primitives", + "revm-primitives 7.1.0", + "ripemd", + "secp256k1 0.29.1", + "sha2", + "substrate-bn", +] + +[[package]] +name = "revm-precompile" +version = "14.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a88c8c7c5f9b988a9e65fc0990c6ce859cdb74114db705bd118a96d22d08027" +dependencies = [ + "aurora-engine-modexp", + "c-kzg", + "cfg-if 1.0.0", + "k256", + "once_cell", + "revm-primitives 13.0.0", "ripemd", "secp256k1 0.29.1", "sha2", @@ -3839,13 +3971,13 @@ version = "7.1.0" source = "git+https://github.com/scroll-tech/revm?branch=scroll-evm-executor/v40#5e215742c4d9d771f73d74fcba39628b1a2e3452" dependencies = [ "alloy-eips", - "alloy-primitives", + "alloy-primitives 0.7.7", "auto_impl", "bitflags 2.6.0", "bitvec", "c-kzg", "cfg-if 1.0.0", - "derive_more", + "derive_more 0.99.18", "dyn-clone", "enumn", "hashbrown 0.14.5", @@ -3854,6 +3986,25 @@ dependencies = [ "serde", ] +[[package]] +name = "revm-primitives" +version = "13.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d11fa1e195b0bebaf3fb18596f314a13ba3a4cb1fdd16d3465934d812fd921e" +dependencies = [ + "alloy-eip2930", + "alloy-eip7702", + "alloy-primitives 0.8.10", + "auto_impl", + "bitflags 2.6.0", + "bitvec", + "cfg-if 1.0.0", + "dyn-clone", + "enumn", + "hex", + "serde", +] + [[package]] name = "revm_precompiles" version = "1.1.2" @@ -3985,6 +4136,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustc-hex" version = "2.1.0" @@ -4112,7 +4269,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eca070c12893629e2cc820a9761bedf6ce1dcddc9852984d1dc734b8bd9bd024" dependencies = [ "cfg-if 1.0.0", - "derive_more", + "derive_more 0.99.18", "parity-scale-codec", "scale-info-derive", ] @@ -4282,6 +4439,7 @@ version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ + "indexmap", "itoa", "memchr", "ryu", @@ -4448,9 +4606,9 @@ dependencies = [ "num-traits", "poseidon", "rand", - "revm", + "revm 2.3.1", "rlp", - "rustc-hash", + "rustc-hash 1.1.0", "serde", "sha3 0.10.8", ] diff --git a/Cargo.toml b/Cargo.toml index af433433c5..c059b621e7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -104,3 +104,6 @@ overflow-checks = true rpath = false lto = "thin" incremental = true + +[workspace.lints.clippy] +doc_lazy_continuation = "allow" diff --git a/aggregator/Cargo.toml b/aggregator/Cargo.toml index ca3748bf50..1b1afdc5dd 100644 --- a/aggregator/Cargo.toml +++ b/aggregator/Cargo.toml @@ -47,3 +47,6 @@ csv = "1.1" default = ["revm-precompile/c-kzg", "halo2_proofs/circuit-params"] display = [] print-trace = ["ark-std/print-trace"] + +[lints] +workspace = true diff --git a/aggregator/src/aggregation/rlc/gates.rs b/aggregator/src/aggregation/rlc/gates.rs index 94f781b1e6..cb78e9f307 100644 --- a/aggregator/src/aggregation/rlc/gates.rs +++ b/aggregator/src/aggregation/rlc/gates.rs @@ -465,6 +465,8 @@ impl RlcConfig { a: &AssignedCell, offset: &mut usize, ) -> Result, Error> { + #[allow(unused_imports)] + use halo2_proofs::arithmetic::Field; // constraints // - res + a * a_inv = 1 // - res * a = 0 diff --git a/aggregator/src/lib.rs b/aggregator/src/lib.rs index bf608e7cdc..18f8e67017 100644 --- a/aggregator/src/lib.rs +++ b/aggregator/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(lazy_cell)] /// proof aggregation mod aggregation; /// This module implements `Batch` related data types. diff --git a/bus-mapping/Cargo.toml b/bus-mapping/Cargo.toml index eb7867cd17..8fa5e971c9 100644 --- a/bus-mapping/Cargo.toml +++ b/bus-mapping/Cargo.toml @@ -57,3 +57,6 @@ rpc-legacy-tracer = [] # and must be rebuild fix-refund = ["rpc-legacy-tracer"] retrace-tx = ["scroll", "external-tracer"] + +[lints] +workspace = true diff --git a/bus-mapping/src/lib.rs b/bus-mapping/src/lib.rs index e7a239ef0d..eb81d766e8 100644 --- a/bus-mapping/src/lib.rs +++ b/bus-mapping/src/lib.rs @@ -218,7 +218,6 @@ #![allow(clippy::result_large_err)] // it's large, but what can we do? #![allow(clippy::collapsible_else_if)] #![allow(incomplete_features)] -#![feature(lazy_cell)] #![feature(adt_const_params)] extern crate alloc; diff --git a/circuit-benchmarks/Cargo.toml b/circuit-benchmarks/Cargo.toml index 8ecaf2104f..26ab286529 100644 --- a/circuit-benchmarks/Cargo.toml +++ b/circuit-benchmarks/Cargo.toml @@ -29,3 +29,6 @@ default = [] benches = [] scroll = ["bus-mapping/scroll", "eth-types/scroll", "mock/scroll", "zkevm-circuits/scroll"] print-trace = ["ark-std/print-trace"] + +[lints] +workspace = true diff --git a/eth-types/Cargo.toml b/eth-types/Cargo.toml index 26c8469694..a693d0cbeb 100644 --- a/eth-types/Cargo.toml +++ b/eth-types/Cargo.toml @@ -39,3 +39,6 @@ scroll = ["revm-precompile/scroll", "revm-primitives/scroll"] enable-stack = [] enable-memory = [] enable-storage = [] + +[lints] +workspace = true diff --git a/eth-types/src/lib.rs b/eth-types/src/lib.rs index 92e2ecd336..c0461dcb29 100644 --- a/eth-types/src/lib.rs +++ b/eth-types/src/lib.rs @@ -10,7 +10,6 @@ #![deny(rustdoc::broken_intra_doc_links)] // GasCost is used as type parameter #![feature(adt_const_params)] -#![feature(lazy_cell)] #![deny(missing_docs)] //#![deny(unsafe_code)] Allowed now until we find a // better way to handle downcasting from Operation into it's variants. diff --git a/external-tracer/Cargo.toml b/external-tracer/Cargo.toml index 63a4b95602..c2b86fab25 100644 --- a/external-tracer/Cargo.toml +++ b/external-tracer/Cargo.toml @@ -18,3 +18,6 @@ scroll = ["eth-types/scroll", "geth-utils/scroll"] enable-stack = [] enable-memory = [] enable-storage = [] + +[lints] +workspace = true diff --git a/gadgets/Cargo.toml b/gadgets/Cargo.toml index 64b0da74b6..fecc48da24 100644 --- a/gadgets/Cargo.toml +++ b/gadgets/Cargo.toml @@ -17,3 +17,6 @@ rand.workspace = true [features] default = ["halo2_proofs/circuit-params"] + +[lints] +workspace = true diff --git a/geth-utils/Cargo.toml b/geth-utils/Cargo.toml index 9e0dcf6a52..cee2588e9d 100644 --- a/geth-utils/Cargo.toml +++ b/geth-utils/Cargo.toml @@ -12,3 +12,6 @@ env_logger.workspace = true [features] default = [] scroll = [] + +[lints] +workspace = true diff --git a/integration-tests/Cargo.toml b/integration-tests/Cargo.toml index 2961211f72..d1d19aa41f 100644 --- a/integration-tests/Cargo.toml +++ b/integration-tests/Cargo.toml @@ -36,4 +36,6 @@ mock_prover = [] scroll= ["bus-mapping/scroll", "eth-types/scroll", "mock/scroll", "zkevm-circuits/scroll"] fix-refund = ["bus-mapping/fix-refund"] rpc-legacy-tracer = ["bus-mapping/rpc-legacy-tracer"] -retrace-tx = ["bus-mapping/retrace-tx"] \ No newline at end of file +retrace-tx = ["bus-mapping/retrace-tx"] +[lints] +workspace = true diff --git a/integration-tests/src/lib.rs b/integration-tests/src/lib.rs index bcbd158762..5e161fc8ae 100644 --- a/integration-tests/src/lib.rs +++ b/integration-tests/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(lazy_cell)] //! Integration testing #![deny(rustdoc::broken_intra_doc_links)] diff --git a/integration-tests/tests/circuit_input_builder.rs b/integration-tests/tests/circuit_input_builder.rs index a8ee0a6c3f..2c88ac5d0e 100644 --- a/integration-tests/tests/circuit_input_builder.rs +++ b/integration-tests/tests/circuit_input_builder.rs @@ -1,4 +1,3 @@ -#![feature(lazy_cell)] #![cfg(feature = "circuit_input_builder")] use bus_mapping::circuit_input_builder::{build_state_code_db, BuilderClient, CircuitsParams}; diff --git a/integration-tests/tests/rpc.rs b/integration-tests/tests/rpc.rs index 706ee59c9d..4b31fe213a 100644 --- a/integration-tests/tests/rpc.rs +++ b/integration-tests/tests/rpc.rs @@ -1,4 +1,3 @@ -#![feature(lazy_cell)] #![cfg(feature = "rpc")] use eth_types::{StorageProof, Word}; diff --git a/mock/Cargo.toml b/mock/Cargo.toml index 01e9b46832..93fd3eccea 100644 --- a/mock/Cargo.toml +++ b/mock/Cargo.toml @@ -20,3 +20,6 @@ scroll = ["eth-types/scroll", "external-tracer/scroll"] enable-stack = ["eth-types/enable-stack", "external-tracer/enable-stack"] enable-memory = ["eth-types/enable-memory", "external-tracer/enable-memory"] enable-storage = ["eth-types/enable-storage", "external-tracer/enable-storage"] + +[lints] +workspace = true diff --git a/mock/src/lib.rs b/mock/src/lib.rs index 5d7c89c2cc..a7e8a1602e 100644 --- a/mock/src/lib.rs +++ b/mock/src/lib.rs @@ -1,4 +1,3 @@ -#![feature(lazy_cell)] //! Mock types and functions to generate GethData used for tests use eth_types::{address, bytecode, bytecode::Bytecode, word, Address, Bytes, Word}; diff --git a/prover/Cargo.toml b/prover/Cargo.toml index a51f7c5b6b..30ddae897b 100644 --- a/prover/Cargo.toml +++ b/prover/Cargo.toml @@ -35,6 +35,7 @@ serde_derive = "1.0" serde_json = { workspace = true, features = ["unbounded_depth"] } serde_stacker.workspace = true sha2 ="0.10.2" +revm = { version = "17.1.0", default-features = false, features = ["std"] } [features] default = ["scroll"] @@ -42,3 +43,6 @@ parallel_syn = ["halo2_proofs/parallel_syn", "zkevm-circuits/parallel_syn"] scroll = ["bus-mapping/scroll", "eth-types/scroll", "zkevm-circuits/scroll"] strict-ccc = ["bus-mapping/strict-ccc", "zkevm-circuits/strict-ccc"] test = [] + +[lints] +workspace = true diff --git a/prover/src/aggregator/prover.rs b/prover/src/aggregator/prover.rs index bb18fa0874..fcfe4831ee 100644 --- a/prover/src/aggregator/prover.rs +++ b/prover/src/aggregator/prover.rs @@ -93,7 +93,8 @@ impl<'params> Prover<'params> { .or_else(|| self.raw_vk_bundle.clone()) } - // Return the EVM proof for verification. + // Return the batch proof for a BatchProvingTask. + // TODO: should we rename the method name to `load_or_gen_batch_proof`? pub fn gen_batch_proof( &mut self, batch: BatchProvingTask, @@ -101,11 +102,19 @@ impl<'params> Prover<'params> { output_dir: Option<&str>, ) -> Result { let name = name.map_or_else(|| batch.identifier(), |name| name.to_string()); + log::info!("gen_batch_proof with identifier {name}"); + + if let Some(output_dir) = output_dir { + if let Ok(batch_proof) = BatchProof::from_json_file(output_dir, &name) { + log::info!("batch proof loaded from {output_dir}"); + return Ok(batch_proof); + } + } let (layer3_snark, batch_hash) = self.load_or_gen_last_agg_snark::(&name, batch, output_dir)?; - // Load or generate final compression thin EVM proof (layer-4). + // Load or generate batch compression thin proof (layer-4). let layer4_snark = self.prover_impl.load_or_gen_comp_snark( &name, LayerId::Layer4.id(), @@ -114,14 +123,16 @@ impl<'params> Prover<'params> { layer3_snark, output_dir, )?; - log::info!("Got final compression thin EVM proof (layer-4): {name}"); + log::info!("Got batch compression thin proof (layer-4): {name}"); self.check_batch_vk(); let pk = self.prover_impl.pk(LayerId::Layer4.id()); let batch_proof = BatchProof::new(layer4_snark, pk, batch_hash)?; if let Some(output_dir) = output_dir { - batch_proof.dump(output_dir, "agg")?; + batch_proof.dump_vk(output_dir, "agg")?; + batch_proof.dump(output_dir, &name)?; + log::debug!("batch proof dumped to {output_dir}"); } Ok(batch_proof) diff --git a/prover/src/evm.rs b/prover/src/evm.rs index b87541a042..fa5ad6f180 100644 --- a/prover/src/evm.rs +++ b/prover/src/evm.rs @@ -39,3 +39,69 @@ pub fn gen_evm_verifier>( let success = evm_proof.proof.evm_verify(deployment_code); assert!(success); } + +use revm::{ + primitives::{Env, ExecutionResult, Output, SpecId, TxEnv, TxKind}, + Evm, InMemoryDB, +}; + +/// Deploy contract and then call with calldata. +/// Returns gas_used of call to deployed contract if both transactions are successful. +pub fn deploy_and_call(deployment_code: Vec, calldata: Vec) -> Result { + let mut env = Box::::default(); + env.tx = TxEnv { + gas_limit: u64::MAX, + transact_to: TxKind::Create, + data: deployment_code.into(), + ..Default::default() + }; + let mut db = InMemoryDB::default(); + let mut evm = Evm::builder() + .with_spec_id(SpecId::CANCUN) + .with_db(&mut db) + .with_env(env.clone()) + .build(); + let result = evm.transact_commit().unwrap(); + let contract = match result { + ExecutionResult::Success { + output: Output::Create(_, Some(contract)), + .. + } => contract, + ExecutionResult::Revert { gas_used, output } => { + return Err(format!( + "Contract deployment transaction reverts with gas_used {gas_used} and output {:#x}", + output + )) + } + ExecutionResult::Halt { reason, gas_used } => return Err(format!( + "Contract deployment transaction halts unexpectedly with gas_used {gas_used} and reason {:?}", + reason + )), + _ => unreachable!(), + }; + drop(evm); + + env.tx = TxEnv { + gas_limit: u64::MAX, + transact_to: TxKind::Call(contract), + data: calldata.into(), + ..Default::default() + }; + let mut evm = Evm::builder() + .with_spec_id(SpecId::CANCUN) + .with_db(&mut db) + .with_env(env) + .build(); + let result = evm.transact_commit().unwrap(); + match result { + ExecutionResult::Success { gas_used, .. } => Ok(gas_used), + ExecutionResult::Revert { gas_used, output } => Err(format!( + "Contract call transaction reverts with gas_used {gas_used} and output {:#x}", + output + )), + ExecutionResult::Halt { reason, gas_used } => Err(format!( + "Contract call transaction halts unexpectedly with gas_used {gas_used} and reason {:?}", + reason + )), + } +} diff --git a/prover/src/io.rs b/prover/src/io.rs index 9b42e5a91b..644e1ac0aa 100644 --- a/prover/src/io.rs +++ b/prover/src/io.rs @@ -4,21 +4,28 @@ use halo2_proofs::{ plonk::{Circuit, VerifyingKey}, SerdeFormat, }; +use serde::de::Deserialize; use snark_verifier::util::arithmetic::PrimeField; use snark_verifier_sdk::Snark; +use std::io::BufReader; use std::{ fs::File, io::{Cursor, Read, Write}, path::{Path, PathBuf}, }; -pub fn from_json_file<'de, P: serde::Deserialize<'de>>(file_path: &str) -> anyhow::Result

{ - if !Path::new(&file_path).exists() { - anyhow::bail!("File {file_path} doesn't exist"); +pub fn from_json_file<'de, P, T>(filename: P) -> anyhow::Result +where + P: AsRef, + T: Deserialize<'de>, +{ + let file_path = filename.as_ref(); + if !file_path.exists() { + anyhow::bail!("File {:?} doesn't exist", file_path); } let fd = File::open(file_path)?; - let mut deserializer = serde_json::Deserializer::from_reader(fd); + let mut deserializer = serde_json::Deserializer::from_reader(BufReader::new(fd)); deserializer.disable_recursion_limit(); let deserializer = serde_stacker::Deserializer::new(&mut deserializer); @@ -53,7 +60,10 @@ pub fn serialize_instance(instance: &[Vec]) -> Vec { serde_json::to_vec(&instances_for_serde).unwrap() } -pub fn read_all(filename: &str) -> Vec { +pub fn read_all

(filename: P) -> Vec +where + P: AsRef, +{ let mut buf = vec![]; let mut fd = std::fs::File::open(filename).unwrap(); fd.read_to_end(&mut buf).unwrap(); @@ -76,7 +86,7 @@ pub fn try_to_read(dir: &str, filename: &str) -> Option> { path.push(filename); if path.exists() { - Some(read_all(&path.to_string_lossy())) + Some(read_all(path)) } else { None } @@ -102,7 +112,7 @@ pub fn serialize_vk(vk: &VerifyingKey) -> Vec { pub fn deserialize_vk>(raw_vk: &[u8]) -> VerifyingKey { VerifyingKey::::read::<_, C>(&mut Cursor::new(raw_vk), SerdeFormat::Processed, ()) - .unwrap() + .unwrap_or_else(|_| panic!("failed to deserialize vk with len {}", raw_vk.len())) } pub fn write_snark(file_path: &str, snark: &Snark) { diff --git a/prover/src/lib.rs b/prover/src/lib.rs index 64a9a14da2..a49b88e8f8 100644 --- a/prover/src/lib.rs +++ b/prover/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(lazy_cell)] - /// Meaning of each circuit: /// inner: first layer EVM super circuit /// layer1: compression circuit of "inner" @@ -27,6 +25,7 @@ pub use aggregator::{check_chunk_hashes, BatchData, BatchHash, BatchHeader, MAX_ pub use common::{ChunkInfo, CompressionCircuit}; pub use eth_types; pub use eth_types::l2_types::BlockTrace; +pub use evm::deploy_and_call; pub use proof::{BatchProof, BundleProof, ChunkProof, EvmProof, Proof}; pub use snark_verifier_sdk::{CircuitExt, Snark}; pub use types::{BatchProvingTask, BundleProvingTask, ChunkProvingTask, WitnessBlock}; diff --git a/prover/src/proof.rs b/prover/src/proof.rs index 1a0a3a2c95..4d5d8f81f9 100644 --- a/prover/src/proof.rs +++ b/prover/src/proof.rs @@ -9,7 +9,7 @@ use halo2_proofs::{ plonk::{Circuit, ProvingKey, VerifyingKey}, }; use serde_derive::{Deserialize, Serialize}; -use snark_verifier_sdk::{verify_evm_proof, Snark}; +use snark_verifier_sdk::Snark; use std::{fs::File, path::PathBuf}; mod batch; @@ -71,7 +71,11 @@ impl Proof { } pub fn evm_verify(&self, deployment_code: Vec) -> bool { - verify_evm_proof(deployment_code, self.instances(), self.proof().to_vec()) + let instances = self.instances(); + let proof = self.proof().to_vec(); + let calldata = snark_verifier::loader::evm::encode_calldata(&instances, &proof); + let result = crate::evm::deploy_and_call(deployment_code, calldata); + result.is_ok() } pub fn instances(&self) -> Vec> { @@ -115,7 +119,7 @@ pub fn dump_vk(dir: &str, filename: &str, raw_vk: &[u8]) { pub fn from_json_file<'de, P: serde::Deserialize<'de>>(dir: &str, filename: &str) -> Result

{ let file_path = dump_proof_path(dir, filename); - crate::io::from_json_file(&file_path) + crate::io::from_json_file(file_path) } fn dump_proof_path(dir: &str, filename: &str) -> String { diff --git a/prover/src/proof/batch.rs b/prover/src/proof/batch.rs index 5cce5e1a08..e0f4aec4f8 100644 --- a/prover/src/proof/batch.rs +++ b/prover/src/proof/batch.rs @@ -45,11 +45,18 @@ impl BatchProof { from_json_file(dir, &dump_filename(name)) } - pub fn dump(&self, dir: &str, name: &str) -> Result<()> { + pub fn dump_vk(&self, dir: &str, name: &str) -> Result<()> { let filename = dump_filename(name); + if self.proof.vk.is_empty() { + log::warn!("batch proof vk is empty, skip dumping"); + } else { + dump_vk(dir, &filename, &self.proof.vk) + } + Ok(()) + } - dump_vk(dir, &filename, &self.proof.vk); - + pub fn dump(&self, dir: &str, name: &str) -> Result<()> { + let filename = dump_filename(name); dump_as_json(dir, &filename, &self) } } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 584353ad1c..804a8d6114 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "nightly-2024-01-25" +channel = "nightly-2024-07-07" diff --git a/testool/Cargo.toml b/testool/Cargo.toml index 43fbc9e17e..b0c66d48df 100644 --- a/testool/Cargo.toml +++ b/testool/Cargo.toml @@ -65,3 +65,6 @@ chunk-prove = ["prover/test", "parallel_syn", "scroll"] enable-stack = ["zkevm-circuits/enable-stack"] enable-memory = ["zkevm-circuits/enable-memory"] enable-storage = ["zkevm-circuits/enable-storage"] + +[lints] +workspace = true diff --git a/testool/src/bin/testool.rs b/testool/src/bin/testool.rs index fe315f096f..a25cc8a996 100644 --- a/testool/src/bin/testool.rs +++ b/testool/src/bin/testool.rs @@ -1,4 +1,3 @@ -#![feature(lazy_cell)] //! Execute the bytecode from an empty state and run the EVM and State circuits use anyhow::{bail, Result}; diff --git a/testool/src/lib.rs b/testool/src/lib.rs index 5d368bfb07..2a4e2b3ac5 100644 --- a/testool/src/lib.rs +++ b/testool/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(lazy_cell)] - #[macro_use] extern crate prettytable; diff --git a/zkevm-circuits/Cargo.toml b/zkevm-circuits/Cargo.toml index 70f20eeed8..b138489a6a 100644 --- a/zkevm-circuits/Cargo.toml +++ b/zkevm-circuits/Cargo.toml @@ -74,3 +74,6 @@ enable-memory = ["bus-mapping/enable-memory"] enable-storage = ["bus-mapping/enable-storage"] dual-bytecode = [] + +[lints] +workspace = true diff --git a/zkevm-circuits/src/lib.rs b/zkevm-circuits/src/lib.rs index 3f9eebae0e..833901890f 100644 --- a/zkevm-circuits/src/lib.rs +++ b/zkevm-circuits/src/lib.rs @@ -6,7 +6,6 @@ // Needed by DummyGadget in evm circuit #![feature(adt_const_params)] #![feature(trait_alias)] -#![feature(lazy_cell)] // Needed by some builder patterns in testing modules. #![cfg_attr(docsrs, feature(doc_cfg))] // Temporary until we have more of the crate implemented. diff --git a/zktrie/Cargo.toml b/zktrie/Cargo.toml index 33cc999f4c..6d902a1228 100644 --- a/zktrie/Cargo.toml +++ b/zktrie/Cargo.toml @@ -22,3 +22,6 @@ serde_json.workspace = true [features] default = [] + +[lints] +workspace = true