Skip to content
Business logic Audit finding Intermediate

Possible Wrong bAsset Rewards/Borrow limits Calculation

The contract's reward and borrow limit calculations rely on configuration values that are updated without recalculating the epoch operations, leaving stale data. An attacker could potentially exploit this to obtain incorrect rewards or borrow limits.

defsec Follow

Originally disclosed on Code4rena

Submitted by defsec

During the code review, It has been observed that reward calculation has been done with execute_epoch_operations function. However, the config are stored in the storage. When the anc_purchase_factor is updated by the owner, the execute_epoch_operations is not called.

Proof of Concept

  1. Navigate to the following contract.
https:
  1. Config is updated with update_config function.
    if let Some(threshold_deposit_rate) = threshold_deposit_rate {
        config.threshold_deposit_rate = threshold_deposit_rate;
    }

    if let Some(buffer_distribution_factor) = buffer_distribution_factor {
        config.buffer_distribution_factor = buffer_distribution_factor;
    }

    if let Some(anc_purchase_factor) = anc_purchase_factor {
        config.anc_purchase_factor = anc_purchase_factor;
    }

    if let Some(target_deposit_rate) = target_deposit_rate {
        config.target_deposit_rate = target_deposit_rate;
    }

    if let Some(epoch_period) = epoch_period {
        config.epoch_period = epoch_period;
    }

    if let Some(price_timeframe) = price_timeframe {
        config.price_timeframe = price_timeframe;
    }
  1. After the update, execute_epoch_operations function is not called. That will cause to out-of-date data.

Recommended Mitigation Steps

Consider calling execute_epoch_operations function after config update.

Alex the Entreprenerd (triage) commented:

Confirmed Lack of validation.

Albert Chon (judge) commented:

Good catch.


The original report as published on Code4rena, by defsec. 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 update_config function does not trigger a recalculation of epoch-dependent values, so the stored configuration and the computed state become inconsistent.

Impact

The stale data could lead to incorrect reward or borrow limit calculations, potentially allowing users to receive more rewards or borrow more than intended.

What the attacker needed

Owner updates config

The fix

The execute_epoch_operations function should be called after updating the configuration.

How it was found

  1. Navigate to the contract.
  2. Update the configuration using the update_config function.
  3. Observe that execute_epoch_operations is not called afterwards.

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 changing settings doesn't immediately update the calculations that depend on them. So the system keeps using old numbers until the next scheduled update, which could give someone wrong rewards or borrowing limits.

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 defsec

View all

16 more disclosed reports, best first.

More from Anchor contest

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.