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§
sourcetype InitialState
type InitialState
The initial state of the rollup.
sourcetype TxReceiptContents: Serialize + DeserializeOwned + Clone
type TxReceiptContents: Serialize + DeserializeOwned + Clone
The contents of a transaction receipt. This is the data that is persisted in the database
sourcetype BatchReceiptContents: Serialize + DeserializeOwned + Clone
type BatchReceiptContents: Serialize + DeserializeOwned + Clone
The contents of a batch receipt. This is the data that is persisted in the database
sourcetype Witness: Default + Serialize
type Witness: Default + Serialize
Witness is a data that is produced during actual batch execution or validated together with proof during verification
sourcetype MisbehaviorProof
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§
sourcefn init_chain(&mut self, params: Self::InitialState)
fn init_chain(&mut self, params: Self::InitialState)
Perform one-time initialization for the genesis block.
sourcefn begin_slot(&mut self, witness: Self::Witness)
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.
sourcefn apply_blob(
&mut self,
blob: impl BlobTransactionTrait,
misbehavior_hint: Option<Self::MisbehaviorProof>
) -> BatchReceipt<Self::BatchReceiptContents, Self::TxReceiptContents>
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).