sherlock-audit / 2024-08-cork-protocol-judging

2 stars 2 forks source link

Parvez.eth - Unsafe Casting #257

Closed sherlock-admin3 closed 2 months ago

sherlock-admin3 commented 2 months ago

Parvez.eth

Invalid

Unsafe Casting

Title

M - 4 Unsafe Casting

Summary

Downcasting int/uints in Solidity can be unsafe due to the potential for data loss and unintended behavior.When downcasting a larger integer type to a smaller one (e.g., uint256 to uint128), the value may exceed the range of the target type,leading to truncation and loss of significant digits. Use OpenZeppelin's SafeCast library to safely downcast integers.

Code Snippet

5 Found Instances - Found in src/contracts/core/flash-swaps/FlashSwapRouter.sol [Line: 222](https://github.com/sherlock-audit/2024-08-cork-protocol/blob/main/Depeg-swap/contracts/core/flash-swaps/FlashSwapRouter.sol#L222) ```solidity raReserve += uint112(raAdded); ``` - Found in src/contracts/core/flash-swaps/FlashSwapRouter.sol [Line: 229](https://github.com/sherlock-audit/2024-08-cork-protocol/blob/main/Depeg-swap/contracts/core/flash-swaps/FlashSwapRouter.sol#L229) ```solidity raReserve += uint112(raAdded); ``` - Found in src/contracts/core/flash-swaps/FlashSwapRouter.sol [Line: 230](https://github.com/sherlock-audit/2024-08-cork-protocol/blob/main/Depeg-swap/contracts/core/flash-swaps/FlashSwapRouter.sol#L230) ```solidity ctReserve += uint112(ctAdded); ``` - Found in src/contracts/libraries/DsFlashSwap.sol [Line: 116](https://github.com/sherlock-audit/2024-08-cork-protocol/blob/main/Depeg-swap/contracts/libraries/DsFlashSwap.sol#L116) ```solidity raReserve += uint112(raAdded); ``` - Found in src/contracts/libraries/DsFlashSwap.sol [Line: 117](https://github.com/sherlock-audit/2024-08-cork-protocol/blob/main/Depeg-swap/contracts/libraries/DsFlashSwap.sol#L117) ```solidity ctReserve -= uint112(ctSubstracted); ```