Skip to content
Business logic Audit finding Advanced

Loss of liquidation compensation assets in absorb

In the absorb function, calling shrine.melt after free causes the caller to receive less compensation than intended because free only updates balances for yangs after the first non-zero balance, missing unaccounted updates from earlier zero-balance yangs. An attacker could exploit this to reduce the compensation they receive, though the impact is capped at 50 USD.

etherhood Follow

Originally disclosed on Code4rena

Submitted by etherhood

In absorb, since shrine.melt is being called after free, caller will end up receiving less compensation than actually intended. It is because in free, while checking user deposits, there are two cases when user has pending redistribution with exception: 1: User’s yang 1 has zero balance 2: User’s yang 1 has non zero balance

In both cases user’s balances are due for an update, if first n yang balances are zero, caller will miss out on compensation from unaccounted yang updates from all yangs due for redistribution until it encounters one with non zero yang balance. When it encounters first non-zero yang balance, it will still miss out on unaccounted fund from that yang as well, but after that it will be okay, since charge() would be called inside seize function which will then update balances for all yangs.

Proof of Concept

This is inside free function, where only after first non-zero yang balance is seize called and redistribution updated for trove and all its yangs. All calls to deposit will return less than actual balance of trove.

            loop {
                match yangs_copy.pop_front() {
                    Option::Some(yang) => {
                        let deposited_yang_amt: Wad = shrine.get_deposit(*yang, trove_id);

                        let freed_asset_amt: u128 = if deposited_yang_amt.is_zero() {
                            0
                        } else {
                            let freed_yang: Wad = wadray::rmul_wr(deposited_yang_amt, percentage_freed);
                            let exit_amt: u128 = sentinel.exit(*yang, recipient, trove_id, freed_yang);
                            shrine.seize(*yang, trove_id, freed_yang);
                            exit_amt
                        };

                        freed_assets.append(AssetBalance { address: *yang, amount: freed_asset_amt });
                    },
                    Option::None => { break; }
                };
            };

Tools Used

VS Code

Recommended Mitigation Steps

The absorb function should update order of melt and free:

            shrine.melt(absorber.contract_address, trove_id, purge_amt);
            let compensation_assets: Span<AssetBalance> = self.free(shrine, trove_id, pct_value_to_compensate, caller);

tserg (Opus) commented:

This is valid and mitigated.

tserg (Opus) confirmed, but disagreed with severity and commented:

Caller still gets compensation, plus it is capped to 50 USD, so the impact of this is capped to 50 USD. User funds are also not at risk.

0xsomeone (judge) decreased severity to Medium and commented:

The warden has showcased a way in which the compensation for the caller of the absorption will be lower than intended.

While the issue is valid, I agree with the sponsor in that the severity of this cannot be considered high-risk. User funds are indeed affected, however, so I believe a medium-risk rating is more apt.


The original report as published on Code4rena, by etherhood. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

Likely the order of operations in absorb: free is called before melt, so free does not account for pending redistribution updates on zero-balance yangs.

Impact

The caller of absorb receives less compensation than intended, but the loss is capped at 50 USD and user funds are not at risk.

What the attacker needed

Caller of absorb function

The fix

The absorb function should update the order of melt and free, calling melt before free.

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 user's debt is liquidated, they get some compensation. The code calculates this compensation before updating all their balances, so some funds are missed. This means the user gets less money than they should, but the loss is small (at most 50 dollars).

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.

More by etherhood

View all

1 more disclosed report, best first.

More from Opus

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.