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 #212

Open
code423n4 opened this issue May 24, 2022 · 0 comments
Open

Gas Optimizations #212

code423n4 opened this issue May 24, 2022 · 0 comments
Labels
bug Something isn't working G (Gas Optimization) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons

Comments

@code423n4
Copy link
Contributor

1. Save gas by keeping track of nextEpochDate instead of reading from storage.

Details

In AuraLocker._checkpointEpoch(), there is a while loop to fill epoch gaps until the next epoch date. Each iter, it reads from storage 4 times (2 in the while condition, 2 when calculate nextEpochDate).
In fact, nextEpochDate can be kept track simply by adding rewardsDuration each epoch.

Proof of concept

https://github.com/code-423n4/2022-05-aura/blob/4989a2077546a5394e3650bf3c224669a0f7e690/contracts/AuraLocker.sol#L334-L335

Recommended Mitigation Steps

Use variable nextEpochDate to cache like this

uint256 nextEpochDate = uint256(epochs[epochs.length - 1].date);
while (nextEpockDate != currentEpoch) {
  uint256 nextEpochDate = nextEpockDate.add(rewardsDuration);
  epochs.push(Epoch({ supply: 0, date: uint32(nextEpochDate) }));
}
@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels May 24, 2022
code423n4 added a commit that referenced this issue May 24, 2022
@0xMaharishi 0xMaharishi added the sponsor acknowledged Technically the issue is correct, but we're not going to resolve it for XYZ reasons label May 27, 2022
@0xMaharishi 0xMaharishi added the resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) label May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working G (Gas Optimization) resolved Finding has been patched by sponsor (sponsor pls link to PR containing fix) 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