Skip to content

Commit

Permalink
Add StateTransitionOutput (Sovereign-Labs#1195)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkolad authored Nov 30, 2023
1 parent eec0c0e commit 88b77d6
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions full-node/sov-stf-runner/src/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
use std::marker::PhantomData;

use sov_rollup_interface::da::DaVerifier;
use serde::{Deserialize, Serialize};
use sov_rollup_interface::da::{BlockHeaderTrait, DaVerifier};
use sov_rollup_interface::stf::StateTransitionFunction;
use sov_rollup_interface::zk::{Zkvm, ZkvmGuest};

use crate::StateTransitionData;

#[derive(Serialize, Deserialize)]
/// Output of the verifier.
pub struct StateTransitionOutput<StateRoot, SlotHash> {
/// The state root before the state transition
pub pre_state_root: StateRoot,
/// The state root after the state transition
pub post_state_root: StateRoot,
/// Da block hash
pub da_block_hash: SlotHash,
}

/// Verifies a state transition
pub struct StateTransitionVerifier<ST, Da, Zk>
where
Expand Down Expand Up @@ -34,11 +46,7 @@ where
}

/// Verify the next block
pub fn run_block(
&self,
zkvm: Zk,
pre_state: Stf::PreState,
) -> Result<Stf::StateRoot, Da::Error> {
pub fn run_block(&self, zkvm: Zk, pre_state: Stf::PreState) -> Result<(), Da::Error> {
let mut data: StateTransitionData<_, _, Da::Spec> = zkvm.read_from_host();
let validity_condition = self.da_verifier.verify_relevant_tx_list(
&data.da_block_header,
Expand All @@ -56,7 +64,13 @@ where
&mut data.blobs,
);

zkvm.commit(&result.state_root);
Ok(result.state_root)
let out = StateTransitionOutput {
pre_state_root: data.pre_state_root,
post_state_root: result.state_root,
da_block_hash: data.da_block_header.hash(),
};

zkvm.commit(&out);
Ok(())
}
}

0 comments on commit 88b77d6

Please sign in to comment.