code-423n4 / 2022-07-juicebox-findings

0 stars 0 forks source link

Unsafe casts `uint256` to `int256` and `int256` to `uint256` #293

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Lines of code

https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/733810a0339a5c0cb608345e6fc66a6edeac13cc/contracts/JBController.sol#L816 https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/733810a0339a5c0cb608345e6fc66a6edeac13cc/contracts/JBController.sol#L668 https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/733810a0339a5c0cb608345e6fc66a6edeac13cc/contracts/JBController.sol#L681 https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/733810a0339a5c0cb608345e6fc66a6edeac13cc/contracts/JBController.sol#L743 https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/733810a0339a5c0cb608345e6fc66a6edeac13cc/contracts/JBController.sol#L785 https://github.com/jbx-protocol/juice-contracts-v2-code4rena/blob/733810a0339a5c0cb608345e6fc66a6edeac13cc/contracts/JBController.sol#L859

Vulnerability details

Impact

The JBController contract performs many unsafe casts uint256 to int256 and int256 to uint256 In example:

Proof of Concept

int256 to uint256:

uint256 to int256:

Note: in the L1076 and L1077 there are two more casts but in the L1075 check the cast

Tools Used

Review

Recommended Mitigation Steps

Use a SafeCast library of openzeppelin toUint256(int256 value) and toInt256(uint256 value) or check the number before cast it

mejango commented 2 years ago

acknowledged here https://info.juicebox.money/dev/learn/risks#large-number-risk