Skip to content
Business logic Audit finding Intermediate

Malicious user can bypass maturity period for newly added levels

New staking levels created after a contract upgrade never receive a boost price, so the cost to skip the maturity period is calculated as zero. A user staking into such a level could boost and delegate immediately without paying the intended fee.

Vechain | Stargate Hayabusa

Originally disclosed on Immunefi

60259 sc low malicious user can bypass maturity period for newly added levels

Description

Summary

The system allows creation of new staking levels via addLevel(), and each level is expected to require a boost fee to skip maturity before delegation. During the upgrade, initializeV3() sets the boostPricePerBlock values only for pre-existing levels. However, new levels added after the upgrade do not store or initialize any boostPricePerBlock value. Because the boost amount is computed as:

boostAmount = maturityBlocksRemaining * boostPricePerBlock

new levels default to boostPricePerBlock = 0, resulting in boostAmount = 0. As a result, users can stake and instantly delegate without paying the intended VTHO boost fee, effectively bypassing the maturity period entirely.

This breaks the economic model of the system and violates the expected requirement that skipping maturity must incur cost.

Vulnerability Details

Relevant code paths:

During upgrade:

Solidity
function initializeV3(
    address stargate,
    uint8[] memory levelIds,
    uint256[] memory boostPricesPerBlock
) external onlyRole(UPGRADER_ROLE) reinitializer(3) {
    ...
    for (uint256 i; i < levelIds.length; i++) {
        Levels.updateLevelBoostPricePerBlock($, levelIds[i], boostPricesPerBlock[i]);
    }
}

Only provided levelIds receive boost price updates.

Adding new levels:

Solidity
function addLevel(
    DataTypes.LevelAndSupply memory _levelAndSupply
) external onlyRole(LEVEL_OPERATOR_ROLE) {
    Levels.addLevel(_getStargateNFTStorage(), _levelAndSupply);
}

There is no assignment to set the boostPricePerBlock for the new level, so new levels implicitly use the storage default value of 0.

Because boosting costs 0 for new levels, any user can perform the following sequence and bypass maturity:

{% stepper %} {% step %}

Stake into a newly added level

User stakes to a level that was added after the upgrade and therefore has boostPricePerBlock = 0. {% endstep %}

{% step %}

Automatically boost for free

Because boostAmount = maturityBlocksRemaining * boostPricePerBlock and boostPricePerBlock == 0, the computed boosting cost is zero. {% endstep %}

{% step %}

Instantly delegate

The user delegates immediately, effectively bypassing the intended maturity waiting period without incurring the expected VTHO cost. {% endstep %} {% endstepper %}

Impact

This is a broken system behavior. The core issue is that the logic does not enforce boost price requirements for new levels and there is no functionality to set the boostPricePerBlock in a separate transaction for a specific level at creation time. This allows users to bypass maturity without payment and undermines the protocol staking economics.

Recommendation

Modify addLevel to allow setting the boostPricePerBlock when creating a new level (for example, include a parameter in addLevel or ensure addLevel initializes boostPricePerBlock to a non-zero value, or require an explicit setter callable only by level operators immediately after creation). Ensure upgrade and initialization paths cover future-added levels or add validation preventing zero-priced boosts for levels where maturity/boosting is expected.

Proof of Concept

The reporter provided integration tests demonstrating the issue. Run with: yarn hardhat test --network vechain_solo test/integration/Delegation.test.ts

Two relevant test cases are summarized below.

<details> <summary>1) Test showing boost is charged for previous levels</summary>

Test excerpt:

TS
it.only("previous levels are not missing the boostprice.", async () => {
    const paramsKey = "0x00000000000064656c656761746f722d636f6e74726163742d61646472657373";
    const stargateAddress = await protocolParamsContract.get(paramsKey);
    const expectedParamsVal = BigInt(await stargateContract.getAddress());
    expect(stargateAddress).to.equal(expectedParamsVal);

    const validatorAddress = await protocolStakerContract.firstActive();
    expect(compareAddresses(validatorAddress, deployer.address)).to.be.true;

    const [leaderGroupSize, queuedValidators] =
        await protocolStakerContract.getValidationsNum();
    expect(leaderGroupSize).to.equal(1);
    expect(queuedValidators).to.equal(0);

    let balanceBefore = await mockedVthoToken.balanceOf(user);
    console.log("Balance before stake and delegate: ", balanceBefore);

    let approveTx = await mockedVthoToken.connect(user).approve(await stargateNFTContract.getAddress(), balanceBefore);
    await approveTx.wait();

    // staking the token here 
    const levelId = 1;
    const levelSpec = await stargateNFTContract.getLevel(levelId);
    const levelVetAmountRequired = levelSpec.vetAmountRequiredToStake;

    // staking to get the NFT
    let stakeTx = await stargateContract
        .connect(user)
        .stakeAndDelegate(levelId, deployer.address, { value: levelVetAmountRequired });
    await stakeTx.wait();
    log("\nπŸŽ‰ Correctly staked an NFT of level", levelId);

    let balanceAfter = await mockedVthoToken.balanceOf(user);
    console.log("Balance before stake and delegate: ", balanceAfter);
});

