sov_rollup_interface/state_machine/
optimistic.rs

1//! Utilities for building an optimistic state machine
2use borsh::{BorshDeserialize, BorshSerialize};
3use serde::{Deserialize, Serialize};
4
5use crate::da::DaSpec;
6use crate::zk::StateTransition;
7
8/// A proof that the attester was bonded at the transition num `transition_num`.
9/// For rollups using the `jmt`, this will be a `jmt::SparseMerkleProof`
10#[derive(
11    Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize, Serialize, Deserialize, Default,
12)]
13pub struct ProofOfBond<StateProof> {
14    /// The transition number for which the proof of bond applies
15    pub claimed_transition_num: u64,
16    /// The actual state proof that the attester was bonded
17    pub proof: StateProof,
18}
19
20/// An attestation that a particular DA layer block transitioned the rollup state to some value
21#[derive(
22    Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize, Serialize, Deserialize, Default,
23)]
24pub struct Attestation<Da: DaSpec, StateProof, StateRoot> {
25    /// The alleged state root before applying the contents of the da block
26    pub initial_state_root: StateRoot,
27    /// The hash of the block in which the transition occurred
28    pub da_block_hash: Da::SlotHash,
29    /// The alleged post-state root
30    pub post_state_root: StateRoot,
31    /// A proof that the attester was bonded at some point in time before the attestation is generated
32    pub proof_of_bond: ProofOfBond<StateProof>,
33}
34
35/// The contents of a challenge to an attestation, which are contained as a public output of the proof
36/// Generic over an address type and a validity condition
37#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize, Serialize, Deserialize)]
38pub struct ChallengeContents<Address, Da: DaSpec, Root> {
39    /// The rollup address of the originator of this challenge
40    pub challenger_address: Address,
41    /// The state transition that was proven
42    pub state_transition: StateTransition<Da, Address, Root>,
43}
44
45#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, Serialize, Deserialize)]
46/// This struct contains the challenge as a raw blob
47pub struct Challenge<'a>(&'a [u8]);