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

00768 Streamline Hardhat Smart Contract Verification Process Similar to Sourcify #781

Merged
merged 1 commit into from
Nov 29, 2023
Merged
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
29 changes: 23 additions & 6 deletions src/utils/solc/SolcUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,38 @@ export class SolcUtils {
// https://docs.soliditylang.org/en/v0.4.25/metadata.html#encoding-of-the-metadata-hash-in-the-bytecode
const components1 = splitAuxdata(bytecode1)
const components2 = splitAuxdata(bytecode2)
const bytecode1NoHash = components1.length >= 1 ? components1[0] : bytecode1
const bytecode2NoHash = components2.length >= 1 ? components2[0] : bytecode2
const opCodes1 = components1.length >= 2 ? components1[0] : bytecode1
const opCodes2 = components2.length >= 2 ? components2[0] : bytecode2
const hash1 = components1.length >= 2 ? components1[1] : ""
const hash2 = components2.length >= 2 ? components2[1] : ""

const cleanOpCodes1 = this.clearPlaceholders(opCodes1)
const cleanOpCodes2 = this.clearPlaceholders(opCodes2)

let result: BytecodeComparison
if (bytecode1 === bytecode2) {
result = BytecodeComparison.fullMatch
} else if (bytecode1NoHash === bytecode2NoHash) {
result = BytecodeComparison.partialMatch
if (cleanOpCodes1 === cleanOpCodes2) {
result = hash1 === hash2 ? BytecodeComparison.fullMatch : BytecodeComparison.partialMatch
} else {
result = BytecodeComparison.mismatch
}

return result
}

public static clearPlaceholders(bytecode: string): string {
bytecode = bytecode.startsWith("0x") ? bytecode.slice(2) : bytecode

// If first opcode is 0x73 then next 20 bytes represent an address placeholder => should be cleared
let result: string
if (bytecode.length >= 42 && bytecode.startsWith("73")) {
result = bytecode.slice(42)
} else {
result = bytecode
}

return result
}

}


Expand Down