_distributeProfit will use the stale globalIC.swingTraderCollateralDeficit()/swingTraderCollateralRatio() , which will result in incorrect profit distribution
The profit distribution function reads stale collateral deficit and ratio values from globalIC because the contract does not synchronise globalIC before calling handleProfit. This causes the swing trader's collateral to be understated, making the deficit appear larger and leading to an incorrect split of profits between liquidity providers and the swing trader.
Submitted by cccz
The \_distributeProfit() (called by handleProfit()) will use globalIC.swingTraderCollateralDeficit()/swingTraderCollateralRatio() when distributing profits, and the latest globalIC.swingTraderCollateralDeficit()/swingTraderCollateralRatio() needs to be used to ensure that profits are distributed correctly.
uint256 globalSwingTraderDeficit = (maltDataLab.maltToRewardDecimals(
globalIC.swingTraderCollateralDeficit()
) * maltDataLab.priceTarget()) / (10**collateralToken.decimals());
// this is already in collateralToken.decimals()
uint256 lpCut;
uint256 swingTraderCut;
if (globalSwingTraderDeficit == 0) {
lpCut = distributeCut;
} else {
uint256 runwayDeficit = rewardThrottle.runwayDeficit();
if (runwayDeficit == 0) {
swingTraderCut = distributeCut;
} else {
uint256 totalDeficit = runwayDeficit + globalSwingTraderDeficit;
However, the two calls to handleProfit in the contract do not call syncGlobalCollateral to synchronize the data in globalIC.
syncGlobalCollateral will use the data in getCollateralizedMalt(), including the collateralToken balance in overflowPool/swingTraderManager/liquidityExtension and the malt balance in swingTraderManager.
function syncGlobalCollateral() public onlyActive {
globalIC.sync(getCollateralizedMalt());
}
function getCollateralizedMalt() public view returns (PoolCollateral memory) {
uint256 target = maltDataLab.priceTarget(); // 是否选用 getActualPriceTarget()
uint256 unity = 10**collateralToken.decimals();
// Convert all balances to be denominated in units of Malt target price
uint256 overflowBalance = maltDataLab.rewardToMaltDecimals((collateralToken.balanceOf(
address(overflowPool)
) * unity) / target);
uint256 liquidityExtensionBalance = (collateralToken.balanceOf(
address(liquidityExtension)
) * unity) / target;
(
uint256 swingTraderMaltBalance,
uint256 swingTraderBalance
) = swingTraderManager.getTokenBalances();
swingTraderBalance = (swingTraderBalance * unity) / target;
- Before handleProfit is called by StabilizerNode.stabilize.
profitDistributor.handleProfit(rewards);
a. checkAuctionFinalization is called to liquidityExtension.allocateBurnBudget, which transfers the collateralToken from liquidityExtension to swingTrader. The increase of collateralToken in swingTrader will make the data in globalIC stale.
function allocateBurnBudget(uint256 amount)
external
onlyRoleMalt(AUCTION_ROLE, "Must have auction privs")
onlyActive
returns (uint256 purchased)
{
// Send the burnable amount to the swing trader so it can be used to burn more malt if required
require(
collateralToken.balanceOf(address(this)) >= amount,
"LE: Insufficient balance"
);
collateralToken.safeTransfer(address(swingTrader), amount);
emit AllocateBurnBudget(amount);
}
b. swingTraderManager.sellMalt will exchange malt for collateralToken, and the increase of collateralToken in swingTrader will also make the data in globalIC stale.
uint256 swingAmount = swingTraderManager.sellMalt(tradeSize);
- Before SwingTrader.sellMalt is called to handleProfit.
function _handleProfitDistribution(uint256 profit) internal virtual {
if (profit != 0) {
collateralToken.safeTransfer(address(profitDistributor), profit);
profitDistributor.handleProfit(profit);
}
}
a. dexHandler.sellMalt will exchange malt for collateralToken, and the increase of collateralToken in swingTrader will also make the data in globalIC stale.
malt.safeTransfer(address(dexHandler), maxAmount);
uint256 rewards = dexHandler.sellMalt(maxAmount, 10000);
One obvious effect is that as the collateralToken in swingTrader increases, collateral.swingTrade will be smaller than it actually is, and the result of globalIC.swingTraderCollateralDeficit() will be larger than it should be.
function swingTraderCollateralDeficit() public view returns (uint256) {
// Note that collateral.swingTrader is already denominated in malt.decimals()
uint256 maltSupply = malt.totalSupply();
uint256 collateral = collateral.swingTrader; // gas
if (collateral >= maltSupply) {
return 0;
}
return maltSupply - collateral;
}
thus making lpCut larger:
uint256 globalSwingTraderDeficit = (maltDataLab.maltToRewardDecimals(
globalIC.swingTraderCollateralDeficit()
) * maltDataLab.priceTarget()) / (10**collateralToken.decimals());
// this is already in collateralToken.decimals()
uint256 lpCut;
uint256 swingTraderCut;
if (globalSwingTraderDeficit == 0) {
lpCut = distributeCut;
} else {
uint256 runwayDeficit = rewardThrottle.runwayDeficit();
if (runwayDeficit == 0) {
swingTraderCut = distributeCut;
} else {
uint256 totalDeficit = runwayDeficit + globalSwingTraderDeficit;
uint256 globalSwingTraderRatio = maltDataLab.maltToRewardDecimals(
globalIC.swingTraderCollateralRatio()
);
// Already in collateralToken.decimals
uint256 poolSwingTraderRatio = impliedCollateralService
.swingTraderCollateralRatio();
if (poolSwingTraderRatio < globalSwingTraderRatio) {
swingTraderCut = (distributeCut * swingTraderPreferenceBps) / 10000;
lpCut = distributeCut - swingTraderCut;
} else {
lpCut =
(((distributeCut * runwayDeficit) / totalDeficit) *
(10000 - lpThrottleBps)) /
10000;
Proof of Concept
Recommended Mitigation Steps
Call syncGlobalCollateral to synchronize the data in globalIC before calling handleProfit.
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
Impact
Profits may be distributed incorrectly, with liquidity providers receiving a larger cut than they should because the stale deficit makes the swing trader appear more undercollateralised than it is.
What the attacker needed
HandleProfit is called after collateral changes
The fix
Call syncGlobalCollateral to synchronise globalIC before calling handleProfit.
How it was found
- Before handleProfit is called by StabilizerNode.stabilize, checkAuctionFinalization calls allocateBurnBudget, which transfers collateral tokens to the swing trader and makes globalIC stale.
- Also before handleProfit, swingTraderManager.sellMalt exchanges malt for collateral tokens, increasing the swing trader's collateral and further staling globalIC.
- Before SwingTrader.sellMalt calls handleProfit, dexHandler.sellMalt exchanges malt for collateral tokens, again increasing the swing trader's collateral and staling globalIC.
- handleProfit then reads the stale globalIC.swingTraderCollateralDeficit() and globalIC.swingTraderCollateralRatio(), producing an inflated deficit and an incorrect lpCut.
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 smart contract keeps a cached summary of how much collateral the swing trader holds. When that collateral changes, the cache is not updated before profits are split, so the contract uses old numbers. As a result, the wrong amount of profit goes to each group.
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.