SourceLess · AsgardAsgard · chain 1313

Part III · Building on the chain · Chapter 6 of 15

Hephaestus — the AresLang standard library

Hephaestus, the standard library of AresLang, the SourceLess contract language, function by function, with what each one takes.

40,722 bytes 6,605 words newest date 2026-08-30

Corrections (1) · Closed or struck (6)

Verify: the published bytes are in the raw file ARESLANG_STDLIB.md, whose SHA-256 is in SHA256SUMS.
153f0045b4137f0b8792527733294771b71923590e097cb5c0ccf06f199a458f

Corrected, date not recorded 1 of 7 Next

Date: 2026-08-30 Status: specification, then implementation. Withdrawn: The library described here is not built. It is. stdlib/ ships index.ts, source.ts, access.ts, pausable.ts, math.ts, text.ts, time.ts, value.ts and gas.ts, covered by tests/integration/hephaestus.integration.test.ts (53 tests), and compose / composeSource are the delivery mechanism — which is neither of §7's two, see §8. Read §1–§7 as the design argument this document was written to be and the errata at the end as the current state; where they disagree, the errata is right.

Closed, date not recorded 2 of 7 Next

House name: Hephaestus — Greek, the smith who forged the armour of Ares. AresLang is already named for the god; the library is the forge that arms him. Closed: A registry entry in NAMING.md is owed and is not written yet. Written: docs/NAMING.md:76 carries it, and records the boundary the name draws — this is source an author composes at build time, not chain state and not consensus code.


0. How to read this document#

Every item carries one of three marks, and nothing is written without one.

MarkMeaning
TodayWritable in AresLang as the language stands in runtime/ right now. Every "Today" claim below was compiled and executed against the built runtime before it was written down.
In flightDepends on work another agent is doing now: maps, loops, safe arithmetic, and the AresHost context/value interface. Not available, and stated as unavailable.
ProposalNeither built nor in flight. Something this document argues for. A proposal is a request to a future author, not a fact about the tree.

Gas figures marked measured were produced by running the code through AresLangVM and reading gasUsed. Figures marked counted were derived by adding the published per-opcode costs over the instruction stream the compiler emits. Nothing here is estimated.


0.1 The runtime moved while this document was being written#

Everything marked measured below was run against the built v1 runtime: 26 opcodes, ARES_BYTECODE_VERSION = 1. While it was being written, the runtime owner landed the v2 container in runtime/bytecode.ts:

v2: maps (MLOAD/MSTORE), checked unsigned subtraction (SUBU), string ops (CONCAT/LEN),
    and the host surface (SELF/TIMESTAMP/HEIGHT/BALANCE/TRANSFER).

and the parser now reserves map while for in self timestamp height.

What that changes, and what it does not. Re-checked after the first draft: the v2 work is further along than "opcodes exist in a container". runtime/compiler.ts emits MLOAD, MSTORE, SUBU, SELF, TIMESTAMP and TRANSFER; while and for are compiled; and runtime/vm.ts carries a complete v2 gas table with its reasoning written down:

OpcodeGasOpcodeGas
TRANSFER2100LOAD50
BALANCE400CONCAT6 + 1 per 32 code units of result
MSTORE220REQUIRE5
STORE200SUBU3
EMIT100LEN / SELF / TIMESTAMP / HEIGHT2
MLOAD55everything else1

plus 20 gas on every backward jump, which is what makes non-termination a metered revert rather than a hung node. The host is implemented by Nidavellir in src/core/contract-state.ts, and a VM constructed without a host refuses the host opcodes rather than answering them with a default.

The v1 numbers in this document are still correct for v1 opcodes, which is most of what the library is built from. Nothing below was re-measured after the v2 landing.

Two items in §5 move as a result, and are corrected in place rather than left standing:

  • SUBU is checked unsigned subtraction. It makes the §5.1 sub routine a single opcode instead of a four-instruction guarded idiom, and it moves underflow protection from L3 to L1. §2.1 still describes what a bare SUB does, because SUB still exists and a contract that uses it still gets a negative uint.
  • Maps, loops, the host surface and string primitives are present and priced, not absent. Wherever §5 below says a thing cannot be written, read it as a statement about the v1 runtime this document was measured against. The boundary argument in §4 is unaffected and is in fact confirmed: the runtime owner put every one of those capabilities in the layer §4 argues for.
  • §5.7's third bullet is out of date twice over, and both corrections are consensus rules. It says a contract cannot receive native STR at all. A deployed contract is now a legal transfer recipient (contracts.has, answered from the deployed set), and separately an address with no STR.domain at all is now a legal recipient too — see CONTRACT_TEMPLATES.md §2 and docs/book/LEDGER_AND_STATE.md §2.2.1. Both directions are solved. What is still refused, on both paths, is a Hnitbjorg account.

