Conversation
Updated author list and added details on chain extensions and runtime calls for smart contracts.
|
This would definitely help build contracts that natively integrate with Bittensor and subnets. However I can't manage to find any examples of smart contracts built with Have you heard about Frontier @silva-fj @bdmason? I'm just discovering it, but it might be a good solution as well. Maybe it's what already powers the EVM pallet? As I see it the main roadblock for contract interactions right now is the need to bridge funds from SS58 to H160 accounts, and for users to handle two different types of accounts. |
Here you can find a list of some of the chains that integrated the Here you can find some examples
Yes, a fork of frontier is what is used for bittensor EVM. |
BIT-0019: Substrate Smart Contracts
Abstract
This BIT proposes the integration of Substrate's
pallet_contractsinto 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_contractsto 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_contractsAPI 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_runtimeis a function already present inpallet_contractsAPI that dispatches aCallpassed 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.