-
Notifications
You must be signed in to change notification settings - Fork 20.7k
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
accounts/abi/bind: handle UnpackLog with zero topics #26920
Conversation
Is there a case where log.Topics is zero length? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Odd, both windows-builders failed on this:
I wonder if we have some breakage on |
I guess it doesn't hurt to have this extra check but why did you decide to add it? |
We had an audit done of a fork if this repo and the auditors raised this issue. I was split on whether to explain why this wasn't an issue (which it is not in the way that it's used here) or to add the suggested check. I decided that adding the check would make the correctness of this code much more clear at very minimal cost and since it's used as a library as well, that seemed like a good tradeoff. |
Yes there can be a log with length 0 through the They are not very common since Solidity smart contracts typically use an identifier of the event as the first topic and any indexed parameters as the rest of the topics in the log: https://docs.soliditylang.org/en/v0.8.19/abi-spec.html#events, but you can create them by using an anonymous event or manually create an event with zero topics by doing something lower level. |
This PR is strictly an improvement because abigen would crash for LOG0 otherwise. But I feel uneasy about returning an error for this case because technically it should be possible to unpack the data field of a LOG0. |
Ah nice, I agree it would be great to add support for handling anonymous logs. Thanks for updating and reviewing! Tbh because The reason I think this is a good change is to make it more obviously correct and gracefully handle this slightly unexpected case. |
I didn't know this as well and learned yesterday how anonymous events work. They do have a name and that's what the I have locally added some more tests, I will polish and push by this evening. It would be also nice to have a testcase which generates code for a contract with anonymous events. |
Abigen doesn't generate a type for anonymous events because it's not possible to filter them specifically. It is still possible to search by contract address. So there's a case to be made for allowing unpacking of anonymous events, however they seem to be used veeeery seldom. So I will revert my changes and approve the PR how you had it in the beginning. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR adds error handling for the case that
UnpackLog
orUnpackLogIntoMap
is called with a log that has zero topics.Also moves errors from
fmt.Errorf(...)
with no formatted arguments to useerrors.New
and declare the errors at the top of the file.