Crate sov_modules_api
source ·Expand description
sov-modules-api
The sov-modules-api
crate provides essential traits for the Module System. Here are the key traits defined by the
crate:
-
The
Module
trait: Defines how to initialize and change the state of a module. This is the main trait that module developers need to implement. The author of a module must specify:-
Configuration upon rollup deployment: This includes the
genesis()
method and theConfig
type, which determine how the module is set up initially. Note that the initialization for logic for modules is identical to theGenesis
trait (described below). We blanket implementGenesis
for allModule
s, but keep it as a separate trait since some other structs need to implement it as well. -
Interaction with user messages: The module must define the
call
method and theCallMessage
type, which handle user messages. These messages typically result in changes to the module’s state.
-
-
The
ModuleInfo
trait: Provides additional information related to a module. This trait is automatically derived. -
The
Spec
trait: It defines all the types that modules are generic over. This separation allows the module logic to be independent of concerns such as the specific storage system or concrete signature schemes used for signing rollup transactions. Currently acceptable hashes forSpec
should fit into 32 bytes. -
The
Context
trait implements theSpec
and introduces additional methods accessible within modules. Currently, it includes thesender()
method, which returns the address of the transaction sender. This trait will be further extended with other useful methods, such asbatch_hash()
, and more. This crate defines also the default implementation for theContext
trait. -
The
Genesis
trait: Defines how the rollup is initialized during deployment phase. -
The
DispatchCall
trait: Defines how messages are forwarded to the appropriate module and how the call message is executed. The implementation of this trait can be generated automatically using a macro.
Re-exports
pub use sov_rollup_interface::digest;
Modules
- The rollup capabilities module defines “capabilities” that rollup must provide if they wish to use the standard app template. If you don’t want to provide these capabilities, you can bypass the Sovereign module-system completely and write a state transition function from scratch. See here for docs
- Procedural macros to assist with creating new modules.
Structs
- Response type for the
Module::call
method. - A key-value pair representing a change to the rollup state
- A unique identifier for each state variable in a module.
- The public output of a SNARK proof in Sovereign, this struct makes a claim that the state of the rollup has transitioned from
initial_state_root
tofinal_state_root
if and only if the conditionvalidity_condition
is satisfied.
Enums
- General error type in the Module System.
- A type that can’t be instantiated.
Traits
- A marker trait for general addresses.
- This trait wraps “blob transaction” from a data availability layer allowing partial consumption of the blob data by the rollup.
- A context contains information which is passed to modules during transaction execution. Currently, context includes the sender of the transaction as recovered from its signature.
- A specification for the types used by a DA layer.
- A trait that needs to be implemented for any call message.
- A trait that specifies how a runtime should encode the data for each module
- Methods from this trait should be called only once during the rollup deployment.
- All the methods have a default implementation that can’t be invoked (because they take
NonInstantiable
parameter). This allows developers to override only some of the methods in their implementation and safely ignore the others. - Every module has to implement this trait.
- PublicKey used in the Module System.
- An address used inside rollup
- Signature used in the Module System.
SlotData
is the subset of a DA layer block which is stored in the rollup’s database. At the very least, the rollup needs access to the hashes and headers of all DA layer blocks, but rollups may choose to partial (or full) block data as well.- The
Spec
trait configures certain key primitives to be used by a by a particular instance of a rollup.Spec
is almost always implemented on a Context object; since all Modules are generic over a Context, rollup developers can easily optimize their code for different environments by simply swapping out the Context (and by extension, the Spec). - This trait is implemented on the struct/enum which expresses the validity condition
- This trait expresses that a type can check a validity condition.
- A Zk proof system capable of proving and verifying arbitrary Rust code Must support recursive proofs.
Functions
- Accepts Vec<> of tuples (&ModuleInfo, &TValue), and returns Vec<&TValue> sorted by mapped module dependencies
Derive Macros
- Derives the
DispatchCall
trait for the underlying type. - Derives the
Genesis
trait for the underlying runtimestruct
. - Adds encoding functionality to the underlying type.
- Derives the
ModuleCallJsonSchema
trait for the underlying type. - Derives the
ModuleInfo
trait for the underlyingstruct
.