From 6cd681c9cee4641c67bc341e03231d886ec7501a Mon Sep 17 00:00:00 2001 From: kumaryash90 Date: Fri, 14 Nov 2025 15:29:13 +0000 Subject: [PATCH] Fix resolve implementation (#8413) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ## PR-Codex overview This PR focuses on improving the `resolveImplementation` function in the `thirdweb` package by enhancing the implementation resolution process for proxy contracts. ### Detailed summary - Replaced the existing implementation resolution logic with a more robust approach using `Promise.all` to fetch implementations from both storage and contract calls. - Introduced a loop to handle multiple implementations, ensuring that valid addresses are checked before proceeding. - Updated the return logic to ensure correct addresses and bytecode are returned based on the resolved implementation. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` ## Summary by CodeRabbit * **Bug Fixes** * Improved the reliability of contract implementation resolution to handle edge cases more robustly when detecting implementations across proxy contracts and various contract architecture types. Processing is now more efficient through concurrent implementation detection and optimized fallback handling, ensuring more consistent and faster results in complex contract scenarios. --- .changeset/afraid-regions-push.md | 5 ++ .../utils/bytecode/resolveImplementation.ts | 49 ++++++++++--------- 2 files changed, 30 insertions(+), 24 deletions(-) create mode 100644 .changeset/afraid-regions-push.md diff --git a/.changeset/afraid-regions-push.md b/.changeset/afraid-regions-push.md new file mode 100644 index 00000000000..8355fa89e90 --- /dev/null +++ b/.changeset/afraid-regions-push.md @@ -0,0 +1,5 @@ +--- +"thirdweb": patch +--- + +Resolve implementation from contract call diff --git a/packages/thirdweb/src/utils/bytecode/resolveImplementation.ts b/packages/thirdweb/src/utils/bytecode/resolveImplementation.ts index e2ab742fc53..afb9566ea66 100644 --- a/packages/thirdweb/src/utils/bytecode/resolveImplementation.ts +++ b/packages/thirdweb/src/utils/bytecode/resolveImplementation.ts @@ -47,8 +47,6 @@ export async function resolveImplementation( } // check other proxy types - let implementationAddress: string | undefined; - if (beacon && beacon !== AddressZero) { // In case of a BeaconProxy, it is setup as BeaconProxy --> Beacon --> Implementation // Hence we replace the proxy address with Beacon address, and continue further resolving below @@ -56,33 +54,36 @@ export async function resolveImplementation( ...contract, address: beacon, }); - - implementationAddress = await getImplementationFromContractCall(contract); - } else { - implementationAddress = await getImplementationFromStorageSlot(contract); } - if ( - implementationAddress && - isAddress(implementationAddress) && - implementationAddress !== AddressZero - ) { - const implementationBytecode = await getBytecode({ - ...contract, - address: implementationAddress, - }); - // return the original contract bytecode if the implementation bytecode is empty - if (implementationBytecode === "0x") { + const implementations = await Promise.all([ + getImplementationFromStorageSlot(contract), + getImplementationFromContractCall(contract), + ]); + + for (const implementationAddress of implementations) { + if ( + implementationAddress && + isAddress(implementationAddress) && + implementationAddress !== AddressZero + ) { + const implementationBytecode = await getBytecode({ + ...contract, + address: implementationAddress, + }); + // return the original contract bytecode if the implementation bytecode is empty + if (implementationBytecode === "0x") { + return { + address: contract.address, + bytecode: originalBytecode, + }; + } + return { - address: contract.address, - bytecode: originalBytecode, + address: implementationAddress, + bytecode: implementationBytecode, }; } - - return { - address: implementationAddress, - bytecode: implementationBytecode, - }; } return { address: contract.address, bytecode: originalBytecode };