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
Represent present value with 256 bits instead of 104 #454
Conversation
Just measured, and it seems to save ~100 bytes contract size and a few hundred gas on supply, transfer, and withdraw, in addition to avoiding the unsafe cast. |
4e73974
to
b71a54e
Compare
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 nice that this shaves off some gas and contract size. However, other than the unchecked change, I don't think these changes are actually adding extra safety right?
I've always been supportive of using uint256/int256
for intermediate variables, but this is a pretty large change late in the cycle so I'll want to spend some more time to review this. But I definitely think this is the right change to make. 👍
Well it gets rid of the unsafe cast in |
Yeah, that's what I meant by "unchecked change". Just to make sure I'm not missing anything, I want to double check with you that that's the only change here that changes the safety of our code. The other changes are more gas savings/optimizations (e.g. less explicit casting) right? |
Yes, those 2 changes should be the difference |
792d5b4
to
6123b1d
Compare
b84caae
to
8ed42ce
Compare
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.
Nice, looks good!
This internally uses 256 bits for present values instead of artificially constraining them to 104 bits. This avoids an unsafe cast we were doing previously to save gas, and also opens up some other gas optimizations / contract size reductions. However, this also removes some previously unchecked math, which makes it a slight tradeoff in terms of gas.
As pointed out by ChainSecurity.
8ed42ce
to
6cf788f
Compare
This internally uses 256 bits for present values instead of artificially constraining them to 104 bits. This avoids an unsafe cast we were doing previously to save gas, and also opens up some other gas optimizations / contract size reductions. However, this also removes some previously unchecked math, which makes it a slight tradeoff in terms of gas.