Skip to content

Commit

Permalink
Use borsh deser (#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaziciahmet authored Aug 5, 2024
1 parent 816bfaa commit 374c7e7
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 35 deletions.
11 changes: 4 additions & 7 deletions crates/risc0-bonsai/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ use risc0_zkvm::{
compute_image_id, ExecutorEnvBuilder, ExecutorImpl, Groth16Receipt, InnerReceipt, Journal,
Receipt,
};
use serde::de::DeserializeOwned;
use serde::Serialize;
use sov_risc0_adapter::guest::Risc0Guest;
use sov_rollup_interface::zk::{Proof, Zkvm, ZkvmHost};
use tracing::{debug, error, instrument, trace, warn};
Expand Down Expand Up @@ -511,10 +509,7 @@ impl<'host> Zkvm for Risc0BonsaiHost<'host> {
unimplemented!();
}

fn verify_and_extract_output<
Da: sov_rollup_interface::da::DaSpec,
Root: Serialize + DeserializeOwned,
>(
fn verify_and_extract_output<Da: sov_rollup_interface::da::DaSpec, Root: BorshDeserialize>(
serialized_proof: &[u8],
code_commitment: &Self::CodeCommitment,
) -> Result<sov_rollup_interface::zk::StateTransition<Da, Root>, Self::Error> {
Expand All @@ -523,6 +518,8 @@ impl<'host> Zkvm for Risc0BonsaiHost<'host> {
#[allow(clippy::clone_on_copy)]
receipt.verify(code_commitment.clone())?;

Ok(receipt.journal.decode()?)
Ok(BorshDeserialize::deserialize(
&mut receipt.journal.bytes.as_slice(),
)?)
}
}
12 changes: 3 additions & 9 deletions crates/sovereign-sdk/adapters/mock-zkvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,12 @@ impl<ValidityCond: ValidityCondition> sov_rollup_interface::zk::Zkvm for MockZkv
Ok(&serialized_proof[33..])
}

fn verify_and_extract_output<
Da: sov_rollup_interface::da::DaSpec,
Root: serde::Serialize + serde::de::DeserializeOwned,
>(
fn verify_and_extract_output<Da: sov_rollup_interface::da::DaSpec, Root: BorshDeserialize>(
serialized_proof: &[u8],
code_commitment: &Self::CodeCommitment,
) -> Result<sov_rollup_interface::zk::StateTransition<Da, Root>, Self::Error> {
let output = Self::verify(serialized_proof, code_commitment)?;
Ok(bincode::deserialize(output)?)
Ok(BorshDeserialize::deserialize(&mut &*output)?)
}
}

Expand Down Expand Up @@ -216,10 +213,7 @@ impl sov_rollup_interface::zk::Zkvm for MockZkGuest {
unimplemented!()
}

fn verify_and_extract_output<
Da: sov_rollup_interface::da::DaSpec,
Root: Serialize + serde::de::DeserializeOwned,
>(
fn verify_and_extract_output<Da: sov_rollup_interface::da::DaSpec, Root: BorshDeserialize>(
_serialized_proof: &[u8],
_code_commitment: &Self::CodeCommitment,
) -> Result<sov_rollup_interface::zk::StateTransition<Da, Root>, Self::Error> {
Expand Down
8 changes: 2 additions & 6 deletions crates/sovereign-sdk/adapters/risc0/src/guest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
//! for host(native) and guest(zkvm) part.
//! The host implementation is used for tests only and brings no real value.
use serde::de::DeserializeOwned;
use serde::Serialize;
use borsh::BorshDeserialize;
use sov_rollup_interface::zk::Zkvm;

use crate::Risc0MethodId;
Expand Down Expand Up @@ -37,10 +36,7 @@ impl Zkvm for Risc0Guest {
todo!("Implement once risc0 supports recursion: https://github.com/Sovereign-Labs/sovereign-sdk/issues/633")
}

fn verify_and_extract_output<
Da: sov_rollup_interface::da::DaSpec,
Root: Serialize + DeserializeOwned,
>(
fn verify_and_extract_output<Da: sov_rollup_interface::da::DaSpec, Root: BorshDeserialize>(
_serialized_proof: &[u8],
_code_commitment: &Self::CodeCommitment,
) -> Result<sov_rollup_interface::zk::StateTransition<Da, Root>, Self::Error> {
Expand Down
16 changes: 4 additions & 12 deletions crates/sovereign-sdk/adapters/risc0/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
use borsh::{BorshDeserialize, BorshSerialize};
use risc0_zkvm::{ExecutorEnvBuilder, ExecutorImpl, InnerReceipt, Journal, Receipt, Session};
use serde::de::DeserializeOwned;
use serde::Serialize;
use sov_rollup_interface::zk::{Proof, Zkvm, ZkvmHost};

use crate::guest::Risc0Guest;
Expand Down Expand Up @@ -121,15 +119,12 @@ impl<'host> Zkvm for Risc0Host<'host> {
verify_from_slice(serialized_proof, code_commitment)
}

fn verify_and_extract_output<
Da: sov_rollup_interface::da::DaSpec,
Root: Serialize + DeserializeOwned,
>(
fn verify_and_extract_output<Da: sov_rollup_interface::da::DaSpec, Root: BorshDeserialize>(
serialized_proof: &[u8],
code_commitment: &Self::CodeCommitment,
) -> Result<sov_rollup_interface::zk::StateTransition<Da, Root>, Self::Error> {
let output = Self::verify(serialized_proof, code_commitment)?;
Ok(risc0_zkvm::serde::from_slice(output)?)
Ok(BorshDeserialize::deserialize(&mut &*output)?)
}
}

Expand All @@ -148,15 +143,12 @@ impl Zkvm for Risc0Verifier {
verify_from_slice(serialized_proof, code_commitment)
}

fn verify_and_extract_output<
Da: sov_rollup_interface::da::DaSpec,
Root: Serialize + DeserializeOwned,
>(
fn verify_and_extract_output<Da: sov_rollup_interface::da::DaSpec, Root: BorshDeserialize>(
serialized_proof: &[u8],
code_commitment: &Self::CodeCommitment,
) -> Result<sov_rollup_interface::zk::StateTransition<Da, Root>, Self::Error> {
let output = Self::verify(serialized_proof, code_commitment)?;
Ok(risc0_zkvm::serde::from_slice(output)?)
Ok(BorshDeserialize::deserialize(&mut &*output)?)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,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<Da: DaSpec, Root: Serialize + DeserializeOwned>(
fn verify_and_extract_output<Da: DaSpec, Root: BorshDeserialize>(
serialized_proof: &[u8],
code_commitment: &Self::CodeCommitment,
) -> Result<StateTransition<Da, Root>, Self::Error>;
Expand Down

0 comments on commit 374c7e7

Please sign in to comment.