diff --git a/crates/batch-prover/src/proving.rs b/crates/batch-prover/src/proving.rs index 2c37bd123..99000ef02 100644 --- a/crates/batch-prover/src/proving.rs +++ b/crates/batch-prover/src/proving.rs @@ -324,7 +324,6 @@ where // save proof along with tx id to db, should be queryable by slot number or slot hash // TODO: select output version based on spec let (last_active_spec_id, circuit_output) = match Vm::extract_output::< - ::Spec, BatchProofCircuitOutput<::Spec, StateRoot>, >(&proof) { @@ -335,7 +334,6 @@ where Err(e) => { info!("Failed to extract post fork 1 output from proof: {:?}. Trying to extract pre fork 1 output", e); let output = Vm::extract_output::< - ::Spec, OldBatchProofCircuitOutput<::Spec, StateRoot>, >(&proof) .expect("Should be able to extract either pre or post fork 1 output"); diff --git a/crates/batch-prover/tests/prover_tests.rs b/crates/batch-prover/tests/prover_tests.rs index 0cc6ff093..dfa270164 100644 --- a/crates/batch-prover/tests/prover_tests.rs +++ b/crates/batch-prover/tests/prover_tests.rs @@ -357,10 +357,9 @@ async fn spawn_prove( } fn extract_output_header(proof: &Vec) -> MockBlockHeader { - MockZkvm::extract_output::< - MockDaSpec, - BatchProofCircuitInput<'static, [u8; 0], Vec, MockDaSpec, ()>, - >(proof) + MockZkvm::extract_output::, MockDaSpec, ()>>( + proof, + ) .unwrap() .da_block_header_of_commitments } diff --git a/crates/fullnode/src/da_block_handler.rs b/crates/fullnode/src/da_block_handler.rs index 8c1d6d8fa..9fcd21779 100644 --- a/crates/fullnode/src/da_block_handler.rs +++ b/crates/fullnode/src/da_block_handler.rs @@ -304,7 +304,6 @@ where // TODO: select output version based on spec let (last_active_spec_id, batch_proof_output) = match Vm::extract_output::< - ::Spec, BatchProofCircuitOutput<::Spec, StateRoot>, >(&proof) { @@ -315,7 +314,6 @@ where Err(e) => { info!("Failed to extract post fork 1 output from proof: {:?}. Trying to extract pre fork 1 output", e); let output = Vm::extract_output::< - ::Spec, OldBatchProofCircuitOutput<::Spec, StateRoot>, >(&proof) .expect("Should be able to extract either pre or post fork 1 output"); diff --git a/crates/light-client-prover/src/circuit.rs b/crates/light-client-prover/src/circuit.rs index b32559046..d782855e7 100644 --- a/crates/light-client-prover/src/circuit.rs +++ b/crates/light-client-prover/src/circuit.rs @@ -30,7 +30,7 @@ pub fn run_circuit( // Extract previous light client proof output let previous_light_client_proof_output = if let Some(journal) = input.previous_light_client_proof_journal { - let prev_output = G::verify_and_extract_output::( + let prev_output = G::verify_and_deserialize_output::( &journal, &input.light_client_proof_method_id.into(), ) @@ -205,16 +205,3 @@ pub fn run_circuit( batch_proof_method_ids, }) } - -#[test] -fn test_binary_search() { - let ve = [1, 4, 7, 9, 14]; - let idx = ve.binary_search(&4); // 1 - assert_eq!(idx, Ok(1)); - let idx = ve.binary_search(&100); // 5 - 1 - assert_eq!(idx, Err(5)); - let idx = ve.binary_search(&7); // 2 - assert_eq!(idx, Ok(2)); - let idx = ve.binary_search(&8); // 3-1 - assert_eq!(idx, Err(3)); -} diff --git a/crates/light-client-prover/src/da_block_handler.rs b/crates/light-client-prover/src/da_block_handler.rs index b1de72738..c123bc0e6 100644 --- a/crates/light-client-prover/src/da_block_handler.rs +++ b/crates/light-client-prover/src/da_block_handler.rs @@ -164,7 +164,6 @@ where for batch_proof in batch_proofs { if let DaDataLightClient::Complete(proof) = batch_proof { let last_l2_height = match Vm::extract_output::< - ::Spec, BatchProofCircuitOutput<::Spec, [u8; 32]>, >(&proof) { @@ -172,7 +171,6 @@ where Err(e) => { info!("Failed to extract post fork 1 output from proof: {:?}. Trying to extract pre fork 1 output", e); Vm::extract_output::< - ::Spec, OldBatchProofCircuitOutput<::Spec, [u8; 32]>, >(&proof) .map_err(|_| anyhow!("Proof should be deserializable"))?; @@ -262,7 +260,7 @@ where .prove(light_client_elf, circuit_input, assumptions) .await?; - let circuit_output = Vm::extract_output::(&proof) + let circuit_output = Vm::extract_output::(&proof) .expect("Should deserialize valid proof"); tracing::info!( diff --git a/crates/risc0/src/guest.rs b/crates/risc0/src/guest.rs index 6e0d2399f..781d4834f 100644 --- a/crates/risc0/src/guest.rs +++ b/crates/risc0/src/guest.rs @@ -55,7 +55,7 @@ impl Zkvm for Risc0Guest { Ok(T::try_from_slice(journal)?) } - fn verify_and_extract_output( + fn verify_and_deserialize_output( journal: &[u8], code_commitment: &Self::CodeCommitment, ) -> Result { diff --git a/crates/risc0/src/host.rs b/crates/risc0/src/host.rs index 0e53d7155..ad93b3b88 100644 --- a/crates/risc0/src/host.rs +++ b/crates/risc0/src/host.rs @@ -1,7 +1,4 @@ //! This module implements the [`ZkvmHost`] trait for the RISC0 VM. - -use std::io::Cursor; - use borsh::{BorshDeserialize, BorshSerialize}; use metrics::histogram; use risc0_zkvm::sha::Digest; @@ -162,9 +159,7 @@ impl ZkvmHost for Risc0BonsaiHost { Ok(serialized_receipt) } - fn extract_output( - proof: &Proof, - ) -> Result { + fn extract_output(proof: &Proof) -> Result { let receipt: Receipt = bincode::deserialize(proof)?; let journal = receipt.journal; @@ -225,11 +220,10 @@ impl Zkvm for Risc0BonsaiHost { } fn deserialize_output(journal: &[u8]) -> Result { - let mut reader = Cursor::new(journal); - Ok(T::deserialize_reader(&mut reader)?) + Ok(T::try_from_slice(journal)?) } - fn verify_and_extract_output( + fn verify_and_deserialize_output( serialized_proof: &[u8], code_commitment: &Self::CodeCommitment, ) -> Result { diff --git a/crates/sovereign-sdk/adapters/mock-zkvm/src/lib.rs b/crates/sovereign-sdk/adapters/mock-zkvm/src/lib.rs index c141815ea..85610da5b 100644 --- a/crates/sovereign-sdk/adapters/mock-zkvm/src/lib.rs +++ b/crates/sovereign-sdk/adapters/mock-zkvm/src/lib.rs @@ -149,7 +149,7 @@ impl sov_rollup_interface::zk::Zkvm for MockZkvm { } } - fn verify_and_extract_output( + fn verify_and_deserialize_output( serialized_proof: &[u8], code_commitment: &Self::CodeCommitment, ) -> Result { @@ -201,9 +201,7 @@ impl sov_rollup_interface::zk::ZkvmHost for MockZkvm { Ok(self.committed_data.pop_front().unwrap_or_default()) } - fn extract_output( - proof: &Proof, - ) -> Result { + fn extract_output(proof: &Proof) -> Result { let data: ProofInfo = borsh::from_slice(proof)?; T::try_from_slice(&data.hint).map_err(Into::into) @@ -259,7 +257,7 @@ impl sov_rollup_interface::zk::Zkvm for MockZkGuest { } } - fn verify_and_extract_output( + fn verify_and_deserialize_output( journal: &[u8], _code_commitment: &Self::CodeCommitment, ) -> Result { 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 e066a8656..2b4b75e8b 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 @@ -47,7 +47,7 @@ pub trait ZkvmHost: Zkvm + Clone { fn run(&mut self, elf: Vec, with_proof: bool) -> Result; /// Extracts public input and receipt from the proof. - fn extract_output(proof: &Proof) -> Result; + fn extract_output(proof: &Proof) -> Result; /// Host recovers pending proving sessions and returns proving results fn recover_proving_sessions(&self) -> Result, anyhow::Error>; @@ -92,7 +92,7 @@ pub trait Zkvm: Send + Sync { /// Same as [`verify`](Zkvm::verify), except that instead of returning the output /// as a serialized array, it returns a state transition structure. /// TODO: specify a deserializer for the output - fn verify_and_extract_output( + fn verify_and_deserialize_output( serialized_proof: &[u8], code_commitment: &Self::CodeCommitment, ) -> Result; diff --git a/crates/sp1/src/guest.rs b/crates/sp1/src/guest.rs index 20fd5a9e8..18178eada 100644 --- a/crates/sp1/src/guest.rs +++ b/crates/sp1/src/guest.rs @@ -30,7 +30,7 @@ impl Zkvm for SP1Guest { unimplemented!() } - fn verify_and_extract_output( + fn verify_and_deserialize_output( _serialized_proof: &[u8], _code_commitment: &Self::CodeCommitment, ) -> Result { diff --git a/crates/sp1/src/host.rs b/crates/sp1/src/host.rs index c80ca88ee..21208e414 100644 --- a/crates/sp1/src/host.rs +++ b/crates/sp1/src/host.rs @@ -133,7 +133,7 @@ impl ZkvmHost for SP1Host { } } - fn extract_output( + fn extract_output( proof: &Proof, ) -> Result { let public_values = match proof { @@ -194,7 +194,7 @@ impl Zkvm for SP1Host { Ok(proof.public_values.to_vec()) } - fn verify_and_extract_output( + fn verify_and_deserialize_output( serialized_proof: &[u8], code_commitment: &Self::CodeCommitment, ) -> Result {