Skip to content

Commit

Permalink
fix OOC errors (0xPolygonHermez#3100)
Browse files Browse the repository at this point in the history
* fix OOC errors

* fix OOC errors
  • Loading branch information
ToniRamirezM authored Jan 18, 2024
1 parent bc72f05 commit cfe5048
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
3 changes: 2 additions & 1 deletion jsonrpc/endpoints_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/0xPolygonHermez/zkevm-node/pool"
"github.com/0xPolygonHermez/zkevm-node/state"
"github.com/0xPolygonHermez/zkevm-node/state/runtime"
"github.com/0xPolygonHermez/zkevm-node/state/runtime/executor"
"github.com/ethereum/go-ethereum/common"
ethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/jackc/pgx/v4"
Expand Down Expand Up @@ -105,7 +106,7 @@ func (e *EthEndpoints) Call(arg *types.TxArgs, blockArg *types.BlockNumberOrHash
result, err := e.state.ProcessUnsignedTransaction(ctx, tx, sender, blockToProcess, true, dbTx)
if err != nil {
errMsg := fmt.Sprintf("failed to execute the unsigned transaction: %v", err.Error())
logError := !runtime.IsOutOfCounterError(err) && !errors.Is(err, runtime.ErrOutOfGas)
logError := !executor.IsROMOutOfCountersError(executor.RomErrorCode(err)) && !errors.Is(err, runtime.ErrOutOfGas)
return RPCErrorResponse(types.DefaultErrorCode, errMsg, nil, logError)
}

Expand Down
6 changes: 5 additions & 1 deletion state/runtime/executor/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func RomErr(errorCode RomError) error {
return runtime.ErrOutOfCountersPadding
case RomError_ROM_ERROR_OUT_OF_COUNTERS_POSEIDON:
return runtime.ErrOutOfCountersPoseidon
case RomError_ROM_ERROR_OUT_OF_COUNTERS_SHA:
return runtime.ErrOutOfCountersSha
case RomError_ROM_ERROR_INVALID_JUMP:
return runtime.ErrInvalidJump
case RomError_ROM_ERROR_INVALID_OPCODE:
Expand Down Expand Up @@ -129,6 +131,8 @@ func RomErrorCode(err error) RomError {
return RomError_ROM_ERROR_OUT_OF_COUNTERS_PADDING
case runtime.ErrOutOfCountersPoseidon:
return RomError_ROM_ERROR_OUT_OF_COUNTERS_POSEIDON
case runtime.ErrOutOfCountersSha:
return RomError_ROM_ERROR_OUT_OF_COUNTERS_SHA
case runtime.ErrInvalidJump:
return RomError_ROM_ERROR_INVALID_JUMP
case runtime.ErrInvalidOpCode:
Expand Down Expand Up @@ -174,7 +178,7 @@ func RomErrorCode(err error) RomError {

// IsROMOutOfCountersError indicates if the error is an ROM OOC
func IsROMOutOfCountersError(error RomError) bool {
return error >= RomError_ROM_ERROR_OUT_OF_COUNTERS_STEP && error <= RomError_ROM_ERROR_OUT_OF_COUNTERS_POSEIDON
return error >= RomError_ROM_ERROR_OUT_OF_COUNTERS_STEP && error <= RomError_ROM_ERROR_OUT_OF_COUNTERS_SHA
}

// IsROMOutOfGasError indicates if the error is an ROM OOG
Expand Down
14 changes: 2 additions & 12 deletions state/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ var (
ErrOutOfCountersPadding = errors.New("not enough padding counters to continue the execution")
// ErrOutOfCountersPoseidon indicates there are not enough poseidon counters to continue the execution
ErrOutOfCountersPoseidon = errors.New("not enough poseidon counters to continue the execution")
// ErrOutOfCountersSha indicates there are not enough sha256 counters to continue the execution
ErrOutOfCountersSha = errors.New("not enough sha256 counters to continue the execution")
// ErrIntrinsicInvalidSignature indicates the transaction is failing at the signature intrinsic check
ErrIntrinsicInvalidSignature = errors.New("signature intrinsic error")
// ErrIntrinsicInvalidChainID indicates the transaction is failing at the chain id intrinsic check
Expand Down Expand Up @@ -344,15 +346,3 @@ func (r *ExecutionResult) Failed() bool {
func (r *ExecutionResult) Reverted() bool {
return errors.Is(r.Err, ErrExecutionReverted)
}

// IsOutOfCounterError checks if the provided error is one
// of the errors related to out of counters errors
func IsOutOfCounterError(err error) bool {
return errors.Is(err, ErrOutOfCountersArith) ||
errors.Is(err, ErrOutOfCountersBinary) ||
errors.Is(err, ErrOutOfCountersKeccak) ||
errors.Is(err, ErrOutOfCountersMemory) ||
errors.Is(err, ErrOutOfCountersPadding) ||
errors.Is(err, ErrOutOfCountersPoseidon) ||
errors.Is(err, ErrOutOfCountersStep)
}

0 comments on commit cfe5048

Please sign in to comment.