From 44cbd0f28f612abdb56d9b9f601ee5ecc3ce0a7f Mon Sep 17 00:00:00 2001 From: jfldde <168934971+jfldde@users.noreply.github.com> Date: Fri, 10 Jan 2025 19:19:53 +0000 Subject: [PATCH] Remove use_latest_elf (#1681) Co-authored-by: eyusufatik --- Cargo.lock | 2 +- Cargo.toml | 2 +- bin/citrea/src/guests.rs | 17 ++++++- bin/citrea/src/lib.rs | 2 +- bin/citrea/src/main.rs | 8 ++++ bin/citrea/src/rollup/bitcoin.rs | 18 ++++++-- bin/citrea/src/rollup/mock.rs | 6 +-- .../tests/bitcoin_e2e/batch_prover_test.rs | 45 ++++++------------ .../tests/bitcoin_e2e/light_client_test.rs | 22 +++------ bin/citrea/tests/e2e/mod.rs | 1 - bin/citrea/tests/e2e/proving.rs | 4 +- bin/citrea/tests/e2e/reopen.rs | 15 ++---- bin/citrea/tests/e2e/syncing.rs | 1 - bin/citrea/tests/test_client/mod.rs | 3 +- crates/batch-prover/src/da_block_handler.rs | 2 - crates/batch-prover/src/proving.rs | 16 +------ crates/batch-prover/src/rpc.rs | 3 -- crates/bitcoin-da/src/verifier.rs | 2 +- crates/common/src/config.rs | 19 ++------ crates/primitives/src/forks.rs | 10 ++-- crates/risc0/Cargo.toml | 1 + crates/risc0/src/host.rs | 15 +++++- .../rollup-interface/src/network.rs | 5 +- guests/risc0/batch-proof/bitcoin/Cargo.toml | 2 +- .../bitcoin/src/bin/batch_proof_bitcoin.rs | 37 +++++++++++---- guests/risc0/batch-proof/mock/Cargo.toml | 2 +- .../src/bin/light_client_proof_bitcoin.rs | 46 +++++++++++-------- .../risc0/light-client-proof/mock/Cargo.toml | 2 +- 28 files changed, 154 insertions(+), 154 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7a1e339b2f..52e20943cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1909,7 +1909,7 @@ dependencies = [ [[package]] name = "citrea-e2e" version = "0.1.0" -source = "git+https://github.com/chainwayxyz/citrea-e2e?rev=ab88a607ca5aad2245d3c54f8822e02a1b71f50e#ab88a607ca5aad2245d3c54f8822e02a1b71f50e" +source = "git+https://github.com/chainwayxyz/citrea-e2e?rev=af85eae3010331df0e0cda5288f741b6d298813f#af85eae3010331df0e0cda5288f741b6d298813f" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index c6654f34d3..50603528c5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -154,7 +154,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 = "ab88a607ca5aad2245d3c54f8822e02a1b71f50e" } +citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "af85eae3010331df0e0cda5288f741b6d298813f" } [patch.crates-io] bitcoincore-rpc = { version = "0.18.0", git = "https://github.com/chainwayxyz/rust-bitcoincore-rpc.git", rev = "ca3cfa2" } diff --git a/bin/citrea/src/guests.rs b/bin/citrea/src/guests.rs index 2671c4539a..5599864d0f 100644 --- a/bin/citrea/src/guests.rs +++ b/bin/citrea/src/guests.rs @@ -48,8 +48,8 @@ lazy_static! { ); 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)> = { + + pub(crate) static ref BATCH_PROOF_REGTEST_BITCOIN_GUESTS: HashMap)> = { HashMap::from( [ // this is ELF of genesis fork except for da namespace [1, 1] -> [1] and [2,2] -> [2] @@ -61,6 +61,19 @@ lazy_static! { ] ) }; + + /// 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)> = { + HashMap::from( + [ + (SpecId::Fork1, + (Digest::new(citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ID), + citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ELF.to_vec()) + ) + ] + ) + }; + pub(crate) static ref LIGHT_CLIENT_LATEST_BITCOIN_GUESTS: HashMap)> = { let mut m = HashMap::new(); diff --git a/bin/citrea/src/lib.rs b/bin/citrea/src/lib.rs index 212c7be718..9d979e53d6 100644 --- a/bin/citrea/src/lib.rs +++ b/bin/citrea/src/lib.rs @@ -18,7 +18,7 @@ pub use rollup::*; /// The network currently running. #[derive(clap::ValueEnum, Copy, Clone, Default, Debug, Serialize)] -#[serde(rename_all = "kebab-case")] +#[serde(rename_all = "lowercase")] pub enum NetworkArg { /// Mainnet #[default] diff --git a/bin/citrea/src/main.rs b/bin/citrea/src/main.rs index 5cb41d89d1..8bab726321 100644 --- a/bin/citrea/src/main.rs +++ b/bin/citrea/src/main.rs @@ -40,6 +40,10 @@ struct Args { #[arg(long, default_value_t)] dev: bool, + /// Run the regtest chain + #[arg(long, default_value_t, conflicts_with = "dev")] + dev_all_forks: bool, + /// Path to the genesis configuration. /// Defines the genesis of module states like evm. #[arg(long)] @@ -153,6 +157,10 @@ async fn main() -> Result<(), anyhow::Error> { network = Network::Nightly; } + if args.dev_all_forks { + network = Network::TestNetworkWithForks; + } + info!("Starting node on {network}"); match args.da_layer { diff --git a/bin/citrea/src/rollup/bitcoin.rs b/bin/citrea/src/rollup/bitcoin.rs index c844dd96c5..117b713c46 100644 --- a/bin/citrea/src/rollup/bitcoin.rs +++ b/bin/citrea/src/rollup/bitcoin.rs @@ -31,8 +31,8 @@ use tracing::instrument; use crate::guests::{ BATCH_PROOF_DEVNET_GUESTS, BATCH_PROOF_LATEST_BITCOIN_GUESTS, BATCH_PROOF_MAINNET_GUESTS, - BATCH_PROOF_TESTNET_GUESTS, LIGHT_CLIENT_DEVNET_GUESTS, LIGHT_CLIENT_LATEST_BITCOIN_GUESTS, - LIGHT_CLIENT_MAINNET_GUESTS, LIGHT_CLIENT_TESTNET_GUESTS, + BATCH_PROOF_REGTEST_BITCOIN_GUESTS, BATCH_PROOF_TESTNET_GUESTS, LIGHT_CLIENT_DEVNET_GUESTS, + LIGHT_CLIENT_LATEST_BITCOIN_GUESTS, LIGHT_CLIENT_MAINNET_GUESTS, LIGHT_CLIENT_TESTNET_GUESTS, }; use crate::{CitreaRollupBlueprint, Network}; @@ -180,6 +180,10 @@ impl RollupBlueprint for BitcoinRollup { .iter() .map(|(k, (_, code))| (*k, code.clone())) .collect(), + Network::TestNetworkWithForks => BATCH_PROOF_REGTEST_BITCOIN_GUESTS + .iter() + .map(|(k, (_, code))| (*k, code.clone())) + .collect(), } } @@ -197,7 +201,7 @@ impl RollupBlueprint for BitcoinRollup { .iter() .map(|(k, (_, code))| (*k, code.clone())) .collect(), - Network::Nightly => LIGHT_CLIENT_LATEST_BITCOIN_GUESTS + Network::Nightly | Network::TestNetworkWithForks => LIGHT_CLIENT_LATEST_BITCOIN_GUESTS .iter() .map(|(k, (_, code))| (*k, code.clone())) .collect(), @@ -224,6 +228,10 @@ impl RollupBlueprint for BitcoinRollup { .iter() .map(|(k, (id, _))| (*k, *id)) .collect(), + Network::TestNetworkWithForks => BATCH_PROOF_REGTEST_BITCOIN_GUESTS + .iter() + .map(|(k, (id, _))| (*k, *id)) + .collect(), } } @@ -243,7 +251,7 @@ impl RollupBlueprint for BitcoinRollup { .iter() .map(|(k, (id, _))| (*k, *id)) .collect(), - Network::Nightly => LIGHT_CLIENT_LATEST_BITCOIN_GUESTS + Network::Nightly | Network::TestNetworkWithForks => LIGHT_CLIENT_LATEST_BITCOIN_GUESTS .iter() .map(|(k, (id, _))| (*k, *id)) .collect(), @@ -258,7 +266,7 @@ impl RollupBlueprint for BitcoinRollup { ledger_db: LedgerDB, proof_sampling_number: usize, ) -> Self::ProverService { - let vm = Risc0BonsaiHost::new(ledger_db.clone()); + let vm = Risc0BonsaiHost::new(ledger_db.clone(), self.network); // let vm = SP1Host::new( // include_bytes!("../guests/sp1/batch-prover-bitcoin/elf/zkvm-elf"), // ledger_db.clone(), diff --git a/bin/citrea/src/rollup/mock.rs b/bin/citrea/src/rollup/mock.rs index 10cd1e8654..5297b098f9 100644 --- a/bin/citrea/src/rollup/mock.rs +++ b/bin/citrea/src/rollup/mock.rs @@ -25,7 +25,7 @@ use crate::{CitreaRollupBlueprint, Network}; /// Rollup with MockDa pub struct MockDemoRollup { - _network: Network, + network: Network, } impl CitreaRollupBlueprint for MockDemoRollup {} @@ -45,7 +45,7 @@ impl RollupBlueprint for MockDemoRollup { fn new(network: Network) -> Self { use_network_forks(network); - Self { _network: network } + Self { network } } fn create_rpc_methods( @@ -134,7 +134,7 @@ impl RollupBlueprint for MockDemoRollup { ledger_db: LedgerDB, proof_sampling_number: usize, ) -> Self::ProverService { - let vm = Risc0BonsaiHost::new(ledger_db.clone()); + let vm = Risc0BonsaiHost::new(ledger_db.clone(), self.network); let proof_mode = match proving_mode { ProverGuestRunConfig::Skip => ProofGenMode::Skip, diff --git a/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs b/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs index afb616b419..78e465c8f3 100644 --- a/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs +++ b/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs @@ -9,7 +9,7 @@ use bitcoin_da::service::{BitcoinService, BitcoinServiceConfig, FINALITY_DEPTH}; use bitcoin_da::spec::RollupParams; use citrea_common::tasks::manager::TaskManager; use citrea_e2e::config::{ - BatchProverConfig, LightClientProverConfig, ProverGuestRunConfig, SequencerConfig, + BatchProverConfig, CitreaMode, LightClientProverConfig, ProverGuestRunConfig, SequencerConfig, SequencerMempoolConfig, TestCaseConfig, TestCaseEnv, }; use citrea_e2e::framework::TestFramework; @@ -19,13 +19,14 @@ use citrea_e2e::test_case::{TestCase, TestCaseRunner}; use citrea_e2e::traits::NodeT; use citrea_e2e::Result; use citrea_light_client_prover::rpc::LightClientProverRpcClient; -use citrea_primitives::forks::{fork_from_block_number, get_forks}; +use citrea_primitives::forks::{fork_from_block_number, get_forks, use_network_forks}; use citrea_primitives::{TO_BATCH_PROOF_PREFIX, TO_LIGHT_CLIENT_PREFIX}; use sov_ledger_rpc::LedgerRpcClient; use sov_modules_api::fork::ForkManager; use sov_modules_api::SpecId; use sov_rollup_interface::da::{DaTxRequest, SequencerCommitment}; use sov_rollup_interface::rpc::VerifiedBatchProofResponse; +use sov_rollup_interface::Network; use tokio::time::sleep; use super::get_citrea_path; @@ -72,13 +73,6 @@ impl TestCase for BasicProverTest { } } - fn batch_prover_config() -> BatchProverConfig { - BatchProverConfig { - use_latest_elf: false, - ..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(); @@ -165,13 +159,6 @@ impl TestCase for SkipPreprovenCommitmentsTest { } } - fn batch_prover_config() -> BatchProverConfig { - BatchProverConfig { - use_latest_elf: false, - ..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(); @@ -551,6 +538,15 @@ impl TestCase for ForkElfSwitchingTest { with_batch_prover: true, with_full_node: true, with_light_client_prover: true, + mode: CitreaMode::DevAllForks, + ..Default::default() + } + } + + fn light_client_prover_config() -> LightClientProverConfig { + LightClientProverConfig { + initial_da_height: 171, + enable_recovery: false, ..Default::default() } } @@ -569,21 +565,6 @@ impl TestCase for ForkElfSwitchingTest { } } - fn batch_prover_config() -> BatchProverConfig { - BatchProverConfig { - use_latest_elf: false, - ..Default::default() - } - } - - fn light_client_prover_config() -> LightClientProverConfig { - LightClientProverConfig { - initial_da_height: 171, - enable_recovery: false, - ..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(); @@ -693,6 +674,8 @@ impl TestCase for ForkElfSwitchingTest { #[tokio::test] async fn test_fork_elf_switching() -> Result<()> { + use_network_forks(Network::TestNetworkWithForks); + TestCaseRunner::new(ForkElfSwitchingTest) .set_citrea_path(get_citrea_path()) .run() diff --git a/bin/citrea/tests/bitcoin_e2e/light_client_test.rs b/bin/citrea/tests/bitcoin_e2e/light_client_test.rs index 2f494d49c8..84dcabb523 100644 --- a/bin/citrea/tests/bitcoin_e2e/light_client_test.rs +++ b/bin/citrea/tests/bitcoin_e2e/light_client_test.rs @@ -11,8 +11,8 @@ use citrea_batch_prover::rpc::BatchProverRpcClient; use citrea_batch_prover::GroupCommitments; use citrea_common::tasks::manager::TaskManager; use citrea_e2e::config::{ - BatchProverConfig, LightClientProverConfig, SequencerConfig, SequencerMempoolConfig, - TestCaseConfig, + BatchProverConfig, CitreaMode, LightClientProverConfig, SequencerConfig, + SequencerMempoolConfig, TestCaseConfig, }; use citrea_e2e::framework::TestFramework; use citrea_e2e::node::NodeKind; @@ -42,6 +42,7 @@ impl TestCase for LightClientProvingTest { with_batch_prover: true, with_light_client_prover: true, with_full_node: true, + mode: CitreaMode::DevAllForks, ..Default::default() } } @@ -57,7 +58,6 @@ impl TestCase for LightClientProvingTest { fn batch_prover_config() -> BatchProverConfig { BatchProverConfig { enable_recovery: false, - use_latest_elf: false, ..Default::default() } } @@ -172,6 +172,7 @@ impl TestCase for LightClientProvingTestMultipleProofs { with_batch_prover: true, with_light_client_prover: true, with_full_node: true, + mode: CitreaMode::DevAllForks, ..Default::default() } } @@ -193,7 +194,6 @@ impl TestCase for LightClientProvingTestMultipleProofs { BatchProverConfig { enable_recovery: false, proof_sampling_number: 99999999, - use_latest_elf: false, ..Default::default() } } @@ -245,11 +245,7 @@ impl TestCase for LightClientProvingTestMultipleProofs { batch_prover .client .http_client() - .prove( - commitment_l1_height, - false, - Some(GroupCommitments::OneByOne), - ) + .prove(commitment_l1_height, Some(GroupCommitments::OneByOne)) .await .unwrap(); @@ -374,11 +370,7 @@ impl TestCase for LightClientProvingTestMultipleProofs { batch_prover .client .http_client() - .prove( - commitment_l1_height, - false, - Some(GroupCommitments::OneByOne), - ) + .prove(commitment_l1_height, Some(GroupCommitments::OneByOne)) .await .unwrap(); @@ -467,6 +459,7 @@ impl TestCase for LightClientBatchProofMethodIdUpdateTest { with_sequencer: true, with_batch_prover: true, with_light_client_prover: true, + mode: CitreaMode::DevAllForks, ..Default::default() } } @@ -482,7 +475,6 @@ impl TestCase for LightClientBatchProofMethodIdUpdateTest { fn batch_prover_config() -> BatchProverConfig { BatchProverConfig { enable_recovery: false, - use_latest_elf: false, ..Default::default() } } diff --git a/bin/citrea/tests/e2e/mod.rs b/bin/citrea/tests/e2e/mod.rs index 227904c576..866c73c135 100644 --- a/bin/citrea/tests/e2e/mod.rs +++ b/bin/citrea/tests/e2e/mod.rs @@ -96,7 +96,6 @@ async fn test_all_flow() { proving_mode: sov_stf_runner::ProverGuestRunConfig::Execute, proof_sampling_number: 0, enable_recovery: true, - use_latest_elf: true, }), None, rollup_config, diff --git a/bin/citrea/tests/e2e/proving.rs b/bin/citrea/tests/e2e/proving.rs index 7ffbea9c15..fd93c6a6a0 100644 --- a/bin/citrea/tests/e2e/proving.rs +++ b/bin/citrea/tests/e2e/proving.rs @@ -64,7 +64,6 @@ async fn full_node_verify_proof_and_store() { proving_mode: sov_stf_runner::ProverGuestRunConfig::Execute, proof_sampling_number: 0, enable_recovery: true, - use_latest_elf: true, }), None, rollup_config, @@ -247,7 +246,6 @@ async fn test_batch_prover_prove_rpc() { // Make it impossible for proving to happen proof_sampling_number: 1_000_000, enable_recovery: true, - use_latest_elf: true, }), None, rollup_config, @@ -301,7 +299,7 @@ async fn test_batch_prover_prove_rpc() { // Trigger proving via the RPC endpoint prover_node_test_client - .batch_prover_prove(3, true, Some(GroupCommitments::Normal)) + .batch_prover_prove(3, Some(GroupCommitments::Normal)) .await; // wait here until we see from prover's rpc that it finished proving diff --git a/bin/citrea/tests/e2e/reopen.rs b/bin/citrea/tests/e2e/reopen.rs index bafb3326cf..6f65d67a68 100644 --- a/bin/citrea/tests/e2e/reopen.rs +++ b/bin/citrea/tests/e2e/reopen.rs @@ -330,10 +330,7 @@ async fn test_reopen_prover() -> Result<(), anyhow::Error> { start_rollup( prover_node_port_tx, GenesisPaths::from_dir(TEST_DATA_GENESIS_PATH), - Some(BatchProverConfig { - use_latest_elf: true, - ..Default::default() - }), + Some(BatchProverConfig::default()), None, rollup_config, None, @@ -402,10 +399,7 @@ async fn test_reopen_prover() -> Result<(), anyhow::Error> { start_rollup( prover_node_port_tx, GenesisPaths::from_dir(TEST_DATA_GENESIS_PATH), - Some(BatchProverConfig { - use_latest_elf: true, - ..Default::default() - }), + Some(BatchProverConfig::default()), None, rollup_config, None, @@ -458,10 +452,7 @@ async fn test_reopen_prover() -> Result<(), anyhow::Error> { start_rollup( prover_node_port_tx, GenesisPaths::from_dir(TEST_DATA_GENESIS_PATH), - Some(BatchProverConfig { - use_latest_elf: true, - ..Default::default() - }), + Some(BatchProverConfig::default()), None, rollup_config, None, diff --git a/bin/citrea/tests/e2e/syncing.rs b/bin/citrea/tests/e2e/syncing.rs index 9c87eade8f..ca02a24833 100644 --- a/bin/citrea/tests/e2e/syncing.rs +++ b/bin/citrea/tests/e2e/syncing.rs @@ -299,7 +299,6 @@ async fn test_prover_sync_with_commitments() -> Result<(), anyhow::Error> { proving_mode: sov_stf_runner::ProverGuestRunConfig::Execute, proof_sampling_number: 0, enable_recovery: true, - use_latest_elf: true, }), None, rollup_config, diff --git a/bin/citrea/tests/test_client/mod.rs b/bin/citrea/tests/test_client/mod.rs index f2247abadc..a372eb1ed3 100644 --- a/bin/citrea/tests/test_client/mod.rs +++ b/bin/citrea/tests/test_client/mod.rs @@ -728,13 +728,12 @@ impl TestClient { pub(crate) async fn batch_prover_prove( &self, l1_height: u64, - use_latest_elf: bool, group_commitments: Option, ) { self.http_client .request( "batchProver_prove", - rpc_params![l1_height, use_latest_elf, group_commitments], + rpc_params![l1_height, group_commitments], ) .await .unwrap() diff --git a/crates/batch-prover/src/da_block_handler.rs b/crates/batch-prover/src/da_block_handler.rs index 57e176601b..b587dcf4dd 100644 --- a/crates/batch-prover/src/da_block_handler.rs +++ b/crates/batch-prover/src/da_block_handler.rs @@ -260,7 +260,6 @@ where l1_block, sequencer_commitments, inputs, - self.prover_config.use_latest_elf, ) .await?; } else { @@ -293,7 +292,6 @@ where self.ledger_db.clone(), txs_and_proofs, self.code_commitments_by_spec.clone(), - self.prover_config.use_latest_elf, ) .await?; diff --git a/crates/batch-prover/src/proving.rs b/crates/batch-prover/src/proving.rs index c0340d9092..41434911c9 100644 --- a/crates/batch-prover/src/proving.rs +++ b/crates/batch-prover/src/proving.rs @@ -211,7 +211,6 @@ where Ok((sequencer_commitments, batch_proof_circuit_inputs)) } -#[allow(clippy::too_many_arguments)] pub(crate) async fn prove_l1( prover_service: Arc, ledger: DB, @@ -220,7 +219,6 @@ pub(crate) async fn prove_l1( l1_block: &Da::FilteredBlock, sequencer_commitments: Vec, inputs: Vec>, - use_latest_elf: bool, ) -> anyhow::Result<()> where Da: DaService, @@ -248,11 +246,7 @@ where let seq_com = sequencer_commitments.get(i).expect("Commitment exists"); let last_l2_height = seq_com.l2_end_block_number; - let mut current_spec = fork_from_block_number(last_l2_height).spec_id; - - if use_latest_elf { - current_spec = SpecId::Fork1; - } + let current_spec = fork_from_block_number(last_l2_height).spec_id; let elf = elfs_by_spec .get(¤t_spec) @@ -288,7 +282,6 @@ where ledger.clone(), txs_and_proofs, code_commitments_by_spec.clone(), - use_latest_elf, ) .await?; @@ -331,7 +324,6 @@ pub(crate) async fn extract_and_store_proof( ledger_db: DB, txs_and_proofs: Vec<(::TransactionId, Proof)>, code_commitments_by_spec: HashMap, - use_latest_elf: bool, ) -> Result<(), anyhow::Error> where Da: DaService, @@ -350,7 +342,7 @@ where // l1_height => (tx_id, proof, circuit_output) // save proof along with tx id to db, should be queryable by slot number or slot hash - let (mut last_active_spec_id, circuit_output) = match Vm::extract_output::< + let (last_active_spec_id, circuit_output) = match Vm::extract_output::< BatchProofCircuitOutput<::Spec, StateRoot>, >(&proof) { @@ -384,10 +376,6 @@ where } }; - if use_latest_elf { - last_active_spec_id = SpecId::Fork1; - } - let code_commitment = code_commitments_by_spec .get(&last_active_spec_id) .expect("Proof public input must contain valid spec id"); diff --git a/crates/batch-prover/src/rpc.rs b/crates/batch-prover/src/rpc.rs index 49c7b5604e..b28725b82c 100644 --- a/crates/batch-prover/src/rpc.rs +++ b/crates/batch-prover/src/rpc.rs @@ -75,7 +75,6 @@ pub trait BatchProverRpc { async fn prove( &self, l1_height: u64, - use_latest_elf: bool, group_commitments: Option, ) -> RpcResult<()>; } @@ -203,7 +202,6 @@ where async fn prove( &self, l1_height: u64, - use_latest_elf: bool, group_commitments: Option, ) -> RpcResult<()> { let l1_block: ::FilteredBlock = self @@ -245,7 +243,6 @@ where &l1_block, sequencer_commitments, inputs, - use_latest_elf, ) .await .map_err(|e| { diff --git a/crates/bitcoin-da/src/verifier.rs b/crates/bitcoin-da/src/verifier.rs index 577e86ee1d..5a2fd4ce05 100644 --- a/crates/bitcoin-da/src/verifier.rs +++ b/crates/bitcoin-da/src/verifier.rs @@ -258,7 +258,7 @@ impl DaVerifier for BitcoinVerifier { latest_da_state.unwrap_or(&INITIAL_SIGNET_STATE), block_header, ), - Network::Nightly => { + Network::Nightly | Network::TestNetworkWithForks => { // For regtest, if this is the first light client proof, we always // consider the block valid with respect to its parent block, so // it can start from anywhere. diff --git a/crates/common/src/config.rs b/crates/common/src/config.rs index 20c8ed34ae..35258c95ba 100644 --- a/crates/common/src/config.rs +++ b/crates/common/src/config.rs @@ -239,8 +239,6 @@ pub struct BatchProverConfig { pub proof_sampling_number: usize, /// If true prover will try to recover ongoing proving sessions pub enable_recovery: bool, - /// Whether to always use latest ELF or not - pub use_latest_elf: bool, } /// Prover configuration @@ -262,9 +260,6 @@ impl Default for BatchProverConfig { proving_mode: ProverGuestRunConfig::Execute, proof_sampling_number: 0, enable_recovery: true, - // defaults to false. beacuse in production we don't want to accedentially set this to true. - // true actually applies to testing mostly. - use_latest_elf: false, } } } @@ -286,10 +281,6 @@ impl FromEnv for BatchProverConfig { proving_mode: serde_json::from_str(&format!("\"{}\"", std::env::var("PROVING_MODE")?))?, proof_sampling_number: std::env::var("PROOF_SAMPLING_NUMBER")?.parse()?, enable_recovery: std::env::var("ENABLE_RECOVERY")?.parse()?, - use_latest_elf: std::env::var("USE_LATEST_ELF")? - .parse() - .ok() - .unwrap_or(false), }) } } @@ -461,7 +452,7 @@ mod tests { sequencer_public_key = "0000000000000000000000000000000000000000000000000000000000000000" sequencer_da_pub_key = "7777777777777777777777777777777777777777777777777777777777777777" prover_da_pub_key = "" - + [rpc] bind_host = "127.0.0.1" bind_port = 12345 @@ -472,11 +463,11 @@ mod tests { [da] sender_address = "0000000000000000000000000000000000000000000000000000000000000000" db_path = "/tmp/da" - + [storage] path = "/tmp/rollup" db_max_open_files = 123 - + [runner] include_tx_body = true sequencer_client_url = "http://0.0.0.0:12346" @@ -535,7 +526,6 @@ mod tests { proving_mode = "skip" proof_sampling_number = 500 enable_recovery = true - use_latest_elf = false "#; let config_file = create_config_from(config); @@ -545,7 +535,6 @@ mod tests { proving_mode: ProverGuestRunConfig::Skip, proof_sampling_number: 500, enable_recovery: true, - use_latest_elf: false, }; assert_eq!(config, expected); } @@ -598,7 +587,6 @@ mod tests { std::env::set_var("PROVING_MODE", "skip"); std::env::set_var("PROOF_SAMPLING_NUMBER", "500"); std::env::set_var("ENABLE_RECOVERY", "true"); - std::env::set_var("USE_LATEST_ELF", "false"); let prover_config = BatchProverConfig::from_env().unwrap(); @@ -606,7 +594,6 @@ mod tests { proving_mode: ProverGuestRunConfig::Skip, proof_sampling_number: 500, enable_recovery: true, - use_latest_elf: false, }; assert_eq!(prover_config, expected); } diff --git a/crates/primitives/src/forks.rs b/crates/primitives/src/forks.rs index 1b37cde08c..0a905c87e8 100644 --- a/crates/primitives/src/forks.rs +++ b/crates/primitives/src/forks.rs @@ -17,6 +17,7 @@ pub fn use_network_forks(network: Network) { Network::Testnet => &TESTNET_FORKS, Network::Devnet => &DEVNET_FORKS, Network::Nightly => &NIGHTLY_FORKS, + Network::TestNetworkWithForks => &ALL_FORKS, }; #[cfg(not(feature = "testing"))] @@ -56,19 +57,18 @@ 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), + Fork::new(SpecId::Fork1, u64::MAX), ]; pub const DEVNET_FORKS: [Fork; 2] = [ Fork::new(SpecId::Genesis, 0), - Fork::new(SpecId::Fork1, 999_999_999), + Fork::new(SpecId::Fork1, u64::MAX), ]; -#[cfg(feature = "testing")] -pub const NIGHTLY_FORKS: [Fork; 2] = [Fork::new(SpecId::Genesis, 0), Fork::new(SpecId::Fork1, 100)]; -#[cfg(not(feature = "testing"))] pub const NIGHTLY_FORKS: [Fork; 1] = [Fork::new(SpecId::Fork1, 0)]; +pub const ALL_FORKS: [Fork; 2] = [Fork::new(SpecId::Genesis, 0), Fork::new(SpecId::Fork1, 100)]; + const _CHECK_FORKS: () = { if !verify_forks(&MAINNET_FORKS) || !verify_forks(&TESTNET_FORKS) diff --git a/crates/risc0/Cargo.toml b/crates/risc0/Cargo.toml index 1e0534df6e..b7b1ee0914 100644 --- a/crates/risc0/Cargo.toml +++ b/crates/risc0/Cargo.toml @@ -25,6 +25,7 @@ tracing = { workspace = true } [features] default = [] +testing = [] native = [ "dep:sov-db", "dep:metrics", diff --git a/crates/risc0/src/host.rs b/crates/risc0/src/host.rs index a21f31af99..43c8f8a25b 100644 --- a/crates/risc0/src/host.rs +++ b/crates/risc0/src/host.rs @@ -8,6 +8,7 @@ use risc0_zkvm::{ }; use sov_db::ledger_db::LedgerDB; use sov_rollup_interface::zk::{Proof, Zkvm, ZkvmHost}; +use sov_rollup_interface::Network; use tracing::{debug, info}; use crate::guest::Risc0Guest; @@ -39,11 +40,13 @@ pub struct Risc0BonsaiHost { env: Vec, assumptions: Vec, _ledger_db: LedgerDB, + #[cfg(feature = "testing")] + network: Network, } impl Risc0BonsaiHost { /// Create a new Risc0Host to prove the given binary. - pub fn new(ledger_db: LedgerDB) -> Self { + pub fn new(ledger_db: LedgerDB, _network: Network) -> Self { match std::env::var("RISC0_PROVER") { Ok(prover) => match prover.as_str() { "bonsai" => { @@ -80,6 +83,8 @@ impl Risc0BonsaiHost { env: Default::default(), assumptions: vec![], _ledger_db: ledger_db, + #[cfg(feature = "testing")] + network: _network, } } } @@ -122,6 +127,13 @@ impl ZkvmHost for Risc0BonsaiHost { tracing::debug!("{:?} assumptions added to the env", self.assumptions.len()); + #[cfg(feature = "testing")] + { + if self.network == Network::TestNetworkWithForks { + env.env_var("ALL_FORKS", "1"); + } + } + let env = env.write_slice(&self.env).build().unwrap(); // The `RISC0_PROVER` environment variable, if specified, will select the @@ -134,6 +146,7 @@ impl ZkvmHost for Risc0BonsaiHost { let prover = default_prover(); tracing::info!("Starting risc0 proving"); + let ProveInfo { receipt, stats } = prover.prove_with_opts(env, &elf, &ProverOpts::groth16())?; diff --git a/crates/sovereign-sdk/rollup-interface/src/network.rs b/crates/sovereign-sdk/rollup-interface/src/network.rs index c66c77dc4a..a80f08582e 100644 --- a/crates/sovereign-sdk/rollup-interface/src/network.rs +++ b/crates/sovereign-sdk/rollup-interface/src/network.rs @@ -1,7 +1,7 @@ use core::fmt::Display; /// The network currently running. -#[derive(Copy, Clone, Default, Debug)] +#[derive(Copy, Clone, Default, Debug, PartialEq)] pub enum Network { /// Mainnet #[default] @@ -12,6 +12,8 @@ pub enum Network { Devnet, /// Nightly Nightly, + /// Regtest + TestNetworkWithForks, } impl Display for Network { @@ -28,6 +30,7 @@ impl Network { b"testnet" => Some(Network::Testnet), b"devnet" => Some(Network::Devnet), b"nightly" => Some(Network::Nightly), + b"testnetworkwithforks" => Some(Network::TestNetworkWithForks), _ => None, } } diff --git a/guests/risc0/batch-proof/bitcoin/Cargo.toml b/guests/risc0/batch-proof/bitcoin/Cargo.toml index 483c08c42e..55603e5721 100644 --- a/guests/risc0/batch-proof/bitcoin/Cargo.toml +++ b/guests/risc0/batch-proof/bitcoin/Cargo.toml @@ -8,7 +8,7 @@ resolver = "2" [dependencies] risc0-zkvm = { version = "1.2.0", default-features = false } -risc0-zkvm-platform = { version = "1.2.0" } +risc0-zkvm-platform = { version = "1.2.0", features = ["sys-getenv"] } anyhow = "1.0.95" bitcoin-da = { path = "../../../../crates/bitcoin-da", default-features = false } 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 index 271e4290ff..92eafd3112 100644 --- a/guests/risc0/batch-proof/bitcoin/src/bin/batch_proof_bitcoin.rs +++ b/guests/risc0/batch-proof/bitcoin/src/bin/batch_proof_bitcoin.rs @@ -1,7 +1,9 @@ #![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::forks::{ + ALL_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; @@ -17,12 +19,10 @@ 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"), - } - } + Some(network) => match Network::const_from_str(network) { + Some(network) => network, + None => panic!("Invalid CITREA_NETWORK value"), + }, None => Network::Nightly, }; @@ -31,7 +31,7 @@ const SEQUENCER_PUBLIC_KEY: [u8; 32] = { Network::Mainnet => "0000000000000000000000000000000000000000000000000000000000000000", Network::Testnet => "4682a70af1d3fae53a5a26b682e2e75f7a1de21ad5fc8d61794ca889880d39d1", Network::Devnet => "52f41a5076498d1ae8bdfa57d19e91e3c2c94b6de21985d099cd48cfa7aef174", - Network::Nightly => { + Network::Nightly | Network::TestNetworkWithForks => { match option_env!("SEQUENCER_PUBLIC_KEY") { Some(hex_pub_key) => hex_pub_key, None => "204040e364c10f2bec9c1fe500a1cd4c247c89d650a01ed7e82caba867877c21", @@ -50,7 +50,7 @@ const SEQUENCER_DA_PUBLIC_KEY: [u8; 33] = { Network::Mainnet => "030000000000000000000000000000000000000000000000000000000000000000", Network::Testnet => "03015a7c4d2cc1c771198686e2ebef6fe7004f4136d61f6225b061d1bb9b821b9b", Network::Devnet => "039cd55f9b3dcf306c4d54f66cd7c4b27cc788632cd6fb73d80c99d303c6536486", - Network::Nightly => { + Network::Nightly | Network::TestNetworkWithForks => { match option_env!("SEQUENCER_DA_PUB_KEY") { Some(hex_pub_key) => hex_pub_key, None => "02588d202afcc1ee4ab5254c7847ec25b9a135bbda0f2bc69ee1a714749fd77dc9", @@ -69,8 +69,19 @@ const FORKS: &[Fork] = match NETWORK { Network::Testnet => &TESTNET_FORKS, Network::Devnet => &DEVNET_FORKS, Network::Nightly => &NIGHTLY_FORKS, + Network::TestNetworkWithForks => &ALL_FORKS, }; +fn get_forks() -> &'static [Fork] { + #[cfg(feature = "testing")] + { + if std::env::var("ALL_FORKS") == Ok(String::from("1")) { + return &ALL_FORKS; + } + } + FORKS +} + pub fn main() { let guest = Risc0Guest::new(); let storage = ZkStorage::new(); @@ -87,7 +98,13 @@ pub fn main() { 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) + .run_sequencer_commitments_in_da_slot( + data, + storage, + &SEQUENCER_PUBLIC_KEY, + &SEQUENCER_DA_PUBLIC_KEY, + get_forks(), + ) .expect("Prover must be honest"); guest.commit(&out); diff --git a/guests/risc0/batch-proof/mock/Cargo.toml b/guests/risc0/batch-proof/mock/Cargo.toml index c8290038d7..97844806ff 100644 --- a/guests/risc0/batch-proof/mock/Cargo.toml +++ b/guests/risc0/batch-proof/mock/Cargo.toml @@ -8,7 +8,7 @@ resolver = "2" [dependencies] risc0-zkvm = { version = "1.2.0", default-features = false } -risc0-zkvm-platform = { version = "1.2.0" } +risc0-zkvm-platform = { version = "1.2.0", features = ["sys-getenv"] } anyhow = "1.0.95" citrea-primitives = { path = "../../../../crates/primitives" } 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 index 8b45cb0e59..8398abbb58 100644 --- 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 @@ -24,7 +24,7 @@ const L2_GENESIS_ROOT: [u8; 32] = { // 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") { + Network::Nightly | Network::TestNetworkWithForks => match option_env!("L2_GENESIS_ROOT") { Some(hex_root) => hex_root, None => "dacb59b0ff5d16985a8418235133eee37758a3ac1b76ab6d1f87c6df20e4d4da", }, @@ -64,18 +64,20 @@ const INITIAL_BATCH_PROOF_METHOD_IDS: &[(u64, [u32; 8])] = { ], // TODO: Update Network::Devnet => &[(0, [0; 8])], - Network::Nightly => match option_env!("BATCH_PROOF_METHOD_ID") { - Some(hex_method_id) => &[(0, decode_to_u32_array(hex_method_id))], - None => &[ - ( - 0, - decode_to_u32_array( - "382a4e434d1b4b0912604a9de8876e75ff7603680c90107d78f6f71784ef1922", + Network::Nightly | Network::TestNetworkWithForks => { + match option_env!("BATCH_PROOF_METHOD_ID") { + Some(hex_method_id) => &[(0, decode_to_u32_array(hex_method_id))], + None => &[ + ( + 0, + decode_to_u32_array( + "382a4e434d1b4b0912604a9de8876e75ff7603680c90107d78f6f71784ef1922", + ), ), - ), - (100, citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ID), - ], - }, + (100, citrea_risc0_batch_proof::BATCH_PROOF_BITCOIN_ID), + ], + } + } } }; @@ -84,10 +86,12 @@ const BATCH_PROVER_DA_PUBLIC_KEY: [u8; 33] = { 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", - }, + Network::Nightly | Network::TestNetworkWithForks => { + 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()) { @@ -101,10 +105,12 @@ pub const METHOD_ID_UPGRADE_AUTHORITY_DA_PUBLIC_KEY: [u8; 33] = { Network::Mainnet => "000000000000000000000000000000000000000000000000000000000000000000", Network::Testnet => "000000000000000000000000000000000000000000000000000000000000000000", Network::Devnet => "000000000000000000000000000000000000000000000000000000000000000000", - Network::Nightly => match option_env!("METHOD_ID_UPGRADE_AUTHORITY_DA_PUBLIC_KEY") { - Some(hex_pub_key) => hex_pub_key, - None => "0313c4ff65eb94999e0ac41cfe21592baa52910f5a5ada9074b816de4f560189db", - }, + Network::Nightly | Network::TestNetworkWithForks => { + match option_env!("METHOD_ID_UPGRADE_AUTHORITY_DA_PUBLIC_KEY") { + Some(hex_pub_key) => hex_pub_key, + None => "0313c4ff65eb94999e0ac41cfe21592baa52910f5a5ada9074b816de4f560189db", + } + } }; match const_hex::const_decode_to_array(hex_pub_key.as_bytes()) { diff --git a/guests/risc0/light-client-proof/mock/Cargo.toml b/guests/risc0/light-client-proof/mock/Cargo.toml index 1772416581..108c0d5b4c 100644 --- a/guests/risc0/light-client-proof/mock/Cargo.toml +++ b/guests/risc0/light-client-proof/mock/Cargo.toml @@ -8,7 +8,7 @@ resolver = "2" [dependencies] risc0-zkvm = { version = "1.2.0", default-features = false } -risc0-zkvm-platform = { version = "1.2.0" } +risc0-zkvm-platform = { version = "1.2.0", features = ["sys-getenv"] } anyhow = "1.0.95" sov-mock-da = { path = "../../../../crates/sovereign-sdk/adapters/mock-da", default-features = false }