pub trait StateTransitionFunction<Vm: Zkvm> {
    type StateRoot;
    type InitialState;
    type TxReceiptContents: Serialize + DeserializeOwned + Clone;
    type BatchReceiptContents: Serialize + DeserializeOwned + Clone;
    type Witness: Default + Serialize;
    type MisbehaviorProof;

    // Required methods
    fn init_chain(&mut self, params: Self::InitialState);
    fn begin_slot(&mut self, witness: Self::Witness);
    fn apply_blob(
        &mut self,
        blob: impl BlobTransactionTrait,
        misbehavior_hint: Option<Self::MisbehaviorProof>
    ) -> BatchReceipt<Self::BatchReceiptContents, Self::TxReceiptContents>;
    fn end_slot(&mut self) -> (Self::StateRoot, Self::Witness);
}
Expand description

State transition function defines business logic that responsible for changing state. Terminology:

  • state root: root hash of state merkle tree
  • block: DA layer block
  • batch: Set of transactions grouped together, or block on L2
  • blob: Non serialised batch

Required Associated Types§

source

type StateRoot

Root hash of state merkle tree

source

type InitialState

The initial state of the rollup.

source

type TxReceiptContents: Serialize + DeserializeOwned + Clone

The contents of a transaction receipt. This is the data that is persisted in the database

source

type BatchReceiptContents: Serialize + DeserializeOwned + Clone

The contents of a batch receipt. This is the data that is persisted in the database

source

type Witness: Default + Serialize

Witness is a data that is produced during actual batch execution or validated together with proof during verification

source

type MisbehaviorProof

A proof that the sequencer has misbehaved. For example, this could be a merkle proof of a transaction with an invalid signature

Required Methods§

source

fn init_chain(&mut self, params: Self::InitialState)

Perform one-time initialization for the genesis block.

source

fn begin_slot(&mut self, witness: Self::Witness)

Called at the beginning of each DA-layer block - whether or not that block contains any data relevant to the rollup. If slot is started in Full Node mode, default witness should be provided. If slot is started in Zero Knowledge mode, witness from execution should be provided.

source

fn apply_blob( &mut self, blob: impl BlobTransactionTrait, misbehavior_hint: Option<Self::MisbehaviorProof> ) -> BatchReceipt<Self::BatchReceiptContents, Self::TxReceiptContents>

Apply a blob/batch of transactions to the rollup, slashing the sequencer who proposed the blob on failure. The concrete blob type is defined by the DA layer implementation, which is why we use a generic here instead of an associated type. Misbehavior hint allows prover optimizations - the sequencer can be slashed for including a transaction which fails stateless checks (i.e. has an invalid signature) - and in that case we ignore his entire batch. This method lets you give a hint to the prover telling it where that invalid signature is, so that it can skip signature checks on other transactions. (If the misbehavior hint is wrong, then the host is malicious so we can just panic - which means that no proof will be created).

source

fn end_slot(&mut self) -> (Self::StateRoot, Self::Witness)

Called once at the end of each DA layer block (i.e. after all rollup blobs have been processed) Commits state changes to the database

Implementors§