Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 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
10 changes: 8 additions & 2 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use keystore_rs::{FileStore, KeyChain, KeyStore};
use prism_keys::{CryptoAlgorithm, SigningKey};
use prism_serde::base64::ToBase64;
use sp1_sdk::{HashableKey, Prover as _, ProverClient};
use sp1_sdk::{HashableKey, ProverClient};
use std::io::{Error, ErrorKind};

use node_types::NodeType;
Expand All @@ -32,7 +32,7 @@
};

let config =
load_config(args.clone()).map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

Check failure on line 35 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this can be `std::io::Error::other(_)`

let start_height = config.clone().network.celestia_config.unwrap_or_default().start_height;

Expand All @@ -42,10 +42,12 @@

let da = initialize_light_da_layer(&config).await.map_err(|e| {
error!("error initializing light da layer: {}", e);
Error::new(ErrorKind::Other, e.to_string())

Check failure on line 45 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this can be `std::io::Error::other(_)`
})?;

let client = ProverClient::builder().mock().build();
info!("SP1_PROVER: {:?}", std::env::var("SP1_PROVER"));

let client = ProverClient::from_env();
let (_, vk) = client.setup(PRISM_ELF);
let event_channel = EventChannel::new();

Expand All @@ -59,16 +61,18 @@
}
Commands::Prover(_) => {
let db =
initialize_db(&config).map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

Check failure on line 64 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this can be `std::io::Error::other(_)`

let da = initialize_da_layer(&config)
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

Check failure on line 68 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this can be `std::io::Error::other(_)`
info!(
"keystore type: {:?}",
config.clone().keystore_type.unwrap_or_default()
);

info!("SP1_PROVER: {:?}", std::env::var("SP1_PROVER"));

let signing_key = get_signing_key(config.keystore_type, config.keystore_path)?;
let verifying_key = signing_key.verifying_key();

Expand All @@ -88,22 +92,24 @@

Arc::new(Prover::new(db, da, &prover_cfg).map_err(|e| {
error!("error initializing prover: {}", e);
Error::new(ErrorKind::Other, e.to_string())

Check failure on line 95 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this can be `std::io::Error::other(_)`
})?)
}
Commands::FullNode(_) => {
let db =
initialize_db(&config).map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

Check failure on line 100 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this can be `std::io::Error::other(_)`

let da = initialize_da_layer(&config)
.await
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

Check failure on line 104 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this can be `std::io::Error::other(_)`

info!(
"keystore type: {:?}",
config.clone().keystore_type.unwrap_or_default()
);

info!("SP1_PROVER: {:?}", std::env::var("SP1_PROVER"));

let signing_key = get_signing_key(config.keystore_type, config.keystore_path)?;

let verifying_key = config
Expand All @@ -122,12 +128,12 @@

Arc::new(Prover::new(db, da, &prover_cfg).map_err(|e| {
error!("error initializing prover: {}", e);
Error::new(ErrorKind::Other, e.to_string())

Check failure on line 131 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this can be `std::io::Error::other(_)`
})?)
}
};

node.start().await.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))

Check failure on line 136 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this can be `std::io::Error::other(_)`
}

