Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ jobs:
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
use_oidc: true
files: codecov.info

wasm-test:
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/da/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ prism-common = { workspace = true }
prism-events = { workspace = true }
libp2p = { workspace = true, features = ["serde"] }
mockall = { workspace = true }
bincode = { workspace = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
celestia-rpc = { workspace = true }
Expand Down
78 changes: 51 additions & 27 deletions crates/da/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,50 @@ pub mod celestia;
pub mod consts;
pub mod memory;

#[cfg(target_arch = "wasm32")]
type Groth16Proof = Vec<u8>;
pub type VerifiableEpoch = Box<dyn VerifiableStateTransition>;

#[derive(Serialize, Deserialize, Clone, Debug, Default)]
/// Represents an [`SP1ProofWithPublicValues`] that can be used in wasm32
/// environments.
///
/// This is necessary because wasm32 cannot decode the [`proof_bytes`] back into
/// an [`SP1ProofWithPublicValues`], but provers will still need something
/// deserializable back into the original type (for STARK recursion)
pub struct SuccinctProof {
/// Represents the bincode serialization of a [`SP1ProofWithPublicValues`].
///
/// Can be used by `sp1_verifier::groth16::Groth16Verifier::verify` as the
/// `proof` field.
pub proof_bytes: Vec<u8>,

/// Represents the output of [`SP1ProofWithPublicValues::public_values()`]
///
/// Can be used by `sp1_verifier::groth16::Groth16Verifier::verify` as the
/// `public_values` field.
pub public_values: Vec<u8>,
}

#[cfg(not(target_arch = "wasm32"))]
type Groth16Proof = SP1ProofWithPublicValues;
impl TryInto<SP1ProofWithPublicValues> for SuccinctProof {
type Error = Box<bincode::ErrorKind>;

#[cfg(target_arch = "wasm32")]
type CompressedProof = Vec<u8>;
fn try_into(self) -> Result<SP1ProofWithPublicValues, Self::Error> {
bincode::deserialize::<SP1ProofWithPublicValues>(&self.proof_bytes)
}
}

#[cfg(not(target_arch = "wasm32"))]
type CompressedProof = SP1ProofWithPublicValues;

pub type VerifiableEpoch = Box<dyn VerifiableStateTransition>;
impl TryFrom<SP1ProofWithPublicValues> for SuccinctProof {
type Error = Box<bincode::ErrorKind>;

fn try_from(proof: SP1ProofWithPublicValues) -> Result<Self, Self::Error> {
let proof_bytes = bincode::serialize(&proof)?;
Ok(SuccinctProof {
proof_bytes,
public_values: proof.public_values.to_vec(),
})
}
}

/// Represents the commitments from epoch verification (previous and current)
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -90,12 +121,10 @@ pub struct FinalizedEpoch {
pub current_commitment: Digest,

/// Groth16 proof of the state transition.
pub proof: Groth16Proof,
/// Auxiliary data for WASM arch to read the public values of the proof.
pub public_values: Vec<u8>,
pub snark: SuccinctProof,

/// Compressed proof of the state transition, stored for cheaper recursive proving.
pub compressed_proof: CompressedProof,
/// Compressed proof of the state transition, stored for the next recursion step.
pub stark: SuccinctProof,

/// The signature of this struct by the prover, with the signature field set to `None`.
pub signature: Option<String>,
Expand Down Expand Up @@ -136,19 +165,15 @@ impl VerifiableStateTransition for FinalizedEpoch {
) -> Result<EpochCommitments, EpochVerificationError> {
self.verify_signature(vk.clone())?;

if self.public_values.len() < 64 {
if self.snark.public_values.len() < 64 {
return Err(EpochVerificationError::InvalidPublicValues(
self.public_values.len(),
self.snark.public_values.len(),
));
}

self.verify_commitments()?;

#[cfg(target_arch = "wasm32")]
let finalized_epoch_proof = &self.proof;

#[cfg(not(target_arch = "wasm32"))]
let finalized_epoch_proof = self.proof.bytes();
let finalized_epoch_proof = &self.snark.proof_bytes;

let vkey = if self.height == 0 {
&sp1_vkeys.base_vk
Expand All @@ -157,8 +182,8 @@ impl VerifiableStateTransition for FinalizedEpoch {
};

Groth16Verifier::verify(
&finalized_epoch_proof,
&self.public_values,
finalized_epoch_proof,
&self.snark.public_values,
vkey,
&sp1_verifier::GROTH16_VK_BYTES,
)
Expand All @@ -182,11 +207,11 @@ impl FinalizedEpoch {

fn extract_commitments(&self) -> Result<(Digest, Digest), EpochVerificationError> {
let mut slice = [0u8; 32];
slice.copy_from_slice(&self.public_values[..32]);
slice.copy_from_slice(&self.snark.public_values[..32]);
let proof_prev_commitment = Digest::from(slice);

let mut slice = [0u8; 32];
slice.copy_from_slice(&self.public_values[32..64]);
slice.copy_from_slice(&self.snark.public_values[32..64]);
let proof_current_commitment = Digest::from(slice);

Ok((proof_prev_commitment, proof_current_commitment))
Expand All @@ -211,9 +236,8 @@ impl FinalizedEpoch {
height: self.height,
prev_commitment: self.prev_commitment,
current_commitment: self.current_commitment,
proof: self.proof.clone(),
compressed_proof: self.compressed_proof.clone(),
public_values: self.public_values.clone(),
snark: self.snark.clone(),
stark: self.stark.clone(),
signature: None,
tip_da_height: self.tip_da_height,
};
Expand Down
4 changes: 2 additions & 2 deletions crates/node_types/lightclient/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ async fn test_backwards_sync_does_not_restart() {
.await;
publisher.send(PrismEvent::UpdateDAHeight { height: 1000 });
// TODO: Find better way
tokio::time::sleep(Duration::from_secs(1)).await;
tokio::time::sleep(Duration::from_millis(200)).await;
assert!(lc.get_sync_state().await.latest_finalized_epoch.is_none());
}

Expand All @@ -292,7 +292,7 @@ async fn test_will_not_process_older_epoch() {

publisher.send(PrismEvent::UpdateDAHeight { height: 8 });
// TODO: replace with event listener
tokio::time::sleep(Duration::from_secs(1)).await;
tokio::time::sleep(Duration::from_millis(200)).await;

let sync_state = lc.get_sync_state().await;
assert_eq!(sync_state.current_height, 9);
Expand Down
1 change: 1 addition & 0 deletions crates/node_types/prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ prism-keys = { workspace = true }
prism-da = { workspace = true }
sp1-sdk = { workspace = true }
prism-telemetry-registry = { workspace = true }
mockall = { workspace = true }

[dev-dependencies]
paste = { workspace = true }
Expand Down
17 changes: 13 additions & 4 deletions crates/node_types/prover/src/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use tokio::{sync::RwLock, task::JoinSet};
use tokio_util::sync::CancellationToken;

use crate::{
prover_engine::ProverEngine,
prover_engine::{engine::ProverEngine, sp1_prover::SP1ProverEngine},
sequencer::Sequencer,
syncer::Syncer,
webserver::{WebServer, WebServerConfig},
Expand Down Expand Up @@ -110,7 +110,7 @@ impl Config {
#[allow(dead_code)]
pub struct Prover {
pub cfg: Config,
prover_engine: Arc<ProverEngine>,
prover_engine: Arc<dyn ProverEngine>,
sequencer: Arc<Sequencer>,
syncer: Arc<Syncer>,
latest_epoch_da_height: Arc<RwLock<u64>>,
Expand All @@ -125,9 +125,18 @@ impl Prover {
cfg: &Config,
cancellation_token: CancellationToken,
) -> Result<Prover> {
let latest_epoch_da_height = Arc::new(RwLock::new(0));
let prover_engine = Arc::new(SP1ProverEngine::new(&cfg.prover_engine)?);
Prover::new_with_engine(db, da, prover_engine, cfg, cancellation_token)
}

let prover_engine = Arc::new(ProverEngine::new(&cfg.prover_engine)?);
pub fn new_with_engine(
db: Arc<Box<dyn Database>>,
da: Arc<dyn DataAvailabilityLayer>,
prover_engine: Arc<dyn ProverEngine>,
cfg: &Config,
cancellation_token: CancellationToken,
) -> Result<Prover> {
let latest_epoch_da_height = Arc::new(RwLock::new(0));

let sequencer = Arc::new(Sequencer::new(
db.clone(),
Expand Down
Loading
Loading