polkadot-sdk
polkadot-sdk copied to clipboard
Add initial version of `pallet_revive`
This is a heavily modified and stripped down version of pallet_contracts
. We decided to fork instead of extend the old pallet. Reasons for that are:
- There is no benefit of supporting both on the same pallet as the intended payload for the new pallet (recompiled YUL) will be using a different ABI.
- It is much easier since it allows us to remove all the code that was necessary to support Wasm and focus fully on running cross compiled YUL contracts.
The code is reviewable but can't be merged because it depends on an unreleased version of PolkaVM via git.
Current state
All tests are passing and the code is not quick and dirty but written to last. The work is not finished, though. It is included in the kitchensink-runtime
and a node can be built. However, we merge early in order to be able to start testing other components as early as possible.
Outstanding changes are tracked here and will be merged separately: https://github.com/paritytech/polkadot-sdk/issues/5308
Syscall Interface
The syscall interface is best explored by generating the docs of this crate and looking at the SyscallDoc
trait. Arguments are passed in registers a0-a5 in the order they are listed. If there are more than 6 arguments (call, instantiate) a pointer to a packed struct of the arguments is expected as the only argument. I plan to create variants of those syscalls with less arguments specifically for YUL.
Functions are just referenced by their name as ASCII within the PolkaVM container. Rather than by a syscall number as it was the case in the last implementation.
Changes vs. pallet_contracts
The changes are too numerous to list them all here. This is an incomplete list:
- Use PolkaVM instead of wasmi to execute contracts
- Made Runtime generic over a new
Memory
trait as we can't map memory directly on PolkaVM anymore - No static verification on code upload. Everything is a determinstic runtime failure
- Removed all migrations and reset the pallet version
- Removed the nonce storage item and instead use the deployers account nonce to generate a unique trie
- We now bump the deployers account nonce on contract instantiation to they are bumped even within a batch transaction
- Removed the instantiation nonce host function: We should add a new
instantiate
variant as a replacement for thos
- ContractInfoOf of uses the indentity hasher now
- Remove the determinism feature: User of that feature should switch to soft floats
- The
unstable
attribute has been replaced by aapi_version
attribute to declare at which version an API became available- leaving out that attribute makes the API effectively unstable
- a new
api_version
field on the CodeInfo makes sure that old contracts can't access new APIs (necessary due to lack of static verification.
- Added a
behaviour_version
field to CodeInfo that can used if we need to introduce breaking changes and keep the old behaviour for existing contracts - Unified storage vs. transient and fixed vs. variable sized keys all into one set of multiplexing host functions
- Removed all contract observeable limits from the
Config
trait and instead hardcode them - Removed the Schedule
- Removed all deprecated host functions
- Simplify chain extension as preperation for making it a pre-compile