Skip to content

Commit

Permalink
Check balance overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
icodezjb committed Feb 4, 2024
1 parent cfef5ca commit f42dbeb
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions frame/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use crate::{
chainx_value_shrink, runner::Runner as RunnerT, AccountCodes, AccountStorages, AddressMapping,
BlockHashMapping, Config, Error, Event, FeeCalculator, OnChargeEVMTransaction, Pallet,
BlockHashMapping, Config, Error, Event, FeeCalculator, OnChargeEVMTransaction, Pallet, BalanceOf
};
use evm::{
backend::Backend as BackendT,
Expand All @@ -41,7 +41,10 @@ pub struct Runner<T: Config> {
_marker: PhantomData<T>,
}

impl<T: Config> Runner<T> {
impl<T: Config> Runner<T>
where
BalanceOf<T>: TryFrom<U256> + Into<U256>,
{
/// Execute an EVM operation.
pub fn execute<'config, 'precompiles, F, R>(
source: H160,
Expand Down Expand Up @@ -223,7 +226,10 @@ impl<T: Config> Runner<T> {
}
}

impl<T: Config> RunnerT<T> for Runner<T> {
impl<T: Config> RunnerT<T> for Runner<T>
where
BalanceOf<T>: TryFrom<U256> + Into<U256>,
{
type Error = Error<T>;

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

impl<'vicinity, 'config, T: Config> StackStateT<'config>
for SubstrateStackState<'vicinity, 'config, T>
where
BalanceOf<T>: TryFrom<U256> + Into<U256>,
{
fn metadata(&self) -> &StackSubstateMetadata<'config> {
self.substate.metadata()
Expand Down Expand Up @@ -611,10 +619,12 @@ impl<'vicinity, 'config, T: Config> StackStateT<'config>
T::Currency::transfer(
&source,
&target,
value.low_u128().unique_saturated_into(),
value
.try_into()
.map_err(|_| ExitError::OutOfFund)?,
ExistenceRequirement::AllowDeath,
)
.map_err(|_| ExitError::OutOfFund)
.map_err(|_| ExitError::OutOfFund)
}

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

0 comments on commit f42dbeb

Please sign in to comment.