Randomness can be exploited in some cases
The contract uses the same random seed to generate both the normal balls and the bonus ball, so when the maximum numbers are equal the bonus ball is always one of the normal balls. This reduces the effective number of combinations and lets an attacker buy all possible tickets to guarantee a profit.
Submitted by touristS, also found by hgrano
https://github.com/code-423n4/2025-11-megapot/blob/main/contracts/ScaledEntropyProvider.sol#L251
Finding description and impact
The contract currently generates both normal balls and the bonus ball using the same seed derived from the entropy source.
https://github.com/code-423n4/2025-11-megapot/blob/main/contracts/ScaledEntropyProvider.sol#L251
function entropyCallback(uint64 sequence, address /*provider*/, bytes32 randomNumber) internal override {
PendingRequest memory req = pending[sequence];
if (req.callback == address(0)) revert UnknownSequence();
delete pending[sequence];
@> uint256[][] memory scaledRandomNumbers = _getScaledRandomness(randomNumber, req.setRequests);
(bool success, ) = req.callback.call(abi.encodeWithSelector(req.selector, sequence, scaledRandomNumbers, req.context));
if (!success) revert CallbackFailed(req.selector);
emit EntropyFulfilled(sequence, randomNumber);
emit ScaledRandomnessDelivered(sequence, req.callback, scaledRandomNumbers.length);
}
However, when normalballMax and bonusballMax are equal, this results in overlapping randomness - the bonus ball is always included within the normal balls.
This breaks the assumption of truly randomness. As a result, users can statistically exploit the predictable overlap to gain a higher probability of winning.
For example, when
prizePool=(2,992,626 ~ 3,092,380),lpEdgeTarget = 30%,normalballMax = 30, The computedbonusballMaxbecomes 30.- Expected odds: 1 in
C(30, 5) * C(30, 1)≈ 1 in 4,275,180 - Exploited odds: 1 in
C(30, 5) * C(5, 1)≈ 1 in 712,530
This means users’ odds of winning increase roughly (bonusballMax / 5) times.
Therefore, users can deterministically exploit draws by purchasing all combinations(712,530) and guaranteeing a positive return including jackpot.
Recommended mitigation steps
Use a different seed for the bonus ball when generating random numbers.
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 } 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 () => {
it("demonstrates bonus ball is always included in normal balls when normalBallMax == bonusballMax", async () => {
const deployer = new DeployHelper(owner.wallet);
const fisherYatesTester = await deployer.deployFisherYatesWithRejectionTester();
const normalBallMax = 30;
const bonusballMax = 30;
const seed = BigInt(12345);
// let's test with the same seed:
console.log(`\n --- test with the same seed ---`);
const normalsSame = await fisherYatesTester.draw(BigInt(1), BigInt(normalBallMax), BigInt(5), seed);
const bonusSame = await fisherYatesTester.draw(BigInt(1), BigInt(bonusballMax), BigInt(1), seed);
const bonusValue = bonusSame[0];
console.log(`Normal balls: [${normalsSame.join(", ")}]`);
console.log(`Bonus ball: ${bonusValue}`);
});
});
});
Result:
--- test with the same seed ---
Normal balls: [30, 18, 24, 3, 19]
Bonus ball: 30
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 same random seed is reused for both the normal ball draw and the bonus ball draw, causing the bonus ball to be a subset of the normal balls when the maximum values match.
Impact
An attacker could buy all possible ticket combinations and guarantee a positive return, including the jackpot, when the maximum numbers are equal.
What the attacker needed
NormalballMax equals bonusballMax; attacker can buy all combinations
The fix
Use a different seed for the bonus ball when generating random numbers.
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 lottery uses random numbers to pick winning tickets. Here, the same random seed is used for two different parts of the draw, so the bonus number is not independent. That makes the winning odds much better than they should be, and someone can buy every possible ticket to win for sure.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.