Collateral parameters can be overwritten
The addCollateral function's duplicate check is flawed: when the first collateral token is added again, the condition validCollateral[0] != _collateral is false, so the require that prevents duplicates is skipped. An attacker with owner privileges could overwrite the collateral parameters and add the same token multiple times, breaking accounting.
Submitted by cmichel, also found by csanuragjain and gzeon
It’s possible to repeatedly add the first collateral token in validCollateral through the Whitelist.addCollateral function. The validCollateral[0] != _collateral check will return false and skip further checks.
POC
Owner calls addCollateral(collateral=validCollateral[0]):
function addCollateral(
address _collateral,
uint256 _minRatio,
address _oracle,
uint256 _decimals,
address _priceCurve,
bool _isWrapped
) external onlyOwner {
checkContract(_collateral);
checkContract(_oracle);
checkContract(_priceCurve);
// If collateral list is not 0, and if the 0th index is not equal to this collateral,
// then if index is 0 that means it is not set yet.
// @audit evaluates validCollateral[0] != validCollateral[0] which is obv. false => skips require check
if (validCollateral.length != 0 && validCollateral[0] != _collateral) {
require(collateralParams[_collateral].index == 0, "collateral already exists");
}
validCollateral.push(_collateral);
// overwrites parameters
collateralParams[_collateral] = CollateralParams(
_minRatio,
_oracle,
_decimals,
true,
_priceCurve,
validCollateral.length - 1,
_isWrapped
);
}
Impact
The collateral parameters collateralParams are re-initialized which can break the existing accounting. The collateral token also exists multiple times in validCollateral.
Recommended Mitigation Steps
Fix the check. It should be something like:
if (validCollateral.length > 0) {
require(collateralParams[_collateral].index == 0 && validCollateral[0] != _collateral, "collateral already exists");
}
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The duplicate check uses a condition that is false when the collateral is the first element, so the require statement that should prevent duplicates is never executed.
Impact
The collateral parameters are re-initialized, which can break existing accounting, and the token appears multiple times in validCollateral.
What the attacker needed
Owner privileges
The fix
The check should be fixed so that it correctly rejects duplicates even when the collateral is the first element, for example by requiring that the index is zero and the first element is not the same collateral.
How it was found
- The owner calls addCollateral with the address of the first collateral token already in validCollateral.
- The check validCollateral[0] != _collateral evaluates to false, so the require that would reject a duplicate is skipped.
- The function pushes the token again and overwrites its CollateralParams.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
This is a smart contract bug where a function meant to add a new collateral token fails to stop you from adding the same token again if it is the first one in the list. Because the check is skipped, the token's settings get overwritten and the token appears multiple times, which can mess up the contract's internal bookkeeping.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.