-
Notifications
You must be signed in to change notification settings - Fork 122
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
Ponder Implicitly Removes Null Bytes from Event Arguments #1456
Comments
Hi, thanks for opening. Was not aware of the historical context here, thanks for sharing. We shipped this change ~2 weeks ago in I can definitely see how this makes it difficult to achieve the desired behavior here for ENS, so I'm open to a different solution. For context, we received several reports (both ENS and non-ENS apps) running into this issue because they were trying to store user-provided text in a postgres So, it's a bit of a dilemma. Couple ideas:
My instinct is that ENS is the outlier here, so I struggle with any option that doesn't sanitize by default. That direction regresses to every ponder app having to manually sanitize Appreciate your take! |
It's a bit strict of me but I think the postgres error should be intentional behavior. It does mean user-education & burden on devs to sanitize user-provided strings, which is definitely an overhead. I don't love a configuration flag, in a code-over-config way, it'd be more explicit for someone in userland to say I agree that ENS is an outlier, but it does seem that storing user-provided strings is pretty universal. The unique aspect here is that in ENS these strings are hyper specific unique values and identity matters, versus something like the zora on-chain comments. I'll admit that if postgres threw an error, it'd be a really shitty experience to not know about this and then have your index crash randomly in the future because of a user providing a malformed string. So ensuring that doesn't happen would be quite nice for DX — that's a point for the config option w/ defaults. That said the alternative (bad data because dev didn't know about null character removal) is a much worse type of bug (implicit, difficult to track down) that could occur in the future as well, depending on how the dev is using those user-provided values. Failing hard and fast seems preferable in this case. But if ENS-style apps are a clear outlier, then the config + documentation seems like a reasonable choice. |
Version
0.8.28
Current behavior
In indexing ENS, some labels with null bytes are emitted, but these labels cannot be stored in postgres (which is likely the reason ponder trims them to begin with). Unfortunately this removes information from the application-layer who might handle these cases differently. In ENS's case, it's important that
'vitalik\x00'.eth
andvitalik.eth
are differentiable.In this specific case, we can use
const hadNullBytes = labelhash(name) !== label
as a proxy for null-byte detection, since thelabel
argument in that event is justlabelhash(name)
and will be different for the originalname
value that includes the null byte.More information is available here, where I debugged this behavior 👇
namehash/ensnode#36
Expected behavior
I believe the current behavior of ponder is extremely reasonable, but I worry that the developer integrating ponder loses this information and may accidentally index the wrong data. In our case we were treating these two names as identical, which messed up the resulting data (and would have perhaps enabled someone resolving
vitalik.eth
to receive the imposter's information. We assumed we were getting the raw argument data from ponder, intending to handle the null-byte ourselves, but were actually receiving strings with null bytes already removed.It seems that the default behavior of postgres is to throw an error if a null byte is inserted, though I'm not sure why this didn't cause subgraph indexers from failing to index these names in the original postmortem.
https://ens.mirror.xyz/9GN77d-MqGvRypm72FcwgxlUnPSuKWhG3rWxddHhRwM
In any case, I think that the default behavior, where postgres throws an unrecoverable error, forcing the user to handle this case, is likely the correct path. Ponder can/should provide null-byte helper functions to make this easier on users, for example a
containsNullCharacters
orremoveNullCharacters
helper fn.Steps to reproduce
You don't really need to reproduce this, but here's an offending tx:
0x535bf909ec258054cb03ab03498b4de0b365e1037a43fcdfbdcb28202382a9cd
which you can access via ponder with the following config:and you can log the arguments provided to your
NameRegistered
event handler to see that the null byte is removed.the relevant line in ponder is https://github.com/ponder-sh/ponder/blob/178bcbfd36b5eb418ee118c0e6b02a46c9c7ed6d/packages/core/src/sync/events.ts#L505C25-L505C45
Link to repository
https://github.com/namehash/ensnode
Anything else?
No response
The text was updated successfully, but these errors were encountered: