Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxies: UnknownProxyResolver #86

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/disasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { hexToBytes, bytesToHex } from "./utils.js";

import { opcodes, pushWidth, isPush, isLog, isHalt, isCompare } from "./opcodes.js";

import { slotResolvers, SequenceWalletProxyResolver, FixedProxyResolver } from "./proxies.js";
import { slotResolvers, SequenceWalletProxyResolver, FixedProxyResolver, UnknownProxyResolver } from "./proxies.js";


function valueToOffset(value: Uint8Array): number {
Expand Down Expand Up @@ -149,7 +149,7 @@ export class Program {
fallback?: number; // instruction offset for fallback function

eventCandidates: Array<string>; // PUSH32 found before a LOG instruction
proxySlots: Array<string>; // PUSH32 found that match known proxy slots
fixedSlots: Array<string>; // PUSH32 followed by SLOAD
proxies: Array<ProxyResolver>;

init?: Program; // Program embedded as init code
Expand All @@ -159,7 +159,7 @@ export class Program {
this.selectors = {};
this.notPayable = {};
this.eventCandidates = [];
this.proxySlots = [];
this.fixedSlots = [];
this.proxies = [];
this.init = init;
}
Expand Down Expand Up @@ -265,6 +265,13 @@ export function disasm(bytecode: string, config?: {onlyJumpTable: boolean}): Pro
continue
}

if (inst === opcodes.SLOAD &&
isPush(code.at(-2))
) {
const slot = bytesToHex(code.valueAt(-2));
p.fixedSlots.push(slot);
}

// Possible minimal proxy pattern? EIP-1167
if (inst === opcodes.DELEGATECALL &&
code.at(-2) === opcodes.GAS) {
Expand All @@ -281,6 +288,15 @@ export function disasm(bytecode: string, config?: {onlyJumpTable: boolean}): Pro
) {
// SequenceWallet-style proxy (keyed on address)
p.proxies.push(new SequenceWalletProxyResolver());

} else if (
code.at(-3) === opcodes.DUP5 &&
p.fixedSlots.length > 0
) {
// Might be a custom TransparentProxy? Not handling it yet
p.proxies.push(new UnknownProxyResolver({
slot: p.fixedSlots[0] || undefined,
}));
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,21 @@ export class FixedProxyResolver extends BaseProxyResolver implements ProxyResolv
}
};

// UnknownProxyResolver is used when we don't know what kind of proxy this is, so we attach some details to figure out later.
export class UnknownProxyResolver extends BaseProxyResolver implements ProxyResolver {
context : any;

constructor(context: any) {
super("UnknownProxy");
this.context = context;
}

async resolve(provider: StorageProvider, address: string): Promise<string> {
throw new Error("UnknownProxy: " + JSON.stringify(this.context));
}
};



// Lookups:

Expand Down
Loading