Test output shows VTHO balance decreased as expected for old levels:

Balance before stake and delegate:  87112285931760246646623899502532662132735n
Balance before stake and delegate:  87112285931760246646615555003917976460036n
βœ” Newly added levels are missing boostPrice. (188ms)
</details> <details> <summary>2) Test showing newly added level has boostAmt == 0</summary>

Test excerpt:

TS
it.only("Newly added levels are missing boostPrice.", async () => {
    const paramsKey = "0x00000000000064656c656761746f722d636f6e74726163742d61646472657373";
    const stargateAddress = await protocolParamsContract.get(paramsKey);
    const expectedParamsVal = BigInt(await stargateContract.getAddress());
    expect(stargateAddress).to.equal(expectedParamsVal);

    const validatorAddress = await protocolStakerContract.firstActive();
    expect(compareAddresses(validatorAddress, deployer.address)).to.be.true;

    const [leaderGroupSize, queuedValidators] =
        await protocolStakerContract.getValidationsNum();
    expect(leaderGroupSize).to.equal(1);
    expect(queuedValidators).to.equal(0);

    const levelOperator =(await ethers.getSigners())[5];

    const grantTx = await stargateNFTContract.grantRole(
        await stargateNFTContract.LEVEL_OPERATOR_ROLE(),
        levelOperator.address
    );
    await grantTx.wait();

    const currentLevelIds = await stargateNFTContract.getLevelIds();

    const newLevelAndSupply = {
        level: {
            id: 25,
            name: "My New Level",
            isX: false,
            vetAmountRequiredToStake: ethers.parseEther("1000000"),
            scaledRewardFactor: 150,
            maturityBlocks: 30,
        },
        cap: 872,
        circulatingSupply: 0,
    };

    const expectedLevelId = currentLevelIds[currentLevelIds.length - 1] + 1n;

    // Add new level
    const addLevelTx = await stargateNFTContract
        .connect(levelOperator)
        .addLevel(newLevelAndSupply);
    await addLevelTx.wait();

    await mineBlocks(1);

    // staking the token here 
    const levelId = expectedLevelId;
    const levelSpec = await stargateNFTContract.getLevel(levelId);
    const levelVetAmountRequired = levelSpec.vetAmountRequiredToStake;        

    // staking to get the NFT
    let stakeTx = await stargateContract
        .connect(user)
        .stake(levelId, { value: levelVetAmountRequired });
    await stakeTx.wait();
    log("\nπŸŽ‰ Correctly staked an NFT of level", levelId);

    const tokenId = await stargateNFTContract.getCurrentTokenId();
    let boostAmt = await stargateNFTContract.boostAmount(tokenId);
    console.log("boostAmt: ", boostAmt);
});

Test output shows boost amount is zero for newly added level:

app env:  local
boostAmt:  0n
βœ” Newly added levels are missing boostPrice. (153ms)
</details>

If you want, I can:

  • Propose a small code patch (diff) to initialize boostPricePerBlock in addLevel or add a setter restricted to the appropriate role.
  • Draft unit tests to prevent regression.

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

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

Stargate is the staking and delegation layer of the Vechain Hayabusa upgrade. Users stake VET into a level and receive an NFT representing that position; the NFT can then be delegated to a validator. Each level defines a maturity period, expressed in blocks, that must elapse before delegation is allowed. A user who does not want to wait can pay a boost fee in VTHO to skip the remaining maturity, and the fee is meant to scale with the number of blocks still outstanding.

The finding targets the StargateNFT contract:

Text
https://github.com/immunefi-team/audit-comp-vechain-stargate-hayabusa/tree/main/packages/contracts/contracts/StargateNFT/StargateNFT.sol

The report is a smart contract finding of Low severity, with the listed impact being griefing: no profit motive for the attacker, but damage to the users or the protocol. The economic premise of the feature is that skipping maturity always costs something. The report shows a path where it costs nothing.

Setup

The proof of concept is an integration test run with the command below. The proof of concept is run with:

