Skip to content

Commit 83af4f1

Browse files
authored
Fixes to massive replace for contracts from verifyDepracted (#2299)
Contracts added via verifyDeprecated cannot be fixed by the endpoint since they will never have a match. However, for fixing [#2227](#2227), it is not necessary to have a match because we only replace metadata. So, we should allow replacing contracts without match in replaceContract endpoint.
2 parents ea49774 + 261e585 commit 83af4f1

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

services/database/massive-replace-script/config-constructor-arguments-transformation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121
WHERE c.creation_code_hash IS NOT NULL
2222
AND position(substring(recompiled_creation_code.code for 200) in creation_code.code) != 0
2323
AND (vc.creation_match is null or vc.creation_match = false)
24+
AND c.runtime_code_hash <> decode('F2915DCA011E27647A7C8A50F7062915FDB4D4A1DE05D7333605DB231E5FC1F2', 'hex')
2425
AND sm.id >= $1
2526
ORDER BY sm.id ASC
2627
LIMIT $2

services/server/src/server/apiv1/verification/private/stateless/customReplaceMethods.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
getDatabaseColumnsFromVerification,
55
} from "../../../../services/utils/database-util";
66
import { SourcifyDatabaseService } from "../../../../services/storageServices/SourcifyDatabaseService";
7+
import { BadRequestError } from "../../../../../common/errors";
78

89
export type CustomReplaceMethod = (
910
sourcifyDatabaseService: SourcifyDatabaseService,
@@ -14,6 +15,22 @@ export const replaceCreationInformation: CustomReplaceMethod = async (
1415
sourcifyDatabaseService: SourcifyDatabaseService,
1516
verification: VerificationExport,
1617
) => {
18+
const verificationStatus = verification.status;
19+
const creationMatch =
20+
verificationStatus.creationMatch === "perfect" ||
21+
verificationStatus.creationMatch === "partial";
22+
23+
const runtimeMatch =
24+
verificationStatus.runtimeMatch === "perfect" ||
25+
verificationStatus.runtimeMatch === "partial";
26+
27+
// If the new verification leads to a non-match, we can't replace the contract
28+
if (!runtimeMatch && !creationMatch) {
29+
throw new BadRequestError(
30+
"Failed to match the contract with the new verification",
31+
);
32+
}
33+
1734
// Get database columns from verification
1835
const databaseColumns =
1936
await getDatabaseColumnsFromVerification(verification);

services/server/src/server/apiv1/verification/private/stateless/private.stateless.handlers.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -285,23 +285,11 @@ export async function replaceContract(
285285
transactionHash,
286286
);
287287

288-
await verification.verify();
289-
290-
// Get the verification status
291-
const verificationStatus = verification.status;
292-
const creationMatch =
293-
verificationStatus.creationMatch === "perfect" ||
294-
verificationStatus.creationMatch === "partial";
295-
296-
const runtimeMatch =
297-
verificationStatus.runtimeMatch === "perfect" ||
298-
verificationStatus.runtimeMatch === "partial";
299-
300-
// If the new verification leads to a non-match, we can't replace the contract
301-
if (!runtimeMatch && !creationMatch) {
302-
throw new BadRequestError(
303-
"Failed to match the contract with the new verification",
304-
);
288+
try {
289+
await verification.verify();
290+
} catch {
291+
// Some methods do not require verification, so we ignore errors here.
292+
// This is imported to fix contracts that were added via verifyDeprecated, because they will never have a match.
305293
}
306294

307295
try {
@@ -329,7 +317,7 @@ export async function replaceContract(
329317
address: address,
330318
chainId: chainId,
331319
transactionHash: transactionHash,
332-
newStatus: verificationStatus,
320+
newStatus: verification.status,
333321
rpcFailedFetchingCreationBytecode,
334322
});
335323
} catch (error: any) {

0 commit comments

Comments
 (0)