Skip to content

Commit

Permalink
Merge pull request #121 from oasysgames/feat/deny-write-only
Browse files Browse the repository at this point in the history
skip deny call if readonly
  • Loading branch information
tak1827 authored Dec 8, 2024
2 parents f9f501e + 2e5208d commit 8460f8c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Hex())
}
estimate, revert, err := gasestimator.Estimate(ctx, call, opts, gasCap)
if err != nil {
if len(revert) > 0 {
Expand Down Expand Up @@ -1867,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 {
Expand Down

0 comments on commit 8460f8c

Please sign in to comment.