Bash
yarn hardhat test --network vechain_solo test/integration/Delegation.test.ts

The tests use a mocked VTHO token (mockedVthoToken), the Stargate contract, the StargateNFT contract, a protocol params contract and a protocol staker contract. The test code asserts a single active validator (the deployer), a leader group size of 1 and no queued validators.

Two roles matter for the finding:

  1. UPGRADER_ROLE, which is allowed to call initializeV3() during the upgrade and seed boost prices for existing levels.
  2. LEVEL_OPERATOR_ROLE, which is allowed to call addLevel() to create new staking levels.

In the second test the level operator is taken from the available signers and granted the role explicitly:

TS
const levelOperator =(await ethers.getSigners())[5];

const grantTx = await stargateNFTContract.grantRole(
    await stargateNFTContract.LEVEL_OPERATOR_ROLE(),
    levelOperator.address
);
await grantTx.wait();

No special precondition is needed on the attacker side beyond the existence of a level added after the upgrade.

Finding it

The researcher compared two code paths. The first is the upgrade initialiser, which is where boost prices are introduced:

Solidity
function initializeV3(
    address stargate,
    uint8[] memory levelIds,
    uint256[] memory boostPricesPerBlock
) external onlyRole(UPGRADER_ROLE) reinitializer(3) {
    ...
    for (uint256 i; i < levelIds.length; i++) {
        Levels.updateLevelBoostPricePerBlock($, levelIds[i], boostPricesPerBlock[i]);
    }
}

This loop only touches the level IDs passed in by the upgrader, which are the levels that already exist at upgrade time. The second path is level creation:

Solidity
function addLevel(
    DataTypes.LevelAndSupply memory _levelAndSupply
) external onlyRole(LEVEL_OPERATOR_ROLE) {
    Levels.addLevel(_getStargateNFTStorage(), _levelAndSupply);
}

addLevel() takes a level definition and supply information and forwards them to the library. Nothing in this function assigns a boostPricePerBlock to the new level, and the report states there is no separate function to set the boost price for a specific level after creation either. A level created after the upgrade therefore keeps the storage default, which is 0.

That matters because the boost cost is computed as:

Text
boostAmount = maturityBlocksRemaining * boostPricePerBlock

With boostPricePerBlock = 0, the product is zero regardless of how many maturity blocks remain. The maturity period is still enforced in the sense that the boost path exists, but the price of taking it collapses to nothing.

Exploitation

The sequence needs no special tooling: a user stakes into a newly added level and boosts immediately.

Step 1: Stake into a newly added level

The user stakes into a level that was added after the upgrade and therefore has boostPricePerBlock = 0. In the test this is done through the Stargate contract's stake function, with the VET amount taken from the level specification:

TS
const levelId = expectedLevelId;
const levelSpec = await stargateNFTContract.getLevel(levelId);
const levelVetAmountRequired = levelSpec.vetAmountRequiredToStake;

// staking to get the NFT
let stakeTx = await stargateContract
    .connect(user)
    .stake(levelId, { value: levelVetAmountRequired });
await stakeTx.wait();

The level used in the test is created by the level operator with addLevel and the following definition:

TS
const newLevelAndSupply = {
    level: {
        id: 25,
        name: "My New Level",
        isX: false,
        vetAmountRequiredToStake: ethers.parseEther("1000000"),
        scaledRewardFactor: 150,
        maturityBlocks: 30,
    },
    cap: 872,
    circulatingSupply: 0,
};

The test derives the expected ID from the current level list, adds the level and mines a block:

TS
const expectedLevelId = currentLevelIds[currentLevelIds.length - 1] + 1n;

// Add new level
const addLevelTx = await stargateNFTContract
    .connect(levelOperator)
    .addLevel(newLevelAndSupply);
await addLevelTx.wait();

await mineBlocks(1);

Step 2: Automatically boost for free

Because boostAmount = maturityBlocksRemaining * boostPricePerBlock and boostPricePerBlock == 0, the computed boosting cost is zero. The test reads the boost amount for the freshly minted token:

TS
const tokenId = await stargateNFTContract.getCurrentTokenId();
let boostAmt = await stargateNFTContract.boostAmount(tokenId);
console.log("boostAmt: ", boostAmt);

The output confirms the zero price for the new level:

Text
app env:  local
boostAmt:  0n
βœ” Newly added levels are missing boostPrice. (153ms)

Step 3: Instantly delegate

The user delegates immediately, bypassing the intended maturity waiting period without incurring the expected VTHO cost. The report describes this as the third step of the sequence; the test excerpt shown stops at reading the boost amount.