1. Why the library exists, and why it cannot be a library contract#

The requirement is that a contract author never has to import anything from outside SourceLess. On most chains that is met by publishing library contracts and having user contracts delegate-call into them.

That is not available here, and will not be soon. Three facts, all checkable in runtime/:

  1. There is no call opcode. The 26 opcodes in bytecode.ts are stack, arithmetic, comparison, storage, locals, jumps, REQUIRE, EMIT, CALLER, RET, HALT. Nothing transfers control to another module.
  2. There is no call expression either. parsePrimary in runtime/parser.ts accepts an integer, a string, a boolean, an identifier, caller, a unary operator, or a parenthesised expression. f(x) is a syntax error. A contract cannot call its own second function, let alone somebody else's contract.
  3. contracts/executor.ts states the rule the whole design rests on: "There is still no host-callback path: a contract can only do what its own bytecode does."

So a Hephaestus "function" that a user contract calls at runtime cannot exist. The library must be expanded into the calling contract at compile time, or it is not a library.

The failure this prevents. If the library were shipped as deployable contracts on the assumption that a call mechanism arrives later, every contract deployed in the meantime would either be dead code or would have to be redeployed at a new address — and a contract's address binds its bytecode (deriveContractAddress), so "redeploy" means "a different contract", and every holder of a balance in the old one has to be migrated by hand.


2. The language as it stands today#

Stated exactly, so nothing below over-promises.

Typesuint, int, bool, address, string
Keywordscontract state event fn view let return if else require emit true false caller
Statementslet, assignment, return, if/else, require, emit
Operators+ - * / %, == != < > <= >=, &&, or, !, unary -
Opcodes26
Loopsnone
Maps and arraysnone
Function callsnone, including to the contract's own functions
Cross-contract callsnone
Native value transfernone
Block time, height, self addressnone
Hashingnone
String operationsnone — not concatenation, not length, not indexing, not ordering

Three properties of the runtime that a library author must know, because two of them are usually assumed the other way round.

2.1 There is one integer type at runtime, and it is arbitrary precision#

uint and int are a compile-time annotation and an ABI-boundary check. validateArgs in src/core/contract-state.ts refuses a negative argument to a uint parameter. Nothing refuses a negative value stored in a uint slot.

contract Unsafe {
  state total: uint = 10;
  fn take(amount: uint) -> uint { total = total - amount; return total; }
}

take(25)  ->  success: true   return: -15   slot 'total' = -15          [measured]

That is the single most important fact for the arithmetic module. AresLang does not wrap. There is no 2^256 modulus and therefore no addition overflow of the Solidity kind. The arithmetic hazard here is the opposite one: unsigned underflow silently produces a negative balance, and a require(a >= b) before every subtraction is the whole of the defence.

2.2 Arithmetic has a width ceiling instead of a wrap#

MAX_INTEGER_BITS is 4096. A result wider than that reverts rather than truncating.

let x = n*n; let y = x*x; let z = y*y;      with n = 2^600
->  reverted: "integer of 4801 bits exceeds the limit"                  [measured]

A multiplication that would overflow on another chain is a revert here, not a corrupt value. Loss of funds by multiplicative overflow is not reachable. Denial of service by building enormous integers is, which is why width is also charged for.

2.3 A revert is total#

AresLangVM.run reads through the committed storage and writes only into its own write-set, which it discards on any revert; SindriLedger commits the write-set only on success. A contract does not need to unwind anything by hand, and a half-applied state change is not a failure mode that exists here.


3. The price list#

Per-opcode gas, from runtime/vm.ts:

OpcodeGas
STORE — write a state slot200
LOAD — read a state slot50
EMIT — one event100
REQUIRE5
every other opcode, including LLOAD / LSTORE on locals1
surcharge on ADD / SUB / MUL when the result exceeds 64 bits1 + ceil(bits/64), on top of the opcode's own 1

