From 08cc48910df351d068c1ce224d4102f40cb1dce1 Mon Sep 17 00:00:00 2001 From: kumaryash90 Date: Mon, 3 Feb 2025 17:56:14 +0000 Subject: [PATCH] [SDK] Update implementation addr extraction logic (#6093) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TOOL-3258 --- ## PR-Codex overview This PR introduces support for EIP-7702 by adding functionality to extract the implementation address from a specific bytecode pattern. It includes a new utility function and a corresponding test case. ### Detailed summary - Added EIP-7702 support in `extractMinimalProxyImplementationAddress.ts` to extract the implementation address from bytecode. - Implemented a check for bytecode length and prefix. - Added a test case in `extractMinimalProxyImplementationAddress.test.ts` to validate the new functionality. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` --- .changeset/thick-kangaroos-smoke.md | 5 +++++ .../extractMinimalProxyImplementationAddress.test.ts | 6 ++++++ .../bytecode/extractMinimalProxyImplementationAddress.ts | 6 ++++++ 3 files changed, 17 insertions(+) create mode 100644 .changeset/thick-kangaroos-smoke.md diff --git a/.changeset/thick-kangaroos-smoke.md b/.changeset/thick-kangaroos-smoke.md new file mode 100644 index 00000000000..c885e884774 --- /dev/null +++ b/.changeset/thick-kangaroos-smoke.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +7702 delegation designator diff --git a/packages/thirdweb/src/utils/bytecode/extractMinimalProxyImplementationAddress.test.ts b/packages/thirdweb/src/utils/bytecode/extractMinimalProxyImplementationAddress.test.ts index 8efe9398594..50a9a4e9b3c 100644 --- a/packages/thirdweb/src/utils/bytecode/extractMinimalProxyImplementationAddress.test.ts +++ b/packages/thirdweb/src/utils/bytecode/extractMinimalProxyImplementationAddress.test.ts @@ -51,6 +51,12 @@ describe("extractMinimalProxyImplementationAddress", () => { expect(result).toBe("0xbebebebebebebebebebebebebebebebebebebebe"); }); + it("should extract address from EIP-7702 delegation designator", () => { + const bytecode = "0xef0100bebebebebebebebebebebebebebebebebebebebe"; + const result = extractMinimalProxyImplementationAddress(bytecode); + expect(result).toBe("0xbebebebebebebebebebebebebebebebebebebebe"); + }); + it("should return undefined for non-matching bytecode", () => { const bytecode = "0x60806040526000805534801561001457600080fd5b50610150806100246000396000f3fe"; diff --git a/packages/thirdweb/src/utils/bytecode/extractMinimalProxyImplementationAddress.ts b/packages/thirdweb/src/utils/bytecode/extractMinimalProxyImplementationAddress.ts index d1b3546e7a2..9c6b3646ca9 100644 --- a/packages/thirdweb/src/utils/bytecode/extractMinimalProxyImplementationAddress.ts +++ b/packages/thirdweb/src/utils/bytecode/extractMinimalProxyImplementationAddress.ts @@ -54,5 +54,11 @@ export function extractMinimalProxyImplementationAddress( return `0x${implementationAddress}`; } + // EIP-7702 - https://eips.ethereum.org/EIPS/eip-7702#abstract + if (bytecode.length === 48 && bytecode.startsWith("0xef0100")) { + const implementationAddress = bytecode.slice(8, 48); + return `0x${implementationAddress}`; + } + return undefined; }