From f6501f2c305c0ef096497f7bacec3d0d55f0e6fd Mon Sep 17 00:00:00 2001 From: tak Date: Fri, 6 Dec 2024 15:18:20 +0700 Subject: [PATCH 1/3] skip deny call if readonly --- core/vm/evm.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/vm/evm.go b/core/vm/evm.go index c84fc1ee7..47d4d57b7 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -178,7 +178,9 @@ func (evm *EVM) Interpreter() *EVMInterpreter { // execution error or failed value transfer. func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas uint64, value *uint256.Int) (ret []byte, leftOverGas uint64, err error) { // Fail if the address is not allowed to call - if IsDeniedToCall(evm.StateDB, addr) { + // Skip the check if this call is readonly (eth_call) + readOnly := evm.Config.NoBaseFee + if !readOnly && IsDeniedToCall(evm.StateDB, addr) { return nil, 0, ErrUnauthorizedCall } // Fail if we're trying to execute above the call depth limit From 2e7455c97b1c0c4eff65982e46ce4e8f6659e715 Mon Sep 17 00:00:00 2001 From: tak Date: Fri, 6 Dec 2024 18:20:15 +0700 Subject: [PATCH 2/3] denycall check in estimate gas --- internal/ethapi/api.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index b9f6f4dec..f7f4d9b54 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1253,6 +1253,11 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr if err != nil { return 0, err } + // Fail if the address is not allowed to call + to := args.To + if to != nil && vm.IsDeniedToCall(state, *to) { + return 0, fmt.Errorf("the calling contract is in denlylist. to: %s", to) + } estimate, revert, err := gasestimator.Estimate(ctx, call, opts, gasCap) if err != nil { if len(revert) > 0 { From 7dba25cf58baba13f8f8cf6c4027370a2e0cb100 Mon Sep 17 00:00:00 2001 From: tak Date: Fri, 6 Dec 2024 18:26:50 +0700 Subject: [PATCH 3/3] improve print of To --- internal/ethapi/api.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index f7f4d9b54..02bf5547b 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1256,7 +1256,7 @@ func DoEstimateGas(ctx context.Context, b Backend, args TransactionArgs, blockNr // Fail if the address is not allowed to call to := args.To if to != nil && vm.IsDeniedToCall(state, *to) { - return 0, fmt.Errorf("the calling contract is in denlylist. to: %s", to) + return 0, fmt.Errorf("the calling contract is in denlylist. to: %s", to.Hex()) } estimate, revert, err := gasestimator.Estimate(ctx, call, opts, gasCap) if err != nil { @@ -1872,7 +1872,7 @@ func SubmitTransaction(ctx context.Context, b Backend, tx *types.Transaction) (c } // Fail if the address is not allowed to call if to != nil && vm.IsDeniedToCall(state, *to) { - return common.Hash{}, fmt.Errorf("the calling contract is in denlylist. to: %s", to) + return common.Hash{}, fmt.Errorf("the calling contract is in denlylist. to: %s", to.Hex()) } if err := b.SendTx(ctx, tx); err != nil {