From aa7b4ca6747559618499fd4a9a629c8375862fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kaan=20Uzdo=C4=9Fan?= Date: Tue, 27 Aug 2024 16:43:19 +0300 Subject: [PATCH] Fix verification logic (#1594) * Don't return false when auxdata differs in creation code but find by edited-recompilation When a contract's creation code has for some reason a different auxdata, the current control flow returns false and abrubts the cborAuxdata position finding process. Instead it should continue to find the positions by editing the contract and recompiling. The real auxdata is actually embedded inside the bytecode. * Fix wrong match check in verification logic. Change logs * Add comment --- packages/lib-sourcify/src/lib/CheckedContract.ts | 1 - packages/lib-sourcify/src/lib/SourcifyChain.ts | 6 ++++-- packages/lib-sourcify/src/lib/verification.ts | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/lib-sourcify/src/lib/CheckedContract.ts b/packages/lib-sourcify/src/lib/CheckedContract.ts index 4fbbb85a5..8d0ee26e3 100644 --- a/packages/lib-sourcify/src/lib/CheckedContract.ts +++ b/packages/lib-sourcify/src/lib/CheckedContract.ts @@ -363,7 +363,6 @@ export class CheckedContract { "The creation auxdata from raw bytecode differs from the legacyAssembly's auxdata", { name: this.name }, ); - return false; } } } diff --git a/packages/lib-sourcify/src/lib/SourcifyChain.ts b/packages/lib-sourcify/src/lib/SourcifyChain.ts index c7552addc..20db0adc0 100644 --- a/packages/lib-sourcify/src/lib/SourcifyChain.ts +++ b/packages/lib-sourcify/src/lib/SourcifyChain.ts @@ -227,7 +227,7 @@ export default class SourcifyChain { } throw new Error( - 'None of the RPCs responded fetching tx ' + + 'None of the RPCs could successfully fetch tx traces for ' + creatorTxHash + ' on chain ' + this.chainId, @@ -420,7 +420,9 @@ export default class SourcifyChain { } if (!creationBytecode) { - throw new Error('Cannot get creation bytecode'); + throw new Error( + `Cannot get the creation bytecode for ${address} from the transaction hash ${transactionHash} on chain ${this.chainId}`, + ); } return { diff --git a/packages/lib-sourcify/src/lib/verification.ts b/packages/lib-sourcify/src/lib/verification.ts index 9596eee48..ebd44ccce 100644 --- a/packages/lib-sourcify/src/lib/verification.ts +++ b/packages/lib-sourcify/src/lib/verification.ts @@ -179,16 +179,16 @@ export async function verifyDeployed( generateCreationCborAuxdataPositions, recompiled.creationLinkReferences, ); - if (match.runtimeMatch === 'partial') { + if (match.creationMatch === 'partial') { logDebug('Matched partial with creation tx', { chain: sourcifyChain.chainId, address, - runtimeMatch: match.runtimeMatch, + creationMatch: match.creationMatch, creatorTxHash, }); match = await tryToFindPerfectMetadataAndMatch( checkedContract, - runtimeBytecode, + runtimeBytecode, // TODO: This is also weird we pass the runtime bytecode here match, async (match, recompiled) => { await matchWithCreationTx(