Skip to content

Commit

Permalink
do not allow Call from RPC and runtime API for bound accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
Roznovjak committed Feb 19, 2024
1 parent 72ae6a2 commit f69e03e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
62 changes: 62 additions & 0 deletions integration-tests/src/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use crate::{assert_balance, polkadot_test_net::*};
use fp_evm::{Context, Transfer};
use fp_rpc::runtime_decl_for_ethereum_runtime_rpc_api::EthereumRuntimeRPCApi;
use frame_support::{assert_ok, dispatch::GetDispatchInfo, sp_runtime::codec::Encode, traits::Contains};
use frame_system::RawOrigin;
use hex_literal::hex;
Expand Down Expand Up @@ -247,6 +248,67 @@ mod account_conversion {
assert!(fee / UNITS == 10);
});
}

#[test]
fn evm_call_from_runtime_rpc_should_be_accepted_from_bound_addresses() {
TestNet::reset();

Hydra::execute_with(|| {
//Arrange
let data =
hex!["4d0045544800d1820d45118d78d091e685490c674d7596e62d1f0000000000000000140000000f0000c16ff28623"]
.to_vec();

//Act & Assert
assert_ok!(hydradx_runtime::Runtime::call(
evm_address(), // from
DISPATCH_ADDR, // to
data, // data
U256::from(1000u64),
U256::from(100000u64),
None,
None,
None,
false,
None,
));
});
}

#[test]
fn evm_call_from_runtime_rpc_should_not_be_accepted_from_bound_addresses() {
TestNet::reset();

Hydra::execute_with(|| {
//Arrange
let data =
hex!["4d0045544800d1820d45118d78d091e685490c674d7596e62d1f0000000000000000140000000f0000c16ff28623"]
.to_vec();

assert_ok!(EVMAccounts::bind_evm_address(hydradx_runtime::RuntimeOrigin::signed(
ALICE.into()
)),);

let evm_address = EVMAccounts::evm_address(&Into::<AccountId>::into(ALICE));

//Act & Assert
assert_noop!(
hydradx_runtime::Runtime::call(
evm_address, // from
DISPATCH_ADDR, // to
data, // data
U256::from(1000u64),
U256::from(100000u64),
None,
None,
None,
false,
None,
),
pallet_evm_accounts::Error::<hydradx_runtime::Runtime>::BoundAddressCannotBeUsed
);
});
}
}

mod standard_precompiles {
Expand Down
2 changes: 2 additions & 0 deletions pallets/evm-accounts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ pub mod pallet {
TruncatedAccountAlreadyUsed,
/// Address is already bound
AddressAlreadyBound,
/// Bound address cannot be used
BoundAddressCannotBeUsed,
}

#[pallet::hooks]
Expand Down
4 changes: 4 additions & 0 deletions runtime/hydradx/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ impl_runtime_apis! {
_ => (None, None),
};

if EVMAccounts::bound_account_id(from).is_some() {
return Err(pallet_evm_accounts::Error::<Runtime>::BoundAddressCannotBeUsed.into())
};

<Runtime as pallet_evm::Config>::Runner::call(
from,
to,
Expand Down

0 comments on commit f69e03e

Please sign in to comment.