diff --git a/fvm/evm/handler/handler.go b/fvm/evm/handler/handler.go index e8e88c2eff0..859b376630c 100644 --- a/fvm/evm/handler/handler.go +++ b/fvm/evm/handler/handler.go @@ -96,6 +96,10 @@ func (h *ContractHandler) deployCOA(uuid uint64) (types.Address, error) { if err != nil { return types.Address{}, err } + if res == nil || res.Failed() { + return types.Address{}, types.ErrDirectCallExecutionFailed + } + return res.DeployedContractAddress, nil } @@ -491,8 +495,17 @@ func (a *Account) deposit(v *types.FLOWTokenVault) error { if err != nil { return err } - _, err = a.fch.executeAndHandleCall(ctx, call, v.Balance(), false) - return err + + res, err := a.fch.executeAndHandleCall(ctx, call, v.Balance(), false) + if err != nil { + return err + } + + if res == nil || res.Failed() { + return types.ErrDirectCallExecutionFailed + } + + return nil } // Withdraw deducts the balance from the account and @@ -521,11 +534,15 @@ func (a *Account) withdraw(b types.Balance) (*types.FLOWTokenVault, error) { return nil, types.ErrWithdrawBalanceRounding } - _, err = a.fch.executeAndHandleCall(ctx, call, b, true) + res, err := a.fch.executeAndHandleCall(ctx, call, b, true) if err != nil { return nil, err } + if res == nil || res.Failed() { + return nil, types.ErrDirectCallExecutionFailed + } + return types.NewFlowTokenVault(b), nil } @@ -546,8 +563,16 @@ func (a *Account) transfer(to types.Address, balance types.Balance) error { if err != nil { return err } - _, err = a.fch.executeAndHandleCall(ctx, call, nil, false) - return err + res, err := a.fch.executeAndHandleCall(ctx, call, nil, false) + if err != nil { + return err + } + + if res == nil || res.Failed() { + return types.ErrDirectCallExecutionFailed + } + + return nil } // Deploy deploys a contract to the EVM environment @@ -576,6 +601,11 @@ func (a *Account) deploy(code types.Code, gaslimit types.GasLimit, balance types if err != nil { return types.Address{}, err } + + if res == nil || res.Failed() { + return types.Address{}, types.ErrDirectCallExecutionFailed + } + return types.Address(res.DeployedContractAddress), nil } diff --git a/fvm/evm/types/errors.go b/fvm/evm/types/errors.go index 6d2a89801e9..999e8f5c571 100644 --- a/fvm/evm/types/errors.go +++ b/fvm/evm/types/errors.go @@ -109,6 +109,9 @@ var ( // yeild to rounding error, i.e. the balance contains fractions smaller than 10^8 Flow (smallest unit allowed to transfer). ErrWithdrawBalanceRounding = NewEVMValidationError(errors.New("withdraw failed! the balance is susceptible to the rounding error")) + // ErrDirectCallExecutionFailed is returned when the direct call execution has failed. + ErrDirectCallExecutionFailed = NewEVMValidationError(errors.New("direct call execution failed")) + // ErrInsufficientTotalSupply is returned when flow token // is withdraw request is there but not enough balance is on EVM vault // this should never happen but its a saftey measure to protect Flow against EVM issues.