diff --git a/Cargo.lock b/Cargo.lock index 8050443d5..c7a8ea7b6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1829,7 +1829,7 @@ dependencies = [ [[package]] name = "citrea-e2e" version = "0.1.0" -source = "git+https://github.com/chainwayxyz/citrea-e2e?rev=07914ec#07914ecfc5ce4ae0006faa4b359e086523e2513e" +source = "git+https://github.com/chainwayxyz/citrea-e2e?rev=faf3414#faf3414d9f6088788b1baa03454022f28470be51" dependencies = [ "anyhow", "async-trait", @@ -1842,8 +1842,8 @@ dependencies = [ "rand 0.8.5", "serde", "serde_json", - "sov-ledger-rpc 0.5.0-rc.1 (git+https://github.com/chainwayxyz/citrea?rev=a043984)", - "sov-rollup-interface 0.5.0-rc.1 (git+https://github.com/chainwayxyz/citrea?rev=a043984)", + "sov-ledger-rpc 0.5.0-rc.1 (git+https://github.com/chainwayxyz/citrea?rev=42693cc)", + "sov-rollup-interface 0.5.0-rc.1 (git+https://github.com/chainwayxyz/citrea?rev=42693cc)", "tempfile", "tokio", "toml", @@ -7322,11 +7322,11 @@ dependencies = [ [[package]] name = "sov-ledger-rpc" version = "0.5.0-rc.1" -source = "git+https://github.com/chainwayxyz/citrea?rev=a043984#a0439843a37801331279869a2eb57d985e2d296f" +source = "git+https://github.com/chainwayxyz/citrea?rev=42693cc#42693ccf14925734bd3882550138440f6c7e47fd" dependencies = [ "jsonrpsee", "serde", - "sov-rollup-interface 0.5.0-rc.1 (git+https://github.com/chainwayxyz/citrea?rev=a043984)", + "sov-rollup-interface 0.5.0-rc.1 (git+https://github.com/chainwayxyz/citrea?rev=42693cc)", ] [[package]] @@ -7524,7 +7524,7 @@ dependencies = [ [[package]] name = "sov-rollup-interface" version = "0.5.0-rc.1" -source = "git+https://github.com/chainwayxyz/citrea?rev=a043984#a0439843a37801331279869a2eb57d985e2d296f" +source = "git+https://github.com/chainwayxyz/citrea?rev=42693cc#42693ccf14925734bd3882550138440f6c7e47fd" dependencies = [ "anyhow", "async-trait", diff --git a/bin/citrea/Cargo.toml b/bin/citrea/Cargo.toml index 03a3a25b2..ea622063b 100644 --- a/bin/citrea/Cargo.toml +++ b/bin/citrea/Cargo.toml @@ -89,7 +89,7 @@ rustc_version_runtime = { workspace = true } # bitcoin-e2e dependencies bitcoin.workspace = true bitcoincore-rpc.workspace = true -citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "07914ec" } +citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "faf3414" } [build-dependencies] sp1-helper = { version = "3.0.0", default-features = false } diff --git a/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs b/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs index bf3aeea51..c4ac7a1db 100644 --- a/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs +++ b/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs @@ -93,7 +93,7 @@ impl TestCase for BasicProverTest { { // print some debug info about state diff - let state_diff = &proofs[0].state_transition.state_diff; + let state_diff = &proofs[0].proof_output.state_diff; let state_diff_size: usize = state_diff .iter() .map(|(k, v)| k.len() + v.as_ref().map(|v| v.len()).unwrap_or_default()) @@ -231,7 +231,7 @@ impl TestCase for SkipPreprovenCommitmentsTest { assert!(proofs .first() .unwrap() - .state_transition + .proof_output .preproven_commitments .is_empty()); @@ -302,7 +302,7 @@ impl TestCase for SkipPreprovenCommitmentsTest { proofs .first() .unwrap() - .state_transition + .proof_output .preproven_commitments .len(), 1 diff --git a/bin/citrea/tests/e2e/mod.rs b/bin/citrea/tests/e2e/mod.rs index 0bec8150d..1e125efe9 100644 --- a/bin/citrea/tests/e2e/mod.rs +++ b/bin/citrea/tests/e2e/mod.rs @@ -16,7 +16,7 @@ use citrea_evm::smart_contracts::SimpleStorageContract; use citrea_stf::genesis_config::GenesisPaths; use reth_primitives::{Address, BlockNumberOrTag, U256}; use sov_mock_da::{MockAddress, MockDaService}; -use sov_rollup_interface::rpc::{LastVerifiedProofResponse, SoftConfirmationStatus}; +use sov_rollup_interface::rpc::{LastVerifiedBatchProofResponse, SoftConfirmationStatus}; use sov_rollup_interface::services::da::DaService; use tokio::task::JoinHandle; @@ -207,7 +207,7 @@ async fn test_all_flow() { .await .unwrap(); - let LastVerifiedProofResponse { + let LastVerifiedBatchProofResponse { proof: last_proof, height: proof_l1_height, } = full_node_test_client @@ -219,15 +219,9 @@ async fn test_all_flow() { assert_eq!(proof_l1_height, 4); assert_eq!(last_proof.proof, full_node_proof[0].proof); - assert_eq!( - last_proof.state_transition, - full_node_proof[0].state_transition - ); + assert_eq!(last_proof.proof_output, full_node_proof[0].proof_output); - assert_eq!( - prover_proof.state_transition, - full_node_proof[0].state_transition - ); + assert_eq!(prover_proof.proof_output, full_node_proof[0].proof_output); full_node_test_client .ledger_get_soft_confirmation_status(5) @@ -299,7 +293,7 @@ async fn test_all_flow() { .await .unwrap(); - let LastVerifiedProofResponse { + let LastVerifiedBatchProofResponse { proof: last_proof, height: proof_l1_height, } = full_node_test_client @@ -309,14 +303,14 @@ async fn test_all_flow() { assert_eq!(proof_l1_height, 6); assert_eq!(last_proof.proof, full_node_proof_data[0].proof); assert_eq!( - last_proof.state_transition, - full_node_proof_data[0].state_transition + last_proof.proof_output, + full_node_proof_data[0].proof_output ); assert_eq!(prover_proof_data.proof, full_node_proof_data[0].proof); assert_eq!( - prover_proof_data.state_transition, - full_node_proof_data[0].state_transition + prover_proof_data.proof_output, + full_node_proof_data[0].proof_output ); let balance = full_node_test_client diff --git a/bin/citrea/tests/e2e/proving.rs b/bin/citrea/tests/e2e/proving.rs index c7b5c93d2..7550d9132 100644 --- a/bin/citrea/tests/e2e/proving.rs +++ b/bin/citrea/tests/e2e/proving.rs @@ -165,10 +165,7 @@ async fn full_node_verify_proof_and_store() { .unwrap(); assert_eq!(prover_proof.proof, full_node_proof[0].proof); - assert_eq!( - prover_proof.state_transition, - full_node_proof[0].state_transition - ); + assert_eq!(prover_proof.proof_output, full_node_proof[0].proof_output); full_node_test_client .ledger_get_soft_confirmation_status(5) @@ -343,10 +340,7 @@ async fn test_prover_prove_rpc() { .unwrap(); assert_eq!(prover_proof.proof, full_node_proof[0].proof); - assert_eq!( - prover_proof.state_transition, - full_node_proof[0].state_transition - ); + assert_eq!(prover_proof.proof_output, full_node_proof[0].proof_output); full_node_test_client .ledger_get_soft_confirmation_status(5) diff --git a/bin/citrea/tests/test_client/mod.rs b/bin/citrea/tests/test_client/mod.rs index c883499f9..a26c32e7b 100644 --- a/bin/citrea/tests/test_client/mod.rs +++ b/bin/citrea/tests/test_client/mod.rs @@ -20,8 +20,8 @@ use reth_rpc_types::trace::geth::{GethDebugTracingOptions, GethTrace}; use reth_rpc_types::RichBlock; use sequencer_client::GetSoftConfirmationResponse; use sov_rollup_interface::rpc::{ - BatchProofResponse, LastVerifiedProofResponse, SequencerCommitmentResponse, - SoftConfirmationResponse, SoftConfirmationStatus, VerifiedProofResponse, + BatchProofResponse, LastVerifiedBatchProofResponse, SequencerCommitmentResponse, + SoftConfirmationResponse, SoftConfirmationStatus, VerifiedBatchProofResponse, }; pub const SEND_ETH_GAS: u128 = 21001; @@ -546,7 +546,7 @@ impl TestClient { pub(crate) async fn ledger_get_verified_batch_proofs_by_slot_height( &self, height: u64, - ) -> Option> { + ) -> Option> { self.http_client .request( "ledger_getVerifiedBatchProofsBySlotHeight", @@ -558,7 +558,7 @@ impl TestClient { pub(crate) async fn ledger_get_last_verified_batch_proof( &self, - ) -> Option { + ) -> Option { self.http_client .request("ledger_getLastVerifiedBatchProof", rpc_params![]) .await diff --git a/crates/batch-prover/src/da_block_handler.rs b/crates/batch-prover/src/da_block_handler.rs index 78d1a590a..422e89e9d 100644 --- a/crates/batch-prover/src/da_block_handler.rs +++ b/crates/batch-prover/src/da_block_handler.rs @@ -181,8 +181,8 @@ where ) .await; - let (sequencer_commitments, state_transitions) = match data_to_prove { - Ok((commitments, transitions)) => (commitments, transitions), + let (sequencer_commitments, inputs) = match data_to_prove { + Ok((commitments, inputs)) => (commitments, inputs), Err(e) => match e { L1ProcessingError::NoSeqCommitments { l1_height } => { info!("No sequencer commitment found at height {}", l1_height,); @@ -243,7 +243,7 @@ where self.code_commitments_by_spec.clone(), l1_block.clone(), sequencer_commitments, - state_transitions, + inputs, ) .await?; } else { @@ -332,7 +332,7 @@ async fn sync_l1( } } -pub(crate) async fn get_state_transition_data_from_commitments< +pub(crate) async fn get_batch_proof_circuit_input_from_commitments< Da: DaService, DB: BatchProverLedgerOps, Witness: DeserializeOwned, diff --git a/crates/batch-prover/src/proving.rs b/crates/batch-prover/src/proving.rs index 1bfd5efed..f4509a044 100644 --- a/crates/batch-prover/src/proving.rs +++ b/crates/batch-prover/src/proving.rs @@ -10,18 +10,18 @@ use citrea_common::utils::{check_l2_range_exists, filter_out_proven_commitments} use serde::de::DeserializeOwned; use serde::Serialize; use sov_db::ledger_db::BatchProverLedgerOps; -use sov_db::schema::types::{BatchNumber, StoredBatchProof, StoredStateTransition}; +use sov_db::schema::types::{BatchNumber, StoredBatchProof, StoredBatchProofOutput}; use sov_modules_api::{BlobReaderTrait, SlotData, SpecId, Zkvm}; use sov_rollup_interface::da::{BlockHeaderTrait, DaNamespace, DaSpec, SequencerCommitment}; use sov_rollup_interface::rpc::SoftConfirmationStatus; use sov_rollup_interface::services::da::DaService; -use sov_rollup_interface::zk::{Proof, StateTransition, StateTransitionData, ZkvmHost}; +use sov_rollup_interface::zk::{BatchProofCircuitInput, BatchProofCircuitOutput, Proof, ZkvmHost}; use sov_stf_runner::ProverService; use tokio::sync::Mutex; use tracing::{debug, info}; use crate::da_block_handler::{ - break_sequencer_commitments_into_groups, get_state_transition_data_from_commitments, + break_sequencer_commitments_into_groups, get_batch_proof_circuit_input_from_commitments, }; use crate::errors::L1ProcessingError; @@ -36,7 +36,7 @@ pub(crate) async fn data_to_prove( ) -> Result< ( Vec, - Vec>, + Vec>, ), L1ProcessingError, > @@ -112,7 +112,7 @@ where _ => vec![(0..=sequencer_commitments.len() - 1)], }; - let mut state_transitions = vec![]; + let mut batch_proof_circuit_inputs = vec![]; for sequencer_commitments_range in ranges { let first_l2_height_of_l1 = @@ -123,7 +123,7 @@ where state_transition_witnesses, soft_confirmations, da_block_headers_of_soft_confirmations, - ) = get_state_transition_data_from_commitments( + ) = get_batch_proof_circuit_input_from_commitments( &sequencer_commitments[sequencer_commitments_range.clone()], &da_service, &ledger, @@ -160,31 +160,30 @@ where })? .expect("There should be a state root"); - let state_transition_data: StateTransitionData = - StateTransitionData { - initial_state_root, - final_state_root, - initial_batch_hash, - da_data: da_data.clone(), - da_block_header_of_commitments: da_block_header_of_commitments.clone(), - inclusion_proof: inclusion_proof.clone(), - completeness_proof: completeness_proof.clone(), - soft_confirmations, - state_transition_witnesses, - da_block_headers_of_soft_confirmations, - preproven_commitments: preproven_commitments.to_vec(), - sequencer_commitments_range: ( - *sequencer_commitments_range.start() as u32, - *sequencer_commitments_range.end() as u32, - ), - sequencer_public_key: sequencer_pub_key.clone(), - sequencer_da_public_key: sequencer_da_pub_key.clone(), - }; - - state_transitions.push(state_transition_data); + let input: BatchProofCircuitInput = BatchProofCircuitInput { + initial_state_root, + final_state_root, + initial_batch_hash, + da_data: da_data.clone(), + da_block_header_of_commitments: da_block_header_of_commitments.clone(), + inclusion_proof: inclusion_proof.clone(), + completeness_proof: completeness_proof.clone(), + soft_confirmations, + state_transition_witnesses, + da_block_headers_of_soft_confirmations, + preproven_commitments: preproven_commitments.to_vec(), + sequencer_commitments_range: ( + *sequencer_commitments_range.start() as u32, + *sequencer_commitments_range.end() as u32, + ), + sequencer_public_key: sequencer_pub_key.clone(), + sequencer_da_public_key: sequencer_da_pub_key.clone(), + }; + + batch_proof_circuit_inputs.push(input); } - Ok((sequencer_commitments, state_transitions)) + Ok((sequencer_commitments, batch_proof_circuit_inputs)) } pub(crate) async fn prove_l1( @@ -193,7 +192,7 @@ pub(crate) async fn prove_l1( code_commitments_by_spec: HashMap, l1_block: Da::FilteredBlock, sequencer_commitments: Vec, - state_transitions: Vec>, + inputs: Vec>, ) -> anyhow::Result<()> where Da: DaService, @@ -215,13 +214,10 @@ where .unwrap_or(vec![]); // Add each non-proven proof's data to ProverService - for state_transition_data in state_transitions { - if !state_transition_already_proven::( - &state_transition_data, - &submitted_proofs, - ) { + for input in inputs { + if !state_transition_already_proven::(&input, &submitted_proofs) { prover_service - .add_proof_data((borsh::to_vec(&state_transition_data)?, vec![])) + .add_proof_data((borsh::to_vec(&input)?, vec![])) .await; } } @@ -249,7 +245,7 @@ where } pub(crate) fn state_transition_already_proven( - state_transition: &StateTransitionData, + input: &BatchProofCircuitInput, proofs: &Vec, ) -> bool where @@ -264,10 +260,9 @@ where Witness: Default + BorshDeserialize + Serialize + DeserializeOwned, { for proof in proofs { - if proof.state_transition.initial_state_root == state_transition.initial_state_root.as_ref() - && proof.state_transition.final_state_root == state_transition.final_state_root.as_ref() - && proof.state_transition.sequencer_commitments_range - == state_transition.sequencer_commitments_range + if proof.proof_output.initial_state_root == input.initial_state_root.as_ref() + && proof.proof_output.final_state_root == input.final_state_root.as_ref() + && proof.proof_output.sequencer_commitments_range == input.sequencer_commitments_range { return true; } @@ -299,7 +294,7 @@ where // save proof along with tx id to db, should be queryable by slot number or slot hash let transition_data = Vm::extract_output::< ::Spec, - StateTransition<::Spec, StateRoot>, + BatchProofCircuitOutput<::Spec, StateRoot>, >(&proof) .expect("Proof should be deserializable"); @@ -315,7 +310,7 @@ where let slot_hash = transition_data.da_slot_hash.into(); - let stored_state_transition = StoredStateTransition { + let stored_batch_proof_output = StoredBatchProofOutput { initial_state_root: transition_data.initial_state_root.as_ref().to_vec(), final_state_root: transition_data.final_state_root.as_ref().to_vec(), state_diff: transition_data.state_diff, @@ -334,7 +329,7 @@ where l1_height, tx_id_u8, proof, - stored_state_transition, + stored_batch_proof_output, ) { panic!("Failed to put proof data in the ledger db: {}", e); } diff --git a/crates/batch-prover/src/rpc.rs b/crates/batch-prover/src/rpc.rs index 72b605a91..e81d500a7 100644 --- a/crates/batch-prover/src/rpc.rs +++ b/crates/batch-prover/src/rpc.rs @@ -24,7 +24,7 @@ use crate::proving::{data_to_prove, prove_l1}; pub struct ProverInputResponse { pub commitment_range: (u32, u32), pub l1_block_height: u64, - pub encoded_serialized_state_transition_data: String, + pub encoded_serialized_batch_proof_input: String, } pub(crate) struct RpcContext @@ -153,7 +153,7 @@ where ) })?; - let (_, state_transitions) = data_to_prove::( + let (_, inputs) = data_to_prove::( self.context.da_service.clone(), self.context.ledger.clone(), self.context.sequencer_pub_key.clone(), @@ -171,23 +171,23 @@ where ) })?; - let mut state_transition_responses = vec![]; + let mut batch_proof_circuit_input_responses = vec![]; - for state_transition_data in state_transitions { - let range_start = state_transition_data.sequencer_commitments_range.0; - let range_end = state_transition_data.sequencer_commitments_range.1; - let serialized_state_transition = serialize_state_transition(state_transition_data); + for input in inputs { + let range_start = input.sequencer_commitments_range.0; + let range_end = input.sequencer_commitments_range.1; + let serialized_circuit_input = serialize_batch_proof_circuit_input(input); let response = ProverInputResponse { commitment_range: (range_start, range_end), l1_block_height: l1_height, - encoded_serialized_state_transition_data: hex::encode(serialized_state_transition), + encoded_serialized_batch_proof_input: hex::encode(serialized_circuit_input), }; - state_transition_responses.push(response); + batch_proof_circuit_input_responses.push(response); } - Ok(state_transition_responses) + Ok(batch_proof_circuit_input_responses) } async fn prove(&self, l1_height: u64, group_commitments: Option) -> RpcResult<()> { @@ -204,24 +204,23 @@ where ) })?; - let (sequencer_commitments, state_transitions) = - data_to_prove::( - self.context.da_service.clone(), - self.context.ledger.clone(), - self.context.sequencer_pub_key.clone(), - self.context.sequencer_da_pub_key.clone(), - self.context.l1_block_cache.clone(), - l1_block.clone(), - group_commitments, + let (sequencer_commitments, inputs) = data_to_prove::( + self.context.da_service.clone(), + self.context.ledger.clone(), + self.context.sequencer_pub_key.clone(), + self.context.sequencer_da_pub_key.clone(), + self.context.l1_block_cache.clone(), + l1_block.clone(), + group_commitments, + ) + .await + .map_err(|e| { + ErrorObjectOwned::owned( + INTERNAL_ERROR_CODE, + INTERNAL_ERROR_MSG, + Some(format!("{e}",)), ) - .await - .map_err(|e| { - ErrorObjectOwned::owned( - INTERNAL_ERROR_CODE, - INTERNAL_ERROR_MSG, - Some(format!("{e}",)), - ) - })?; + })?; prove_l1::( self.context.prover_service.clone(), @@ -229,7 +228,7 @@ where self.context.code_commitments_by_spec.clone(), l1_block, sequencer_commitments, - state_transitions, + inputs, ) .await .map_err(|e| { @@ -244,7 +243,7 @@ where } } -fn serialize_state_transition(item: T) -> Vec { +fn serialize_batch_proof_circuit_input(item: T) -> Vec { borsh::to_vec(&item).expect("Risc0 hint serialization is infallible") } diff --git a/crates/batch-prover/tests/prover_tests.rs b/crates/batch-prover/tests/prover_tests.rs index e3830da92..1d3fb6881 100644 --- a/crates/batch-prover/tests/prover_tests.rs +++ b/crates/batch-prover/tests/prover_tests.rs @@ -9,7 +9,7 @@ use sov_mock_da::{ }; use sov_mock_zkvm::MockZkvm; use sov_rollup_interface::da::Time; -use sov_rollup_interface::zk::StateTransitionData; +use sov_rollup_interface::zk::BatchProofCircuitInput; use sov_stf_runner::mock::MockStf; use sov_stf_runner::ProverService; @@ -102,8 +102,8 @@ fn make_new_prover(thread_pool_size: usize, da_service: Arc) -> T fn make_transition_data( header_hash: MockHash, -) -> StateTransitionData<[u8; 0], Vec, MockDaSpec> { - StateTransitionData { +) -> BatchProofCircuitInput<[u8; 0], Vec, MockDaSpec> { + BatchProofCircuitInput { initial_state_root: [], final_state_root: [], initial_batch_hash: [0; 32], diff --git a/crates/citrea-stf/src/verifier.rs b/crates/citrea-stf/src/verifier.rs index db13ba1fe..99c187c32 100644 --- a/crates/citrea-stf/src/verifier.rs +++ b/crates/citrea-stf/src/verifier.rs @@ -3,7 +3,7 @@ use std::marker::PhantomData; use citrea_primitives::forks::FORKS; use sov_rollup_interface::da::{BlockHeaderTrait, DaNamespace, DaVerifier}; use sov_rollup_interface::stf::StateTransitionFunction; -use sov_rollup_interface::zk::{StateTransition, StateTransitionData, Zkvm, ZkvmGuest}; +use sov_rollup_interface::zk::{BatchProofCircuitInput, BatchProofCircuitOutput, Zkvm, ZkvmGuest}; /// Verifies a state transition pub struct StateTransitionVerifier @@ -39,7 +39,7 @@ where pre_state: Stf::PreState, ) -> Result<(), Da::Error> { println!("Running sequencer commitments in DA slot"); - let data: StateTransitionData = zkvm.read_from_host(); + 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"); @@ -79,7 +79,7 @@ where "Invalid final state root" ); - let out: StateTransition = StateTransition { + let out: BatchProofCircuitOutput = BatchProofCircuitOutput { initial_state_root: data.initial_state_root, final_state_root, initial_batch_hash: data.initial_batch_hash, diff --git a/crates/fullnode/src/da_block_handler.rs b/crates/fullnode/src/da_block_handler.rs index dc371db8c..3f953962e 100644 --- a/crates/fullnode/src/da_block_handler.rs +++ b/crates/fullnode/src/da_block_handler.rs @@ -15,14 +15,14 @@ use serde::de::DeserializeOwned; use serde::Serialize; use sov_db::ledger_db::NodeLedgerOps; use sov_db::schema::types::{ - BatchNumber, SlotNumber, StoredSoftConfirmation, StoredStateTransition, + BatchNumber, SlotNumber, StoredBatchProofOutput, StoredSoftConfirmation, }; use sov_modules_api::{Context, Zkvm}; use sov_rollup_interface::da::{BlockHeaderTrait, SequencerCommitment}; use sov_rollup_interface::rpc::SoftConfirmationStatus; use sov_rollup_interface::services::da::{DaService, SlotData}; use sov_rollup_interface::spec::SpecId; -use sov_rollup_interface::zk::{Proof, StateTransition, ZkvmHost}; +use sov_rollup_interface::zk::{BatchProofCircuitOutput, Proof, ZkvmHost}; use tokio::select; use tokio::sync::{mpsc, Mutex}; use tokio::time::{sleep, Duration}; @@ -296,13 +296,13 @@ where ); tracing::debug!("ZK proof: {:?}", proof); - let state_transition = Vm::extract_output::< + let batch_proof_output = Vm::extract_output::< ::Spec, - StateTransition<::Spec, StateRoot>, + BatchProofCircuitOutput<::Spec, StateRoot>, >(&proof) .expect("Proof should be deserializable"); - if state_transition.sequencer_da_public_key != self.sequencer_da_pub_key - || state_transition.sequencer_public_key != self.sequencer_pub_key + if batch_proof_output.sequencer_da_public_key != self.sequencer_da_pub_key + || batch_proof_output.sequencer_public_key != self.sequencer_pub_key { return Err(anyhow!( "Proof verification: Sequencer public key or sequencer da public key mismatch. Skipping proof." @@ -311,24 +311,24 @@ where let code_commitment = self .code_commitments_by_spec - .get(&state_transition.last_active_spec_id) + .get(&batch_proof_output.last_active_spec_id) .expect("Proof public input must contain valid spec id"); Vm::verify(proof.as_slice(), code_commitment) .map_err(|err| anyhow!("Failed to verify proof: {:?}. Skipping it...", err))?; - let stored_state_transition = StoredStateTransition { - initial_state_root: state_transition.initial_state_root.as_ref().to_vec(), - final_state_root: state_transition.final_state_root.as_ref().to_vec(), - state_diff: state_transition.state_diff, - da_slot_hash: state_transition.da_slot_hash.clone().into(), - sequencer_commitments_range: state_transition.sequencer_commitments_range, - sequencer_public_key: state_transition.sequencer_public_key, - sequencer_da_public_key: state_transition.sequencer_da_public_key, - preproven_commitments: state_transition.preproven_commitments.clone(), - validity_condition: borsh::to_vec(&state_transition.validity_condition).unwrap(), + let stored_batch_proof_output = StoredBatchProofOutput { + initial_state_root: batch_proof_output.initial_state_root.as_ref().to_vec(), + final_state_root: batch_proof_output.final_state_root.as_ref().to_vec(), + state_diff: batch_proof_output.state_diff, + da_slot_hash: batch_proof_output.da_slot_hash.clone().into(), + sequencer_commitments_range: batch_proof_output.sequencer_commitments_range, + sequencer_public_key: batch_proof_output.sequencer_public_key, + sequencer_da_public_key: batch_proof_output.sequencer_da_public_key, + preproven_commitments: batch_proof_output.preproven_commitments.clone(), + validity_condition: borsh::to_vec(&batch_proof_output.validity_condition).unwrap(), }; - let l1_hash = state_transition.da_slot_hash.into(); + let l1_hash = batch_proof_output.da_slot_hash.into(); // This is the l1 height where the sequencer commitment was read by the prover and proof generated by those commitments // We need to get commitments in this l1 height and set them as proven @@ -357,7 +357,7 @@ where commitments_on_da_slot.sort(); - let excluded_commitment_indices = state_transition.preproven_commitments.clone(); + let excluded_commitment_indices = batch_proof_output.preproven_commitments.clone(); let filtered_commitments: Vec = commitments_on_da_slot .into_iter() .enumerate() @@ -366,7 +366,7 @@ where .collect(); let l2_height = filtered_commitments - [state_transition.sequencer_commitments_range.0 as usize] + [batch_proof_output.sequencer_commitments_range.0 as usize] .l2_start_block_number; // Fetch the block prior to the one at l2_height so compare state roots @@ -381,21 +381,21 @@ where })?; if prior_soft_confirmation_post_state_root.as_ref() - != state_transition.initial_state_root.as_ref() + != batch_proof_output.initial_state_root.as_ref() { return Err(anyhow!( "Proof verification: For a known and verified sequencer commitment. Pre state root mismatch - expected 0x{} but got 0x{}. Skipping proof.", hex::encode(&prior_soft_confirmation_post_state_root), - hex::encode(&state_transition.initial_state_root) + hex::encode(&batch_proof_output.initial_state_root) ).into()); } for commitment in filtered_commitments .iter() - .skip(state_transition.sequencer_commitments_range.0 as usize) + .skip(batch_proof_output.sequencer_commitments_range.0 as usize) .take( - (state_transition.sequencer_commitments_range.1 - - state_transition.sequencer_commitments_range.0 + (batch_proof_output.sequencer_commitments_range.1 + - batch_proof_output.sequencer_commitments_range.0 + 1) as usize, ) { @@ -410,7 +410,7 @@ where self.ledger_db.update_verified_proof_data( l1_block.header().height(), proof.clone(), - stored_state_transition, + stored_batch_proof_output, )?; Ok(()) } diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs index 0a03702a9..4e0934dc1 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs @@ -24,7 +24,7 @@ use crate::schema::tables::{ }; use crate::schema::types::{ split_tx_for_storage, BatchNumber, L2HeightRange, SlotNumber, StoredBatchProof, - StoredLightClientProof, StoredSlot, StoredSoftConfirmation, StoredStateTransition, + StoredBatchProofOutput, StoredLightClientProof, StoredSlot, StoredSoftConfirmation, StoredVerifiedProof, }; @@ -545,18 +545,18 @@ impl BatchProverLedgerOps for LedgerDB { } /// Stores proof related data on disk, accessible via l1 slot height - #[instrument(level = "trace", skip(self, proof, state_transition), err, ret)] + #[instrument(level = "trace", skip(self, proof, proof_output), err, ret)] fn insert_batch_proof_data_by_l1_height( &self, l1_height: u64, l1_tx_id: [u8; 32], proof: Proof, - state_transition: StoredStateTransition, + proof_output: StoredBatchProofOutput, ) -> anyhow::Result<()> { let data_to_store = StoredBatchProof { l1_tx_id, proof, - state_transition, + proof_output, }; let proofs = self.db.get::(&SlotNumber(l1_height))?; match proofs { @@ -784,12 +784,12 @@ impl SequencerLedgerOps for LedgerDB { impl NodeLedgerOps for LedgerDB { /// Stores proof related data on disk, accessible via l1 slot height - #[instrument(level = "trace", skip(self, proof, state_transition), err, ret)] + #[instrument(level = "trace", skip(self, proof, proof_output), err, ret)] fn update_verified_proof_data( &self, l1_height: u64, proof: Proof, - state_transition: StoredStateTransition, + proof_output: StoredBatchProofOutput, ) -> anyhow::Result<()> { let verified_proofs = self .db @@ -799,7 +799,7 @@ impl NodeLedgerOps for LedgerDB { Some(mut verified_proofs) => { let stored_verified_proof = StoredVerifiedProof { proof, - state_transition, + proof_output, }; verified_proofs.push(stored_verified_proof); self.db.put::( @@ -811,7 +811,7 @@ impl NodeLedgerOps for LedgerDB { &SlotNumber(l1_height), &vec![StoredVerifiedProof { proof, - state_transition, + proof_output, }], ), } diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/rpc.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/rpc.rs index 0e86c657f..f5b9e826c 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/rpc.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/rpc.rs @@ -1,8 +1,8 @@ use serde::de::DeserializeOwned; use sov_rollup_interface::rpc::{ - sequencer_commitment_to_response, BatchProofResponse, LastVerifiedProofResponse, + sequencer_commitment_to_response, BatchProofResponse, LastVerifiedBatchProofResponse, LedgerRpcProvider, SequencerCommitmentResponse, SoftConfirmationIdentifier, - SoftConfirmationResponse, VerifiedProofResponse, + SoftConfirmationResponse, VerifiedBatchProofResponse, }; use crate::schema::tables::{ @@ -159,7 +159,7 @@ impl LedgerRpcProvider for LedgerDB { fn get_verified_proof_data_by_l1_height( &self, height: u64, - ) -> Result>, anyhow::Error> { + ) -> Result>, anyhow::Error> { match self .db .get::(&SlotNumber(height))? @@ -167,7 +167,7 @@ impl LedgerRpcProvider for LedgerDB { Some(stored_proofs) => Ok(Some( stored_proofs .into_iter() - .map(VerifiedProofResponse::from) + .map(VerifiedBatchProofResponse::from) .collect(), )), None => Ok(None), @@ -176,11 +176,11 @@ impl LedgerRpcProvider for LedgerDB { fn get_last_verified_batch_proof( &self, - ) -> Result, anyhow::Error> { + ) -> Result, anyhow::Error> { let mut iter = self.db.iter::()?; iter.seek_to_last(); match iter.next() { - Some(Ok(item)) => Ok(Some(LastVerifiedProofResponse { + Some(Ok(item)) => Ok(Some(LastVerifiedBatchProofResponse { proof: item.value[0].clone().into(), height: item.key.0, })), diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs index 2ceafa737..fc5197466 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs @@ -10,8 +10,8 @@ use sov_schema_db::SchemaBatch; use super::ItemNumbers; use crate::schema::types::{ - BatchNumber, L2HeightRange, SlotNumber, StoredBatchProof, StoredLightClientProof, StoredSlot, - StoredSoftConfirmation, StoredStateTransition, + BatchNumber, L2HeightRange, SlotNumber, StoredBatchProof, StoredBatchProofOutput, + StoredLightClientProof, StoredSlot, StoredSoftConfirmation, }; /// Shared ledger operations @@ -145,7 +145,7 @@ pub trait NodeLedgerOps: SharedLedgerOps { &self, l1_height: u64, proof: Proof, - state_transition: StoredStateTransition, + output: StoredBatchProofOutput, ) -> Result<()>; /// Get the most recent committed slot, if any @@ -167,7 +167,7 @@ pub trait BatchProverLedgerOps: SharedLedgerOps + Send + Sync { l1_height: u64, l1_tx_id: [u8; 32], proof: Proof, - state_transition: StoredStateTransition, + output: StoredBatchProofOutput, ) -> Result<()>; /// Gets proofs by L1 height 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 4db4e8f04..13f6dbcd6 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 @@ -5,8 +5,8 @@ use borsh::{BorshDeserialize, BorshSerialize}; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use sov_rollup_interface::rpc::{ - BatchProofResponse, HexTx, SoftConfirmationResponse, StateTransitionRpcResponse, TxIdentifier, - TxResponse, VerifiedProofResponse, + BatchProofOutputRpcResponse, BatchProofResponse, HexTx, SoftConfirmationResponse, TxIdentifier, + TxResponse, VerifiedBatchProofResponse, }; use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; use sov_rollup_interface::stf::{Event, EventKey, TransactionReceipt}; @@ -88,8 +88,8 @@ pub struct StoredBatchProof { pub l1_tx_id: [u8; 32], /// Proof pub proof: Proof, - /// State transition - pub state_transition: StoredStateTransition, + /// Output + pub proof_output: StoredBatchProofOutput, } impl From for BatchProofResponse { @@ -97,7 +97,7 @@ impl From for BatchProofResponse { Self { l1_tx_id: value.l1_tx_id, proof: value.proof, - state_transition: StateTransitionRpcResponse::from(value.state_transition), + proof_output: BatchProofOutputRpcResponse::from(value.proof_output), } } } @@ -108,21 +108,21 @@ pub struct StoredVerifiedProof { /// Verified Proof pub proof: Proof, /// State transition - pub state_transition: StoredStateTransition, + pub proof_output: StoredBatchProofOutput, } -impl From for VerifiedProofResponse { +impl From for VerifiedBatchProofResponse { fn from(value: StoredVerifiedProof) -> Self { Self { proof: value.proof, - state_transition: StateTransitionRpcResponse::from(value.state_transition), + proof_output: BatchProofOutputRpcResponse::from(value.proof_output), } } } /// The on-disk format for a state transition. #[derive(Debug, PartialEq, BorshDeserialize, BorshSerialize, Clone)] -pub struct StoredStateTransition { +pub struct StoredBatchProofOutput { /// The state of the rollup before the transition pub initial_state_root: Vec, /// The state of the rollup after the transition @@ -146,8 +146,8 @@ pub struct StoredStateTransition { pub validity_condition: Vec, } -impl From for StateTransitionRpcResponse { - fn from(value: StoredStateTransition) -> Self { +impl From for BatchProofOutputRpcResponse { + fn from(value: StoredBatchProofOutput) -> Self { Self { initial_state_root: value.initial_state_root, final_state_root: value.final_state_root, diff --git a/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/client.rs b/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/client.rs index af2580092..986197e71 100644 --- a/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/client.rs +++ b/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/client.rs @@ -6,7 +6,7 @@ use jsonrpsee::proc_macros::rpc; use sov_rollup_interface::rpc::{ BatchProofResponse, SequencerCommitmentResponse, SoftConfirmationResponse, - SoftConfirmationStatus, VerifiedProofResponse, + SoftConfirmationStatus, VerifiedBatchProofResponse, }; use crate::HexHash; @@ -89,9 +89,9 @@ pub trait Rpc { async fn get_verified_batch_proofs_by_slot_height( &self, height: u64, - ) -> RpcResult>>; + ) -> RpcResult>>; /// Gets last verified proog #[method(name = "getLastVerifiedBatchProof")] - async fn get_last_verified_batch_proof(&self) -> RpcResult>; + async fn get_last_verified_batch_proof(&self) -> RpcResult>; } diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs index f4f14f154..cac2038a7 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs @@ -196,7 +196,7 @@ pub use sov_rollup_interface::soft_confirmation::{ }; pub use sov_rollup_interface::stf::{Event, StateDiff}; pub use sov_rollup_interface::zk::{ - StateTransition, ValidityCondition, ValidityConditionChecker, Zkvm, + BatchProofCircuitOutput, ValidityCondition, ValidityConditionChecker, Zkvm, }; pub use sov_rollup_interface::{digest, BasicAddress, RollupAddress}; 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 28917ce27..4278e9469 100644 --- a/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs +++ b/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs @@ -216,25 +216,25 @@ pub struct BatchProofResponse { /// Proof pub proof: ProofRpcResponse, /// State transition - pub state_transition: StateTransitionRpcResponse, + pub proof_output: BatchProofOutputRpcResponse, } /// The rpc response of proof by l1 slot height #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct VerifiedProofResponse { +pub struct VerifiedBatchProofResponse { /// Proof pub proof: ProofRpcResponse, /// State transition - pub state_transition: StateTransitionRpcResponse, + pub proof_output: BatchProofOutputRpcResponse, } /// The rpc response of the last verified proof #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct LastVerifiedProofResponse { +pub struct LastVerifiedBatchProofResponse { /// Proof data - pub proof: VerifiedProofResponse, + pub proof: VerifiedBatchProofResponse, /// L1 height of the proof pub height: u64, } @@ -245,7 +245,7 @@ pub type ProofRpcResponse = Vec; /// The state transition response of ledger proof data rpc #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -pub struct StateTransitionRpcResponse { +pub struct BatchProofOutputRpcResponse { /// The state of the rollup before the transition #[serde(with = "hex::serde")] pub initial_state_root: Vec, @@ -452,12 +452,12 @@ pub trait LedgerRpcProvider { fn get_verified_proof_data_by_l1_height( &self, height: u64, - ) -> Result>, anyhow::Error>; + ) -> Result>, anyhow::Error>; /// Get last verified proof fn get_last_verified_batch_proof( &self, - ) -> Result, anyhow::Error>; + ) -> Result, anyhow::Error>; /// Get head soft confirmation fn get_head_soft_confirmation(&self) diff --git a/crates/sovereign-sdk/rollup-interface/src/state_machine/optimistic.rs b/crates/sovereign-sdk/rollup-interface/src/state_machine/optimistic.rs index 86ae31db8..ece7f648a 100644 --- a/crates/sovereign-sdk/rollup-interface/src/state_machine/optimistic.rs +++ b/crates/sovereign-sdk/rollup-interface/src/state_machine/optimistic.rs @@ -3,7 +3,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; use crate::da::DaSpec; -use crate::zk::StateTransition; +use crate::zk::BatchProofCircuitOutput; /// A proof that the attester was bonded at the transition num `transition_num`. /// For rollups using the `jmt`, this will be a `jmt::SparseMerkleProof` @@ -39,7 +39,7 @@ pub struct ChallengeContents { /// The rollup address of the originator of this challenge pub challenger_address: Address, /// The state transition that was proven - pub state_transition: StateTransition, + pub state_transition: BatchProofCircuitOutput, } #[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, Serialize, Deserialize)] 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 be6d122f3..3101cfec3 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 @@ -123,13 +123,13 @@ pub trait ValidityCondition: /// State diff produced by the Zk proof pub type CumulativeStateDiff = BTreeMap, Option>>; -/// The public output of a SNARK proof in Sovereign, this struct makes a claim that +/// The public output of a SNARK batch proof in Sovereign, this struct makes a claim that /// the state of the rollup has transitioned from `initial_state_root` to `final_state_root` -/// if and only if the condition `validity_condition` is satisfied. /// -/// The period of time covered by a state transition proof may be a single slot, or a range of slots on the DA layer. +/// The period of time covered by a state transition proof is a range of L2 blocks whose sequencer +/// commitments are included in the DA slot with hash `da_slot_hash`. The range is inclusive. #[derive(Clone, Debug, Serialize, Deserialize, BorshSerialize, BorshDeserialize, PartialEq, Eq)] -pub struct StateTransition { +pub struct BatchProofCircuitOutput { /// The state of the rollup before the transition pub initial_state_root: Root, /// The state of the rollup after the transition @@ -179,7 +179,7 @@ pub trait Matches { // StateTransitionFunction, DA, and Zkvm traits. #[serde(bound = "StateRoot: Serialize + DeserializeOwned, Witness: Serialize + DeserializeOwned")] /// Data required to verify a state transition. -pub struct StateTransitionData { +pub struct BatchProofCircuitInput { /// The state root before the state transition pub initial_state_root: StateRoot, /// The state root after the state transition