Skip to content

Commit

Permalink
Hooks impl for demo-stf should include chain_state (#974)
Browse files Browse the repository at this point in the history
* fix: include chain-state in hooks-impl for demo-stf

* Fix mock validity cond; improve guest logging (#15)

---------

Co-authored-by: Preston Evans <[email protected]>
  • Loading branch information
Farhad-Shabani and preston-evans98 authored Oct 3, 2023
1 parent 0f4f694 commit 5664adc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
12 changes: 12 additions & 0 deletions examples/demo-stf/src/hooks_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ impl<C: Context, Da: DaSpec> SlotHooks<Da> for Runtime<C, Da> {
#[cfg(feature = "experimental")]
self.evm
.begin_slot_hook(slot_header.hash().into(), working_set);

self.chain_state.begin_slot_hook(
slot_header,
validity_condition,
pre_state_root,
working_set,
);
}

fn end_slot_hook(
Expand All @@ -98,6 +105,8 @@ impl<C: Context, Da: DaSpec> SlotHooks<Da> for Runtime<C, Da> {
) {
#[cfg(feature = "experimental")]
self.evm.end_slot_hook(working_set);

self.chain_state.end_slot_hook(working_set);
}
}

Expand All @@ -111,5 +120,8 @@ impl<C: Context, Da: sov_modules_api::DaSpec> FinalizeHook<Da> for Runtime<C, Da
) {
#[cfg(feature = "experimental")]
self.evm.finalize_hook(root_hash, accessory_working_set);

self.chain_state
.finalize_hook(root_hash, accessory_working_set);
}
}
18 changes: 9 additions & 9 deletions full-node/sov-stf-runner/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,16 @@ where
state_transition_witness: slot_result.witness,
};
vm.add_hint(transition_data);

match config {
ProofGenConfig::Simulate(verifier) => {
verifier.run_block(vm.simulate_with_hints()).map_err(|e| {
tracing::info_span!("guest_execution").in_scope(|| match config {
ProofGenConfig::Simulate(verifier) => verifier
.run_block(vm.simulate_with_hints())
.map_err(|e| {
anyhow::anyhow!("Guest execution must succeed but failed with {:?}", e)
})?;
}
ProofGenConfig::Execute => vm.run(false)?,
ProofGenConfig::Prover => vm.run(true)?,
}
})
.map(|_| ()),
ProofGenConfig::Execute => vm.run(false),
ProofGenConfig::Prover => vm.run(true),
})?;
}
let next_state_root = slot_result.state_root;

Expand Down
2 changes: 1 addition & 1 deletion rollup-interface/src/state_machine/mocks/da.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl DaVerifier for MockDaVerifier {
_inclusion_proof: <Self::Spec as DaSpec>::InclusionMultiProof,
_completeness_proof: <Self::Spec as DaSpec>::CompletenessProof,
) -> Result<<Self::Spec as DaSpec>::ValidityCondition, Self::Error> {
Ok(MockValidityCond { is_valid: true })
Ok(Default::default())
}
}

Expand Down
18 changes: 8 additions & 10 deletions rollup-interface/src/state_machine/mocks/validity_condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,20 @@ use crate::zk::{ValidityCondition, ValidityConditionChecker};

/// A trivial test validity condition structure that only contains a boolean
#[derive(
Debug,
BorshDeserialize,
BorshSerialize,
Serialize,
Deserialize,
PartialEq,
Clone,
Copy,
Default,
Eq,
Debug, BorshDeserialize, BorshSerialize, Serialize, Deserialize, PartialEq, Clone, Copy, Eq,
)]
pub struct MockValidityCond {
/// The associated validity condition field. If it is true, the validity condition is verified
pub is_valid: bool,
}

// Validity conditions should usually be valid
impl Default for MockValidityCond {
fn default() -> Self {
Self { is_valid: true }
}
}

impl ValidityCondition for MockValidityCond {
type Error = Error;
fn combine<H: Digest>(&self, rhs: Self) -> Result<Self, Self::Error> {
Expand Down

0 comments on commit 5664adc

Please sign in to comment.