Misuse of AMM model on minting Synth (resubmit to add more detail)
The Pool contract calculates the amount of Synth to mint using the same AMM formula as a token swap, but minting does not reduce the pool's token balance. An attacker could repeatedly mint Synth at a favourable rate, extracting value and making the synthetic asset hard to keep pegged.
Submitted by jonah1005
Pool calculates the amount to be minted based on token_amount and sparta_amount of the Pool. However, since token_amount in the pool would not decrease when users mint Synth, it’s always cheaper to mint synth than swap the tokens.
The synthetics would be really hard to be on peg. Or, there would be a flash-loan attacker to win all the arbitrage space.
In Pool’s mint synth, The synth amount is calculated at L:232
uint output = iUTILS(_DAO().UTILS()).calcSwapOutput(_actualInputBase, baseAmount, tokenAmount);
which is the same as swapping base to token at L:287
uint256 _X = baseAmount;
uint256 _Y = tokenAmount;
_y = iUTILS(_DAO().UTILS()).calcSwapOutput(_x, _X, _Y); // Calc TOKEN output
However, while swapping tokens decrease pool’s token, mint just mint it out of the air.
Here’s a POC: Swap sparta to token for ten times
for i in range(10):
amount = 10 * 10**18
transfer_amount = int(amount/10)
base.functions.transfer(token_pool.address, transfer_amount).transact()
token_pool.functions.swapTo(token.address, user).transact()
Mint Synth for ten times
for i in range(10):
amount = 10 * 10**18
transfer_amount = int(amount/10)
base.functions.transfer(token_pool.address, transfer_amount).transact()
token_pool.functions.mintSynth(token_synth.address, user).transact()
The Pool was initialized with 10000:10000 in both cases. While the first case(swap token) gets 4744.4059 and the second case gets 6223.758.
The debt should be considered in the AMM pool so I recommend to maintain a debt variable in the Pool and use tokenAmount - debt when the Pool calculates the token price. Here’s some idea of it:
uint256 public debt;
function _tokenAmount() returns (uint256) {
return tokenAmount - debt;
}
// Swap SPARTA for Synths
function mintSynth(address synthOut, address member) external returns(uint outputAmount, uint fee) {
require(iSYNTHFACTORY(_DAO().SYNTHFACTORY()).isSynth(synthOut) == true, "!synth"); // Must be a valid Synth
uint256 _actualInputBase = _getAddedBaseAmount(); // Get received SPARTA amount
// Use tokenAmount - debt to calculate the value
uint output = iUTILS(_DAO().UTILS()).calcSwapOutput(_actualInputBase, baseAmount, _tokenAmount()); // Calculate value of swapping SPARTA to the relevant underlying TOKEN
// increment the debt
debt += output
uint _liquidityUnits = iUTILS(_DAO().UTILS()).calcLiquidityUnitsAsym(_actualInputBase, address(this)); // Calculate LP tokens to be minted
_incrementPoolBalances(_actualInputBase, 0); // Update recorded SPARTA amount
uint _fee = iUTILS(_DAO().UTILS()).calcSwapFee(_actualInputBase, baseAmount, tokenAmount); // Calc slip fee in TOKEN
fee = iUTILS(_DAO().UTILS()).calcSpotValueInBase(TOKEN, _fee); // Convert TOKEN fee to SPARTA
_mint(synthOut, _liquidityUnits); // Mint the LP tokens directly to the Synth contract to hold
iSYNTH(synthOut).mintSynth(member, output); // Mint the Synth tokens directly to the user
_addPoolMetrics(fee); // Add slip fee to the revenue metrics
emit MintSynth(member, BASE, _actualInputBase, TOKEN, outputAmount);
return (output, fee);
}
verifyfirst (Spartan) confirmed:
We agree with the issue submitted, discussions are already in progress around ensuring the mint rate considers the floating debt. Potential high risk, however, hard to create a scenario to prove this.
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 minting logic reuses the swap output formula without accounting for the debt created by newly minted Synth, so the pool's token balance does not reflect the increased supply.
Impact
An attacker could repeatedly mint Synth at a favourable rate, extracting value and making the synthetic asset hard to keep pegged; the project confirmed the risk but noted it was hard to create a scenario to prove it.
What the attacker needed
Access to the Pool contract; SPARTA tokens to deposit
The fix
The project should maintain a debt variable in the Pool and use tokenAmount minus debt when calculating the token price for minting.
How it was found
- Transfer SPARTA to the pool and call swapTo to swap for the token, repeating ten times.
- Transfer SPARTA to the pool and call mintSynth to mint Synth, repeating ten times.
- Compare the total token or Synth received in each case.
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 liquidity pool uses a formula to price swaps: the more of one token you take out, the more expensive it gets. Here, minting a synthetic token used the same formula but did not reduce the pool's token balance, so the price never went up. An attacker could keep minting at the cheap initial price and sell the synthetic tokens for a profit.
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.