Levelcirculatingsupplyupdated not emitted during supply changes
The LevelCirculatingSupplyUpdated event is only emitted when a level is created, not when the circulating supply changes through mint, burn or migrate. Off-chain indexers and dApps relying on this event will see stale per-level supply values after the initial creation.
- Disclosed after under an hour
60525 sc insight levelcirculatingsupplyupdated not emitted during supply changes
Submitted on Nov 23rd 2025 at 19:11:24 UTC by @Rhaydden for Audit Comp | Vechain | Stargate Hayabusa
- Report ID: #60525
- Report Type: Smart Contract
- Report severity: Insight
- Target: https://github.com/immunefi-team/audit-comp-vechain-stargate-hayabusa/tree/main/packages/contracts/contracts/StargateNFT/libraries/Levels.sol
- Impacts:
Description
Finding description and impact
LevelCirculatingSupplyUpdated event is documented and exposed in IStargateNFT as being emitted “when the circulating supply of a token level is updated.” In the current implementation, the event is only emitted on level creation (addLevel) and not when circulating supply actually changes thereafter (mint, burn, migrate).
In Levels.sol, the event is emitted once inside addLevel:
emit LevelCirculatingSupplyUpdated($.MAX_LEVEL_ID, 0, _levelAndSupply.circulatingSupply);
Then all subsequent supply changes go through _incrementLevelCirculatingSupply / _decrementLevelCirculatingSupply, which call _checkpointLevelCirculatingSupply:
function _incrementLevelCirculatingSupply(...) internal {
uint208 circulatingSupply = _getCirculatingSupply($, _levelId);
_checkpointLevelCirculatingSupply($, _levelId, circulatingSupply + 1);
}
function _decrementLevelCirculatingSupply(...) internal {
uint208 circulatingSupply = _getCirculatingSupply($, _levelId);
_checkpointLevelCirculatingSupply($, _levelId, circulatingSupply - 1);
}
function _checkpointLevelCirculatingSupply(...) internal {
$.circulatingSupply[_levelId].push(Clock._clock(), _circulatingSupply);
}
As we see, no event is emitted in these paths.
Impact
Any offchain indexers and dApps relying on LevelCirculatingSupplyUpdated to track per-level supply will get incorrect values after the initial add. They’ll observe one initial “0 → initialSupply” event and then miss all later increments/decrements. The on-chain state is correct and queryable through the checkpoints (getLevelsCirculatingSupplies and getCirculatingSupplyAtBlock), and consumers could reconstruct supply from TokenMinted/TokenBurned. Albeit, the public interface and natspec promise an event-based feed which doesnt actually exist post creation.
Severity: Insight. Optimizations and Enhancements
Recommended mitigation steps
Emit LevelCirculatingSupplyUpdated whenever supply changes.
Proof of Concept
Proof of concept
Create and add the poc below to a packages/contracts/test/unit/StargateNFT/CirculatingSupplyEvents.test.ts file:
import { HardhatEthersSigner } from "@nomicfoundation/hardhat-ethers/signers";
import { expect } from "chai";
import { ethers } from "hardhat";
import { createLocalConfig } from "@repo/config/contracts/envs/local";
import {
getOrDeployContracts,
} from "../../helpers";
import {
Stargate,
StargateNFT,
TokenAuctionMock,
TokenAuctionMock__factory,
} from "../../../typechain-types";
// PoC: LevelCirculatingSupplyUpdated is not emitted when supply actually changes (mint/burn/migrate)
// but is emitted on addLevel
describe("poc: LevelCirculatingSupplyUpdated emission behavior", () => {
let deployer: HardhatEthersSigner;
let user: HardhatEthersSigner;
let otherAccounts: HardhatEthersSigner[];
let stargateNFTContract: StargateNFT;
let stargateContract: Stargate;
beforeEach(async () => {
[deployer, user, ...otherAccounts] = await ethers.getSigners();
});
describe("Mint/Burn do not emit LevelCirculatingSupplyUpdated", () => {
beforeEach(async () => {
const config = createLocalConfig();
// Allow calling mint/burn directly by setting stargate to deployer for tests
config.STARGATE_CONTRACT_ADDRESS = deployer.address;
const contracts = await getOrDeployContracts({ forceDeploy: true, config });
stargateNFTContract = contracts.stargateNFTContract;
stargateContract = contracts.stargateContract;
});
it("mint does not emit LevelCirculatingSupplyUpdated", async () => {
const level = await stargateNFTContract.getLevel(1);
const txMint = stargateNFTContract
.connect(deployer)
.mint(level.id, user.address);
await expect(txMint)
.to.emit(stargateNFTContract, "TokenMinted")
.withArgs(
user.address,
level.id,
false,
(await stargateNFTContract.getCurrentTokenId()) + 1n,
level.vetAmountRequiredToStake
);
await expect(txMint).to.not.emit(
stargateNFTContract,
"LevelCirculatingSupplyUpdated"
);
// sanity: circulating supply increased
const supplyAfter = await stargateNFTContract.getLevelSupply(level.id);
expect(supplyAfter.circulating).to.equal(1);
});
it("burn does not emit LevelCirculatingSupplyUpdated", async () => {
const level = await stargateNFTContract.getLevel(1);
const tokenId = (await stargateNFTContract.getCurrentTokenId()) + 1n;
await (await stargateNFTContract.connect(deployer).mint(level.id, user.address)).wait();
const txBurn = stargateNFTContract.connect(deployer).burn(tokenId);
await expect(txBurn)
.to.emit(stargateNFTContract, "TokenBurned")
.withArgs(user.address, level.id, tokenId, level.vetAmountRequiredToStake);
await expect(txBurn).to.not.emit(
stargateNFTContract,
"LevelCirculatingSupplyUpdated"
);
// sanity: circulating supply decreased
const supplyAfter = await stargateNFTContract.getLevelSupply(level.id);
expect(supplyAfter.circulating).to.equal(0);
});
});
describe("Migrate does not emit LevelCirculatingSupplyUpdated", () => {
let legacyNodesMock: TokenAuctionMock;
beforeEach(async () => {
const legacyNodesMockFactory = new TokenAuctionMock__factory(deployer);
legacyNodesMock = await legacyNodesMockFactory.deploy();
await legacyNodesMock.waitForDeployment();
const config = createLocalConfig();
config.STARGATE_CONTRACT_ADDRESS = deployer.address;
// Override legacy nodes address with the mock so we can control metadata
config.TOKEN_AUCTION_CONTRACT_ADDRESS = await legacyNodesMock.getAddress();
const contracts = await getOrDeployContracts({ forceDeploy: true, config });
stargateNFTContract = contracts.stargateNFTContract;
stargateContract = contracts.stargateContract;
});
it("migrate does not emit LevelCirculatingSupplyUpdated", async () => {
const LEVEL_ID = 4;
const TOKEN_ID = 500; // <= LEGACY_LAST_TOKEN_ID so it can be preserved
// Prepare legacy token metadata so migrate can succeed
await (await legacyNodesMock.helper__setMetadata(TOKEN_ID, {
owner: user.address,
strengthLevel: LEVEL_ID,
onUpgrade: false,
isOnAuction: false,
lastTransferTime: 0,
createdAt: 0,
updatedAt: 0,
})).wait();
const level = await stargateNFTContract.getLevel(LEVEL_ID);
const txMigrate = stargateNFTContract.connect(deployer).migrate(TOKEN_ID);
await expect(txMigrate)
.to.emit(stargateNFTContract, "TokenMinted")
.withArgs(user.address, LEVEL_ID, true, TOKEN_ID, level.vetAmountRequiredToStake);
await expect(txMigrate).to.not.emit(
stargateNFTContract,
"LevelCirculatingSupplyUpdated"
);
const supplyAfter = await stargateNFTContract.getLevelSupply(LEVEL_ID);
expect(supplyAfter.circulating).to.equal(1);
});
});
describe("Sanity: addLevel does emit LevelCirculatingSupplyUpdated", () => {
let levelOperator: HardhatEthersSigner;
beforeEach(async () => {
const config = createLocalConfig();
// Any address can be level operator if granted; deployer will grant to user
const contracts = await getOrDeployContracts({ forceDeploy: true, config });
stargateNFTContract = contracts.stargateNFTContract;
stargateContract = contracts.stargateContract;
levelOperator = otherAccounts[0];
await (await stargateNFTContract.grantRole(
await stargateNFTContract.LEVEL_OPERATOR_ROLE(),
levelOperator.address
)).wait();
});
it("addLevel emits LevelCirculatingSupplyUpdated once", async () => {
const currentIds = await stargateNFTContract.getLevelIds();
const expectedNewId = currentIds[currentIds.length - 1] + 1n;
const tx = stargateNFTContract.connect(levelOperator).addLevel({
level: {
id: 123, // ignored
name: "My New Level",
isX: false,
vetAmountRequiredToStake: ethers.parseEther("42"),
scaledRewardFactor: 150,
maturityBlocks: 10,
},
cap: 5,
circulatingSupply: 2,
});
await expect(tx)
.to.emit(stargateNFTContract, "LevelCirculatingSupplyUpdated")
.withArgs(expectedNewId, 0, 2);
});
});
});
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
The supply-changing helper functions update stored checkpoints but never emit the documented event.
Impact
Off-chain indexers and dApps relying on the event will get incorrect per-level supply values after the initial add, though on-chain state remains correct and queryable.
What the attacker needed
Access to the deployed contracts; ability to mint, burn or migrate tokens
The fix
The event should be emitted whenever the circulating supply changes.
How it was found
- Deploy the contracts locally with the Stargate address set to the deployer.
- Mint a token at a level and check that TokenMinted is emitted but LevelCirculatingSupplyUpdated is not.
- Burn a token and check that TokenBurned is emitted but LevelCirculatingSupplyUpdated is not.
- Migrate a legacy token and check that TokenMinted is emitted but LevelCirculatingSupplyUpdated is not.
- Add a new level and confirm LevelCirculatingSupplyUpdated is emitted once.
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 can announce things that happen by sending out 'events', which are like public notices that other software can listen for. This contract promises to send a notice whenever the number of tokens at a level changes, but it only sends it once when the level is first created. Anyone building a dashboard from those notices will show the wrong numbers after that.
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.