SourceLess · AsgardAsgard · chain 1313

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

The ZK13 vault standard

The vault standard: deposits, shares, and the accounting a vault may not get wrong.

26,344 bytes 4,287 words newest date 2026-09-17

Verify: the published bytes are in the raw file ZK13_VAULT_STANDARD.md, whose SHA-256 is in SHA256SUMS.
f9bd9c156e8c5c95b761ae6feba416356351c909260f46a7ced3705da5518b62

Date: 2026-09-17 Status: specification, with a conforming reference implementation.

templates/zk13-vault.ares implements everything below and compiles on areslang-1.2.0. It was deployed and exercised on a real BlockchainCore — genesis with proved STR.domains, signed deploy and call records sealed into blocks, validateChain() accepted afterwards — and every gas figure and every worked number in this document is what the STARW VM actually produced on that run.

That run is not a committed test. It was a script this desk ran once; the template is not in the suite CI executes, and §11 says exactly what that means and what is owed — including for the attack measured in §5.1.

No ZK13 vault has been deployed on a public network, because no realm has a published address (docs/INSTALL.md §6). A share price that behaves correctly on a local chain is not the same claim as a pool holding value in public.

Naming. A sixth use of the ZK13 family name, after the proof system, the zk13str_ address format, and the fungible, NFT and multi-token standards. A registry amendment is owed to the naming owner — docs/NAMING.md:136 entry (3) should read the ZK13 asset standards family (fungible, NFT, multi-token, vault). This desk may not edit NAMING.md. The standard references no proof, no commitment and no nullifier.

Siblings: ZK13_TOKEN_STANDARD.md, ZK13_NFT_STANDARD.md, ZK13_MULTI_TOKEN_STANDARD.md.


1. What a ZK13 vault is, and is not#

A ZK13 vault is a pool of one asset, owned pro rata by holders of a share. Deposit assets and receive shares; the pool grows when anyone funds yield into it; redeem shares for assets at whatever the pool is worth then. It is the familiar tokenised-vault shape, and the accounting is the same accounting.

It is not:

  • a wrapper around somebody else's token. It cannot be — see §2, which is the one structural difference from the common tokenised-vault interface and the reason for every other difference in this document.
  • a yield source. Nothing in a conforming vault generates a return. fundYield is a voluntary payment by whoever calls it, and a vault nobody funds pays back exactly what was deposited, minus rounding. A vault must not be described as interest-bearing unless something outside it is committed to funding it, and that commitment is not enforceable by this contract.
  • a staking contract. Staking accrues by TIME against a rate (templates/staking-token.ares); a vault accrues by SHARE against a pool. The difference is not cosmetic: a staking contract owes a debt it may be unable to pay, and a vault owes a proportion it can always pay.
  • a native-STR vault. See §2.

2. Why the asset and the vault are one contract#

The common tokenised-vault interface is a wrapper: the vault holds a balance in ANOTHER contract and calls transferFrom on it to move a depositor's tokens. Neither half of that is available here.

  1. There are no cross-contract calls. AresOp (runtime/bytecode.ts) has no call opcode and the compiler resolves exactly four builtin names; contracts/executor.ts states the rule the design rests on — a contract can only do what its own bytecode does. A separate vault could never move a depositor's token balance.
  2. A contract cannot be caller. So even if a depositor transferred tokens to a vault's address by hand, the vault could never move them out again. A ZK13 balance at a vault address is inert forever.

A vault over a ZK13 token is therefore only writable inside that token's own contract, and a conforming vault is one contract holding two ledgers: the asset and the share. This is the same reasoning that makes templates/staking-token.ares one contract rather than two, and it is not a limitation this standard can design around.

And it cannot vault native STR, for a different reason that is just as permanent: a call record carries no value and there is no deposit hook, so a contract cannot learn who paid it. Every per-depositor native pattern — a native vault, native staking, a token sale, a tip jar — is unwritable for that one reason. It is item 1 in ZK13_TOKEN_STANDARD.md's remaining-gaps list and the highest-value change for this standard by a wide margin.

The consequence for an integrator, stated plainly: you cannot write a vault for a token somebody else deployed. The issuer of the asset must have deployed the vault with it, in the same contract, from the start. There is no retrofit.


3. Two ledgers in one contract, and which view answers for which#

A conforming vault answers the whole ZK13 fungible interface for its asset, and adds a share-side surface with distinct names. The split is part of the standard, because a vault whose balanceOf sometimes means shares is a vault whose accounting nobody can check.

