ODSafeManager.enterSystem - Transfer wrong amount of collateral, debt
The enterSystem function in ODSafeManager reads the locked collateral and generated debt of the destination safe handler instead of the source, so it transfers the wrong amounts. This breaks the function's intended behaviour and can cause it to fail or move incorrect collateral and debt.
Submitted by klau5
If src has less lockedCollateral and generatedDebt than safeHandler, enterSystem cannot succeed.
The enterSystem function is behaving differently than intended.
Proof of Concept
The ODSafeManager.enterSystem function retrieves the amount of safeHandler’s lockedCollateral and generatedDebt and sends it to safeHandler. The purpose of this function is to send _src’s lockedCollateral and generatedDebt to safeHandler, so it is sending wrong amounts.
function enterSystem(address _src, uint256 _safe) external handlerAllowed(_src) safeAllowed(_safe) {
SAFEData memory _sData = _safeData[_safe];
@> ISAFEEngine.SAFE memory _safeInfo = ISAFEEngine(safeEngine).safes(_sData.collateralType, _sData.safeHandler);
@> int256 _deltaCollateral = _safeInfo.lockedCollateral.toInt();
@> int256 _deltaDebt = _safeInfo.generatedDebt.toInt();
ISAFEEngine(safeEngine).transferSAFECollateralAndDebt(
@> _sData.collateralType, _src, _sData.safeHandler, _deltaCollateral, _deltaDebt
);
emit EnterSystem(msg.sender, _src, _safe);
}
Recommended Mitigation Steps
Use lockedCollateral and generatedDebt of _src.
function enterSystem(address _src, uint256 _safe) external handlerAllowed(_src) safeAllowed(_safe) {
SAFEData memory _sData = _safeData[_safe];
+ ISAFEEngine.SAFE memory _safeInfo = ISAFEEngine(safeEngine).safes(_sData.collateralType, _src);
- ISAFEEngine.SAFE memory _safeInfo = ISAFEEngine(safeEngine).safes(_sData.collateralType, _sData.safeHandler);
int256 _deltaCollateral = _safeInfo.lockedCollateral.toInt();
int256 _deltaDebt = _safeInfo.generatedDebt.toInt();
ISAFEEngine(safeEngine).transferSAFECollateralAndDebt(
_sData.collateralType, _src, _sData.safeHandler, _deltaCollateral, _deltaDebt
);
emit EnterSystem(msg.sender, _src, _safe);
}
The warden has demonstrated how
enterSystem()callstransferSAFECollateralAndDebt()with collateral and debt amounts of the wrong safe handler, causing its functionality to be broken. As such, I agree with medium severity.
pi0neerpat (OpenDollar) commented:
This appears to be accurate, as the collateral and debt amounts are being recorded from the destination address instead of the source address.
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 code fetches the SAFE data using the destination safe handler instead of the source address.
Impact
The function's functionality is broken, and it may fail or transfer incorrect collateral and debt amounts.
What the attacker needed
None
The fix
The code should read lockedCollateral and generatedDebt from the source address (_src) instead of the destination safe handler.
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 move a user's collateral and debt to another safe actually looks up the amounts from the wrong safe. As a result, the transfer uses the destination's numbers instead of the source's, so the function does not work as intended and may fail or move the wrong amounts.
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.