Control: old levels still charge

A second test exercises a pre-existing level: The user approves the mocked VTHO token and stakes and delegates in one call:

TS
let balanceBefore = await mockedVthoToken.balanceOf(user);
console.log("Balance before stake and delegate: ", balanceBefore);

let approveTx = await mockedVthoToken.connect(user).approve(await stargateNFTContract.getAddress(), balanceBefore);
await approveTx.wait();

// staking the token here
const levelId = 1;
const levelSpec = await stargateNFTContract.getLevel(levelId);
const levelVetAmountRequired = levelSpec.vetAmountRequiredToStake;

// staking to get the NFT
let stakeTx = await stargateContract
    .connect(user)
    .stakeAndDelegate(levelId, deployer.address, { value: levelVetAmountRequired });
await stakeTx.wait();
log("\nπŸŽ‰ Correctly staked an NFT of level", levelId);

let balanceAfter = await mockedVthoToken.balanceOf(user);
console.log("Balance before stake and delegate: ", balanceAfter);

The VTHO balance drops:

Text
Balance before stake and delegate:  [redacted]
Balance before stake and delegate:  [redacted]
βœ” Newly added levels are missing boostPrice. (188ms)

Both test cases are marked it.only.

Root cause

The boost price is stored per level, and the only place it is written is the loop inside initializeV3(), which iterates over the level IDs supplied by the upgrader. Levels that exist at upgrade time get a price; levels created afterwards never do. addLevel() accepts a DataTypes.LevelAndSupply structure that carries the level definition and supply cap but no boost price, and the report states there is no separate setter to fill the gap after creation. The new level therefore reads back the storage default of 0, and the multiplication in the boost amount formula turns every remaining maturity block into a free skip.

The problem is not who can create a level but what a created level contains.

Impact

Any user can stake into a level added after the upgrade and delegate immediately without paying the VTHO boost fee, so the maturity period provides no economic protection for those levels. The report frames this as a broken system behaviour that undermines the protocol staking economics and violates the expectation that skipping maturity must incur a cost. The listed impact is griefing: no profit motive for the attacker, but damage to the users or the protocol. The condition is that a level with a zero boost price exists, which the report says is the case for levels added after the upgrade.

Fix

The recommendation is to make level creation set the boost price. Concretely, the report suggests one of the following:

  1. Add a boostPricePerBlock parameter to addLevel so the price is supplied at creation time.
  2. Have addLevel initialise boostPricePerBlock to a non-zero value.
  3. Require an explicit setter, callable only by level operators, immediately after creation.

It also asks that upgrade and initialisation paths cover future-added levels, or that validation prevents zero-priced boosts for levels where maturity and boosting are expected. The report does not state that a patch was applied.

Variants to test

  1. Other per-level parameters seeded only at upgrade. Look for fields written in a reinitialiser loop over existing IDs and not in the creation function. A positive result is a newly created entity whose field reads back as the storage default while older entities have a real value.
  2. Zero-price or zero-rate bypasses in fee formulas. Any cost computed as quantity * rate where the rate is per-entity and settable is a candidate. A positive result is a fee of zero for an operation that the documentation says is charged.
  3. Missing setters after creation. Check whether a value that is meant to be configurable per entity has any write path at all outside the upgrade. A positive result is a field that can only ever be changed by re-running an initialiser, which in practice means never for new entities.
  4. Default-value reliance in upgradeable contracts. For any storage variable introduced in a new implementation version, check what a freshly created record gets. A positive result is a security-relevant field that defaults to a permissive value such as zero or false.

Hunting notes

This class of bug hides at the seam between an upgrade initialiser and a creation function. During review, list every storage field that the new implementation introduces, find every write to it, and check whether the write path covers entities created after the upgrade. A reinitialiser that loops over a caller-supplied list of IDs is a strong signal: it can only ever cover what exists at that moment.

The report includes two integration tests. One test demonstrated that a pre-existing level charges VTHO on stake and delegate, and the other demonstrated that a newly added level reports a boost amount of zero.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 16 min read.

What happened, in plain words

Stargate is a piece of software that runs on the VeChain blockchain. It is part of a larger upgrade called Hayabusa. Its job is staking: a user locks up some VET (a cryptocurrency) and in return receives a digital receipt called an NFT. That NFT can then be handed to a validator, a computer that helps run the network, so the locked VET counts towards that validator's weight. This handover is called delegation.

Staking is organised into levels. Each level has rules: how much VET you must lock, and a waiting period called the maturity period. The maturity period is counted in blocks. A block is a bundle of transactions that the network adds to its shared record roughly on a schedule, so counting in blocks is a way of counting time. You are not allowed to delegate until the maturity period has passed.

