diff --git a/chain-extensions/types/xvm/src/lib.rs b/chain-extensions/types/xvm/src/lib.rs index c1cd231cdc..d23ccd9102 100644 --- a/chain-extensions/types/xvm/src/lib.rs +++ b/chain-extensions/types/xvm/src/lib.rs @@ -41,7 +41,8 @@ impl From for XvmExecutionResult { SameVmCallNotAllowed => 2, InvalidTarget => 3, InputTooLarge => 4, - ExecutionFailed(_) => 5, + BadOrigin => 5, + ExecutionFailed(_) => 6, }; Self::Err(error_code) } diff --git a/chain-extensions/xvm/src/lib.rs b/chain-extensions/xvm/src/lib.rs index 84b8dd2994..9696fc6d7a 100644 --- a/chain-extensions/xvm/src/lib.rs +++ b/chain-extensions/xvm/src/lib.rs @@ -18,9 +18,12 @@ #![cfg_attr(not(feature = "std"), no_std)] -use astar_primitives::xvm::{Context, VmId, XvmCall}; +use astar_primitives::xvm::{CallError, Context, VmId, XvmCall}; use frame_support::dispatch::Encode; -use pallet_contracts::{chain_extension::{ChainExtension, Environment, Ext, InitState, RetVal}, Origin}; +use pallet_contracts::{ + chain_extension::{ChainExtension, Environment, Ext, InitState, RetVal}, + Origin, +}; use sp_runtime::DispatchError; use sp_std::marker::PhantomData; use xvm_chain_extension_types::{XvmCallArgs, XvmExecutionResult}; @@ -80,8 +83,9 @@ where target: "xvm-extension::xvm_call", "root origin not supported" ); - // TODO: expand XvmErrors with BadOrigin - return Ok(RetVal::Converging(XvmExecutionResult::UnknownError as u32)); + return Ok(RetVal::Converging( + XvmExecutionResult::from(CallError::BadOrigin).into(), + )); } }; diff --git a/pallets/xvm/Cargo.toml b/pallets/xvm/Cargo.toml index 6121f5657a..6f1022bf24 100644 --- a/pallets/xvm/Cargo.toml +++ b/pallets/xvm/Cargo.toml @@ -32,11 +32,11 @@ pallet-contracts = { workspace = true } astar-primitives = { workspace = true } [dev-dependencies] -sp-io = { workspace = true } fp-evm = { workspace = true } -pallet-timestamp = { workspace = true, features = ["std"] } pallet-balances = { workspace = true, features = ["std"] } pallet-insecure-randomness-collective-flip = { workspace = true, features = ["std"] } +pallet-timestamp = { workspace = true, features = ["std"] } +sp-io = { workspace = true } [features] default = ["std"] @@ -47,7 +47,7 @@ std = [ "frame-system/std", "pallet-contracts/std", "pallet-evm/std", - "pallet-insecure-randomness-collective-flip/std", + "pallet-insecure-randomness-collective-flip/std", "scale-info/std", "serde", "sp-core/std", diff --git a/pallets/xvm/src/lib.rs b/pallets/xvm/src/lib.rs index e5927c2647..bcb451c140 100644 --- a/pallets/xvm/src/lib.rs +++ b/pallets/xvm/src/lib.rs @@ -32,6 +32,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use frame_support::{ensure, pallet_prelude::*, traits::ConstU32, BoundedVec}; +use pallet_contracts::{CollectEvents, DebugInfo, Determinism}; use pallet_evm::GasWeightMapping; use parity_scale_codec::Decode; use sp_core::U256; @@ -209,8 +210,9 @@ impl Pallet { context.weight_limit, None, input, - false, - pallet_contracts::Determinism::Deterministic, + DebugInfo::Skip, + CollectEvents::Skip, + Determinism::Enforced, ); log::trace!(target: "xvm::wasm_call", "WASM call result: {:?}", call_result); diff --git a/pallets/xvm/src/mock.rs b/pallets/xvm/src/mock.rs index 2c06bc4d63..f080bcb5e6 100644 --- a/pallets/xvm/src/mock.rs +++ b/pallets/xvm/src/mock.rs @@ -21,7 +21,7 @@ use super::*; use crate as pallet_xvm; -use fp_evm::{CallInfo as EvmCallInfo, ExitReason, ExitSucceed}; +use fp_evm::{CallInfo as EvmCallInfo, ExitReason, ExitSucceed, UsedGas}; use frame_support::{ construct_runtime, dispatch::{DispatchErrorWithPostInfo, PostDispatchInfo}, @@ -79,6 +79,10 @@ impl pallet_balances::Config for TestRuntime { type ExistentialDeposit = ConstU128<2>; type AccountStore = System; type WeightInfo = (); + type HoldIdentifier = (); + type FreezeIdentifier = (); + type MaxHolds = ConstU32<0>; + type MaxFreezes = ConstU32<0>; } impl pallet_timestamp::Config for TestRuntime { @@ -93,7 +97,7 @@ impl pallet_insecure_randomness_collective_flip::Config for TestRuntime {} parameter_types! { pub const DepositPerItem: Balance = 1_000; pub const DepositPerByte: Balance = 1_000; - pub DeletionWeightLimit: Weight = Weight::from_parts(u64::MAX, u64::MAX); + pub const DefaultDepositLimit: Balance = 1_000; pub Schedule: pallet_contracts::Schedule = Default::default(); } @@ -106,12 +110,11 @@ impl pallet_contracts::Config for TestRuntime { type CallFilter = Nothing; type DepositPerItem = DepositPerItem; type DepositPerByte = DepositPerByte; + type DefaultDepositLimit = DefaultDepositLimit; type CallStack = [pallet_contracts::Frame; 5]; type WeightPrice = (); type WeightInfo = pallet_contracts::weights::SubstrateWeight; type ChainExtension = (); - type DeletionQueueDepth = ConstU32<128>; - type DeletionWeightLimit = DeletionWeightLimit; type Schedule = Schedule; type AddressGenerator = pallet_contracts::DefaultAddressGenerator; type MaxCodeLen = ConstU32<{ 123 * 1024 }>; @@ -142,8 +145,12 @@ impl CheckedEthereumTransact for MockEthereumTransact { EvmCallInfo { exit_reason: ExitReason::Succeed(ExitSucceed::Returned), value: Default::default(), - used_gas: Default::default(), + used_gas: UsedGas { + standard: Default::default(), + effective: Default::default(), + }, logs: Default::default(), + weight_info: None, }, )) } diff --git a/precompiles/xvm/src/mock.rs b/precompiles/xvm/src/mock.rs index 6829093ebd..bf209b7480 100644 --- a/precompiles/xvm/src/mock.rs +++ b/precompiles/xvm/src/mock.rs @@ -22,7 +22,9 @@ use super::*; use fp_evm::IsPrecompileResult; use frame_support::{ - construct_runtime, ensure, parameter_types, traits::{ConstU32, ConstU64, Everything}, weights::Weight, + construct_runtime, ensure, parameter_types, + traits::{ConstU32, ConstU64, Everything}, + weights::Weight, }; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; diff --git a/primitives/src/xvm.rs b/primitives/src/xvm.rs index 50d4d472a0..e3ae06c526 100644 --- a/primitives/src/xvm.rs +++ b/primitives/src/xvm.rs @@ -64,6 +64,8 @@ pub enum CallError { InvalidTarget, /// Input is too large. InputTooLarge, + /// Bad origin. + BadOrigin, /// The call failed on EVM or WASM execution. ExecutionFailed(Vec), } diff --git a/runtime/shibuya/Cargo.toml b/runtime/shibuya/Cargo.toml index b8c8d6843b..6c0a7d7454 100644 --- a/runtime/shibuya/Cargo.toml +++ b/runtime/shibuya/Cargo.toml @@ -253,7 +253,7 @@ runtime-benchmarks = [ "pallet-preimage/runtime-benchmarks", "pallet-collator-selection/runtime-benchmarks", "pallet-ethereum-checked/runtime-benchmarks", - "pallet-xvm/runtime-benchmarks", + "pallet-xvm/runtime-benchmarks", "polkadot-runtime/runtime-benchmarks", "orml-xtokens/runtime-benchmarks", "astar-primitives/runtime-benchmarks",