Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flow EVM] improve handler #5516

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions fvm/evm/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
3 changes: 3 additions & 0 deletions fvm/evm/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading