WhenNotPaused modifier in the CDPVault can be bypassed by users
The CDPVault contract's pause mechanism can be bypassed because the public modifyCollateralAndDebt function lacks the whenNotPaused modifier, allowing users to deposit or withdraw even when the contract is paused.
Submitted by Kaysoft, also found by Afriauditor (1, 2), chaduke, 0xAlix2, boraichodrunkenmaster, ElCid, Spearmint, josephxander, Centaur, zhaojohnson, Bigsam, peanuts, yashar, Inspecktor, ak1, hash, pkqs90, zxriptor, JanuaryPersimmon2024, and ustas
https://github.com/code-423n4/2024-07-loopfi/blob/main/src/CDPVault.sol#L239-L249
Impact
Users can still execute deposit and withdraw functions when the CDPVault.sol is paused as against the design expectation by just calling the modifyCollateralAndDebt(...) function with the necessary parameters.
Proof of Concept
By design it is expected that when the CDPVault.sol contract is paused by the Dao, the deposits and withdrawals cannot be made due to the whenNotPaused modifier on the deposit and withdraw functions. However, the pause mechanism can be bypassed by users to deposit or withdraw on the CDPVault contract by directly calling the modifyCollateralAndDebt(...) function since it is public since it is the same function that is called by the deposit and withdraw functions.
Both the deposit and withdraw functions of the CDPVault.sol only make simple calculations before calling the public modifyCollateralAndDebt(...) function. This allows any user to directly call the modifyCollateralAndDebt(...) function when the CDPVault.sol contract is paused.
File: CDPVault.sol
function deposit(address to, uint256 amount) external whenNotPaused returns (uint256 tokenAmount) {
tokenAmount = wdiv(amount, tokenScale);
int256 deltaCollateral = toInt256(tokenAmount);
@> modifyCollateralAndDebt({
owner: to,
collateralizer: msg.sender,
creditor: msg.sender,
deltaCollateral: deltaCollateral,
deltaDebt: 0
});
}
function withdraw(address to, uint256 amount) external whenNotPaused returns (uint256 tokenAmount) {
tokenAmount = wdiv(amount, tokenScale);
int256 deltaCollateral = -toInt256(tokenAmount);
@> modifyCollateralAndDebt({
owner: to,
collateralizer: msg.sender,
creditor: msg.sender,
deltaCollateral: deltaCollateral,
deltaDebt: 0
});
}
function modifyCollateralAndDebt(
address owner,
address collateralizer,
address creditor,
int256 deltaCollateral,
int256 deltaDebt
) public {
...
}
Recommended Mitigation Steps
Consider implementing either of the two solutions:
- Make the
modifyCollateralAndDebt(...)internalinstead ofpublic, or - Add the
whenNotPausedmodifier to themodifyCollateralAndDebt(...)function.
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 public modifyCollateralAndDebt function, which performs the actual collateral and debt changes, lacks the whenNotPaused modifier that the deposit and withdraw wrappers have.
Impact
Users could deposit or withdraw collateral while the contract is paused, defeating the emergency pause control.
What the attacker needed
Contract is paused by the DAO; attacker can call the public function
How it was found
- Wait until the CDPVault contract is paused by the DAO.
- Call the public modifyCollateralAndDebt function directly with the desired collateral and debt parameters to deposit or withdraw.
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.
A smart contract can have a pause switch to stop deposits and withdrawals in an emergency. The deposit and withdraw functions were protected by this switch, but they both call a public helper function that was not protected. Anyone could call that helper directly and still move funds while the contract was supposed to be paused.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.