LedgerSurfaceWhat it is
assetname, symbol, decimals, totalSupply, maxSupply, lifetimeIssued, balanceOf, transfer, burn, mintThe ZK13 token this contract issues, conforming to ZK13_TOKEN_STANDARD.md
shareshareBalanceOf, totalShares, shareDecimals, transferSharesA claim on the pool
pooltotalAssetsAssets held by the vault itself

The invariant a reviewer checks:

totalSupply() == (the sum of balanceOf over every address) + totalAssets()

Deposited assets LEAVE the depositor's balance and are held in the pool, which is not a balance entry at any address. There is deliberately no address at which the pooled assets appear: crediting them to self would suggest they could move like a balance, and they cannot — a contract cannot be caller.


4. The interface#

4.1 Views — every conforming vault must expose all of these#

view fn standard() -> string                                  // "zk13-vault/1+zk13-fungible/1"

// the asset, exactly as the fungible standard requires it
view fn name() -> string
view fn symbol() -> string
view fn decimals() -> uint
view fn totalSupply() -> uint
view fn maxSupply() -> uint
view fn lifetimeIssued() -> uint
view fn balanceOf(account: address) -> uint
view fn owner() -> address
view fn minter() -> address
view fn paused() -> bool

// the pool and the share
view fn totalAssets() -> uint
view fn totalShares() -> uint
view fn shareBalanceOf(account: address) -> uint
view fn shareDecimals() -> uint

// the quotes
view fn convertToShares(assets: uint) -> uint                 // rounds down
view fn convertToAssets(shareAmount: uint) -> uint            // rounds down
view fn previewDeposit(assets: uint) -> uint                  // rounds down
view fn previewMintShares(shareAmount: uint) -> uint          // rounds UP
view fn previewWithdraw(assets: uint) -> uint                 // rounds UP
view fn previewRedeem(shareAmount: uint) -> uint              // rounds down
view fn maxRedeem(account: address) -> uint
view fn maxWithdraw(account: address) -> uint

Every quote MUST be the identical arithmetic its mutating function performs, so a caller can price a move before making it. They are view, so the compiler has refused them the ability to write anything and a wallet can call one against live state.

A quote is an estimate, and the return value of the mutating call is the fact. Between the quote and the record landing, anyone may deposit, redeem or fund yield. Every mutating function in §4.2 therefore RETURNS what it actually did.

maxDeposit and maxMint are deliberately absent. The common interface has them and returns the largest fixed-width integer for "unlimited"; this VM's integers are arbitrary-precision, so there is no maximum value to return and a sentinel would be a lie in a different font. The only real limit on a deposit is the pause, and paused() answers that.

4.2 Mutating functions#

fn deposit(assets: uint) -> uint             // assets in, shares out (rounded down), returns shares
fn mintShares(shareAmount: uint) -> uint     // exact shares out, assets in (rounded UP), returns assets
fn withdraw(assets: uint) -> uint            // exact assets out, shares in (rounded UP), returns shares
fn redeem(shareAmount: uint) -> uint         // shares in, assets out (rounded down), returns assets
fn transferShares(to: address, amount: uint) -> bool
fn fundYield(amount: uint) -> bool
// plus the asset's own transfer / burn / mint and the owner functions of the fungible standard

The four entry points are the common interface's four, and the pairing is the same: deposit/redeem name an amount the caller HAS, mintShares/withdraw name an amount the caller WANTS.

mintShares is not called mint, and the name is load-bearing: mint on a conforming vault is the ASSET's minter function, and the two are not remotely the same power. One issues the underlying token by authority; the other buys a claim on the pool with tokens the caller already holds.

There is no receiver or owner argument on any of the four. The common interface takes both so a router contract can deposit on a user's behalf; there are no cross-contract calls here, so such an argument would only let one address move another's position. Every function acts for caller.

4.3 Events#

event Deposit(owner: address, assets: uint, sharesMinted: uint)
event Withdraw(owner: address, assets: uint, sharesBurned: uint)
event YieldFunded(from: address, assets: uint)
event ShareTransfer(from: address, to: address, amount: uint)
event Transfer(from: address, to: address, amount: uint)      // the ASSET ledger, as the fungible standard defines it
  • deposit and mintShares BOTH emit Deposit, because they are the same movement — assets into the pool, shares to the caller — and an indexer must not have to know which entry point was used. withdraw and redeem both emit Withdraw, for the same reason.
  • Movements into and out of the pool are NOT Transfer. They are not movements between two addresses, and an indexer summing Transfer to reconstruct balances must not see them.
  • fundYield emits YieldFunded and no Transfer: the assets left a balance and entered the pool, and the depositor received nothing.