Bounds: gas limit 1,000,000 by default; stack 1,024; integers 4,096 bits; syntax tree 256 levels deep.

Two consequences shape every idiom in this document:

  • A state read costs fifty times a local read. let bal = total; costs 51 (LOAD 50 plus LSTORE 1), and every later use costs 1. Reading the same slot three times costs 150. Bind once.
  • A state write costs 200; a guard costs 5 to 57. Guards are cheap relative to the work they protect. There is no economic argument for omitting one.

3.1 Gas is not a fee, and the 10% ceiling is a real constraint#

SourceLess charges the caller nothing. postMineForContractRecord mints STR into the Feeless Pool to cover the execution, at EXECUTION_COST_MINOR_PER_GAS = 1 minor STR per gas — and computePostMining caps the mint at 10% of the "transaction amount", which for a contract call is the declared gas limit:

minted = min(gasUsed, gasLimit / 10)

Declare a gas limit of at least ten times your expected use. A call that declares 100,000 and burns 50,000 is covered to 10,000; the other 40,000 is reported as uncoveredMinor and nobody pays it. This is not a user-visible failure — the call still succeeds — but it is the network absorbing an unfunded cost, and a template that systematically under-declares its limit quietly drains the fee-free model. Every template in CONTRACT_TEMPLATES.md states a recommended limit for this reason.


4. The boundary: three layers, and why each item sits where it does#

LayerWhat lives hereWhy
L1 — VM / opcodeanything a bytecode sequence cannot produce from its own inputsA contract can only do what its bytecode does. Facts about the world — the time, the height, its own address, another account's balance, a hash — are not derivable from the stack.
L2 — compileranything that is pure AresLang semantics but needs an expansion mechanism the language does not haveThere is no call opcode, so a shared routine has to be inlined, and the compiler is the only thing positioned to inline it.
L3 — AresLang sourceeverything elseIf it can be written in the language it should be, because then it is auditable as source by the person deploying it and nothing has to be trusted underneath.

The rule that decides the boundary: put it in the VM only when no bytecode could compute it. A VM opcode is code every node must run identically forever and cannot be changed without a fork. An inlined AresLang routine is code the deployer can read in their own contract.

Applying the rule:

CapabilityLayerWhy it cannot be lower
Checked subtraction, cap checks, comparisonsL3require and >= already exist. Nothing is missing.
Ownable, roles over a fixed slot set, pausableL3caller, require, a state slot. Nothing is missing.
Reentrancy guardL3A bool slot and a require.
A shared, non-duplicated version of the aboveL2No call opcode; the routine must be textually present in the caller.
Address well-formednessL1 or ABIzk13str_<40 hex>_<4 hex> needs string length, slicing and SHA-256. AresLang has none of the three, and computing a checksum in-contract at roughly ten opcodes per character would be absurd. This belongs in validateArgs, before a single opcode runs.
Map / keyed storageL1A map key is a hash of a key and a slot name. There is no hashing opcode and no string concatenation, so a map cannot be expressed. In flight.
LoopsL1 for metering, L2 for syntaxJMP / JZ exist; the parser has no loop form and the compiler emits no back edges and no bounded-iteration metering. In flight.
blockTimestampMs, blockHeight, selfAddressL1Host facts. No bytecode can derive them. In flight, behind AresHost.
balanceOf, transferL1Host facts and host effects. In flight, behind AresHost.
String concat / length / compareL1The VM's only string operations are EQ, NEQ, and a truthiness test that reads length. Proposal.

5. The modules#

5.1 math — arithmetic that cannot go quietly wrong#

Why it exists. Not overflow — AresLang does not wrap. Underflow. A uint slot will hold a negative number (§2.1), and every token, escrow and staking balance in CONTRACT_TEMPLATES.md is one subtraction away from that.

