Skip to content

StackOverflowError

Represents an invalid bytecode error that occurs when there is a stack overflow during execution. This error is typically encountered when an operation causes the stack to exceed its limit.

Stack overflow errors can occur due to:

  • Excessive recursion leading to too many function calls.
  • Bugs in smart contract logic that cause infinite loops or excessive stack usage.
  • Incorrect management of stack operations (e.g., pushing too many items onto the stack).

To debug a stack overflow error:

  1. Review Contract Logic: Ensure that your smart contract logic correctly handles recursion and stack operations.
  2. Optimize Stack Usage: Refactor your code to reduce stack usage, such as minimizing the depth of recursive calls.
  3. Use TEVM Tracing: Utilize TEVM tracing to step through the transaction and inspect stack changes.
  4. Use Other Tools: Use other tools with tracing such as Foundry.
  • Ethereumjs Source: Refer to the source file where this error can occur.

Example

try {
// Some operation that can throw a StackOverflowError
} catch (error) {
if (error instanceof StackOverflowError) {
console.error(error.message);
// Handle the stack overflow error
}
}

Param

A human-readable error message.

Param

Additional parameters for the BaseError.

Extends

Constructors

new StackOverflowError()

new StackOverflowError(message?, args?, tag?): StackOverflowError

Constructs a StackOverflowError. Represents an invalid bytecode error that occurs when there is a stack overflow during execution. This error is typically encountered when an operation causes the stack to exceed its limit.

Stack overflow errors can occur due to:

  • Excessive recursion leading to too many function calls.
  • Bugs in smart contract logic that cause infinite loops or excessive stack usage.
  • Incorrect management of stack operations (e.g., pushing too many items onto the stack).

To debug a stack overflow error:

  1. Review Contract Logic: Ensure that your smart contract logic correctly handles recursion and stack operations.
  2. Optimize Stack Usage: Refactor your code to reduce stack usage, such as minimizing the depth of recursive calls.
  3. Use TEVM Tracing: Utilize TEVM tracing to step through the transaction and inspect stack changes.
  4. Use Other Tools: Use other tools with tracing such as Foundry.
  • Ethereumjs Source: Refer to the source file where this error can occur.

Parameters

message?: string = 'Stack overflow error occurred.'

Human-readable error message.

args?: StackOverflowErrorParameters = {}

Additional parameters for the BaseError.

tag?: string = 'StackOverflowError'

The tag for the error.

Returns

StackOverflowError

Overrides

ExecutionError.constructor

Defined in

packages/errors/src/ethereum/ethereumjs/StackOverflowError.js:78

Properties

_tag

_tag: string

Same as name, used internally.

Inherited from

ExecutionError._tag

Defined in

packages/errors/src/ethereum/BaseError.js:82


cause

cause: any

Inherited from

ExecutionError.cause

Defined in

packages/errors/src/ethereum/BaseError.js:114


code

code: number

Inherited from

ExecutionError.code

Defined in

packages/errors/src/ethereum/BaseError.js:112


details

details: string

Inherited from

ExecutionError.details

Defined in

packages/errors/src/ethereum/BaseError.js:91


docsPath

docsPath: undefined | string

Path to the documentation for this error.

Inherited from

ExecutionError.docsPath

Defined in

packages/errors/src/ethereum/BaseError.js:96


message

message: string

Human-readable error message.

Inherited from

ExecutionError.message

Defined in

node_modules/.pnpm/typescript@5.6.2/node_modules/typescript/lib/lib.es5.d.ts:1077


metaMessages

metaMessages: undefined | string[]

Additional meta messages for more context.

Inherited from

ExecutionError.metaMessages

Defined in

packages/errors/src/ethereum/BaseError.js:100


name

name: string

The name of the error, used to discriminate errors.

Inherited from

ExecutionError.name

Defined in

node_modules/.pnpm/typescript@5.6.2/node_modules/typescript/lib/lib.es5.d.ts:1076


shortMessage

shortMessage: string

Inherited from

ExecutionError.shortMessage

Defined in

packages/errors/src/ethereum/BaseError.js:104


stack?

optional stack: string

Inherited from

ExecutionError.stack

Defined in

node_modules/.pnpm/typescript@5.6.2/node_modules/typescript/lib/lib.es5.d.ts:1078


version

version: string

Inherited from

ExecutionError.version

Defined in

packages/errors/src/ethereum/BaseError.js:108


code

static code: number = -32000

Error code, analogous to the code in JSON RPC error.

Inherited from

ExecutionError.code

Defined in

packages/errors/src/ethereum/ExecutionErrorError.js:46


EVMErrorMessage

static EVMErrorMessage: EvmErrorMessage = EVMErrorMessage.STACK_OVERFLOW

Defined in

packages/errors/src/ethereum/ethereumjs/StackOverflowError.js:56


prepareStackTrace()?

static optional prepareStackTrace: (err, stackTraces) => any

Optional override for formatting stack traces

Parameters

err: Error

stackTraces: CallSite[]

Returns

any

See

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from

ExecutionError.prepareStackTrace

Defined in

node_modules/.pnpm/@types+node@22.7.3/node_modules/@types/node/globals.d.ts:143


stackTraceLimit

static stackTraceLimit: number

Inherited from

ExecutionError.stackTraceLimit

Defined in

node_modules/.pnpm/@types+node@22.7.3/node_modules/@types/node/globals.d.ts:145

Methods

walk()

walk(fn?): unknown

Walks through the error chain.

Parameters

fn?: Function

A function to execute on each error in the chain.

Returns

unknown

The first error that matches the function, or the original error.

Inherited from

ExecutionError.walk

Defined in

packages/errors/src/ethereum/BaseError.js:137


captureStackTrace()

captureStackTrace(targetObject, constructorOpt)

static captureStackTrace(targetObject, constructorOpt?): void

Create .stack property on a target object

Parameters

targetObject: object

constructorOpt?: Function

Returns

void

Inherited from

ExecutionError.captureStackTrace

Defined in

node_modules/.pnpm/@types+node@22.7.3/node_modules/@types/node/globals.d.ts:136

captureStackTrace(targetObject, constructorOpt)

static captureStackTrace(targetObject, constructorOpt?): void

Create .stack property on a target object

Parameters

targetObject: object

constructorOpt?: Function

Returns

void

Inherited from

ExecutionError.captureStackTrace

Defined in

node_modules/.pnpm/bun-types@1.1.29/node_modules/bun-types/globals.d.ts:1630

captureStackTrace(targetObject, constructorOpt)

static captureStackTrace(targetObject, constructorOpt?): void

Create .stack property on a target object

Parameters

targetObject: object

constructorOpt?: Function

Returns

void

Inherited from

ExecutionError.captureStackTrace

Defined in

node_modules/.pnpm/@types+node@20.12.14/node_modules/@types/node/globals.d.ts:21