Skip to content

Commit f42dbeb

Browse files
committed
Check balance overflow
1 parent cfef5ca commit f42dbeb

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

frame/evm/src/runner/stack.rs

+15-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
use crate::{
2121
chainx_value_shrink, runner::Runner as RunnerT, AccountCodes, AccountStorages, AddressMapping,
22-
BlockHashMapping, Config, Error, Event, FeeCalculator, OnChargeEVMTransaction, Pallet,
22+
BlockHashMapping, Config, Error, Event, FeeCalculator, OnChargeEVMTransaction, Pallet, BalanceOf
2323
};
2424
use evm::{
2525
backend::Backend as BackendT,
@@ -41,7 +41,10 @@ pub struct Runner<T: Config> {
4141
_marker: PhantomData<T>,
4242
}
4343

44-
impl<T: Config> Runner<T> {
44+
impl<T: Config> Runner<T>
45+
where
46+
BalanceOf<T>: TryFrom<U256> + Into<U256>,
47+
{
4548
/// Execute an EVM operation.
4649
pub fn execute<'config, 'precompiles, F, R>(
4750
source: H160,
@@ -223,7 +226,10 @@ impl<T: Config> Runner<T> {
223226
}
224227
}
225228

226-
impl<T: Config> RunnerT<T> for Runner<T> {
229+
impl<T: Config> RunnerT<T> for Runner<T>
230+
where
231+
BalanceOf<T>: TryFrom<U256> + Into<U256>,
232+
{
227233
type Error = Error<T>;
228234

229235
fn call(
@@ -521,6 +527,8 @@ impl<'vicinity, 'config, T: Config> BackendT for SubstrateStackState<'vicinity,
521527

522528
impl<'vicinity, 'config, T: Config> StackStateT<'config>
523529
for SubstrateStackState<'vicinity, 'config, T>
530+
where
531+
BalanceOf<T>: TryFrom<U256> + Into<U256>,
524532
{
525533
fn metadata(&self) -> &StackSubstateMetadata<'config> {
526534
self.substate.metadata()
@@ -611,10 +619,12 @@ impl<'vicinity, 'config, T: Config> StackStateT<'config>
611619
T::Currency::transfer(
612620
&source,
613621
&target,
614-
value.low_u128().unique_saturated_into(),
622+
value
623+
.try_into()
624+
.map_err(|_| ExitError::OutOfFund)?,
615625
ExistenceRequirement::AllowDeath,
616626
)
617-
.map_err(|_| ExitError::OutOfFund)
627+
.map_err(|_| ExitError::OutOfFund)
618628
}
619629

620630
fn reset_balance(&mut self, _address: H160) {

0 commit comments

Comments
 (0)