pub trait StateTransitionFunction<Vm: Zkvm, Da: DaSpec> {
type StateRoot: Serialize + DeserializeOwned + Clone + AsRef<[u8]>;
type InitialState;
type TxReceiptContents: Serialize + DeserializeOwned + Clone;
type BatchReceiptContents: Serialize + DeserializeOwned + Clone;
type Witness: Default + Serialize + DeserializeOwned;
type Condition: ValidityCondition;
// Required methods
fn init_chain(&mut self, params: Self::InitialState) -> Self::StateRoot;
fn apply_slot<'a, I>(
&mut self,
pre_state_root: &Self::StateRoot,
witness: Self::Witness,
slot_header: &Da::BlockHeader,
validity_condition: &Da::ValidityCondition,
blobs: I,
) -> SlotResult<Self::StateRoot, Self::BatchReceiptContents, Self::TxReceiptContents, Self::Witness>
where I: IntoIterator<Item = &'a mut Da::BlobTransaction>;
}
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 or anything else that can be posted on DA layer, like attestation or proof.
Required Associated Types§
Sourcetype StateRoot: Serialize + DeserializeOwned + Clone + AsRef<[u8]>
type StateRoot: Serialize + DeserializeOwned + Clone + AsRef<[u8]>
Root hash of state merkle tree
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 + DeserializeOwned
type Witness: Default + Serialize + DeserializeOwned
Witness is a data that is produced during actual batch execution or validated together with proof during verification
Sourcetype Condition: ValidityCondition
type Condition: ValidityCondition
The validity condition that must be verified outside of the Vm
Required Methods§
Sourcefn init_chain(&mut self, params: Self::InitialState) -> Self::StateRoot
fn init_chain(&mut self, params: Self::InitialState) -> Self::StateRoot
Perform one-time initialization for the genesis block and returns the resulting root hash wrapped in a result. If the init chain fails we panic.
Sourcefn apply_slot<'a, I>(
&mut self,
pre_state_root: &Self::StateRoot,
witness: Self::Witness,
slot_header: &Da::BlockHeader,
validity_condition: &Da::ValidityCondition,
blobs: I,
) -> SlotResult<Self::StateRoot, Self::BatchReceiptContents, Self::TxReceiptContents, Self::Witness>where
I: IntoIterator<Item = &'a mut Da::BlobTransaction>,
fn apply_slot<'a, I>(
&mut self,
pre_state_root: &Self::StateRoot,
witness: Self::Witness,
slot_header: &Da::BlockHeader,
validity_condition: &Da::ValidityCondition,
blobs: I,
) -> SlotResult<Self::StateRoot, Self::BatchReceiptContents, Self::TxReceiptContents, Self::Witness>where
I: IntoIterator<Item = &'a mut Da::BlobTransaction>,
Called at 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.
Applies batches of transactions to the rollup,
slashing the sequencer who proposed the blob on failure.
The blobs are contained into a slot whose data is contained within the slot_data
parameter,
this parameter is mainly used within the begin_slot hook.
The concrete blob type is defined by the DA layer implementation,
which is why we use a generic here instead of an associated type.
Commits state changes to the database
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.