0x996 - Due to precision loss, it is impossible to correctly calculate `tokenAReturnAmount`, `tokenBReturnAmount`, `tokenReturnAmount`, and `tokenOutReturnAmount`. #184
Due to precision loss, it is impossible to correctly calculate tokenAReturnAmount, tokenBReturnAmount, tokenReturnAmount, and tokenOutReturnAmount.
Summary:
Due to precision loss, it is impossible to correctly calculate tokenAReturnAmount, tokenBReturnAmount, tokenReturnAmount, and tokenOutReturnAmount.
Vulnerability Detail
The reason lies in the fact that the calculation of these values uses Divide before multiply, where performing division before multiplication leads to precision loss.
A simple example is as follows (can be run in Remix):
constructor(uint256 _a, uint256 _b) {
a = _a;
b = _b;
}
function test01() public view returns (uint256){
return (a * b) / b;
}
function test02() public view returns (uint256){
return (a / b) * b;
}
}
// The final result:
// a = 1, b =2:
// Call test01 -->> Result: 1
// Call test02 -->> Result: 0
0x996
medium
Due to precision loss, it is impossible to correctly calculate
tokenAReturnAmount
,tokenBReturnAmount
,tokenReturnAmount
, andtokenOutReturnAmount
.Summary:
Due to precision loss, it is impossible to correctly calculate
tokenAReturnAmount
,tokenBReturnAmount
,tokenReturnAmount
, andtokenOutReturnAmount
.Vulnerability Detail
Divide before multiply
, where performing division before multiplication leads to precision loss.contract test { uint256 a; uint256 b;
}
// The final result: // a = 1, b =2: // Call test01 -->> Result: 1 // Call test02 -->> Result: 0