-
Notifications
You must be signed in to change notification settings - Fork 0
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
Constant variable can be immutable (UFactoryProvider.sol) #42
Comments
Support for this was added in Solidity v0.6.12. |
I've built a very simple test:
Vs
And I'm getting Keccak 8 Keccak 8 immutable So arguably immutable is way cheaper This without optimizer If I do it with the optimizer: Keccak 8 Keccak 8 Immutable While this may not be enough, I think the finding is valid |
@GalloDaSballo I dug into this as well, because I was really interested in seeing how this works. Here's what I'm getting which is a bit different than your result: Constant
Immutable
Using Remix I'm getting the gas costs:
So given this I think it's strictly better to using immutable? Either way, and I apologize for not including this in the original message, |
Interesting that you get such different values. I think the proper way would be to setup an hardhat repo and run it a while. That said, given that the contracts are meant to be upgradeable, you can't use a constructor so the finding is invalid |
Handle
ye0lde
Vulnerability details
Impact
Changing the variable from constant to immutable will reduce keccak operations and save gas.
Proof of Concept
The variable that can be changed from
constant
toimmutable
is here:https://github.com/code-423n4/2021-12-perennial/blob/fd7c38823833a51ae0c6ae3856a3d93a7309c0e4/protocol/contracts/factory/UFactoryProvider.sol#L23
A previous finding with additional explanation and a pointer to the Ethereum/solidity issue is here:
code-423n4/2021-10-slingshot-findings#3
Tools Used
Visual Studio Code, Remix
Recommended Mitigation Steps
Change the constant variable to immutable.
The text was updated successfully, but these errors were encountered: