The current logic incorrectly checks decimal0 instead of decimal1. This mistake could cause unintended consequences in scenarios where the value of decimal1 needs to be checked and updated accordingly.
Proof of Concept
In the Stable2::decodeWellData() function, there are conditional checks to set default values (decimal 18) when either of the decimal values is zero.
function decodeWellData(bytes memory data) public view virtual returns (uint256[] memory decimals) {
(uint256 decimal0, uint256 decimal1) = abi.decode(data, (uint256, uint256));
// if well data returns 0, assume 18 decimals.
if (decimal0 == 0) {
decimal0 = 18;
}
if (decimal0 == 0) {
decimal1 = 18;
}
... ...
}
However, the function checks decimal0 twice instead of checking decimal1, which may result in decimal1 being incorrectly set to 18.
Therefore, in case that reserve token 1 has non-18 decimals, the funtionality of the pool will be ruined due to the whole incorrect calculations.
Tools Used
Manual Review
Recommended Mitigation Steps
decimal1 should be checked in the function:
function decodeWellData(bytes memory data) public view virtual returns (uint256[] memory decimals) {
(uint256 decimal0, uint256 decimal1) = abi.decode(data, (uint256, uint256));
// if well data returns 0, assume 18 decimals.
if (decimal0 == 0) {
decimal0 = 18;
}
- if (decimal0 == 0) {
+ if (decimal1 == 0) {
decimal1 = 18;
}
... ...
}
Lines of code
https://github.com/code-423n4/2024-07-basin/blob/7d5aacbb144d0ba0bc358dfde6e0cc913d25310e/src/functions/Stable2.sol#L317
Vulnerability details
Impact
The current logic incorrectly checks
decimal0
instead ofdecimal1
. This mistake could cause unintended consequences in scenarios where the value ofdecimal1
needs to be checked and updated accordingly.Proof of Concept
In the
Stable2::decodeWellData()
function, there are conditional checks to set default values (decimal 18) when either of the decimal values is zero.However, the function checks
decimal0
twice instead of checkingdecimal1
, which may result indecimal1
being incorrectly set to 18.Therefore, in case that reserve token 1 has non-18 decimals, the funtionality of the pool will be ruined due to the whole incorrect calculations.
Tools Used
Manual Review
Recommended Mitigation Steps
decimal1
should be checked in the function:Assessed type
ERC20