Skip to content
Business logic Audit finding Advanced

During the call to native_issuance, there's a missing gas charge before call to CalculateRewards

The native_issuance call reads storage through CalculateRewards without first charging the storage-read gas, so the call is undercharged. An attacker could call the exposed issuance() function and pay less gas than the protocol's intended accounting for those reads.

emarai Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

56513 bc insight during the call to native issuance there s a missing gas charge before call to calculaterewards

Submitted on Oct 17th 2025 at 06:55:44 UTC by @emarai for Attackathon | VeChain Hayabusa Upgrade

Description

Brief/Intro

The call to staker_native::native_issuance is followed by a call to Energy.Native(env.State(), env.BlockContext().Time).CalculateRewards(staker), which reads from storage. Any read from storage should be preceded by charger.Charge(thor.SloadGas); otherwise the call to native_issuance is cheaper than it actually needs to be.

Vulnerability Details

In builtin/staker_native.go line 445 the native_issuance implementation calls CalculateRewards without a prior gas charge:

Go
{"native_issuance", func(env *xenv.Environment) ([]any, error) {
    charger := gascharger.New(env)

    staker := Staker.NativeMetered(env.State(), charger)
@>    issuance, err := Energy.Native(env.State(), env.BlockContext().Time).CalculateRewards(staker)
    if err != nil {
        return nil, err
    }
    return []any{issuance}, nil
}}

The CalculateRewards function in builtin/energy/energy.go (around line 341) performs storage reads such as e.params.Get(thor.KeyCurveFactor) and staker.LockedStake(). Each of these storage reads should incur thor.SloadGas. Because these reads are not preceded by a gas charge in the native call, the native call is undercharged. The gas charged should be 400 instead of 200 (see PoC).

Relevant snippet from CalculateRewards:

Go
func (e *Energy) CalculateRewards(staker staker) (*big.Int, error) {
@>    totalStaked, _, err := staker.LockedStake()
    if err != nil {
        return nil, err
    }
    // sqrt(totalStaked in VET) * 1e18, we are calculating sqrt on VET and then converting to wei
    sqrtStake := new(big.Int).Sqrt(new(big.Int).SetUint64(totalStaked))
    sqrtStake.Mul(sqrtStake, bigE18)

@>    curveFactor, err := e.params.Get(thor.KeyCurveFactor)
    if err != nil {
        return nil, err
    }
    if curveFactor.Uint64() == 0 {
        curveFactor = thor.InitialCurveFactor
    }

    // reward = 1 * curveFactor * sqrt(totalStaked / 1e18) / blocksPerYear
    reward := big.NewInt(1)
    reward.Mul(reward, curveFactor)
    reward.Mul(reward, sqrtStake)
    reward.Div(reward, thor.NumberOfBlocksPerYear)
    return reward, nil
}

Impact Details

Gas for native calls is cheaper than it should be; the native call is exposed via the generated staker.sol contract's issuance() function:

Solidity
function issuance() external view returns (uint256 issued) {
    return StakerNative(address(this)).native_issuance();
}

This means external callers (or contracts) invoking issuance() may pay less gas than the protocol's intended accounting for storage reads, altering transaction-fee behavior relative to design.

References

Proof of Concept

<details> <summary>PoC: modify test to demonstrate missing gas charge</summary>

Change the following line in builtin/staker_native_gas_test.go, then run the test:

Command: go test -timeout 30s -run ^TestStakerNativeGasCosts$ github.com/vechain/thor/v2/builtin

Patch:

Diff
--- a/builtin/staker_native_gas_test.go
+++ b/builtin/staker_native_gas_test.go
@@ -236,7 +236,7 @@ func TestStakerNativeGasCosts(t *testing.T) {
                },
                {
                        function:    "native_issuance",
-                       expectedGas: 200,
+                       expectedGas: 400,
                        description: "Get issuance for the current block",
                },
        }

The test will fail because the code did not charge for the additional storage read (e.params.Get(thor.KeyCurveFactor)), demonstrating the undercharge.

</details>

The original report as published on Immunefi, by emarai. 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

Likely the native_issuance handler calls CalculateRewards, which performs storage reads, without first calling charger.Charge(thor.SloadGas) for those reads.

Impact

External callers or contracts invoking issuance() may pay less gas than the protocol's intended accounting for storage reads, altering transaction-fee behaviour relative to design.

What the attacker needed

Ability to call the issuance() function

How it was found

  1. Modify the expected gas for native_issuance in the gas cost test from 200 to 400.
  2. Run the staker native gas cost test.
  3. Observe the test fails, showing the storage read was not charged.

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.

Every operation on a blockchain costs a small fee called gas, and reading saved data (storage) has its own gas price. Here a function read saved data but the code forgot to add that read's gas cost, so calling it was cheaper than intended. The report is about a small fee-accounting mistake, not a way to steal funds.

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 emarai

View all

3 more disclosed reports, best first.

More from VeChain Hayabusa Upgrade

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.