XChain VM: Configuration Reference

Constructor Parameters

The VM is configured at instantiation via a single config object:

const vm = new XChainVM({
    gasSchedule: config['GAS_SCHEDULE'],
    gasCeiling:  1000000,
    limits: {
        maxCpuTimeMs:      30000,
        maxMemory:         8,
        maxEmissions:      50,
        maxStateKeys:      10000,
        maxStateValueSize: 65536,
        maxCodeSize:       65536,
        maxStateKeySize:   1024,
        maxBlockCacheSize: 1000
    }
});
Parameter Type Default Description
gasSchedule object (required) Per-operation gas costs (see Gas Schedule below)
gasCeiling number 1000000 Maximum gas allowed per single contract execution
limits object (see below) Resource limits for isolate execution

The VM has no environment variables, configuration files, or runtime reconfiguration. All settings are fixed at construction time by the indexer. Being settable is not the same as being binding: limits.maxCpuTimeMs is accepted here but bounds only ungated (non-consensus) executions, because a consensus execution resolves its wall-clock budget from a protocol constant instead (see Resource Limits below). limits.maxStackDepth is not settable at all: the recursion bound is consensus-affecting, so the constructor overwrites any supplied value with the protocol constant and the isolate reads the constant directly. The constructor example above omits it, as the indexer does.

Gas Schedule

The gas schedule defines the cost of each metered operation. These values are set by the indexer’s unified gas fee configuration and passed to the VM at construction.

Operation Key Cost Description
Computation VM_COMPUTATION 1 Charged at each __gas() injection point (loop iterations, branches, function calls). Indexed for loops are charged twice per iteration: see note below
State read VM_STATE_READ 100 state.get(), state.has(), getBalance(), getTokenInfo(), getPollResult(), attestation.getResponse(), contract.getStake(), contract.getTotalStaked(), contract.getStakers()
State write VM_STATE_WRITE 200 state.set()
State delete VM_STATE_DELETE 100 state.delete()
Oracle read VM_ORACLE_READ 100 oracle.getPrice(), oracle.getPriceAtRound()
Cross-chain read VM_CROSSCHAIN_READ 100 crossChain.getAttestation(), crossChain.isSettled(), crossChain.getCallResult()
Action emission VM_EMISSION 500 Each emit.*() call (SEND, MINT, ORDER, etc.); also charged on attestation.request() and contract.slash()
Attestation request VM_ATTEST_REQUEST 5000 Additional fee on top of VM_EMISSION for attestation.request(): reflects the validator-network work that backs the eventual response
Cross-chain call request VM_XCALL_REQUEST 2000 Additional fee on top of VM_EMISSION for emit.crossExecute(); the federation relay work. The call also pre-pays its remote gasLimit plus VM_XCALL_CALLBACK, with no refund of unused remote gas
Cross-chain callback ceiling VM_XCALL_CALLBACK 20000 Fixed gas ceiling the result/expiry callback runs against on the source chain, pre-paid at emit.crossExecute() time

Context accessors (getBlockHeight, getSourceAddress, etc.), control flow (revert, require), and logging (log, isLogFull, getLogCount) are gas-free. oracle.getSnapshotAge() is also gas-free. Its value is consensus seconds at and after the snapshot-age seconds flag day (not yet pinned) and whole blocks before it, so a contract that compares it to a limit must state which unit the limit is in.

Indexed for loops cost 2 × VM_COMPUTATION per iteration. The metering transform injects a charge at the top of the loop body and a second charge into the update expression (for (…; i++) is rewritten as for (…; (__gas(1), i++))) so each iteration is metered twice. A for loop of N iterations therefore costs 2 × N × VM_COMPUTATION. while, do-while, for-in, and for-of loops have no update expression and cost 1 × VM_COMPUTATION per iteration. Budget gas ceilings for indexed for loops accordingly.

Resource Limits

Parameter Key Default Description
Gas ceiling gasCeiling 1,000,000 Maximum gas per execution. Primary execution bound.
Max call depth maxCallDepth (VM_MAX_CALL_DEPTH) 4 Maximum call depth for emit.execute trees. A user-submitted EXECUTE is depth 0; each emit.execute hop adds 1.
Min call gas minCallGas (VM_MIN_CALL_GAS) 5,000 Minimum gasLimit per emit.execute call. Bounds call-tree fan-out: every call costs at least VM_EMISSION + VM_MIN_CALL_GAS out of the caller’s budget.
Max stack depth maxStackDepth 512 Intra-contract recursion bound, injected into the isolate as __DEPTH_LIMIT. Consensus-affecting, so it is fixed: a supplied value is replaced by the 512 protocol constant (MAX_STACK_DEPTH), and changing vm.limits.maxStackDepth after construction has no effect. Once the gate is active (unconditional on testnet/regtest; per-coin heights on mainnet) the value is ignored and the bound is pinned to 256 (MAX_STACK_DEPTH_MUSL). The native-input depth guard is capped at 256 whatever this value is
CPU timeout maxCpuTimeMs 30,000 ms Wall-clock timeout for ungated (non-consensus) executions only: benches, fuzzing, the toolkit simulator, and pre-activation replay. A consensus execution ignores this knob (see the next row)
Consensus wall-clock budget CONSENSUS_MAX_WALL_MS 30,000 ms The wall-clock budget every consensus execution runs against. A protocol constant, not a node setting: it is unconditional on testnet and regtest, and on mainnet from the contract-era flag day (see Flag Days). Lowering maxCpuTimeMs on a live indexer does not tighten it
Memory maxMemory 8 MB V8 isolate heap size limit. Exceeding triggers out_of_memory error.
Emissions maxEmissions 50 Maximum platform actions a contract can emit per execution
State keys maxStateKeys 10,000 Maximum key-value pairs a contract can store
State value size maxStateValueSize 65,536 bytes Maximum size of a single state value (JSON-serialized)
State key size maxStateKeySize 1,024 bytes Maximum size of a single state key (UTF-8 encoded)
Code size maxCodeSize 65,536 bytes Maximum contract source code size (enforced at both deploy and execute)
Block cache size maxBlockCacheSize 1,000 entries Maximum compiled script entries cached per block

