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

Overflow is desired when adding/subtracting cumulative prices #148

Closed
code423n4 opened this issue Sep 8, 2022 · 2 comments
Closed

Overflow is desired when adding/subtracting cumulative prices #148

code423n4 opened this issue Sep 8, 2022 · 2 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists edited-by-warden QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-09-canto/blob/6f98ffa7ec55c2ca03aa4cd2301503487f0c412d/src/Swap/BaseV1-core.sol#L141-L143
https://github.com/code-423n4/2022-09-canto/blob/6f98ffa7ec55c2ca03aa4cd2301503487f0c412d/src/Swap/BaseV1-core.sol#L166-L168

Vulnerability details

Impact

Contract will revert when cumulative prices reach type(uint256).max

PoC

Cumulative prices are designed to work with overflows/underflows because the difference is computed to calculate TWAP so this behavior is desired.
Please see Notes on overflow from Uniswap V2.

https://docs.uniswap.org/protocol/V2/guides/smart-contract-integration/building-an-oracle

Addition of the variables reserve0CumulativeLast, reserve1CumulativeLast and totalSupplyCumulativeLast need to be put in a unchecked block otherwise the contract will revert when some of them reach the maximum.

Finally, timestamps can also be put in unchecked box just to save gas, though it is imposible for your case as you use uint256. (Uniswap uses uint32)

Recommended

If I am not wrong, you can uncheck all these functions completely

_update
currentCumulativePrice
current (Except for line 177 maybe)
sample
reserves
sampleReserves
sampleSupply

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Sep 8, 2022
code423n4 added a commit that referenced this issue Sep 8, 2022
@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly edited-by-warden and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Sep 8, 2022
@nivasan1 nivasan1 added the duplicate This issue or pull request already exists label Sep 9, 2022
@nivasan1
Copy link
Collaborator

nivasan1 commented Sep 9, 2022

duplicate #35

@nivasan1 nivasan1 closed this as completed Sep 9, 2022
@0xean
Copy link
Collaborator

0xean commented Oct 13, 2022

closing as dupe of #174 - wardens QA report.

@0xean 0xean added QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Oct 13, 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 duplicate This issue or pull request already exists edited-by-warden QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Projects
None yet
Development

No branches or pull requests

3 participants