Skip to content
DoS Audit finding Advanced

Brittle, Hardcoded Gas Metering Model

The report argues that native contract wrappers charge gas through manually pre-calculated hardcoded calls rather than dynamic metering, so a refactor of the underlying storage logic could leave operations mis-priced. The author claims this could open a gas-based denial-of-service vector, but no exploit is demonstrated.

rionnaldi Follow

Originally disclosed on Immunefi

Informational View original
  • Disclosed after under an hour

56187 bc insight brittle hardcoded gas metering model

Submitted on Oct 12th 2025 at 12:42:33 UTC by @rionnaldi for Attackathon | VeChain Hayabusa Upgrade

Description

Brief / Intro

All native functions in this file use a static, hardcoded gas metering model. The Go code makes an explicit env.UseGas() call with a manually pre-calculated gas cost. This pattern is brittle and a significant source of long-term maintenance risk.

Vulnerability Details

This design tightly couples the gas accounting logic (in the _native.go wrapper) to the business logic (in the underlying authority.go implementation). If a developer refactors Authority.Native(...).Get() to use one or three SLOADs instead of two, they must remember to find and update this UseGas call. Forgetting to do so will cause the operation to be mis-priced, leading to a potential gas-based DoS vector.

This is an inferior pattern compared to the dynamic gascharger model used in the Staker contract, where the gascharger object is passed down and gas is consumed dynamically as storage operations occur. The gascharger model correctly decouples accounting from logic.

Impact Details

This pattern makes refactoring and maintaining code more error-prone because developers need to remember and update the UseGas call whenever underlying storage or computation changes.

Recommendation

Create a long-term plan to refactor the Authority, Energy, and other older built-in contracts to use the gascharger model. Suggested migration steps:

{% stepper %} {% step %}

Create a metered constructor

Create a NativeMetered constructor for the Authority contract that accepts a *gascharger.Charger. {% endstep %}

{% step %}

Pass a charger into core logic

Pass the charger into the core logic functions (Add, Revoke, Get, etc.) so the core can consume gas as operations (e.g., SLOAD, SSTORE) are performed. {% endstep %}

{% step %}

Remove hardcoded UseGas calls

Remove all hardcoded env.UseGas() calls and have the underlying storage abstractions charge gas dynamically via the charger. {% endstep %} {% endstepper %}

Benefit

  • Reduces Risk of Bugs: Decouples gas logic from business logic, making it impossible to forget to update gas costs during a refactor.
  • Improves Maintainability: Simplifies the code and makes it easier and safer to modify.
  • Standardizes Architecture: Creates a single, robust gas accounting model across all built-in contracts.

References

https://github.com/vechain/thor/blob/release/hayabusa/builtin/authority\\_native.go

https://github.com/vechain/thor/blob/release/hayabusa/builtin/staker\\_native.go

Proof of Concept

builtin/authority_native.go:

{% code title="authority_native.go" %}

Go
		{"native_get", func(env *xenv.Environment) []any {
			var nodeMaster common.Address
			env.ParseArgs(&nodeMaster)

			env.UseGas(thor.SloadGas * 2) // Manually calculated gas cost
			listed, endorsor, identity, active, err := Authority.Native(env.State()).Get(thor.Address(nodeMaster))
			}
		}

{% endcode %}

List of files using this pattern: authority_native.go, energy_native.go, extension_native.go, params_native.go, prototype_native.go

The original report as published on Immunefi, by rionnaldi. 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 gas cost for native contract calls is hardcoded in the wrapper layer, decoupled from the storage operations actually performed by the underlying logic.

Impact

If the underlying logic is refactored without updating the hardcoded cost, operations could be mis-priced, which the author says may create a gas-based denial-of-service vector; no exploitation is shown.

What the attacker needed

None

The fix

The older built-in contracts should be refactored to accept a gas charger object so gas is consumed dynamically as storage operations occur, removing the hardcoded calls.

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.

Smart contracts on this chain pay 'gas', a fee for the computing work each operation costs. Here the fee for some built-in functions is written by hand as a fixed number instead of being counted as the work actually happens, so if the code underneath changes and nobody updates the number, users could be charged the wrong amount. The report is a design warning, not a working attack.

What is DoS?

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.

More by rionnaldi

View all

2 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.

Denial of service

The lesson behind this report.

A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.