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

Unnecessary checked arithmetic when no overflow/underflow possible (2) #77

Closed
code423n4 opened this issue Jan 5, 2022 · 1 comment
Closed
Labels
bug Something isn't working duplicate This issue or pull request already exists G (Gas Optimization)

Comments

@code423n4
Copy link
Contributor

Handle

Dravee

Vulnerability details

Impact

Increased gas cost.

Proof of Concept

Solidity version 0.8+ comes with implicit overflow and underflow checks on unsigned integers.
When an overflow or an underflow isn't possible (as an example, when a comparison is made before the arithmetic operation), some gas can be saved by using an unchecked block.

https://docs.soliditylang.org/en/v0.8.10/control-structures.html#checked-or-unchecked-arithmetic

Let's look at these lines:

Timeswap-V1-Core\contracts\TimeswapPair.sol:162:            pool.liquidities[factory.owner()] += liquidityTotal - liquidityOut;
Timeswap-V1-Core\contracts\TimeswapPair.sol:168:            pool.liquidities[factory.owner()] += liquidityTotal - liquidityOut;

Here, in MintMath.getLiquidity:L54: liquidityOut is set to a value <= liquidityTotal. Therefore liquidityTotal - liquidityOut cannot underflow.

Tools Used

VS Code

Recommended Mitigation Steps

Uncheck arithmetic operations when possible.

@code423n4 code423n4 added bug Something isn't working G (Gas Optimization) labels Jan 5, 2022
code423n4 added a commit that referenced this issue Jan 5, 2022
@amateur-dev
Copy link
Collaborator

Similar issue highlighted over here #156 ; hence closing this.

@amateur-dev amateur-dev added the duplicate This issue or pull request already exists label Jan 15, 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 G (Gas Optimization)
Projects
None yet
Development

No branches or pull requests

2 participants