Skip to content

Commit

Permalink
cleanup l2 batch proof
Browse files Browse the repository at this point in the history
  • Loading branch information
prajwolrg committed Jan 29, 2025
1 parent f3fb380 commit 0c2e551
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 38 deletions.
4 changes: 2 additions & 2 deletions crates/proof-impl/checkpoint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ pub fn process_checkpoint_proof(
l1_batch_output.final_state_hash,
),
(
l2_batch_output.initial_snapshot.hash,
l2_batch_output.final_snapshot.hash,
l2_batch_output.initial_state_hash,
l2_batch_output.final_state_hash,
),
l1_batch_output.rollup_params_commitment,
);
Expand Down
14 changes: 5 additions & 9 deletions crates/proof-impl/cl-agg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ pub fn process_cl_agg(zkvm: &impl ZkVmEnv, cl_stf_vk: &[u32; 8]) {
"At least one CL proof is required for aggregation"
);

let mut cl_proof_pp_start: L2BatchProofOutput = zkvm.read_verified_borsh(cl_stf_vk);
// `BatchInfo` has range which is inclusive. This makes it compatible and avoids off by 1 issue.
// TODO: Do this in a better way
cl_proof_pp_start.initial_snapshot.slot += 1;

let cl_proof_pp_start: L2BatchProofOutput = zkvm.read_verified_borsh(cl_stf_vk);
let mut cl_proof_pp_prev = cl_proof_pp_start.clone();
let mut acc_deposits = cl_proof_pp_start.deposits.clone();

Expand All @@ -36,8 +32,8 @@ pub fn process_cl_agg(zkvm: &impl ZkVmEnv, cl_stf_vk: &[u32; 8]) {
// proof of the batch
let public_params = L2BatchProofOutput {
deposits: acc_deposits,
initial_snapshot: cl_proof_pp_start.initial_snapshot,
final_snapshot: cl_proof_pp_prev.final_snapshot,
initial_state_hash: cl_proof_pp_start.initial_state_hash,
final_state_hash: cl_proof_pp_prev.final_state_hash,
rollup_params_commitment,
};

Expand All @@ -50,8 +46,8 @@ fn validate_proof_consistency(
next_proof_cs_snap: &L2BatchProofOutput,
) {
assert_eq!(
current_proof_cs_snap.final_snapshot.hash, // post-state root of the current proof
next_proof_cs_snap.initial_snapshot.hash, // initial state root of the next proof
current_proof_cs_snap.final_state_hash, // post-state root of the current proof
next_proof_cs_snap.initial_state_hash, // initial state root of the next proof
"State root mismatch between proofs"
);
}
34 changes: 7 additions & 27 deletions crates/proof-impl/cl-stf/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,16 @@ use strata_primitives::{buf::Buf32, params::RollupParams};
use strata_state::{
block::ExecSegment,
block_validation::{check_block_credential, validate_block_segments},
id::L2BlockId,
tx::DepositInfo,
};
pub use strata_state::{block::L2Block, chain_state::Chainstate, state_op::StateCache};
use strata_zkvm::ZkVmEnv;

#[derive(Debug, Clone, BorshSerialize, BorshDeserialize)]
pub struct ChainStateSnapshot {
pub hash: Buf32,
pub slot: u64,
pub l2_blockid: L2BlockId,
}

#[derive(Debug, Clone, BorshSerialize, BorshDeserialize)]
pub struct L2BatchProofOutput {
pub deposits: Vec<DepositInfo>,
pub initial_snapshot: ChainStateSnapshot,
pub final_snapshot: ChainStateSnapshot,
pub initial_state_hash: Buf32,
pub final_state_hash: Buf32,
pub rollup_params_commitment: Buf32,
}

Expand Down Expand Up @@ -95,23 +87,11 @@ fn process_cl_stf(
let new_state =
verify_and_transition(prev_state.clone(), new_block, exec_update, rollup_params);

let initial_snapshot = ChainStateSnapshot {
hash: prev_state.compute_state_root(),
slot: prev_state.chain_tip_slot(),
l2_blockid: prev_state.chain_tip_blockid(),
};

let final_snapshot = ChainStateSnapshot {
hash: new_state.compute_state_root(),
slot: new_state.chain_tip_slot(),
l2_blockid: new_state.chain_tip_blockid(),
};

L2BatchProofOutput {
// TODO: Accumulate the deposits
deposits: Vec::new(),
initial_snapshot,
final_snapshot,
initial_state_hash: prev_state.compute_state_root(),
final_state_hash: new_state.compute_state_root(),
rollup_params_commitment: *rollup_params_commitment,
}
}
Expand Down Expand Up @@ -152,7 +132,7 @@ pub fn batch_process_cl_stf(zkvm: &impl ZkVmEnv, el_vkey: &[u32; 8]) {
);

assert_eq!(
cl_update.initial_snapshot.hash, cl_update_acc.final_snapshot.hash,
cl_update.initial_state_hash, cl_update_acc.final_state_hash,
"Snapshot hash mismatch between consecutive updates."
);

Expand All @@ -162,8 +142,8 @@ pub fn batch_process_cl_stf(zkvm: &impl ZkVmEnv, el_vkey: &[u32; 8]) {

let output = L2BatchProofOutput {
deposits,
initial_snapshot: initial_cl_update.initial_snapshot,
final_snapshot: cl_update_acc.final_snapshot,
initial_state_hash: initial_cl_update.initial_state_hash,
final_state_hash: cl_update_acc.final_state_hash,
rollup_params_commitment: cl_update_acc.rollup_params_commitment,
};

Expand Down

0 comments on commit 0c2e551

Please sign in to comment.