Skip to content

Commit

Permalink
fix address stack in contract deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
zemse committed May 15, 2024
1 parent 648fefb commit da8e735
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/opcodes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import staticcall from "./staticcall";

export function parse(
step: MinimalInterpreterStep,
currentAddress: string
currentAddress: { value: string }
): Item<any> | AwaitedItem<any> | undefined {
switch (step.opcode.name) {
case "EXTCODESIZE":
Expand Down
4 changes: 2 additions & 2 deletions src/opcodes/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { parse } from ".";
export interface LOG {
data: string;
topics: string[];
address: string;
address: { value: string };
}

async function format(
Expand All @@ -19,7 +19,7 @@ async function format(
data: item.params.data,
topics: item.params.topics,
},
item.params.address,
item.params.address.value,
dependencies
)}`;
}
Expand Down
2 changes: 1 addition & 1 deletion src/opcodes/log0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface LOG0 extends LOG {

function parse(
step: MinimalInterpreterStep,
currentAddress?: string
currentAddress?: { value: string }
): Item<LOG0> {
if (!currentAddress) {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion src/opcodes/log1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface LOG1 extends LOG {

function parse(
step: MinimalInterpreterStep,
currentAddress?: string
currentAddress?: { value: string }
): Item<LOG1> {
if (!currentAddress) {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion src/opcodes/log2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface LOG2 extends LOG {

function parse(
step: MinimalInterpreterStep,
currentAddress?: string
currentAddress?: { value: string }
): Item<LOG2> {
if (!currentAddress) {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion src/opcodes/log3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface LOG3 extends LOG {

function parse(
step: MinimalInterpreterStep,
currentAddress?: string
currentAddress?: { value: string }
): Item<LOG3> {
if (!currentAddress) {
throw new Error(
Expand Down
2 changes: 1 addition & 1 deletion src/opcodes/log4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface LOG4 extends LOG {

function parse(
step: MinimalInterpreterStep,
currentAddress?: string
currentAddress?: { value: string }
): Item<LOG4> {
if (!currentAddress) {
throw new Error(
Expand Down
9 changes: 6 additions & 3 deletions src/trace-recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class TraceRecorder {
public previousOpcode: string | undefined;
public tracerEnv: TracerEnv;
public awaitedItems: Array<AwaitedItem<any>>;
public addressStack: string[];
public addressStack: { value: string }[]; // object is used to allow lazy assignment to value in CREATE/2

constructor(vm: MinimalEthereumJsVm, tracerEnv: TracerEnv) {
this.vm = vm;
Expand Down Expand Up @@ -131,6 +131,7 @@ export class TraceRecorder {
},
children: [],
} as Item<CREATE>;
this.addressStack.push({ value: "lazy" });
} else if (message.to === undefined && salt !== undefined) {
item = {
opcode: "CREATE2",
Expand All @@ -143,9 +144,10 @@ export class TraceRecorder {
},
children: [],
} as Item<CREATE2>;
this.addressStack.push({ value: "lazy" });
} else {
item = {
opcode: "UNKNOWN",
opcode: "UNKNOWN_MESSAGE",
params: {},
children: [],
};
Expand Down Expand Up @@ -182,7 +184,8 @@ export class TraceRecorder {
}
}

this.addressStack.push(contractAddress);
let ptr = this.addressStack[this.addressStack.length - 1];
ptr.value = contractAddress;

resolve?.();
}
Expand Down
5 changes: 4 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ export interface Item<Params> {
export interface AwaitedItem<T> {
isAwaitedItem: true;
next: number;
parse: (step: MinimalInterpreterStep, currentAddress?: string) => Item<T>;
parse: (
step: MinimalInterpreterStep,
currentAddress?: { value: string }
) => Item<T>;
}

export interface CallItem extends Item<CALL> {
Expand Down

0 comments on commit da8e735

Please sign in to comment.