If you do not want to wait, the system offers a shortcut: you can pay a fee in VTHO (another token) to skip the remaining waiting time. This is called boosting. The fee is supposed to grow with the number of blocks you still have to wait, so skipping a long wait costs more than skipping a short one.

The report shows that this fee can end up being zero. When the upgrade was applied, the fee was filled in only for the levels that already existed at that moment. Levels created afterwards never got a fee, so the system treats their fee as zero. Anyone who stakes into such a level can skip the waiting period for free. The report rates this Low severity and files it under griefing: the attacker does not steal money, but the protocol's economic rules are broken.

A few words you will meet throughout. A smart contract is a program that lives on the blockchain and runs automatically when someone calls it; think of a vending machine that does exactly what its instructions say and nothing else. A function is a named action inside such a program, like a button on the machine. A role is a permission label: only an address holding a particular role may press a particular button. Storage is the contract's long-term memory, and every memory slot starts out holding a default value, which for numbers is zero, unless someone writes something else into it. Finally, a test is a small program that drives the contract and checks the result, so a researcher can prove a bug without touching the real network.

Context

Stargate is the staking and delegation layer of the Vechain Hayabusa upgrade. Users stake VET into a level and receive an NFT representing that position; the NFT can then be delegated to a validator. Each level defines a maturity period, expressed in blocks, that must elapse before delegation is allowed. A user who does not want to wait can pay a boost fee in VTHO to skip the remaining maturity, and the fee is meant to scale with the number of blocks still outstanding.

The finding targets the StargateNFT contract:

Text
https://github.com/immunefi-team/audit-comp-vechain-stargate-hayabusa/tree/main/packages/contracts/contracts/StargateNFT/StargateNFT.sol

That link points at the source code of the contract on GitHub. Reading a contract's source is how a reviewer learns what buttons it offers and what rules it enforces.

The report is a smart contract finding of Low severity, filed under the griefing impact category: no profit motive for the attacker, but damage to the users or the protocol. The economic premise of the feature is that skipping maturity always costs something. The report shows a path where it costs nothing.

Setup

The proof of concept is an integration test run with the command below. A local network is a private copy of the blockchain running on the researcher's own machine: it behaves like the real thing but nothing is at risk and everything can be reset. Hardhat is a toolkit for building and testing blockchain programs. The proof of concept is run with:

Bash
yarn hardhat test --network vechain_solo test/integration/Delegation.test.ts

Line by line: yarn is a package manager, a tool that installs and runs other tools. hardhat test tells Hardhat to run a test file. --network vechain_solo says to run it against the local solo network rather than a public one. test/integration/Delegation.test.ts is the file containing the tests, written in TypeScript (a variant of JavaScript with type annotations). The command runs the test file against the local solo network.

The tests use a mocked VTHO token (mockedVthoToken), the Stargate contract, the StargateNFT contract, a protocol params contract and a protocol staker contract. A mock is a stand-in that behaves like the real thing for testing purposes, the way a flight simulator stands in for a plane. The params contract stores configuration values; the staker contract manages validators. The test code asserts a single active validator (the deployer), a leader group size of 1 and no queued validators. Asserting means the test checks a condition and fails loudly if it is not true, so the rest of the test can rely on it.

Two roles matter for the finding:

  1. UPGRADER_ROLE, which is allowed to call initializeV3() during the upgrade and seed boost prices for existing levels.
  2. LEVEL_OPERATOR_ROLE, which is allowed to call addLevel() to create new staking levels.

In the second test the level operator is taken from the available signers and granted the role explicitly:

TS
const levelOperator =(await ethers.getSigners())[5];

const grantTx = await stargateNFTContract.grantRole(
    await stargateNFTContract.LEVEL_OPERATOR_ROLE(),
    levelOperator.address
);
await grantTx.wait();

Line by line: ethers.getSigners() returns the list of test accounts Hardhat has prepared, each with an address and a private key. Index [5] picks the sixth one and stores it as levelOperator. stargateNFTContract.LEVEL_OPERATOR_ROLE() asks the contract for the identifier of the level operator role, so the test does not have to hardcode it. grantRole(...) is then called with that identifier and levelOperator.address, which gives that account the permission. await grantTx.wait() pauses until the transaction is confirmed, so the next line runs only after the permission is really in place.

No special precondition is needed on the attacker side beyond the existence of a level added after the upgrade.

Finding it

The researcher compared two code paths. The first is the upgrade initialiser, which is where boost prices are introduced:

