Skip to content
Audit finding Beginner

Unnecessary Call to Get Balance In MintingLogic::boostOnBehalfOf()

The boostOnBehalfOf function reads the user's VTHO balance twice, once into a local variable and again in the condition check. This causes a small, avoidable gas overhead and code verbosity, but no functional vulnerability.

JJSOnChain Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

59993 sc insight unnecessary call to get balance in mintinglogic boostonbehalfof

Submitted on Nov 17th 2025 at 12:46:06 UTC by @JJSOnChain for Audit Comp | Vechain | Stargate Hayabusa

Description

Brief / Intro

The boostOnBehalfOf() function redundantly fetches a user's VTHO balance twice, increasing code verbosity and causing a small, avoidable gas overhead.

Vulnerability Details

In boostOnBehalfOf(), the code retrieves the balance into a local variable, then calls balanceOf again when checking the required boost amount:

Solidity
uint256 balance = $.vthoToken.balanceOf(_sender); 
// check that the boost amount is enough
if ($.vthoToken.balanceOf(_sender) < requiredBoostAmount) { // @audit-info - could simply use `balance`
    revert Errors.InsufficientBalance(
        address($.vthoToken),
        _sender,
        requiredBoostAmount,
        balance
    );
}

Since the balance was already fetched into balance, the second call to $.vthoToken.balanceOf(_sender) is redundant. The condition can (and should) use the already-read balance variable to avoid the extra external call.

Impact Details

This results in an unnecessary external call to the token contract, increasing transaction gas slightly and adding verbosity to the code. While not a functional vulnerability, it is an efficiency and code-quality improvement to consolidate to a single balance read.

Proof of Concept

<details> <summary>Code excerpt (from packages/contracts/contracts/StargateNFT/libraries/MintingLogic.sol around Line 116)</summary>
Solidity
function boostOnBehalfOf(
    DataTypes.StargateNFTStorage storage $,
    address _sender,
    uint256 _tokenId
) external {
    // check that the token is not already boosted
    if ($.maturityPeriodEndBlock[_tokenId] <= Clock._clock()) {
        revert Errors.MaturityPeriodEnded(_tokenId);
    }

    uint256 requiredBoostAmount = _boostAmount($, _tokenId);

    uint256 balance = $.vthoToken.balanceOf(_sender);   // <--- first read
    // check that the boost amount is enough
    if ($.vthoToken.balanceOf(_sender) < requiredBoostAmount) {  // <--- redundant second read
        revert Errors.InsufficientBalance(
            address($.vthoToken),
            _sender,
            requiredBoostAmount,
            balance
        );
    }
    ...
}

Suggested minimal fix: use the previously read balance in the if condition:

Solidity
if (balance < requiredBoostAmount) {
    revert Errors.InsufficientBalance(
        address($.vthoToken),
        _sender,
        requiredBoostAmount,
        balance
    );
}
</details>

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

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 code calls balanceOf again instead of using the already-fetched balance variable.

Impact

This results in an unnecessary external call to the token contract, increasing transaction gas slightly and adding verbosity to the code; it is not a functional vulnerability.

What the attacker needed

None

The fix

The code should be fixed by using the previously read balance variable in the condition instead of calling balanceOf again.

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.

This is a code quality issue, not a security bug. The function asks the token contract for the same balance twice instead of reusing the first answer, which wastes a little gas. Gas is the fee paid to run code on a blockchain.

More from Vechain | Stargate Hayabusa

View all

The newest disclosed reports for this program.

Similar reports

Same bug class and techniques, clearest first.