Events are not in the state root. Sindri excludes them deliberately, so an event is evidence and never logic, and no contract logic may depend on one having been emitted.

4.4 Errors#

StringRaised when
amount must be positivea zero amount is passed to any of the four entry points or to fundYield
insufficient balancethe caller's ASSET balance is below what the call needs
insufficient sharesthe caller's SHARE balance is below what the call needs
no sharesa deposit that would round down to zero shares
no assetsa redemption that would round down to zero assets
no shares outstandingfundYield while totalShares() is 0
vault shorta withdrawal of more assets than the pool holds
empty recipient, self transfer, self is not payableas the fungible standard defines them
paused, not owner, not minter, not the pending owner, mint closed, supply capas the fungible standard defines them

5. Compliance rules#

5.1 Pricing, and the virtual offset#

A conforming vault prices against the pool PLUS a virtual offset:

shares_out  = floor( assets * (totalShares + virtualShares) / (totalAssets + 1) )
assets_out  = floor( shares * (totalAssets + 1) / (totalShares + virtualShares) )
shares_in   = ceil ( assets * (totalShares + virtualShares) / (totalAssets + 1) )
assets_in   = ceil ( shares * (totalAssets + 1) / (totalShares + virtualShares) )

virtualShares is declared at deployment, is at least 1, and never changes. The reference implementation uses 10,000,000 (10^7), so a fresh vault opens at ten million shares to one asset unit.

The offset exists to defeat the inflation attack: be the first depositor with one unit, donate a large amount straight into the pool, and every later depositor's share count rounds down to zero or near it — their assets become yours.

MEASURED on the reference implementation. Attacker deposits 1 unit (10,000,000 shares), donates 1,000 into the pool with fundYield, victim then deposits 1,000 and receives 19,960,079 shares. Pool 2,001 assets against 29,960,079 real shares. maxWithdraw afterwards: victim 999 against the 1,000 deposited; attacker 501 against the 1,001 they put in. The attack cost the attacker 500 to deprive the victim of 1.

Two honest riders on that number:

  1. The missing 501 is not the attacker's either — it backs the phantom shares, and nobody can withdraw it. Which is the second rule:
  2. The phantom shares keep a fraction of every increase in the pool — and only of the increase. This was checked in three cases rather than reasoned about, and the first result corrected an earlier draft of this section which claimed the pool could never be emptied:
    CaseMeasured
    no yield fundedDeposit 1,000, redeem every share: 1,000 out, totalAssets() 0. The offset cancels exactly, because it sits on both sides of the ratio
    yield fundedDeposit 1,000, fund 500 of yield, redeem every share: 1,499 out, 1 unit left in a pool with no shares outstanding — virtualShares / (totalShares + virtualShares) of the yield, which is a thousandth of it at an offset of 10^7
    donation-inflatedThe attack above: 501 of 2,001 stranded, which is the attacker's money and is why the attack does not pay

    The residue is not destroyed: it prices into the pool for whoever deposits next. What it is not is claimable by the holders who were there when it appeared. A vault whose accounting requires the pool to reach exactly zero after any yield should not be built on this shape, and a conforming implementation MUST state the leakage in its own header rather than leaving a depositor to find it.

The measurement says the cheap version of this attack is self-defeating here. It does not say no pricing attack exists: an attacker willing to donate ten million times a victim's deposit can still round that victim down, and would be paying ten million times the victim's deposit to do it.

5.2 Rounding direction#

Every rounding goes to the pool, never to the caller. This is the rule that keeps a vault from being drained one unit at a time by a loop of tiny calls, and the direction is fixed for each entry point (§4.2). A vault that rounded a caller's favour anywhere does not conform — not because the single unit matters, but because a caller can repeat the call.

deposit MUST refuse a deposit that buys zero shares (no shares), and redeem MUST refuse a redemption that pays zero assets (no assets). Both are the same rule: a call that takes value and returns nothing is a loss the caller asked for by accident. The no assets rule also means a holder cannot exit an empty pool — there is nothing there to pay them, and burning the shares would not change that.

