The JalaPair::_update function reverts due to the desired overflow inherited from UniswapV2 fork logic.
Vulnerability Detail
When calculating timeElapsed, the following calculation is made: uint32 timeElapsed = blockTimestamp - blockTimestampLast;. Where uint32 blockTimestamp = uint32(block.timestamp % 2 ** 32); and blockTimestampLast is the result of the same calculation but on the previous call to the _update function. This underflow situation is really likely to happen, in fact the code has a comment saying that overflow is desired.
Because of this, some transactions will go through and others won't depending on the block.timestamp value.
Impact
The whole functionality of the DEX will be affected and working intermittently. Users will experience funds unavailability.
santiellena
high
JalaPair::_update
reverts due to underflowSummary
The
JalaPair::_update
function reverts due to the desired overflow inherited from UniswapV2 fork logic.Vulnerability Detail
When calculating
timeElapsed
, the following calculation is made:uint32 timeElapsed = blockTimestamp - blockTimestampLast;
. Whereuint32 blockTimestamp = uint32(block.timestamp % 2 ** 32);
andblockTimestampLast
is the result of the same calculation but on the previous call to the_update
function. This underflow situation is really likely to happen, in fact the code has a comment saying that overflow is desired.Because of this, some transactions will go through and others won't depending on the
block.timestamp
value.Impact
The whole functionality of the DEX will be affected and working intermittently. Users will experience funds unavailability.
Code Snippet
https://github.com/sherlock-audit/2024-02-jala-swap/blob/030d3ed54214754301154bce0e58ea534100a7e3/jalaswap-dex-contract/contracts/JalaPair.sol#L97
Tool used
Manual Review
Recommendation
To let the calculation overflow or underflow, add the
unchecked
label to the code:Duplicate of #186