From 02f4351b804adf6b3598f546bc3b640827da8ae6 Mon Sep 17 00:00:00 2001 From: ramtinms Date: Tue, 5 Mar 2024 19:15:34 -0800 Subject: [PATCH] add more checks on the result --- fvm/evm/handler/handler.go | 40 +++++++++++++++++++++++++++++++++----- fvm/evm/types/errors.go | 3 +++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/fvm/evm/handler/handler.go b/fvm/evm/handler/handler.go index 249609da7c6..477edbc9a63 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 } @@ -485,8 +489,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 @@ -515,11 +528,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 } @@ -540,8 +557,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 @@ -570,6 +595,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.