5.3 Redemption is never pausable#

redeem and withdraw MUST NOT be gated by the pause, and this is the most important rule in the standard. The owner may stop deposits, funding, share transfers, asset transfers and minting; the one thing the owner MUST NOT be able to do is stand between a holder and their own share of the pool.

The same asymmetry is in templates/staking-token.ares, where unstake runs while paused. It is the house rule for any contract holding somebody else's value: the emergency stop stops new business, not exits.

5.4 The owner has no path to the pool#

A conforming vault has no function that moves pooled assets to an address. No fee, no skim, no sweep, no emergency recovery. A reviewer checks this by reading catalog(address): the only functions that lower totalAssets() are redeem and withdraw, and both pay caller against caller's own shares.

A vault that wants a fee takes it in the SHARE ledger at deposit time, visibly, or it does not have one. This standard does not define a fee shape, because every shape proposed so far needed either a privileged path to the pool or an arithmetic the depositor could not check.

5.5 Yield#

fundYield(amount) moves assets from the caller's own balance into the pool, for the benefit of every share outstanding. It MUST refuse while totalShares() is 0: into an empty vault the donation would be priced against a pool that already holds it, and nobody could ever claim it.

A conforming vault MAY restrict who can fund yield; the reference implementation lets anyone, because a donation cannot harm a holder under §5.1's pricing and a restriction would be one more privileged role for no gain.

5.6 Shares are transferable, or they are not — and the ABI says which#

A share is a bearer claim: whoever holds it can redeem it. transferShares is REQUIRED in the base standard, because a claim nobody can move is a different product and should say so. A vault that wants non-transferable shares omits transferShares and declares standard() == "zk13-vault/1+bound" — enforced by absence, which is the only enforcement available here.

5.7 The asset side must conform on its own#

Everything in ZK13_TOKEN_STANDARD.md §5 and §6 applies to the asset ledger unchanged: the cap bounds lifetime issuance, minting closes permanently, the owner cannot reach a holder's balance, a self-transfer is refused, and every movement emits exactly one Transfer. A vault is not an excuse to relax any of it.


6. Design against theft#

  1. No function that writes a share balance to an arbitrary value. Shares are created only by deposit/mintShares and destroyed only by redeem/withdraw.
  2. No privileged path to the pool (§5.4).
  3. No pausable exit (§5.3).
  4. No mutable pricing parameter. virtualShares is fixed at deployment. An owner who can change the offset can reprice every position in the vault.
  5. No rounding in the caller's favour anywhere (§5.2).
  6. No single-step ownership change.
  7. No unbounded work. Every function is a fixed number of map and arithmetic operations.
  8. No upgrade path and no proxy. Bytecode is in the address preimage; there is no setCode.

7. What this standard cannot express on this VM, precisely#

Feature elsewhereStatus hereWhy, exactly
A vault over a token deployed by somebody elseNot expressibleNo cross-contract calls, and a contract cannot be caller. §2
A vault over native STRNot expressibleA call record carries no value and there is no deposit hook, so a contract cannot learn who paid it. §2
deposit(assets, receiver) / withdraw(assets, receiver, owner)RefusedThe arguments exist for router contracts, which cannot exist here; with no router they only let one address move another's position. §4.2
maxDeposit / maxMintRefusedArbitrary-precision integers have no maximum value to return, and a sentinel would misreport a real limit. §4.1
A share token usable as a separate token outside the vaultNot expressibleThe share ledger is a map in this contract; nothing outside can read or move it, because nothing outside can call in
A performance or management fee accrued over timeExpressible, and not defined hereThe arithmetic works (timestamp is available), but every shape proposed needed a privileged path to the pool or an arithmetic a depositor could not check. §5.4
Flash loansNot expressibleA flash loan is a call out and a call back in. Neither exists
A yield strategy that deploys the pool anywhereNot expressibleThe pool cannot leave this contract except to a holder, because a contract cannot call another contract, and native TRANSFER moves STR rather than this contract's asset
An asset with a decimals offset chosen at deploymentNot expressible as a computed valueNo exponentiation. virtualShares and shareDecimals are two constants that must agree, and nothing in the machine checks that they do — the reference implementation says so at the declaration, in capitals
A share price with fractional precisionNot applicableThere is no floating point anywhere in this machine, deliberately. Prices are integer ratios, and the rounding rules in §5.2 are the whole of the precision story

