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

Auction.sol: currentAuctionId should be cached in functions using it frequently #378

Closed
code423n4 opened this issue Dec 1, 2021 · 2 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Handle

harleythedog

Vulnerability details

Impact

In Auction.sol, the storage variable currentAuctionId is frequently used across the contract. In functions that read from this variable multiple times, it would save gas to copy it into a local memory variable first and then use the memory variable for calculations. This is because SLOAD operations are much more expensive than MLOAD operations.

Proof of Concept

For example, see _checkAuctionFinalization here: https://github.com/code-423n4/2021-11-malt/blob/c3a204a2c0f7c653c6c2dda9f4563fd1dc1cecf3/src/contracts/Auction.sol#L746

It would save a lot of gas if currentAuctionId was read from storage once at the start and then the local memory variable was used on subsequent reads.

Tools Used

Inspection

Recommended Mitigation Steps

Cache currentAuctionId reads when there are multiple reads in a function.

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Dec 1, 2021
code423n4 added a commit that referenced this issue Dec 1, 2021
@0xScotch 0xScotch added the duplicate This issue or pull request already exists label Dec 8, 2021
@0xScotch
Copy link
Collaborator

0xScotch commented Dec 8, 2021

#89

@0xScotch 0xScotch closed this as completed Dec 8, 2021
@GalloDaSballo
Copy link
Collaborator

Duplicate of #89

@GalloDaSballo GalloDaSballo marked this as a duplicate of #89 Dec 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization)
Projects
None yet
Development

No branches or pull requests

3 participants