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

TwapOracle.sol update() Multiple SLOAD During Loop #157

Closed
code423n4 opened this issue Nov 15, 2021 · 3 comments
Closed

TwapOracle.sol update() Multiple SLOAD During Loop #157

code423n4 opened this issue Nov 15, 2021 · 3 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization) TwapOracle

Comments

@code423n4
Copy link
Contributor

Handle

Meta0xNull

Vulnerability details

Impact

Repeat SLOAD _pairs during the loop
Save _pairs as pairData in Storage in loop
Multiple SLOAD pairData within same loop

Storage SLOAD are more expensive than read local variables. The Gas Price Add Up during Loop is very very expensive.

Proof of Concept

https://github.com/code-423n4/2021-11-vader/blob/main/contracts/twap/TwapOracle.sol#L322-L368

Tools Used

Manual Review

Recommended Mitigation Steps

Before the Loop Start, SLOAD _pairs and caching it once in a local variable _pairs_temp. Then use local variable _pairs_temp in the loop.

PairData _pairs_temp = _pairs;

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Nov 15, 2021
code423n4 added a commit that referenced this issue Nov 15, 2021
@SamSteinGG SamSteinGG added the duplicate This issue or pull request already exists label Nov 20, 2021
@SamSteinGG
Copy link
Collaborator

Duplicate of #94

@SamSteinGG SamSteinGG marked this as a duplicate of #94 Nov 20, 2021
@alcueca
Copy link
Collaborator

alcueca commented Dec 10, 2021

Not a duplicate of #94

@alcueca alcueca reopened this Dec 10, 2021
@SamSteinGG
Copy link
Collaborator

The TWAP oracle module has been completely removed and redesigned from scratch as LBTwap that is subject of the new audit.

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) TwapOracle
Projects
None yet
Development

No branches or pull requests

4 participants