From 8feb7158fac0c2eb663ad24fef9c0c18aafdbc2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Yaz=C4=B1c=C4=B1?= <75089142+yaziciahmet@users.noreply.github.com> Date: Sat, 21 Dec 2024 21:11:56 +0100 Subject: [PATCH] Set ZK constants in compile time (#1613) Co-authored-by: jfldde <168934971+jfldde@users.noreply.github.com> --- .github/workflows/checks.yml | 14 +- .github/workflows/release.yml | 4 +- Cargo.lock | 31 +- Cargo.toml | 2 +- Makefile | 6 +- bin/citrea/Cargo.toml | 10 +- bin/citrea/src/guests.rs | 32 +- bin/citrea/src/lib.rs | 2 +- bin/citrea/src/main.rs | 3 +- bin/citrea/src/rollup/bitcoin.rs | 32 +- bin/citrea/src/rollup/mock.rs | 25 +- bin/citrea/src/rollup/mod.rs | 15 +- .../tests/bitcoin_e2e/batch_prover_test.rs | 21 +- .../tests/bitcoin_e2e/light_client_test.rs | 19 - bin/citrea/tests/e2e/mod.rs | 5 +- bin/citrea/tests/test_helpers/mod.rs | 24 +- crates/batch-prover/Cargo.toml | 1 - crates/batch-prover/src/da_block_handler.rs | 7 +- crates/batch-prover/src/proving.rs | 8 +- crates/batch-prover/src/runner.rs | 4 +- crates/batch-prover/tests/prover_tests.rs | 6 +- crates/citrea-stf/src/lib.rs | 4 +- crates/citrea-stf/src/verifier.rs | 41 +- crates/evm/src/evm/conversions.rs | 5 +- crates/evm/src/query.rs | 16 +- crates/evm/src/tests/call_tests.rs | 133 ++-- crates/evm/src/tests/fork_tests.rs | 12 +- crates/evm/src/tests/genesis_tests.rs | 2 +- crates/evm/src/tests/hooks_tests.rs | 38 +- .../src/tests/queries/estimate_gas_tests.rs | 6 +- crates/evm/src/tests/queries/log_tests.rs | 18 +- crates/evm/src/tests/sys_tx_tests.rs | 42 +- crates/evm/src/tests/utils.rs | 10 +- crates/fullnode/src/da_block_handler.rs | 6 +- crates/fullnode/src/runner.rs | 4 +- crates/light-client-prover/src/circuit.rs | 27 +- .../src/da_block_handler.rs | 23 +- crates/light-client-prover/src/tests/mod.rs | 187 +++--- crates/primitives/src/forks.rs | 106 +-- crates/prover-services/Cargo.toml | 7 - crates/prover-services/src/lib.rs | 40 +- crates/prover-services/src/parallel/mod.rs | 65 +- crates/sequencer/src/runner.rs | 4 +- .../adapters/mock-da/src/service.rs | 4 +- .../adapters/mock-da/src/types/address.rs | 128 ++-- .../adapters/mock-da/src/types/mod.rs | 2 +- .../adapters/mock-da/src/verifier.rs | 2 +- .../full-node/db/sov-db/src/schema/types.rs | 3 - .../full-node/sov-stf-runner/src/mock/mod.rs | 2 + .../sov-stf-runner/src/prover_service/mod.rs | 3 - .../sov-modules-rollup-blueprint/src/lib.rs | 17 +- .../sov-modules-stf-blueprint/Cargo.toml | 1 - .../sov-modules-stf-blueprint/src/lib.rs | 5 +- .../sovereign-sdk/rollup-interface/Makefile | 2 +- .../rollup-interface/src/fork/manager.rs | 25 +- .../rollup-interface/src/fork/mod.rs | 51 ++ .../rollup-interface/src/fork/tests.rs | 12 +- .../sovereign-sdk/rollup-interface/src/lib.rs | 3 + .../rollup-interface/src/network.rs | 34 + .../rollup-interface/src/node/rpc/mod.rs | 3 - .../rollup-interface/src/spec.rs | 103 ++- .../rollup-interface/src/state_machine/stf.rs | 2 + .../src/state_machine/zk/mod.rs | 10 +- crates/sp1/src/guest.rs | 6 +- guests/risc0/Dockerfile | 8 +- guests/risc0/Makefile | 21 +- .../src/bin/batch_proof_bitcoin.rs | 32 - .../src/bin/batch_proof_mock.rs | 23 - guests/risc0/{ => batch-proof}/Cargo.toml | 8 +- .../bitcoin}/Cargo.lock | 2 +- .../bitcoin}/Cargo.toml | 17 +- .../bitcoin/src/bin/batch_proof_bitcoin.rs | 94 +++ guests/risc0/batch-proof/build.rs | 80 +++ .../mock}/Cargo.lock | 3 +- .../mock}/Cargo.toml | 16 +- .../mock/src/bin/batch_proof_mock.rs | 44 ++ guests/risc0/{ => batch-proof}/src/lib.rs | 0 .../light-client-proof-bitcoin/Cargo.toml | 37 -- .../src/bin/light_client_proof_bitcoin.rs | 23 - .../risc0/light-client-proof-mock/Cargo.toml | 37 -- .../src/bin/light_client_proof_mock.rs | 17 - guests/risc0/light-client-proof/Cargo.toml | 20 + .../bitcoin}/Cargo.lock | 608 ++++++++++++++++- .../light-client-proof/bitcoin/Cargo.toml | 40 ++ .../src/bin/light_client_proof_bitcoin.rs | 100 +++ .../risc0/{ => light-client-proof}/build.rs | 12 +- .../mock}/Cargo.lock | 610 +++++++++++------- .../risc0/light-client-proof/mock/Cargo.toml | 40 ++ .../mock/src/bin/light_client_proof_mock.rs | 31 + guests/risc0/light-client-proof/src/lib.rs | 1 + .../Cargo.lock | 16 +- .../Cargo.toml | 17 +- guests/sp1/batch-proof-bitcoin/src/main.rs | 94 +++ guests/sp1/batch-prover-bitcoin/src/main.rs | 32 - guests/sp1/build.rs | 2 +- .../light_client_prover_rollup_config.toml | 2 +- .../bitcoin-regtest/rollup_config.toml | 2 +- .../mock/batch_prover_rollup_config.toml | 25 + resources/configs/mock/rollup_config.toml | 6 +- .../configs/mock/sequencer_rollup_config.toml | 4 +- 100 files changed, 2332 insertions(+), 1277 deletions(-) create mode 100644 crates/sovereign-sdk/rollup-interface/src/network.rs delete mode 100644 guests/risc0/batch-proof-bitcoin/src/bin/batch_proof_bitcoin.rs delete mode 100644 guests/risc0/batch-proof-mock/src/bin/batch_proof_mock.rs rename guests/risc0/{ => batch-proof}/Cargo.toml (66%) rename guests/risc0/{batch-proof-bitcoin => batch-proof/bitcoin}/Cargo.lock (99%) rename guests/risc0/{batch-proof-bitcoin => batch-proof/bitcoin}/Cargo.toml (57%) create mode 100644 guests/risc0/batch-proof/bitcoin/src/bin/batch_proof_bitcoin.rs create mode 100644 guests/risc0/batch-proof/build.rs rename guests/risc0/{batch-proof-mock => batch-proof/mock}/Cargo.lock (99%) rename guests/risc0/{batch-proof-mock => batch-proof/mock}/Cargo.toml (56%) create mode 100644 guests/risc0/batch-proof/mock/src/bin/batch_proof_mock.rs rename guests/risc0/{ => batch-proof}/src/lib.rs (100%) delete mode 100644 guests/risc0/light-client-proof-bitcoin/Cargo.toml delete mode 100644 guests/risc0/light-client-proof-bitcoin/src/bin/light_client_proof_bitcoin.rs delete mode 100644 guests/risc0/light-client-proof-mock/Cargo.toml delete mode 100644 guests/risc0/light-client-proof-mock/src/bin/light_client_proof_mock.rs create mode 100644 guests/risc0/light-client-proof/Cargo.toml rename guests/risc0/{light-client-proof-mock => light-client-proof/bitcoin}/Cargo.lock (74%) create mode 100644 guests/risc0/light-client-proof/bitcoin/Cargo.toml create mode 100644 guests/risc0/light-client-proof/bitcoin/src/bin/light_client_proof_bitcoin.rs rename guests/risc0/{ => light-client-proof}/build.rs (87%) rename guests/risc0/{light-client-proof-bitcoin => light-client-proof/mock}/Cargo.lock (84%) create mode 100644 guests/risc0/light-client-proof/mock/Cargo.toml create mode 100644 guests/risc0/light-client-proof/mock/src/bin/light_client_proof_mock.rs create mode 100644 guests/risc0/light-client-proof/src/lib.rs rename guests/sp1/{batch-prover-bitcoin => batch-proof-bitcoin}/Cargo.lock (99%) rename guests/sp1/{batch-prover-bitcoin => batch-proof-bitcoin}/Cargo.toml (77%) create mode 100644 guests/sp1/batch-proof-bitcoin/src/main.rs delete mode 100644 guests/sp1/batch-prover-bitcoin/src/main.rs create mode 100644 resources/configs/mock/batch_prover_rollup_config.toml diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 48744f3d4..8b44a1407 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -98,7 +98,7 @@ jobs: - name: Build citrea run: make build-release env: - REPR_GUEST_BUILD: 1 + CITREA_NETWORK: nightly - name: Upload artifact uses: actions/upload-artifact@v4 @@ -267,9 +267,9 @@ jobs: run: npm install - name: Run uniswap tests run: | - RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ & + RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ --dev & sleep 2 - RUST_LOG=off ./target/release/citrea --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ & + RUST_LOG=off ./target/release/citrea --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ --dev & sleep 2 cd ./bin/citrea/tests/evm/uniswap npx hardhat run --network citrea scripts/01_deploy.js @@ -310,9 +310,9 @@ jobs: run: pip install -r requirements.txt - name: Run web3.py tests run: | - RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ & + RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ --dev & sleep 2 - RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ & + RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ --dev & sleep 2 cd ./bin/citrea/tests/evm/web3_py python test.py @@ -338,9 +338,9 @@ jobs: run: npm install - name: Run ethers_js tests run: | - RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ & + RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/sequencer_rollup_config.toml --sequencer resources/configs/mock/sequencer_config.toml --genesis-paths resources/genesis/mock/ --dev & sleep 2 - RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ & + RUST_LOG=off ./target/release/citrea --da-layer mock --rollup-config-path resources/configs/mock/rollup_config.toml --genesis-paths resources/genesis/mock/ --dev & sleep 2 cd ./bin/citrea/tests/evm/ethers_js npm install diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d97a7faf0..055f926a4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -40,7 +40,7 @@ jobs: - name: Build Project env: - REPR_GUEST_BUILD: 1 + SKIP_GUEST_BUILD: 1 run: | cargo build --release @@ -76,7 +76,7 @@ jobs: github_token: ${{ secrets.GITHUB_TOKEN }} - name: Build Project env: - REPR_GUEST_BUILD: 1 + SKIP_GUEST_BUILD: 1 run: | source $HOME/.cargo/env cargo build --release diff --git a/Cargo.lock b/Cargo.lock index 51ce6996c..817531156 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1809,6 +1809,8 @@ dependencies = [ "citrea-light-client-prover", "citrea-primitives", "citrea-risc0-adapter", + "citrea-risc0-batch-proof", + "citrea-risc0-light-client", "citrea-sequencer", "citrea-stf", "clap", @@ -1827,7 +1829,6 @@ dependencies = [ "reth-primitives", "reth-transaction-pool", "revm", - "risc0", "risc0-binfmt", "rs_merkle", "rustc_version_runtime", @@ -1865,7 +1866,6 @@ dependencies = [ "borsh", "citrea-common", "citrea-primitives", - "citrea-stf", "futures", "hex", "jsonrpsee", @@ -1931,7 +1931,7 @@ dependencies = [ [[package]] name = "citrea-e2e" version = "0.1.0" -source = "git+https://github.com/chainwayxyz/citrea-e2e?rev=51a4d19#51a4d1958ead4021115bd81ac9aa1b1fcf6f7e0c" +source = "git+https://github.com/chainwayxyz/citrea-e2e?rev=6a87ce3#6a87ce3f3576392451a10fa1a52d678befc1eba6" dependencies = [ "anyhow", "async-trait", @@ -2119,6 +2119,20 @@ dependencies = [ "tracing", ] +[[package]] +name = "citrea-risc0-batch-proof" +version = "0.5.0-rc.1" +dependencies = [ + "risc0-build", +] + +[[package]] +name = "citrea-risc0-light-client" +version = "0.5.0-rc.1" +dependencies = [ + "risc0-build", +] + [[package]] name = "citrea-sequencer" version = "0.5.0-rc.1" @@ -5469,8 +5483,6 @@ dependencies = [ "async-trait", "bincode", "borsh", - "citrea-primitives", - "citrea-stf", "futures", "hex", "jsonrpsee", @@ -5478,7 +5490,6 @@ dependencies = [ "parking_lot", "rand", "rayon", - "rs_merkle", "serde", "sha2", "sov-db", @@ -7133,13 +7144,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "risc0" -version = "0.5.0-rc.1" -dependencies = [ - "risc0-build", -] - [[package]] name = "risc0-binfmt" version = "1.1.3" @@ -8335,7 +8339,6 @@ version = "0.5.0-rc.1" dependencies = [ "anyhow", "borsh", - "citrea-primitives", "hex", "itertools 0.13.0", "jmt", diff --git a/Cargo.toml b/Cargo.toml index cba031550..71b4e3b84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -155,7 +155,7 @@ alloy-eips = { version = "0.4.2", default-features = false } alloy-consensus = { version = "0.4.2", default-features = false, features = ["serde", "serde-bincode-compat"] } alloy-network = { version = "0.4.2", default-features = false } -citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "51a4d19" } +citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "6a87ce3" } [patch.crates-io] bitcoincore-rpc = { version = "0.18.0", git = "https://github.com/chainwayxyz/rust-bitcoincore-rpc.git", rev = "ca3cfa2" } diff --git a/Makefile b/Makefile index 0225ab27d..88c283c65 100644 --- a/Makefile +++ b/Makefile @@ -11,10 +11,6 @@ LIGHT_OUT_PATH := resources/guests/risc0/ help: ## Display this help message @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) -.PHONY: build-risc0 -build-risc0: - $(MAKE) -j 2 -C guests/risc0 all - .PHONY: build-risc0-docker build-risc0-docker: $(MAKE) -C guests/risc0 batch-proof-bitcoin-docker OUT_PATH=$(BATCH_OUT_PATH) @@ -32,7 +28,7 @@ build: ## Build the project build-test: ## Build the project @cargo build $(TEST_FEATURES) -build-release: build-risc0 build-sp1 ## Build the project in release mode +build-release: build-risc0-docker build-sp1 ## Build the project in release mode @cargo build --release clean: ## Cleans compiled diff --git a/bin/citrea/Cargo.toml b/bin/citrea/Cargo.toml index f78e815a9..13213e6da 100644 --- a/bin/citrea/Cargo.toml +++ b/bin/citrea/Cargo.toml @@ -19,8 +19,9 @@ citrea-common = { path = "../../crates/common" } citrea-fullnode = { path = "../../crates/fullnode" } citrea-light-client-prover = { path = "../../crates/light-client-prover", features = ["native"] } citrea-primitives = { path = "../../crates/primitives" } -citrea-risc0 = { package = "risc0", path = "../../guests/risc0" } citrea-risc0-adapter = { path = "../../crates/risc0", features = ["native"] } +citrea-risc0-batch-proof = { path = "../../guests/risc0/batch-proof" } +citrea-risc0-light-client = { path = "../../guests/risc0/light-client-proof" } citrea-sequencer = { path = "../../crates/sequencer" } # citrea-sp1 = { path = "../../crates/sp1", features = ["native"] } citrea-stf = { path = "../../crates/citrea-stf", features = ["native"] } @@ -102,7 +103,12 @@ sp1-helper = { version = "3.0.0", default-features = false } [features] default = [] # Deviate from convention by making the "native" feature active by default. This aligns with how this package is meant to be used (as a binary first, library second). -testing = ["citrea-primitives/testing", "citrea-risc0/testing", "sov-rollup-interface/testing"] +testing = [ + "citrea-primitives/testing", + "citrea-risc0-batch-proof/testing", + "citrea-risc0-light-client/testing", + "sov-rollup-interface/testing", +] [[bin]] name = "citrea" diff --git a/bin/citrea/src/guests.rs b/bin/citrea/src/guests.rs index f0fa4db98..d4ccd9199 100644 --- a/bin/citrea/src/guests.rs +++ b/bin/citrea/src/guests.rs @@ -19,26 +19,50 @@ lazy_static! { pub(crate) static ref BATCH_PROOF_LATEST_MOCK_GUESTS: HashMap)> = { let mut m = HashMap::new(); - m.insert(SpecId::Genesis, (Digest::new(citrea_risc0::BATCH_PROOF_MOCK_ID), citrea_risc0::BATCH_PROOF_MOCK_ELF.to_vec())); + m.insert( + SpecId::Fork1, + ( + Digest::new(citrea_risc0_batch_proof::BATCH_PROOF_MOCK_ID), + citrea_risc0_batch_proof::BATCH_PROOF_MOCK_ELF.to_vec(), + ), + ); m }; pub(crate) static ref LIGHT_CLIENT_LATEST_MOCK_GUESTS: HashMap)> = { let mut m = HashMap::new(); - m.insert(SpecId::Genesis, (Digest::new(citrea_risc0::LIGHT_CLIENT_PROOF_MOCK_ID), citrea_risc0::LIGHT_CLIENT_PROOF_MOCK_ELF.to_vec())); + m.insert( + SpecId::Fork1, + ( + Digest::new(citrea_risc0_light_client::LIGHT_CLIENT_PROOF_MOCK_ID), + citrea_risc0_light_client::LIGHT_CLIENT_PROOF_MOCK_ELF.to_vec(), + ) + ); m }; /// The following 2 are used as latest guest builds for tests that use Bitcoin DA. pub(crate) static ref BATCH_PROOF_LATEST_BITCOIN_GUESTS: HashMap)> = { let mut m = HashMap::new(); - m.insert(SpecId::Genesis, (Digest::new(citrea_risc0::BATCH_PROOF_BITCOIN_ID), citrea_risc0::BATCH_PROOF_BITCOIN_ELF.to_vec())); + m.insert( + SpecId::Fork1, + ( + Digest::new(citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ID), + citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ELF.to_vec(), + ) + ); m }; pub(crate) static ref LIGHT_CLIENT_LATEST_BITCOIN_GUESTS: HashMap)> = { let mut m = HashMap::new(); - m.insert(SpecId::Genesis, (Digest::new(citrea_risc0::LIGHT_CLIENT_PROOF_BITCOIN_ID), citrea_risc0::LIGHT_CLIENT_PROOF_BITCOIN_ELF.to_vec())); + m.insert( + SpecId::Fork1, + ( + Digest::new(citrea_risc0_light_client::LIGHT_CLIENT_PROOF_BITCOIN_ID), + citrea_risc0_light_client::LIGHT_CLIENT_PROOF_BITCOIN_ELF.to_vec(), + ) + ); m }; /// Production guests diff --git a/bin/citrea/src/lib.rs b/bin/citrea/src/lib.rs index a661c1153..212c7be71 100644 --- a/bin/citrea/src/lib.rs +++ b/bin/citrea/src/lib.rs @@ -5,7 +5,7 @@ use std::env; use std::str::FromStr; use serde::Serialize; -use sov_modules_rollup_blueprint::Network; +use sov_rollup_interface::Network; use tracing::Level; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; diff --git a/bin/citrea/src/main.rs b/bin/citrea/src/main.rs index d6596a0f9..5cb41d89d 100644 --- a/bin/citrea/src/main.rs +++ b/bin/citrea/src/main.rs @@ -17,7 +17,8 @@ use metrics_exporter_prometheus::PrometheusBuilder; use metrics_util::MetricKindMask; use sov_mock_da::MockDaConfig; use sov_modules_api::Spec; -use sov_modules_rollup_blueprint::{Network, RollupBlueprint}; +use sov_modules_rollup_blueprint::RollupBlueprint; +use sov_rollup_interface::Network; use sov_state::storage::NativeStorage; use tracing::{debug, error, info, instrument}; diff --git a/bin/citrea/src/rollup/bitcoin.rs b/bin/citrea/src/rollup/bitcoin.rs index db874e489..6a6c4232c 100644 --- a/bin/citrea/src/rollup/bitcoin.rs +++ b/bin/citrea/src/rollup/bitcoin.rs @@ -9,25 +9,24 @@ use bitcoin_da::verifier::BitcoinVerifier; use citrea_common::rpc::register_healthcheck_rpc; use citrea_common::tasks::manager::TaskManager; use citrea_common::FullNodeConfig; +use citrea_primitives::forks::use_network_forks; use citrea_primitives::{TO_BATCH_PROOF_PREFIX, TO_LIGHT_CLIENT_PREFIX}; use citrea_risc0_adapter::host::Risc0BonsaiHost; // use citrea_sp1::host::SP1Host; use citrea_stf::genesis_config::StorageConfig; use citrea_stf::runtime::Runtime; -use citrea_stf::verifier::StateTransitionVerifier; use prover_services::{ParallelProverService, ProofGenMode}; use sov_db::ledger_db::LedgerDB; use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext}; use sov_modules_api::{Address, SpecId, Zkvm}; use sov_modules_rollup_blueprint::RollupBlueprint; -use sov_modules_stf_blueprint::StfBlueprint; use sov_prover_storage_manager::{ProverStorageManager, SnapshotManager}; use sov_rollup_interface::da::DaVerifier; use sov_rollup_interface::services::da::SenderWithNotifier; -use sov_state::{ProverStorage, ZkStorage}; +use sov_state::ProverStorage; use sov_stf_runner::ProverGuestRunConfig; +use tokio::sync::broadcast; use tokio::sync::mpsc::unbounded_channel; -use tokio::sync::{broadcast, Mutex}; use tracing::instrument; use crate::guests::{ @@ -57,13 +56,10 @@ impl RollupBlueprint for BitcoinRollup { type ZkRuntime = Runtime; type NativeRuntime = Runtime; - type ProverService = ParallelProverService< - Self::DaService, - Self::Vm, - StfBlueprint, - >; + type ProverService = ParallelProverService; fn new(network: Network) -> Self { + use_network_forks(network); Self { network } } @@ -259,7 +255,6 @@ impl RollupBlueprint for BitcoinRollup { &self, proving_mode: ProverGuestRunConfig, da_service: &Arc, - da_verifier: Self::DaVerifier, ledger_db: LedgerDB, proof_sampling_number: usize, ) -> Self::ProverService { @@ -269,15 +264,8 @@ impl RollupBlueprint for BitcoinRollup { // ledger_db.clone(), // ); - let zk_stf = StfBlueprint::new(); - let zk_storage = ZkStorage::new(); - let proof_mode = match proving_mode { ProverGuestRunConfig::Skip => ProofGenMode::Skip, - ProverGuestRunConfig::Simulate => { - let stf_verifier = StateTransitionVerifier::new(zk_stf, da_verifier); - ProofGenMode::Simulate(Arc::new(Mutex::new(stf_verifier))) - } ProverGuestRunConfig::Execute => ProofGenMode::Execute, ProverGuestRunConfig::Prove => ProofGenMode::ProveWithSampling, ProverGuestRunConfig::ProveWithFakeProofs => { @@ -285,13 +273,7 @@ impl RollupBlueprint for BitcoinRollup { } }; - ParallelProverService::new_from_env( - da_service.clone(), - vm, - proof_mode, - zk_storage, - ledger_db, - ) - .expect("Should be able to instantiate prover service") + ParallelProverService::new_from_env(da_service.clone(), vm, proof_mode, ledger_db) + .expect("Should be able to instantiate prover service") } } diff --git a/bin/citrea/src/rollup/mock.rs b/bin/citrea/src/rollup/mock.rs index e47662608..10cd1e865 100644 --- a/bin/citrea/src/rollup/mock.rs +++ b/bin/citrea/src/rollup/mock.rs @@ -5,22 +5,20 @@ use async_trait::async_trait; use citrea_common::rpc::register_healthcheck_rpc; use citrea_common::tasks::manager::TaskManager; use citrea_common::FullNodeConfig; +use citrea_primitives::forks::use_network_forks; // use citrea_sp1::host::SP1Host; use citrea_risc0_adapter::host::Risc0BonsaiHost; use citrea_stf::genesis_config::StorageConfig; use citrea_stf::runtime::Runtime; -use citrea_stf::verifier::StateTransitionVerifier; use prover_services::{ParallelProverService, ProofGenMode}; use sov_db::ledger_db::LedgerDB; use sov_mock_da::{MockDaConfig, MockDaService, MockDaSpec, MockDaVerifier}; use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext}; use sov_modules_api::{Address, Spec, SpecId, Zkvm}; use sov_modules_rollup_blueprint::RollupBlueprint; -use sov_modules_stf_blueprint::StfBlueprint; use sov_prover_storage_manager::ProverStorageManager; -use sov_state::ZkStorage; use sov_stf_runner::ProverGuestRunConfig; -use tokio::sync::{broadcast, Mutex}; +use tokio::sync::broadcast; use crate::guests::{BATCH_PROOF_LATEST_MOCK_GUESTS, LIGHT_CLIENT_LATEST_MOCK_GUESTS}; use crate::{CitreaRollupBlueprint, Network}; @@ -43,13 +41,10 @@ impl RollupBlueprint for MockDemoRollup { type NativeContext = DefaultContext; type ZkRuntime = Runtime; type NativeRuntime = Runtime; - type ProverService = ParallelProverService< - Self::DaService, - Self::Vm, - StfBlueprint, - >; + type ProverService = ParallelProverService; fn new(network: Network) -> Self { + use_network_forks(network); Self { _network: network } } @@ -91,7 +86,7 @@ impl RollupBlueprint for MockDemoRollup { _task_manager: &mut TaskManager<()>, ) -> Result, anyhow::Error> { Ok(Arc::new(MockDaService::new( - rollup_config.da.sender_address, + rollup_config.da.sender_address.clone(), &rollup_config.da.db_path, ))) } @@ -136,21 +131,13 @@ impl RollupBlueprint for MockDemoRollup { &self, proving_mode: ProverGuestRunConfig, da_service: &Arc, - da_verifier: Self::DaVerifier, ledger_db: LedgerDB, proof_sampling_number: usize, ) -> Self::ProverService { let vm = Risc0BonsaiHost::new(ledger_db.clone()); - let zk_stf = StfBlueprint::new(); - let zk_storage = ZkStorage::new(); - let proof_mode = match proving_mode { ProverGuestRunConfig::Skip => ProofGenMode::Skip, - ProverGuestRunConfig::Simulate => { - let stf_verifier = StateTransitionVerifier::new(zk_stf, da_verifier); - ProofGenMode::Simulate(Arc::new(Mutex::new(stf_verifier))) - } ProverGuestRunConfig::Execute => ProofGenMode::Execute, ProverGuestRunConfig::Prove => ProofGenMode::ProveWithSampling, ProverGuestRunConfig::ProveWithFakeProofs => { @@ -158,7 +145,7 @@ impl RollupBlueprint for MockDemoRollup { } }; - ParallelProverService::new(da_service.clone(), vm, proof_mode, zk_storage, 1, ledger_db) + ParallelProverService::new(da_service.clone(), vm, proof_mode, 1, ledger_db) .expect("Should be able to instantiate prover service") } diff --git a/bin/citrea/src/rollup/mod.rs b/bin/citrea/src/rollup/mod.rs index 8968ed7c9..8e36c8f91 100644 --- a/bin/citrea/src/rollup/mod.rs +++ b/bin/citrea/src/rollup/mod.rs @@ -7,7 +7,7 @@ use citrea_common::tasks::manager::TaskManager; use citrea_common::{BatchProverConfig, FullNodeConfig, LightClientProverConfig, SequencerConfig}; use citrea_fullnode::CitreaFullnode; use citrea_light_client_prover::runner::CitreaLightClientProver; -use citrea_primitives::forks::FORKS; +use citrea_primitives::forks::get_forks; use citrea_sequencer::CitreaSequencer; use jsonrpsee::RpcModule; use sov_db::ledger_db::migrations::LedgerDBMigrator; @@ -125,7 +125,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { .map(|(l2_height, _)| l2_height) .unwrap_or(SoftConfirmationNumber(0)); - let mut fork_manager = ForkManager::new(FORKS, current_l2_height.0); + let mut fork_manager = ForkManager::new(get_forks(), current_l2_height.0); fork_manager.register_handler(Box::new(ledger_db.clone())); let seq = CitreaSequencer::new( @@ -256,7 +256,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { .map(|(l2_height, _)| l2_height) .unwrap_or(SoftConfirmationNumber(0)); - let mut fork_manager = ForkManager::new(FORKS, current_l2_height.0); + let mut fork_manager = ForkManager::new(get_forks(), current_l2_height.0); fork_manager.register_handler(Box::new(ledger_db.clone())); let runner = CitreaFullnode::new( @@ -309,8 +309,6 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { .create_da_service(&rollup_config, true, &mut task_manager) .await?; - let da_verifier = self.create_da_verifier(); - // Migrate before constructing ledger_db instance so that no lock is present. let migrator = LedgerDBMigrator::new( rollup_config.storage.path.as_path(), @@ -329,7 +327,6 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { .create_prover_service( prover_config.proving_mode, &da_service, - da_verifier, ledger_db.clone(), prover_config.proof_sampling_number, ) @@ -394,7 +391,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { .map_err(|e| anyhow!("Failed to get head soft confirmation: {}", e))? .unwrap_or(0); - let mut fork_manager = ForkManager::new(FORKS, current_l2_height); + let mut fork_manager = ForkManager::new(get_forks(), current_l2_height); fork_manager.register_handler(Box::new(ledger_db.clone())); let runner = CitreaBatchProver::new( @@ -445,7 +442,6 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { let da_service = self .create_da_service(&rollup_config, true, &mut task_manager) .await?; - let da_verifier = self.create_da_verifier(); let rocksdb_config = RocksdbConfig::new( rollup_config.storage.path.as_path(), @@ -458,7 +454,6 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { .create_prover_service( prover_config.proving_mode, &da_service, - da_verifier, ledger_db.clone(), prover_config.proof_sampling_number, ) @@ -491,7 +486,7 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { .map(|(l2_height, _)| l2_height) .unwrap_or(SoftConfirmationNumber(0)); - let mut fork_manager = ForkManager::new(FORKS, current_l2_height.0); + let mut fork_manager = ForkManager::new(get_forks(), current_l2_height.0); fork_manager.register_handler(Box::new(ledger_db.clone())); let runner = CitreaLightClientProver::new( diff --git a/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs b/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs index cd0797981..1d70e07fb 100644 --- a/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs +++ b/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs @@ -147,6 +147,13 @@ impl TestCase for SkipPreprovenCommitmentsTest { } } + fn sequencer_config() -> SequencerConfig { + SequencerConfig { + min_soft_confirmations_per_commitment: 1, + ..Default::default() + } + } + async fn run_test(&mut self, f: &mut TestFramework) -> Result<()> { let da = f.bitcoin_nodes.get(0).unwrap(); let sequencer = f.sequencer.as_ref().unwrap(); @@ -164,13 +171,19 @@ impl TestCase for SkipPreprovenCommitmentsTest { node_password: da_config.rpc_password.clone(), network: bitcoin::Network::Regtest, da_private_key: Some( - // This is the private key used by the sequencer. // This is because the prover has a check to make sure that the commitment was // submitted by the sequencer and NOT any other key. Which means that arbitrary keys // CANNOT submit preproven commitments. // Using the sequencer DA private key means that we simulate the fact that the sequencer // somehow resubmitted the same commitment. - "045FFC81A3C1FDB3AF1359DBF2D114B0B3EFBF7F29CC9C5DA01267AA39D2C78D".to_owned(), + sequencer + .config() + .rollup + .da + .da_private_key + .as_ref() + .unwrap() + .clone(), ), tx_backup_dir: Self::test_config() .dir @@ -197,8 +210,8 @@ impl TestCase for SkipPreprovenCommitmentsTest { self.task_manager .spawn(|tk| bitcoin_da_service.clone().run_da_queue(rx, tk)); - // Generate 1 FINALIZED DA block. - da.generate(1 + FINALITY_DEPTH).await?; + // Generate FINALIZED DA block. + da.generate(FINALITY_DEPTH).await?; let min_soft_confirmations_per_commitment = sequencer.min_soft_confirmations_per_commitment(); diff --git a/bin/citrea/tests/bitcoin_e2e/light_client_test.rs b/bin/citrea/tests/bitcoin_e2e/light_client_test.rs index 74a5e0bf0..41bc9caf1 100644 --- a/bin/citrea/tests/bitcoin_e2e/light_client_test.rs +++ b/bin/citrea/tests/bitcoin_e2e/light_client_test.rs @@ -321,16 +321,6 @@ impl TestCase for LightClientProvingTestMultipleProofs { light_client_proof.light_client_proof_output.last_l2_height ); - // Should always be the same - assert_eq!( - light_client_proof2 - .light_client_proof_output - .l2_genesis_state_root, - light_client_proof - .light_client_proof_output - .l2_genesis_state_root - ); - assert!(light_client_proof2 .light_client_proof_output .unchained_batch_proofs_info @@ -417,15 +407,6 @@ impl TestCase for LightClientProvingTestMultipleProofs { batch_proofs[0].proof_output.final_state_root ); - assert_eq!( - light_client_proof3 - .light_client_proof_output - .l2_genesis_state_root, - light_client_proof - .light_client_proof_output - .l2_genesis_state_root - ); - assert_ne!( light_client_proof3.light_client_proof_output.last_l2_height, light_client_proof.light_client_proof_output.last_l2_height diff --git a/bin/citrea/tests/e2e/mod.rs b/bin/citrea/tests/e2e/mod.rs index ea622c060..866c73c13 100644 --- a/bin/citrea/tests/e2e/mod.rs +++ b/bin/citrea/tests/e2e/mod.rs @@ -13,11 +13,10 @@ use std::time::Duration; use alloy_primitives::{Address, U256}; use citrea_common::{BatchProverConfig, SequencerConfig}; use citrea_evm::smart_contracts::SimpleStorageContract; -use citrea_primitives::forks::FORKS; +use citrea_primitives::forks::fork_from_block_number; use citrea_stf::genesis_config::GenesisPaths; use reth_primitives::BlockNumberOrTag; use sov_mock_da::{MockAddress, MockDaService}; -use sov_modules_api::fork::fork_from_block_number; use sov_rollup_interface::rpc::{LastVerifiedBatchProofResponse, SoftConfirmationStatus}; use sov_rollup_interface::services::da::DaService; use sov_rollup_interface::spec::SpecId; @@ -654,7 +653,7 @@ async fn test_offchain_contract_storage() { wait_for_l2_block(&sequencer_client, 1000, Some(Duration::from_secs(300))).await; let seq_height = sequencer_client.eth_block_number().await; - let seq_fork = fork_from_block_number(FORKS, seq_height); + let seq_fork = fork_from_block_number(seq_height); // Assert we are at fork1 assert_eq!(seq_fork.spec_id, SpecId::Fork1); diff --git a/bin/citrea/tests/test_helpers/mod.rs b/bin/citrea/tests/test_helpers/mod.rs index 795003091..1ce84ff95 100644 --- a/bin/citrea/tests/test_helpers/mod.rs +++ b/bin/citrea/tests/test_helpers/mod.rs @@ -14,10 +14,11 @@ use citrea_stf::genesis_config::GenesisPaths; use sov_mock_da::{MockAddress, MockBlock, MockDaConfig, MockDaService}; use sov_modules_api::default_signature::private_key::DefaultPrivateKey; use sov_modules_api::PrivateKey; -use sov_modules_rollup_blueprint::{Network, RollupBlueprint as _}; +use sov_modules_rollup_blueprint::RollupBlueprint as _; use sov_rollup_interface::da::{BlobReaderTrait, DaData, SequencerCommitment}; use sov_rollup_interface::services::da::{DaService, SlotData}; use sov_rollup_interface::zk::Proof; +use sov_rollup_interface::Network; use tempfile::TempDir; use tokio::sync::oneshot; use tokio::time::sleep; @@ -49,7 +50,7 @@ pub async fn start_rollup( // Fake receipts are receipts without the proof, they only include the journal, which makes them suitable for testing and development std::env::set_var("RISC0_DEV_MODE", "1"); - let mock_demo_rollup = MockDemoRollup::new(Network::Testnet); + let mock_demo_rollup = MockDemoRollup::new(Network::Nightly); if sequencer_config.is_some() && rollup_prover_config.is_some() { panic!("Both sequencer and batch prover config cannot be set at the same time"); @@ -149,14 +150,23 @@ pub fn create_default_rollup_config( da_path: &Path, node_mode: NodeMode, ) -> FullNodeConfig { + let sequencer_da_pub_key = vec![ + 2, 88, 141, 32, 42, 252, 193, 238, 74, 181, 37, 76, 120, 71, 236, 37, 185, 161, 53, 187, + 218, 15, 43, 198, 158, 225, 167, 20, 116, 159, 215, 125, 201, + ]; + let prover_da_pub_key = vec![ + 3, 238, 218, 184, 136, 228, 95, 59, 220, 62, 201, 145, 140, 73, 28, 17, 229, 207, 122, 240, + 169, 31, 56, 185, 127, 188, 30, 19, 90, 228, 5, 102, 1, + ]; + FullNodeConfig { public_keys: RollupPublicKeys { sequencer_public_key: vec![ 32, 64, 64, 227, 100, 193, 15, 43, 236, 156, 31, 229, 0, 161, 205, 76, 36, 124, 137, 214, 80, 160, 30, 215, 232, 44, 171, 168, 103, 135, 124, 33, ], - sequencer_da_pub_key: vec![0; 32], - prover_da_pub_key: vec![0; 32], + sequencer_da_pub_key: sequencer_da_pub_key.clone(), + prover_da_pub_key: prover_da_pub_key.clone(), }, storage: StorageConfig { path: rollup_path.to_path_buf(), @@ -184,7 +194,11 @@ pub fn create_default_rollup_config( NodeMode::SequencerNode => None, }, da: MockDaConfig { - sender_address: MockAddress::from([0; 32]), + sender_address: match node_mode { + NodeMode::SequencerNode => MockAddress::from(sequencer_da_pub_key), + NodeMode::Prover(_) => MockAddress::from(prover_da_pub_key), + _ => MockAddress::new([0; 32]), + }, db_path: da_path.to_path_buf(), }, telemetry: Default::default(), diff --git a/crates/batch-prover/Cargo.toml b/crates/batch-prover/Cargo.toml index 137b1d6bb..91bfe5c17 100644 --- a/crates/batch-prover/Cargo.toml +++ b/crates/batch-prover/Cargo.toml @@ -51,7 +51,6 @@ sha2 = { workspace = true } tempfile = { workspace = true } citrea-primitives = { path = "../primitives", features = ["testing"] } -citrea-stf = { path = "../citrea-stf", features = ["native"] } prover-services = { path = "../prover-services" } sov-mock-da = { path = "../sovereign-sdk/adapters/mock-da", features = ["native"] } sov-mock-zkvm = { path = "../sovereign-sdk/adapters/mock-zkvm" } diff --git a/crates/batch-prover/src/da_block_handler.rs b/crates/batch-prover/src/da_block_handler.rs index a0be33e5b..cffdb18d3 100644 --- a/crates/batch-prover/src/da_block_handler.rs +++ b/crates/batch-prover/src/da_block_handler.rs @@ -11,14 +11,13 @@ use citrea_common::da::get_da_block_at_height; use citrea_common::utils::merge_state_diffs; use citrea_common::BatchProverConfig; use citrea_primitives::compression::compress_blob; -use citrea_primitives::forks::FORKS; +use citrea_primitives::forks::fork_from_block_number; use citrea_primitives::MAX_TXBODY_SIZE; use rand::Rng; use serde::de::DeserializeOwned; use serde::Serialize; use sov_db::ledger_db::BatchProverLedgerOps; use sov_db::schema::types::{SlotNumber, SoftConfirmationNumber}; -use sov_modules_api::fork::fork_from_block_number; use sov_modules_api::{DaSpec, StateDiff, Zkvm}; use sov_rollup_interface::da::{BlockHeaderTrait, SequencerCommitment}; use sov_rollup_interface::services::da::{DaService, SlotData}; @@ -449,7 +448,7 @@ pub(crate) fn break_sequencer_commitments_into_groups( .first() .ok_or(anyhow!("No Sequencer commitments found"))? .l2_start_block_number; - let mut current_spec = fork_from_block_number(FORKS, first_block_number).spec_id; + let mut current_spec = fork_from_block_number(first_block_number).spec_id; let mut range = 0usize..=0usize; let mut cumulative_state_diff = StateDiff::new(); @@ -479,7 +478,7 @@ pub(crate) fn break_sequencer_commitments_into_groups( let state_diff_threshold_reached = compressed_state_diff.len() > MAX_TXBODY_SIZE; let commitment_spec = - fork_from_block_number(FORKS, sequencer_commitment.l2_end_block_number).spec_id; + fork_from_block_number(sequencer_commitment.l2_end_block_number).spec_id; if commitment_spec != current_spec || state_diff_threshold_reached { result_range.push(range); diff --git a/crates/batch-prover/src/proving.rs b/crates/batch-prover/src/proving.rs index b680cc284..8c2e580dd 100644 --- a/crates/batch-prover/src/proving.rs +++ b/crates/batch-prover/src/proving.rs @@ -7,14 +7,13 @@ use borsh::{BorshDeserialize, BorshSerialize}; use citrea_common::cache::L1BlockCache; use citrea_common::da::extract_sequencer_commitments; use citrea_common::utils::{check_l2_range_exists, filter_out_proven_commitments}; -use citrea_primitives::forks::FORKS; +use citrea_primitives::forks::fork_from_block_number; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use sov_db::ledger_db::BatchProverLedgerOps; use sov_db::schema::types::{SoftConfirmationNumber, StoredBatchProof, StoredBatchProofOutput}; use sov_modules_api::{BatchProofCircuitOutput, BlobReaderTrait, SlotData, SpecId, Zkvm}; use sov_rollup_interface::da::{BlockHeaderTrait, DaNamespace, DaSpec, SequencerCommitment}; -use sov_rollup_interface::fork::fork_from_block_number; use sov_rollup_interface::rpc::SoftConfirmationStatus; use sov_rollup_interface::services::da::DaService; use sov_rollup_interface::zk::{BatchProofCircuitInput, Proof, ZkvmHost}; @@ -245,7 +244,7 @@ where .last() .expect("Should have at least 1 commitment") .l2_end_block_number; - let current_spec = fork_from_block_number(FORKS, last_l2_height).spec_id; + let current_spec = fork_from_block_number(last_l2_height).spec_id; let elf = elfs_by_spec .get(¤t_spec) .expect("Every fork should have an elf attached") @@ -328,8 +327,7 @@ where >(&proof) .expect("Proof should be deserializable"); - let last_active_spec_id = - fork_from_block_number(FORKS, circuit_output.last_l2_height).spec_id; + let last_active_spec_id = fork_from_block_number(circuit_output.last_l2_height).spec_id; let code_commitment = code_commitments_by_spec .get(&last_active_spec_id) diff --git a/crates/batch-prover/src/runner.rs b/crates/batch-prover/src/runner.rs index 76acd6342..f6171cc32 100644 --- a/crates/batch-prover/src/runner.rs +++ b/crates/batch-prover/src/runner.rs @@ -73,7 +73,7 @@ where elfs_by_spec: HashMap>, l1_block_cache: Arc>>, sync_blocks_count: u64, - fork_manager: ForkManager, + fork_manager: ForkManager<'static>, soft_confirmation_tx: broadcast::Sender, task_manager: TaskManager<()>, } @@ -106,7 +106,7 @@ where prover_config: BatchProverConfig, code_commitments_by_spec: HashMap, elfs_by_spec: HashMap>, - fork_manager: ForkManager, + fork_manager: ForkManager<'static>, soft_confirmation_tx: broadcast::Sender, task_manager: TaskManager<()>, ) -> Result { diff --git a/crates/batch-prover/tests/prover_tests.rs b/crates/batch-prover/tests/prover_tests.rs index 8e4d48c08..0cc6ff093 100644 --- a/crates/batch-prover/tests/prover_tests.rs +++ b/crates/batch-prover/tests/prover_tests.rs @@ -9,7 +9,6 @@ use sov_mock_da::{MockAddress, MockBlockHeader, MockDaService, MockDaSpec, MockH use sov_mock_zkvm::MockZkvm; use sov_rollup_interface::da::Time; use sov_rollup_interface::zk::{BatchProofCircuitInput, Proof, ZkvmHost}; -use sov_stf_runner::mock::MockStf; use sov_stf_runner::ProverService; use tokio::sync::oneshot; @@ -289,7 +288,7 @@ async fn test_multiple_parallel_proof_run() { } struct TestProver { - prover_service: Arc>, + prover_service: Arc>, vm: MockZkvm, } @@ -305,7 +304,6 @@ fn make_new_prover(thread_pool_size: usize, da_service: Arc) -> T da_service, vm.clone(), proof_mode, - (), thread_pool_size, ledger_db, ) @@ -344,7 +342,7 @@ fn make_transition_data( } async fn spawn_prove( - prover_service: Arc>, + prover_service: Arc>, ) -> oneshot::Receiver> { let (tx, rx) = oneshot::channel(); tokio::spawn(async move { diff --git a/crates/citrea-stf/src/lib.rs b/crates/citrea-stf/src/lib.rs index 2f188fa8a..ff87d81d9 100644 --- a/crates/citrea-stf/src/lib.rs +++ b/crates/citrea-stf/src/lib.rs @@ -12,5 +12,5 @@ use sov_rollup_interface::da::DaVerifier; use verifier::StateTransitionVerifier; /// Alias for StateTransitionVerifier. -pub type StfVerifier = - StateTransitionVerifier::Spec, RT>, DA, Vm>; +pub type StfVerifier = + StateTransitionVerifier::Spec, RT>, DA>; diff --git a/crates/citrea-stf/src/verifier.rs b/crates/citrea-stf/src/verifier.rs index b2dcd2a08..6ec2ffdb7 100644 --- a/crates/citrea-stf/src/verifier.rs +++ b/crates/citrea-stf/src/verifier.rs @@ -1,45 +1,38 @@ -use std::marker::PhantomData; - +use sov_modules_api::fork::Fork; use sov_rollup_interface::da::{BlockHeaderTrait, DaNamespace, DaVerifier}; use sov_rollup_interface::stf::{ApplySequencerCommitmentsOutput, StateTransitionFunction}; -use sov_rollup_interface::zk::{BatchProofCircuitInput, BatchProofCircuitOutput, Zkvm, ZkvmGuest}; +use sov_rollup_interface::zk::{BatchProofCircuitInput, BatchProofCircuitOutput}; /// Verifies a state transition -pub struct StateTransitionVerifier +pub struct StateTransitionVerifier where Da: DaVerifier, - Zk: Zkvm, ST: StateTransitionFunction, { app: ST, da_verifier: Da, - phantom: PhantomData, } -impl StateTransitionVerifier +impl StateTransitionVerifier where Da: DaVerifier, - Zk: ZkvmGuest, Stf: StateTransitionFunction, { /// Create a [`StateTransitionVerifier`] pub fn new(app: Stf, da_verifier: Da) -> Self { - Self { - app, - da_verifier, - phantom: Default::default(), - } + Self { app, da_verifier } } /// Verify the next block pub fn run_sequencer_commitments_in_da_slot( &mut self, - zkvm: Zk, + data: BatchProofCircuitInput, pre_state: Stf::PreState, - ) -> Result<(), Da::Error> { + sequencer_public_key: &[u8], + sequencer_da_public_key: &[u8], + forks: &[Fork], + ) -> Result, Da::Error> { println!("Running sequencer commitments in DA slot"); - let data: BatchProofCircuitInput = - zkvm.read_from_host(); if !data.da_block_header_of_commitments.verify_hash() { panic!("Invalid hash of DA block header of commitments"); @@ -74,8 +67,8 @@ where } = self .app .apply_soft_confirmations_from_sequencer_commitments( - data.sequencer_public_key.as_ref(), - data.sequencer_da_public_key.as_ref(), + sequencer_public_key, + sequencer_da_public_key, &data.initial_state_root, pre_state, data.da_data, @@ -84,25 +77,25 @@ where data.da_block_headers_of_soft_confirmations, data.soft_confirmations, data.preproven_commitments.clone(), + forks, ); println!("out of apply_soft_confirmations_from_sequencer_commitments"); - let out: BatchProofCircuitOutput = BatchProofCircuitOutput { + let out = BatchProofCircuitOutput { initial_state_root: data.initial_state_root, final_state_root, final_soft_confirmation_hash, state_diff, prev_soft_confirmation_hash: data.prev_soft_confirmation_hash, da_slot_hash: data.da_block_header_of_commitments.hash(), - sequencer_public_key: data.sequencer_public_key, - sequencer_da_public_key: data.sequencer_da_public_key, + sequencer_public_key: sequencer_public_key.to_vec(), + sequencer_da_public_key: sequencer_da_public_key.to_vec(), sequencer_commitments_range: data.sequencer_commitments_range, preproven_commitments: data.preproven_commitments, last_l2_height, }; - zkvm.commit(&out); - Ok(()) + Ok(out) } } diff --git a/crates/evm/src/evm/conversions.rs b/crates/evm/src/evm/conversions.rs index d8fa56e6d..e261f5b99 100644 --- a/crates/evm/src/evm/conversions.rs +++ b/crates/evm/src/evm/conversions.rs @@ -133,9 +133,8 @@ impl From for TransactionSignedEcRecovered { pub(crate) fn sealed_block_to_block_env( sealed_header: &reth_primitives::SealedHeader, ) -> revm::primitives::BlockEnv { - use citrea_primitives::forks::FORKS; + use citrea_primitives::forks::fork_from_block_number; use revm::primitives::BlobExcessGasAndPrice; - use sov_modules_api::fork::fork_from_block_number; use crate::citrea_spec_id_to_evm_spec_id; @@ -151,7 +150,7 @@ pub(crate) fn sealed_block_to_block_env( .excess_blob_gas .or_else(|| { if citrea_spec_id_to_evm_spec_id( - fork_from_block_number(FORKS, sealed_header.number).spec_id, + fork_from_block_number(sealed_header.number).spec_id, ) >= SpecId::CANCUN { Some(0) diff --git a/crates/evm/src/query.rs b/crates/evm/src/query.rs index e5b235cd7..28bbce772 100644 --- a/crates/evm/src/query.rs +++ b/crates/evm/src/query.rs @@ -17,7 +17,7 @@ use alloy_rpc_types_eth::Block as AlloyRpcBlock; use alloy_rpc_types_trace::geth::{GethDebugTracingOptions, TraceResult}; use alloy_serde::OtherFields; use citrea_primitives::basefee::calculate_next_block_base_fee; -use citrea_primitives::forks::FORKS; +use citrea_primitives::forks::fork_from_block_number; use jsonrpsee::core::RpcResult; use reth_primitives::{ Block, BlockBody, BlockId, BlockNumberOrTag, SealedHeader, TransactionSignedEcRecovered, @@ -37,7 +37,6 @@ use revm::{Database, DatabaseCommit}; use revm_inspectors::access_list::AccessListInspector; use revm_inspectors::tracing::{TracingInspector, TracingInspectorConfig}; use serde::{Deserialize, Serialize}; -use sov_modules_api::fork::fork_from_block_number; use sov_modules_api::macros::rpc_gen; use sov_modules_api::prelude::*; use sov_modules_api::WorkingSet; @@ -382,7 +381,7 @@ impl Evm { let block_number = self.block_number_for_id(&block_number, working_set)?; let current_spec = - citrea_spec_id_to_evm_spec_id(fork_from_block_number(FORKS, block_number).spec_id); + citrea_spec_id_to_evm_spec_id(fork_from_block_number(block_number).spec_id); self.set_state_to_end_of_evm_block_by_block_id(block_id, working_set)?; @@ -587,7 +586,7 @@ impl Evm { .get(working_set) .expect("EVM chain config should be set"); - let citrea_spec_id = fork_from_block_number(FORKS, block_num).spec_id; + let citrea_spec_id = fork_from_block_number(block_num).spec_id; let evm_spec_id = citrea_spec_id_to_evm_spec_id(citrea_spec_id); let cfg_env = get_cfg_env(cfg, evm_spec_id); @@ -682,7 +681,7 @@ impl Evm { .get(working_set) .expect("EVM chain config should be set"); - let citrea_spec_id = fork_from_block_number(FORKS, block_num).spec_id; + let citrea_spec_id = fork_from_block_number(block_num).spec_id; let evm_spec_id = citrea_spec_id_to_evm_spec_id(citrea_spec_id); let cfg_env = get_cfg_env(cfg, evm_spec_id); @@ -795,8 +794,7 @@ impl Evm { .get(working_set) .expect("EVM chain config should be set"); - let citrea_spec_id = - fork_from_block_number(FORKS, block_env.number.saturating_to()).spec_id; + let citrea_spec_id = fork_from_block_number(block_env.number.saturating_to()).spec_id; let evm_spec_id = citrea_spec_id_to_evm_spec_id(citrea_spec_id); let cfg_env = get_cfg_env(cfg, evm_spec_id); @@ -1229,7 +1227,7 @@ impl Evm { // set state to end of the previous block set_state_to_end_of_evm_block::(block_number - 1, working_set); - let citrea_spec_id = fork_from_block_number(FORKS, block_number).spec_id; + let citrea_spec_id = fork_from_block_number(block_number).spec_id; let evm_spec_id = citrea_spec_id_to_evm_spec_id(citrea_spec_id); let block_env = sealed_block_to_block_env(&sealed_block.header); @@ -1857,7 +1855,7 @@ fn get_pending_block_env( cfg.base_fee_params, )); block_env.blob_excess_gas_and_price = if citrea_spec_id_to_evm_spec_id( - fork_from_block_number(FORKS, block_env.number.saturating_to()).spec_id, + fork_from_block_number(block_env.number.saturating_to()).spec_id, ) >= SpecId::CANCUN { Some(BlobExcessGasAndPrice::new(0)) diff --git a/crates/evm/src/tests/call_tests.rs b/crates/evm/src/tests/call_tests.rs index 926bcf0e0..2c56c5ea0 100644 --- a/crates/evm/src/tests/call_tests.rs +++ b/crates/evm/src/tests/call_tests.rs @@ -30,7 +30,8 @@ use crate::tests::test_signer::TestSigner; use crate::tests::utils::{ config_push_contracts, create_contract_message, create_contract_message_with_fee, create_contract_message_with_fee_and_gas_limit, create_contract_transaction, get_evm, - get_evm_config, get_evm_config_starting_base_fee, publish_event_message, set_arg_message, + get_evm_config, get_evm_config_starting_base_fee, get_evm_with_spec, publish_event_message, + set_arg_message, }; use crate::tests::DEFAULT_CHAIN_ID; use crate::{ @@ -69,7 +70,7 @@ fn call_multiple_test() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, + current_spec: SovSpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -82,7 +83,7 @@ fn call_multiple_test() { { let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SovSpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SovSpecId::Fork1, l1_fee_rate); let transactions: Vec = vec![ create_contract_transaction(&dev_signer1, 0, SimpleStorageContract::default()), @@ -138,8 +139,8 @@ fn call_multiple_test() { logs: vec![] }, gas_used: 50751, - log_index_start: 0, - l1_diff_size: 255 + log_index_start: 0, + l1_diff_size: 53 }, Receipt { receipt: reth_primitives::Receipt { @@ -155,9 +156,9 @@ fn call_multiple_test() { ).unwrap() } ]}, - gas_used: 80620, - log_index_start: 0, - l1_diff_size: 561 + gas_used: 80620, + log_index_start: 0, + l1_diff_size: 94 }, Receipt { receipt: reth_primitives::Receipt{ @@ -183,7 +184,7 @@ fn call_multiple_test() { }, gas_used: 169150, log_index_start: 1, - l1_diff_size: 1019 + l1_diff_size: 154 }, Receipt { receipt: reth_primitives::Receipt { @@ -200,13 +201,13 @@ fn call_multiple_test() { }, gas_used: 80620, log_index_start: 0, - l1_diff_size: 561 + l1_diff_size: 94 }, - Receipt { receipt: reth_primitives::Receipt { tx_type: reth_primitives::TxType::Eip1559, success: true, cumulative_gas_used: 213563, logs: vec![] }, gas_used: 132943, log_index_start: 1, l1_diff_size: 567 }, - Receipt { receipt: reth_primitives::Receipt { tx_type: reth_primitives::TxType::Eip1559, success: true, cumulative_gas_used: 257293, logs: vec![] }, gas_used: 43730, log_index_start: 1, l1_diff_size: 255 }, - Receipt { receipt: reth_primitives::Receipt { tx_type: reth_primitives::TxType::Eip1559, success: true, cumulative_gas_used: 283923, logs: vec![] }, gas_used: 26630, log_index_start: 1, l1_diff_size: 255 }, + Receipt { receipt: reth_primitives::Receipt { tx_type: reth_primitives::TxType::Eip1559, success: true, cumulative_gas_used: 213563, logs: vec![] }, gas_used: 132943, log_index_start: 1, l1_diff_size: 52 }, + Receipt { receipt: reth_primitives::Receipt { tx_type: reth_primitives::TxType::Eip1559, success: true, cumulative_gas_used: 257293, logs: vec![] }, gas_used: 43730, log_index_start: 1, l1_diff_size: 53 }, + Receipt { receipt: reth_primitives::Receipt { tx_type: reth_primitives::TxType::Eip1559, success: true, cumulative_gas_used: 283923, logs: vec![] }, gas_used: 26630, log_index_start: 1, l1_diff_size: 53 }, Receipt { receipt: reth_primitives::Receipt { tx_type: reth_primitives::TxType::Eip1559, success: true, cumulative_gas_used: 310553, logs: vec![] }, - gas_used: 26630, log_index_start: 1, l1_diff_size: 255 }] + gas_used: 26630, log_index_start: 1, l1_diff_size: 53 }] ); // checkout esad/fix-block-env-bug branch let tx = evm @@ -236,7 +237,7 @@ fn call_test() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, + current_spec: SovSpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -248,7 +249,7 @@ fn call_test() { let set_arg = 999; { let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SovSpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SovSpecId::Fork1, l1_fee_rate); let rlp_transactions = vec![ create_contract_message(&dev_signer, 0, SimpleStorageContract::default()), @@ -285,7 +286,7 @@ fn call_test() { }, gas_used: 50751, log_index_start: 0, - l1_diff_size: 255 + l1_diff_size: 53 }, Receipt { receipt: reth_primitives::Receipt { @@ -304,7 +305,7 @@ fn call_test() { }, gas_used: 80620, log_index_start: 0, - l1_diff_size: 561 + l1_diff_size: 94 }, Receipt { receipt: reth_primitives::Receipt { @@ -330,7 +331,7 @@ fn call_test() { }, gas_used: 169150, log_index_start: 1, - l1_diff_size: 1019 + l1_diff_size: 154 }, Receipt { receipt: reth_primitives::Receipt { @@ -349,7 +350,7 @@ fn call_test() { }, gas_used: 80620, log_index_start: 0, - l1_diff_size: 561 + l1_diff_size: 94 }, Receipt { receipt: reth_primitives::Receipt { @@ -360,7 +361,7 @@ fn call_test() { }, gas_used: 132943, log_index_start: 1, - l1_diff_size: 567 + l1_diff_size: 52 }, Receipt { receipt: reth_primitives::Receipt { @@ -371,7 +372,7 @@ fn call_test() { }, gas_used: 43730, log_index_start: 1, - l1_diff_size: 255 + l1_diff_size: 53 }] ); } @@ -393,7 +394,7 @@ fn failed_transaction_test() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, + current_spec: SovSpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -403,7 +404,7 @@ fn failed_transaction_test() { evm.begin_soft_confirmation_hook(&soft_confirmation_info, working_set); { let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SovSpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SovSpecId::Fork1, l1_fee_rate); let rlp_transactions = vec![create_contract_message( &dev_signer, 0, @@ -443,7 +444,7 @@ fn failed_transaction_test() { }, gas_used: 50751, log_index_start: 0, - l1_diff_size: 255 + l1_diff_size: 53 }, Receipt { receipt: reth_primitives::Receipt{ @@ -462,7 +463,7 @@ fn failed_transaction_test() { }, gas_used: 80620, log_index_start: 0, - l1_diff_size: 561 + l1_diff_size: 94 }, Receipt { receipt: reth_primitives::Receipt { @@ -486,7 +487,7 @@ fn failed_transaction_test() { }, gas_used: 169150, log_index_start: 1, - l1_diff_size: 1019 + l1_diff_size: 154 }, Receipt { receipt: reth_primitives::Receipt { @@ -505,7 +506,7 @@ fn failed_transaction_test() { }, gas_used: 80620, log_index_start: 0, - l1_diff_size: 561 + l1_diff_size: 94 } ] ); @@ -526,7 +527,7 @@ fn self_destruct_test() { let (config, dev_signer, contract_addr) = get_evm_config(U256::from_str("100000000000000000000").unwrap(), None); - let (mut evm, mut working_set) = get_evm(&config); + let (mut evm, mut working_set) = get_evm_with_spec(&config, SovSpecId::Genesis); let l1_fee_rate = 0; let mut l2_height = 2; @@ -813,7 +814,7 @@ fn test_block_hash_in_evm() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, + current_spec: SovSpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -823,7 +824,7 @@ fn test_block_hash_in_evm() { evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SovSpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SovSpecId::Fork1, l1_fee_rate); let deploy_message = create_contract_message(&dev_signer, 0, BlockHashContract::default()); @@ -850,7 +851,7 @@ fn test_block_hash_in_evm() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [99u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, + current_spec: SovSpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -961,7 +962,7 @@ fn test_block_gas_limit() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, + current_spec: SovSpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -971,7 +972,7 @@ fn test_block_gas_limit() { evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SovSpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SovSpecId::Fork1, l1_fee_rate); // deploy logs contract let mut rlp_transactions = vec![create_contract_message( @@ -1026,7 +1027,7 @@ fn test_block_gas_limit() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, + current_spec: SovSpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -1036,7 +1037,7 @@ fn test_block_gas_limit() { evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SovSpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SovSpecId::Fork1, l1_fee_rate); // deploy logs contract let mut rlp_transactions = vec![create_contract_message( @@ -1182,7 +1183,7 @@ fn test_l1_fee_success() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, + current_spec: SovSpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -1193,7 +1194,7 @@ fn test_l1_fee_success() { { let sender_address = generate_address::("sender"); - let context = C::new(sender_address, 2, SovSpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, 2, SovSpecId::Fork1, l1_fee_rate); let deploy_message = create_contract_message_with_priority_fee( &dev_signer, @@ -1248,7 +1249,7 @@ fn test_l1_fee_success() { }, gas_used: 50751, log_index_start: 0, - l1_diff_size: 255 + l1_diff_size: 53, }, Receipt { receipt: reth_primitives::Receipt { @@ -1267,7 +1268,7 @@ fn test_l1_fee_success() { }, gas_used: 80620, log_index_start: 0, - l1_diff_size: 561 + l1_diff_size: 94 }, Receipt { receipt: reth_primitives::Receipt { @@ -1292,7 +1293,7 @@ fn test_l1_fee_success() { }, gas_used: 169150, log_index_start: 1, - l1_diff_size: 1019 + l1_diff_size: 154 }, Receipt { receipt: reth_primitives::Receipt { @@ -1310,7 +1311,7 @@ fn test_l1_fee_success() { }, gas_used: 80620, log_index_start: 0, - l1_diff_size: 561 + l1_diff_size: 94, }, Receipt { receipt: reth_primitives::Receipt { @@ -1321,7 +1322,7 @@ fn test_l1_fee_success() { }, gas_used: 114235, log_index_start: 1, - l1_diff_size: 479 + l1_diff_size: 52, } ] ) @@ -1339,11 +1340,11 @@ fn test_l1_fee_success() { ); run_tx( 1, - U256::from(100000000000000u64 - gas_fee_paid * 10000001 - 479 - L1_FEE_OVERHEAD as u64), + U256::from(100000000000000u64 - gas_fee_paid * 10000001 - 52 - L1_FEE_OVERHEAD as u64), // priority fee goes to coinbase U256::from(gas_fee_paid), U256::from(gas_fee_paid * 10000000), - U256::from(479 + L1_FEE_OVERHEAD as u64), + U256::from(52 + L1_FEE_OVERHEAD as u64), ); } @@ -1366,7 +1367,7 @@ fn test_l1_fee_not_enough_funds() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, + current_spec: SovSpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -1377,7 +1378,7 @@ fn test_l1_fee_not_enough_funds() { { let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SovSpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SovSpecId::Fork1, l1_fee_rate); let deploy_message = create_contract_message_with_fee_and_gas_limit( &dev_signer, @@ -1416,7 +1417,7 @@ fn test_l1_fee_not_enough_funds() { }, gas_used: 50751, log_index_start: 0, - l1_diff_size: 255 + l1_diff_size: 53 }, Receipt { receipt: reth_primitives::Receipt { @@ -1435,7 +1436,7 @@ fn test_l1_fee_not_enough_funds() { }, gas_used: 80620, log_index_start: 0, - l1_diff_size: 561 + l1_diff_size: 94 }, Receipt { receipt: reth_primitives::Receipt { @@ -1461,7 +1462,7 @@ fn test_l1_fee_not_enough_funds() { }, gas_used: 169150, log_index_start: 1, - l1_diff_size: 1019 + l1_diff_size: 154 } ] ); @@ -1499,7 +1500,7 @@ fn test_l1_fee_halt() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, + current_spec: SovSpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -1510,7 +1511,7 @@ fn test_l1_fee_halt() { { let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SovSpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SovSpecId::Fork1, l1_fee_rate); let deploy_message = create_contract_message_with_fee( &dev_signer, @@ -1557,7 +1558,7 @@ fn test_l1_fee_halt() { }, gas_used: 50751, log_index_start: 0, - l1_diff_size: 255 + l1_diff_size: 53 }, Receipt { receipt: reth_primitives::Receipt { @@ -1576,7 +1577,7 @@ fn test_l1_fee_halt() { }, gas_used: 80620, log_index_start: 0, - l1_diff_size: 561 + l1_diff_size: 94 }, Receipt { receipt: reth_primitives::Receipt { @@ -1602,7 +1603,7 @@ fn test_l1_fee_halt() { }, gas_used: 169150, log_index_start: 1, - l1_diff_size: 1019 + l1_diff_size: 154 }, Receipt { receipt: reth_primitives::Receipt { @@ -1621,7 +1622,7 @@ fn test_l1_fee_halt() { }, gas_used: 80620, log_index_start: 0, - l1_diff_size: 561 + l1_diff_size: 94 }, Receipt { receipt: reth_primitives::Receipt { @@ -1632,7 +1633,7 @@ fn test_l1_fee_halt() { }, gas_used: 106947, log_index_start: 1, - l1_diff_size: 447 + l1_diff_size: 52 }, Receipt { receipt: reth_primitives::Receipt @@ -1643,7 +1644,7 @@ fn test_l1_fee_halt() { }, gas_used: 1000000, log_index_start: 1, - l1_diff_size: 96 + l1_diff_size: 31 } ] ); @@ -1654,8 +1655,8 @@ fn test_l1_fee_halt() { .unwrap(); let expenses = 1106947_u64 * 10000000 + // evm gas - 447 + // l1 contract deploy fee - 96 + // l1 contract call fee + 52 + // l1 contract deploy fee + 31 + // l1 contract call fee 2 * L1_FEE_OVERHEAD as u64; // l1 fee overhead *2 assert_eq!( db_account.balance, @@ -1670,7 +1671,7 @@ fn test_l1_fee_halt() { assert_eq!(base_fee_vault.balance, U256::from(1106947_u64 * 10000000)); assert_eq!( l1_fee_vault.balance, - U256::from(447 + 96 + 2 * L1_FEE_OVERHEAD as u64) + U256::from(52 + 31 + 2 * L1_FEE_OVERHEAD as u64) ); } @@ -1679,7 +1680,7 @@ fn test_l1_fee_compression_discount() { let (config, dev_signer, _) = get_evm_config_starting_base_fee(U256::from_str("100000000000000").unwrap(), None, 1); - let (mut evm, mut working_set) = get_evm(&config); + let (mut evm, mut working_set) = get_evm_with_spec(&config, SovSpecId::Genesis); let l1_fee_rate = 1; let soft_confirmation_info = HookSoftConfirmationInfo { @@ -1849,7 +1850,7 @@ fn test_call_with_block_overrides() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, + current_spec: SovSpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -1860,7 +1861,7 @@ fn test_call_with_block_overrides() { let sender_address = generate_address::("sender"); evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { - let context = C::new(sender_address, l2_height, SovSpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SovSpecId::Fork1, l1_fee_rate); let deploy_message = create_contract_message(&dev_signer, 0, BlockHashContract::default()); @@ -1886,7 +1887,7 @@ fn test_call_with_block_overrides() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [99u8; 32].to_vec(), - current_spec: SovSpecId::Genesis, + current_spec: SovSpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -1988,7 +1989,7 @@ fn test_blob_tx() { let sender_address = generate_address::("sender"); evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { - let context = C::new(sender_address, l2_height, SovSpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SovSpecId::Fork1, l1_fee_rate); let blob_message = dev_signer .sign_blob_transaction(Address::ZERO, vec![B256::random()], 0) diff --git a/crates/evm/src/tests/fork_tests.rs b/crates/evm/src/tests/fork_tests.rs index f117f5b8c..0f79562cf 100644 --- a/crates/evm/src/tests/fork_tests.rs +++ b/crates/evm/src/tests/fork_tests.rs @@ -17,7 +17,9 @@ use crate::smart_contracts::{ SelfdestructingConstructorContract, SimpleStorageContract, TransientStorageContract, }; use crate::tests::test_signer::TestSigner; -use crate::tests::utils::{create_contract_message, get_evm, get_evm_config, set_arg_message}; +use crate::tests::utils::{ + create_contract_message, get_evm, get_evm_config, get_evm_with_spec, set_arg_message, +}; use crate::RlpEvmTransaction; type C = DefaultContext; @@ -82,7 +84,7 @@ fn test_cancun_transient_storage_activation() { let (config, dev_signer, contract_addr) = get_evm_config(U256::from_str("100000000000000000000").unwrap(), None); - let (mut evm, mut working_set) = get_evm(&config); + let (mut evm, mut working_set) = get_evm_with_spec(&config, SovSpecId::Genesis); let l1_fee_rate = 0; let mut l2_height = 2; @@ -238,7 +240,7 @@ fn test_cancun_mcopy_activation() { let (config, dev_signer, contract_addr) = get_evm_config(U256::from_str("100000000000000000000").unwrap(), None); - let (mut evm, mut working_set) = get_evm(&config); + let (mut evm, mut working_set) = get_evm_with_spec(&config, SovSpecId::Genesis); let l1_fee_rate = 0; let mut l2_height = 2; @@ -439,7 +441,7 @@ fn test_blob_base_fee_should_return_1() { let (config, dev_signer, contract_addr) = get_evm_config(U256::from_str("100000000000000000000").unwrap(), None); - let (mut evm, mut working_set) = get_evm(&config); + let (mut evm, mut working_set) = get_evm_with_spec(&config, SovSpecId::Genesis); let l1_fee_rate = 0; let mut l2_height = 2; @@ -674,7 +676,7 @@ fn test_offchain_contract_storage_evm() { let (config, dev_signer, contract_addr) = get_evm_config(U256::from_str("100000000000000000000").unwrap(), None); - let (mut evm, mut working_set) = get_evm(&config); + let (mut evm, mut working_set) = get_evm_with_spec(&config, SovSpecId::Genesis); let l1_fee_rate = 0; let mut l2_height = 2; diff --git a/crates/evm/src/tests/genesis_tests.rs b/crates/evm/src/tests/genesis_tests.rs index a5e949c2d..7f296e065 100644 --- a/crates/evm/src/tests/genesis_tests.rs +++ b/crates/evm/src/tests/genesis_tests.rs @@ -164,7 +164,7 @@ fn genesis_block() { #[test] fn genesis_head() { let (evm, mut working_set) = get_evm(&get_evm_test_config()); - let head = evm.head.get(&mut working_set).unwrap(); + let head = evm.head_rlp.get(&mut working_set).unwrap(); assert_eq!(head.header.parent_hash, *GENESIS_HASH); let genesis_block = evm .blocks diff --git a/crates/evm/src/tests/hooks_tests.rs b/crates/evm/src/tests/hooks_tests.rs index ef1c76c6f..d895ce622 100644 --- a/crates/evm/src/tests/hooks_tests.rs +++ b/crates/evm/src/tests/hooks_tests.rs @@ -6,7 +6,7 @@ use reth_primitives::{ Header, Signature, TransactionSigned, TransactionSignedNoHash, EMPTY_OMMER_ROOT_HASH, KECCAK_EMPTY, }; -use revm::primitives::BlockEnv; +use revm::primitives::{BlobExcessGasAndPrice, BlockEnv}; use sov_modules_api::hooks::HookSoftConfirmationInfo; use sov_modules_api::{StateMapAccessor, StateValueAccessor, StateVecAccessor}; use sov_rollup_interface::spec::SpecId; @@ -34,7 +34,7 @@ fn begin_soft_confirmation_hook_creates_pending_block() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -52,7 +52,7 @@ fn begin_soft_confirmation_hook_creates_pending_block() { basefee: U256::from(767816299), gas_limit: U256::from(config.block_gas_limit), difficulty: U256::ZERO, - blob_excess_gas_and_price: None + blob_excess_gas_and_price: Some(BlobExcessGasAndPrice::new(0)) } ); } @@ -74,7 +74,7 @@ fn end_soft_confirmation_hook_sets_head() { da_slot_height: 1, da_slot_txs_commitment: txs_commitment.into(), pre_state_root: pre_state_root.to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -90,19 +90,19 @@ fn end_soft_confirmation_hook_sets_head() { .push(create_pending_transaction(2, 1)); evm.end_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); - let head = evm.head.get(&mut working_set).unwrap(); + let head = evm.head_rlp.get(&mut working_set).unwrap(); let pending_head = evm .pending_head .get(&mut working_set.accessory_state()) .unwrap(); - assert_eq!(head, pending_head.into()); + assert_eq!(head, pending_head); assert_eq!( head, Block { - header: crate::primitive_types::DoNotUseHeader { + header: alloy_consensus::Header { parent_hash: B256::from(hex!( - "42b2df14615729c49a449b8f42c1a9eb4b9b62fb6a70464eabfa362cd1d20f75" + "cddac53c8ce67726f9d2c51cdfca6af78e24e836ffbc614e878a59d89fcd7738" )), ommers_hash: EMPTY_OMMER_ROOT_HASH, @@ -122,11 +122,11 @@ fn end_soft_confirmation_hook_sets_head() { gas_used: 200u64, timestamp: 54, mix_hash: *DA_ROOT_HASH, - nonce: 0, + nonce: 0u64.into(), base_fee_per_gas: Some(767816299), extra_data: Bytes::default(), - blob_gas_used: None, - excess_blob_gas: None, + blob_gas_used: Some(0), + excess_blob_gas: Some(0), parent_beacon_block_root: None, requests_root: None, }, @@ -149,7 +149,7 @@ fn end_soft_confirmation_hook_moves_transactions_and_receipts() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -272,7 +272,7 @@ fn finalize_hook_creates_final_block() { da_slot_height: 1, da_slot_txs_commitment: txs_commitment.into(), pre_state_root: root.to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -301,7 +301,7 @@ fn finalize_hook_creates_final_block() { da_slot_height: 1, da_slot_txs_commitment: txs_commitment.into(), pre_state_root: root_hash.to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -340,8 +340,8 @@ fn finalize_hook_creates_final_block() { nonce: B64::ZERO, base_fee_per_gas: Some(767816299), extra_data: Bytes::default(), - blob_gas_used: None, - excess_blob_gas: None, + blob_gas_used: Some(0), + excess_blob_gas: Some(0), parent_beacon_block_root: None, requests_root: None, }; @@ -390,7 +390,7 @@ fn begin_soft_confirmation_hook_appends_last_block_hashes() { da_slot_height: 1, da_slot_txs_commitment: txs_commitment.into(), pre_state_root: root.to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -433,7 +433,7 @@ fn begin_soft_confirmation_hook_appends_last_block_hashes() { da_slot_height: 1, da_slot_txs_commitment: random_32_bytes, pre_state_root: random_32_bytes.to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -457,7 +457,7 @@ fn begin_soft_confirmation_hook_appends_last_block_hashes() { da_slot_height: 1, da_slot_txs_commitment: random_32_bytes, pre_state_root: random_32_bytes.to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, diff --git a/crates/evm/src/tests/queries/estimate_gas_tests.rs b/crates/evm/src/tests/queries/estimate_gas_tests.rs index bfbeb2578..814468a56 100644 --- a/crates/evm/src/tests/queries/estimate_gas_tests.rs +++ b/crates/evm/src/tests/queries/estimate_gas_tests.rs @@ -51,7 +51,7 @@ fn test_payable_contract_value() { } #[test] -fn test_tx_request_fields_gas() { +fn test_tx_request_fields_gas_fork1() { let (evm, mut working_set, signer) = init_evm_single_block(); let tx_req_contract_call = TransactionRequest { @@ -94,7 +94,7 @@ fn test_tx_request_fields_gas() { ); assert_eq!( contract_diff_size.unwrap(), - serde_json::from_value::(json![{"gas":"0x6601","l1DiffSize":"0x60"}]) + serde_json::from_value::(json![{"gas":"0x6601","l1DiffSize":"0x1f"}]) .unwrap() ); @@ -110,7 +110,7 @@ fn test_tx_request_fields_gas() { ); assert_eq!( contract_diff_size.unwrap(), - serde_json::from_value::(json![{"gas":"0x6601","l1DiffSize":"0x60"}]) + serde_json::from_value::(json![{"gas":"0x6601","l1DiffSize":"0x1f"}]) .unwrap() ); diff --git a/crates/evm/src/tests/queries/log_tests.rs b/crates/evm/src/tests/queries/log_tests.rs index 69bc08edc..f1135ac90 100644 --- a/crates/evm/src/tests/queries/log_tests.rs +++ b/crates/evm/src/tests/queries/log_tests.rs @@ -79,7 +79,7 @@ fn log_filter_test_at_block_hash() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -89,7 +89,7 @@ fn log_filter_test_at_block_hash() { { let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SpecId::Fork1, l1_fee_rate); // deploy logs contract // call the contract function @@ -288,7 +288,7 @@ fn log_filter_test_with_range() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -298,7 +298,7 @@ fn log_filter_test_with_range() { { let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SpecId::Fork1, l1_fee_rate); // deploy selfdestruct contract // call the contract function @@ -350,7 +350,7 @@ fn log_filter_test_with_range() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [99u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -360,7 +360,7 @@ fn log_filter_test_with_range() { { let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SpecId::Fork1, l1_fee_rate); // call the contract function evm.call( CallMessage { @@ -414,7 +414,7 @@ fn test_log_limits() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -424,7 +424,7 @@ fn test_log_limits() { { let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SpecId::Fork1, l1_fee_rate); // deploy logs contract let mut rlp_transactions = vec![create_contract_message( @@ -515,7 +515,7 @@ fn test_log_limits() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [99u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, diff --git a/crates/evm/src/tests/sys_tx_tests.rs b/crates/evm/src/tests/sys_tx_tests.rs index e43531036..c1bad1f2a 100644 --- a/crates/evm/src/tests/sys_tx_tests.rs +++ b/crates/evm/src/tests/sys_tx_tests.rs @@ -51,7 +51,7 @@ fn test_sys_bitcoin_light_client() { }, gas_used: 50751, log_index_start: 0, - l1_diff_size: 255, + l1_diff_size: 53, }, Receipt { // BitcoinLightClient::setBlockInfo(U256, U256) receipt: reth_primitives::Receipt { @@ -70,7 +70,7 @@ fn test_sys_bitcoin_light_client() { }, gas_used: 80620, log_index_start: 0, - l1_diff_size: 561, + l1_diff_size: 94, }, Receipt { receipt: reth_primitives::Receipt { @@ -96,7 +96,7 @@ fn test_sys_bitcoin_light_client() { }, gas_used: 169150, log_index_start: 1, - l1_diff_size: 1019, + l1_diff_size: 154, } ] ); @@ -158,7 +158,7 @@ fn test_sys_bitcoin_light_client() { da_slot_height: 2, da_slot_txs_commitment: [3u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -170,7 +170,7 @@ fn test_sys_bitcoin_light_client() { { let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SpecId::Fork1, l1_fee_rate); let deploy_message = create_contract_message_with_fee( &dev_signer, @@ -222,7 +222,7 @@ fn test_sys_bitcoin_light_client() { }, gas_used: 80620, log_index_start: 0, - l1_diff_size: 561, + l1_diff_size: 94, }, Receipt { receipt: reth_primitives::Receipt { @@ -233,7 +233,7 @@ fn test_sys_bitcoin_light_client() { }, gas_used: 114235, log_index_start: 1, - l1_diff_size: 479, + l1_diff_size: 52, }, ] ); @@ -241,7 +241,7 @@ fn test_sys_bitcoin_light_client() { let l1_fee_vault = evm.accounts.get(&L1_FEE_VAULT, &mut working_set).unwrap(); assert_eq!(base_fee_vault.balance, U256::from(114235u64 * 10000000)); - assert_eq!(l1_fee_vault.balance, U256::from(479 + L1_FEE_OVERHEAD)); + assert_eq!(l1_fee_vault.balance, U256::from(52 + L1_FEE_OVERHEAD)); let hash = evm .get_call( @@ -292,7 +292,7 @@ fn test_sys_tx_gas_usage_effect_on_block_gas_limit() { let mut l2_height = 2; let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SpecId::Fork1, l1_fee_rate); let soft_confirmation_info = HookSoftConfirmationInfo { l2_height, @@ -300,7 +300,7 @@ fn test_sys_tx_gas_usage_effect_on_block_gas_limit() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate: 1, @@ -335,7 +335,7 @@ fn test_sys_tx_gas_usage_effect_on_block_gas_limit() { da_slot_height: 2, da_slot_txs_commitment: [43u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -343,7 +343,7 @@ fn test_sys_tx_gas_usage_effect_on_block_gas_limit() { }; evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { - let context = C::new(sender_address, l2_height, SpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SpecId::Fork1, l1_fee_rate); let pending_cumulative_from_sum: u128 = evm .pending_transactions @@ -411,7 +411,7 @@ fn test_sys_tx_gas_usage_effect_on_block_gas_limit() { da_slot_height: 2, da_slot_txs_commitment: [43u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -419,7 +419,7 @@ fn test_sys_tx_gas_usage_effect_on_block_gas_limit() { }; evm.begin_soft_confirmation_hook(&soft_confirmation_info, &mut working_set); { - let context = C::new(sender_address, l2_height, SpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SpecId::Fork1, l1_fee_rate); let pending_cumulative_from_sum: u128 = evm .pending_transactions @@ -511,7 +511,7 @@ fn test_bridge() { 188, 45, 73, 146, 108, 41, 125, 77, 133, 86, 235, 104, ], pre_state_root: [1u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -621,7 +621,7 @@ fn test_upgrade_light_client() { let l2_height = 2; let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SpecId::Fork1, l1_fee_rate); let soft_confirmation_info = HookSoftConfirmationInfo { l2_height, @@ -629,7 +629,7 @@ fn test_upgrade_light_client() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -747,7 +747,7 @@ fn test_change_upgrade_owner() { let l1_fee_rate = 1; let mut l2_height = 2; let sender_address = generate_address::("sender"); - let context = C::new(sender_address, l2_height, SpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SpecId::Fork1, l1_fee_rate); let soft_confirmation_info = HookSoftConfirmationInfo { l2_height, @@ -755,7 +755,7 @@ fn test_change_upgrade_owner() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, @@ -786,7 +786,7 @@ fn test_change_upgrade_owner() { evm.finalize_hook(&[99u8; 32].into(), &mut working_set.accessory_state()); l2_height += 1; - let context = C::new(sender_address, l2_height, SpecId::Genesis, l1_fee_rate); + let context = C::new(sender_address, l2_height, SpecId::Fork1, l1_fee_rate); let soft_confirmation_info = HookSoftConfirmationInfo { l2_height, @@ -794,7 +794,7 @@ fn test_change_upgrade_owner() { da_slot_height: 1, da_slot_txs_commitment: [42u8; 32], pre_state_root: [10u8; 32].to_vec(), - current_spec: SpecId::Genesis, + current_spec: SpecId::Fork1, pub_key: vec![], deposit_data: vec![], l1_fee_rate, diff --git a/crates/evm/src/tests/utils.rs b/crates/evm/src/tests/utils.rs index 38761e33b..1ba486428 100644 --- a/crates/evm/src/tests/utils.rs +++ b/crates/evm/src/tests/utils.rs @@ -52,7 +52,15 @@ pub(crate) fn get_evm_with_storage( ); (evm, working_set, prover_storage) } + pub(crate) fn get_evm(config: &EvmConfig) -> (Evm, WorkingSet<::Storage>) { + get_evm_with_spec(config, SovSpecId::Fork1) +} + +pub(crate) fn get_evm_with_spec( + config: &EvmConfig, + spec_id: SovSpecId, +) -> (Evm, WorkingSet<::Storage>) { let tmpdir = tempfile::tempdir().unwrap(); let storage = new_orphan_storage(tmpdir.path()).unwrap(); let mut working_set = WorkingSet::new(storage.clone()); @@ -70,7 +78,7 @@ pub(crate) fn get_evm(config: &EvmConfig) -> (Evm, WorkingSet<::St da_slot_height: 1, da_slot_txs_commitment: [2u8; 32], pre_state_root: root.to_vec(), - current_spec: SovSpecId::Genesis, + current_spec: spec_id, pub_key: vec![], deposit_data: vec![], l1_fee_rate: 0, diff --git a/crates/fullnode/src/da_block_handler.rs b/crates/fullnode/src/da_block_handler.rs index 862b52e28..cb7cd7eee 100644 --- a/crates/fullnode/src/da_block_handler.rs +++ b/crates/fullnode/src/da_block_handler.rs @@ -10,7 +10,7 @@ use citrea_common::cache::L1BlockCache; use citrea_common::da::{extract_sequencer_commitments, extract_zk_proofs, get_da_block_at_height}; use citrea_common::error::SyncError; use citrea_common::utils::check_l2_range_exists; -use citrea_primitives::forks::FORKS; +use citrea_primitives::forks::fork_from_block_number; use rs_merkle::algorithms::Sha256; use rs_merkle::MerkleTree; use serde::de::DeserializeOwned; @@ -21,7 +21,6 @@ use sov_db::schema::types::{ }; use sov_modules_api::{Context, Zkvm}; use sov_rollup_interface::da::{BlockHeaderTrait, SequencerCommitment}; -use sov_rollup_interface::fork::fork_from_block_number; use sov_rollup_interface::rpc::SoftConfirmationStatus; use sov_rollup_interface::services::da::{DaService, SlotData}; use sov_rollup_interface::spec::SpecId; @@ -315,8 +314,7 @@ where ).into()); } - let last_active_spec_id = - fork_from_block_number(FORKS, batch_proof_output.last_l2_height).spec_id; + let last_active_spec_id = fork_from_block_number(batch_proof_output.last_l2_height).spec_id; let code_commitment = self .code_commitments_by_spec .get(&last_active_spec_id) diff --git a/crates/fullnode/src/runner.rs b/crates/fullnode/src/runner.rs index 3e596b87f..2eafe51f6 100644 --- a/crates/fullnode/src/runner.rs +++ b/crates/fullnode/src/runner.rs @@ -70,7 +70,7 @@ where code_commitments_by_spec: HashMap, l1_block_cache: Arc>>, sync_blocks_count: u64, - fork_manager: ForkManager, + fork_manager: ForkManager<'static>, soft_confirmation_tx: broadcast::Sender, pruning_config: Option, task_manager: TaskManager<()>, @@ -101,7 +101,7 @@ where mut storage_manager: ProverStorageManager, init_variant: InitVariant, Da::Spec>, code_commitments_by_spec: HashMap, - fork_manager: ForkManager, + fork_manager: ForkManager<'static>, soft_confirmation_tx: broadcast::Sender, task_manager: TaskManager<()>, ) -> Result { diff --git a/crates/light-client-prover/src/circuit.rs b/crates/light-client-prover/src/circuit.rs index 3e70890c6..eb80f3705 100644 --- a/crates/light-client-prover/src/circuit.rs +++ b/crates/light-client-prover/src/circuit.rs @@ -17,10 +17,11 @@ pub enum LightClientVerificationError { pub fn run_circuit( da_verifier: DaV, - guest: &G, + input: LightClientCircuitInput, + l2_genesis_root: [u8; 32], + batch_proof_method_id: [u32; 8], + batch_prover_da_public_key: &[u8], ) -> Result, LightClientVerificationError> { - let input: LightClientCircuitInput = guest.read_from_host(); - // Extract previous light client proof output let previous_light_client_proof_output = if let Some(journal) = input.previous_light_client_proof_journal { @@ -57,21 +58,13 @@ pub fn run_circuit( // Mapping from initial state root to final state root and last L2 height let mut initial_to_final = std::collections::BTreeMap::<[u8; 32], ([u8; 32], u64)>::new(); - let (mut last_state_root, mut last_l2_height, l2_genesis_state_root) = + let (mut last_state_root, mut last_l2_height) = previous_light_client_proof_output.as_ref().map_or_else( || { - let r = input - .l2_genesis_state_root - .expect("if no preious proof, genesis must exist"); - (r, 0, r) - }, - |prev_journal| { - ( - prev_journal.state_root, - prev_journal.last_l2_height, - prev_journal.l2_genesis_state_root, - ) + // if no previous proof, we start from genesis state root + (l2_genesis_root, 0) }, + |prev_journal| (prev_journal.state_root, prev_journal.last_l2_height), ); // If we have a previous light client proof, check they can be chained @@ -90,10 +83,9 @@ pub fn run_circuit( } // TODO: Test for multiple assumptions to see if the env::verify function does automatic matching between the journal and the assumption or do we need to verify them in order? // https://github.com/chainwayxyz/citrea/issues/1401 - let batch_proof_method_id = input.batch_proof_method_id; // Parse the batch proof da data for blob in input.da_data { - if blob.sender().as_ref() == input.batch_prover_da_pub_key { + if blob.sender().as_ref() == batch_prover_da_public_key { let data = DaDataLightClient::try_from_slice(blob.verified_data()); if let Ok(data) = data { @@ -159,6 +151,5 @@ pub fn run_circuit( da_prev_11_timestamps: block_updates.prev_11_timestamps, unchained_batch_proofs_info: unchained_outputs, last_l2_height, - l2_genesis_state_root, }) } diff --git a/crates/light-client-prover/src/da_block_handler.rs b/crates/light-client-prover/src/da_block_handler.rs index 7c513f9b6..f522e1c4d 100644 --- a/crates/light-client-prover/src/da_block_handler.rs +++ b/crates/light-client-prover/src/da_block_handler.rs @@ -7,12 +7,11 @@ use borsh::BorshDeserialize; use citrea_common::cache::L1BlockCache; use citrea_common::da::get_da_block_at_height; use citrea_common::LightClientProverConfig; -use citrea_primitives::forks::FORKS; +use citrea_primitives::forks::fork_from_block_number; use jsonrpsee::http_client::HttpClient; use sov_db::ledger_db::{LightClientProverLedgerOps, SharedLedgerOps}; use sov_db::schema::types::{SlotNumber, StoredLightClientProofOutput}; use sov_ledger_rpc::LedgerRpcClient; -use sov_modules_api::fork::fork_from_block_number; use sov_modules_api::{BatchProofCircuitOutput, BlobReaderTrait, DaSpec, Zkvm}; use sov_rollup_interface::da::{BlockHeaderTrait, DaDataLightClient, DaNamespace}; use sov_rollup_interface::services::da::{DaService, SlotData}; @@ -169,7 +168,7 @@ where >(&proof) .map_err(|_| anyhow!("Proof should be deserializable"))?; let last_l2_height = batch_proof_output.last_l2_height; - let current_spec = fork_from_block_number(FORKS, last_l2_height).spec_id; + let current_spec = fork_from_block_number(last_l2_height).spec_id; let batch_proof_method_id = self .batch_proof_code_commitments .get(¤t_spec) @@ -183,7 +182,6 @@ where } let previous_l1_height = l1_height - 1; let mut light_client_proof_journal = None; - let mut l2_genesis_state_root = None; let l2_last_height = match self .ledger_db .get_light_client_proof_data_by_l1_height(previous_l1_height)? @@ -205,13 +203,6 @@ where // If the prev block is the block before the first processed l1 block // then we don't have a previous light client proof, so just give an info if previous_l1_height == initial_l1_height { - // TODO: Provide genesis state root here to the light client proof circuit input - l2_genesis_state_root = self - .sequencer_client - .get_l2_genesis_state_root() - .await? - .map(|v| v.as_slice().try_into().unwrap()); - tracing::info!( "No previous light client proof found for L1 block: {}", previous_l1_height @@ -231,11 +222,7 @@ where let l2_last_height = l2_last_height.ok_or(anyhow!( "Could not determine the last L2 height for batch proof" ))?; - let current_fork = fork_from_block_number(FORKS, l2_last_height); - let batch_proof_method_id = self - .batch_proof_code_commitments - .get(¤t_fork.spec_id) - .expect("Fork should have a guest code attached"); + let current_fork = fork_from_block_number(l2_last_height); let light_client_proof_code_commitment = self .light_client_proof_code_commitments .get(¤t_fork.spec_id) @@ -251,11 +238,8 @@ where inclusion_proof, completeness_proof, da_block_header: l1_block.header().clone(), - batch_prover_da_pub_key: self.batch_prover_da_pub_key.clone(), - batch_proof_method_id: batch_proof_method_id.clone().into(), light_client_proof_method_id: light_client_proof_code_commitment.clone().into(), previous_light_client_proof_journal: light_client_proof_journal, - l2_genesis_state_root, }; let proof = self @@ -282,7 +266,6 @@ where da_prev_11_timestamps: circuit_output.da_prev_11_timestamps, unchained_batch_proofs_info: circuit_output.unchained_batch_proofs_info, last_l2_height: circuit_output.last_l2_height, - l2_genesis_state_root: circuit_output.l2_genesis_state_root, }; self.ledger_db.insert_light_client_proof_data_by_l1_height( diff --git a/crates/light-client-prover/src/tests/mod.rs b/crates/light-client-prover/src/tests/mod.rs index 59a391505..e2f689f70 100644 --- a/crates/light-client-prover/src/tests/mod.rs +++ b/crates/light-client-prover/src/tests/mod.rs @@ -1,6 +1,6 @@ mod test_utils; -use sov_mock_da::{MockBlockHeader, MockDaSpec, MockDaVerifier}; +use sov_mock_da::{MockBlockHeader, MockDaVerifier}; use sov_mock_zkvm::MockZkGuest; use sov_rollup_interface::zk::LightClientCircuitInput; use test_utils::{create_mock_blob, create_prev_lcp_serialized}; @@ -18,23 +18,26 @@ fn test_light_client_circuit_valid_da_valid_data() { let block_header_1 = MockBlockHeader::from_height(1); - let input = LightClientCircuitInput:: { + let input = LightClientCircuitInput { previous_light_client_proof_journal: None, light_client_proof_method_id, da_block_header: block_header_1, da_data: vec![blob_1, blob_2], inclusion_proof: [1u8; 32], completeness_proof: (), - l2_genesis_state_root: Some([1u8; 32]), - batch_proof_method_id, - batch_prover_da_pub_key: [9; 32].to_vec(), }; - let serialized_input = borsh::to_vec(&input).expect("should serialize"); - - let mut guest = MockZkGuest::new(serialized_input); + let l2_genesis_state_root = [1u8; 32]; + let batch_prover_da_pub_key = [9; 32].to_vec(); - let output_1 = run_circuit(da_verifier.clone(), &guest).unwrap(); + let output_1 = run_circuit::<_, MockZkGuest>( + da_verifier.clone(), + input, + l2_genesis_state_root, + batch_proof_method_id, + &batch_prover_da_pub_key, + ) + .unwrap(); // Check that the state transition actually happened assert_eq!(output_1.state_root, [3; 32]); @@ -49,23 +52,23 @@ fn test_light_client_circuit_valid_da_valid_data() { let mock_output_1_serialized = create_prev_lcp_serialized(output_1, true); - let input_2 = LightClientCircuitInput:: { + let input_2 = LightClientCircuitInput { previous_light_client_proof_journal: Some(mock_output_1_serialized), da_block_header: block_header_2, da_data: vec![blob_3, blob_4], light_client_proof_method_id, inclusion_proof: [1u8; 32], completeness_proof: (), - l2_genesis_state_root: None, - batch_proof_method_id, - batch_prover_da_pub_key: [9; 32].to_vec(), }; - let serialized_input_2 = borsh::to_vec(&input_2).expect("should serialize"); - - guest.input = serialized_input_2; - - let output_2 = run_circuit(da_verifier, &guest).unwrap(); + let output_2 = run_circuit::<_, MockZkGuest>( + da_verifier.clone(), + input_2, + l2_genesis_state_root, + batch_proof_method_id, + &batch_prover_da_pub_key, + ) + .unwrap(); // Check that the state transition actually happened assert_eq!(output_2.state_root, [5; 32]); @@ -76,6 +79,7 @@ fn test_light_client_circuit_valid_da_valid_data() { #[test] fn test_wrong_order_da_blocks_should_still_work() { let light_client_proof_method_id = [1u32; 8]; + let batch_proof_method_id = [1u32; 8]; let da_verifier = MockDaVerifier {}; let blob_1 = create_mock_blob([1u8; 32], [2u8; 32], 2, true); @@ -83,23 +87,26 @@ fn test_wrong_order_da_blocks_should_still_work() { let block_header_1 = MockBlockHeader::from_height(1); - let input = LightClientCircuitInput:: { + let input = LightClientCircuitInput { previous_light_client_proof_journal: None, light_client_proof_method_id, da_block_header: block_header_1, da_data: vec![blob_2, blob_1], inclusion_proof: [1u8; 32], completeness_proof: (), - l2_genesis_state_root: Some([1u8; 32]), - batch_proof_method_id: light_client_proof_method_id, - batch_prover_da_pub_key: [9; 32].to_vec(), }; - let serialized_input = borsh::to_vec(&input).expect("should serialize"); - - let guest = MockZkGuest::new(serialized_input); + let l2_genesis_state_root = [1u8; 32]; + let batch_prover_da_pub_key = [9; 32].to_vec(); - let output_1 = run_circuit(da_verifier.clone(), &guest).unwrap(); + let output_1 = run_circuit::<_, MockZkGuest>( + da_verifier.clone(), + input, + l2_genesis_state_root, + batch_proof_method_id, + &batch_prover_da_pub_key, + ) + .unwrap(); // Check that the state transition actually happened assert_eq!(output_1.state_root, [3; 32]); @@ -110,6 +117,7 @@ fn test_wrong_order_da_blocks_should_still_work() { #[test] fn create_unchainable_outputs_then_chain_them_on_next_block() { let light_client_proof_method_id = [1u32; 8]; + let batch_proof_method_id = [1u32; 8]; let da_verifier = MockDaVerifier {}; let block_header_1 = MockBlockHeader::from_height(1); @@ -117,23 +125,26 @@ fn create_unchainable_outputs_then_chain_them_on_next_block() { let blob_1 = create_mock_blob([2u8; 32], [3u8; 32], 3, true); let blob_2 = create_mock_blob([3u8; 32], [4u8; 32], 4, true); - let input = LightClientCircuitInput:: { + let input = LightClientCircuitInput { previous_light_client_proof_journal: None, light_client_proof_method_id, da_block_header: block_header_1, da_data: vec![blob_2, blob_1], inclusion_proof: [1u8; 32], completeness_proof: (), - l2_genesis_state_root: Some([1u8; 32]), - batch_proof_method_id: light_client_proof_method_id, - batch_prover_da_pub_key: [9; 32].to_vec(), }; - let serialized_input = borsh::to_vec(&input).expect("should serialize"); + let l2_genesis_state_root = [1u8; 32]; + let batch_prover_da_pub_key = [9; 32].to_vec(); - let mut guest = MockZkGuest::new(serialized_input); - - let output_1 = run_circuit(da_verifier.clone(), &guest).unwrap(); + let output_1 = run_circuit::<_, MockZkGuest>( + da_verifier.clone(), + input, + l2_genesis_state_root, + batch_proof_method_id, + &batch_prover_da_pub_key, + ) + .unwrap(); // Check that the state transition has not happened because we are missing 1->2 assert_eq!(output_1.state_root, [1; 32]); @@ -159,17 +170,23 @@ fn create_unchainable_outputs_then_chain_them_on_next_block() { let mock_output_1_ser = create_prev_lcp_serialized(output_1, true); - let input_2 = LightClientCircuitInput:: { + let input_2 = LightClientCircuitInput { previous_light_client_proof_journal: Some(mock_output_1_ser), + light_client_proof_method_id, da_block_header: block_header_2, da_data: vec![blob_1], - l2_genesis_state_root: None, - ..input + inclusion_proof: [1u8; 32], + completeness_proof: (), }; - guest.input = borsh::to_vec(&input_2).unwrap(); - - let output_2 = run_circuit(da_verifier, &guest).unwrap(); + let output_2 = run_circuit::<_, MockZkGuest>( + da_verifier.clone(), + input_2, + l2_genesis_state_root, + batch_proof_method_id, + &batch_prover_da_pub_key, + ) + .unwrap(); // Check that the state transition actually happened from 1-4 now @@ -181,6 +198,7 @@ fn create_unchainable_outputs_then_chain_them_on_next_block() { #[test] fn test_header_chain_proof_height_and_hash() { let light_client_proof_method_id = [1u32; 8]; + let batch_proof_method_id = [1u32; 8]; let da_verifier = MockDaVerifier {}; let blob_1 = create_mock_blob([1u8; 32], [2u8; 32], 2, true); @@ -188,23 +206,26 @@ fn test_header_chain_proof_height_and_hash() { let block_header_1 = MockBlockHeader::from_height(1); - let input = LightClientCircuitInput:: { + let input = LightClientCircuitInput { previous_light_client_proof_journal: None, light_client_proof_method_id, da_block_header: block_header_1, da_data: vec![blob_1, blob_2], inclusion_proof: [1u8; 32], completeness_proof: (), - l2_genesis_state_root: Some([1u8; 32]), - batch_proof_method_id: light_client_proof_method_id, - batch_prover_da_pub_key: [9; 32].to_vec(), }; - let serialized_input = borsh::to_vec(&input).expect("should serialize"); - - let mut guest = MockZkGuest::new(serialized_input); + let l2_genesis_state_root = [1u8; 32]; + let batch_prover_da_pub_key = [9; 32].to_vec(); - let output_1 = run_circuit(da_verifier.clone(), &guest).unwrap(); + let output_1 = run_circuit::<_, MockZkGuest>( + da_verifier.clone(), + input, + l2_genesis_state_root, + batch_proof_method_id, + &batch_prover_da_pub_key, + ) + .unwrap(); // Check that the state transition actually happened assert_eq!(output_1.state_root, [3; 32]); @@ -219,24 +240,23 @@ fn test_header_chain_proof_height_and_hash() { let prev_lcp_out = create_prev_lcp_serialized(output_1, true); - let input_2 = LightClientCircuitInput:: { + let input_2 = LightClientCircuitInput { previous_light_client_proof_journal: Some(prev_lcp_out), da_block_header: block_header_2, da_data: vec![blob_3, blob_4], light_client_proof_method_id, inclusion_proof: [1u8; 32], completeness_proof: (), - l2_genesis_state_root: None, - batch_proof_method_id: light_client_proof_method_id, - batch_prover_da_pub_key: [9; 32].to_vec(), }; - let serialized_input_2 = borsh::to_vec(&input_2).expect("should serialize"); - - guest.input = serialized_input_2; - // Header chain verification must fail because the l1 block 3 was given before l1 block 2 - let res = run_circuit(da_verifier, &guest); + let res = run_circuit::<_, MockZkGuest>( + da_verifier, + input_2, + l2_genesis_state_root, + batch_proof_method_id, + &batch_prover_da_pub_key, + ); assert!(matches!( res, Err(LightClientVerificationError::HeaderChainVerificationFailed) @@ -254,23 +274,26 @@ fn test_unverifiable_batch_proofs() { let block_header_1 = MockBlockHeader::from_height(1); - let input = LightClientCircuitInput:: { + let input = LightClientCircuitInput { previous_light_client_proof_journal: None, light_client_proof_method_id, da_block_header: block_header_1, da_data: vec![blob_1, blob_2], inclusion_proof: [1u8; 32], completeness_proof: (), - l2_genesis_state_root: Some([1u8; 32]), - batch_proof_method_id, - batch_prover_da_pub_key: [9; 32].to_vec(), }; - let serialized_input = borsh::to_vec(&input).expect("should serialize"); + let l2_genesis_state_root = [1u8; 32]; + let batch_prover_da_pub_key = [9; 32].to_vec(); - let guest = MockZkGuest::new(serialized_input); - - let output_1 = run_circuit(da_verifier.clone(), &guest).unwrap(); + let output_1 = run_circuit::<_, MockZkGuest>( + da_verifier.clone(), + input, + l2_genesis_state_root, + batch_proof_method_id, + &batch_prover_da_pub_key, + ) + .unwrap(); // Check that the state transition actually happened but only for verified batch proof // and assert the unverified is ignored, so it is not even in the unchained outputs @@ -291,23 +314,26 @@ fn test_unverifiable_prev_light_client_proof() { let block_header_1 = MockBlockHeader::from_height(1); - let input = LightClientCircuitInput:: { + let input = LightClientCircuitInput { previous_light_client_proof_journal: None, light_client_proof_method_id, da_block_header: block_header_1, da_data: vec![blob_1, blob_2], inclusion_proof: [1u8; 32], completeness_proof: (), - l2_genesis_state_root: Some([1u8; 32]), - batch_proof_method_id, - batch_prover_da_pub_key: [9; 32].to_vec(), }; - let serialized_input = borsh::to_vec(&input).expect("should serialize"); - - let mut guest = MockZkGuest::new(serialized_input); + let l2_genesis_state_root = [1u8; 32]; + let batch_prover_da_pub_key = [9; 32].to_vec(); - let output_1 = run_circuit(da_verifier.clone(), &guest).unwrap(); + let output_1 = run_circuit::<_, MockZkGuest>( + da_verifier.clone(), + input, + l2_genesis_state_root, + batch_proof_method_id, + &batch_prover_da_pub_key, + ) + .unwrap(); // Check that the state transition actually happened but only for verified batch proof // and assert the unverified is ignored, so it is not even in the unchained outputs @@ -320,21 +346,22 @@ fn test_unverifiable_prev_light_client_proof() { let prev_lcp_out = create_prev_lcp_serialized(output_1, false); - let input_2 = LightClientCircuitInput:: { + let input_2 = LightClientCircuitInput { previous_light_client_proof_journal: Some(prev_lcp_out), da_block_header: block_header_2, da_data: vec![], light_client_proof_method_id, inclusion_proof: [1u8; 32], completeness_proof: (), - l2_genesis_state_root: None, - batch_proof_method_id: light_client_proof_method_id, - batch_prover_da_pub_key: [9; 32].to_vec(), }; - guest.input = borsh::to_vec(&input_2).unwrap(); - - let res = run_circuit(da_verifier, &guest); + let res = run_circuit::<_, MockZkGuest>( + da_verifier, + input_2, + l2_genesis_state_root, + light_client_proof_method_id, + &batch_prover_da_pub_key, + ); assert!(matches!( res, Err(LightClientVerificationError::InvalidPreviousLightClientProof) diff --git a/crates/primitives/src/forks.rs b/crates/primitives/src/forks.rs index 6934c7c86..a67598aea 100644 --- a/crates/primitives/src/forks.rs +++ b/crates/primitives/src/forks.rs @@ -1,49 +1,73 @@ -use sov_rollup_interface::fork::Fork; +use std::sync::OnceLock; + +use sov_rollup_interface::fork::{fork_pos_from_block_number, verify_forks, Fork}; use sov_rollup_interface::spec::SpecId; +use sov_rollup_interface::Network; + +static FORKS: OnceLock<&'static [Fork]> = OnceLock::new(); + +/// Set forks globally based on the network. Must be called once at the start of the application. +pub fn use_network_forks(network: Network) { + let forks: &[Fork] = match network { + Network::Mainnet => &MAINNET_FORKS, + Network::Testnet => &TESTNET_FORKS, + Network::Devnet => &DEVNET_FORKS, + Network::Nightly => &NIGHTLY_FORKS, + }; + + #[cfg(not(feature = "testing"))] + FORKS.set(forks).expect("Forks must be set exactly once"); -/// This defines the list of forks which will be activated -/// at specific heights. -#[cfg(not(feature = "testing"))] -pub const FORKS: &[Fork] = &[ - Fork { - spec_id: SpecId::Genesis, - activation_height: 0, - }, - Fork { - spec_id: SpecId::Fork1, - activation_height: 99999999999, // TODO: change this to the correct height once decided - }, - // Examples of how we can define further forks - // Fork { spec_id: SpecId::Fork2, activation_height: 1000 }, + #[cfg(feature = "testing")] + let _ = FORKS.set(forks); +} + +/// Get forks. Forks need to be set before calling this method if not in testing environment. +/// In testing environment default forks are used. +pub fn get_forks() -> &'static [Fork] { + match FORKS.get() { + Some(forks) => forks, + None => { + #[cfg(not(feature = "testing"))] + panic!("Forks must be set before accessing"); + + #[cfg(feature = "testing")] + { + use_network_forks(Network::Nightly); + FORKS.get().expect("Just set it") + } + } + } +} + +/// Get fork from the given block number. Forks must be set before calling this method if not in test environment. +/// In test environment default forks are used. +pub fn fork_from_block_number(block_number: u64) -> Fork { + let forks = get_forks(); + let pos = fork_pos_from_block_number(forks, block_number); + forks[pos] +} + +pub const MAINNET_FORKS: [Fork; 1] = [Fork::new(SpecId::Fork1, 0)]; + +pub const TESTNET_FORKS: [Fork; 2] = [ + Fork::new(SpecId::Genesis, 0), + Fork::new(SpecId::Fork1, 999_999_999), ]; -#[cfg(feature = "testing")] -pub const FORKS: &[Fork] = &[ - Fork { - spec_id: SpecId::Genesis, - activation_height: 0, - }, - Fork { - spec_id: SpecId::Fork1, - activation_height: 1000, - }, - Fork { - spec_id: SpecId::Fork2, - activation_height: 2000, - }, +pub const DEVNET_FORKS: [Fork; 2] = [ + Fork::new(SpecId::Genesis, 0), + Fork::new(SpecId::Fork1, 999_999_999), ]; -const _CHECK_FORKS_ARE_SORTED: () = { - const fn check_forks_are_sorted() { - let mut height = FORKS[0].activation_height; - let mut i = 1; - while i < FORKS.len() { - let fork = FORKS[i]; - let fork_height = fork.activation_height; - assert!(fork_height > height, "FORKS are not sorted!"); - height = fork_height; - i += 1; - } +pub const NIGHTLY_FORKS: [Fork; 1] = [Fork::new(SpecId::Fork1, 0)]; + +const _CHECK_FORKS: () = { + if !verify_forks(&MAINNET_FORKS) + || !verify_forks(&TESTNET_FORKS) + || !verify_forks(&DEVNET_FORKS) + || !verify_forks(&NIGHTLY_FORKS) + { + panic!("FORKS order is invalid") } - check_forks_are_sorted() }; diff --git a/crates/prover-services/Cargo.toml b/crates/prover-services/Cargo.toml index 5fa4f737d..e87bba960 100644 --- a/crates/prover-services/Cargo.toml +++ b/crates/prover-services/Cargo.toml @@ -9,10 +9,6 @@ publish.workspace = true repository.workspace = true [dependencies] -# Citrea Deps -citrea-primitives = { path = "../primitives" } -citrea-stf = { path = "../citrea-stf" } - # Sov SDK deps sov-db = { path = "../sovereign-sdk/full-node/db/sov-db" } sov-modules-api = { path = "../sovereign-sdk/module-system/sov-modules-api", default-features = false } @@ -31,7 +27,6 @@ num_cpus = { workspace = true } parking_lot = { workspace = true } rand = { workspace = true } rayon = { workspace = true } -rs_merkle = { workspace = true } serde = { workspace = true } tokio = { workspace = true } tokio-util = { workspace = true } @@ -43,5 +38,3 @@ sha2 = { workspace = true } tempfile = { workspace = true } sov-stf-runner = { path = "../sovereign-sdk/full-node/sov-stf-runner", features = ["mock"] } - -citrea-stf = { path = "../citrea-stf", features = ["native"] } diff --git a/crates/prover-services/src/lib.rs b/crates/prover-services/src/lib.rs index 5fd74c1c9..35ee91377 100644 --- a/crates/prover-services/src/lib.rs +++ b/crates/prover-services/src/lib.rs @@ -1,27 +1,10 @@ -use std::sync::Arc; - -use citrea_stf::verifier::StateTransitionVerifier; -use sov_rollup_interface::services::da::DaService; -use sov_rollup_interface::stf::StateTransitionFunction; -use sov_rollup_interface::zk::ZkvmHost; -use tokio::sync::Mutex; - mod parallel; pub use parallel::*; -type Simulator = - Arc>>; - -pub enum ProofGenMode -where - Da: DaService, - Vm: ZkvmHost, - Stf: StateTransitionFunction, -{ +#[derive(Debug, Clone, Copy)] +pub enum ProofGenMode { /// Skips proving. Skip, - /// The simulator runs the rollup verifier logic without even emulating the zkVM - Simulate(Simulator), /// The executor runs the rollup verification logic in the zkVM, but does not actually /// produce a zk proof Execute, @@ -38,22 +21,3 @@ where usize, ), } - -impl Clone for ProofGenMode -where - Da: DaService, - Vm: ZkvmHost, - Stf: StateTransitionFunction, -{ - fn clone(&self) -> Self { - match self { - Self::Skip => Self::Skip, - Self::Execute => Self::Execute, - Self::ProveWithSampling => Self::ProveWithSampling, - Self::ProveWithSamplingWithFakeProofs(proof_sampling_number) => { - Self::ProveWithSamplingWithFakeProofs(*proof_sampling_number) - } - Self::Simulate(simulate) => Self::Simulate(Arc::clone(simulate)), - } - } -} diff --git a/crates/prover-services/src/parallel/mod.rs b/crates/prover-services/src/parallel/mod.rs index 60a8a7ad4..30eae50b8 100644 --- a/crates/prover-services/src/parallel/mod.rs +++ b/crates/prover-services/src/parallel/mod.rs @@ -6,7 +6,6 @@ use rand::Rng; use sov_db::ledger_db::LedgerDB; use sov_rollup_interface::da::DaData; use sov_rollup_interface::services::da::DaService; -use sov_rollup_interface::stf::StateTransitionFunction; use sov_rollup_interface::zk::{Proof, ZkvmHost}; use sov_stf_runner::ProverService; use tokio::sync::{oneshot, Mutex}; @@ -19,38 +18,32 @@ pub(crate) type Assumptions = Vec>; pub(crate) type ProofData = (Input, Assumptions); /// Prover service that generates proofs in parallel. -pub struct ParallelProverService +pub struct ParallelProverService where Da: DaService, Vm: ZkvmHost + 'static, - Stf: StateTransitionFunction + Send + Sync + 'static, - Stf::PreState: Clone + Send + Sync + 'static, { thread_pool: rayon::ThreadPool, - proof_mode: ProofGenMode, + proof_mode: ProofGenMode, da_service: Arc, vm: Vm, - zk_storage: Stf::PreState, _ledger_db: LedgerDB, proof_queue: Arc>>, } -impl ParallelProverService +impl ParallelProverService where Da: DaService, Vm: ZkvmHost, - Stf: StateTransitionFunction + Send + Sync, - Stf::PreState: Clone + Send + Sync, { /// Creates a new prover. pub fn new( da_service: Arc, vm: Vm, - proof_mode: ProofGenMode, - zk_storage: Stf::PreState, + proof_mode: ProofGenMode, thread_pool_size: usize, _ledger_db: LedgerDB, ) -> anyhow::Result { @@ -63,9 +56,6 @@ where ProofGenMode::Skip => { tracing::info!("Prover is configured to skip proving"); } - ProofGenMode::Simulate(_) => { - tracing::info!("Prover is configured to simulate proving"); - } ProofGenMode::Execute => { tracing::info!("Prover is configured to execute proving"); } @@ -93,7 +83,6 @@ where proof_mode, da_service, vm, - zk_storage, _ledger_db, proof_queue: Arc::new(Mutex::new(vec![])), }) @@ -104,8 +93,7 @@ where pub fn new_from_env( da_service: Arc, vm: Vm, - proof_mode: ProofGenMode, - zk_storage: Stf::PreState, + proof_mode: ProofGenMode, _ledger_db: LedgerDB, ) -> anyhow::Result { let thread_pool_size = std::env::var("PARALLEL_PROOF_LIMIT") @@ -113,14 +101,7 @@ where .parse::() .expect("PARALLEL_PROOF_LIMIT must be valid unsigned number"); - Self::new( - da_service, - vm, - proof_mode, - zk_storage, - thread_pool_size, - _ledger_db, - ) + Self::new(da_service, vm, proof_mode, thread_pool_size, _ledger_db) } async fn prove_all(&self, elf: Vec, proof_queue: Vec) -> Vec { @@ -168,8 +149,7 @@ where async fn prove_one(&self, elf: Vec, (input, assumptions): ProofData) -> Proof { let mut vm = self.vm.clone(); - let zk_storage = self.zk_storage.clone(); - let proof_mode = self.proof_mode.clone(); + let proof_mode = self.proof_mode; vm.add_hint(input); for assumption in assumptions { @@ -178,8 +158,7 @@ where let (tx, rx) = oneshot::channel(); self.thread_pool.spawn(move || { - let proof = - make_proof(vm, elf, zk_storage, proof_mode).expect("Proof creation must not fail"); + let proof = make_proof(vm, elf, proof_mode).expect("Proof creation must not fail"); let _ = tx.send(proof); }); @@ -196,12 +175,10 @@ where } #[async_trait] -impl ProverService for ParallelProverService +impl ProverService for ParallelProverService where Da: DaService, Vm: ZkvmHost, - Stf: StateTransitionFunction + Send + Sync, - Stf::PreState: Clone + Send + Sync, { type DaService = Da; @@ -252,41 +229,23 @@ where } } -fn make_proof( +fn make_proof( mut vm: Vm, elf: Vec, - zk_storage: Stf::PreState, - proof_mode: ProofGenMode, + proof_mode: ProofGenMode, ) -> Result where - Da: DaService, Vm: ZkvmHost, - Stf: StateTransitionFunction + Send + Sync, - Stf::PreState: Send + Sync, { match proof_mode { ProofGenMode::Skip => Ok(Vec::default()), - ProofGenMode::Simulate(verifier) => { - let mut verifier = verifier.blocking_lock(); - verifier - .run_sequencer_commitments_in_da_slot(vm.simulate_with_hints(), zk_storage) - .map(|_| Vec::default()) - .map_err(|e| { - anyhow::anyhow!("Guest execution must succeed but failed with {:?}", e) - }) - } - ProofGenMode::Execute => { - drop(proof_mode); - vm.run(elf, false) - } + ProofGenMode::Execute => vm.run(elf, false), ProofGenMode::ProveWithSampling => { - drop(proof_mode); // `make_proof` is called with a probability in this case. // When it's called, we have to produce a real proof. vm.run(elf, true) } ProofGenMode::ProveWithSamplingWithFakeProofs(proof_sampling_number) => { - drop(proof_mode); // `make_proof` is called unconditionally in this case. // When it's called, we have to calculate the probabiliry for a proof // and produce a real proof if we are lucky. If unlucky - produce a fake proof. diff --git a/crates/sequencer/src/runner.rs b/crates/sequencer/src/runner.rs index f60b512ce..43b98966a 100644 --- a/crates/sequencer/src/runner.rs +++ b/crates/sequencer/src/runner.rs @@ -94,7 +94,7 @@ where sequencer_pub_key: Vec, sequencer_da_pub_key: Vec, rpc_config: RpcConfig, - fork_manager: ForkManager, + fork_manager: ForkManager<'static>, soft_confirmation_tx: broadcast::Sender, task_manager: TaskManager<()>, } @@ -122,7 +122,7 @@ where public_keys: RollupPublicKeys, ledger_db: DB, rpc_config: RpcConfig, - fork_manager: ForkManager, + fork_manager: ForkManager<'static>, soft_confirmation_tx: broadcast::Sender, task_manager: TaskManager<()>, ) -> anyhow::Result { diff --git a/crates/sovereign-sdk/adapters/mock-da/src/service.rs b/crates/sovereign-sdk/adapters/mock-da/src/service.rs index 9080cfdef..df9f92740 100644 --- a/crates/sovereign-sdk/adapters/mock-da/src/service.rs +++ b/crates/sovereign-sdk/adapters/mock-da/src/service.rs @@ -115,7 +115,7 @@ impl MockDaService { /// Get sequencer address pub fn get_sequencer_address(&self) -> MockAddress { - self.sequencer_da_address + self.sequencer_da_address.clone() } /// Change number of wait attempts before giving up on waiting for block @@ -221,7 +221,7 @@ impl MockDaService { let blob = MockBlob::new_with_zkp_proof( blob.to_vec(), zkp_proof, - self.sequencer_da_address, + self.sequencer_da_address.clone(), data_hash, ); let header = MockBlockHeader { diff --git a/crates/sovereign-sdk/adapters/mock-da/src/types/address.rs b/crates/sovereign-sdk/adapters/mock-da/src/types/address.rs index a813f67e6..249206b48 100644 --- a/crates/sovereign-sdk/adapters/mock-da/src/types/address.rs +++ b/crates/sovereign-sdk/adapters/mock-da/src/types/address.rs @@ -1,102 +1,98 @@ +use std::fmt; use std::str::FromStr; +use borsh::{BorshDeserialize, BorshSerialize}; +use serde::{Deserialize, Serialize}; use sov_rollup_interface::{BasicAddress, RollupAddress}; -/// Sequencer DA address used in tests. -pub const MOCK_SEQUENCER_DA_ADDRESS: [u8; 32] = [0u8; 32]; - -/// A mock address type used for testing. Internally, this type is standard 32 byte array. -#[derive( - Debug, PartialEq, Clone, Eq, Copy, Hash, Default, borsh::BorshDeserialize, borsh::BorshSerialize, -)] -pub struct MockAddress { - /// Underlying mock address. - addr: [u8; 32], -} +/// MockAddress is a wrapper around Vec to implement AddressTrait +#[derive(Debug, PartialEq, Clone, Eq, BorshDeserialize, BorshSerialize, Hash)] +pub struct MockAddress(pub Vec); impl MockAddress { - /// Creates a new mock address containing the given bytes. - pub const fn new(addr: [u8; 32]) -> Self { - Self { addr } + /// Create new MockAddress + pub fn new(arr: [u8; 32]) -> Self { + Self(arr.to_vec()) } } -impl serde::Serialize for MockAddress { - fn serialize(&self, serializer: S) -> Result - where - S: serde::Serializer, - { - if serializer.is_human_readable() { - serde::Serialize::serialize(&hex::encode(self.addr), serializer) - } else { - serde::Serialize::serialize(&self.addr, serializer) - } +impl BasicAddress for MockAddress {} +impl RollupAddress for MockAddress {} + +impl FromStr for MockAddress { + type Err = anyhow::Error; + + fn from_str(s: &str) -> Result { + Ok(Self(hex::decode(s)?)) } } -impl<'de> serde::Deserialize<'de> for MockAddress { - fn deserialize(deserializer: D) -> Result - where - D: serde::Deserializer<'de>, - { - if deserializer.is_human_readable() { - let hex_addr: String = serde::Deserialize::deserialize(deserializer)?; - Ok(MockAddress::from_str(&hex_addr).map_err(serde::de::Error::custom)?) - } else { - let addr = <[u8; 32] as serde::Deserialize>::deserialize(deserializer)?; - Ok(MockAddress { addr }) - } +impl fmt::Display for MockAddress { + fn fmt(&self, f: &mut fmt::Formatter) -> core::fmt::Result { + let hash = hex::encode(&self.0); + write!(f, "{hash}") } } -impl FromStr for MockAddress { - type Err = anyhow::Error; - - fn from_str(s: &str) -> Result { - let addr = hex::decode(s).map_err(anyhow::Error::msg)?; - if addr.len() != 32 { - return Err(anyhow::anyhow!("Invalid address length")); - } +impl AsRef<[u8]> for MockAddress { + fn as_ref(&self) -> &[u8] { + self.0.as_ref() + } +} - let mut array = [0; 32]; - array.copy_from_slice(&addr); - Ok(MockAddress { addr: array }) +impl From<[u8; 32]> for MockAddress { + fn from(value: [u8; 32]) -> Self { + Self(value.to_vec()) } } impl<'a> TryFrom<&'a [u8]> for MockAddress { type Error = anyhow::Error; - fn try_from(addr: &'a [u8]) -> Result { - if addr.len() != 32 { - anyhow::bail!("Address must be 32 bytes long"); - } - let mut addr_bytes = [0u8; 32]; - addr_bytes.copy_from_slice(addr); - Ok(Self { addr: addr_bytes }) + fn try_from(value: &'a [u8]) -> Result { + Ok(Self(value.to_vec())) } } -impl AsRef<[u8]> for MockAddress { - fn as_ref(&self) -> &[u8] { - &self.addr +impl From> for MockAddress { + fn from(value: Vec) -> Self { + Self(value) } } -impl From<[u8; 32]> for MockAddress { - fn from(addr: [u8; 32]) -> Self { - MockAddress { addr } +impl Default for MockAddress { + fn default() -> Self { + Self(vec![0; 32]) } } -impl std::fmt::Display for MockAddress { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - write!(f, "{}", hex::encode(self.addr)) +impl Serialize for MockAddress { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + if serializer.is_human_readable() { + Serialize::serialize(&hex::encode(&self.0), serializer) + } else { + Serialize::serialize(&self.0, serializer) + } } } -impl BasicAddress for MockAddress {} -impl RollupAddress for MockAddress {} +impl<'de> Deserialize<'de> for MockAddress { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + if deserializer.is_human_readable() { + let hex_addr: String = Deserialize::deserialize(deserializer)?; + Ok(MockAddress::from_str(&hex_addr).map_err(serde::de::Error::custom)?) + } else { + let addr = as Deserialize>::deserialize(deserializer)?; + Ok(MockAddress(addr)) + } + } +} #[cfg(test)] mod tests { @@ -104,7 +100,7 @@ mod tests { #[test] fn test_mock_address_string() { - let addr = MockAddress { addr: [3u8; 32] }; + let addr = MockAddress::from([3; 32]); let s = addr.to_string(); let recovered_addr = s.parse::().unwrap(); assert_eq!(addr, recovered_addr); diff --git a/crates/sovereign-sdk/adapters/mock-da/src/types/mod.rs b/crates/sovereign-sdk/adapters/mock-da/src/types/mod.rs index c6e86ea0f..61641b31d 100644 --- a/crates/sovereign-sdk/adapters/mock-da/src/types/mod.rs +++ b/crates/sovereign-sdk/adapters/mock-da/src/types/mod.rs @@ -4,7 +4,7 @@ use std::fmt::{Debug, Formatter}; use std::hash::Hasher; use std::path::PathBuf; -pub use address::{MockAddress, MOCK_SEQUENCER_DA_ADDRESS}; +pub use address::MockAddress; use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; use sov_rollup_interface::da::{BlockHashTrait, BlockHeaderTrait, CountedBufReader, Time}; diff --git a/crates/sovereign-sdk/adapters/mock-da/src/verifier.rs b/crates/sovereign-sdk/adapters/mock-da/src/verifier.rs index fb4fddb93..b731c435b 100644 --- a/crates/sovereign-sdk/adapters/mock-da/src/verifier.rs +++ b/crates/sovereign-sdk/adapters/mock-da/src/verifier.rs @@ -11,7 +11,7 @@ impl BlobReaderTrait for MockBlob { type Address = MockAddress; fn sender(&self) -> Self::Address { - self.address + self.address.clone() } fn hash(&self) -> [u8; 32] { diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs index 6f90dad4e..8071efd15 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs @@ -81,8 +81,6 @@ pub struct StoredLightClientProofOutput { pub unchained_batch_proofs_info: Vec, /// Last l2 height after proof. pub last_l2_height: u64, - /// L2 genesis state root. - pub l2_genesis_state_root: [u8; 32], } impl From for LightClientProofOutputRpcResponse { @@ -98,7 +96,6 @@ impl From for LightClientProofOutputRpcResponse { da_prev_11_timestamps: value.da_prev_11_timestamps, unchained_batch_proofs_info: value.unchained_batch_proofs_info, last_l2_height: value.last_l2_height, - l2_genesis_state_root: value.l2_genesis_state_root, } } } diff --git a/crates/sovereign-sdk/full-node/sov-stf-runner/src/mock/mod.rs b/crates/sovereign-sdk/full-node/sov-stf-runner/src/mock/mod.rs index d1bbc262f..9ca38533f 100644 --- a/crates/sovereign-sdk/full-node/sov-stf-runner/src/mock/mod.rs +++ b/crates/sovereign-sdk/full-node/sov-stf-runner/src/mock/mod.rs @@ -1,4 +1,5 @@ use sov_modules_api::default_context::DefaultContext; +use sov_modules_api::fork::Fork; use sov_modules_api::transaction::Transaction; use sov_rollup_interface::da::DaSpec; use sov_rollup_interface::spec::SpecId; @@ -61,6 +62,7 @@ impl StateTransitionFunction for MockStf { Vec>, >, _preproven_commitment_indicies: Vec, + _forks: &[Fork], ) -> ApplySequencerCommitmentsOutput { todo!() } diff --git a/crates/sovereign-sdk/full-node/sov-stf-runner/src/prover_service/mod.rs b/crates/sovereign-sdk/full-node/sov-stf-runner/src/prover_service/mod.rs index 6ff15c577..90749b66b 100644 --- a/crates/sovereign-sdk/full-node/sov-stf-runner/src/prover_service/mod.rs +++ b/crates/sovereign-sdk/full-node/sov-stf-runner/src/prover_service/mod.rs @@ -10,8 +10,6 @@ use thiserror::Error; pub enum ProverGuestRunConfig { /// Skip proving. Skip, - /// Run the rollup verification logic inside the current process. - Simulate, /// Run the rollup verifier in a zkVM executor. Execute, /// Run the rollup verifier and create a SNARK of execution. @@ -28,7 +26,6 @@ impl<'de> Deserialize<'de> for ProverGuestRunConfig { let s = ::deserialize(deserializer)?; match s.as_str() { "skip" => Ok(ProverGuestRunConfig::Skip), - "simulate" => Ok(ProverGuestRunConfig::Simulate), "execute" => Ok(ProverGuestRunConfig::Execute), "prove" => Ok(ProverGuestRunConfig::Prove), "prove-with-fakes" => Ok(ProverGuestRunConfig::ProveWithFakeProofs), diff --git a/crates/sovereign-sdk/module-system/sov-modules-rollup-blueprint/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-rollup-blueprint/src/lib.rs index b916d710f..e1757e7a7 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-rollup-blueprint/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-rollup-blueprint/src/lib.rs @@ -7,7 +7,6 @@ use std::sync::Arc; use async_trait::async_trait; use citrea_common::tasks::manager::TaskManager; use citrea_common::FullNodeConfig; -use derive_more::Display; use sov_db::ledger_db::LedgerDB; use sov_db::rocks_db_config::RocksdbConfig; use sov_modules_api::{Context, DaSpec, Spec}; @@ -17,6 +16,7 @@ use sov_rollup_interface::da::DaVerifier; use sov_rollup_interface::services::da::DaService; use sov_rollup_interface::spec::SpecId; use sov_rollup_interface::zk::{Zkvm, ZkvmHost}; +use sov_rollup_interface::Network; use sov_stf_runner::{ProverGuestRunConfig, ProverService}; use tokio::sync::broadcast; @@ -24,20 +24,6 @@ mod runtime_rpc; pub use runtime_rpc::*; -/// The network currently running. -#[derive(Copy, Clone, Default, Debug, Display)] -pub enum Network { - /// Mainnet - #[default] - Mainnet, - /// Testnet - Testnet, - /// Testnet - Devnet, - /// nightly - Nightly, -} - /// This trait defines how to crate all the necessary dependencies required by a rollup. #[async_trait] pub trait RollupBlueprint: Sized + Send + Sync { @@ -139,7 +125,6 @@ pub trait RollupBlueprint: Sized + Send + Sync { &self, proving_mode: ProverGuestRunConfig, da_service: &Arc, - da_verifier: Self::DaVerifier, ledger_db: LedgerDB, proof_sampling_number: usize, ) -> Self::ProverService; diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/Cargo.toml b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/Cargo.toml index bcb643b16..cb251b7a6 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/Cargo.toml +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/Cargo.toml @@ -23,7 +23,6 @@ serde = { workspace = true, features = ["derive"] } tracing = { workspace = true, optional = true } # Sovereign-SDK deps -citrea-primitives = { path = "../../../primitives", default-features = false } sov-modules-api = { path = "../sov-modules-api", default-features = false } sov-rollup-interface = { path = "../../rollup-interface" } sov-state = { path = "../sov-state" } diff --git a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs index 9651e15fa..e1732b06b 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-stf-blueprint/src/lib.rs @@ -2,11 +2,11 @@ #![doc = include_str!("../README.md")] use borsh::BorshDeserialize; -use citrea_primitives::forks::FORKS; use itertools::Itertools; use rs_merkle::algorithms::Sha256; use rs_merkle::MerkleTree; use sov_modules_api::da::BlockHeaderTrait; +use sov_modules_api::fork::Fork; use sov_modules_api::hooks::{ ApplySoftConfirmationHooks, FinalizeHook, HookSoftConfirmationInfo, SlotHooks, TxHooks, }; @@ -438,6 +438,7 @@ where Vec>, >, preproven_commitment_indices: Vec, + forks: &[Fork], ) -> ApplySequencerCommitmentsOutput { let mut state_diff = CumulativeStateDiff::default(); @@ -508,7 +509,7 @@ where let mut previous_batch_hash = soft_confirmations[0][0].prev_hash(); let mut last_commitment_end_height: Option = None; - let mut fork_manager = ForkManager::new(FORKS, sequencer_commitments_range.0 as u64); + let mut fork_manager = ForkManager::new(forks, sequencer_commitments_range.0 as u64); // should panic if number of sequencer commitments, soft confirmations, slot headers and witnesses don't match for (((sequencer_commitment, soft_confirmations), da_block_headers), witnesses) in diff --git a/crates/sovereign-sdk/rollup-interface/Makefile b/crates/sovereign-sdk/rollup-interface/Makefile index 5411c1dc3..54948d530 100644 --- a/crates/sovereign-sdk/rollup-interface/Makefile +++ b/crates/sovereign-sdk/rollup-interface/Makefile @@ -6,5 +6,5 @@ help: ## Display this help message check-no-std: ## Checks that project compiles without std # check bare metal cargo hack check --feature-powerset \ - --exclude-features default,fuzzing,std,native,testing,arbitrary \ + --exclude-features default,std,native,testing,arbitrary \ --target thumbv6m-none-eabi diff --git a/crates/sovereign-sdk/rollup-interface/src/fork/manager.rs b/crates/sovereign-sdk/rollup-interface/src/fork/manager.rs index 505645d7e..d6f34601b 100644 --- a/crates/sovereign-sdk/rollup-interface/src/fork/manager.rs +++ b/crates/sovereign-sdk/rollup-interface/src/fork/manager.rs @@ -2,23 +2,20 @@ use alloc::boxed::Box; use alloc::vec; use alloc::vec::Vec; -use super::{Fork, ForkMigration}; +use super::{fork_pos_from_block_number, verify_forks, Fork, ForkMigration}; -pub struct ForkManager { - forks: &'static [Fork], +pub struct ForkManager<'a> { + forks: &'a [Fork], active_fork_idx: usize, migration_handlers: Vec>, } -impl ForkManager { - pub fn new(forks: &'static [Fork], current_l2_height: u64) -> Self { - // FORKS from citrea-primitives are checked at compile time to be sorted. +impl<'a> ForkManager<'a> { + /// Creates new `ForkManager`. Forks are expected to be in ascending order, if not, panics in debug mode. + pub fn new(forks: &'a [Fork], current_l2_height: u64) -> Self { + debug_assert!(verify_forks(forks), "Forks must be ordered correctly"); - let pos = forks.binary_search_by(|fork| fork.activation_height.cmp(¤t_l2_height)); - let active_fork_idx = match pos { - Ok(idx) => idx, - Err(idx) => idx.saturating_sub(1), - }; + let active_fork_idx = fork_pos_from_block_number(forks, current_l2_height); Self { forks, @@ -63,9 +60,3 @@ impl ForkManager { Ok(()) } } - -/// Simple search for the fork to which a specific block number blongs. -/// This assumes that the list of forks is sorted by block number in ascending fashion. -pub fn fork_from_block_number(forks: &'static [Fork], block_number: u64) -> Fork { - ForkManager::new(forks, block_number).active_fork() -} diff --git a/crates/sovereign-sdk/rollup-interface/src/fork/mod.rs b/crates/sovereign-sdk/rollup-interface/src/fork/mod.rs index bd00b1e87..c7e03fb9b 100644 --- a/crates/sovereign-sdk/rollup-interface/src/fork/mod.rs +++ b/crates/sovereign-sdk/rollup-interface/src/fork/mod.rs @@ -19,6 +19,21 @@ pub struct Fork { pub activation_height: u64, } +impl PartialEq for Fork { + fn eq(&self, other: &Self) -> bool { + self.spec_id == other.spec_id && self.activation_height == other.activation_height + } +} + +impl Default for Fork { + fn default() -> Self { + Self { + spec_id: SpecId::Genesis, + activation_height: 0, + } + } +} + impl Fork { /// Creates new Fork instance pub const fn new(spec_id: SpecId, activation_height: u64) -> Self { @@ -28,3 +43,39 @@ impl Fork { } } } + +/// Verifies the order of forks. +pub const fn verify_forks(forks: &[Fork]) -> bool { + let mut i = 0; + while i < forks.len() { + let fork = forks[i]; + if i == 0 { + // Ensure that the first fork starts from height 0 + if fork.activation_height != 0 { + return false; + } + } else { + // Validate spec_id increase by 1, and activation height is strictly greater than the previous fork + if (fork.spec_id as u8).wrapping_sub(forks[i - 1].spec_id as u8) != 1 + || fork.activation_height <= forks[i - 1].activation_height + { + return false; + } + } + + i += 1; + } + + true +} + +/// Simple search for the fork to which a specific block number belongs. +/// This assumes that the list of forks is sorted by block number in ascending fashion. +pub fn fork_pos_from_block_number(forks: &[Fork], block_number: u64) -> usize { + let pos = forks.binary_search_by(|fork| fork.activation_height.cmp(&block_number)); + + match pos { + Ok(idx) => idx, + Err(idx) => idx.saturating_sub(1), + } +} diff --git a/crates/sovereign-sdk/rollup-interface/src/fork/tests.rs b/crates/sovereign-sdk/rollup-interface/src/fork/tests.rs index 3bb5da400..1b2b687f2 100644 --- a/crates/sovereign-sdk/rollup-interface/src/fork/tests.rs +++ b/crates/sovereign-sdk/rollup-interface/src/fork/tests.rs @@ -1,21 +1,21 @@ use anyhow::anyhow; use super::ForkManager; -use crate::fork::{fork_from_block_number, Fork, ForkMigration}; +use crate::fork::{fork_pos_from_block_number, Fork, ForkMigration}; use crate::spec::SpecId; #[test] -fn test_fork_from_block_number() { +fn test_fork_pos_from_block_number() { static T_FORKS: &[Fork] = &[ Fork::new(SpecId::Genesis, 0), Fork::new(SpecId::Fork1, 100), Fork::new(SpecId::Fork2, 500), ]; - assert_eq!(fork_from_block_number(T_FORKS, 5).spec_id, SpecId::Genesis); - assert_eq!(fork_from_block_number(T_FORKS, 105).spec_id, SpecId::Fork1); - assert_eq!(fork_from_block_number(T_FORKS, 350).spec_id, SpecId::Fork1); - assert_eq!(fork_from_block_number(T_FORKS, 505).spec_id, SpecId::Fork2); + assert_eq!(fork_pos_from_block_number(T_FORKS, 5), 0); + assert_eq!(fork_pos_from_block_number(T_FORKS, 105), 1); + assert_eq!(fork_pos_from_block_number(T_FORKS, 350), 1); + assert_eq!(fork_pos_from_block_number(T_FORKS, 505), 2); } #[test] diff --git a/crates/sovereign-sdk/rollup-interface/src/lib.rs b/crates/sovereign-sdk/rollup-interface/src/lib.rs index b5fde562f..2d5e35369 100644 --- a/crates/sovereign-sdk/rollup-interface/src/lib.rs +++ b/crates/sovereign-sdk/rollup-interface/src/lib.rs @@ -17,6 +17,9 @@ pub const CITREA_VERSION: &str = "v0.5.5"; mod state_machine; pub use state_machine::*; +mod network; +pub use network::*; + mod node; #[cfg(not(target_has_atomic = "ptr"))] diff --git a/crates/sovereign-sdk/rollup-interface/src/network.rs b/crates/sovereign-sdk/rollup-interface/src/network.rs new file mode 100644 index 000000000..c66c77dc4 --- /dev/null +++ b/crates/sovereign-sdk/rollup-interface/src/network.rs @@ -0,0 +1,34 @@ +use core::fmt::Display; + +/// The network currently running. +#[derive(Copy, Clone, Default, Debug)] +pub enum Network { + /// Mainnet + #[default] + Mainnet, + /// Testnet + Testnet, + /// Devnet + Devnet, + /// Nightly + Nightly, +} + +impl Display for Network { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "{:?}", self) + } +} + +impl Network { + /// Constant function to get the Network from &str + pub const fn const_from_str(s: &str) -> Option { + match s.as_bytes() { + b"mainnet" => Some(Network::Mainnet), + b"testnet" => Some(Network::Testnet), + b"devnet" => Some(Network::Devnet), + b"nightly" => Some(Network::Nightly), + _ => None, + } + } +} diff --git a/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs b/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs index 64f15740e..b885e9f82 100644 --- a/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs +++ b/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs @@ -165,9 +165,6 @@ pub struct LightClientProofOutputRpcResponse { pub unchained_batch_proofs_info: Vec, /// Last l2 height the light client proof verifies pub last_l2_height: u64, - /// Genesis state root of Citrea - #[serde(with = "hex::serde")] - pub l2_genesis_state_root: [u8; 32], } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/crates/sovereign-sdk/rollup-interface/src/spec.rs b/crates/sovereign-sdk/rollup-interface/src/spec.rs index abce77fe7..bf303ed88 100644 --- a/crates/sovereign-sdk/rollup-interface/src/spec.rs +++ b/crates/sovereign-sdk/rollup-interface/src/spec.rs @@ -3,67 +3,52 @@ use core::hash::Hash; use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; -pub use spec::*; -#[cfg(not(feature = "testing"))] -mod spec { - use super::*; - /// Fork specification - #[derive( - Debug, - Clone, - Copy, - Eq, - PartialEq, - PartialOrd, - Default, - BorshDeserialize, - BorshSerialize, - Serialize, - Deserialize, - Hash, - )] - #[borsh(use_discriminant = true)] - pub enum SpecId { - /// Genesis spec - #[default] - Genesis = 0, - /// First fork activates: - /// 1. the light client proof - /// 2. EVM cancun upgrade (with no kzg precompile) - /// 3. Don't use borsh when signing SoftConfirmation's - Fork1 = 1, - } +/// Currently available Citrea fork specs. +#[derive( + Debug, + Clone, + Copy, + Eq, + PartialEq, + PartialOrd, + Default, + BorshDeserialize, + BorshSerialize, + Serialize, + Deserialize, + Hash, +)] +#[borsh(use_discriminant = true)] +pub enum SpecId { + /// Genesis spec + #[default] + Genesis = 0, + /// First fork activates: + /// 1. the light client proof + /// 2. EVM cancun upgrade (with no kzg precompile) + /// 3. Don't use borsh when signing SoftConfirmation's + Fork1 = 1, + /// Fork2 spec + #[cfg(feature = "testing")] + Fork2 = 2, + /// Fork3 spec + #[cfg(feature = "testing")] + Fork3 = 3, } -#[cfg(feature = "testing")] -mod spec { - use super::*; - /// Fork specification - #[derive( - Debug, - Clone, - Copy, - Eq, - PartialEq, - PartialOrd, - Default, - BorshDeserialize, - BorshSerialize, - Serialize, - Deserialize, - Hash, - )] - #[borsh(use_discriminant = true)] - pub enum SpecId { - /// Genesis spec - #[default] - Genesis = 0, - /// First fork - Fork1 = 1, - /// Second fork - Fork2 = 2, - /// Third fork - Fork3 = 3, +impl SpecId { + /// Const fn to convert u8 to corresponding SpecId. Valid values are + /// 0, 1, 2 and 3. + pub const fn from_u8(n: u8) -> Option { + match n { + 0 => Some(SpecId::Genesis), + 1 => Some(SpecId::Fork1), + #[cfg(feature = "testing")] + 2 => Some(SpecId::Fork2), + #[cfg(feature = "testing")] + 3 => Some(SpecId::Fork3), + _ => None, + } } } diff --git a/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs b/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs index 04543ac02..3c0806b0d 100644 --- a/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs +++ b/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs @@ -16,6 +16,7 @@ use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use crate::da::DaSpec; +use crate::fork::Fork; use crate::soft_confirmation::SignedSoftConfirmation; use crate::spec::SpecId; use crate::zk::CumulativeStateDiff; @@ -229,6 +230,7 @@ pub trait StateTransitionFunction { slot_headers: VecDeque>, soft_confirmations: VecDeque>>, preproven_commitment_indicies: Vec, + forks: &[Fork], ) -> ApplySequencerCommitmentsOutput; } diff --git a/crates/sovereign-sdk/rollup-interface/src/state_machine/zk/mod.rs b/crates/sovereign-sdk/rollup-interface/src/state_machine/zk/mod.rs index a39c71619..90502ccab 100644 --- a/crates/sovereign-sdk/rollup-interface/src/state_machine/zk/mod.rs +++ b/crates/sovereign-sdk/rollup-interface/src/state_machine/zk/mod.rs @@ -173,8 +173,10 @@ pub struct BatchProofCircuitInput<'txs, StateRoot, Witness, Da: DaSpec, Tx: Clon /// DA block headers the soft confirmations was constructed on. pub da_block_headers_of_soft_confirmations: VecDeque>, /// Sequencer soft confirmation public key. + /// **DO NOT USE THIS FIELD IN POST FORK1 GUEST** pub sequencer_public_key: Vec, /// Sequencer DA public_key: Vec, + /// **DO NOT USE THIS FIELD IN POST FORK1 GUEST** pub sequencer_da_public_key: Vec, /// The range of sequencer commitments that are being processed. /// The range is inclusive. @@ -234,8 +236,6 @@ pub struct LightClientCircuitOutput { pub unchained_batch_proofs_info: Vec, /// Last l2 height the light client proof verifies pub last_l2_height: u64, - /// Genesis state root of Citrea - pub l2_genesis_state_root: [u8; 32], } /// The input of light client proof @@ -250,15 +250,9 @@ pub struct LightClientCircuitInput { /// DA block header that the batch proofs were found in. pub da_block_header: Da::BlockHeader, - /// Public key of the batch prover - pub batch_prover_da_pub_key: Vec, - /// Batch proof method id - pub batch_proof_method_id: [u32; 8], /// Light client proof method id pub light_client_proof_method_id: [u32; 8], /// Light client proof output /// Optional because the first light client proof doesn't have a previous proof pub previous_light_client_proof_journal: Option>, - /// L2 Genesis state root - pub l2_genesis_state_root: Option<[u8; 32]>, } diff --git a/crates/sp1/src/guest.rs b/crates/sp1/src/guest.rs index 235cb5ee6..20fd5a9e8 100644 --- a/crates/sp1/src/guest.rs +++ b/crates/sp1/src/guest.rs @@ -19,7 +19,7 @@ impl Zkvm for SP1Guest { #[cfg(feature = "native")] type CodeCommitment = crate::host::VerifyingKey; #[cfg(not(feature = "native"))] - type CodeCommitment = (); + type CodeCommitment = [u32; 8]; type Error = anyhow::Error; @@ -36,6 +36,10 @@ impl Zkvm for SP1Guest { ) -> Result { unimplemented!() } + + fn extract_raw_output(_serialized_proof: &[u8]) -> Result, Self::Error> { + unimplemented!() + } } impl ZkvmGuest for SP1Guest { diff --git a/guests/risc0/Dockerfile b/guests/risc0/Dockerfile index a41e3b3ad..e6714df53 100644 --- a/guests/risc0/Dockerfile +++ b/guests/risc0/Dockerfile @@ -2,16 +2,16 @@ FROM risczero/risc0-guest-builder:r0.1.81.0 AS build WORKDIR /src ARG GUEST_NAME -ARG EXAMPLE_ARG="some-default-value" +ARG CITREA_NETWORK COPY . . -ENV CARGO_MANIFEST_PATH="guests/risc0/${GUEST_NAME}/Cargo.toml" +ENV CARGO_MANIFEST_PATH="guests/risc0/${GUEST_NAME}/bitcoin/Cargo.toml" ENV RUSTFLAGS="-C passes=loweratomic -C link-arg=-Ttext=0x00200800 -C link-arg=--fatal-warnings" ENV CARGO_TARGET_DIR="target" ENV CC_riscv32im_risc0_zkvm_elf="/root/.local/share/cargo-risczero/cpp/bin/riscv32-unknown-elf-gcc" ENV CFLAGS_riscv32im_risc0_zkvm_elf="-march=rv32im -nostdlib" -ENV EXAMPLE_ENV=${EXAMPLE_ARG} +ENV CITREA_NETWORK=${CITREA_NETWORK} RUN cargo +risc0 fetch --locked --target riscv32im-risc0-zkvm-elf --manifest-path ${CARGO_MANIFEST_PATH} RUN cargo +risc0 build --release --locked --target riscv32im-risc0-zkvm-elf --manifest-path ${CARGO_MANIFEST_PATH} @@ -21,4 +21,4 @@ FROM scratch AS export ARG GUEST_NAME -COPY --from=build /src/target/riscv32im-risc0-zkvm-elf/release /${GUEST_NAME} +COPY --from=build /src/target/riscv32im-risc0-zkvm-elf/release "/${GUEST_NAME}-bitcoin" diff --git a/guests/risc0/Makefile b/guests/risc0/Makefile index 0f0127d85..ecf8dd769 100644 --- a/guests/risc0/Makefile +++ b/guests/risc0/Makefile @@ -1,18 +1,5 @@ OUT_PATH := resources/guests/risc0/ -.PHONY: all -all: batch-proof-bitcoin light-client-bitcoin - -.PHONY: batch-proof-bitcoin -batch-proof-bitcoin: - cd ../../ && \ - cargo risczero build --manifest-path guests/risc0/batch-proof-bitcoin/Cargo.toml - -.PHONY: light-client-bitcoin -light-client-bitcoin: - cd ../../ && \ - cargo risczero build --manifest-path guests/risc0/light-client-proof-bitcoin/Cargo.toml - .PHONY: batch-proof-bitcoin-docker batch-proof-bitcoin-docker: cd ../../ && \ @@ -20,8 +7,8 @@ batch-proof-bitcoin-docker: --platform linux/amd64 \ --output ./target/riscv-guest/riscv32im-risc0-zkvm-elf/docker \ -f ./guests/risc0/Dockerfile \ - --build-arg GUEST_NAME=batch-proof-bitcoin \ - --build-arg EXAMPLE_ARG=some-value \ + --build-arg GUEST_NAME=batch-proof \ + --build-arg CITREA_NETWORK=$(CITREA_NETWORK) \ -t batch-proof-bitcoin:latest \ --no-cache \ . && \ @@ -34,8 +21,8 @@ light-client-bitcoin-docker: --platform linux/amd64 \ --output ./target/riscv-guest/riscv32im-risc0-zkvm-elf/docker \ -f ./guests/risc0/Dockerfile \ - --build-arg GUEST_NAME=light-client-proof-bitcoin \ - --build-arg EXAMPLE_ARG=some-value \ + --build-arg GUEST_NAME=light-client-proof \ + --build-arg CITREA_NETWORK=$(CITREA_NETWORK) \ -t light-client-proof-bitcoin:latest \ --no-cache \ . && \ diff --git a/guests/risc0/batch-proof-bitcoin/src/bin/batch_proof_bitcoin.rs b/guests/risc0/batch-proof-bitcoin/src/bin/batch_proof_bitcoin.rs deleted file mode 100644 index ca6452321..000000000 --- a/guests/risc0/batch-proof-bitcoin/src/bin/batch_proof_bitcoin.rs +++ /dev/null @@ -1,32 +0,0 @@ -#![no_main] -use bitcoin_da::spec::RollupParams; -use bitcoin_da::verifier::BitcoinVerifier; -use citrea_primitives::{TO_BATCH_PROOF_PREFIX, TO_LIGHT_CLIENT_PREFIX}; -use citrea_risc0_adapter::guest::Risc0Guest; -use citrea_stf::runtime::Runtime; -use citrea_stf::StfVerifier; -use sov_modules_api::default_context::ZkDefaultContext; -use sov_modules_stf_blueprint::StfBlueprint; -use sov_rollup_interface::da::DaVerifier; -use sov_state::ZkStorage; - -risc0_zkvm::guest::entry!(main); - -pub fn main() { - let guest = Risc0Guest::new(); - let storage = ZkStorage::new(); - - let stf: StfBlueprint> = StfBlueprint::new(); - - let mut stf_verifier = StfVerifier::new( - stf, - BitcoinVerifier::new(RollupParams { - to_batch_proof_prefix: TO_BATCH_PROOF_PREFIX.to_vec(), - to_light_client_prefix: TO_LIGHT_CLIENT_PREFIX.to_vec(), - }), - ); - - stf_verifier - .run_sequencer_commitments_in_da_slot(guest, storage) - .expect("Prover must be honest"); -} diff --git a/guests/risc0/batch-proof-mock/src/bin/batch_proof_mock.rs b/guests/risc0/batch-proof-mock/src/bin/batch_proof_mock.rs deleted file mode 100644 index 0347a1fda..000000000 --- a/guests/risc0/batch-proof-mock/src/bin/batch_proof_mock.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![no_main] -use citrea_stf::runtime::Runtime; -use citrea_stf::StfVerifier; -use sov_mock_da::MockDaVerifier; -use sov_modules_api::default_context::ZkDefaultContext; -use sov_modules_stf_blueprint::StfBlueprint; -use citrea_risc0_adapter::guest::Risc0Guest; -use sov_state::ZkStorage; - -risc0_zkvm::guest::entry!(main); - -pub fn main() { - let guest = Risc0Guest::new(); - let storage = ZkStorage::new(); - - let stf: StfBlueprint> = StfBlueprint::new(); - - let mut stf_verifier = StfVerifier::new(stf, MockDaVerifier {}); - - stf_verifier - .run_sequencer_commitments_in_da_slot(guest, storage) - .expect("Prover must be honest"); -} diff --git a/guests/risc0/Cargo.toml b/guests/risc0/batch-proof/Cargo.toml similarity index 66% rename from guests/risc0/Cargo.toml rename to guests/risc0/batch-proof/Cargo.toml index fbc6c312d..dbc912bae 100644 --- a/guests/risc0/Cargo.toml +++ b/guests/risc0/batch-proof/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "risc0" +name = "citrea-risc0-batch-proof" version = "0.5.0-rc.1" edition = "2021" license = "MIT OR Apache-2.0" @@ -11,10 +11,8 @@ risc0-build = { workspace = true } [package.metadata.risc0] methods = [ - "batch-proof-bitcoin", - "batch-proof-mock", - "light-client-proof-bitcoin", - "light-client-proof-mock", + "bitcoin", + "mock", ] [features] diff --git a/guests/risc0/batch-proof-bitcoin/Cargo.lock b/guests/risc0/batch-proof/bitcoin/Cargo.lock similarity index 99% rename from guests/risc0/batch-proof-bitcoin/Cargo.lock rename to guests/risc0/batch-proof/bitcoin/Cargo.lock index fce7a3dd3..8292dd597 100644 --- a/guests/risc0/batch-proof-bitcoin/Cargo.lock +++ b/guests/risc0/batch-proof/bitcoin/Cargo.lock @@ -638,6 +638,7 @@ dependencies = [ "citrea-primitives", "citrea-risc0-adapter", "citrea-stf", + "const-hex", "risc0-zkvm", "risc0-zkvm-platform", "sov-modules-api", @@ -3290,7 +3291,6 @@ version = "0.5.0-rc.1" dependencies = [ "anyhow", "borsh", - "citrea-primitives", "hex", "itertools 0.13.0", "jmt", diff --git a/guests/risc0/batch-proof-bitcoin/Cargo.toml b/guests/risc0/batch-proof/bitcoin/Cargo.toml similarity index 57% rename from guests/risc0/batch-proof-bitcoin/Cargo.toml rename to guests/risc0/batch-proof/bitcoin/Cargo.toml index 3e26e273b..e93a0f0fc 100644 --- a/guests/risc0/batch-proof-bitcoin/Cargo.toml +++ b/guests/risc0/batch-proof/bitcoin/Cargo.toml @@ -11,14 +11,15 @@ risc0-zkvm = { version = "1.1.3", default-features = false } risc0-zkvm-platform = { version = "1.1.3" } anyhow = "1.0.68" -bitcoin-da = { path = "../../../crates/bitcoin-da", default-features = false } -citrea-primitives = { path = "../../../crates/primitives" } -citrea-risc0-adapter = { path = "../../../crates/risc0" } -citrea-stf = { path = "../../../crates/citrea-stf" } -sov-modules-api = { path = "../../../crates/sovereign-sdk/module-system/sov-modules-api", default-features = false } -sov-modules-stf-blueprint = { path = "../../../crates/sovereign-sdk/module-system/sov-modules-stf-blueprint" } -sov-rollup-interface = { path = "../../../crates/sovereign-sdk/rollup-interface" } -sov-state = { path = "../../../crates/sovereign-sdk/module-system/sov-state" } +bitcoin-da = { path = "../../../../crates/bitcoin-da", default-features = false } +citrea-primitives = { path = "../../../../crates/primitives" } +citrea-risc0-adapter = { path = "../../../../crates/risc0" } +citrea-stf = { path = "../../../../crates/citrea-stf" } +const-hex = "1.12" +sov-modules-api = { path = "../../../../crates/sovereign-sdk/module-system/sov-modules-api", default-features = false } +sov-modules-stf-blueprint = { path = "../../../../crates/sovereign-sdk/module-system/sov-modules-stf-blueprint" } +sov-rollup-interface = { path = "../../../../crates/sovereign-sdk/rollup-interface" } +sov-state = { path = "../../../../crates/sovereign-sdk/module-system/sov-state" } [features] testing = ["citrea-primitives/testing"] diff --git a/guests/risc0/batch-proof/bitcoin/src/bin/batch_proof_bitcoin.rs b/guests/risc0/batch-proof/bitcoin/src/bin/batch_proof_bitcoin.rs new file mode 100644 index 000000000..271e4290f --- /dev/null +++ b/guests/risc0/batch-proof/bitcoin/src/bin/batch_proof_bitcoin.rs @@ -0,0 +1,94 @@ +#![no_main] +use bitcoin_da::spec::RollupParams; +use bitcoin_da::verifier::BitcoinVerifier; +use citrea_primitives::forks::{DEVNET_FORKS, MAINNET_FORKS, NIGHTLY_FORKS, TESTNET_FORKS}; +use citrea_primitives::{TO_BATCH_PROOF_PREFIX, TO_LIGHT_CLIENT_PREFIX}; +use citrea_risc0_adapter::guest::Risc0Guest; +use citrea_stf::runtime::Runtime; +use citrea_stf::StfVerifier; +use sov_modules_api::default_context::ZkDefaultContext; +use sov_modules_api::fork::Fork; +use sov_modules_stf_blueprint::StfBlueprint; +use sov_rollup_interface::da::DaVerifier; +use sov_rollup_interface::zk::ZkvmGuest; +use sov_rollup_interface::Network; +use sov_state::ZkStorage; + +risc0_zkvm::guest::entry!(main); + +const NETWORK: Network = match option_env!("CITREA_NETWORK") { + Some(network) => { + match Network::const_from_str(network) { + Some(network) => network, + None => panic!("Invalid CITREA_NETWORK value"), + } + } + None => Network::Nightly, +}; + +const SEQUENCER_PUBLIC_KEY: [u8; 32] = { + let hex_pub_key = match NETWORK { + Network::Mainnet => "0000000000000000000000000000000000000000000000000000000000000000", + Network::Testnet => "4682a70af1d3fae53a5a26b682e2e75f7a1de21ad5fc8d61794ca889880d39d1", + Network::Devnet => "52f41a5076498d1ae8bdfa57d19e91e3c2c94b6de21985d099cd48cfa7aef174", + Network::Nightly => { + match option_env!("SEQUENCER_PUBLIC_KEY") { + Some(hex_pub_key) => hex_pub_key, + None => "204040e364c10f2bec9c1fe500a1cd4c247c89d650a01ed7e82caba867877c21", + } + } + }; + + match const_hex::const_decode_to_array(hex_pub_key.as_bytes()) { + Ok(pub_key) => pub_key, + Err(_) => panic!("SEQUENCER_PUBLIC_KEY must be valid 32-byte hex string"), + } +}; + +const SEQUENCER_DA_PUBLIC_KEY: [u8; 33] = { + let hex_pub_key = match NETWORK { + Network::Mainnet => "030000000000000000000000000000000000000000000000000000000000000000", + Network::Testnet => "03015a7c4d2cc1c771198686e2ebef6fe7004f4136d61f6225b061d1bb9b821b9b", + Network::Devnet => "039cd55f9b3dcf306c4d54f66cd7c4b27cc788632cd6fb73d80c99d303c6536486", + Network::Nightly => { + match option_env!("SEQUENCER_DA_PUB_KEY") { + Some(hex_pub_key) => hex_pub_key, + None => "02588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9", + } + } + }; + + match const_hex::const_decode_to_array(hex_pub_key.as_bytes()) { + Ok(pub_key) => pub_key, + Err(_) => panic!("SEQUENCER_DA_PUB_KEY must be valid 33-byte hex string"), + } +}; + +const FORKS: &[Fork] = match NETWORK { + Network::Mainnet => &MAINNET_FORKS, + Network::Testnet => &TESTNET_FORKS, + Network::Devnet => &DEVNET_FORKS, + Network::Nightly => &NIGHTLY_FORKS, +}; + +pub fn main() { + let guest = Risc0Guest::new(); + let storage = ZkStorage::new(); + let stf = StfBlueprint::new(); + + let mut stf_verifier: StfVerifier<_, ZkDefaultContext, Runtime<_, _>> = StfVerifier::new( + stf, + BitcoinVerifier::new(RollupParams { + to_batch_proof_prefix: TO_BATCH_PROOF_PREFIX.to_vec(), + to_light_client_prefix: TO_LIGHT_CLIENT_PREFIX.to_vec(), + }), + ); + + let data = guest.read_from_host(); + + let out = stf_verifier + .run_sequencer_commitments_in_da_slot(data, storage, &SEQUENCER_PUBLIC_KEY, &SEQUENCER_DA_PUBLIC_KEY, FORKS) + .expect("Prover must be honest"); + + guest.commit(&out); +} diff --git a/guests/risc0/batch-proof/build.rs b/guests/risc0/batch-proof/build.rs new file mode 100644 index 000000000..8fac0a5bb --- /dev/null +++ b/guests/risc0/batch-proof/build.rs @@ -0,0 +1,80 @@ +use std::collections::HashMap; + +use risc0_build::{embed_methods_with_options, DockerOptions, GuestOptions}; + +fn main() { + // Build environment variables + println!("cargo:rerun-if-env-changed=SKIP_GUEST_BUILD"); + println!("cargo:rerun-if-env-changed=REPR_GUEST_BUILD"); + println!("cargo:rerun-if-env-changed=OUT_DIR"); + // Compile time constant environment variables + println!("cargo:rerun-if-env-changed=CITREA_NETWORK"); + println!("cargo:rerun-if-env-changed=SEQUENCER_PUBLIC_KEY"); + println!("cargo:rerun-if-env-changed=SEQUENCER_DA_PUB_KEY"); + + match std::env::var("SKIP_GUEST_BUILD") { + Ok(value) => match value.as_str() { + "1" | "true" => { + println!("cargo:warning=Skipping guest build"); + let out_dir = std::env::var_os("OUT_DIR").unwrap(); + let out_dir = std::path::Path::new(&out_dir); + let methods_path = out_dir.join("methods.rs"); + + let elf = r#" + pub const BATCH_PROOF_BITCOIN_ELF: &[u8] = &[]; + pub const BATCH_PROOF_BITCOIN_ID: [u32; 8] = [0u32; 8]; + pub const BATCH_PROOF_MOCK_ELF: &[u8] = &[]; + pub const BATCH_PROOF_MOCK_ID: [u32; 8] = [0u32; 8]; + "#; + + return std::fs::write(methods_path, elf).expect("Failed to write mock rollup elf"); + } + "0" | "false" => { + println!("cargo:warning=Performing guest build"); + } + _ => { + println!("cargo:warning=Invalid value for SKIP_GUEST_BUILD: '{}'. Expected '0', '1', 'true', or 'false'. Defaulting to performing guest build.", value); + } + }, + Err(std::env::VarError::NotPresent) => { + println!( + "cargo:warning=SKIP_GUEST_BUILD not set. Defaulting to performing guest build." + ); + } + Err(std::env::VarError::NotUnicode(_)) => { + println!("cargo:warning=SKIP_GUEST_BUILD contains invalid Unicode. Defaulting to performing guest build."); + } + } + let guest_pkg_to_options = get_guest_options(); + embed_methods_with_options(guest_pkg_to_options); +} + +fn get_guest_options() -> HashMap<&'static str, risc0_build::GuestOptions> { + let mut guest_pkg_to_options = HashMap::new(); + + let mut features = Vec::new(); + + if std::env::var("CARGO_FEATURE_TESTING").is_ok() { + features.push("testing".to_string()); + } + + let use_docker = if std::env::var("REPR_GUEST_BUILD").is_ok() { + let this_package_dir = std::env!("CARGO_MANIFEST_DIR"); + let root_dir = format!("{this_package_dir}/../../"); + Some(DockerOptions { + root_dir: Some(root_dir.into()), + }) + } else { + println!("cargo:warning=Guest code is not built in docker"); + None + }; + + let opts = GuestOptions { + features, + use_docker, + }; + + guest_pkg_to_options.insert("batch-proof-bitcoin", opts.clone()); + guest_pkg_to_options.insert("batch-proof-mock", opts.clone()); + guest_pkg_to_options +} diff --git a/guests/risc0/batch-proof-mock/Cargo.lock b/guests/risc0/batch-proof/mock/Cargo.lock similarity index 99% rename from guests/risc0/batch-proof-mock/Cargo.lock rename to guests/risc0/batch-proof/mock/Cargo.lock index 9484202c4..409151cc7 100644 --- a/guests/risc0/batch-proof-mock/Cargo.lock +++ b/guests/risc0/batch-proof/mock/Cargo.lock @@ -627,11 +627,13 @@ dependencies = [ "citrea-primitives", "citrea-risc0-adapter", "citrea-stf", + "const-hex", "risc0-zkvm", "risc0-zkvm-platform", "sov-mock-da", "sov-modules-api", "sov-modules-stf-blueprint", + "sov-rollup-interface", "sov-state", ] @@ -3092,7 +3094,6 @@ version = "0.5.0-rc.1" dependencies = [ "anyhow", "borsh", - "citrea-primitives", "hex", "itertools 0.13.0", "jmt", diff --git a/guests/risc0/batch-proof-mock/Cargo.toml b/guests/risc0/batch-proof/mock/Cargo.toml similarity index 56% rename from guests/risc0/batch-proof-mock/Cargo.toml rename to guests/risc0/batch-proof/mock/Cargo.toml index 0d2130df3..dfd623d16 100644 --- a/guests/risc0/batch-proof-mock/Cargo.toml +++ b/guests/risc0/batch-proof/mock/Cargo.toml @@ -11,13 +11,15 @@ risc0-zkvm = { version = "1.1.3", default-features = false } risc0-zkvm-platform = { version = "1.1.3" } anyhow = "1.0" -citrea-primitives = { path = "../../../crates/primitives" } -citrea-risc0-adapter = { path = "../../../crates/risc0" } -citrea-stf = { path = "../../../crates/citrea-stf" } -sov-mock-da = { path = "../../../crates/sovereign-sdk/adapters/mock-da", default-features = false } -sov-modules-api = { path = "../../../crates/sovereign-sdk/module-system/sov-modules-api", default-features = false } -sov-modules-stf-blueprint = { path = "../../../crates/sovereign-sdk/module-system/sov-modules-stf-blueprint" } -sov-state = { path = "../../../crates/sovereign-sdk/module-system/sov-state" } +citrea-primitives = { path = "../../../../crates/primitives" } +citrea-risc0-adapter = { path = "../../../../crates/risc0" } +citrea-stf = { path = "../../../../crates/citrea-stf" } +const-hex = "1.12" +sov-mock-da = { path = "../../../../crates/sovereign-sdk/adapters/mock-da", default-features = false } +sov-modules-api = { path = "../../../../crates/sovereign-sdk/module-system/sov-modules-api", default-features = false } +sov-modules-stf-blueprint = { path = "../../../../crates/sovereign-sdk/module-system/sov-modules-stf-blueprint" } +sov-rollup-interface = { path = "../../../../crates/sovereign-sdk/rollup-interface" } +sov-state = { path = "../../../../crates/sovereign-sdk/module-system/sov-state" } [features] testing = ["citrea-primitives/testing"] diff --git a/guests/risc0/batch-proof/mock/src/bin/batch_proof_mock.rs b/guests/risc0/batch-proof/mock/src/bin/batch_proof_mock.rs new file mode 100644 index 000000000..7e0609a51 --- /dev/null +++ b/guests/risc0/batch-proof/mock/src/bin/batch_proof_mock.rs @@ -0,0 +1,44 @@ +#![no_main] +use citrea_primitives::forks::NIGHTLY_FORKS; +use citrea_stf::runtime::Runtime; +use citrea_stf::StfVerifier; +use sov_mock_da::MockDaVerifier; +use sov_modules_api::default_context::ZkDefaultContext; +use sov_modules_api::fork::Fork; +use sov_modules_stf_blueprint::StfBlueprint; +use citrea_risc0_adapter::guest::Risc0Guest; +use sov_state::ZkStorage; +use sov_rollup_interface::zk::ZkvmGuest; + +risc0_zkvm::guest::entry!(main); + +const SEQUENCER_PUBLIC_KEY: [u8; 32] = match const_hex::const_decode_to_array(b"204040e364c10f2bec9c1fe500a1cd4c247c89d650a01ed7e82caba867877c21") { + Ok(pub_key) => pub_key, + Err(_) => panic!("Can't happen"), +}; + +const SEQUENCER_DA_PUBLIC_KEY: [u8; 33] = match const_hex::const_decode_to_array(b"02588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9") { + Ok(pub_key) => pub_key, + Err(_) => panic!("Can't happen"), +}; + +const FORKS: &[Fork] = &NIGHTLY_FORKS; + +pub fn main() { + let guest = Risc0Guest::new(); + let storage = ZkStorage::new(); + let stf = StfBlueprint::new(); + + let mut stf_verifier: StfVerifier<_, ZkDefaultContext, Runtime<_, _>> = StfVerifier::new( + stf, + MockDaVerifier {} + ); + + let data = guest.read_from_host(); + + let out = stf_verifier + .run_sequencer_commitments_in_da_slot(data, storage, &SEQUENCER_PUBLIC_KEY, &SEQUENCER_DA_PUBLIC_KEY, FORKS) + .expect("Prover must be honest"); + + guest.commit(&out); +} diff --git a/guests/risc0/src/lib.rs b/guests/risc0/batch-proof/src/lib.rs similarity index 100% rename from guests/risc0/src/lib.rs rename to guests/risc0/batch-proof/src/lib.rs diff --git a/guests/risc0/light-client-proof-bitcoin/Cargo.toml b/guests/risc0/light-client-proof-bitcoin/Cargo.toml deleted file mode 100644 index 742cfecdc..000000000 --- a/guests/risc0/light-client-proof-bitcoin/Cargo.toml +++ /dev/null @@ -1,37 +0,0 @@ -[package] -name = "light-client-proof-bitcoin" -version = "0.5.0-rc.1" -edition = "2021" -resolver = "2" - -[workspace] - -[dependencies] -risc0-zkvm = { version = "1.1.3", default-features = false } -risc0-zkvm-platform = { version = "1.1.3" } - -anyhow = "1.0.68" -bitcoin-da = { path = "../../../crates/bitcoin-da", default-features = false } -citrea-light-client-prover = { path = "../../../crates/light-client-prover", default-features = false } -citrea-primitives = { path = "../../../crates/primitives" } -citrea-risc0-adapter = { path = "../../../crates/risc0" } -sov-modules-api = { path = "../../../crates/sovereign-sdk/module-system/sov-modules-api", default-features = false } -sov-modules-stf-blueprint = { path = "../../../crates/sovereign-sdk/module-system/sov-modules-stf-blueprint" } -sov-rollup-interface = { path = "../../../crates/sovereign-sdk/rollup-interface" } -sov-state = { path = "../../../crates/sovereign-sdk/module-system/sov-state" } - -[features] -testing = ["citrea-primitives/testing"] - -[patch.crates-io] -sha2 = { git = "https://github.com/risc0/RustCrypto-hashes", tag = "sha2-v0.10.8-risczero.0" } -ed25519-dalek = { git = "https://github.com/risc0/curve25519-dalek", tag = "curve25519-4.1.2-risczero.0" } -crypto-bigint = { git = "https://github.com/risc0/RustCrypto-crypto-bigint", tag = "v0.5.5-risczero.0" } -secp256k1 = { git = "https://github.com/Sovereign-Labs/rust-secp256k1.git", branch = "risc0-compatible-0-29-0" } -k256 = { git = "https://github.com/risc0/RustCrypto-elliptic-curves", tag = "k256/v0.13.3-risczero.0" } - -[profile.release] -debug = 0 -lto = true -opt-level = 3 -codegen-units = 1 diff --git a/guests/risc0/light-client-proof-bitcoin/src/bin/light_client_proof_bitcoin.rs b/guests/risc0/light-client-proof-bitcoin/src/bin/light_client_proof_bitcoin.rs deleted file mode 100644 index 9bb7bdc9a..000000000 --- a/guests/risc0/light-client-proof-bitcoin/src/bin/light_client_proof_bitcoin.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![no_main] -use bitcoin_da::spec::RollupParams; -use bitcoin_da::verifier::BitcoinVerifier; -use citrea_light_client_prover::circuit::run_circuit; -use citrea_primitives::{TO_BATCH_PROOF_PREFIX, TO_LIGHT_CLIENT_PREFIX}; -use citrea_risc0_adapter::guest::Risc0Guest; -use sov_rollup_interface::da::DaVerifier; -use sov_rollup_interface::zk::ZkvmGuest; - -risc0_zkvm::guest::entry!(main); - -pub fn main() { - let guest = Risc0Guest::new(); - - let da_verifier = BitcoinVerifier::new(RollupParams { - to_batch_proof_prefix: TO_BATCH_PROOF_PREFIX.to_vec(), - to_light_client_prefix: TO_LIGHT_CLIENT_PREFIX.to_vec(), - }); - - let output = run_circuit::(da_verifier, &guest).unwrap(); - - guest.commit(&output); -} diff --git a/guests/risc0/light-client-proof-mock/Cargo.toml b/guests/risc0/light-client-proof-mock/Cargo.toml deleted file mode 100644 index ad87aab07..000000000 --- a/guests/risc0/light-client-proof-mock/Cargo.toml +++ /dev/null @@ -1,37 +0,0 @@ -[package] -name = "light-client-proof-mock" -version = "0.5.0-rc.1" -edition = "2021" -resolver = "2" - -[workspace] - -[dependencies] -risc0-zkvm = { version = "1.1.3", default-features = false } -risc0-zkvm-platform = { version = "1.1.3" } - -anyhow = "1.0.68" -sov-mock-da = { path = "../../../crates/sovereign-sdk/adapters/mock-da", default-features = false } - -citrea-light-client-prover = { path = "../../../crates/light-client-prover", default-features = false } -citrea-primitives = { path = "../../../crates/primitives" } -citrea-risc0-adapter = { path = "../../../crates/risc0" } -sov-modules-api = { path = "../../../crates/sovereign-sdk/module-system/sov-modules-api", default-features = false } -sov-modules-stf-blueprint = { path = "../../../crates/sovereign-sdk/module-system/sov-modules-stf-blueprint" } -sov-rollup-interface = { path = "../../../crates/sovereign-sdk/rollup-interface" } -sov-state = { path = "../../../crates/sovereign-sdk/module-system/sov-state" } - -[features] -testing = ["citrea-primitives/testing"] - -[patch.crates-io] -sha2 = { git = "https://github.com/risc0/RustCrypto-hashes", tag = "sha2-v0.10.8-risczero.0" } -ed25519-dalek = { git = "https://github.com/risc0/curve25519-dalek", tag = "curve25519-4.1.2-risczero.0" } -crypto-bigint = { git = "https://github.com/risc0/RustCrypto-crypto-bigint", tag = "v0.5.5-risczero.0" } -k256 = { git = "https://github.com/risc0/RustCrypto-elliptic-curves", tag = "k256/v0.13.3-risczero.0" } - -[profile.release] -debug = 0 -lto = true -opt-level = 3 -codegen-units = 1 diff --git a/guests/risc0/light-client-proof-mock/src/bin/light_client_proof_mock.rs b/guests/risc0/light-client-proof-mock/src/bin/light_client_proof_mock.rs deleted file mode 100644 index ab50e1947..000000000 --- a/guests/risc0/light-client-proof-mock/src/bin/light_client_proof_mock.rs +++ /dev/null @@ -1,17 +0,0 @@ -#![no_main] -use citrea_light_client_prover::circuit::run_circuit; -use citrea_risc0_adapter::guest::Risc0Guest; -use sov_mock_da::MockDaVerifier; -use sov_rollup_interface::zk::ZkvmGuest; - -risc0_zkvm::guest::entry!(main); - -pub fn main() { - let guest = Risc0Guest::new(); - - let da_verifier = MockDaVerifier {}; - - let output = run_circuit::(da_verifier, &guest).unwrap(); - - guest.commit(&output); -} diff --git a/guests/risc0/light-client-proof/Cargo.toml b/guests/risc0/light-client-proof/Cargo.toml new file mode 100644 index 000000000..ed168f461 --- /dev/null +++ b/guests/risc0/light-client-proof/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "citrea-risc0-light-client" +version = "0.5.0-rc.1" +edition = "2021" +license = "MIT OR Apache-2.0" +publish = false +resolver = "2" + +[build-dependencies] +risc0-build = { workspace = true } + +[package.metadata.risc0] +methods = [ + "bitcoin", + "mock", +] + +[features] +bench = [] +testing = [] diff --git a/guests/risc0/light-client-proof-mock/Cargo.lock b/guests/risc0/light-client-proof/bitcoin/Cargo.lock similarity index 74% rename from guests/risc0/light-client-proof-mock/Cargo.lock rename to guests/risc0/light-client-proof/bitcoin/Cargo.lock index 126c193d7..0f699a5ce 100644 --- a/guests/risc0/light-client-proof-mock/Cargo.lock +++ b/guests/risc0/light-client-proof/bitcoin/Cargo.lock @@ -309,6 +309,16 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "base58ck" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" +dependencies = [ + "bitcoin-internals", + "bitcoin_hashes", +] + [[package]] name = "base64" version = "0.21.7" @@ -331,6 +341,12 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + [[package]] name = "bincode" version = "1.3.3" @@ -340,6 +356,81 @@ dependencies = [ "serde", ] +[[package]] +name = "bitcoin" +version = "0.32.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0032b0e8ead7074cda7fc4f034409607e3f03a6f71d66ade8a307f79b4d99e73" +dependencies = [ + "base58ck", + "bech32 0.11.0", + "bitcoin-internals", + "bitcoin-io", + "bitcoin-units", + "bitcoin_hashes", + "hex-conservative", + "hex_lit", + "secp256k1", + "serde", +] + +[[package]] +name = "bitcoin-da" +version = "0.1.0" +dependencies = [ + "anyhow", + "async-trait", + "bitcoin", + "borsh", + "citrea-primitives", + "crypto-bigint", + "futures", + "hex", + "itertools 0.13.0", + "rand", + "serde", + "serde_json", + "sha2", + "sov-rollup-interface", + "thiserror", +] + +[[package]] +name = "bitcoin-internals" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" +dependencies = [ + "serde", +] + +[[package]] +name = "bitcoin-io" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" + +[[package]] +name = "bitcoin-units" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5285c8bcaa25876d07f37e3d30c303f2609179716e11d688f51e8f1fe70063e2" +dependencies = [ + "bitcoin-internals", + "serde", +] + +[[package]] +name = "bitcoin_hashes" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" +dependencies = [ + "bitcoin-io", + "hex-conservative", + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -466,10 +557,39 @@ name = "bytes" version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" + +[[package]] +name = "camino" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea" dependencies = [ "serde", ] +[[package]] +name = "cargo_metadata" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror", +] + [[package]] name = "cc" version = "1.1.25" @@ -525,6 +645,13 @@ dependencies = [ "tracing", ] +[[package]] +name = "citrea-risc0-batch-proof" +version = "0.5.0-rc.1" +dependencies = [ + "risc0-build", +] + [[package]] name = "const-hex" version = "1.13.1" @@ -544,12 +671,39 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "const_panic" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53857514f72ee4a2b583de67401e3ff63a5472ca4acf289d09a9ea7636dfec17" + [[package]] name = "constant_time_eq" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" +[[package]] +name = "constmuck" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0e253ed9cc2e1bcc63d791dbe28f818fdff4fceb00d2ff1d3eb943574c623f8" +dependencies = [ + "bytemuck", + "constmuck_internal", + "typewit", +] + +[[package]] +name = "constmuck_internal" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5927bf986ef0398efc2725a986975c1bad3140c883e7bf102f3dec8bcdf0375" +dependencies = [ + "bytemuck", + "const_panic", +] + [[package]] name = "convert_case" version = "0.4.0" @@ -604,6 +758,7 @@ version = "0.5.5" source = "git+https://github.com/risc0/RustCrypto-crypto-bigint?tag=v0.5.5-risczero.0#3ab63a6f1048833f7047d5a50532e4a4cc789384" dependencies = [ "getrandom", + "rand_core", "subtle", "zeroize", ] @@ -702,6 +857,33 @@ dependencies = [ "subtle", ] +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + +[[package]] +name = "docker-generate" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf673e0848ef09fa4aeeba78e681cf651c0c7d35f76ee38cec8e55bc32fa111" + [[package]] name = "downcast-rs" version = "1.2.1" @@ -754,6 +936,22 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + [[package]] name = "fiat-crypto" version = "0.2.9" @@ -787,6 +985,95 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" +[[package]] +name = "futures" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" + +[[package]] +name = "futures-executor" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" + +[[package]] +name = "futures-macro" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] +name = "futures-sink" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" + +[[package]] +name = "futures-task" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" + +[[package]] +name = "futures-util" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "pin-utils", + "slab", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -832,12 +1119,27 @@ dependencies = [ "serde", ] +[[package]] +name = "hex-conservative" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" +dependencies = [ + "arrayvec", +] + [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" +[[package]] +name = "hex_lit" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" + [[package]] name = "ics23" version = "0.11.3" @@ -940,6 +1242,12 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.159" @@ -953,22 +1261,41 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] -name = "light-client-proof-mock" +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.6.0", + "libc", +] + +[[package]] +name = "light-client-proof-bitcoin" version = "0.5.0-rc.1" dependencies = [ "anyhow", + "bitcoin-da", "citrea-light-client-prover", "citrea-primitives", "citrea-risc0-adapter", + "citrea-risc0-batch-proof", + "const-hex", + "constmuck", "risc0-zkvm", "risc0-zkvm-platform", - "sov-mock-da", "sov-modules-api", "sov-modules-stf-blueprint", "sov-rollup-interface", "sov-state", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "log" version = "0.4.22" @@ -1066,6 +1393,12 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "paste" version = "1.0.15" @@ -1078,6 +1411,12 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "platforms" version = "3.4.1" @@ -1141,10 +1480,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c2511913b88df1637da85cc8d96ec8e43a3f8bb8ccb71ee1ac240d6f3df58d" dependencies = [ "bitflags 2.6.0", + "lazy_static", "num-traits", "rand", "rand_chacha", "rand_xorshift", + "regex-syntax", "unarray", ] @@ -1186,6 +1527,7 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ + "libc", "rand_chacha", "rand_core", ] @@ -1205,6 +1547,9 @@ name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] [[package]] name = "rand_xorshift" @@ -1215,6 +1560,23 @@ dependencies = [ "rand_core", ] +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + [[package]] name = "ripemd" version = "0.1.3" @@ -1240,6 +1602,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "risc0-build" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc684382e24a8c91331040c33f1c789c755a5c1b0b8a32fefc1730ca36dd7072" +dependencies = [ + "anyhow", + "cargo_metadata", + "dirs", + "docker-generate", + "hex", + "risc0-binfmt", + "risc0-zkp", + "risc0-zkvm-platform", + "serde", + "serde_json", + "tempfile", +] + [[package]] name = "risc0-circuit-recursion" version = "1.1.3" @@ -1412,6 +1793,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags 2.6.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "ryu" version = "1.0.18" @@ -1442,11 +1836,33 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "secp256k1" +version = "0.29.0" +source = "git+https://github.com/Sovereign-Labs/rust-secp256k1.git?branch=risc0-compatible-0-29-0#3769ab9b2227d430ca2c58546daf3680017cfefb" +dependencies = [ + "bitcoin_hashes", + "rand", + "secp256k1-sys", + "serde", +] + +[[package]] +name = "secp256k1-sys" +version = "0.10.0" +source = "git+https://github.com/Sovereign-Labs/rust-secp256k1.git?branch=risc0-compatible-0-29-0#3769ab9b2227d430ca2c58546daf3680017cfefb" +dependencies = [ + "cc", +] + [[package]] name = "semver" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +dependencies = [ + "serde", +] [[package]] name = "serde" @@ -1524,18 +1940,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" [[package]] -name = "sov-mock-da" -version = "0.5.0-rc.1" +name = "slab" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ - "anyhow", - "async-trait", - "borsh", - "bytes", - "hex", - "serde", - "sha2", - "sov-rollup-interface", - "tracing", + "autocfg", ] [[package]] @@ -1543,7 +1953,7 @@ name = "sov-modules-api" version = "0.5.0-rc.1" dependencies = [ "anyhow", - "bech32", + "bech32 0.9.1", "borsh", "derive_more 0.99.18", "digest", @@ -1563,7 +1973,7 @@ name = "sov-modules-core" version = "0.5.0-rc.1" dependencies = [ "anyhow", - "bech32", + "bech32 0.9.1", "borsh", "derive_more 0.99.18", "digest", @@ -1582,7 +1992,6 @@ version = "0.5.0-rc.1" dependencies = [ "anyhow", "borsh", - "citrea-primitives", "hex", "itertools 0.13.0", "jmt", @@ -1673,6 +2082,19 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "tempfile" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "thiserror" version = "1.0.64" @@ -1767,6 +2189,12 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "typewit" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb77c29baba9e4d3a6182d51fa75e3215c7fd1dab8f4ea9d107c716878e55fc0" + [[package]] name = "unarray" version = "0.1.4" @@ -1803,6 +2231,154 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "winnow" version = "0.6.20" diff --git a/guests/risc0/light-client-proof/bitcoin/Cargo.toml b/guests/risc0/light-client-proof/bitcoin/Cargo.toml new file mode 100644 index 000000000..b9376cae0 --- /dev/null +++ b/guests/risc0/light-client-proof/bitcoin/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "light-client-proof-bitcoin" +version = "0.5.0-rc.1" +edition = "2021" +resolver = "2" + +[workspace] + +[dependencies] +risc0-zkvm = { version = "1.1.3", default-features = false } +risc0-zkvm-platform = { version = "1.1.3" } + +anyhow = "1.0.68" +bitcoin-da = { path = "../../../../crates/bitcoin-da", default-features = false } +citrea-light-client-prover = { path = "../../../../crates/light-client-prover", default-features = false } +citrea-primitives = { path = "../../../../crates/primitives" } +citrea-risc0-adapter = { path = "../../../../crates/risc0" } +citrea-risc0-batch-proof = { path = "../../batch-proof" } +const-hex = "1.12" +constmuck = "1.1" +sov-modules-api = { path = "../../../../crates/sovereign-sdk/module-system/sov-modules-api", default-features = false } +sov-modules-stf-blueprint = { path = "../../../../crates/sovereign-sdk/module-system/sov-modules-stf-blueprint" } +sov-rollup-interface = { path = "../../../../crates/sovereign-sdk/rollup-interface" } +sov-state = { path = "../../../../crates/sovereign-sdk/module-system/sov-state" } + +[features] +testing = ["citrea-primitives/testing", "citrea-risc0-batch-proof/testing"] + +[patch.crates-io] +sha2 = { git = "https://github.com/risc0/RustCrypto-hashes", tag = "sha2-v0.10.8-risczero.0" } +ed25519-dalek = { git = "https://github.com/risc0/curve25519-dalek", tag = "curve25519-4.1.2-risczero.0" } +crypto-bigint = { git = "https://github.com/risc0/RustCrypto-crypto-bigint", tag = "v0.5.5-risczero.0" } +secp256k1 = { git = "https://github.com/Sovereign-Labs/rust-secp256k1.git", branch = "risc0-compatible-0-29-0" } +k256 = { git = "https://github.com/risc0/RustCrypto-elliptic-curves", tag = "k256/v0.13.3-risczero.0" } + +[profile.release] +debug = 0 +lto = true +opt-level = 3 +codegen-units = 1 diff --git a/guests/risc0/light-client-proof/bitcoin/src/bin/light_client_proof_bitcoin.rs b/guests/risc0/light-client-proof/bitcoin/src/bin/light_client_proof_bitcoin.rs new file mode 100644 index 000000000..dac874bf0 --- /dev/null +++ b/guests/risc0/light-client-proof/bitcoin/src/bin/light_client_proof_bitcoin.rs @@ -0,0 +1,100 @@ +#![no_main] +use bitcoin_da::spec::RollupParams; +use bitcoin_da::verifier::BitcoinVerifier; +use citrea_light_client_prover::circuit::run_circuit; +use citrea_primitives::{TO_BATCH_PROOF_PREFIX, TO_LIGHT_CLIENT_PREFIX}; +use citrea_risc0_adapter::guest::Risc0Guest; +use sov_rollup_interface::da::DaVerifier; +use sov_rollup_interface::zk::ZkvmGuest; +use sov_rollup_interface::Network; + +risc0_zkvm::guest::entry!(main); + +const NETWORK: Network = match option_env!("CITREA_NETWORK") { + Some(network) => { + match Network::const_from_str(network) { + Some(network) => network, + None => panic!("Invalid CITREA_NETWORK value"), + } + } + None => Network::Nightly, +}; + +const L2_GENESIS_ROOT: [u8; 32] = { + let hex_root = match NETWORK { + Network::Mainnet => "0000000000000000000000000000000000000000000000000000000000000000", + // TODO: Update this after finding out the first batch prover output of the next release + Network::Testnet => "05183faf24857f0fa6d4a7738fe5ef14b7ebe88be0f66e6f87f461485554d531", + Network::Devnet => "c23eb4eec08765750400f6e98567ef1977dc86334318f5424b7783c4080c0a36", + Network::Nightly => { + match option_env!("L2_GENESIS_ROOT") { + Some(hex_root) => hex_root, + None => "dacb59b0ff5d16985a8418235133eee37758a3ac1b76ab6d1f87c6df20e4d4da", + } + } + }; + + match const_hex::const_decode_to_array(hex_root.as_bytes()) { + Ok(root) => root, + Err(_) => panic!("L2_GENESIS_ROOT must be valid 32-byte hex string"), + } +}; + +const BATCH_PROOF_METHOD_ID: [u32; 8] = { + // TODO: Don't forget to always update devnet, testnet, mainnet method ids just before release + let hex_method_id = match NETWORK { + Network::Mainnet => "0000000000000000000000000000000000000000000000000000000000000000", + Network::Testnet => "0000000000000000000000000000000000000000000000000000000000000000", + Network::Devnet => "0000000000000000000000000000000000000000000000000000000000000000", + Network::Nightly => { + match option_env!("BATCH_PROOF_METHOD_ID") { + Some(hex_method_id) => hex_method_id, + None => "", + } + } + }; + + // Use default nightly batch proof method_id + if hex_method_id.is_empty() { + citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ID + } else { + match const_hex::const_decode_to_array::<32>(hex_method_id.as_bytes()) { + Ok(method_id) => constmuck::cast(method_id), + Err(_) => panic!("BATCH_PROOF_METHOD_ID must be valid 32-byte hex string"), + } + } +}; + +const BATCH_PROVER_DA_PUBLIC_KEY: [u8; 33] = { + let hex_pub_key = match NETWORK { + Network::Mainnet => "030000000000000000000000000000000000000000000000000000000000000000", + Network::Testnet => "0357d255ab93638a2d880787ebaadfefdfc9bb51a26b4a37e5d588e04e54c60a42", + Network::Devnet => "03fc6fb2ef68368009c895d2d4351dcca4109ec2f5f327291a0553570ce769f5e5", + Network::Nightly => { + match option_env!("PROVER_DA_PUB_KEY") { + Some(hex_pub_key) => hex_pub_key, + None => "03eedab888e45f3bdc3ec9918c491c11e5cf7af0a91f38b97fbc1e135ae4056601", + } + } + }; + + match const_hex::const_decode_to_array(hex_pub_key.as_bytes()) { + Ok(pub_key) => pub_key, + Err(_) => panic!("PROVER_DA_PUB_KEY must be valid 33-byte hex string"), + } +}; + +pub fn main() { + let guest = Risc0Guest::new(); + + let da_verifier = BitcoinVerifier::new(RollupParams { + to_batch_proof_prefix: TO_BATCH_PROOF_PREFIX.to_vec(), + to_light_client_prefix: TO_LIGHT_CLIENT_PREFIX.to_vec(), + }); + + let input = guest.read_from_host(); + + let output = run_circuit::(da_verifier, input, L2_GENESIS_ROOT, BATCH_PROOF_METHOD_ID, &BATCH_PROVER_DA_PUBLIC_KEY).unwrap(); + + guest.commit(&output); +} diff --git a/guests/risc0/build.rs b/guests/risc0/light-client-proof/build.rs similarity index 87% rename from guests/risc0/build.rs rename to guests/risc0/light-client-proof/build.rs index 163238bf0..023624f2a 100644 --- a/guests/risc0/build.rs +++ b/guests/risc0/light-client-proof/build.rs @@ -3,9 +3,15 @@ use std::collections::HashMap; use risc0_build::{embed_methods_with_options, DockerOptions, GuestOptions}; fn main() { + // Build environment variables println!("cargo:rerun-if-env-changed=SKIP_GUEST_BUILD"); println!("cargo:rerun-if-env-changed=REPR_GUEST_BUILD"); println!("cargo:rerun-if-env-changed=OUT_DIR"); + // Compile time constant environment variables + println!("cargo:rerun-if-env-changed=CITREA_NETWORK"); + println!("cargo:rerun-if-env-changed=L2_GENESIS_ROOT"); + println!("cargo:rerun-if-env-changed=BATCH_PROOF_METHOD_ID"); + println!("cargo:rerun-if-env-changed=PROVER_DA_PUB_KEY"); match std::env::var("SKIP_GUEST_BUILD") { Ok(value) => match value.as_str() { @@ -16,10 +22,6 @@ fn main() { let methods_path = out_dir.join("methods.rs"); let elf = r#" - pub const BATCH_PROOF_BITCOIN_ELF: &[u8] = &[]; - pub const BATCH_PROOF_BITCOIN_ID: [u32; 8] = [0u32; 8]; - pub const BATCH_PROOF_MOCK_ELF: &[u8] = &[]; - pub const BATCH_PROOF_MOCK_ID: [u32; 8] = [0u32; 8]; pub const LIGHT_CLIENT_PROOF_BITCOIN_ELF: &[u8] = &[]; pub const LIGHT_CLIENT_PROOF_BITCOIN_ID: [u32; 8] = [0u32; 8]; pub const LIGHT_CLIENT_PROOF_MOCK_ELF: &[u8] = &[]; @@ -73,8 +75,6 @@ fn get_guest_options() -> HashMap<&'static str, risc0_build::GuestOptions> { use_docker, }; - guest_pkg_to_options.insert("batch-proof-bitcoin", opts.clone()); - guest_pkg_to_options.insert("batch-proof-mock", opts.clone()); guest_pkg_to_options.insert("light-client-proof-bitcoin", opts.clone()); guest_pkg_to_options.insert("light-client-proof-mock", opts); guest_pkg_to_options diff --git a/guests/risc0/light-client-proof-bitcoin/Cargo.lock b/guests/risc0/light-client-proof/mock/Cargo.lock similarity index 84% rename from guests/risc0/light-client-proof-bitcoin/Cargo.lock rename to guests/risc0/light-client-proof/mock/Cargo.lock index be9dc7754..f46282c44 100644 --- a/guests/risc0/light-client-proof-bitcoin/Cargo.lock +++ b/guests/risc0/light-client-proof/mock/Cargo.lock @@ -309,16 +309,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" -[[package]] -name = "base58ck" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c8d66485a3a2ea485c1913c4572ce0256067a5377ac8c75c4960e1cda98605f" -dependencies = [ - "bitcoin-internals", - "bitcoin_hashes", -] - [[package]] name = "base64" version = "0.21.7" @@ -341,12 +331,6 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" -[[package]] -name = "bech32" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" - [[package]] name = "bincode" version = "1.3.3" @@ -356,81 +340,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bitcoin" -version = "0.32.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0032b0e8ead7074cda7fc4f034409607e3f03a6f71d66ade8a307f79b4d99e73" -dependencies = [ - "base58ck", - "bech32 0.11.0", - "bitcoin-internals", - "bitcoin-io", - "bitcoin-units", - "bitcoin_hashes", - "hex-conservative", - "hex_lit", - "secp256k1", - "serde", -] - -[[package]] -name = "bitcoin-da" -version = "0.1.0" -dependencies = [ - "anyhow", - "async-trait", - "bitcoin", - "borsh", - "citrea-primitives", - "crypto-bigint", - "futures", - "hex", - "itertools 0.13.0", - "rand", - "serde", - "serde_json", - "sha2", - "sov-rollup-interface", - "thiserror", -] - -[[package]] -name = "bitcoin-internals" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30bdbe14aa07b06e6cfeffc529a1f099e5fbe249524f8125358604df99a4bed2" -dependencies = [ - "serde", -] - -[[package]] -name = "bitcoin-io" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "340e09e8399c7bd8912f495af6aa58bea0c9214773417ffaa8f6460f93aaee56" - -[[package]] -name = "bitcoin-units" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5285c8bcaa25876d07f37e3d30c303f2609179716e11d688f51e8f1fe70063e2" -dependencies = [ - "bitcoin-internals", - "serde", -] - -[[package]] -name = "bitcoin_hashes" -version = "0.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb18c03d0db0247e147a21a6faafd5a7eb851c743db062de72018b6b7e8e4d16" -dependencies = [ - "bitcoin-io", - "hex-conservative", - "serde", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -557,6 +466,41 @@ name = "bytes" version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "428d9aa8fbc0670b7b8d6030a7fadd0f86151cae55e4dbbece15f3780a3dfaf3" +dependencies = [ + "serde", +] + +[[package]] +name = "camino" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b96ec4966b5813e2c0507c1f86115c8c5abaadc3980879c3424042a02fd1ad3" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo-platform" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d886547e41f740c616ae73108f6eb70afe6d940c7bc697cb30f13daec073037" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror", +] [[package]] name = "cc" @@ -613,6 +557,13 @@ dependencies = [ "tracing", ] +[[package]] +name = "citrea-risc0-batch-proof" +version = "0.5.0-rc.1" +dependencies = [ + "risc0-build", +] + [[package]] name = "const-hex" version = "1.13.1" @@ -632,12 +583,39 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" +[[package]] +name = "const_panic" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53857514f72ee4a2b583de67401e3ff63a5472ca4acf289d09a9ea7636dfec17" + [[package]] name = "constant_time_eq" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c74b8349d32d297c9134b8c88677813a227df8f779daa29bfc29c183fe3dca6" +[[package]] +name = "constmuck" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0e253ed9cc2e1bcc63d791dbe28f818fdff4fceb00d2ff1d3eb943574c623f8" +dependencies = [ + "bytemuck", + "constmuck_internal", + "typewit", +] + +[[package]] +name = "constmuck_internal" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5927bf986ef0398efc2725a986975c1bad3140c883e7bf102f3dec8bcdf0375" +dependencies = [ + "bytemuck", + "const_panic", +] + [[package]] name = "convert_case" version = "0.4.0" @@ -692,7 +670,6 @@ version = "0.5.5" source = "git+https://github.com/risc0/RustCrypto-crypto-bigint?tag=v0.5.5-risczero.0#3ab63a6f1048833f7047d5a50532e4a4cc789384" dependencies = [ "getrandom", - "rand_core", "subtle", "zeroize", ] @@ -791,6 +768,33 @@ dependencies = [ "subtle", ] +[[package]] +name = "dirs" +version = "5.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.48.0", +] + +[[package]] +name = "docker-generate" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf673e0848ef09fa4aeeba78e681cf651c0c7d35f76ee38cec8e55bc32fa111" + [[package]] name = "downcast-rs" version = "1.2.1" @@ -843,6 +847,22 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" +dependencies = [ + "libc", + "windows-sys 0.59.0", +] + +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + [[package]] name = "fiat-crypto" version = "0.2.9" @@ -876,95 +896,6 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" -[[package]] -name = "futures" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" - -[[package]] -name = "futures-executor" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e28d1d997f585e54aebc3f97d39e72338912123a67330d723fdbb564d646c9f" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" - -[[package]] -name = "futures-macro" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "162ee34ebcb7c64a8abebc059ce0fee27c2262618d7b60ed8faf72fef13c3650" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.87", -] - -[[package]] -name = "futures-sink" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" - -[[package]] -name = "futures-task" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" - -[[package]] -name = "futures-util" -version = "0.3.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - [[package]] name = "generic-array" version = "0.14.7" @@ -1010,27 +941,12 @@ dependencies = [ "serde", ] -[[package]] -name = "hex-conservative" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5313b072ce3c597065a808dbf612c4c8e8590bdbf8b579508bf7a762c5eae6cd" -dependencies = [ - "arrayvec", -] - [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" -[[package]] -name = "hex_lit" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" - [[package]] name = "ics23" version = "0.11.3" @@ -1133,6 +1049,12 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + [[package]] name = "libc" version = "0.2.159" @@ -1146,22 +1068,41 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] -name = "light-client-proof-bitcoin" +name = "libredox" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" +dependencies = [ + "bitflags 2.6.0", + "libc", +] + +[[package]] +name = "light-client-proof-mock" version = "0.5.0-rc.1" dependencies = [ "anyhow", - "bitcoin-da", "citrea-light-client-prover", "citrea-primitives", "citrea-risc0-adapter", + "citrea-risc0-batch-proof", + "const-hex", + "constmuck", "risc0-zkvm", "risc0-zkvm-platform", + "sov-mock-da", "sov-modules-api", "sov-modules-stf-blueprint", "sov-rollup-interface", "sov-state", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "log" version = "0.4.22" @@ -1259,6 +1200,12 @@ version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + [[package]] name = "paste" version = "1.0.15" @@ -1271,12 +1218,6 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "platforms" version = "3.4.1" @@ -1340,10 +1281,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c2511913b88df1637da85cc8d96ec8e43a3f8bb8ccb71ee1ac240d6f3df58d" dependencies = [ "bitflags 2.6.0", + "lazy_static", "num-traits", "rand", "rand_chacha", "rand_xorshift", + "regex-syntax", "unarray", ] @@ -1418,6 +1361,23 @@ dependencies = [ "rand_core", ] +[[package]] +name = "redox_users" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" +dependencies = [ + "getrandom", + "libredox", + "thiserror", +] + +[[package]] +name = "regex-syntax" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" + [[package]] name = "ripemd" version = "0.1.3" @@ -1443,6 +1403,25 @@ dependencies = [ "tracing", ] +[[package]] +name = "risc0-build" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc684382e24a8c91331040c33f1c789c755a5c1b0b8a32fefc1730ca36dd7072" +dependencies = [ + "anyhow", + "cargo_metadata", + "dirs", + "docker-generate", + "hex", + "risc0-binfmt", + "risc0-zkp", + "risc0-zkvm-platform", + "serde", + "serde_json", + "tempfile", +] + [[package]] name = "risc0-circuit-recursion" version = "1.1.3" @@ -1615,6 +1594,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +dependencies = [ + "bitflags 2.6.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "ryu" version = "1.0.18" @@ -1645,30 +1637,14 @@ dependencies = [ "syn 2.0.87", ] -[[package]] -name = "secp256k1" -version = "0.29.0" -source = "git+https://github.com/Sovereign-Labs/rust-secp256k1.git?branch=risc0-compatible-0-29-0#3769ab9b2227d430ca2c58546daf3680017cfefb" -dependencies = [ - "bitcoin_hashes", - "rand", - "secp256k1-sys", - "serde", -] - -[[package]] -name = "secp256k1-sys" -version = "0.10.0" -source = "git+https://github.com/Sovereign-Labs/rust-secp256k1.git?branch=risc0-compatible-0-29-0#3769ab9b2227d430ca2c58546daf3680017cfefb" -dependencies = [ - "cc", -] - [[package]] name = "semver" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +dependencies = [ + "serde", +] [[package]] name = "serde" @@ -1746,12 +1722,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" [[package]] -name = "slab" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" +name = "sov-mock-da" +version = "0.5.0-rc.1" dependencies = [ - "autocfg", + "anyhow", + "async-trait", + "borsh", + "bytes", + "hex", + "serde", + "sha2", + "sov-rollup-interface", + "tracing", ] [[package]] @@ -1759,7 +1741,7 @@ name = "sov-modules-api" version = "0.5.0-rc.1" dependencies = [ "anyhow", - "bech32 0.9.1", + "bech32", "borsh", "derive_more 0.99.18", "digest", @@ -1779,7 +1761,7 @@ name = "sov-modules-core" version = "0.5.0-rc.1" dependencies = [ "anyhow", - "bech32 0.9.1", + "bech32", "borsh", "derive_more 0.99.18", "digest", @@ -1798,7 +1780,6 @@ version = "0.5.0-rc.1" dependencies = [ "anyhow", "borsh", - "citrea-primitives", "hex", "itertools 0.13.0", "jmt", @@ -1889,6 +1870,19 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "tempfile" +version = "3.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f2c9fc62d0beef6951ccffd757e241266a2c833136efbe35af6cd2567dca5b" +dependencies = [ + "cfg-if", + "fastrand", + "once_cell", + "rustix", + "windows-sys 0.59.0", +] + [[package]] name = "thiserror" version = "1.0.64" @@ -1983,6 +1977,12 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "typewit" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb77c29baba9e4d3a6182d51fa75e3215c7fd1dab8f4ea9d107c716878e55fc0" + [[package]] name = "unarray" version = "0.1.4" @@ -2019,6 +2019,154 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + [[package]] name = "winnow" version = "0.6.20" diff --git a/guests/risc0/light-client-proof/mock/Cargo.toml b/guests/risc0/light-client-proof/mock/Cargo.toml new file mode 100644 index 000000000..2d538687b --- /dev/null +++ b/guests/risc0/light-client-proof/mock/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "light-client-proof-mock" +version = "0.5.0-rc.1" +edition = "2021" +resolver = "2" + +[workspace] + +[dependencies] +risc0-zkvm = { version = "1.1.3", default-features = false } +risc0-zkvm-platform = { version = "1.1.3" } + +anyhow = "1.0.68" +sov-mock-da = { path = "../../../../crates/sovereign-sdk/adapters/mock-da", default-features = false } + +citrea-light-client-prover = { path = "../../../../crates/light-client-prover", default-features = false } +citrea-primitives = { path = "../../../../crates/primitives" } +citrea-risc0-adapter = { path = "../../../../crates/risc0" } +citrea-risc0-batch-proof = { path = "../../batch-proof" } +const-hex = "1.12" +constmuck = "1.1" +sov-modules-api = { path = "../../../../crates/sovereign-sdk/module-system/sov-modules-api", default-features = false } +sov-modules-stf-blueprint = { path = "../../../../crates/sovereign-sdk/module-system/sov-modules-stf-blueprint" } +sov-rollup-interface = { path = "../../../../crates/sovereign-sdk/rollup-interface" } +sov-state = { path = "../../../../crates/sovereign-sdk/module-system/sov-state" } + +[features] +testing = ["citrea-primitives/testing", "citrea-risc0-batch-proof/testing"] + +[patch.crates-io] +sha2 = { git = "https://github.com/risc0/RustCrypto-hashes", tag = "sha2-v0.10.8-risczero.0" } +ed25519-dalek = { git = "https://github.com/risc0/curve25519-dalek", tag = "curve25519-4.1.2-risczero.0" } +crypto-bigint = { git = "https://github.com/risc0/RustCrypto-crypto-bigint", tag = "v0.5.5-risczero.0" } +k256 = { git = "https://github.com/risc0/RustCrypto-elliptic-curves", tag = "k256/v0.13.3-risczero.0" } + +[profile.release] +debug = 0 +lto = true +opt-level = 3 +codegen-units = 1 diff --git a/guests/risc0/light-client-proof/mock/src/bin/light_client_proof_mock.rs b/guests/risc0/light-client-proof/mock/src/bin/light_client_proof_mock.rs new file mode 100644 index 000000000..3bdf1f9d7 --- /dev/null +++ b/guests/risc0/light-client-proof/mock/src/bin/light_client_proof_mock.rs @@ -0,0 +1,31 @@ +#![no_main] +use citrea_light_client_prover::circuit::run_circuit; +use citrea_risc0_adapter::guest::Risc0Guest; +use sov_mock_da::MockDaVerifier; +use sov_rollup_interface::zk::ZkvmGuest; + +risc0_zkvm::guest::entry!(main); + +const L2_GENESIS_ROOT: [u8; 32] = match const_hex::const_decode_to_array(b"dacb59b0ff5d16985a8418235133eee37758a3ac1b76ab6d1f87c6df20e4d4da") { + Ok(root) => root, + Err(_) => panic!("Can't happen"), +}; + +const BATCH_PROOF_METHOD_ID: [u32; 8] = citrea_risc0_batch_proof::BATCH_PROOF_MOCK_ID; + +const BATCH_PROVER_DA_PUBLIC_KEY: [u8; 33] = match const_hex::const_decode_to_array(b"03eedab888e45f3bdc3ec9918c491c11e5cf7af0a91f38b97fbc1e135ae4056601") { + Ok(pub_key) => pub_key, + Err(_) => panic!("Can't happen"), +}; + +pub fn main() { + let guest = Risc0Guest::new(); + + let da_verifier = MockDaVerifier {}; + + let input = guest.read_from_host(); + + let output = run_circuit::(da_verifier, input, L2_GENESIS_ROOT, BATCH_PROOF_METHOD_ID, &BATCH_PROVER_DA_PUBLIC_KEY).unwrap(); + + guest.commit(&output); +} diff --git a/guests/risc0/light-client-proof/src/lib.rs b/guests/risc0/light-client-proof/src/lib.rs new file mode 100644 index 000000000..1bdb3085f --- /dev/null +++ b/guests/risc0/light-client-proof/src/lib.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/methods.rs")); diff --git a/guests/sp1/batch-prover-bitcoin/Cargo.lock b/guests/sp1/batch-proof-bitcoin/Cargo.lock similarity index 99% rename from guests/sp1/batch-prover-bitcoin/Cargo.lock rename to guests/sp1/batch-proof-bitcoin/Cargo.lock index 38cf158bc..313b3553b 100644 --- a/guests/sp1/batch-prover-bitcoin/Cargo.lock +++ b/guests/sp1/batch-proof-bitcoin/Cargo.lock @@ -550,8 +550,10 @@ dependencies = [ "bitcoin", "borsh", "citrea-primitives", + "crypto-bigint", "futures", "hex", + "itertools 0.13.0", "rand", "serde", "serde_json", @@ -702,9 +704,9 @@ dependencies = [ [[package]] name = "brotli" -version = "6.0.0" +version = "7.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74f7971dbd9326d58187408ab83117d8ac1bb9c17b085fdacd1cf2f598719b6b" +checksum = "cc97b8f16f944bba54f0433f07e30be199b6dc2bd25937444bbad560bcea29bd" dependencies = [ "alloc-no-stdlib", "alloc-stdlib", @@ -806,7 +808,6 @@ dependencies = [ "alloy-eips", "alloy-primitives 0.7.7", "alloy-sol-types", - "anyhow", "borsh", "citrea-primitives", "hex", @@ -2640,7 +2641,6 @@ dependencies = [ name = "soft-confirmation-rule-enforcer" version = "0.5.0-rc.1" dependencies = [ - "anyhow", "borsh", "serde", "sov-modules-api", @@ -2652,7 +2652,6 @@ dependencies = [ name = "sov-accounts" version = "0.5.0-rc.1" dependencies = [ - "anyhow", "borsh", "serde", "sov-modules-api", @@ -2668,6 +2667,7 @@ dependencies = [ "bech32 0.9.1", "borsh", "derive_more 0.99.18", + "digest 0.10.7", "ed25519-dalek", "hex", "jmt", @@ -2716,6 +2716,7 @@ version = "0.5.0-rc.1" dependencies = [ "anyhow", "borsh", + "citrea-primitives", "hex", "itertools 0.13.0", "jmt", @@ -2736,9 +2737,7 @@ dependencies = [ "bytes", "digest 0.10.7", "hex", - "proptest", "serde", - "sha2", "thiserror", ] @@ -2777,6 +2776,7 @@ dependencies = [ "citrea-primitives", "citrea-sp1", "citrea-stf", + "const-hex", "curve25519-dalek", "sov-modules-api", "sov-modules-stf-blueprint", @@ -2812,7 +2812,7 @@ dependencies = [ [[package]] name = "sp1-lib" version = "3.0.0" -source = "git+https://github.com/succinctlabs/sp1.git?branch=dev#d13675665bff079b6da4f115cb322eadca6bb50e" +source = "git+https://github.com/succinctlabs/sp1.git?branch=dev#aa5d95360403878c947d1e72b84d7f24cc5ce228" dependencies = [ "bincode", "serde", diff --git a/guests/sp1/batch-prover-bitcoin/Cargo.toml b/guests/sp1/batch-proof-bitcoin/Cargo.toml similarity index 77% rename from guests/sp1/batch-prover-bitcoin/Cargo.toml rename to guests/sp1/batch-proof-bitcoin/Cargo.toml index 2ff03e769..1e0728bb2 100644 --- a/guests/sp1/batch-prover-bitcoin/Cargo.toml +++ b/guests/sp1/batch-proof-bitcoin/Cargo.toml @@ -7,14 +7,15 @@ edition = "2021" resolver = "2" [dependencies] -bitcoin-da = { path = "../../../../crates/bitcoin-da", default-features = false } -citrea-primitives = { path = "../../../../crates/primitives" } -citrea-sp1 = { path = "../../../../crates/sp1", default-features = false } -citrea-stf = { path = "../../../../crates/citrea-stf" } -sov-modules-api = { path = "../../../../crates/sovereign-sdk/module-system/sov-modules-api", default-features = false } -sov-modules-stf-blueprint = { path = "../../../../crates/sovereign-sdk/module-system/sov-modules-stf-blueprint" } -sov-rollup-interface = { path = "../../../../crates/sovereign-sdk/rollup-interface" } -sov-state = { path = "../../../../crates/sovereign-sdk/module-system/sov-state" } +bitcoin-da = { path = "../../../crates/bitcoin-da", default-features = false } +citrea-primitives = { path = "../../../crates/primitives" } +citrea-sp1 = { path = "../../../crates/sp1", default-features = false } +citrea-stf = { path = "../../../crates/citrea-stf" } +const-hex = "1.12" +sov-modules-api = { path = "../../../crates/sovereign-sdk/module-system/sov-modules-api", default-features = false } +sov-modules-stf-blueprint = { path = "../../../crates/sovereign-sdk/module-system/sov-modules-stf-blueprint" } +sov-rollup-interface = { path = "../../../crates/sovereign-sdk/rollup-interface" } +sov-state = { path = "../../../crates/sovereign-sdk/module-system/sov-state" } sp1-zkvm = { version = "3.0.0", default-features = false, features = ["lib"] } # Have to put this here to enable features for the patch crate even though we don't use this crate explicitly diff --git a/guests/sp1/batch-proof-bitcoin/src/main.rs b/guests/sp1/batch-proof-bitcoin/src/main.rs new file mode 100644 index 000000000..a4a83e9e2 --- /dev/null +++ b/guests/sp1/batch-proof-bitcoin/src/main.rs @@ -0,0 +1,94 @@ +#![no_main] +sp1_zkvm::entrypoint!(main); + +use bitcoin_da::spec::RollupParams; +use bitcoin_da::verifier::BitcoinVerifier; +use citrea_primitives::forks::{DEVNET_FORKS, MAINNET_FORKS, NIGHTLY_FORKS, TESTNET_FORKS}; +use citrea_primitives::{TO_BATCH_PROOF_PREFIX, TO_LIGHT_CLIENT_PREFIX}; +use citrea_sp1::guest::SP1Guest; +use citrea_stf::runtime::Runtime; +use citrea_stf::StfVerifier; +use sov_modules_api::default_context::ZkDefaultContext; +use sov_modules_stf_blueprint::StfBlueprint; +use sov_rollup_interface::da::DaVerifier; +use sov_rollup_interface::zk::ZkvmGuest; +use sov_rollup_interface::Network; +use sov_state::ZkStorage; + +const NETWORK: Network = match option_env!("CITREA_NETWORK") { + Some(network) => { + match Network::const_from_str(network) { + Some(network) => network, + None => panic!("Invalid CITREA_NETWORK value"), + } + } + None => Network::Nightly, +}; + +const SEQUENCER_PUBLIC_KEY: [u8; 32] = { + let hex_pub_key = match NETWORK { + Network::Mainnet => "4682a70af1d3fae53a5a26b682e2e75f7a1de21ad5fc8d61794ca889880d39d1", + Network::Testnet => "4682a70af1d3fae53a5a26b682e2e75f7a1de21ad5fc8d61794ca889880d39d1", + Network::Devnet => "52f41a5076498d1ae8bdfa57d19e91e3c2c94b6de21985d099cd48cfa7aef174", + Network::Nightly => { + match option_env!("SEQUENCER_PUBLIC_KEY") { + Some(hex_pub_key) => hex_pub_key, + None => "204040e364c10f2bec9c1fe500a1cd4c247c89d650a01ed7e82caba867877c21", + } + } + }; + + match const_hex::const_decode_to_array(hex_pub_key.as_bytes()) { + Ok(pub_key) => pub_key, + Err(_) => panic!("SEQUENCER_PUBLIC_KEY must be valid 32-byte hex string"), + } +}; + +const SEQUENCER_DA_PUBLIC_KEY: [u8; 33] = { + let hex_pub_key = match NETWORK { + Network::Mainnet => "03015a7c4d2cc1c771198686e2ebef6fe7004f4136d61f6225b061d1bb9b821b9b", + Network::Testnet => "03015a7c4d2cc1c771198686e2ebef6fe7004f4136d61f6225b061d1bb9b821b9b", + Network::Devnet => "039cd55f9b3dcf306c4d54f66cd7c4b27cc788632cd6fb73d80c99d303c6536486", + Network::Nightly => { + match option_env!("SEQUENCER_DA_PUBLIC_KEY") { + Some(hex_pub_key) => hex_pub_key, + None => "02588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9", + } + } + }; + + match const_hex::const_decode_to_array(hex_pub_key.as_bytes()) { + Ok(pub_key) => pub_key, + Err(_) => panic!("SEQUENCER_DA_PUBLIC_KEY must be valid 33-byte hex string"), + } +}; + +const FORKS: &[Fork] = match NETWORK { + Network::Mainnet => &MAINNET_FORKS, + Network::Testnet => &TESTNET_FORKS, + Network::Devnet => &DEVNET_FORKS, + Network::Nightly => &NIGHTLY_FORKS, +}; + + +pub fn main() { + let guest = SP1Guest::new(); + let storage = ZkStorage::new(); + let stf = StfBlueprint::new(); + + let mut stf_verifier: StfVerifier<_, ZkDefaultContext, Runtime<_, _>> = StfVerifier::new( + stf, + BitcoinVerifier::new(RollupParams { + to_batch_proof_prefix: TO_BATCH_PROOF_PREFIX.to_vec(), + to_light_client_prefix: TO_LIGHT_CLIENT_PREFIX.to_vec(), + }), + ); + + let data = guest.read_from_host(); + + let out = stf_verifier + .run_sequencer_commitments_in_da_slot(data, storage, &SEQUENCER_PUBLIC_KEY, &SEQUENCER_DA_PUBLIC_KEY, FORKS) + .expect("Prover must be honest"); + + guest.commit(&out); +} diff --git a/guests/sp1/batch-prover-bitcoin/src/main.rs b/guests/sp1/batch-prover-bitcoin/src/main.rs deleted file mode 100644 index f54ab3ff9..000000000 --- a/guests/sp1/batch-prover-bitcoin/src/main.rs +++ /dev/null @@ -1,32 +0,0 @@ -#![no_main] -sp1_zkvm::entrypoint!(main); - -use bitcoin_da::spec::RollupParams; -use bitcoin_da::verifier::BitcoinVerifier; -use citrea_primitives::{TO_BATCH_PROOF_PREFIX, TO_LIGHT_CLIENT_PREFIX}; -use citrea_sp1::guest::SP1Guest; -use citrea_stf::runtime::Runtime; -use citrea_stf::StfVerifier; -use sov_modules_api::default_context::ZkDefaultContext; -use sov_modules_stf_blueprint::StfBlueprint; -use sov_rollup_interface::da::DaVerifier; -use sov_state::ZkStorage; - -pub fn main() { - let guest = SP1Guest::new(); - let storage = ZkStorage::new(); - - let stf: StfBlueprint> = StfBlueprint::new(); - - let mut stf_verifier = StfVerifier::new( - stf, - BitcoinVerifier::new(RollupParams { - to_batch_proof_prefix: TO_BATCH_PROOF_PREFIX.to_vec(), - to_light_client_prefix: TO_LIGHT_CLIENT_PREFIX.to_vec(), - }), - ); - - stf_verifier - .run_sequencer_commitments_in_da_slot(guest, storage) - .expect("Prover must be honest"); -} diff --git a/guests/sp1/build.rs b/guests/sp1/build.rs index df85c43d8..51b60b30d 100644 --- a/guests/sp1/build.rs +++ b/guests/sp1/build.rs @@ -23,7 +23,7 @@ fn main() { fn build_sp1_guest() { println!("cargo:rerun-if-env-changed=BUILD_SP1_GUEST"); - let bitcoin_program_path = "guests/sp1/batch-prover-bitcoin"; + let bitcoin_program_path = "guests/sp1/batch-proof-bitcoin"; let build_args = sp1_helper::BuildArgs { elf_name: "zkvm-elf".to_string(), diff --git a/resources/configs/bitcoin-regtest/light_client_prover_rollup_config.toml b/resources/configs/bitcoin-regtest/light_client_prover_rollup_config.toml index 2844d258a..5fc2ef64b 100644 --- a/resources/configs/bitcoin-regtest/light_client_prover_rollup_config.toml +++ b/resources/configs/bitcoin-regtest/light_client_prover_rollup_config.toml @@ -1,7 +1,7 @@ [public_keys] sequencer_public_key = "204040e364c10f2bec9c1fe500a1cd4c247c89d650a01ed7e82caba867877c21" sequencer_da_pub_key = "02588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9" -prover_da_pub_key = "" +prover_da_pub_key = "03eedab888e45f3bdc3ec9918c491c11e5cf7af0a91f38b97fbc1e135ae4056601" [da] # fill here diff --git a/resources/configs/bitcoin-regtest/rollup_config.toml b/resources/configs/bitcoin-regtest/rollup_config.toml index b5381546c..b71c64b25 100644 --- a/resources/configs/bitcoin-regtest/rollup_config.toml +++ b/resources/configs/bitcoin-regtest/rollup_config.toml @@ -1,7 +1,7 @@ [public_keys] sequencer_public_key = "204040e364c10f2bec9c1fe500a1cd4c247c89d650a01ed7e82caba867877c21" sequencer_da_pub_key = "02588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9" -prover_da_pub_key = "" +prover_da_pub_key = "03eedab888e45f3bdc3ec9918c491c11e5cf7af0a91f38b97fbc1e135ae4056601" [da] # fill here diff --git a/resources/configs/mock/batch_prover_rollup_config.toml b/resources/configs/mock/batch_prover_rollup_config.toml new file mode 100644 index 000000000..1a7d42f2d --- /dev/null +++ b/resources/configs/mock/batch_prover_rollup_config.toml @@ -0,0 +1,25 @@ +[public_keys] +sequencer_public_key = "204040e364c10f2bec9c1fe500a1cd4c247c89d650a01ed7e82caba867877c21" +sequencer_da_pub_key = "02588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9" +prover_da_pub_key = "03eedab888e45f3bdc3ec9918c491c11e5cf7af0a91f38b97fbc1e135ae4056601" + +[da] +sender_address = "03eedab888e45f3bdc3ec9918c491c11e5cf7af0a91f38b97fbc1e135ae4056601" +db_path = "resources/dbs/da-db" + +[storage] +# The path to the rollup's data directory. Paths that do not begin with `/` are interpreted as relative paths. +path = "resources/dbs/full-node-db" +db_max_open_files = 5000 + +[rpc] +# the host and port to bind the rpc server for +bind_host = "127.0.0.1" +bind_port = 12346 +enable_subscriptions = true +max_subscriptions_per_connection = 100 + +[runner] +include_tx_body = false +sequencer_client_url = "http://0.0.0.0:12345" +# pruning_config.distance = 10 diff --git a/resources/configs/mock/rollup_config.toml b/resources/configs/mock/rollup_config.toml index a19c13be2..a9e0e1881 100644 --- a/resources/configs/mock/rollup_config.toml +++ b/resources/configs/mock/rollup_config.toml @@ -1,10 +1,10 @@ [public_keys] sequencer_public_key = "204040e364c10f2bec9c1fe500a1cd4c247c89d650a01ed7e82caba867877c21" -sequencer_da_pub_key = "0000000000000000000000000000000000000000000000000000000000000000" -prover_da_pub_key = "" +sequencer_da_pub_key = "02588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9" +prover_da_pub_key = "03eedab888e45f3bdc3ec9918c491c11e5cf7af0a91f38b97fbc1e135ae4056601" [da] -sender_address = "0000000000000000000000000000000000000000000000000000000000000000" +sender_address = "02588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9" db_path = "resources/dbs/da-db" [storage] diff --git a/resources/configs/mock/sequencer_rollup_config.toml b/resources/configs/mock/sequencer_rollup_config.toml index 4f293dcdc..6349202a3 100644 --- a/resources/configs/mock/sequencer_rollup_config.toml +++ b/resources/configs/mock/sequencer_rollup_config.toml @@ -1,10 +1,10 @@ [public_keys] sequencer_public_key = "204040e364c10f2bec9c1fe500a1cd4c247c89d650a01ed7e82caba867877c21" -sequencer_da_pub_key = "0000000000000000000000000000000000000000000000000000000000000000" +sequencer_da_pub_key = "02588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9" prover_da_pub_key = "" [da] -sender_address = "0000000000000000000000000000000000000000000000000000000000000000" +sender_address = "02588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9" db_path = "resources/dbs/da-db" [storage]