-
Notifications
You must be signed in to change notification settings - Fork 44
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
[audit] #1: Add gas optimization to Sha3 #57
Conversation
@@ -3,7 +3,7 @@ pragma solidity ^0.8.23; | |||
|
|||
library Sha3 { |
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.
is this a lib we inherited?
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.
Functionally; ENS had this method included in the body of the reverse registrar and i moved it out to this lib.
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.
ok, then just noting that if we wanted to try to avoid writing assembly, we could have maybe used this from Solady https://github.com/Vectorized/solady/blob/main/src/utils/LibString.sol#L963
Also isn't keccak256
a variant of sha3
but not exactly the same?
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.
It's true that keccak256
and sha3
aren't the same though perhaps their results are equivalent in this context... TBH I didn't dig too much into the functionality here since it's leveraged in the wild by ENS exactly like this. I'm a little reticent to introduce our own methodology leveraging the solady toLowerCase
function.
Perhaps I should add a natspec to the top of this file referencing the ENS implementation so that it's clear we're just inheriting this logic?
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.
Added natspec header
From Spearbit:
Description
hexAddress
can be optimised by replacing:with
and
with
Also underscores can be added to
ALPHABET
to make it more readable.[!Note] The current implementation copies the same implementation from ens-contracts
Recommendation
Apply the following patch to save around 40 gas: