Skip to content

Gas and limits

Gas is NDSR’s instruction fuel (about one unit per bytecode operator; structural operators such as block and end are free) plus fixed costs for host calls. Every executed function call also costs 12 gas for the injected stack-limit check.

Host function Cost
console.log 100 + 1 per byte
hive.emit 500 + 2 per byte (name + data)
crypto.hash 200 + 1 per byte
storage.get 1,000 + 1 per byte of key + 1 per byte of value returned
storage.set 5,000 + 10 per byte of key + value
storage.del 2,000 + 1 per byte of key
hive.call 10,000 + 1 per byte (address + function + input) + instantiation (16 per initial memory page, 1 per table element, 1 per data-segment byte) + compilation on the first call to a module (4 per code byte) + the callee’s gas + 1 per byte of output

Costs above are those of execution revision 2, live today. Revision 3 adds rows and reprices crypto.hash: see below.

  • gas_used on success or trap = what was consumed. Out of gas charges the full limit and fails the call. A module rejected by validation uses 0.
  • hive.call hands all remaining gas to the callee and charges what it used on every path.
  • One execution may load at most 8 distinct modules through hive.call (the calling module itself and repeat calls to a module already loaded do not count). Calling a 9th distinct module traps the caller.
  • Gas is checked at function entries, loop headers and host calls. A call may therefore finish a short loop-free stretch slightly past its limit and report gas_used = gas_limit. This is deterministic, so it does not affect agreement.
Host function or charge Cost
crypto.verify_ed25519 235,000 + 9 per byte of message
crypto.ecrecover_secp256k1 780,000
crypto.keccak256 2,500 + 15 per byte
crypto.sha256 1,700 + 17 per byte
ctx.time, ctx.kind, ctx.gas_left 100
ctx.caller, ctx.origin, ctx.module_address, ctx.round_id, ctx.network 1,300 + 1 per byte returned
ctx.call_id 200
hive.emit_indexed 500 + 2 per byte (name + data + topics) + 1,000 per topic
crypto.hash (repriced) 4,300 + 15 per byte (revision 2: 200 + 1 per byte)
Signed call, charged once before the module starts ed25519 240,000; eip191 790,000; plus 6,000 for the nonce (not for read-only calls)
  • crypto.hash repricing. Measured against the same reference as the new functions, the revision 2 price of crypto.hash was about 20× too low in base cost and 15× per byte. Under revision 3 it costs 4,300 + 15 per byte, so gas_used, and therefore the receipt, of any execution that calls crypto.hash changes once revision 3 is active. Its output is unchanged. Use crypto.keccak256 (2,500 + 15 per byte, raw 32 bytes, no hex encoding) in new code. Every other existing cost is unchanged.
  • Signed calls pay their verification up front: an eip191 call with a nonce costs 796,000 gas before the first instruction runs, an ed25519 call 246,000. Set gas_limit to at least that plus what the function needs; a lower limit is rejected with 400 before execution. A nonce mismatch fails with gas_used equal to this charge. Signed calls
  • Pricing basis: 3 gas per nanosecond of native work (the fastest wasm throughput measured on the reference host) with a 25 % margin, measured on the slowest validator class (Linux x86-64), so a module cannot make a validator do more work per gas with the crypto functions than with plain code. Compared with verification in module code, ed25519 drops from about 2.5 M to 235,000 gas and secp256k1 recovery from about 9.6 M to 780,000 (both about 11–12× cheaper).
  • ctx.random, ctx.beacon and eip712 signed calls are deferred to a later revision and have no price.
Module Call Gas
Rust addNumbers 10,570
Rust counter increment (storage + event) 18,671
AssemblyScript counter increment 12,305
Go (TinyGo) addNumbers 91,204
Go ledger.record (hive.call + storage + event) 488,464
Rust oracle aggregate, 4 reports 69,709
Rust EIP-191 signature recovery in module code (attestation example, revision 2) 9,630,772
JavaScript engine counter increment 2,557,020
Python counter get about 10 M
Where Default gas_limit Maximum
ndsr run 1,000,000 10^10 (node --max-gas)
hivec run (Rust, Go) 1,000,000
hivec run (JavaScript, Python SDKs) 1,000,000,000
POST /v1/execute 1,000,000 50,000,000
Committee tasks the project’s max_gas_limit 10^10

For committee tasks, each verified vote earns max(1, ceil(gas_used / gas_per_unit)) compute units, with gas_per_unit = 1,000,000 on the testnet. A task that uses 89k gas earns 1 unit per correct miner; one that uses 9.6M gas earns 10. See Reward epochs.

All nodes on a network enforce the same limits (they are consensus parameters).

Limit Value
.hbc file 16 MiB
module.wasm 12 MiB
manifest.json 64 KiB
Linear memory per instance 64 MiB (memory.grow beyond returns −1)
Table elements 100,000
Input / output per call 1 MiB / 1 MiB (output must be valid UTF-8)
Events per call 64
Event name / data 64 bytes / 16 KiB
Event topics (hive.emit_indexed, revision 3) 0–4 × 32 bytes
Signed call validity (expires_at − issued_at, revision 3) at most 600 s
Storage key / value 256 bytes / 64 KiB
State written per top-level call (keys + values) 1 MiB
console.log per message 4 KiB
hive.call depth 8
Logical stack 65,536 units per instance
/v1/execute request body 256 KiB
Task input (/v1/projects/{id}/tasks) 1 MiB