Skip to main content

Try it Live

Run Opcode examples in the interactive playground

Opcode.isValidJumpDest()

Check if offset is a valid JUMPDEST in bytecode.
import { isValidJumpDest } from 'tevm/Opcode'

const valid = isValidJumpDest(bytecode, 3)  // true

Parameters

  • bytecode: Uint8Array - Contract bytecode
  • offset: number - Program counter offset to check

Returns

boolean - True if offset is valid JUMPDEST

Validation Rules

Valid JUMPDEST must:
  1. Be within bytecode bounds
  2. Be JUMPDEST opcode (0x5B)
  3. NOT be inside PUSH immediate data

Use Cases

Runtime Jump Validation

function executeJump(bytecode: Uint8Array, targetOffset: number): void {
  if (!Opcode.isValidJumpDest(bytecode, targetOffset)) {
    throw new Error(`Invalid jump destination: ${targetOffset}`)
  }
  // Proceed with jump
}

Find Invalid Jumps

function findInvalidJumps(bytecode: Uint8Array): number[] {
  const instructions = Opcode.parse(bytecode)
  const invalid: number[] = []

  for (const inst of instructions) {
    if (Opcode.isJump(inst.opcode)) {
      // In real analysis, would need to trace stack for target
      // This is simplified example
    }
  }

  return invalid
}