interface BasicBlock { /** Block index (0-based) */ index: number /** Starting program counter */ startPc: number /** Ending program counter (exclusive) */ endPc: number /** Number of instructions in block */ instructionCount: number /** Total static gas cost */ gasEstimate: number /** Minimum stack items required to enter */ minStack: number /** Maximum stack depth reached */ maxStack: number /** Net stack effect (exit - entry) */ stackEffect: number /** Block terminator type */ terminator: TerminatorType /** Jump target PC (if terminator is JUMP/JUMPI) */ target?: number /** Whether block is reachable from entry */ isReachable: boolean /** Successor block indices */ successors: number[] /** Predecessor block indices */ predecessors: number[]}
const code = Bytecode(contractBytecode);// Find which block contains an instructionconst targetPc = 142;const block = code.getBlock(targetPc);if (block) { console.log(`PC ${targetPc} is in block ${block.index}`); console.log(`Block spans PC ${block.startPc} to ${block.endPc}`); console.log(`Gas cost for block: ${block.gasEstimate}`);} else { console.warn(`PC ${targetPc} not found in any block`);}
// PUSH2 0x1234 at PC 0 means:// PC 0: PUSH2 opcode// PC 1-2: immediate data (0x1234)const block1 = code.getBlock(0); // Valid: block startconst block2 = code.getBlock(1); // Same block (inside PUSH data)const block3 = code.getBlock(2); // Same block (inside PUSH data)// All three return the same blockconsole.log(block1.index === block2?.index); // true