Skip to content
Business logic Audit finding Intermediate

Makers can permanently lock JIT penalty revenue from the protocol treasury

The JIT penalty applied when makers withdraw shortly after adding liquidity reduces the amount returned to the maker, but the penalty amount is never tracked or transferred to the protocol treasury. As a result, the penalty remains as idle ERC20 tokens in the contract with no function to claim or sweep them.

0x37 Follow with HeckerTrieuTien, Motomoto and 7 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2025-09-ammplify-judging/issues/482

Found by

0x37, HeckerTrieuTien, Motomoto, Slayer, anonymousjoe, axelot, ezsia, khaye26, roshark, t.aksoy

Summary

Missing accounting and withdrawal for JIT penalties will cause a permanent lockup of protocol revenue for the protocol treasury as makers who withdraw shortly after adding liquidity will incur a penalty that remains as idle ERC20 on the contract with no path to claim or route it.

Root Cause

In src/facets/Maker.sol, the code applies FeeLib.applyJITPenalties to reduce the amounts returned to the maker, but never tracks or routes the difference (the penalty) to any recipient (e.g., treasury). The reduced amounts are sent to the user, and the undistributed remainder stays in the contract as idle token balance. There is no admin/treasury function to sweep or withdraw these balances.

Make a detailed explanation of the root cause of issue:

  • The penalty calculation only scales down the user’s redemption amounts and returns the reduced values; it does not emit, credit, or transfer the penalty to any accounting bucket or address.
  • Settlement uses RFTLib.settle, which sends/receives the specified deltas with the counterparty. Since the deltas already include the penalty reduction, nothing explicitly transfers the penalty to a treasury; it simply remains in the diamond contract’s balance.
  • The Admin facet exposes configuration setters (including JIT penalty config), but there is no function to sweep stray ERC20 balances or collect penalties to a treasury address.

Vulnerable path

adjustMaker applies penalty and settles reduced payout to the maker

Solidity
// src/facets/Maker.sol (excerpt from adjustMaker)
} else {
    require(data.yBalance < 0);
    PoolWalker.settle(pInfo, asset.lowTick, asset.highTick, data);
    uint256 removedX = uint256(-data.xBalance);
    uint256 removedY = uint256(-data.yBalance);
    (removedX, removedY) = FeeLib.applyJITPenalties(asset, removedX, removedY);
    balances[0] = -int256(removedX);
    balances[1] = -int256(removedY);
    RFTLib.settle(msg.sender, tokens, balances, rftData);
}

The user’s withdrawable amounts are reduced by penalty. Only the reduced amounts are sent out; the penalty difference is not transferred anywhere and stays in the contract.

removeMaker follows the same pattern

Solidity
// src/facets/Maker.sol (excerpt from removeMaker)
removedX = uint256(-data.xBalance);
removedY = uint256(-data.yBalance);
(removedX, removedY) = FeeLib.applyJITPenalties(asset, removedX, removedY);
// ...
balances[0] = -int256(removedX);
balances[1] = -int256(removedY);
RFTLib.settle(recipient, tokens, balances, rftData);

Again, only the reduced amounts are sent to the user, with the penalty left unaccounted.

penalty math only scales down, does not route funds

Solidity
// src/Fee.sol (excerpt)
function applyJITPenalties(
    Asset storage asset,
    uint256 xBalance,
    uint256 yBalance
) internal view returns (uint256 xBalanceOut, uint256 yBalanceOut) {
    FeeStore storage store = Store.fees();
    uint128 duration = uint128(block.timestamp) - asset.timestamp;
    if (duration >= store.jitLifetime) {
        return (xBalance, yBalance);
    }
    uint256 penaltyX64 = store.jitPenaltyX64;
    xBalanceOut = FullMath.mulX64(xBalance, penaltyX64, true);
    yBalanceOut = FullMath.mulX64(yBalance, penaltyX64, true);
}

The function returns smaller xBalanceOut/yBalanceOut but does not emit or credit the difference to any beneficiary.

settlement does not forward the penalty anywhere

Solidity
// lib/Commons/src/Util/RFT.sol (excerpt)
if (change < 0) {
    TransferHelper.safeTransfer(token, payer, uint256(-change));
}
if (change > 0 && !isRFTPayer) {
    TransferHelper.safeTransferFrom(token, payer, address(this), uint256(change));
}

RFTLib.settle just enacts the provided deltas with the selected counterparty. Since the penalty has already been removed from those deltas, no funds are sent to a treasury; the penalty remains in the contract.

Explanation: There is no way for the protocol to withdraw idle balances that build up from penalties.

impact

Protocol treasury cannot claim JIT penalties; funds get stuck in the contract.

Mitigation

Preferred: Route penalties to a configured treasury address at the time of application.

Illustrative patch approach:

  1. Add a configurable treasury address.
Solidity
// src/Fee.sol
struct FeeStore {
    // ... existing fields
    address treasury; // recipient of protocol penalties
}

Discussion

sherlock-admin2

The protocol team fixed this issue in the following PRs/commits: https://github.com/itos-finance/Ammplify/pull/26/

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

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 penalty calculation only reduces the maker's payout and the reduced amount is settled, but the difference is never credited or transferred to any treasury address, and no sweep function exists.

Impact

The protocol treasury cannot claim the JIT penalty revenue, so those funds become permanently stuck in the contract.

What the attacker needed

Maker adds liquidity then withdraws within JIT lifetime

The fix

The issue was fixed by the protocol team in a pull request.

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 someone provides liquidity and then quickly removes it, the protocol charges a penalty by giving them back less than they put in. The problem is that the extra tokens kept as the penalty are not sent to the protocol's treasury or recorded anywhere; they just sit in the contract. Since there is no function to withdraw these leftover tokens, the protocol can never collect that revenue.

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 0x37

View all

79 more disclosed reports, best first.

More from Ammplify

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.