Closed code423n4 closed 2 years ago
WatchPug
Caching the new storage value in the stack and reusing it instead of reading from storage redundantly can save gas.
Instances include:
https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L185-L189
pool.state.x += xIncrease; pool.state.y += yIncrease; pool.state.z += zIncrease; emit Sync(maturity, pool.state.x, pool.state.y, pool.state.z);
Can be changed to:
uint112 newX = pool.state.x + xIncrease; uint112 newY = pool.state.y + yIncrease; uint112 newZ = pool.state.z + zIncrease; pool.state.x = newX; pool.state.y = newY; pool.state.z = newZ; emit Sync(maturity, newX, newY, newZ);
https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L256-L260
pool.state.x += xIncrease; pool.state.y -= yDecrease; pool.state.z -= zDecrease; emit Sync(maturity, pool.state.x, pool.state.y, pool.state.z);
Consider caching new value of pool.state.x, pool.state.y and pool.state.z;
pool.state.x
pool.state.y
pool.state.z
https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L330-L336
pool.state.x -= xDecrease; pool.state.y += yIncrease; pool.state.z += zIncrease; asset.safeTransfer(assetTo, xDecrease); emit Sync(maturity, pool.state.x, pool.state.y, pool.state.z);
We have stack too deep error.
closing as invalid based on stack too deep errors.
Handle
WatchPug
Vulnerability details
Caching the new storage value in the stack and reusing it instead of reading from storage redundantly can save gas.
Instances include:
https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L185-L189
Can be changed to:
https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L256-L260
Consider caching new value of
pool.state.x
,pool.state.y
andpool.state.z
;https://github.com/code-423n4/2022-01-timeswap/blob/bf50d2a8bb93a5571f35f96bd74af54d9c92a210/Timeswap/Timeswap-V1-Core/contracts/TimeswapPair.sol#L330-L336
Consider caching new value of
pool.state.x
,pool.state.y
andpool.state.z
;