github.com/amazechain/amc@v0.1.3/internal/vm/errors.go (about)

     1  // Copyright 2023 The AmazeChain Authors
     2  // This file is part of the AmazeChain library.
     3  //
     4  // The AmazeChain library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The AmazeChain library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the AmazeChain library. If not, see <http://www.gnu.org/licenses/>.
    16  package vm
    17  
    18  import (
    19  	"errors"
    20  	"fmt"
    21  )
    22  
    23  // List evm execution errors
    24  var (
    25  	// ErrInvalidSubroutineEntry means that a BEGINSUB was reached via iteration,
    26  	// as opposed to from a JUMPSUB instruction
    27  	ErrInvalidSubroutineEntry   = errors.New("invalid subroutine entry")
    28  	ErrOutOfGas                 = errors.New("out of gas")
    29  	ErrCodeStoreOutOfGas        = errors.New("contract creation code storage out of gas")
    30  	ErrDepth                    = errors.New("max call depth exceeded")
    31  	ErrInsufficientBalance      = errors.New("insufficient balance for transfer")
    32  	ErrContractAddressCollision = errors.New("contract address collision")
    33  	ErrExecutionReverted        = errors.New("execution reverted")
    34  	ErrMaxCodeSizeExceeded      = errors.New("max code size exceeded")
    35  	ErrInvalidJump              = errors.New("invalid jump destination")
    36  	ErrWriteProtection          = errors.New("write protection")
    37  	ErrReturnDataOutOfBounds    = errors.New("return data out of bounds")
    38  	ErrGasUintOverflow          = errors.New("gas uint64 overflow")
    39  	ErrInvalidRetsub            = errors.New("invalid retsub")
    40  	ErrReturnStackExceeded      = errors.New("return stack limit reached")
    41  	ErrInvalidCode              = errors.New("invalid code")
    42  	ErrNonceUintOverflow        = errors.New("nonce uint64 overflow")
    43  
    44  	// errStopToken is an internal token indicating interpreter loop termination,
    45  	// never returned to outside callers.
    46  	errStopToken = errors.New("stop token")
    47  )
    48  
    49  // ErrStackUnderflow wraps an evm error when the items on the stack less
    50  // than the minimal requirement.
    51  type ErrStackUnderflow struct {
    52  	stackLen int
    53  	required int
    54  }
    55  
    56  func (e *ErrStackUnderflow) Error() string {
    57  	return fmt.Sprintf("stack underflow (%d <=> %d)", e.stackLen, e.required)
    58  }
    59  
    60  // ErrStackOverflow wraps an evm error when the items on the stack exceeds
    61  // the maximum allowance.
    62  type ErrStackOverflow struct {
    63  	stackLen int
    64  	limit    int
    65  }
    66  
    67  func (e *ErrStackOverflow) Error() string {
    68  	return fmt.Sprintf("stack limit reached %d (%d)", e.stackLen, e.limit)
    69  }
    70  
    71  // ErrInvalidOpCode wraps an evm error when an invalid opcode is encountered.
    72  type ErrInvalidOpCode struct {
    73  	opcode OpCode
    74  }
    75  
    76  func (e *ErrInvalidOpCode) Error() string { return fmt.Sprintf("invalid opcode: %s", e.opcode) }