@@ -43,8 +43,9 @@ use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
4343use cumulus_primitives_core:: { AggregateMessageOrigin , ParaId } ;
4444use kusama_runtime_constants:: time:: MINUTES as RC_MINUTES ;
4545use pallet_proxy:: ProxyDefinition ;
46+ use pallet_revive:: { evm:: runtime:: EthExtra , AddressMapper } ;
4647use sp_api:: impl_runtime_apis;
47- use sp_core:: { crypto:: KeyTypeId , OpaqueMetadata } ;
48+ use sp_core:: { crypto:: KeyTypeId , OpaqueMetadata , H160 , U256 } ;
4849use sp_runtime:: {
4950 generic, impl_opaque_keys,
5051 traits:: {
@@ -62,13 +63,13 @@ use sp_version::RuntimeVersion;
6263use codec:: { Decode , DecodeWithMemTracking , Encode , MaxEncodedLen } ;
6364use frame_support:: {
6465 construct_runtime,
65- dispatch:: DispatchClass ,
66+ dispatch:: { DispatchClass , DispatchInfo } ,
6667 genesis_builder_helper:: { build_state, get_preset} ,
6768 ord_parameter_types, parameter_types,
6869 traits:: {
6970 fungible, fungibles, tokens:: imbalance:: ResolveAssetTo , AsEnsureOriginWithArg , ConstBool ,
7071 ConstU128 , ConstU32 , ConstU64 , ConstU8 , Contains , EitherOfDiverse , Equals , EverythingBut ,
71- InstanceFilter , TransformOrigin , WithdrawReasons ,
72+ InstanceFilter , Nothing , TransformOrigin , WithdrawReasons ,
7273 } ,
7374 weights:: { ConstantMultiplier , Weight , WeightToFee as _} ,
7475 BoundedVec , PalletId ,
@@ -82,7 +83,7 @@ use parachains_common::{
8283 message_queue:: * , AccountId , AssetIdForTrustBackedAssets , AuraId , Balance , BlockNumber , Hash ,
8384 Header , Nonce , Signature ,
8485} ;
85- use sp_runtime:: RuntimeDebug ;
86+ use sp_runtime:: { traits :: TransactionExtension , RuntimeDebug } ;
8687pub use system_parachains_constants:: async_backing:: SLOT_DURATION ;
8788use system_parachains_constants:: {
8889 async_backing:: {
@@ -1029,6 +1030,38 @@ impl pallet_remote_proxy::Config for Runtime {
10291030 type WeightInfo = weights:: pallet_remote_proxy:: WeightInfo < Runtime > ;
10301031}
10311032
1033+ parameter_types ! {
1034+ pub const DepositPerItem : Balance = system_para_deposit( 1 , 0 ) ;
1035+ pub const DepositPerByte : Balance = system_para_deposit( 0 , 1 ) ;
1036+ pub CodeHashLockupDepositPercent : Perbill = Perbill :: from_percent( 30 ) ;
1037+ }
1038+
1039+ impl pallet_revive:: Config for Runtime {
1040+ type Time = Timestamp ;
1041+ type Currency = Balances ;
1042+ type RuntimeEvent = RuntimeEvent ;
1043+ type RuntimeCall = RuntimeCall ;
1044+ type CallFilter = Nothing ;
1045+ type DepositPerItem = DepositPerItem ;
1046+ type DepositPerByte = DepositPerByte ;
1047+ type WeightPrice = pallet_transaction_payment:: Pallet < Self > ;
1048+ type WeightInfo = weights:: pallet_revive:: WeightInfo < Self > ;
1049+ type ChainExtension = ( ) ;
1050+ type AddressMapper = pallet_revive:: AccountId32Mapper < Self > ;
1051+ type RuntimeMemory = ConstU32 < { 128 * 1024 * 1024 } > ;
1052+ type PVFMemory = ConstU32 < { 512 * 1024 * 1024 } > ;
1053+ type UnsafeUnstableInterface = ConstBool < false > ;
1054+ type UploadOrigin = EnsureSigned < Self :: AccountId > ;
1055+ type InstantiateOrigin = EnsureSigned < Self :: AccountId > ;
1056+ type RuntimeHoldReason = RuntimeHoldReason ;
1057+ type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent ;
1058+ type Xcm = pallet_xcm:: Pallet < Self > ;
1059+ type ChainId = ConstU64 < 420_420_418 > ;
1060+ type NativeToEthRatio = ConstU32 < 1_000_000 > ; // 10^(18 - 12) Eth is 10^18, Native is 10^12.
1061+ type EthGasEncoder = ( ) ;
1062+ type FindAuthor = <Runtime as pallet_authorship:: Config >:: FindAuthor ;
1063+ }
1064+
10321065// Create the runtime by composing the FRAME pallets that were previously configured.
10331066construct_runtime ! (
10341067 pub enum Runtime
@@ -1077,6 +1110,8 @@ construct_runtime!(
10771110 PoolAssets : pallet_assets:: <Instance3 > = 55 ,
10781111 AssetConversion : pallet_asset_conversion = 56 ,
10791112
1113+ Revive : pallet_revive = 60 ,
1114+
10801115 // State trie migration pallet, only temporary.
10811116 StateTrieMigration : pallet_state_trie_migration = 70 ,
10821117 }
@@ -1102,9 +1137,45 @@ pub type TxExtension = (
11021137 pallet_asset_conversion_tx_payment:: ChargeAssetTxPayment < Runtime > ,
11031138 frame_metadata_hash_extension:: CheckMetadataHash < Runtime > ,
11041139) ;
1140+
1141+ /// Default extensions applied to Ethereum transactions.
1142+ #[ derive( Clone , PartialEq , Eq , Debug ) ]
1143+ pub struct EthExtraImpl ;
1144+
1145+ impl EthExtra for EthExtraImpl {
1146+ type Config = Runtime ;
1147+ type Extension = TxExtension ;
1148+
1149+ fn get_eth_extension ( nonce : u32 , tip : Balance ) -> Self :: Extension {
1150+ (
1151+ frame_system:: CheckNonZeroSender :: < Runtime > :: new ( ) ,
1152+ frame_system:: CheckSpecVersion :: < Runtime > :: new ( ) ,
1153+ frame_system:: CheckTxVersion :: < Runtime > :: new ( ) ,
1154+ frame_system:: CheckGenesis :: < Runtime > :: new ( ) ,
1155+ frame_system:: CheckMortality :: from ( generic:: Era :: Immortal ) ,
1156+ frame_system:: CheckNonce :: < Runtime > :: from ( nonce) ,
1157+ frame_system:: CheckWeight :: < Runtime > :: new ( ) ,
1158+ pallet_asset_conversion_tx_payment:: ChargeAssetTxPayment :: < Runtime > :: from ( tip, None ) ,
1159+ frame_metadata_hash_extension:: CheckMetadataHash :: < Runtime > :: new ( false ) ,
1160+ )
1161+ }
1162+ }
1163+
1164+ // This impl is no longer necessary post stable-2506.
1165+ impl TryFrom < RuntimeCall > for pallet_revive:: Call < Runtime > {
1166+ type Error = ( ) ;
1167+
1168+ fn try_from ( value : RuntimeCall ) -> Result < Self , Self :: Error > {
1169+ match value {
1170+ RuntimeCall :: Revive ( call) => Ok ( call) ,
1171+ _ => Err ( ( ) ) ,
1172+ }
1173+ }
1174+ }
1175+
11051176/// Unchecked extrinsic type as expected by this runtime.
11061177pub type UncheckedExtrinsic =
1107- generic :: UncheckedExtrinsic < Address , RuntimeCall , Signature , TxExtension > ;
1178+ pallet_revive :: evm :: runtime :: UncheckedExtrinsic < Address , Signature , EthExtraImpl > ;
11081179
11091180/// Migrations to apply on runtime upgrade.
11101181pub type Migrations = (
@@ -1221,6 +1292,7 @@ mod benches {
12211292 [ pallet_nfts, Nfts ]
12221293 [ pallet_proxy, Proxy ]
12231294 [ pallet_remote_proxy, RemoteProxyRelayChain ]
1295+ [ pallet_revive, Revive ]
12241296 [ pallet_session, SessionBench :: <Runtime >]
12251297 [ pallet_uniques, Uniques ]
12261298 [ pallet_utility, Utility ]
@@ -1889,6 +1961,173 @@ impl_runtime_apis! {
18891961 }
18901962 }
18911963
1964+ impl pallet_revive:: ReviveApi <Block , AccountId , Balance , Nonce , BlockNumber > for Runtime
1965+ {
1966+ fn balance( address: H160 ) -> U256 {
1967+ Revive :: evm_balance( & address)
1968+ }
1969+
1970+ fn block_gas_limit( ) -> U256 {
1971+ Revive :: evm_block_gas_limit( )
1972+ }
1973+
1974+ fn gas_price( ) -> U256 {
1975+ Revive :: evm_gas_price( )
1976+ }
1977+
1978+ fn nonce( address: H160 ) -> Nonce {
1979+ let account = <Runtime as pallet_revive:: Config >:: AddressMapper :: to_account_id( & address) ;
1980+ System :: account_nonce( account)
1981+ }
1982+
1983+ fn eth_transact( tx: pallet_revive:: evm:: GenericTransaction ) -> Result <pallet_revive:: EthTransactInfo <Balance >, pallet_revive:: EthTransactError >
1984+ {
1985+ let blockweights: BlockWeights = <Runtime as frame_system:: Config >:: BlockWeights :: get( ) ;
1986+ let tx_fee = |pallet_call, mut dispatch_info: DispatchInfo | {
1987+ let call = RuntimeCall :: Revive ( pallet_call) ;
1988+ dispatch_info. extension_weight = EthExtraImpl :: get_eth_extension( 0 , 0u32 . into( ) ) . weight( & call) ;
1989+ let uxt: UncheckedExtrinsic = sp_runtime:: generic:: UncheckedExtrinsic :: new_bare( call) . into( ) ;
1990+
1991+ pallet_transaction_payment:: Pallet :: <Runtime >:: compute_fee(
1992+ uxt. encoded_size( ) as u32 ,
1993+ & dispatch_info,
1994+ 0u32 . into( ) ,
1995+ )
1996+ } ;
1997+
1998+ Revive :: bare_eth_transact( tx, blockweights. max_block, tx_fee)
1999+ }
2000+
2001+ fn call(
2002+ origin: AccountId ,
2003+ dest: H160 ,
2004+ value: Balance ,
2005+ gas_limit: Option <Weight >,
2006+ storage_deposit_limit: Option <Balance >,
2007+ input_data: Vec <u8 >,
2008+ ) -> pallet_revive:: ContractResult <pallet_revive:: ExecReturnValue , Balance > {
2009+ let blockweights= <Runtime as frame_system:: Config >:: BlockWeights :: get( ) ;
2010+ Revive :: bare_call(
2011+ RuntimeOrigin :: signed( origin) ,
2012+ dest,
2013+ value,
2014+ gas_limit. unwrap_or( blockweights. max_block) ,
2015+ pallet_revive:: DepositLimit :: Balance ( storage_deposit_limit. unwrap_or( u128 :: MAX ) ) ,
2016+ input_data,
2017+ )
2018+ }
2019+
2020+ fn instantiate(
2021+ origin: AccountId ,
2022+ value: Balance ,
2023+ gas_limit: Option <Weight >,
2024+ storage_deposit_limit: Option <Balance >,
2025+ code: pallet_revive:: Code ,
2026+ data: Vec <u8 >,
2027+ salt: Option <[ u8 ; 32 ] >,
2028+ ) -> pallet_revive:: ContractResult <pallet_revive:: InstantiateReturnValue , Balance >
2029+ {
2030+ let blockweights= <Runtime as frame_system:: Config >:: BlockWeights :: get( ) ;
2031+ Revive :: bare_instantiate(
2032+ RuntimeOrigin :: signed( origin) ,
2033+ value,
2034+ gas_limit. unwrap_or( blockweights. max_block) ,
2035+ pallet_revive:: DepositLimit :: Balance ( storage_deposit_limit. unwrap_or( u128 :: MAX ) ) ,
2036+ code,
2037+ data,
2038+ salt,
2039+ )
2040+ }
2041+
2042+ fn upload_code(
2043+ origin: AccountId ,
2044+ code: Vec <u8 >,
2045+ storage_deposit_limit: Option <Balance >,
2046+ ) -> pallet_revive:: CodeUploadResult <Balance >
2047+ {
2048+ Revive :: bare_upload_code(
2049+ RuntimeOrigin :: signed( origin) ,
2050+ code,
2051+ storage_deposit_limit. unwrap_or( u128 :: MAX ) ,
2052+ )
2053+ }
2054+
2055+ fn get_storage(
2056+ address: H160 ,
2057+ key: [ u8 ; 32 ] ,
2058+ ) -> pallet_revive:: GetStorageResult {
2059+ Revive :: get_storage(
2060+ address,
2061+ key
2062+ )
2063+ }
2064+
2065+ fn trace_block(
2066+ block: Block ,
2067+ tracer_type: pallet_revive:: evm:: TracerType ,
2068+ ) -> Vec <( u32 , pallet_revive:: evm:: Trace ) > {
2069+ use pallet_revive:: tracing:: trace;
2070+ let mut tracer = Revive :: evm_tracer( tracer_type) ;
2071+ let mut traces = vec![ ] ;
2072+ let ( header, extrinsics) = block. deconstruct( ) ;
2073+ Executive :: initialize_block( & header) ;
2074+ for ( index, ext) in extrinsics. into_iter( ) . enumerate( ) {
2075+ trace( tracer. as_tracing( ) , || {
2076+ let _ = Executive :: apply_extrinsic( ext) ;
2077+ } ) ;
2078+
2079+ if let Some ( tx_trace) = tracer. collect_trace( ) {
2080+ traces. push( ( index as u32 , tx_trace) ) ;
2081+ }
2082+ }
2083+
2084+ traces
2085+ }
2086+
2087+ fn trace_tx(
2088+ block: Block ,
2089+ tx_index: u32 ,
2090+ tracer_type: pallet_revive:: evm:: TracerType ,
2091+ ) -> Option <pallet_revive:: evm:: Trace > {
2092+ use pallet_revive:: tracing:: trace;
2093+ let mut tracer = Revive :: evm_tracer( tracer_type) ;
2094+ let ( header, extrinsics) = block. deconstruct( ) ;
2095+
2096+ Executive :: initialize_block( & header) ;
2097+ for ( index, ext) in extrinsics. into_iter( ) . enumerate( ) {
2098+ if index as u32 == tx_index {
2099+ trace( tracer. as_tracing( ) , || {
2100+ let _ = Executive :: apply_extrinsic( ext) ;
2101+ } ) ;
2102+ break ;
2103+ } else {
2104+ let _ = Executive :: apply_extrinsic( ext) ;
2105+ }
2106+ }
2107+
2108+ tracer. collect_trace( )
2109+ }
2110+
2111+ fn trace_call(
2112+ tx: pallet_revive:: evm:: GenericTransaction ,
2113+ tracer_type: pallet_revive:: evm:: TracerType ,
2114+ )
2115+ -> Result <pallet_revive:: evm:: Trace , pallet_revive:: EthTransactError >
2116+ {
2117+ use pallet_revive:: tracing:: trace;
2118+ let mut tracer = Revive :: evm_tracer( tracer_type) ;
2119+ let result = trace( tracer. as_tracing( ) , || Self :: eth_transact( tx) ) ;
2120+
2121+ if let Some ( trace) = tracer. collect_trace( ) {
2122+ Ok ( trace)
2123+ } else if let Err ( err) = result {
2124+ Err ( err)
2125+ } else {
2126+ Ok ( tracer. empty_trace( ) )
2127+ }
2128+ }
2129+ }
2130+
18922131 #[ cfg( feature = "try-runtime" ) ]
18932132 impl frame_try_runtime:: TryRuntime <Block > for Runtime {
18942133 fn on_runtime_upgrade( checks: frame_try_runtime:: UpgradeCheckSelect ) -> ( Weight , Weight ) {
0 commit comments