Skip to content

Commit

Permalink
Merge pull request #140 from shazow/fix-139
Browse files Browse the repository at this point in the history
disasm: Handle padded resolved address for FixedProxyResolver
  • Loading branch information
shazow authored Oct 10, 2024
2 parents cb0f9dd + 60d0b64 commit 05fd0bd
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/__tests__/auto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ online_test('autoload loadContractResult verified etherscan', async ({ provider,
expect(result.contractResult?.name).toBe("TransparentUpgradeableProxy");
expect(result.contractResult?.compilerVersion).toBe("v0.8.15+commit.e14f2714");
expect(result.contractResult?.loaderResult?.Proxy).toBe("1");
expect(result.contractResult?.loaderResult?.Implementation).toBe("0x8a807d39f1d642dd8c12fe2e249fe97847f01ba0");
expect(result.contractResult?.loaderResult?.Implementation).toMatch(/^0x[0-9a-f]{40}$/);
});
2 changes: 1 addition & 1 deletion src/__tests__/loaders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('loaders module', () => {
const result = await loader.getContract("0xc3d688b66703497daa19211eedff47f25384cdc3");
expect(result.name).toEqual("TransparentUpgradeableProxy");
expect(result.loaderResult?.Proxy).toBeTruthy();
expect(result.loaderResult?.Implementation).toBe("0x8a807d39f1d642dd8c12fe2e249fe97847f01ba0");
expect(result.loaderResult?.Implementation).toMatch(/^0x[0-9a-f]{40}$/);
}, SLOW_ETHERSCAN_TIMEOUT)

online_test('MultiABILoader_getContract', async () => {
Expand Down
21 changes: 20 additions & 1 deletion src/__tests__/proxies.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, describe, test } from 'vitest';

import { cached_test, online_test } from './env';
import { cached_test, online_test, makeProvider } from './env';

import { disasm } from '../disasm';
import { addSlotOffset, readArray, joinSlot } from "../slots.js";
Expand Down Expand Up @@ -125,6 +125,25 @@ describe('known proxy resolving', () => {
// FIXME: Is there one on mainnet? Seems they're all on polygon
//online_test('SequenceWallet Proxy', async() => {
//});

cached_test('LayerrProxy on Sepolia', async({ withCache }) => {
// For issue #139: https://github.com/shazow/whatsabi/issues/139
const provider = makeProvider("https://ethereum-sepolia-rpc.publicnode.com");
const address = "0x2f4eeccbe817e2b9f66e8123387aa81bae08dfec";
const code = await withCache(
`${address}_code`,
async () => {
return await provider.getCode(address)
},
);

const program = disasm(code);
const resolver = program.proxies[0];
const got = await resolver.resolve(provider, address);
const wantImplementation = "0x0000000000f7a60f1c88f317f369e3d8679c6689";

expect(got).toEqual(wantImplementation);
});
});


Expand Down
14 changes: 7 additions & 7 deletions src/__tests__/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import { hexToBytes, bytesToHex, keccak256 } from "../utils";

describe('Utils', () => {
test.each([
new Uint8Array([0,1,2,3]),
new Uint8Array([42,69,255]),
new Uint8Array([0, 1, 2, 3]),
new Uint8Array([42, 69, 255]),
new Uint8Array([255]),
new Uint8Array([255,255]),
new Uint8Array([0,255,0,255]),
new Uint8Array([255, 255]),
new Uint8Array([0, 255, 0, 255]),
])("bytesToHex %s", (bytes) => {
expect(bytesToHex(bytes)).toStrictEqual(ethers.hexlify(bytes));
});

test("bytesToHex padding", () => {
expect(bytesToHex(new Uint8Array([0]), 20)).toStrictEqual("0x0000000000000000000000000000000000000000");
expect(bytesToHex(new Uint8Array([255,255,255]), 20)).toStrictEqual("0x0000000000000000000000000000000000ffffff");
expect(bytesToHex(new Uint8Array([255, 255, 255]), 20)).toStrictEqual("0x0000000000000000000000000000000000ffffff");
});


Expand All @@ -36,8 +36,8 @@ describe('Utils', () => {
"0x00010203",
"0xffff",
"0xffff0000111122223333444455556666777788889999aaaabbbbccccddddeeee",
new Uint8Array([0,1,2,3]),
new Uint8Array([255,0,255,0,255,0]),
new Uint8Array([0, 1, 2, 3]),
new Uint8Array([255, 0, 255, 0, 255, 0]),
])("keccak256 %s", (hex) => {
expect(keccak256(hex)).toStrictEqual(ethers.keccak256(hex));
});
Expand Down
6 changes: 5 additions & 1 deletion src/disasm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,11 @@ export function disasm(bytecode: string, config?: {onlyJumpTable: boolean}): Pro
if (isPush(code.at(-3))) {
// Hardcoded delegate address
// TODO: We can probably do more here to determine which kind? Do we care?
const addr = bytesToHex(code.valueAt(-3), 20);
const val = code.valueAt(-3);
const addr = bytesToHex(
val.slice(val.length-20), // Might be padded with zeros
20,
);
p.proxies.push(new FixedProxyResolver("HardcodedDelegateProxy", addr));

} else if (
Expand Down

0 comments on commit 05fd0bd

Please sign in to comment.