RoutineRuleLayerGas
sub(a, b)require(a >= b) then a - bL3counted 11 over locals: LLOAD 1, LLOAD 1, GTE 1, REQUIRE 5, LLOAD 1, LLOAD 1, SUB 1
add(a, b)plain a + b—1, plus any width surcharge. No guard, and the guard is refused: there is nothing to guard against, and a require(c >= a) after an addition that cannot wrap teaches an author that the check is what makes it safe.
mulCapped(a, b, max)a * b, then require(result <= max)L3counted 8 on top of the multiply
div(a, b)plain a / b—1. The VM already reverts on a zero divisor. A wrapper adds 8 gas and no safety.
mod(a, b)plain a % b—1. Same.
requireFits(x, max)require(x <= max)L3counted 8

Two honesty notes:

  • Division truncates toward zero, not toward negative infinity. -7 / 2 is -3, not -4, because that is BigInt division in the host. For uint quantities this never matters. For int it does, and a template doing signed division must say which rounding it means rather than leaving a reader to assume.
  • mulCapped is not an overflow check. The overflow ceiling is the VM's 4096 bits, and a contract that reaches it reverts with a runtime message rather than the author's. A cap check exists so a token cannot exceed a declared supply — a different rule, with a different message, at a different place.

Worked example, measured, compiled and run against the built runtime:

fn withdraw(amount: uint) -> uint {
  require(caller == owner, "not owner");
  require(total >= amount, "underflow");
  total = total - amount;
  return total;
}

withdraw(10) against total = 5  ->  reverted "underflow", 115 gas, state untouched

5.2 access — who may call#

Ownable — Today. This works in the language as it stands, and it is the one idiom that is already complete:

contract Vault {
  state owner: address = caller;     // set at deployment, to the deployer
  fn setPaused(next: bool) { require(caller == owner, "not owner"); ... }
}

state owner: address = caller; compiles to CALLER, STORE(owner) inside the compiler-generated __init, and SindriLedger.applyDeploy runs __init with caller = deployer — after authenticating the deployer, deliberately, because "an unauthenticated deployer is an unauthenticated CALLER inside the initializer, where state ownership is usually set."

IdiomGas
initialise one state slot at deploy200 for the STORE, plus 1 for the value. Measured: a three-slot __init costs 604
require(caller == owner, ...)counted 57 = CALLER 1 + LOAD 50 + EQ 1 + REQUIRE 5. Measured: a rejected owner-gated setter costs 58 end to end
an owner-gated setter that succeeds and emits one eventmeasured 362
a view accessor comparing an argument to a state slotmeasured 54

caller means something only in signed mode. SindriLedger defaults to signed, where the caller presents a public key that derives to the claimed address and a signature over that exact call, with that exact nonce, bound to that chain's genesis hash. In unauthenticated-local mode the caller is a string the caller chose. Every access-control idiom in this document is worth exactly nothing in the second mode, and the mode is a property of the ledger, not of the contract. A template cannot defend against being deployed onto an unauthenticated ledger and should not pretend to.

Two-step ownership handover — Today, and required.

state owner: address = caller;
state pendingOwner: address = "";

fn proposeOwner(next: address) {
  require(caller == owner, "not owner");
  require(next != "", "owner cannot be empty");
  pendingOwner = next;
}

fn acceptOwnership() {
  require(caller == pendingOwner, "not the pending owner");
  emit OwnerChanged(owner, caller);
  owner = caller;
  pendingOwner = "";
}

Gas: proposeOwner counted 266 (guard 57, non-empty check 8, STORE 200, HALT 1). acceptOwnership counted 561 (guard 57, EMIT 100 with a LOAD 50 and a CALLER 1 and a PUSH 1, two STOREs at 200 each, a CALLER 1 and a PUSH 1, HALT 1).

The failure a one-step handover causes has no fix. owner is storage, code is immutable, and there is no administrator anywhere in SourceLess who can reach into a contract's slots — SindriLedger exposes no write path that is not a call to the contract's own bytecode. A setOwner to a mistyped address is permanent, and §5.6 shows that a mistyped address is currently accepted at the ABI boundary.

Roles — needs maps. Today a role is a named slot: state minter: address;, state pauser: address;. That is genuinely sufficient for a small fixed set of roles and should be offered as such, because it costs 57 gas to check and needs nothing that does not exist. A general hasRole(role, account) needs a map and is in flight. A template must not present a fixed three-slot scheme as a role system that scales: the code is immutable, so "not extensible" is permanent and has to be said out loud at deployment time.

5.3 pausable — Today#

