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
Moduletrait: 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 theConfigtype, which determine how the module is set up initially. Note that the initialization for logic for modules is identical to theGenesistrait (described below). We blanket implementGenesisfor allModules, 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
callmethod and theCallMessagetype, which handle user messages. These messages typically result in changes to the module’s state.
-
-
The
ModuleInfotrait: Provides additional information related to a module. This trait is automatically derived. -
The
Spectrait: 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 forSpecshould fit into 32 bytes. -
The
Contexttrait implements theSpecand 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 theContexttrait. -
The
Genesistrait: Defines how the rollup is initialized during deployment phase. -
The
DispatchCalltrait: 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::callmethod. - 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_roottofinal_state_rootif and only if the conditionvalidity_conditionis 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
NonInstantiableparameter). 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.
SlotDatais 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
Spectrait configures certain key primitives to be used by a by a particular instance of a rollup.Specis 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
DispatchCalltrait for the underlying type. - Derives the
Genesistrait for the underlying runtimestruct. - Adds encoding functionality to the underlying type.
- Derives the
ModuleCallJsonSchematrait for the underlying type. - Derives the
ModuleInfotrait for the underlyingstruct.