Skip to content

Commit

Permalink
Merge pull request #5764 from NomicFoundation/feat/remove-support-for…
Browse files Browse the repository at this point in the history
…-int-aliased-console-logs

feat!: Stop supporting console.log selectors with "(u)int" aliases
  • Loading branch information
fvictorio authored Sep 26, 2024
2 parents 93bf282 + 82d0c84 commit cc619ce
Show file tree
Hide file tree
Showing 11 changed files with 12 additions and 444 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-spoons-sparkle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hardhat": minor
---

Remove support for `console.log` selectors that wrongly use "(u)int" type aliases in the selector calculation
26 changes: 7 additions & 19 deletions packages/hardhat-core/scripts/console-library-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,15 @@ const CONSOLE_LOG_FUNCTIONS =
);

/** Maps from a 4-byte function selector to a signature (argument types) */
const CONSOLE_LOG_SIGNATURES: Map<string, string[]> =
CONSOLE_LOG_FUNCTIONS.reduce((acc, { params }) => {
// We always use `log` for the selector, even if it's logUint, for example.
const CONSOLE_LOG_SIGNATURES = Object.fromEntries(
CONSOLE_LOG_FUNCTIONS.map(({ params }) => {
// We always use "log" for the selector, even if it's logUint, for example.
const signature = toHex(selector({ name: "log", params }));
const types = params.map((p) => p.type);
acc.set(signature, types);

// For backwards compatibility, we additionally support the (invalid)
// selectors that contain the `int`/`uint` aliases in the selector calculation.
if (params.some((p) => ["uint256", "int256"].includes(p.type))) {
const aliased = params.map((p) => ({
...p,
type: p.type.replace("int256", "int"),
}));

const signature = toHex(selector({ name: "log", params: aliased }));
acc.set(signature, types);
}

return acc;
}, new Map());
return [signature, types];
})
);

// Finally, render and save the console.sol and logger.ts files
const consoleSolFile = `\
Expand Down Expand Up @@ -190,7 +178,7 @@ ${Array.from(SINGLE_TYPES.map((param) => capitalize(param.type)))
/** Maps from a 4-byte function selector to a signature (argument types) */
export const CONSOLE_LOG_SIGNATURES: Record<number, string[]> = {
${Array.from(CONSOLE_LOG_SIGNATURES)
${Object.entries(CONSOLE_LOG_SIGNATURES)
.map(([sig, types]) => {
const typeNames = types.map((type) => `${capitalize(type)}Ty`).join(", ");
return ` ${sig}: [${typeNames}],`;
Expand Down

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit cc619ce

Please sign in to comment.