state paused: bool = false;
// at the head of every mutating function:
require(!paused, "paused");
IdiomGas
the require(!paused) guardcounted 56 = LOAD 50 + NOT 1 + REQUIRE 5
pause() / unpause() with an owner guard and an eventcounted 358; the equivalent setter measured 362

Rules a compliant pausable must obey, each naming what it prevents:

  • A view function is never paused. Pausing reads makes a stuck contract unauditable at exactly the moment somebody needs to audit it. It also costs nothing to honour: view functions are enforced non-mutating at execution time by Sindri, not only at compile time.
  • Unpause is never gated more strictly than pause. A pauser who cannot unpause is a denial-of-service key. If pause is delegated to a fast-acting operator, unpause may be gated to the owner; never the reverse.
  • Pause is not a freeze on one holder. Selective freezing is a distinct, confiscation-adjacent power. See ZK13_TOKEN_STANDARD.md §6.

5.4 reentrancy — a guard for a hazard that does not exist yet#

Today, reentrancy is not reachable. There is no cross-contract call and no value transfer, so nothing inside a call can hand control to code that calls back in. A guard today costs 460 gas (measured: entry check, set, clear) and defends against nothing.

It becomes real the moment AresHost.transfer lands, because a transfer is the point at which the contract stops being the only thing running.

Two properties worth writing down now, before the pattern is copied from another chain:

  • The guard cannot get stuck. On any revert the VM discards its write-set and Sindri commits nothing, so a guard set at entry to a call that then reverts is not persisted. Contracts on chains with partial-revert semantics need a release path; this one does not. Component costs: entry check 56, set 201, clear 201.
  • Checks-effects-interactions remains the primary rule and the guard is the backstop. Write the balance down before the transfer, never after. A guard is one bool an author can forget on one function; ordering is a property of every function that has it.

Proposal. The safest form is not a user-space guard at all but a VM rule: a contract may not be re-entered while a frame of it is on the stack. That is enforceable where call frames are tracked, cannot be forgotten by an author, and costs zero gas. It belongs to whoever implements the call opcode. State the cost honestly: it also forbids legitimate same-contract recursion. Since AresLang has no function calls at all today, nothing is lost by forbidding it now and relaxing it later, and the reverse order is not available.

5.5 token — the ZK13 interface#

Signatures, event shapes, compliance rules and the ban list are in ZK13_TOKEN_STANDARD.md. Hephaestus contributes only the implementation aids: checked subtraction, the ownable and pausable idioms above, and the supply-cap check.

One thing to record here: a token needs maps, and maps are in flight. A fungible token over arbitrary holders cannot be written in AresLang today, and no arrangement of existing features gets around it. Any catalogue entry claiming otherwise is claiming a fixed, compile-time-known holder set, which is not a token.

5.6 strings and addresses — mostly absent, and the gap is the point#

AresLang's entire string capability is: string literals, ==, !=, and truthiness (non-empty). No concatenation, no length, no comparison, no slicing, no case folding.

WantLayerStatus
a == b, a != b—Today
"is this string non-empty"—Today, as require(s != "") — 8 gas, and the idiom every address argument needs
length(s)L1Proposal
concat(a, b)L1Proposal, and a prerequisite before user-space map keys are even conceivable
isValidAddress(a)ABI, not the VMProposal — below
normalizeStrDomain(d)ABI or hostProposal. Case folding is security-critical (STR.TREASURY beside STR.treasury is an impersonation primitive) and must never be reimplemented per contract

The address gap is a live defect, not merely a missing feature. validateArgs in src/core/contract-state.ts treats address and string identically — both must be a JavaScript string, and nothing else is checked:

validateArgs(pay(to: address, amount: uint), ["", 1n])                  -> ACCEPTED  [measured]
validateArgs(pay(to: address, amount: uint), ["not-an-address", 1n])    -> ACCEPTED  [measured]

So transfer("", 1000) reaches the bytecode as a well-typed call, and a compliant token that does not check for itself credits a slot no key can ever reach. The tokens are not burned — no supply counter moves — they are stranded, and the contract is immutable, so they stay stranded.

Proposal, and the highest-value single change named in this document: validateArgs should call isValidAddress from src/crypto/signing.ts for address-typed parameters. One import, one branch. It costs no gas because it runs before the first opcode, and it converts a whole class of contract bug into a rejection at the ABI boundary that no author can forget. The four-hex checksum in zk13str_<40 hex>_<4 hex> exists precisely so a mistyped address fails locally; the contract path is currently the one place that does not consult it.

