Expand description
§Revive Pallet
This is an experimental module that provides functionality for the runtime to deploy and execute PolkaVM
smart-contracts. It is a heavily modified pallet_contracts
fork.
§Overview
This module extends accounts based on the [frame_support::traits::fungible
] traits to have smart-contract
functionality. It can be used with other modules that implement accounts based on [frame_support::traits::fungible
].
These “smart-contract accounts” have the ability to instantiate smart-contracts and make calls to other contract and
non-contract accounts.
The smart-contract code is stored once, and later retrievable via its code_hash
. This means that multiple
smart-contracts can be instantiated from the same code
, without replicating the code each time.
When a smart-contract is called, its associated code is retrieved via the code hash and gets executed. This call can alter the storage entries of the smart-contract account, instantiate new smart-contracts, or call other smart-contracts.
Finally, when an account is reaped, its associated code and storage of the smart-contract account will also be deleted.
§Weight
Senders must specify a Weight
limit
with every call, as all instructions invoked by the smart-contract require weight. Unused weight is refunded after the
call, regardless of the execution outcome.
If the weight limit is reached, then all calls and state changes (including balance transfers) are only reverted at the current call’s contract level. For example, if contract A calls B and B runs out of weight mid-call, then all of B’s calls are reverted. Assuming correct error handling by contract A, A’s other calls and state changes still persist.
One ref_time
Weight
is defined as one picosecond of execution time on the runtime’s reference machine.
§Revert Behaviour
Contract call failures are not cascading. When failures occur in a sub-call, they do not “bubble up”, and the call will only revert at the specific contract level. For example, if contract A calls contract B, and B fails, A can decide how to handle that failure, either proceeding or reverting A’s changes.
§Interface
§Dispatchable functions
Those are documented in the reference documentation.
§Usage
This module executes PolkaVM smart contracts. These can potentially be written in any language that compiles to
RISC-V. For now, the only officially supported languages are Solidity (via revive
)
and Rust (check the fixtures
directory for Rust examples).
§Host function tracing
For contract authors, it can be a helpful debugging tool to see which host functions are called, with which arguments, and what the result was.
In order to see these messages on the node console, the log level for the runtime::revive::strace
target needs to
be raised to the trace
level.
Example:
cargo run --release -- --dev -lerror,runtime::revive::strace=trace,runtime::revive=debug
§Unstable Interfaces
Driven by the desire to have an iterative approach in developing new contract interfaces this pallet contains the concept of an unstable interface. Akin to the rust nightly compiler it allows us to add new interfaces but mark them as unstable so that contract languages can experiment with them and give feedback before we stabilize those.
In order to access interfaces which don’t have a stable #[stable]
in runtime.rs
one need to set pallet_revive::Config::UnsafeUnstableInterface
to ConstU32<true>
.
It should be obvious that any production runtime should never be compiled with this feature: In addition to be
subject to change or removal those interfaces might not have proper weights associated with them and are therefore
considered unsafe.
New interfaces are generally added as unstable and might go through several iterations before they are promoted to a stable interface.
License: Apache-2.0
Re-exports§
pub use crate::pallet::genesis;
pub use weights::WeightInfo;
pub use codec;
pub use frame_support;
pub use frame_system;
pub use pallet_transaction_payment;
pub use sp_runtime;
pub use crate::pallet::*;
Modules§
- evm
- Types, and traits to integrate pallet-revive with EVM.
- migrations
- pallet
- The
pallet
module in each FRAME pallet hosts the most important items needed to construct this pallet. - precompiles
- Exposes types that can be used to extend
pallet_revive
with additional functionality. - test_
utils - Shared utilities for testing contracts. This is not part of the tests module because it is made public for other crates to use.
- tracing
- weights
- Autogenerated weights for
pallet_revive
Macros§
- as_
isize_ saturated - Converts a
U256
value to aisize
, saturating toisize::MAX
if the value is too large. - as_
u64_ saturated - Converts a
U256
value to au64
, saturating toMAX
if the value is too large. - as_
usize_ or_ fail - Converts a
U256
value to ausize
, failing the instruction if the value is too large. - as_
usize_ or_ fail_ ret - Converts a
U256
value to ausize
and returnsret
, failing the instruction if the value is too large. - as_
usize_ saturated - Converts a
U256
value to ausize
, saturating toMAX
if the value is too large. - check
- Check if the
SPEC
is enabled, and fail the instruction if it is not. - gas
- gas_
legacy - Records a
gas
cost and fails the instruction if it would exceed the available gas. - gas_
or_ fail_ legacy - Same as
gas_legacy!
, but withgas
as an option. - impl_
runtime_ apis_ plus_ revive - This macro wraps substrate’s
impl_runtime_apis!
and implementspallet_revive
runtime APIs. - otry
- Macro for optional try - returns early if the expression evaluates to None.
Similar to the
?
operator but for use in instruction implementations. - popn
- Pops n values from the stack. Fails the instruction if n values can’t be popped.
- popn_
top - Pops n values from the stack and returns the top value. Fails the instruction if n values can’t be popped.
- push
- Pushes a
B256
value onto the stack. Fails the instruction if the stack is full. - require_
eof - Error if the current call is executing EOF.
- require_
non_ staticcall - Fails the instruction if the current call is static.
- resize_
memory - Resizes the interpreterreter memory if necessary. Fails the instruction if the memory or gas limit is exceeded.
- tri
const
Option?
.
Structs§
- Account
Id32 Mapper - The mapper to be used if the account id is
AccountId32
. - Account
Info - Represents the account information for a contract or an externally owned account (EOA).
- Balance
With Dust - A Balance amount along with some “dust” to represent the lowest decimals that can’t be expressed in the native currency
- Block
Weights - Block weight limits & base values configuration.
- Code
Upload Return Value - The result of successfully uploading a contract.
- Contract
Info - Information for managing an account and its sub trie abstraction. This is the required info to cache for an account.
- Contract
Result - Result type of a
bare_call
orbare_instantiate
call as well asContractsApi::call
andContractsApi::instantiate
. - Dispatch
Info - A bundle of static information collected from the
#[pallet::weight]
attributes. - EthTransact
Info - The result of the execution of a
eth_transact
call. - Exec
Return Value - Output of a contract call or instantiation which ran to completion.
- H160
- Fixed-size uninterpreted hash type with 20 bytes (160 bits) size.
- H256
- Fixed-size uninterpreted hash type with 32 bytes (256 bits) size.
- Instantiate
Return Value - The result of a successful contract instantiation.
- Test
Account Mapper - An account mapper that can be used for testing u64 account ids.
- U256
- Little-endian large integer type 256-bit unsigned integer.
- Weight
Enums§
- Bump
Nonce - Indicates whether the account nonce should be incremented after instantiating a new contract.
- Code
- Reference to an existing code hash or a new vm module.
- Code
Removed - Indicates whether the code was removed after the last refcount was decremented.
- Contract
Access Error - The possible errors that can happen querying the storage of a contract.
- Deposit
Limit - EthTransact
Error - Error type of a
eth_transact
call. - Key
- Combined key type for both fixed and variable sized storage keys.
- Origin
- The type of origins supported by the revive pallet.
- Storage
Deposit - The amount of balance that was either charged or refunded in order to pay for storage.
Constants§
- RUNTIME_
PALLETS_ ADDR - The address used to call the runtime’s pallets dispatchables
Traits§
- Address
Mapper - Map between the native chain account id
T
and an EthereumH160
. - Revive
Api - The API used to dry-run contract interactions.
- Syscall
Doc - Documentation of the syscalls (host functions) available to contracts.
Functions§
- create1
- Determine the address of a contract using CREATE semantics.
- create2
- Determine the address of a contract using the CREATE2 semantics.
- is_
eth_ derived - Returns true if the passed account id is controlled by an eth key.
Type Aliases§
- Balance
Of - Code
Upload Result - Result type of a
bare_code_upload
call. - GetStorage
Result - Result type of a
get_storage
call. - Moment
Of