From 7b65917b74400ffc0548693939b62d073ed51174 Mon Sep 17 00:00:00 2001 From: Ben Mason Date: Wed, 24 Sep 2025 12:25:09 +0100 Subject: [PATCH 1/5] BIT-0018: Substrate Smart Contracts --- bits/BIT-0018-Substrate-Smart-Contracts.md | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 bits/BIT-0018-Substrate-Smart-Contracts.md diff --git a/bits/BIT-0018-Substrate-Smart-Contracts.md b/bits/BIT-0018-Substrate-Smart-Contracts.md new file mode 100644 index 0000000..9812728 --- /dev/null +++ b/bits/BIT-0018-Substrate-Smart-Contracts.md @@ -0,0 +1,86 @@ +# BIT-0018: Substrate Smart Contracts + +- **BIT Number:** 0018 +- **Title:** Substrate Smart Contracts +- **Author(s):** Ben Mason +- **Status:** Draft +- **Type:** Core +- **Created:** 24/09/2025 + +## 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. + +## 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: + +1. **Native Substrate Compatibility**: Smart contracts can directly interact with Bittensor pallets without complex bridging or compatibility layers +2. **Rust/Ink! Development**: Developers can write smart contracts in Rust using the familiar ink! framework, leveraging existing Substrate tooling +3. **Improved Performance**: Native contracts execute more efficiently than EVM contracts on Substrate infrastructure +4. **Better Wallet Integration**: Seamless interaction with Substrate-based wallets like Polkadot.js, SubWallet, and others + +## Getting Started + +For general smart contract development on Subtensor, please refer to the official ink! documentation: + +- [ink! Documentation](https://use.ink/docs/v5/) +- [ink! Getting Started Guide](https://use.ink/docs/v5/getting-started/setup) +- [ink! Examples](https://github.com/use-ink/ink-examples/tree/v5.x.x) + +## Specification + +1. **Pallet Integration**: Add `pallet_contracts` to the Bittensor runtime, configured to work with the existing pallet structure +2. **Whitelist Calls**: List the calls we want to make available to the smart contracts [reference](https://github.com/opentensor/subtensor/pull/2059/files#diff-d6f76ae401d0ed69fd1b08b7726270e3ad7983ab53491c90b55a36787c835418R41) + +## Backwards Compatibility + +This implementation is fully backwards compatible with existing Bittensor functionality: + +1. **EVM Support**: Existing EVM smart contracts continue to function without modification +2. **Migration Path**: Provides a migration path for existing contracts that wish to move to native contracts +3. **Dual Environment**: Both EVM and native contracts can coexist and potentially interact +4. **No Breaking Changes**: No existing pallets or interfaces are modified + +## 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: + +- Hold alpha tokens as collateral +- Implement slashing mechanisms for malicious behavior +- Distribute rewards for positive contributions + +### OTC Trading Desk + +Decentralized over-the-counter trading contracts that enable: + +- Direct peer-to-peer alpha token trading +- Miners to sell without impacting the pool +- Reduced slippage for large trades + +### 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 + +### Storage Access + +Smart contracts can read from storage, but **they cannot write directly to storage**, so they cannot be used to exploit the chain. + +### Runtime Calls + +Smart contracts have 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 + +1. **Conservative Limits**: Start with conservative contract execution limits to ensure network stability +2. **Selective API Exposure**: Carefully control which runtime functions are accessible to contracts for security + +## Copyright + +This document is licensed under [The Unlicense](https://unlicense.org/). From 47f795beab76eef4b68d61fc1ff133d40f5fbe01 Mon Sep 17 00:00:00 2001 From: Ben Mason Date: Wed, 24 Sep 2025 12:29:13 +0100 Subject: [PATCH 2/5] adjust wording --- bits/BIT-0018-Substrate-Smart-Contracts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bits/BIT-0018-Substrate-Smart-Contracts.md b/bits/BIT-0018-Substrate-Smart-Contracts.md index 9812728..e2337a4 100644 --- a/bits/BIT-0018-Substrate-Smart-Contracts.md +++ b/bits/BIT-0018-Substrate-Smart-Contracts.md @@ -70,7 +70,7 @@ Substrate-native bridge contracts for subnets with their own chains to bridge al ### Storage Access -Smart contracts can read from storage, but **they cannot write directly to storage**, so they cannot be used to exploit the chain. +Smart contracts can read from storage, but **they cannot write directly to storage**. ### Runtime Calls From 07550646549836b21a9969a2273d1672bce56373 Mon Sep 17 00:00:00 2001 From: Francisco Silva Date: Wed, 24 Sep 2025 16:16:18 +0200 Subject: [PATCH 3/5] Revise author and enhance smart contract details Updated author list and added details on chain extensions and runtime calls for smart contracts. --- bits/BIT-0018-Substrate-Smart-Contracts.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bits/BIT-0018-Substrate-Smart-Contracts.md b/bits/BIT-0018-Substrate-Smart-Contracts.md index e2337a4..d2b45cf 100644 --- a/bits/BIT-0018-Substrate-Smart-Contracts.md +++ b/bits/BIT-0018-Substrate-Smart-Contracts.md @@ -2,7 +2,7 @@ - **BIT Number:** 0018 - **Title:** Substrate Smart Contracts -- **Author(s):** Ben Mason +- **Author(s):** Ben Mason, Francisco Silva - **Status:** Draft - **Type:** Core - **Created:** 24/09/2025 @@ -68,13 +68,16 @@ Substrate-native bridge contracts for subnets with their own chains to bridge al ## Security Considerations -### Storage Access +### Chain extensions -Smart contracts can read from storage, but **they cannot write directly to storage**. +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 -Smart contracts have 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. +`call_runtime` is a function already present in `pallet_contracts` API that dispatches a `Call` 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 From c0be639b3c1ed23939f19e8b7b2a57542faa4c75 Mon Sep 17 00:00:00 2001 From: Ben Mason Date: Thu, 25 Sep 2025 08:26:44 +0100 Subject: [PATCH 4/5] bump number --- ...art-Contracts.md => BIT-0019-Substrate-Smart-Contracts.md} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename bits/{BIT-0018-Substrate-Smart-Contracts.md => BIT-0019-Substrate-Smart-Contracts.md} (98%) diff --git a/bits/BIT-0018-Substrate-Smart-Contracts.md b/bits/BIT-0019-Substrate-Smart-Contracts.md similarity index 98% rename from bits/BIT-0018-Substrate-Smart-Contracts.md rename to bits/BIT-0019-Substrate-Smart-Contracts.md index d2b45cf..df17f09 100644 --- a/bits/BIT-0018-Substrate-Smart-Contracts.md +++ b/bits/BIT-0019-Substrate-Smart-Contracts.md @@ -1,6 +1,6 @@ -# BIT-0018: Substrate Smart Contracts +# BIT-0019: Substrate Smart Contracts -- **BIT Number:** 0018 +- **BIT Number:** 0019 - **Title:** Substrate Smart Contracts - **Author(s):** Ben Mason, Francisco Silva - **Status:** Draft From 10d56d1847252eafb657c03a0394f499f9fc5096 Mon Sep 17 00:00:00 2001 From: Ben Mason Date: Thu, 25 Sep 2025 08:47:03 +0100 Subject: [PATCH 5/5] add PR --- bits/BIT-0019-Substrate-Smart-Contracts.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bits/BIT-0019-Substrate-Smart-Contracts.md b/bits/BIT-0019-Substrate-Smart-Contracts.md index df17f09..7863c69 100644 --- a/bits/BIT-0019-Substrate-Smart-Contracts.md +++ b/bits/BIT-0019-Substrate-Smart-Contracts.md @@ -11,6 +11,10 @@ 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 + +https://github.com/opentensor/subtensor/pull/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.