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

feat!: Stop supporting console.log selectors with "(u)int" aliases #5764

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
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
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.