Until it exists, every ZK13 token must guard its own address arguments with require(to != "", "empty recipient") — 8 gas — which catches the empty string and nothing else. State the residual clearly: a well-formed-looking but wrong address is not detectable in-contract, ever.

5.7 context — the host facts#

Everything here is in flight, behind the interface the runtime agent is adding:

export interface AresHost {
  selfAddress(): string;
  blockTimestampMs(): number;
  blockHeight(): bigint;
  balanceOf(address: string): bigint;
  transfer(to: string, amountMinor: bigint): void;
}
Host factUnlocksThe rule Hephaestus attaches, and the failure it prevents
selfAddress()escrow, vesting, staking — any contract that must hold a balance keyed at itselfWithout it a contract cannot distinguish its own pot from a user's. With it, an escrow over a ZK13 token needs no transfer opcode at all: the pot is a slot in the same contract that owns the ledger.
blockTimestampMs()vesting cliffs, escrow timeouts, staking accrualA contract must never take a time as an argument. A caller-supplied timestamp is a caller-supplied unlock date. This is why vesting is not writable today. It must be the block's time — identical for every node replaying that block — never a wall clock, which is the discipline the rest of the tree already holds: atMs is threaded through applyDeploy and applyCall and never read from Date.now() on a replay path.
blockHeight()height-based schedulesPrefer height to time for anything adversarial: a producer has some latitude over the timestamp it writes and none over the height.
balanceOf(address)reading native ledger balancesRead-only, and it reads another ledger. A token that mirrors a native balance into its own storage has created a second copy of the truth. Read it; do not cache it.
transfer(to, amountMinor)moving native valueThe dangerous one — below.

transfer brings three failures with it, and all three need a decision before it ships.

  1. Reentrancy becomes reachable. §5.4.
  2. AresHost.transfer must go through the same recipient gate LedgerManager.validate uses — whatever that gate currently is. It does: ValueJournal.transfer and LedgerManager.validate both call reservedAccountRefusal, so neither can drift from the other. The concern as originally written — that a contract would become the route to move STR to an unregistered address — no longer describes a hole, because a plain transfer may reach an unregistered address as well; the anti-sybil property is carried entirely by the sender needing a proved domain, which no path relaxes.
  3. A contract can receive native STR. This bullet said it could not, which was true when it was written. LedgerManager.validate admits a deployed contract as a recipient, and a plain transfer is the only way to fund one. See CONTRACT_TEMPLATES.md §2.

5.8 collections — maps#

In flight. Nothing useful can be said about the gas cost until the storage-key construction is chosen, and inventing a number now would be exactly the asserted-instead-of-measured figure this codebase refuses elsewhere. What can be said:

  • A map read costs at least a LOAD (50) and a map write at least a STORE (200), because it becomes one. Key derivation is charged on top.
  • Sindri's storage commitment is a Glasir tree over glasirKey(slotName) with a type-tagged slotCommitment, and it folds only dirty slots. A map producing one slot per key inherits that incremental behaviour for free. A map that serialises itself into a single slot does not, and re-hashes the whole map on every write — the cost of the commitment then grows with the size of the map rather than with the number of keys touched. This document recommends one slot per key, and it is a recommendation, not a decision this agent owns.
  • Map iteration must not exist, now or after loops land. There are no loops today, the gas limit is per call, and a map whose size a caller controls is a contract that becomes uncallable at some size and can never be fixed, because the code is immutable.

6. What Hephaestus must never contain#

Each ban has a specific reason, and the reason is worth more than the ban.

