Skip to content
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

Gas Optimizations #645

Open
code423n4 opened this issue Jul 14, 2022 · 0 comments
Open

Gas Optimizations #645

code423n4 opened this issue Jul 14, 2022 · 0 comments
Labels
bug Warden finding G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons

Comments

@code423n4
Copy link
Contributor

VaultRegistry.totalSupply(vault) to token.totalSupply(id)

When the total supply of fractional tokens of a vault is needed, we can make a call VaultRegistry.totalSupply(vault), that gets the token/id and then calls FERC1155(info.token).totalSupply(info.id).

However, sometimes we already have these values, so with this method we have a staticall and two warm SLOAD extra. In the following lines, consider using directly FERC1155(token).totalSupply(id).

Buyout.sol: L71, L210, L267, L288
Migration.sol: L95, L200, L470

VaultInfo.id can be uint96

token and id can be packed in a single storage slot if instead of using uint256 we use uint96. The number of vaults won't realistically reach 2**96.

for-loop i++

In general, a for-loop like this can be made more gas efficient.

for (uint256 i = 0; i < length; i++) {
    ...
}

Consider rewriting it like this:

for (uint256 i = 0; i < length; ) {
    ...
    unchecked {
        ++i;
    }
}

Lines

grep -r 'i++'

Migration.sol buyout can be immutable

SInce this variable doesn't change, it can be set immutable. It saves a SLOAD in every function.

nonReentrant modifier in join isn't needed

There's a nonReentrant modifier in Migration.sol#join. I don't a way to reenter from this function, so I suggest to remove it (to save gas of course).

code423n4 added a commit that referenced this issue Jul 14, 2022
@mehtaculous mehtaculous added the sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons label Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Warden finding G (Gas Optimization) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons
Projects
None yet
Development

No branches or pull requests

2 participants