Solidity
function initializeV3(
    address stargate,
    uint8[] memory levelIds,
    uint256[] memory boostPricesPerBlock
) external onlyRole(UPGRADER_ROLE) reinitializer(3) {
    ...
    for (uint256 i; i < levelIds.length; i++) {
        Levels.updateLevelBoostPricePerBlock($, levelIds[i], boostPricesPerBlock[i]);
    }
}

Line by line: function initializeV3(...) declares a function named initializeV3, the third version of the setup routine. It takes three inputs: stargate, an address; levelIds, a list of small numbers identifying levels; and boostPricesPerBlock, a list of prices, one per level. external means it can be called from outside the contract. onlyRole(UPGRADER_ROLE) is a guard that rejects the call unless the caller holds the upgrader role. reinitializer(3) marks this as the setup step for version 3, so it can run once for that version and not again. The ... stands for code the report leaves out. The for loop walks through the list of level IDs one by one, and for each one calls Levels.updateLevelBoostPricePerBlock($, levelIds[i], boostPricesPerBlock[i]), which writes the matching price into that level's storage. The key point is that the loop only touches the IDs the upgrader passes in, and those are the levels that already exist at upgrade time.

The second path is level creation:

Solidity
function addLevel(
    DataTypes.LevelAndSupply memory _levelAndSupply
) external onlyRole(LEVEL_OPERATOR_ROLE) {
    Levels.addLevel(_getStargateNFTStorage(), _levelAndSupply);
}

Line by line: function addLevel(...) declares the function that creates a level. It takes one input, _levelAndSupply, a bundle of data describing the level and its supply limits. external onlyRole(LEVEL_OPERATOR_ROLE) means anyone may call it in principle, but the guard rejects callers without the level operator role. The body does one thing: it hands the storage location and the bundle to the library function Levels.addLevel, which does the actual writing. Nothing here assigns a boostPricePerBlock to the new level, and the report states there is no separate function to set the boost price for a specific level after creation either. A level created after the upgrade therefore keeps the storage default, which is 0.

That matters because the boost cost is computed as:

Text
boostAmount = maturityBlocksRemaining * boostPricePerBlock

This is a multiplication: the number of blocks still to wait, times the price charged per block. With boostPricePerBlock = 0, the product is zero regardless of how many maturity blocks remain, the same way any number multiplied by zero is zero. The maturity period is still enforced in the sense that the boost path exists, but the price of taking it collapses to nothing.

Exploitation

The sequence needs no special tooling: a user stakes into a newly added level and boosts immediately.

Step 1: Stake into a newly added level

The user stakes into a level that was added after the upgrade and therefore has boostPricePerBlock = 0. In the test this is done through the Stargate contract's stake function, with the VET amount taken from the level specification:

TS
const levelId = expectedLevelId;
const levelSpec = await stargateNFTContract.getLevel(levelId);
const levelVetAmountRequired = levelSpec.vetAmountRequiredToStake;

// staking to get the NFT
let stakeTx = await stargateContract
    .connect(user)
    .stake(levelId, { value: levelVetAmountRequired });
await stakeTx.wait();

Line by line: levelId is set to the ID the test expects the new level to have. getLevel(levelId) reads the level's rules back from the contract, and levelSpec.vetAmountRequiredToStake pulls out the amount of VET that must be locked. stargateContract.connect(user).stake(levelId, { value: levelVetAmountRequired }) sends the stake transaction as the user account, naming the level and attaching the required VET as the transaction's value. await stakeTx.wait() waits for confirmation. The test reads the amount from the contract rather than hardcoding it so the call matches whatever the level actually requires.

The level used in the test is created by the level operator with addLevel and the following definition:

TS
const newLevelAndSupply = {
    level: {
        id: 25,
        name: "My New Level",
        isX: false,
        vetAmountRequiredToStake: ethers.parseEther("1000000"),
        scaledRewardFactor: 150,
        maturityBlocks: 30,
    },
    cap: 872,
    circulatingSupply: 0,
};

Line by line: this is a plain data object describing the level. id: 25 is the level's identifier. name is a human-readable label. isX: false is a flag the report does not explain further. vetAmountRequiredToStake: ethers.parseEther("1000000") converts the readable number 1000000 into the smallest unit the blockchain uses, because contracts work in whole numbers. scaledRewardFactor: 150 is a reward multiplier. maturityBlocks: 30 sets the waiting period to 30 blocks. Outside the level object, cap: 872 is the maximum supply and circulatingSupply: 0 is how many are already in circulation. Notice what is absent: there is no field for a boost price.

