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

fix: refactor and document tokenId decoding logic #94

Merged
merged 10 commits into from
Jan 30, 2025

Conversation

shrugs
Copy link
Contributor

@shrugs shrugs commented Jan 28, 2025

closes #44

@shrugs shrugs requested a review from a team as a code owner January 28, 2025 18:42
Copy link
Member

@lightwalker-eth lightwalker-eth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shrugs Hey great to see this PR 😄 Reviewed and shared feedback 👍

packages/ensnode-utils/src/subname-helpers.spec.ts Outdated Show resolved Hide resolved
apps/ensnode/src/lib/ens-helpers.ts Outdated Show resolved Hide resolved
apps/ensnode/src/lib/ens-helpers.ts Outdated Show resolved Hide resolved
apps/ensnode/src/lib/ens-helpers.ts Outdated Show resolved Hide resolved
packages/ensnode-utils/src/subname-helpers.ts Outdated Show resolved Hide resolved
apps/ensnode/src/handlers/NameWrapper.ts Outdated Show resolved Hide resolved
apps/ensnode/src/handlers/Registrar.ts Outdated Show resolved Hide resolved
apps/ensnode/src/handlers/Registrar.ts Outdated Show resolved Hide resolved
@shrugs shrugs force-pushed the fix/label-encoding branch from 28c7a07 to 04aed9b Compare January 28, 2025 21:54
Copy link
Member

@lightwalker-eth lightwalker-eth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shrugs Nice! Thank you! This is definitely moving in the right direction now. Reviewed and shared feedback 👍

// NOTE: ponder intentionally removes null bytes to spare users the footgun of
// inserting null bytes into postgres. We don't like this behavior, though, because it's
// important that 'vitalik\x00'.eth and vitalik.eth are differentiable.
// https://github.com/ponder-sh/ponder/issues/1456
// So here we use the labelhash fn to determine whether ponder modified our `name` argument,
// in which case we know that it used to have null bytes in it, and we should ignore it.
const didHaveNullBytes = labelhash(name) !== label;
const didHaveNullBytes = _labelhash(name) !== labelhash;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. It's not right that we would ever calculate the labelhash of a name.

Is name actually label? Are we able to rename that param? Also appreciate if we could verify from related smart contract logic that this renaming would be appropriate.

Additionally, I just noticed a danger point for us that we need to give very careful consideration to. We're currently using the labelhash implementation in viem that is "unknown label aware": https://github.com/wevm/viem/blob/fe558fdef7e2e9cd5f3f57d8bdeae0c7ff67a1b0/src/utils/ens/labelhash.ts#L20-L33

Therefore, if the string we pass into viem's labelhash is in the format of "[{labelhash}]" where {labelhash} is X, the value returned will be X rather than the keccak256 hash of the label literal, which is the traditional definition of labelhash.

It should also be noted how a similar danger point exists in the viem implementation of namehash. For more details, please see the feedback I just shared on PR 89.

Suggest we review all our calls to labelhash / namehash and see if we need to change something.

Please feel super welcome to ask questions 👍 Happy to help!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this context the events (NameRegistered, NameRenewed) emit what we now call a 'label' called name and what we're calling a 'labelhash' called label. the variable names here stem from those events and the subgraph, which names them the same thing.

i've separated these concerns into #100

@@ -47,35 +48,34 @@ export const makeRegistrarHandlers = (ownedName: OwnedName) => {

await context.db
.update(schema.registration, {
id: makeRegistrationId(ownedName, label, node),
id: makeRegistrationId(ownedName, labelhash, node),
})
.set({ labelName: name, cost });
}

return {
get ownedSubnameNode() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename this function to ownedNameNode too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created issue #99

apps/ensnode/src/handlers/Registrar.ts Show resolved Hide resolved
apps/ensnode/src/handlers/Registrar.ts Outdated Show resolved Hide resolved
@@ -51,7 +96,7 @@ export default function () {

await handleNameTransferred({
context,
event: { ...event, args: { from, to, tokenId } },
event: { ...event, args: { from, to, labelhash: labelhash } },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
event: { ...event, args: { from, to, labelhash: labelhash } },
event: { ...event, args: { from, to, labelhash } },

apps/ensnode/src/plugins/eth/handlers/EthRegistrar.ts Outdated Show resolved Hide resolved
apps/ensnode/src/handlers/NameWrapper.ts Outdated Show resolved Hide resolved
Copy link
Member

@lightwalker-eth lightwalker-eth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shrugs Great updates! Thank you 🚀

@lightwalker-eth lightwalker-eth merged commit fc794fb into main Jan 30, 2025
2 checks passed
@lightwalker-eth lightwalker-eth deleted the fix/label-encoding branch January 30, 2025 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refine tokenIdToLabel
3 participants