diff --git a/Cargo.lock b/Cargo.lock index 2469923f7..aaf4852d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14526,6 +14526,7 @@ name = "tangle-runtime" version = "2.0.0" dependencies = [ "evm-tracer", + "fp-evm", "fp-rpc", "fp-self-contained", "frame-benchmarking", @@ -14539,6 +14540,7 @@ dependencies = [ "log", "num_enum 0.5.11", "pallet-airdrop-claims", + "pallet-assets", "pallet-authorship", "pallet-babe", "pallet-bags-list", @@ -14571,19 +14573,28 @@ dependencies = [ "pallet-evm-precompile-sha3fips", "pallet-evm-precompile-simple", "pallet-evm-precompile-staking", + "pallet-evm-precompile-verify-bls381-signature", + "pallet-evm-precompile-verify-ecdsa-secp256k1-signature", + "pallet-evm-precompile-verify-ecdsa-secp256r1-signature", + "pallet-evm-precompile-verify-ecdsa-stark-signature", + "pallet-evm-precompile-verify-schnorr-signatures", "pallet-evm-precompile-vesting", + "pallet-evm-precompileset-assets-erc20", "pallet-grandpa", "pallet-hotfix-sufficients", "pallet-identity", "pallet-im-online", "pallet-indices", "pallet-insecure-randomness-collective-flip", + "pallet-multi-asset-delegation", "pallet-multisig", "pallet-nomination-pools", "pallet-offences", "pallet-preimage", "pallet-proxy", "pallet-scheduler", + "pallet-services", + "pallet-services-rpc-runtime-api", "pallet-session", "pallet-staking 28.0.0", "pallet-staking-reward-curve", diff --git a/node/src/chainspec/mainnet.rs b/node/src/chainspec/mainnet.rs index 28a082c59..6f8dfc8c2 100644 --- a/node/src/chainspec/mainnet.rs +++ b/node/src/chainspec/mainnet.rs @@ -235,6 +235,7 @@ fn mainnet_genesis( .collect(); RuntimeGenesisConfig { system: SystemConfig { ..Default::default() }, + assets: Default::default(), sudo: SudoConfig { key: Some(root_key) }, balances: BalancesConfig { balances: endowed_accounts.to_vec() }, vesting: VestingConfig { diff --git a/pallets/services/src/mock_evm.rs b/pallets/services/src/mock_evm.rs index b78a50a8c..1ee08d5fe 100644 --- a/pallets/services/src/mock_evm.rs +++ b/pallets/services/src/mock_evm.rs @@ -61,7 +61,7 @@ pub type DefaultPrecompiles = ( PrecompileAt, ECRecoverPublicKey, (CallableByContract, CallableByPrecompile)>, ); -pub type WebbPrecompiles = PrecompileSetBuilder< +pub type TanglePrecompiles = PrecompileSetBuilder< R, (PrecompilesInRangeInclusive<(AddressU64<1>, AddressU64<2095>), DefaultPrecompiles>,), >; @@ -69,7 +69,7 @@ pub type WebbPrecompiles = PrecompileSetBuilder< parameter_types! { pub const MinimumPeriod: u64 = 6000 / 2; - pub PrecompilesValue: WebbPrecompiles = WebbPrecompiles::<_>::new(); + pub PrecompilesValue: TanglePrecompiles = TanglePrecompiles::<_>::new(); } impl pallet_timestamp::Config for Runtime { @@ -201,7 +201,7 @@ impl pallet_evm::Config for Runtime { type AddressMapping = HashedAddressMapping; type Currency = Balances; type RuntimeEvent = RuntimeEvent; - type PrecompilesType = WebbPrecompiles; + type PrecompilesType = TanglePrecompiles; type PrecompilesValue = PrecompilesValue; type ChainId = ChainId; type BlockGasLimit = BlockGasLimit; diff --git a/precompiles/multi-asset-delegation/MultiAssetDelegation.sol b/precompiles/multi-asset-delegation/MultiAssetDelegation.sol index 47d1f03ac..68e975f34 100644 --- a/precompiles/multi-asset-delegation/MultiAssetDelegation.sol +++ b/precompiles/multi-asset-delegation/MultiAssetDelegation.sol @@ -2,7 +2,7 @@ pragma solidity >=0.8.3; /// @dev The MultiAssetDelegation contract's address. -address constant MULTI_ASSET_DELEGATION = 0x0000000000000000000000000000000000000809; +address constant MULTI_ASSET_DELEGATION = 0x0000000000000000000000000000000000000822; /// @dev The MultiAssetDelegation contract's instance. MultiAssetDelegation constant MULTI_ASSET_DELEGATION_CONTRACT = MultiAssetDelegation(MULTI_ASSET_DELEGATION); @@ -10,7 +10,7 @@ MultiAssetDelegation constant MULTI_ASSET_DELEGATION_CONTRACT = MultiAssetDelega /// @author The Tangle Team /// @title Pallet MultiAssetDelegation Interface /// @title The interface through which solidity contracts will interact with the MultiAssetDelegation pallet -/// @custom:address 0x0000000000000000000000000000000000000809 +/// @custom:address 0x0000000000000000000000000000000000000822 interface MultiAssetDelegation { /// @dev Join as an operator with a bond amount. /// @param bondAmount The amount to bond as an operator. diff --git a/precompiles/utils/src/tests.rs b/precompiles/utils/src/tests.rs index af6cf952e..f9e523a60 100644 --- a/precompiles/utils/src/tests.rs +++ b/precompiles/utils/src/tests.rs @@ -918,3 +918,10 @@ fn evm_data_solidity_types() { // Struct encode like tuples assert_eq!(MultiLocation::signature(), "(uint8,bytes[])"); } + +// #[test] +// fn calculate_precompile_address() { +// use crate::precompile_set::AddressU64; +// let address = H160::from_low_u64_be(2082); +// println!("Address {:?}", address); +// } diff --git a/runtime/mainnet/Cargo.toml b/runtime/mainnet/Cargo.toml index 609450f48..8df55ee14 100644 --- a/runtime/mainnet/Cargo.toml +++ b/runtime/mainnet/Cargo.toml @@ -21,9 +21,6 @@ scale-info = { workspace = true } serde = { workspace = true } static_assertions = { workspace = true } -# Webb Substrate Dependencies -pallet-airdrop-claims = { workspace = true } - # Substrate dependencies sp-api = { workspace = true } sp-block-builder = { workspace = true } @@ -70,7 +67,7 @@ pallet-scheduler = { workspace = true } pallet-staking = { workspace = true } pallet-staking-reward-curve = { workspace = true } pallet-treasury = { workspace = true } - +pallet-assets = { workspace = true } pallet-authorship = { workspace = true } pallet-balances = { workspace = true } pallet-identity = { workspace = true } @@ -86,12 +83,17 @@ pallet-multisig = { workspace = true } pallet-vesting = { workspace = true } # Tangle dependencies -tangle-primitives = { workspace = true } +pallet-airdrop-claims = { workspace = true } +pallet-services = { workspace = true } +pallet-services-rpc-runtime-api = { workspace = true } +tangle-primitives = { workspace = true, features = ["verifying"] } tangle-crypto-primitives = { workspace = true } +pallet-multi-asset-delegation = { workspace = true } # Frontier dependencies fp-rpc = { workspace = true } fp-self-contained = { workspace = true } +fp-evm = { workspace = true } # Frontier FRAME dependencies pallet-base-fee = { workspace = true } @@ -108,10 +110,10 @@ pallet-evm-precompile-ed25519 = { workspace = true } pallet-evm-precompile-modexp = { workspace = true } pallet-evm-precompile-sha3fips = { workspace = true } pallet-evm-precompile-simple = { workspace = true } - +pallet-evm-precompileset-assets-erc20 = { workspace = true } pallet-hotfix-sufficients = { workspace = true } -## Moonbeam precompiles +## Tangle precompiles pallet-evm-precompile-batch = { workspace = true } pallet-evm-precompile-call-permit = { workspace = true } pallet-evm-precompile-democracy = { workspace = true } @@ -120,6 +122,11 @@ pallet-evm-precompile-proxy = { workspace = true } pallet-evm-precompile-registry = { workspace = true } pallet-evm-precompile-staking = { workspace = true } pallet-evm-precompile-vesting = { workspace = true } +pallet-evm-precompile-verify-ecdsa-secp256k1-signature = { workspace = true } +pallet-evm-precompile-verify-ecdsa-secp256r1-signature = { workspace = true } +pallet-evm-precompile-verify-ecdsa-stark-signature = { workspace = true } +pallet-evm-precompile-verify-schnorr-signatures = { workspace = true } +pallet-evm-precompile-verify-bls381-signature = { workspace = true } pallet-evm-precompile-multi-asset-delegation = { workspace = true } precompile-utils = { workspace = true } @@ -207,15 +214,19 @@ std = [ "pallet-identity/std", "frame-system-benchmarking?/std", "sp-storage/std", + "pallet-assets/std", - # Tangle dependencies + # Tangle dependencies "tangle-primitives/std", "tangle-crypto-primitives/std", - + "pallet-services/std", + "pallet-multi-asset-delegation/std", + "pallet-services-rpc-runtime-api/std", # Frontier "fp-rpc/std", "fp-self-contained/std", + "fp-evm/std", # Frontier FRAME "pallet-base-fee/std", @@ -237,6 +248,7 @@ std = [ "evm-tracer/std", "rpc-primitives-debug/std", "rpc-primitives-txpool/std", + "pallet-evm-precompileset-assets-erc20/std", # Tangle precompiles "pallet-evm-precompile-preimage/std", @@ -248,6 +260,11 @@ std = [ "pallet-evm-precompile-staking/std", "pallet-evm-precompile-vesting/std", "pallet-evm-precompile-multi-asset-delegation/std", + "pallet-evm-precompile-verify-ecdsa-secp256k1-signature/std", + "pallet-evm-precompile-verify-ecdsa-secp256r1-signature/std", + "pallet-evm-precompile-verify-ecdsa-stark-signature/std", + "pallet-evm-precompile-verify-schnorr-signatures/std", + "pallet-evm-precompile-verify-bls381-signature/std", ] integration-tests = ["tangle-primitives/integration-tests"] with-rocksdb-weights = [] diff --git a/runtime/mainnet/src/frontier_evm.rs b/runtime/mainnet/src/frontier_evm.rs index e93163ec9..cb41b4910 100644 --- a/runtime/mainnet/src/frontier_evm.rs +++ b/runtime/mainnet/src/frontier_evm.rs @@ -16,7 +16,7 @@ // limitations under the License. use crate::{ - precompiles::{PrecompileName, WebbPrecompiles}, + precompiles::{PrecompileName, TanglePrecompiles}, *, }; use frame_support::{pallet_prelude::*, parameter_types, traits::FindAuthor, weights::Weight}; @@ -24,11 +24,33 @@ use sp_core::{crypto::ByteArray, H160, U256}; use sp_runtime::{traits::BlakeTwo256, ConsensusEngineId, Permill}; use sp_std::{marker::PhantomData, prelude::*}; // Frontier +use crate::precompiles::ASSET_PRECOMPILE_ADDRESS_PREFIX; use pallet_ethereum::PostLogContent; use pallet_evm::HashedAddressMapping; +use pallet_evm_precompileset_assets_erc20::AddressToAssetId; use tangle_primitives::evm::WEIGHT_PER_GAS; impl pallet_evm_chain_id::Config for Runtime {} +impl AddressToAssetId for Runtime { + fn address_to_asset_id(address: H160) -> Option { + let mut data = [0u8; 16]; + let address_bytes: [u8; 20] = address.into(); + if ASSET_PRECOMPILE_ADDRESS_PREFIX.eq(&address_bytes[0..4]) { + data.copy_from_slice(&address_bytes[4..20]); + Some(u128::from_be_bytes(data)) + } else { + None + } + } + + fn asset_id_to_address(asset_id: AssetId) -> H160 { + let mut data = [0u8; 20]; + data[0..4].copy_from_slice(ASSET_PRECOMPILE_ADDRESS_PREFIX); + data[4..20].copy_from_slice(&asset_id.to_be_bytes()); + H160::from(data) + } +} + pub struct FindAuthorTruncated(PhantomData); impl> FindAuthor for FindAuthorTruncated { fn find_author<'a, I>(digests: I) -> Option @@ -129,7 +151,7 @@ parameter_types! { /// ) pub const GasLimitPovSizeRatio: u64 = 4; pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0); - pub PrecompilesValue: WebbPrecompiles = WebbPrecompiles::<_>::new(); + pub PrecompilesValue: TanglePrecompiles = TanglePrecompiles::<_>::new(); pub SuicideQuickClearLimit: u32 = 0; } @@ -143,7 +165,7 @@ impl pallet_evm::Config for Runtime { type AddressMapping = HashedAddressMapping; type Currency = Balances; type RuntimeEvent = RuntimeEvent; - type PrecompilesType = WebbPrecompiles; + type PrecompilesType = TanglePrecompiles; type PrecompilesValue = PrecompilesValue; type ChainId = EVMChainId; type BlockGasLimit = BlockGasLimit; diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index 0a7b7325b..14da3e9fe 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -26,12 +26,14 @@ pub mod frontier_evm; pub mod impls; pub mod migrations; pub mod precompiles; +pub mod tangle_services; pub mod voter_bags; use frame_election_provider_support::{ bounds::{ElectionBounds, ElectionBoundsBuilder}, onchain, BalancingConfig, ElectionDataProvider, SequentialPhragmen, VoteWeight, }; +use frame_support::traits::AsEnsureOriginWithArg; use frame_support::{ traits::{ tokens::{PayFromAccount, UnityAssetBalanceConversion}, @@ -39,11 +41,13 @@ use frame_support::{ }, weights::ConstantMultiplier, }; +use frame_system::EnsureSigned; use pallet_election_provider_multi_phase::{GeometricDepositBase, SolutionAccuracyOf}; use pallet_grandpa::{ fg_primitives, AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList, }; use pallet_im_online::sr25519::AuthorityId as ImOnlineId; +use pallet_services_rpc_runtime_api::BlockNumberOf; use pallet_session::historical as pallet_session_historical; pub use pallet_staking::StakerStatus; use pallet_transaction_payment::{ @@ -71,6 +75,8 @@ use sp_runtime::{ SaturatedConversion, }; use sp_staking::currency_to_vote::U128CurrencyToVote; +use tangle_primitives::services::RpcServicesWithBlueprint; +pub use tangle_services::PalletServicesConstraints; #[cfg(any(feature = "std", test))] pub use frame_system::Call as SystemCall; @@ -1201,6 +1207,66 @@ impl pallet_proxy::Config for Runtime { type AnnouncementDepositFactor = AnnouncementDepositFactor; } +parameter_types! { + pub const AssetDeposit: Balance = 10 * UNIT; + pub const AssetAccountDeposit: Balance = DOLLAR; + pub const ApprovalDeposit: Balance = ExistentialDeposit::get(); + pub const AssetsStringLimit: u32 = 50; + pub const MetadataDepositBase: Balance = deposit(1, 68); + pub const MetadataDepositPerByte: Balance = deposit(0, 1); +} + +pub type AssetId = u128; + +impl pallet_assets::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Balance = Balance; + type AssetId = AssetId; + type AssetIdParameter = parity_scale_codec::Compact; + type Currency = Balances; + type CreateOrigin = AsEnsureOriginWithArg>; + type ForceOrigin = frame_system::EnsureRoot; + type AssetDeposit = AssetDeposit; + type AssetAccountDeposit = AssetAccountDeposit; + type MetadataDepositBase = MetadataDepositBase; + type MetadataDepositPerByte = MetadataDepositPerByte; + type ApprovalDeposit = ApprovalDeposit; + type StringLimit = AssetsStringLimit; + type RemoveItemsLimit = ConstU32<1000>; + type Freezer = (); + type Extra = (); + type CallbackHandle = (); + type WeightInfo = pallet_assets::weights::SubstrateWeight; + #[cfg(feature = "runtime-benchmarks")] + type BenchmarkHelper = (); +} + +parameter_types! { + pub const MinOperatorBondAmount: Balance = 10_000; + pub const BondDuration: u32 = 10; + pub const MinDelegateAmount : Balance = 1000; + pub PID: PalletId = PalletId(*b"PotStake"); +} + +impl pallet_multi_asset_delegation::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type Currency = Balances; + type MinOperatorBondAmount = MinOperatorBondAmount; + type BondDuration = BondDuration; + type ServiceManager = Services; + type LeaveOperatorsDelay = ConstU32<10>; + type OperatorBondLessDelay = ConstU32<1>; + type LeaveDelegatorsDelay = ConstU32<1>; + type DelegationBondLessDelay = ConstU32<5>; + type MinDelegateAmount = MinDelegateAmount; + type Fungibles = Assets; + type AssetId = AssetId; + type ForceOrigin = frame_system::EnsureRoot; + type PalletId = PID; + type PoolId = AssetId; + type WeightInfo = (); +} + // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( pub enum Runtime { @@ -1257,7 +1323,9 @@ construct_runtime!( // Jobs: pallet_jobs = 41, // Dkg: pallet_dkg = 42, // ZkSaaS: pallet_zksaas = 43, - + Assets: pallet_assets = 44, + MultiAssetDelegation: pallet_multi_asset_delegation = 45, + Services: pallet_services = 46, } ); @@ -1782,6 +1850,17 @@ impl_runtime_apis! { } } + impl pallet_services_rpc_runtime_api::ServicesApi for Runtime { + fn query_services_with_blueprints_by_operator( + operator: AccountId, + ) -> Result< + Vec>>, + sp_runtime::DispatchError, + > { + Services::services_with_blueprints_by_operator(operator).map_err(Into::into) + } + } + impl fg_primitives::GrandpaApi for Runtime { fn grandpa_authorities() -> GrandpaAuthorityList { Grandpa::grandpa_authorities() diff --git a/runtime/mainnet/src/precompiles.rs b/runtime/mainnet/src/precompiles.rs index 81d8dcd37..a1d4163ed 100644 --- a/runtime/mainnet/src/precompiles.rs +++ b/runtime/mainnet/src/precompiles.rs @@ -12,26 +12,36 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. +use frame_support::parameter_types; use pallet_evm_precompile_balances_erc20::{Erc20BalancesPrecompile, Erc20Metadata}; use pallet_evm_precompile_batch::BatchPrecompile; use pallet_evm_precompile_blake2::Blake2F; use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing}; use pallet_evm_precompile_call_permit::CallPermitPrecompile; +use pallet_evm_precompile_curve25519::{Curve25519Add, Curve25519ScalarMul}; use pallet_evm_precompile_democracy::DemocracyPrecompile; +use pallet_evm_precompile_dispatch::Dispatch; +use pallet_evm_precompile_ed25519::Ed25519Verify; use pallet_evm_precompile_modexp::Modexp; +use pallet_evm_precompile_multi_asset_delegation::MultiAssetDelegationPrecompile; use pallet_evm_precompile_preimage::PreimagePrecompile; use pallet_evm_precompile_registry::PrecompileRegistry; use pallet_evm_precompile_sha3fips::Sha3FIPS256; use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256}; use pallet_evm_precompile_staking::StakingPrecompile; +use pallet_evm_precompile_verify_bls381_signature::Bls381Precompile; +use pallet_evm_precompile_verify_ecdsa_secp256k1_signature::EcdsaSecp256k1Precompile; +use pallet_evm_precompile_verify_ecdsa_secp256r1_signature::EcdsaSecp256r1Precompile; +use pallet_evm_precompile_verify_ecdsa_stark_signature::EcdsaStarkPrecompile; +use pallet_evm_precompile_verify_schnorr_signatures::*; use pallet_evm_precompile_vesting::VestingPrecompile; -//use pallet_evm_precompile_multi_asset_delegation::MultiAssetDelegationPrecompile; - +use pallet_evm_precompileset_assets_erc20::Erc20AssetsPrecompileSet; +use precompile_utils::precompile_set::PrecompileSetStartingWith; +use precompile_utils::precompile_set::PrecompilesInRangeInclusive; use precompile_utils::precompile_set::{ AcceptDelegateCall, AddressU64, CallableByContract, CallableByPrecompile, OnlyFrom, PrecompileAt, PrecompileSetBuilder, SubcallWithMaxNesting, }; - type EthereumPrecompilesChecks = (AcceptDelegateCall, CallableByContract, CallableByPrecompile); pub struct NativeErc20Metadata; @@ -60,8 +70,16 @@ impl Erc20Metadata for NativeErc20Metadata { } } +/// The asset precompile address prefix. Addresses that match against this prefix will be routed +/// to Erc20AssetsPrecompileSet being marked as foreign +pub const ASSET_PRECOMPILE_ADDRESS_PREFIX: &[u8] = &[255u8; 4]; + +parameter_types! { + pub ForeignAssetPrefix: &'static [u8] = ASSET_PRECOMPILE_ADDRESS_PREFIX; +} + #[precompile_utils::precompile_name_from_address] -pub type WebbPrecompilesAt = ( +pub type TanglePrecompilesAt = ( // Ethereum precompiles: PrecompileAt, ECRecover, EthereumPrecompilesChecks>, PrecompileAt, Sha256, EthereumPrecompilesChecks>, @@ -73,7 +91,12 @@ pub type WebbPrecompilesAt = ( PrecompileAt, Bn128Pairing, EthereumPrecompilesChecks>, PrecompileAt, Blake2F, EthereumPrecompilesChecks>, PrecompileAt, Sha3FIPS256, (CallableByContract, CallableByPrecompile)>, + PrecompileAt, Dispatch, (CallableByContract, CallableByPrecompile)>, PrecompileAt, ECRecoverPublicKey, (CallableByContract, CallableByPrecompile)>, + PrecompileAt, Curve25519Add, (CallableByContract, CallableByPrecompile)>, + PrecompileAt, Curve25519ScalarMul, (CallableByContract, CallableByPrecompile)>, + PrecompileAt, Ed25519Verify, (CallableByContract, CallableByPrecompile)>, + // Tangle precompiles PrecompileAt< AddressU64<2048>, StakingPrecompile, @@ -84,7 +107,6 @@ pub type WebbPrecompilesAt = ( VestingPrecompile, (CallableByContract, CallableByPrecompile), >, - // Moonbeam precompiles PrecompileAt< AddressU64<2050>, Erc20BalancesPrecompile, @@ -96,7 +118,7 @@ pub type WebbPrecompilesAt = ( (CallableByContract, CallableByPrecompile), >, PrecompileAt< - AddressU64<2056>, + AddressU64<2052>, BatchPrecompile, ( SubcallWithMaxNesting<2>, @@ -105,25 +127,104 @@ pub type WebbPrecompilesAt = ( ), >, PrecompileAt< - AddressU64<2058>, + AddressU64<2053>, CallPermitPrecompile, (SubcallWithMaxNesting<0>, CallableByContract), >, PrecompileAt< - AddressU64<2067>, + AddressU64<2054>, PreimagePrecompile, (CallableByContract, CallableByPrecompile), >, PrecompileAt< - AddressU64<2069>, + AddressU64<2055>, PrecompileRegistry, (CallableByContract, CallableByPrecompile), >, - // PrecompileAt< - // AddressU64<2070>, - // MultiAssetDelegationPrecompile, - // (CallableByContract, CallableByPrecompile), - // >, + // Ecdsa-Secp256k1 signature verifier precompile + PrecompileAt< + AddressU64<2070>, + EcdsaSecp256k1Precompile, + (CallableByContract, CallableByPrecompile), + >, + // Ecdsa-Secp256r1 signature verifier precompile + PrecompileAt< + AddressU64<2071>, + EcdsaSecp256r1Precompile, + (CallableByContract, CallableByPrecompile), + >, + // Ecdsa-Stark signature verifier precompile + PrecompileAt< + AddressU64<2072>, + EcdsaStarkPrecompile, + (CallableByContract, CallableByPrecompile), + >, + // Schnorr-Sr25519 signature verifier precompile + PrecompileAt< + AddressU64<2073>, + SchnorrSr25519Precompile, + (CallableByContract, CallableByPrecompile), + >, + // Schnorr-Secp256k1 signature verifier precompile + PrecompileAt< + AddressU64<2074>, + SchnorrSecp256k1Precompile, + (CallableByContract, CallableByPrecompile), + >, + // Schnorr-Ed25519 signature verifier precompile + PrecompileAt< + AddressU64<2075>, + SchnorrEd25519Precompile, + (CallableByContract, CallableByPrecompile), + >, + // Schnorr-Ed448 signature verifier precompile + PrecompileAt< + AddressU64<2076>, + SchnorrEd448Precompile, + (CallableByContract, CallableByPrecompile), + >, + // Schnorr-P256 signature verifier precompile + PrecompileAt< + AddressU64<2077>, + SchnorrP256Precompile, + (CallableByContract, CallableByPrecompile), + >, + // Schnorr-P384 signature verifier precompile + PrecompileAt< + AddressU64<2078>, + SchnorrP384Precompile, + (CallableByContract, CallableByPrecompile), + >, + // Schnorr-Ristretto255 signature verifier precompile + PrecompileAt< + AddressU64<2079>, + SchnorrRistretto255Precompile, + (CallableByContract, CallableByPrecompile), + >, + // Schnorr-Taproot signature verifier precompile + PrecompileAt< + AddressU64<2080>, + SchnorrTaprootPrecompile, + (CallableByContract, CallableByPrecompile), + >, + PrecompileAt, Bls381Precompile, (CallableByContract, CallableByPrecompile)>, + // MultiAsset Delegation precompile + PrecompileAt< + AddressU64<2082>, + MultiAssetDelegationPrecompile, + (CallableByContract, CallableByPrecompile), + >, ); -pub type WebbPrecompiles = PrecompileSetBuilder>; +pub type TanglePrecompiles = PrecompileSetBuilder< + R, + ( + PrecompilesInRangeInclusive<(AddressU64<1>, AddressU64<2095>), TanglePrecompilesAt>, + // Prefixed precompile sets (XC20) + PrecompileSetStartingWith< + ForeignAssetPrefix, + Erc20AssetsPrecompileSet, + CallableByContract, + >, + ), +>; diff --git a/runtime/mainnet/src/tangle_services.rs b/runtime/mainnet/src/tangle_services.rs new file mode 100644 index 000000000..5492681cc --- /dev/null +++ b/runtime/mainnet/src/tangle_services.rs @@ -0,0 +1,153 @@ +use super::*; +use frontier_evm::DefaultBaseFeePerGas; +use pallet_evm::GasWeightMapping; +use scale_info::TypeInfo; + +parameter_types! { + pub const ServicesPalletId: PalletId = PalletId(*b"py/srvcs"); +} + +pub struct PalletEvmRunner; + +impl pallet_services::EvmRunner for PalletEvmRunner { + type Error = pallet_evm::Error; + + fn call( + source: sp_core::H160, + target: sp_core::H160, + input: Vec, + value: sp_core::U256, + gas_limit: u64, + is_transactional: bool, + validate: bool, + ) -> Result> { + let max_fee_per_gas = DefaultBaseFeePerGas::get(); + let max_priority_fee_per_gas = + max_fee_per_gas.saturating_mul(U256::from(3) / U256::from(2)); + let nonce = None; + let access_list = Default::default(); + let weight_limit = None; + let proof_size_base_cost = None; + <::Runner as pallet_evm::Runner>::call( + source, + target, + input, + value, + gas_limit, + Some(max_fee_per_gas), + Some(max_priority_fee_per_gas), + nonce, + access_list, + is_transactional, + validate, + weight_limit, + proof_size_base_cost, + ::config(), + ) + .map_err(|o| pallet_services::RunnerError { error: o.error, weight: o.weight }) + } +} + +pub struct PalletEVMGasWeightMapping; + +impl pallet_services::EvmGasWeightMapping for PalletEVMGasWeightMapping { + fn gas_to_weight(gas: u64, without_base_weight: bool) -> Weight { + pallet_evm::FixedGasWeightMapping::::gas_to_weight(gas, without_base_weight) + } + + fn weight_to_gas(weight: Weight) -> u64 { + pallet_evm::FixedGasWeightMapping::::weight_to_gas(weight) + } +} + +parameter_types! { + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxFields: u32 = 256; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxFieldsSize: u32 = 1024; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxMetadataLength: u32 = 1024; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxJobsPerService: u32 = 1024; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxOperatorsPerService: u32 = 1024; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxPermittedCallers: u32 = 256; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxServicesPerOperator: u32 = 1024; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxBlueprintsPerOperator: u32 = 1024; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxServicesPerUser: u32 = 1024; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxBinariesPerGadget: u32 = 64; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxSourcesPerGadget: u32 = 64; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxGitOwnerLength: u32 = 1024; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxGitRepoLength: u32 = 1024; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxGitTagLength: u32 = 1024; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxBinaryNameLength: u32 = 1024; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxIpfsHashLength: u32 = 46; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxContainerRegistryLength: u32 = 1024; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxContainerImageNameLength: u32 = 1024; + + #[derive(Default, Copy, Clone, Eq, PartialEq, RuntimeDebug, Encode, Decode, MaxEncodedLen, TypeInfo, Serialize, Deserialize)] + pub const MaxContainerImageTagLength: u32 = 1024; +} + +pub type PalletServicesConstraints = pallet_services::types::ConstraintsOf; + +impl pallet_services::Config for Runtime { + type RuntimeEvent = RuntimeEvent; + type ForceOrigin = EnsureRootOrHalfCouncil; + type Currency = Balances; + type PalletId = ServicesPalletId; + type EvmRunner = PalletEvmRunner; + type EvmGasWeightMapping = PalletEVMGasWeightMapping; + type MaxFields = MaxFields; + type MaxFieldsSize = MaxFieldsSize; + type MaxMetadataLength = MaxMetadataLength; + type MaxJobsPerService = MaxJobsPerService; + type MaxOperatorsPerService = MaxOperatorsPerService; + type MaxPermittedCallers = MaxPermittedCallers; + type MaxServicesPerOperator = MaxServicesPerOperator; + type MaxBlueprintsPerOperator = MaxBlueprintsPerOperator; + type MaxServicesPerUser = MaxServicesPerUser; + type MaxBinariesPerGadget = MaxBinariesPerGadget; + type MaxSourcesPerGadget = MaxSourcesPerGadget; + type MaxGitOwnerLength = MaxGitOwnerLength; + type MaxGitRepoLength = MaxGitRepoLength; + type MaxGitTagLength = MaxGitTagLength; + type MaxBinaryNameLength = MaxBinaryNameLength; + type MaxIpfsHashLength = MaxIpfsHashLength; + type MaxContainerRegistryLength = MaxContainerRegistryLength; + type MaxContainerImageNameLength = MaxContainerImageNameLength; + type MaxContainerImageTagLength = MaxContainerImageTagLength; + type Constraints = PalletServicesConstraints; + type OperatorDelegationManager = MultiAssetDelegation; + type WeightInfo = (); +} diff --git a/runtime/testnet/Cargo.toml b/runtime/testnet/Cargo.toml index 6cf4021b3..08f7f3b1f 100644 --- a/runtime/testnet/Cargo.toml +++ b/runtime/testnet/Cargo.toml @@ -117,7 +117,6 @@ pallet-evm-precompile-ed25519 = { workspace = true } pallet-evm-precompile-modexp = { workspace = true } pallet-evm-precompile-sha3fips = { workspace = true } pallet-evm-precompile-simple = { workspace = true } - pallet-hotfix-sufficients = { workspace = true } ## Tangle precompiles diff --git a/runtime/testnet/src/frontier_evm.rs b/runtime/testnet/src/frontier_evm.rs index ee952e744..f66af713b 100644 --- a/runtime/testnet/src/frontier_evm.rs +++ b/runtime/testnet/src/frontier_evm.rs @@ -16,7 +16,7 @@ // limitations under the License. use crate::{ - precompiles::{PrecompileName, WebbPrecompiles, ASSET_PRECOMPILE_ADDRESS_PREFIX}, + precompiles::{PrecompileName, TanglePrecompiles, ASSET_PRECOMPILE_ADDRESS_PREFIX}, *, }; use frame_support::{pallet_prelude::*, parameter_types, traits::FindAuthor, weights::Weight}; @@ -77,7 +77,7 @@ parameter_types! { ); pub const GasLimitPovSizeRatio: u64 = GAS_LIMIT_POV_SIZE_RATIO; pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0); - pub PrecompilesValue: WebbPrecompiles = WebbPrecompiles::<_>::new(); + pub PrecompilesValue: TanglePrecompiles = TanglePrecompiles::<_>::new(); } /// Type alias for negative imbalance during fees @@ -139,7 +139,7 @@ impl pallet_evm::Config for Runtime { type AddressMapping = HashedAddressMapping; type Currency = Balances; type RuntimeEvent = RuntimeEvent; - type PrecompilesType = WebbPrecompiles; + type PrecompilesType = TanglePrecompiles; type PrecompilesValue = PrecompilesValue; type ChainId = EVMChainId; type BlockGasLimit = BlockGasLimit; diff --git a/runtime/testnet/src/lib.rs b/runtime/testnet/src/lib.rs index d9eff67f8..188540ad7 100644 --- a/runtime/testnet/src/lib.rs +++ b/runtime/testnet/src/lib.rs @@ -60,7 +60,7 @@ use pallet_tx_pause::RuntimeCallNameOf; use parity_scale_codec::MaxEncodedLen; use parity_scale_codec::{Decode, Encode}; use polkadot_parachain_primitives::primitives::Sibling; -use precompiles::WebbPrecompiles; +use precompiles::TanglePrecompiles; use scale_info::TypeInfo; use serde::{Deserialize, Serialize}; use sp_api::impl_runtime_apis; @@ -161,7 +161,7 @@ use tangle_primitives::{ pub use tangle_services::PalletServicesConstraints; // Precompiles -pub type Precompiles = WebbPrecompiles; +pub type Precompiles = TanglePrecompiles; // Frontier use fp_rpc::TransactionStatus; @@ -1415,7 +1415,6 @@ parameter_types! { pub const AssetsStringLimit: u32 = 50; pub const MetadataDepositBase: Balance = deposit(1, 68); pub const MetadataDepositPerByte: Balance = deposit(0, 1); - pub const ExecutiveBody: BodyId = BodyId::Executive; } pub type AssetId = u128; diff --git a/runtime/testnet/src/precompiles.rs b/runtime/testnet/src/precompiles.rs index 189462f84..40d01a44d 100644 --- a/runtime/testnet/src/precompiles.rs +++ b/runtime/testnet/src/precompiles.rs @@ -17,7 +17,10 @@ use pallet_evm_precompile_batch::BatchPrecompile; use pallet_evm_precompile_blake2::Blake2F; use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing}; use pallet_evm_precompile_call_permit::CallPermitPrecompile; +use pallet_evm_precompile_curve25519::{Curve25519Add, Curve25519ScalarMul}; use pallet_evm_precompile_democracy::DemocracyPrecompile; +use pallet_evm_precompile_dispatch::Dispatch; +use pallet_evm_precompile_ed25519::Ed25519Verify; use pallet_evm_precompile_modexp::Modexp; use pallet_evm_precompile_multi_asset_delegation::MultiAssetDelegationPrecompile; use pallet_evm_precompile_preimage::PreimagePrecompile; @@ -73,7 +76,7 @@ parameter_types! { } #[precompile_utils::precompile_name_from_address] -pub type WebbPrecompilesAt = ( +pub type TanglePrecompilesAt = ( // Ethereum precompiles: PrecompileAt, ECRecover, EthereumPrecompilesChecks>, PrecompileAt, Sha256, EthereumPrecompilesChecks>, @@ -85,7 +88,11 @@ pub type WebbPrecompilesAt = ( PrecompileAt, Bn128Pairing, EthereumPrecompilesChecks>, PrecompileAt, Blake2F, EthereumPrecompilesChecks>, PrecompileAt, Sha3FIPS256, (CallableByContract, CallableByPrecompile)>, + PrecompileAt, Dispatch, (CallableByContract, CallableByPrecompile)>, PrecompileAt, ECRecoverPublicKey, (CallableByContract, CallableByPrecompile)>, + PrecompileAt, Curve25519Add, (CallableByContract, CallableByPrecompile)>, + PrecompileAt, Curve25519ScalarMul, (CallableByContract, CallableByPrecompile)>, + PrecompileAt, Ed25519Verify, (CallableByContract, CallableByPrecompile)>, // Tangle precompiles PrecompileAt< AddressU64<2048>, @@ -197,8 +204,8 @@ pub type WebbPrecompilesAt = ( SchnorrTaprootPrecompile, (CallableByContract, CallableByPrecompile), >, - // Bls12-381 signature verifier precompile PrecompileAt, Bls381Precompile, (CallableByContract, CallableByPrecompile)>, + // MultiAsset Delegation precompile PrecompileAt< AddressU64<2082>, MultiAssetDelegationPrecompile, @@ -206,10 +213,10 @@ pub type WebbPrecompilesAt = ( >, ); -pub type WebbPrecompiles = PrecompileSetBuilder< +pub type TanglePrecompiles = PrecompileSetBuilder< R, ( - PrecompilesInRangeInclusive<(AddressU64<1>, AddressU64<2095>), WebbPrecompilesAt>, + PrecompilesInRangeInclusive<(AddressU64<1>, AddressU64<2095>), TanglePrecompilesAt>, // Prefixed precompile sets (XC20) PrecompileSetStartingWith< ForeignAssetPrefix,