NeverWhy
An upgrade or proxy patternThere is no code-write path in Sindri: bytecode is part of the address preimage and part of the account commitment. Contracts are immutable by construction, and that is a security property other chains pay dearly to approximate. A library shipping a proxy pattern would teach authors to hand one key the power to replace the contract under its holders — the exact failure upgrade proxies enable and this chain does not have.
A setBalance or forceTransfer helperA mint that can also debit is a confiscation primitive. It looks like an administrative convenience right up until it is used.
Anything reading a wall clockDate.now() inside execution makes two nodes replaying the same block reach different state. The whole tree is disciplined about this; the library must not be the exception.
Anything randomisedThe same determinism reason, plus: randomness derived from block data is chosen by the producer.
A "safe" wrapper that only reformats an errordiv already reverts on zero. A wrapper adding 8 gas and a nicer message teaches the author that the wrapper is what makes it safe, and the next author omits it somewhere it would have mattered.
Map iteration§5.8.
A fee, allowance or approval mechanism, in v1Nothing can spend an allowance: there are no cross-contract calls. See ZK13_TOKEN_STANDARD.md §4.

7. Delivery: how a library with no call opcode gets into a contract#

Two mechanisms. This document recommends the second.

A. A textual prelude. use hephaestus.access;, and the compiler splices declarations and statements in before parsing. Simple — and it makes the deployed bytecode differ from the source the author wrote, which breaks the property compileAresContract currently promises: that the ABI and the code both derive from one source text and cannot drift. An author auditing a deployed contract would be auditing something they did not write.

B. Declaration forms the compiler expands, with the expansion visible. ownable, pausable, and a function attribute such as fn withdraw(...) only(owner). The compiler emits the state slot and the guard opcodes, and strblk gains a command that prints the fully expanded source beside the disassembly, so what is deployed is always readable.

Recommendation: B, with the expansion printable. The reason is the one bytecode.ts already states — "Anything that can be deployed can be disassembled back into the exact instruction stream the VM will execute, which is what makes on-chain verification meaningful." A library that hides code inside a contract is at odds with that; a library whose expansion the author can print is not.

Marked as a proposal, and it is the design decision the next wave should settle first, because every module above is written against it.


8. What is owed, and to whom#

Every row in this table has since been paid. They are struck rather than deleted, on the same rule the errata below states: a reader who acted on the earlier version deserves to see what moved, and a list of debts that were quietly settled teaches nobody where the debts came from.

OwedOwnerSettled

Closed, date not recorded 3 of 7 Next

Closed: A NAMING.md registry entry for Hephaestus

the naming ownerWritten. docs/NAMING.md:76

Closed, date not recorded 4 of 7 Next

Closed: The choice between delivery mechanism A and B (§7)

the runtime ownerSettled as neither, and §7's recommendation is withdrawn in the errata below. Composition happens BEFORE compilation, in ordinary application code — compose and composeSource in stdlib/source.ts — so the composed text is the contract and compileAresContract still derives the ABI and the code from one source. A compiler feature would have made an access-control policy a consensus rule

Closed, date not recorded 5 of 7 Next

Closed: isValidAddress in validateArgs (§5.6)

the owner of src/core/contract-state.tsBuilt. The address branch of validateArgs checksum-validates before the first opcode (src/core/contract-state.ts:1642); it was the single highest-value change named here and it landed

Closed, date not recorded 6 of 7 Next

Closed: The domain gate on AresHost.transfer (§5.7)

the runtime owner, jointly with the ledger ownerResolved, and §5.7 records how. ValueJournal.transfer and LedgerManager.validate both call reservedAccountRefusal, so the two directions cannot drift; the receive-side domain requirement is gone from BOTH, and the anti-sybil property is carried entirely by the sender needing a proved domain

Closed, date not recorded 7 of 7

Closed: Whether contract addresses are exempt from the recipient-domain rule

governance, not codeDecided. LedgerManager.validate admits a recipient that is in the deployed set — contracts.has(tx.to), membership of state in the root, never a pattern match on the address (src/core/ledger-manager.ts:443). See CONTRACT_TEMPLATES.md §2

Errata — corrected by implementation#

Everything below was written before the code existed and proved wrong once it did. A specification nobody has implemented is a draft, and these are recorded rather than quietly edited so that anyone who read the earlier version can see what moved.

