after shut, no pulled redistribution yang will be locked
After a shrine is shut down, any redistributed collateral that has not yet been pulled into a trove cannot be released by the caretaker, so it remains locked in the contract. An attacker could not directly exploit this, but users lose access to their redistributed collateral.
bin2chen Follow with mahdikarimi and etherhood
Originally disclosed on Code4rena
Submitted by bin2chen, also found by mahdikarimi and etherhood
In caretaker.release(), we can release the remaining yang:
fn release(ref self: ContractState, trove_id: u64) -> Span<AssetBalance> {
let shrine: IShrineDispatcher = self.shrine.read();
...
loop {
match yangs_copy.pop_front() {
Option::Some(yang) => {
@> let deposited_yang: Wad = shrine.get_deposit(*yang, trove_id);
let asset_amt: u128 = if deposited_yang.is_zero() {
0
} else {
let exit_amt: u128 = sentinel.exit(*yang, trove_owner, trove_id, deposited_yang);
// Seize the collateral only after assets have been
// transferred so that the asset amount per yang in Gate
// does not change and user receives the correct amount
shrine.seize(*yang, trove_id, deposited_yang);
exit_amt
};
released_assets.append(AssetBalance { address: *yang, amount: asset_amt });
},
Option::None => { break; },
};
};
As above, we can only release the yang that already exists in the trove: shrine.get_deposit(*yang, trove_id);.
When shire.get_live() == false, we can no longer perform shire.pull_redistributed_debt_and_yangs(). So if there is any yang that hasn’t been pulled, it can’t be retrieved through caretaker.release(). This part of the yang will be locked in the contract.
Impact
After shut(), the redistributed yang that hasn’t been pulled will be locked in the contract.
Recommended Mitigation
Add pull_when_shut():
fn pull_when_shut(ref self: ContractState, trove_id: u64) {
if self.is_live.read() {
return;
}
let trove: Trove = self.troves.read(trove_id);
let current_interval: u64 = now();
let trove_yang_balances: Span<YangBalance> = self.get_trove_deposits(trove_id);
let (updated_trove_yang_balances, _) = self
.pull_redistributed_debt_and_yangs(trove_id, trove_yang_balances,Wad { val: 0 });
// If there was any exceptional redistribution, write updated yang amounts to trove
if updated_trove_yang_balances.is_some() {
let mut updated_trove_yang_balances = updated_trove_yang_balances.unwrap();
loop {
match updated_trove_yang_balances.pop_front() {
Option::Some(yang_balance) => {
self.deposits.write((*yang_balance.yang_id, trove_id), *yang_balance.amount);
},
Option::None => { break; },
};
};
}
self.trove_redistribution_id.write(trove_id, self.redistributions_count.read());
}
fn release(ref self: ContractState, trove_id: u64) -> Span<AssetBalance> {
let shrine: IShrineDispatcher = self.shrine.read();
...
+ shrine.pull_when_shut(trove_id);
loop {
match yangs_copy.pop_front() {
Option::Some(yang) => {
let deposited_yang: Wad = shrine.get_deposit(*yang, trove_id);
Assessed type
Error
The warden has demonstrated how the graceful shutdown of a shrine can result in loss of funds if an exceptional trove redistribution occurred, resulting in loss of the redistributed collateral.
I believe a medium-risk grade is apt for this exhibit as it relates to a low-likelihood scenario and a loss that is contained.
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 release function only processes collateral already deposited in the trove and does not pull pending redistributed collateral when the shrine is no longer live.
What the attacker needed
Shrine is shut down; trove has pending redistributed collateral
The fix
The release function should first pull any pending redistributed collateral when the shrine is not live, then release all collateral.
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.
When a vault is closed, some collateral may be owed to it from other vaults. Normally, the owner can pull that collateral in. But after the system is shut down, the function to pull it stops working, and the release function only returns collateral already recorded in the vault. So the owed collateral gets stuck.
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.