8. Conformance checklist#

  • [ ] Every view in §4.1 is present, is view in the ABI, and answers while paused.
  • [ ] The four entry points are present with these names, and each RETURNS what it did.
  • [ ] Each quote is the identical arithmetic of its mutating function.
  • [ ] virtualShares >= 1, is fixed at deployment, and no function writes it.
  • [ ] Rounding: down for deposit and redeem, up for mintShares and withdraw.
  • [ ] deposit refuses no shares; redeem refuses no assets.
  • [ ] redeem and withdraw are NOT gated by the pause.
  • [ ] No function moves pooled assets to an address other than the caller against the caller's own shares.
  • [ ] fundYield refuses while no shares are outstanding.
  • [ ] deposit/mintShares emit Deposit; withdraw/redeem emit Withdraw; neither emits Transfer.
  • [ ] The asset ledger conforms to ZK13_TOKEN_STANDARD.md on its own.
  • [ ] The header states the measured leakage to the virtual offset — that a full exit returns the whole pool when no yield has been funded, and keeps a fraction of any yield that has — rather than leaving a depositor to discover it.
  • [ ] The header states the measured gas of every entry point and the limit to declare.

9. The reference implementation, and what it costs#

MEASURED on areslang-1.2.0 with 53-character addresses. Gas is a pure function of the instruction stream, so these are exact for the calls described.

CallGas
deposit1,484
mintShares1,582
withdraw1,531
redeem1,488
fundYield836
transferShares835
transfer (asset)835
mint (asset)1,135
burn (asset)774
proposeOwner / acceptOwnership412 / 612
setPaused / setMinter / closeMinting363 / 471 / 470
gas limit to declare16,000

Ten times the most expensive entry point, because post-mining covers min(gasUsed, gasLimit / 10).

A worked sequence from the real-chain run, for a reader checking the arithmetic by hand: asset minted 1,000,000 to a holder; deposit(1000) returned 10,000,000,000 shares; mintShares(5000000000) cost 500 assets; fundYield(500) raised the pool; withdraw(100) burned 749,750,250 shares; redeem(1000000000) paid 133 assets.


10. Where this comes from, and where it diverges#

Prior artTakenLeft
The common tokenised-vault interfaceThe whole accounting model: shares as a pro-rata claim, the four entry points paired by what the caller names, previews that mirror the mutators exactly, rounding always against the caller, and Deposit/Withdraw as the two movement eventsThe wrapper structure (§2), receiver/owner arguments, maxDeposit/maxMint, and a share that is itself a separate token
The decimals offset of widely used vault librariesThe virtual-offset defence against the inflation attack, and the discipline of reporting what it does and does not buy (§5.1)The offset as a power of ten computed from a decimals() override — there is no exponentiation here, so it is a declared constant with a warning attached
The common fungible-token interfaceThe asset side, through ZK13_TOKEN_STANDARD.mdAllowances, for the reason that standard gives
Compound's cToken / Aave's aTokenThe lesson that an exchange rate stored as state is a number somebody can write, and a ratio derived from two balances is a number nobody can. This standard stores no priceInterest accrual models, reserve factors, and every privileged path that comes with them (§5.4)
SPL Token (Solana)Nothing structurally; a Solana vault is a program plus token accounts it owns, which is precisely the shape §2 forbids hereThe program/account separation
Sui object modelThe framing that a share is a transferable claim rather than a row somebody owns. It shows up here as transferShares being required rather than optional (§5.6)Objects, and ownership as a field of one

11. What is not built#

Not builtWhere it is discussed
Deposit attribution on the native path, without which a native-STR vault stays unwritable§2 — the highest-value change for this standard
Cross-contract calls, without which a vault over somebody else's token stays unwritable§2, §7
A fee shape a depositor can check§5.4, §7
Any committed test over zk13-vault.aresThe seven older templates each have an adversarial suite, and the catalogue-wide properties iterate TEMPLATES in tests/helpers/templates.ts — a list of those seven. This one is not in it. What was done instead: it compiles, it was deployed and exercised on a real BlockchainCore with signed records sealed into blocks and validateChain() accepted, and the §5.1 attack was executed against it — all by scripts this desk ran once and did not commit, because tests/ and scripts/ are not this desk's to write. The attack in §5.1 is the one a suite must re-run on every change, and until it does, that measurement is a fact about one revision
Deployment gasUnmeasured, not estimated: applyDeploy returns no gasUsed