Corrected in ARESLANG_STDLIB.md#

  • §7's recommendation — access control as a compiler feature (fn withdraw() only(owner)) — is withdrawn. The document's own boundary rule defeats it: the compiler is code every node runs identically forever and cannot change without a fork, so a library routine placed there makes an access-control policy a consensus rule. The day someone wants a different message or a three-key owner, the fix would be a hard fork. §7 objected to a textual prelude on the grounds that "the deployed bytecode differs from the source the author wrote" — but that is about where the splice happens. Composition happens before compilation, in ordinary application code, and the composed text is the contract.
  • §5.6's headline change has landed. isValidAddress in validateArgs is in the tree; an address parameter needs no in-contract guard. The residual is text in a string slot.
  • §5.2's "roles — needs maps, in flight" is stale. Maps landed; roles ship as a full map<string, map<address, bool>>.
  • §5.1 still lists sub(a, b) as a library routine. It is refused: SUBU is 3 gas, cannot be omitted because uint - uint is checked by type, and a wrapper would cost more while teaching that the wrapper is what makes it safe.
  • §3 and §0.1 carry two different gas tables, and §3 is the v1 one — no MLOAD, MSTORE, SUBU, BALANCE or TRANSFER. stdlib/gas.ts is authoritative and is re-measured by the test suite, so a wrong number there fails CI.
  • && and || DID not short-circuit, and now do. Writing that limitation down is what got it fixed — see compiler areslang-1.2.0. The library's measured cost for onlyOwnerOrRole fell from 119 gas to 60 on the owner path as a direct result.

Corrected in ZK13_TOKEN_STANDARD.md#

  • §6.6's justification is factually wrong about this VM. The two-statement debit-then-credit does not inflate when from == to: MSTORE writes through, so the credit reads the already-debited value. Measured both ways. The bug appears only when both balances are cached in locals first. Keep the mandated guard — it makes that future edit harmless — but the stated reason for it is not the reason. §6.6's hedge about "map semantics still in flight" is resolved: they are sequential.
  • §5.4's empty recipient rule is unreachable on the record path, since validateArgs checksum-validates every address argument before the first opcode. The guard is kept as defence for a future caller path, and is documented as such rather than as live protection.
  • §5.3's "set minter to ''" cannot be expressed, because "" fails the address ABI check. It needs a dedicated zero-argument closeMinting(), which is what the reference implementation does. The same applies to cancelling a pending owner.
  • §4.3's event set has no event for proposeOwner, which contradicts §6.4's own argument that a two-step handover "leaves a window in which the pending change is visible on chain" — visible in storage, invisible in the log. The reference adds OwnerProposed.

Corrected in CONTRACT_TEMPLATES.md#

  • §2 is stale, and it gated half the document. "A contract cannot be funded with native STR" is no longer true. Consequently §4.3 vesting, §4.4 escrow, §4.5 multisig custody and §4.7 "DAO treasury — in flight" are all writable today, and all four are shipped and adversarially tested.
  • §2's own proposal was mis-scoped. It claimed the funding clause "unblocks the most of this catalogue". It unblocked custody. It did not unblock the deposit-attribution class, which is what actually prevents native staking, a token sale, a per-user vault and a tip jar — see below.
  • A contract address cannot be funded before it is deployed. The receive gate answers from the deployed set, so the only pre-funding path is a genesis allocation.

The gaps that remain, named precisely#

Recorded here because each one blocks a specific, obvious thing a user will try.

  1. Deposit attribution. A call record carries no value and there is no deposit hook, so a contract cannot learn who paid it. Escrow, vesting, multisig and the treasury work because their funds are pooled and governed by roles. Native staking, a token sale, a per-user vault and a tip jar all need to credit a payer, and cannot. This is the single highest-value remaining item for templates.
  2. No domain accessor on the host. AresHost exposes selfAddress, blockTimestampMs, blockHeight, balanceOf and transfer. A contract cannot ask whether an address holds a proved STR.domain, so a domain-bound NFT — a wNFT — is not writable. The shipped nft-collection.ares is an honest plain NFT, and a test asserts its source mentions no domain at all.
  3. No user-defined function calls. The library is composed source rather than linked code, and the staking accrual is copied verbatim three times behind ACCRUAL BEGIN/END markers. That is a real hazard and the template header says so.
  4. No cross-contract calls, so a general multisig or DAO that acts on another contract is not writable.
  5. No constructor arguments. Every parameter is a source constant the user edits or a post-deploy setter. state owner: address = caller; works because the initializer runs with the authenticated deployer as caller — so no template needs a claimOwnership call, and there is no claim race.
  6. Deployment gas is unmeasured. applyDeploy returns no gasUsed, so postMineForContractRecord skips deploys. Left unmeasured rather than estimated.