Consensus Wall-Clock Budget

Wall-clock time is the one limit in the table above that is not a node setting. Gas is the deterministic meter, but gas does not bound wall time: a contract can spend seconds of real time inside a single native operation while its gasUsed stays low, and for those shapes the wall-clock net, not the gas ceiling, is what ends the execution.

Both the status and the gasUsed that come out of a timeout are consensus-visible (gasUsed drives the fee debit and feeds the per-block contract checkpoint). So if each node picked that net for itself, two correctly running validators would commit different bytes for the same block: the node with the tighter budget returns timeout: wall-clock safety net triggered with gasUsed clamped to the gas ceiling, while the node with the looser budget commits the execution’s real state changes and its real gasUsed. That is a chain split produced by a configuration file rather than by a rule.

The rule that removes it:

One consensus contract execution runs against CONSENSUS_MAX_WALL_MS, a protocol constant of 30,000 ms, on every node. The node’s own limits.maxCpuTimeMs does not bind a consensus execution.

Activation is network-aware, matching the VM’s sibling gates:

Network When the consensus budget binds
testnet, regtest Always, from genesis. A pre-launch network has no pre-activation history to preserve.
mainnet From the contract-era flag day, whose block time is listed on Flag Days.
Unknown or unset Same threshold as mainnet, and a block time that is not a finite number resolves to pre-activation. The conservative default keeps replay byte-identical in malformed or test contexts.

Below the gate the node’s maxCpuTimeMs is used verbatim, so historical blocks replay byte-identically and non-consensus callers (benches, fuzzing, the toolkit simulator) keep their own tighter budgets.

The constant is pinned at the value the documented default configuration already used, 30,000 ms, so no execution on a default-configured node changes outcome at the gate. The bound closes a fork surface; it does not re-price the ceiling. Tightening it later is a consensus tightening and needs its own flag day, re-goldened determinism baselines, and an atomic fleet deploy. Lowering maxCpuTimeMs on a live indexer does not tighten what a consensus execution is allowed to spend, and raising it does not loosen it.

Additional Internal Limits

These limits are hardcoded in the VM and not configurable:

Limit Value Location
Log entries per execution 100 collector.js
Log entry size 1,024 bytes UTF-8 (truncated with ...(truncated) marker) collector.js
Return value size 65,536 UTF-16 code units (truncated) index/runtime/contract_io.js
Throwaway isolate memory 8 MB isolate.js, syntax.js
Binary expression metering depth 10 metering/visitor_instrumentation.js

The return-value cap is measured in UTF-16 code units, with String.length over the serialized value, not in UTF-8 bytes: a non-ASCII return at the cap can occupy up to roughly 196,608 UTF-8 bytes, so size a return against code units rather than the encoded size. Truncation is a UTF-16 substring, so a value cut in the middle of a surrogate pair ends with an unpaired surrogate. The log-entry limit directly above is genuinely byte-measured and is the contrasting case.

Bounded Execution Summary

Resource Limit Enforcement
Gas 1,000,000 per execution GasTracker throws GasExhaustedError
Memory 8 MB per isolate isolated-vm kills isolate
Wall-clock time 30 seconds script.runSync() timeout parameter, set to the resolved budget: CONSENSUS_MAX_WALL_MS for a consensus execution, the node’s maxCpuTimeMs only when ungated
Emitted actions 50 per execution EmissionCollector throws on overflow
State keys 10,000 per contract StateManager.set() throws on overflow
State key size 1 KB per key StateManager.set() / delete() throws on overflow
State value size 64 KB per value StateManager.set() throws on overflow
Code size 64 KB per contract Validated at deploy time and enforced at execution
Block cache 1,000 entries per block Excess entries skip cache (non-fatal)
Log entries 100 per execution EmissionCollector.addLog() silently drops

Gas is the primary execution bound. The wall-clock timeout exists only as a safety net for gas metering bugs; it should never trigger under normal operation. Its budget is a consensus quantity, not an operator setting: every validator runs a consensus execution against the same CONSENSUS_MAX_WALL_MS, so a node configured with a tighter maxCpuTimeMs cannot return a different status or a different gasUsed for the same execution.


Copyright © 2025–2026 Dankest, LLC

Based on XChain Platform by Dankest, LLC – https://dankest.llc

Licensed under the GNU Affero General Public License v3.0 (AGPL-3.0-or-later) with a commercial license available for proprietary use.

You may use, modify, and distribute this material under the terms of the License. See LICENSE and NOTICE for full terms. See the licensing overview.

Edit this page on GitHub ↗