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

Precision loss could happen when division comes before multiplication #274

Closed
code423n4 opened this issue Feb 1, 2023 · 5 comments
Closed
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue edited-by-warden grade-c QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@code423n4
Copy link
Contributor

code423n4 commented Feb 1, 2023

Lines of code

https://github.com/code-423n4/2023-01-numoen/blob/2ad9a73d793ea23a25a381faadc86ae0c8cb5913/src/core/Pair.sol#L56-L57

Vulnerability details

Impact

Detailed description of the impact of this finding.

There appears to be division before multiplication in this line of code which could result to precision loss or unexpected output.

Proof of Concept

Provide direct links to all referenced code in GitHub. Add screenshots, logs, or any other relevant proof that illustrates the concept.

https://github.com/code-423n4/2023-01-numoen/blob/2ad9a73d793ea23a25a381faadc86ae0c8cb5913/src/core/Pair.sol#L56-L57

Tools Used

Manual Review

Recommended Mitigation Steps

It is recommended to multiply before doing division

uint256 scale0 = FullMath.mulDiv(amount0 * 1e18 * token0Scale, 1, liquidity);
uint256 scale0 = FullMath.mulDiv(amount0 * 1e18 * token1Scale, 1, liquidity);

@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 Feb 1, 2023
code423n4 added a commit that referenced this issue Feb 1, 2023
@code423n4 code423n4 changed the title Division before multiplication Issues Precision loss could happen when division comes before multiplication Feb 1, 2023
@c4-judge c4-judge closed this as completed Feb 7, 2023
@c4-judge
Copy link

c4-judge commented Feb 7, 2023

berndartmueller marked the issue as duplicate of #264

@berndartmueller
Copy link
Member

Due to the lack of a concrete impact (in comparison to #264) and the overall lack of quality, I'm downgrading this to QA (Low).

@c4-judge
Copy link

berndartmueller marked the issue as not a duplicate

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Feb 13, 2023
@c4-judge
Copy link

berndartmueller changed the severity to QA (Quality Assurance)

@c4-judge c4-judge added grade-c unsatisfactory does not satisfy C4 submission criteria; not eligible for awards labels Feb 16, 2023
@c4-judge
Copy link

berndartmueller marked the issue as grade-c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue edited-by-warden grade-c QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

3 participants