BIT 0019 substrate smart contracts #32
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
BIT-0019: Substrate Smart Contracts
Abstract
This BIT proposes the integration of Substrate's
pallet_contracts
into the Bittensor blockchain, enabling smart contracts written in Rust using the ink! language. This native Substrate smart contract functionality will provide seamless interaction between smart contracts and Bittensor's pallets, offering a more developer-friendly and user-friendly alternative to the existing EVM-based smart contracts.PR
opentensor/subtensor#2059
Motivation
The current EVM integration in Bittensor creates significant friction for both developers and users due to the fundamental differences between Ethereum's account-based model and Substrate's architecture. This mismatch complicates smart contract development, increases gas costs, and creates poor user experiences when interacting with Substrate-based wallets.
By implementing
pallet_contracts
, we enable:Getting Started
For general smart contract development on Subtensor, please refer to the official ink! documentation:
Specification
pallet_contracts
to the Bittensor runtime, configured to work with the existing pallet structureBackwards Compatibility
This implementation is fully backwards compatible with existing Bittensor functionality:
Example Use Cases
Collateral Contracts
Smart contracts that allow subnet owners to create staking mechanisms where miners can stake alpha tokens as collateral for good behavior. These contracts can:
OTC Trading Desk
Decentralized over-the-counter trading contracts that enable:
Native Bridge Contracts
Substrate-native bridge contracts for subnets with their own chains to bridge alpha tokens between subnet chains and Bittensor mainnet.
Security Considerations
Chain extensions
A chain extension is a way to extend
pallet_contracts
API by exposing parts of the runtime logic to smart contracts. Added functions should handle security (needs to be audited). In a case of a wrapper around an existing pallet (so that contract can call functions of this pallet) every pallet dispatchable should be implemented as a chain extension function, unit tested and be benchmarked (to determine the correct amount of weight).Runtime Calls
call_runtime
is a function already present inpallet_contracts
API that dispatches aCall
passed as an argument. This way contracts can call pallets without having to go through chain extensions. There is no security issue and does not need to be audited (as it calls pallets directly), weight is also handled (as it uses weight from the pallet). No need to add tests either (pallets already have tests).To activate/deactivate dispatchables accessible from a contract it should be added to
CallFilter
.Smart contracts can to make runtime calls in which the caller is the contract itself. Similar to how EVM DEXs use ERC20 allowances to move tokens, users would have to grant delegate the contract as a staking proxy to allow it to move stake on their behalf. As with EVM, users have to analyse the contract they are interacting with to decide if it is exploitative or not.
Design Decisions
Copyright
This document is licensed under The Unlicense.