The test then mines a block and reads the level back from the contract, using the expected ID derived from the current level list:

TS
const expectedLevelId = currentLevelIds[currentLevelIds.length - 1] + 1n;

// Add new level
const addLevelTx = await stargateNFTContract
    .connect(levelOperator)
    .addLevel(newLevelAndSupply);
await addLevelTx.wait();

await mineBlocks(1);

Line by line: currentLevelIds is the list of existing level IDs, and currentLevelIds[currentLevelIds.length - 1] takes the last one; adding 1n (a big-integer literal) gives the ID the new level should receive. The addLevel call is sent as levelOperator, the account that was granted the role earlier, passing the object above. await addLevelTx.wait() waits for confirmation. mineBlocks(1) forces the local test network to produce one more block, so the state is settled before the test reads it back.

Step 2: Automatically boost for free

Because boostAmount = maturityBlocksRemaining * boostPricePerBlock and boostPricePerBlock == 0, the computed boosting cost is zero. The test reads the boost amount for the freshly minted token:

TS
const tokenId = await stargateNFTContract.getCurrentTokenId();
let boostAmt = await stargateNFTContract.boostAmount(tokenId);
console.log("boostAmt: ", boostAmt);

Line by line: getCurrentTokenId() returns the identifier of the most recently created NFT, which is the one the user just received from staking. boostAmount(tokenId) asks the contract what the boost would cost for that NFT. console.log prints the answer so the researcher can see it.

The output confirms the zero price for the new level:

Text
app env:  local
boostAmt:  0n
βœ” Newly added levels are missing boostPrice. (153ms)

app env: local says the test ran against the local environment. boostAmt: 0n is the printed cost: zero, with the n marking a big-integer value. The tick and the test name show the test passed, and (153ms) is how long it took.

Step 3: Instantly delegate

The user delegates immediately, bypassing the intended maturity waiting period without incurring the expected VTHO cost. The report describes this as the third step of the sequence; the test excerpt shown stops at reading the boost amount.

Control: old levels still charge

A second test exercises a pre-existing level: A control is a comparison case: if the old level charges and the new one does not, the difference points at the cause. The user approves the mocked VTHO token and stakes and delegates in one call:

TS
let balanceBefore = await mockedVthoToken.balanceOf(user);
console.log("Balance before stake and delegate: ", balanceBefore);

let approveTx = await mockedVthoToken.connect(user).approve(await stargateNFTContract.getAddress(), balanceBefore);
await approveTx.wait();

// staking the token here
const levelId = 1;
const levelSpec = await stargateNFTContract.getLevel(levelId);
const levelVetAmountRequired = levelSpec.vetAmountRequiredToStake;

// staking to get the NFT
let stakeTx = await stargateContract
    .connect(user)
    .stakeAndDelegate(levelId, deployer.address, { value: levelVetAmountRequired });
await stakeTx.wait();
log("\nπŸŽ‰ Correctly staked an NFT of level", levelId);

let balanceAfter = await mockedVthoToken.balanceOf(user);
console.log("Balance before stake and delegate: ", balanceAfter);

Line by line: balanceOf(user) reads how much VTHO the user holds, and the value is printed as the starting point. approve(...) is a standard token action: it lets another contract, here the StargateNFT contract whose address is fetched with getAddress(), spend up to balanceBefore of the user's VTHO. Tokens cannot be pulled by a contract without this permission, the same way a shop cannot charge your card until you authorise it. await approveTx.wait() waits for that approval to be confirmed. levelId = 1 selects an old level, one that existed at upgrade time. The level's required VET amount is read as before. stakeAndDelegate(levelId, deployer.address, { value: levelVetAmountRequired }) does both actions in one transaction, naming the validator to delegate to. log(...) prints a confirmation line. Finally the balance is read again and printed.

The VTHO balance drops:

Text
Balance before stake and delegate:  [redacted]
Balance before stake and delegate:  [redacted]
βœ” Newly added levels are missing boostPrice. (188ms)

The two printed numbers are the balance before and after; the second is smaller, so VTHO was spent. Both lines carry the same label because the test prints the same text twice, once for each reading. The tick shows the test passed.

Both test cases are marked it.only. it.only is a testing-framework marker meaning "run only this test", which is handy while investigating but not something you would leave in a shared suite.

Root cause

The boost price is stored per level, and the only place it is written is the loop inside initializeV3(), which iterates over the level IDs supplied by the upgrader. Levels that exist at upgrade time get a price; levels created afterwards never do. addLevel() accepts a DataTypes.LevelAndSupply structure that carries the level definition and supply cap but no boost price, and the report states there is no separate setter to fill the gap after creation. A setter is simply a function whose job is to write a value. The new level therefore reads back the storage default of 0, and the multiplication in the boost amount formula turns every remaining maturity block into a free skip.

