Skip to content

Commit

Permalink
Cleanup and rename l1_handler to util
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibek Pandey committed Jan 22, 2025
1 parent 6a2c920 commit 89fc287
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 256 deletions.
2 changes: 1 addition & 1 deletion bin/strata-client/src/rpc_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use jsonrpsee::core::RpcResult;
use strata_bridge_relay::relayer::RelayerHandle;
use strata_btcio::{broadcaster::L1BroadcastHandle, writer::EnvelopeHandle};
use strata_consensus_logic::{
checkpoint::CheckpointHandle, csm::state_tracker::reconstruct_state, l1_handler::verify_proof,
checkpoint::CheckpointHandle, csm::state_tracker::reconstruct_state, util::verify_proof,
sync_manager::SyncManager,
};
use strata_db::{
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus-logic/src/csm/client_transition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use strata_state::{
};
use tracing::*;

use crate::{errors::*, genesis::make_genesis_block, l1_handler::verify_proof};
use crate::{errors::*, genesis::make_genesis_block, util::verify_proof};

/// Processes the event given the current consensus state, producing some
/// output. This can return database errors.
Expand Down
253 changes: 0 additions & 253 deletions crates/consensus-logic/src/l1_handler.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/consensus-logic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod csm;
pub mod duty;
pub mod fork_choice_manager;
pub mod genesis;
pub mod l1_handler;
pub mod util;
pub mod reorg;
pub mod sync_manager;
pub mod unfinalized_tracker;
Expand Down
55 changes: 55 additions & 0 deletions crates/consensus-logic/src/util.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use strata_primitives::{params::RollupParams, proof::RollupVerifyingKey};
use strata_risc0_adapter;
use strata_sp1_adapter;
use strata_state::batch::{BatchCheckpoint, CheckpointProofOutput};
use strata_zkvm::{ProofReceipt, ZkVmError, ZkVmResult};
use tracing::*;

/// Verify that the provided checkpoint proof is valid for the verifier key.
///
/// # Caution
///
/// If the checkpoint proof is empty, this function returns an `Ok(())`.
pub fn verify_proof(
checkpoint: &BatchCheckpoint,
proof_receipt: &ProofReceipt,
rollup_params: &RollupParams,
) -> ZkVmResult<()> {
let rollup_vk = rollup_params.rollup_vk;
let checkpoint_idx = checkpoint.batch_info().idx();
let proof = checkpoint.proof();
info!(%checkpoint_idx, "verifying proof");

// FIXME: we are accepting empty proofs for now (devnet) to reduce dependency on the prover
// infra.
if rollup_params.proof_publish_mode.allow_empty() && proof_receipt.is_empty() {
warn!(%checkpoint_idx, "verifying empty proof as correct");
return Ok(());
}

let expected_public_output = checkpoint.get_proof_output();
let actual_public_output: CheckpointProofOutput =
borsh::from_slice(proof_receipt.public_values().as_bytes())
.map_err(|e| ZkVmError::OutputExtractionError { source: e.into() })?;
if expected_public_output != actual_public_output {
dbg!(actual_public_output, expected_public_output);
return Err(ZkVmError::ProofVerificationError(
"Public output mismatch during proof verification".to_string(),
));
}
let public_params_raw = proof_receipt.public_values().as_bytes();

// NOTE/TODO: this should also verify that this checkpoint is based on top of some previous
// checkpoint
match rollup_vk {
RollupVerifyingKey::Risc0VerifyingKey(vk) => {
strata_risc0_adapter::verify_groth16(proof, vk.as_ref(), public_params_raw)
}
RollupVerifyingKey::SP1VerifyingKey(vk) => {
strata_sp1_adapter::verify_groth16(proof, vk.as_ref(), public_params_raw)
}
// In Native Execution mode, we do not actually generate the proof to verify. Checking
// public parameters is sufficient.
RollupVerifyingKey::NativeVerifyingKey(_) => Ok(()),
}
}

0 comments on commit 89fc287

Please sign in to comment.