Skip to content

Commit

Permalink
#1071 prevent overriding already verified contract
Browse files Browse the repository at this point in the history
  • Loading branch information
marcocastignoli committed Jun 21, 2023
1 parent 6a5dd4c commit addbde0
Showing 1 changed file with 47 additions and 45 deletions.
92 changes: 47 additions & 45 deletions src/server/controllers/verification/verification.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,18 @@ export const verifyContractsInSession = async (
for (const id in contractWrappers) {
const contractWrapper = contractWrappers[id];

const found = repositoryService.checkByChainAndAddress(
contractWrapper.address as string,
contractWrapper.chainId as string
);

if (found.length) {
contractWrapper.status = found[0].status || "error";
contractWrapper.statusMessage = found[0].message;
contractWrapper.storageTimestamp = found[0].storageTimestamp;
continue;
}

await checkAndFetchMissing(contractWrapper.contract);

if (!isVerifiable(contractWrapper)) {
Expand All @@ -320,57 +332,47 @@ export const verifyContractsInSession = async (
contract.invalid
);

const found = repositoryService.checkByChainAndAddress(
contractWrapper.address as string,
contractWrapper.chainId as string
);
let match: Match;
if (found.length) {
match = found[0];
} else {
try {
match = await verificationService.verifyDeployed(
checkedContract,
try {
match = await verificationService.verifyDeployed(
checkedContract,
chainId as string,
address as string,
/* contextVariables, */
creatorTxHash
);
// Send to verification again with all source files.
if (match.status === "extra-file-input-bug") {
// Session inputFiles are encoded base64. Why?
const pathBufferInputFiles: PathBuffer[] = Object.values(
session.inputFiles
).map((base64file) => ({
path: base64file.path,
buffer: Buffer.from(base64file.content, FILE_ENCODING),
}));
const contractWithAllSources = await useAllSources(
contractWrapper.contract,
pathBufferInputFiles
);
const tempMatch = await verificationService.verifyDeployed(
contractWithAllSources,
chainId as string,
address as string,
/* contextVariables, */
creatorTxHash
address as string
/* contextVariables */
);
// Send to verification again with all source files.
if (match.status === "extra-file-input-bug") {
// Session inputFiles are encoded base64. Why?
const pathBufferInputFiles: PathBuffer[] = Object.values(
session.inputFiles
).map((base64file) => ({
path: base64file.path,
buffer: Buffer.from(base64file.content, FILE_ENCODING),
}));
const contractWithAllSources = await useAllSources(
contractWrapper.contract,
pathBufferInputFiles
);
const tempMatch = await verificationService.verifyDeployed(
contractWithAllSources,
chainId as string,
address as string
/* contextVariables */
);
if (
tempMatch.status === "perfect" ||
tempMatch.status === "partial"
) {
match = tempMatch;
}
if (tempMatch.status === "perfect" || tempMatch.status === "partial") {
match = tempMatch;
}
} catch (error: any) {
match = {
chainId: contractWrapper.chainId as string,
status: null,
address: contractWrapper.address as string,
message: error.message,
};
}
} catch (error: any) {
match = {
chainId: contractWrapper.chainId as string,
status: null,
address: contractWrapper.address as string,
message: error.message,
};
}

contractWrapper.status = match.status || "error";
contractWrapper.statusMessage = match.message;
contractWrapper.storageTimestamp = match.storageTimestamp;
Expand Down

0 comments on commit addbde0

Please sign in to comment.