Missing reserve interest accrual prior to backstop take rate update leads to incorrect backstop_credit computation
The pool's backstop take rate can be changed without first accruing reserve interest, so interest earned under the old rate is later credited using the new rate. This can misallocate the portion of accrued interest that should go to backstop credit.
Submitted by 0xadrii, also found by oakcobalt, Testerbot, and Tigerfrake
Summary
Reserve interest is not updated when bstop_rate is changed. Because bstop_rate determines the percentage of the accrued interest that will be stored as backstop credit, not accruing the reserve prior to changing the bstop_rate will make previous unaccrued assets too.
Vulnerability details
When loading a reserve and accruing interest, some of the accrued_interest is stored as backstop credit, which will later be auctioned via an interest auction. The amount of interest going to the backstop credit is determined by the bstop_rate, which is configured as a percentage for the reserve in question, and computed as accrued.fixed_mul_floor(e, &i128(bstop_rate), &SCALAR_7);:
// File: reserve.rs
pub fn load(e: &Env, pool_config: &PoolConfig, asset: &Address) -> Reserve {
...
reserve.accrue(e, pool_config.bstop_rate, accrued_interest);
reserve.data.last_time = e.ledger().timestamp();
reserve
}
fn accrue(&mut self, e: &Env, bstop_rate: u32, accrued: i128) {
let pre_update_supply = self.total_supply(e);
if accrued > 0 {
let mut new_backstop_credit: i128 = 0;
if bstop_rate > 0 {
new_backstop_credit = accrued.fixed_mul_floor(e, &i128(bstop_rate), &SCALAR_7);
self.data.backstop_credit += new_backstop_credit;
}
self.data.b_rate = (pre_update_supply + accrued - new_backstop_credit).fixed_div_floor(
e,
&self.data.b_supply,
&SCALAR_12,
);
}
}
bstop_rate can be updated for a specific reserve by calling execute_update_pool():
// File: config.rs
pub fn execute_update_pool(
e: &Env,
backstop_take_rate: u32,
max_positions: u32,
min_collateral: i128,
) {
let mut pool_config = storage::get_pool_config(e);
pool_config.bstop_rate = backstop_take_rate;
...
}
The problem is that updating the bstop_rate does not accrue interest for the reserve. This can lead to the following situation:
- A pool has a total of 100 tokens of a given reserve to be accrued as
accrued_interest. The currentbstop_rateis configured to 30%, so 30 tokens should be stored asbackstop_creditfor the corresponding period. - The admin of the pool triggers a pool update in order to change the
bstop_ratefrom 30% to 0%. Note there’s still not been any accrual in the reserve (this can be due to low interactions in the pool, for example), and the pool updating logic doesn’t accrue interest for the reserve either. This effectively directly sets thebstop_rateto 0%. - After changing the
bstop_rate, an interaction is performed in the pool, and the interest of the reserve is accrued. However, becausebstop_ratewas changed, a 0% of the 100 accrued will be directed to thebackstop_credit, although a 30% should have been directed to it, as the 100 tokens were accrued while the backstop rate config was set to 30%.
Impact
Medium. If bstop_rate changes, the amount of interest allocated to backstop_credit can be miscalculated. This issue is most likely to occur in pools with lower activity, where the longer intervals between interactions allow unaccounted rewards to accumulate. In contrast, pools with higher activity face a reduced risk, as interest accrues with each interaction that triggers one of the main flows.
Recommended mitigation steps
Consider loading the reserve and storing it so that interest is accrued prior to updating the bstop_rate. This will make the old bstop_rate value be used to compute the corresponding interest.
markus_pl10 (Script3) confirmed
Fixed here to update reserves when backstop take rate changes.
Commit b3e5af4 to improve pool config admin functions.
Status: Mitigation confirmed. Full details in reports from Testerbot, oakcobalt, 0xAlix2 and 0x007.
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 pool configuration update changes the backstop take rate without first loading and accruing each reserve, so unaccrued interest is later split using the new rate.
Impact
The amount of interest allocated to backstop credit can be miscalculated, most likely in lower-activity pools where interest accrues less often.
What the attacker needed
Pool admin changes the backstop take rate; unaccrued reserve interest exists
How it was found
- A reserve has unaccrued interest and the backstop take rate is set to a non-zero value.
- The pool admin updates the pool configuration to change the backstop take rate, without any reserve accrual occurring.
- A later pool interaction accrues the reserve interest using the new backstop take rate instead of the old one.
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 lending pool earns interest over time. A setting decides what share of that interest goes to a safety fund called the backstop. If an admin changes that share before the pool has recorded the interest earned so far, the old interest gets split using the new share, so the safety fund can receive too little or too much.
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.