fn get_signing_key(
Expand All @@ -137,7 +143,7 @@
let keystore: Box<dyn KeyStore> = match keystore_type.unwrap_or_default().as_str() {
"file" => {
let file_store = FileStore::new(keystore_path.unwrap_or_default())
.map_err(|e| Error::new(ErrorKind::Other, e.to_string()))?;

Check failure on line 146 in crates/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / clippy

this can be `std::io::Error::other(_)`
Box::new(file_store)
}
"keychain" => Box::new(KeyChain),
Expand Down
9 changes: 8 additions & 1 deletion crates/da/src/celestia/full_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ impl DataAvailabilityLayer for CelestiaConnection {
}

async fn submit_finalized_epoch(&self, epoch: FinalizedEpoch) -> Result<u64> {
debug!("posting {}th epoch to da layer", epoch.height);

let data = epoch.encode_to_bytes().map_err(|e| {
DataAvailabilityError::GeneralError(GeneralError::ParsingError(format!(
Expand All @@ -162,6 +161,14 @@ impl DataAvailabilityLayer for CelestiaConnection {
)))
})?;

debug!(
"posting {}th epoch to da layer ({} bytes)",
epoch.height,
data.len()
);

debug!("epoch: {:?}", epoch);

let blob = Blob::new(self.snark_namespace, data, AppVersion::V3).map_err(|e| {
DataAvailabilityError::GeneralError(GeneralError::BlobCreationError(e.to_string()))
})?;
Expand Down
13 changes: 3 additions & 10 deletions crates/node_types/prover/src/prover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use tokio::{
use crate::webserver::{WebServer, WebServerConfig};
use prism_common::operation::Operation;
use prism_da::{DataAvailabilityLayer, FinalizedEpoch};
use sp1_sdk::{CpuProver, Prover as _, ProverClient, SP1ProvingKey, SP1Stdin, SP1VerifyingKey};
use sp1_sdk::{EnvProver, ProverClient, SP1ProvingKey, SP1Stdin, SP1VerifyingKey};

pub const PRISM_ELF: &[u8] = include_bytes!("../../../../../elf/riscv32im-succinct-zkvm-elf");

Expand Down Expand Up @@ -114,7 +114,7 @@ pub struct Prover {
/// [`tree`] is the representation of the JMT, prism's state tree. It is accessed via the [`db`].
tree: Arc<RwLock<KeyDirectoryTree<Box<dyn Database>>>>,

prover_client: Arc<RwLock<CpuProver>>,
prover_client: Arc<RwLock<EnvProver>>,
proving_key: SP1ProvingKey,
verifying_key: SP1VerifyingKey,
}
Expand All @@ -137,10 +137,7 @@ impl Prover {

let tree = Arc::new(RwLock::new(KeyDirectoryTree::load(db.clone(), saved_epoch)));

#[cfg(feature = "mock_prover")]
let prover_client = ProverClient::builder().mock().build();
#[cfg(not(feature = "mock_prover"))]
let prover_client = ProverClient::builder().cpu().build();
let prover_client = ProverClient::from_env();

let (pk, vk) = prover_client.setup(PRISM_ELF);

Expand Down Expand Up @@ -412,10 +409,6 @@ impl Prover {
let client = self.prover_client.read().await;

info!("generating proof for epoch at height {}", epoch_height);
#[cfg(not(feature = "groth16"))]
let proof = client.prove(&self.proving_key, &stdin).run()?;

#[cfg(feature = "groth16")]
let proof = client.prove(&self.proving_key, &stdin).groth16().run()?;
info!("successfully generated proof for epoch {}", epoch_height);

Expand Down
8 changes: 2 additions & 6 deletions crates/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use prism_storage::{
Database,
};
use rand::{rngs::StdRng, Rng, SeedableRng};
use sp1_sdk::{HashableKey, Prover as _, ProverClient};
use sp1_sdk::{HashableKey, ProverClient};
use std::sync::Arc;
use tokio::{spawn, sync::mpsc, time::Duration};

Expand All @@ -34,13 +34,9 @@ fn setup_db() -> Arc<Box<dyn Database>> {

#[tokio::test]
async fn test_light_client_prover_talking() -> Result<()> {
std::env::set_var(
"RUST_LOG",
"DEBUG,tracing=off,sp1_stark=info,jmt=off,p3_dft=off,p3_fri=off,sp1_core_executor=info,sp1_recursion_program=info,p3_merkle_tree=off,sp1_recursion_compiler=off,sp1_core_machine=off",
);
pretty_env_logger::init();

let prover_client = ProverClient::builder().mock().build();
let prover_client = ProverClient::from_env();

let (_, vk) = prover_client.setup(PRISM_ELF);

Expand Down
10 changes: 7 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ integration-test:
for curve in ed25519 secp256k1 secp256r1; do
just celestia-up

cargo test -p prism-tests --lib --release --features mock_prover
export RUST_LOG="DEBUG,tracing=off,sp1_stark=info,jmt=off,p3_dft=off,p3_fri=off,sp1_core_executor=info,sp1_recursion_program=info,p3_merkle_tree=off,sp1_recursion_compiler=off,sp1_core_machine=off"

SP1_PROVER=mock RUST_LOG=$RUST_LOG cargo test -p prism-tests --lib --release --features mock_prover

just celestia-down
done
Expand All @@ -92,7 +94,8 @@ build:

unit-test:
@echo "Running unit tests..."
cargo test --lib --release --features "mock_prover" -- --skip test_light_client_prover_talking

SP1_PROVER=mock cargo test --lib --release --features "mock_prover" -- --skip test_light_client_prover_talking

coverage:
#!/usr/bin/env bash
Expand All @@ -101,7 +104,8 @@ coverage:
just celestia-up

echo "Generating coverage report..."
if ! cargo llvm-cov nextest --html --output-dir coverage_report --lib --features "mock_prover" --release --workspace --exclude prism-cli --exclude-from-report prism-sp1 --ignore-filename-regex sp1; then

if ! SP1_PROVER=mock cargo llvm-cov nextest --html --output-dir coverage_report --lib --features "mock_prover" --release --workspace --exclude prism-cli --exclude-from-report prism-sp1 --ignore-filename-regex sp1; then
echo "Coverage report generation failed."
else
echo "Coverage report generated in 'coverage_report' directory"
Expand Down
Loading