Skip to content
Business logic Audit finding Intermediate

Emergency unlocking penalty makes long duration positions economically advantageous

The farm-manager contract applies a fixed 2% emergency unlock penalty regardless of how long a position was locked, while longer locks earn much higher reward multipliers. An attacker could lock for the maximum duration to earn boosted rewards, then emergency-unlock cheaply to regain liquidity, undermining the lockup mechanism.

Lambda Follow with Evo

Originally disclosed on Code4rena

Submitted by Lambda, also found by Evo

The farm-manager contract has a static emergency unlock penalty (initialized to 2% in the deployment file deploy_mantra_dex.sh) regardless of the position’s unlocking duration. However, longer unlocking durations provide significantly higher reward weight multipliers (up to 16x for 1 year lockups). This creates an economic imbalance where users are incentivized to:

  1. Create positions with maximum unlocking duration to get the highest weight multiplier (up to 16x).
  2. Emergency unlock when they want liquidity, only paying the fixed 2% penalty.

This undermines the intended lockup mechanism since users can get much higher rewards while maintaining effective liquidity through emergency unlocks. The impact is that the protocol’s liquidity stability guarantees are weakened, as users are economically incentivized to game the system rather than maintain their intended lock periods.

Moreover, it can be profitable to open a huge position 1 second before an epoch ends and withdraw immediately (in the new epoch), which hurts real users of the system.

Proof of Concept

The key components of this issue are:

  1. Emergency unlock penalty is static, set during initialization here.
  2. Weight calculation increases significantly with lock duration here.

For example:

#[test]
fn test_calculate_weight() {
    // 1 day lockup = 1x multiplier
    let weight = calculate_weight(&coin(100, "uwhale"), 86400u64).unwrap();
    assert_eq!(weight, Uint128::new(100));

    // 1 year lockup = ~16x multiplier
    let weight = calculate_weight(&coin(100, "uwhale"), 31556926).unwrap();
    assert_eq!(weight, Uint128::new(1599));
}

Consider this scenario:

  1. User creates position with 1000 tokens and 1 year lock, getting ~16x weight (16000).
  2. After collecting boosted rewards, user emergency exits paying only 2% (20 tokens).
  3. Net result: User got 16x rewards while maintaining effective liquidity with minimal penalty.

This makes it economically optimal to always choose maximum duration and emergency unlock when needed, defeating the purpose of tiered lockup periods.

Recommended mitigation steps

The emergency unlock penalty should scale with:

  1. Remaining lock duration.
  2. Position’s weight multiplier.

Suggested formula:

emergency_penalty = base_penalty * (remaining_duration / total_duration) * (position_weight / base_weight)

This would make emergency unlocks proportionally expensive for positions with higher weights and longer remaining durations, better aligning incentives with the protocol’s goals.

Alternative mitigations:

  • Cap maximum unlock duration to reduce exploitability.
  • Increase base emergency unlock penalty.
  • Add minimum hold period before emergency unlocks are allowed.

The key is ensuring the penalty properly counterbalances the increased rewards from longer lock periods.

jvr0x (MANTRA) confirmed and commented:

This is a valid concern and the team is aware of that. However, the way the team intends to instantiate the farm manager at the beginning is to set min and max unlock periods to 1 day, so in that case all positions would be the same.

Will probably address this issue once/if the team decides to increase the constraint.


The original report as published on Code4rena, by Lambda. 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 emergency unlock penalty is a static value set at initialisation and does not scale with remaining lock duration or the position's weight multiplier.

Impact

The protocol's liquidity stability guarantees are weakened because users are economically incentivised to game the system, and opening a large position just before an epoch ends could hurt real users.

What the attacker needed

Ability to create a farm position; ability to emergency unlock

The fix

The emergency unlock penalty should scale with remaining lock duration and the position's weight multiplier, or alternatively the maximum duration should be capped, the base penalty raised, or a minimum hold period added.

How it was found

  1. Create a position with the maximum unlocking duration to get the highest weight multiplier.
  2. Collect the boosted rewards over time.
  3. Emergency unlock the position, paying only the fixed penalty.

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 staking system rewards people more if they promise to keep their tokens locked for longer. But anyone can break that promise early by paying a small fixed fee, so people can take the big reward and still get their tokens back cheaply. That makes the long-lock promise meaningless.

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 Lambda

View all

64 more disclosed reports, best first.

More from MANTRA DEX

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.