Positions that are not eligible for rewards will affect the reward income of eligible positions
The reward calculation divides by the pool's total liquidity time weight, including positions that are not eligible for rewards, so eligible positions receive less than the intended weekly reward. An attacker could add ineligible liquidity to dilute rewards for legitimate participants.
Submitted by kutugu, also found by sces60107 and Banditx0x (1, 2)
Lines of code
https://github.com/code-423n4/2023-10-canto/blob/40edbe0c9558b478c84336aaad9b9626e5d99f34/canto_ambient/contracts/mixins/LiquidityMining.sol#L181 https://github.com/code-423n4/2023-10-canto/blob/40edbe0c9558b478c84336aaad9b9626e5d99f34/canto_ambient/contracts/mixins/LiquidityMining.sol#L188 https://github.com/code-423n4/2023-10-canto/blob/40edbe0c9558b478c84336aaad9b9626e5d99f34/canto_ambient/contracts/mixins/LiquidityMining.sol#L48
Impact
When calculating reward distribution, the contract uses the current position’s liquidity time weight divided by the total liquidity time weight of the pool, instead of the total liquidity time weight of the pool that meets the reward conditions. This means that if there is a large amount of liquidity in the pool that is not eligible for rewards, the total weekly reward distribution will be much less than the rewardPerWeek, which should not be expected.
Proof of Concept
diff --git a/canto_ambient/test_canto/TestLiquidityMining.js b/canto_ambient/test_canto/TestLiquidityMining.js
index bd21a32..617b070 100644
--- a/canto_ambient/test_canto/TestLiquidityMining.js
+++ b/canto_ambient/test_canto/TestLiquidityMining.js
@@ -32,7 +32,7 @@ chai.use(solidity);
describe("Liquidity Mining Tests", function () {
it("deploy contracts and init pool", async function () {
- const [owner] = await ethers.getSigners();
+ const [owner, others] = await ethers.getSigners();
////////////////////////////////////////////////
// DEPLOY AND MINT cNOTE and USDC
@@ -49,6 +49,14 @@ describe("Liquidity Mining Tests", function () {
owner.address,
ethers.utils.parseUnits("1000000", 6)
);
+ await cNOTE.deposit(
+ others.address,
+ ethers.utils.parseEther("1000000")
+ );
+ await USDC.deposit(
+ others.address,
+ ethers.utils.parseUnits("1000000", 6)
+ );
////////////////////////////////////////////////
// DEPLOY DEX CONTRACT AND ALL PROXIES
@@ -145,6 +153,17 @@ describe("Liquidity Mining Tests", function () {
);
await approveCNOTE.wait();
+ approveUSDC = await USDC.connect(others).approve(
+ dex.address,
+ BigNumber.from(10).pow(36)
+ );
+ await approveUSDC.wait();
+ approveCNOTE = await cNOTE.connect(others).approve(
+ dex.address,
+ BigNumber.from(10).pow(36)
+ );
+ await approveCNOTE.wait();
+
/*
/ 2. set new pool liquidity (amount to lock up for new pool)
/ params = [code, liq]
@@ -222,6 +241,40 @@ describe("Liquidity Mining Tests", function () {
});
await tx.wait();
+ mintConcentratedLiqCmd = abi.encode(
+ [
+ "uint8",
+ "address",
+ "address",
+ "uint256",
+ "int24",
+ "int24",
+ "uint128",
+ "uint128",
+ "uint128",
+ "uint8",
+ "address",
+ ],
+ [
+ 11, // code (mint concentrated liquidity in base token liq)
+ cNOTE.address, // base token
+ USDC.address, // quote token
+ 36000, // poolIDX
+ currentTick - 5, // tickLower
+ currentTick + 5, // tickUpper
+ BigNumber.from("100000000000000000000"), // amount of base token to send
+ BigNumber.from("16602069666338596454400000"), // min price
+ BigNumber.from("20291418481080506777600000"), // max price
+ 0, // reserve flag
+ ZERO_ADDR, // lp conduit address (0 if not using)
+ ]
+ );
+ tx = await dex.connect(others).userCmd(2, mintConcentratedLiqCmd, {
+ gasLimit: 6000000,
+ value: ethers.utils.parseUnits("10", "ether"),
+ });
+ await tx.wait();
+
////////////////////////////////////////////////
// SAMPLE SWAP TEST (swaps 2 USDC for cNOTE)
////////////////////////////////////////////////
@@ -300,9 +353,9 @@ describe("Liquidity Mining Tests", function () {
const dexBalAfter = await ethers.provider.getBalance(dex.address);
const ownerBalAfter = await ethers.provider.getBalance(owner.address);
- // expect dex to have 2 less CANTO since we claimed for 2 weeks worth of rewards
+ // @audit Expect to have less CANTO rewards due to additional and not eligible for rewards liquidity
expect(dexBalBefore.sub(dexBalAfter)).to.equal(
- BigNumber.from("2000000000000000000")
+ BigNumber.from("501412401683494542")
);
});
});
In the pool, there is only one position that meets the reward conditions, and there is also one position that does not meet the conditions.
According to common sense, weekly rewards should be distributed to the only position that meets the reward conditions based on rewardPerWeek. However, in reality, you can see that the rewards that should be distributed every week have been reduced to 1/4 due to the ineligible position.
Tools Used
Hardhat
Recommended Mitigation Steps
Since the reward distribution of concentrated type rewards is conditionally restricted, the conditional restrictions should also be taken into account when calculating the total weight, rather than directly counting the total amount of liquidity.
Assessed type
Context
OpenCoreCH (Canto) disputed and commented via duplicate Issue #94:
Responding to this and #98 here:
The warden seems to assume that
curve.concLiq_is influenced by the width of a position, which is not the case. If someone creates a position with range [0, 1000] and liq. 100 or [480, 520] with liq. 100,curve.concLiq_will be 100 in both cases when the active tick is 500 (and not 0.1 & 2.5, which seems to be the assumption of the warden). This can be seen inTradeMatcher,LevelBook, andLiquidityMath. The logic is not that simple, but the high level summary is that we store for every tick the liquidity (lots) of positions that have the lower / upper tick here (lvl.bidLots_,lvl.askLots_). When a tick is then crossed, the whole liquidity is added or removed fromcurve.concLiq_.However, it can also be easily verified by looking at our test. If the assumption of the warden were true, the user in the test (that has a position with width 30) would not receive 100% of the rewards, but only
1/30. BecauseconcLiq_works this way, the recommendation of the warden would break the system.Something that is true is point 1 from #98. If a user has a very narrow position (less than 21 ticks), it still contributes to
curve.concLiq_.
TL;DR - in some cases reward amounts may be miscalculated, resulting in lower than expected reward amounts.
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 reward calculation uses the total liquidity time weight of the entire pool instead of only the weight of positions that meet the reward conditions.
Impact
Eligible positions could receive significantly less than the intended weekly reward, and the total distributed rewards may be far below the configured amount.
What the attacker needed
A liquidity pool with reward mechanism; ability to add concentrated liquidity positions
The fix
The reward calculation should account for the conditional restrictions on concentrated liquidity rewards when computing the total weight, rather than using the total pool liquidity.
How it was found
- Deploy the contracts and initialise the pool.
- Add a concentrated liquidity position that does not meet the reward conditions.
- Add a position that meets the reward conditions.
- Claim rewards and observe that the payout is lower than the expected weekly reward.
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 pays rewards to people who provide liquidity. The code calculates each person's share by dividing their liquidity by the total liquidity in the pool. If some liquidity is not supposed to earn rewards but is still counted in the total, the people who should earn rewards get a smaller share.
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.