Access control means deciding who may call what. The problem is not who can create a level but what a created level contains.

Impact

Any user can stake into a level added after the upgrade and delegate immediately without paying the VTHO boost fee, so the maturity period provides no economic protection for those levels. The report frames this as a broken system behaviour that undermines the protocol staking economics and violates the expectation that skipping maturity must incur a cost. The listed impact is griefing: no profit motive for the attacker, but damage to the users or the protocol. The condition is that a level with a zero boost price exists, which the report says is the case for levels added after the upgrade.

Fix

The recommendation is to make level creation set the boost price. Concretely, the report suggests one of the following:

  1. Add a boostPricePerBlock parameter to addLevel so the price is supplied at creation time.
  2. Have addLevel initialise boostPricePerBlock to a non-zero value.
  3. Require an explicit setter, callable only by level operators, immediately after creation.

It also asks that upgrade and initialisation paths cover future-added levels, or that validation prevents zero-priced boosts for levels where maturity and boosting are expected. The report does not state that a patch was applied.

Variants to test

  1. Other per-level parameters seeded only at upgrade. Look for fields written in a reinitialiser loop over existing IDs and not in the creation function. A positive result is a newly created entity whose field reads back as the storage default while older entities have a real value.
  2. Zero-price or zero-rate bypasses in fee formulas. Any cost computed as quantity * rate where the rate is per-entity and settable is a candidate. A positive result is a fee of zero for an operation that the documentation says is charged.
  3. Missing setters after creation. Check whether a value that is meant to be configurable per entity has any write path at all outside the upgrade. A positive result is a field that can only ever be changed by re-running an initialiser, which in practice means never for new entities.
  4. Default-value reliance in upgradeable contracts. For any storage variable introduced in a new implementation version, check what a freshly created record gets. A positive result is a security-relevant field that defaults to a permissive value such as zero or false.

Hunting notes

This class of bug hides at the seam between an upgrade initialiser and a creation function. During review, list every storage field that the new implementation introduces, find every write to it, and check whether the write path covers entities created after the upgrade. A reinitialiser that loops over a caller-supplied list of IDs is a strong signal: it can only ever cover what exists at that moment.

The report includes two integration tests. One test demonstrated that a pre-existing level charges VTHO on stake and delegate, and the other demonstrated that a newly added level reports a boost amount of zero.

Glossary

  • Block: a bundle of transactions added to the blockchain's shared record; blocks are produced on a schedule, so counting them is a way of counting time.
  • Blockchain: a shared record of transactions kept by many computers, where entries are hard to change after the fact.
  • Boost: the paid shortcut that skips the remaining maturity period before delegation.
  • Boost fee / boost amount: the VTHO cost of boosting, computed as remaining maturity blocks times the price per block.
  • Contract (smart contract): a program stored on the blockchain that runs automatically when called.
  • Control: a comparison case in a test, used to show that the behaviour differs between two situations.
  • Delegation: handing a staked position to a validator so it counts towards that validator's weight.
  • Function: a named action inside a program.
  • Griefing: an impact category where the attacker gains no money but damages users or the protocol.
  • Hardhat: a toolkit for building, deploying and testing blockchain programs.
  • Initialiser / reinitialiser: a setup function that fills in a contract's storage, often run once per version during an upgrade.
  • Integration test: a test that drives several parts of a system together rather than one unit in isolation.
  • Level: a staking tier with its own rules, such as the VET amount required and the maturity period.
  • Library: reusable code that a contract calls into to do part of its work.
  • Local network (solo network): a private copy of the blockchain running on one machine for testing.
  • Maturity period: the number of blocks that must pass after staking before delegation is allowed.
  • Mock: a stand-in that imitates a real component for testing.
  • NFT: a unique digital token; here it is the receipt for a staked position.
  • Role: a permission label that decides which accounts may call which functions.
  • Severity: a rating of how serious a finding is, here Low.
  • Staking: locking up cryptocurrency in return for a position in the network.
  • Storage: a contract's long-term memory; unset numeric slots read as zero.
  • Transaction: a signed instruction sent to the blockchain, which takes effect once confirmed.
  • Validator: a computer that helps run the network and can receive delegated stake.
  • VET / VTHO: the two tokens involved here; VET is staked and VTHO is used to pay the boost fee.
  • it.only: a test-framework marker that runs only the marked test.

More from Vechain | Stargate Hayabusa

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.