Incorrect ticket price reference in JackpotBridgeManager causes user overpayment after price updates
The JackpotBridgeManager fetches the current global ticket price instead of the price fixed for the active drawing, so after a price increase users overpay and excess funds are locked in the contract, while a price decrease causes a denial of service due to insufficient approval.
avoloder Follow with 0xDemon, 0xHarryBarz and 36 others
Originally disclosed on Code4rena
Submitted by avoloder, also found by 0xDemon, 0xHarryBarz, 0xIconart, 0xnija, 0xvd, Agontuk, AlexCzm, AnantaDeva, Bbash, codertjay, dantehrani, Dulgiq, ephraimvvs, gkrastenov, glorbo, grigorovv, h2134, ht111111, InvarianteX, jaykosai, jerry0422, Nyxaris, prk0, rokinot, Samueltroydomi, saraswati, SarveshLimaye, SavantChat, ScarletFir, securehash1, stakog, threadmodeling, trailongoswami, Varun_05, vesko210, y4y, zcai, and Ziusz
Finding description and impact
In the Jackpot.sol contract, several parameters define each drawing (such as ticketPrice, bonusBall, etc.). These parameters are set at the beginning of a drawing and remain immutable for its duration. Any updates made by governance or an admin only take effect in subsequent drawings; the parameters of the current drawing are never affected.
Critical Timing Considerations:
- Drawing Parameter Isolation: All drawing parameters (ticketPrice, normalBallMax, bonusballMax, referralWinShare) are frozen when the drawing is initialized
- Mid-Drawing Safety: Global parameter changes during active drawings do NOT affect current ticket purchases
- Next Drawing Impact: All parameter changes only take effect in the next drawing parameterization
This finding also addresses the following guiding question:
Can admin changes (e.g., ticketPrice, normalBallMax, fees) made mid-drawing create inconsistent states or violate expectations for players/LPs?
JackpotBridgeManager is a cross-chain bridge that enables ticket purchases and winnings claims across different blockchains. It acts as a custodian and defines the following flow for ticket purchases:
- The user initiates a ticket purchase through the JackpotBridgeManager, providing all required information.
- The JackpotBridgeManager fetches the current single-ticket price and calculates a total amount based on the number of tickets user wants. It then pulls the corresponding funds from the user.
- Afterwards, It approves the Jackpot contract to spend the same amount, allowing the Jackpot contract to pull the funds when needed.
- The JackpotBridgeManager calls the buyTickets function on the Jackpot contract to execute the purchase.
- The Jackpot contract pulls the required funds from the JackpotBridgeManager to complete the transaction.
The problem is that the JackpotBridgeManager fetches the current ticket price defined in the Jackpot contract and not the ticket price of an actual drawing. This leads to two scenarios if the ticket price is updated:
- Price Increase
If the ticket price is increased after a drawing has started, users who purchase tickets through the JackpotBridgeManager will overpay, as it fetches the latest global ticket price rather than the price fixed for the current drawing. The excess funds instead remain locked inside the JackpotBridgeManager contract.
- Price decrease
If the ticket price is decreased after a drawing has started, it would result in a complete denial of service (DoS) of the manager’s buyTickets function. Because the price is lower, the manager would pull fewer funds than required for the actual purchase and, as a result, would not approve a sufficient amount for the Jackpot contract. This leads to an “insufficient approval” revert when the Jackpot contract attempts to pull the funds from the manager
Impact
Impact is High, as both likelihood and impact (Loss of funds, DoS) are High
Recommended mitigation steps
Make sure to fetch the ticket price of an actual drawing and not the latest one from the Jackpot when purchasing tickets through JackpotBridgeManager
uint256 ticketPrice = jackpot.getDrawingState(currentDrawingId).ticketPrice;
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,
DrawingState,
JackpotSystemFixture,
RelayTxData,
Ticket,
} from "@utils/types";
import { deployJackpotSystem } from "@utils/test/jackpotFixture";
import {
calculatePackedTicket,
calculateTicketId,
generateClaimTicketSignature,
generateClaimWinningsSignature,
} from "@utils/protocolUtils";
import { ADDRESS_ZERO } from "@utils/constants";
import {
takeSnapshot,
SnapshotRestorer,
time,
} from "@nomicfoundation/hardhat-toolbox/network-helpers";
const expect = getWaffleExpect();
describe("C4", () => {
let owner: 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;
beforeEach(async () => {
[
owner,
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));
await usdcMock
.connect(owner.wallet)
.approve(jackpot.getAddress(), usdc(1000000));
await jackpot.connect(owner.wallet).lpDeposit(usdc(1000000));
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 subjectTickets: Ticket[];
let subjectRecipient: Address;
let subjectReferrers: Address[];
let subjectReferralSplitBps: bigint[];
let subjectSource: string;
let subjectCaller: Account;
it("charges a higher ticket price when using bridge if price is adjusted", async () => {
subjectTickets = [
{
normals: [BigInt(1), BigInt(2), BigInt(3), BigInt(4), BigInt(5)],
bonusball: BigInt(1)
} as Ticket,
{
normals: [BigInt(2), BigInt(4), BigInt(6), BigInt(7), BigInt(11)],
bonusball: BigInt(3)
} as Ticket,
];
await usdcMock.connect(owner.wallet).transfer(buyerOne.address, usdc(1000));
// Approval and ticket setup
await usdcMock.connect(buyerOne.wallet).approve(jackpotBridgeManager.getAddress(), usdc(10));
subjectRecipient = buyerOne.address;
subjectReferrers = [referrerOne.address, referrerTwo.address, referrerThree.address];
subjectReferralSplitBps = [ether(.3333), ether(.3333), ether(.3334)];
subjectSource = ethers.encodeBytes32String("test");
subjectCaller = buyerOne;
// Verify current ticket price
const actualDrawingState: DrawingState = await jackpot.getDrawingState(1);
const actualDrawingTicketPrice = actualDrawingState.ticketPrice;
const actualGlobalTicketPrice = await jackpot.ticketPrice();
expect(actualDrawingTicketPrice).to.eq(usdc(1));
expect(actualGlobalTicketPrice).to.eq(usdc(1));
// Change global ticket price
await jackpot.setTicketPrice(usdc(3));
const newGlobalTicketPrice = await jackpot.ticketPrice();
expect(newGlobalTicketPrice).to.eq(usdc(3));
const jackpotBridgeManagerBalanceBefore = await usdcMock.balanceOf(jackpotBridgeManager.getAddress());
const jackpotBalanceBefore = await usdcMock.balanceOf(jackpot.getAddress());
await jackpotBridgeManager.connect(buyerOne.wallet).buyTickets(subjectTickets,
subjectRecipient,
subjectReferrers,
subjectReferralSplitBps,
subjectSource);
const jackpotBridgeManagerBalanceAfter = await usdcMock.balanceOf(jackpotBridgeManager.getAddress());
const jackpotBalanceAfter = await usdcMock.balanceOf(jackpot.getAddress());
// Balance of the jackpot contract only increased by the actual drawing ticket price multiplied by the number of bought tickets
expect(jackpotBalanceAfter).to.eq(jackpotBalanceBefore + BigInt(subjectTickets.length) * actualDrawingTicketPrice);
// JackpotBridgeManager charges tickets with the newly updated ticket price and not with the price of the actual drawing
// Here we can see that the excess funds are trapped in the contract
expect(jackpotBridgeManagerBalanceAfter).to.eq(BigInt(subjectTickets.length) * newGlobalTicketPrice - BigInt(subjectTickets.length) * actualDrawingTicketPrice);
// JackpotBridgeManager should've forwarded everything
expect(jackpotBridgeManagerBalanceAfter).to.not.eq(jackpotBridgeManagerBalanceBefore);
});
});
});
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
Users overpay and excess funds are locked in the bridge manager when the price increases, while a price decrease causes a complete denial of service of the buyTickets function.
What the attacker needed
Admin updates global ticket price mid-drawing; user purchases via JackpotBridgeManager
The fix
The bridge manager should fetch the ticket price from the current drawing state instead of the global ticket price.
How it was found
- A drawing is initialised with a ticket price of 1 USDC.
- The global ticket price is updated to 3 USDC.
- A user calls buyTickets on the JackpotBridgeManager for two tickets.
- The manager pulls 6 USDC from the user but only 2 USDC are used by the Jackpot contract, leaving 4 USDC stuck in the manager.
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 for buying lottery tickets on another blockchain uses the wrong price when a ticket price changes. If the price goes up, users pay too much and the extra money gets stuck; if it goes down, the purchase fails entirely.
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.