sourceId instead of refusing the round.
A policy changes nothing about the attestation. It is still value, sourceId, registryVersion, signaturesRequired and timestamp, signed once and verified unchanged on Solana, EVM and Starknet. Verifiers, tickets and feeds see an ordinary attestation.
For a step-by-step walkthrough, see Write and test a policy.
Where it runs
Each node evaluates the whole policy on its own fetches, between decoding the inputs and running the transform:policy key evaluates exactly as before, and its sourceId does not change. The policy is part of the canonical source, so sourceId commits to the policy, to whether an INCONCLUSIVE result can ever be signed, and to what is signed.
The policy block
policy is a top-level key of the source. Omit it when unused; "policy": null is rejected. Inside the block every key is present and an absent optional is null, as everywhere else in a source. The SDK’s defineSource fills the defaults for you; a node or gateway rejects a missing key.
An input that is not a candidate is a helper input. It is fetched and decoded as usual, and
inconclusiveIf, transform and assert can read its fields, but it is never qualified or combined.
Combinators
n is the number of qualifying candidates. Sorting is ascending by value, ties broken by input name.
The spread check for
median and weightedMedian is (max - min) * 10000 <= abs($agg) * maxSpreadBps, computed exactly. All arithmetic is exact decimal. Evaluation reads no node clock and no randomness: time enters only through the round timestamp.
Independence
Checked when the source is parsed, so a gateway and a node reject the same sources:none: no check.distinctHosts: no twohttpcandidates share a URL host name. Chain candidates are not compared.distinctChains: every candidate is a chain input and no two read the same chain.
distinctHosts cannot see two host names that serve one upstream, such as a mirror or an aggregator. Independence of origin is declared, not proven.
References
Policy expressions use the transform grammar plusand, or, not and in, and these references:
A candidate’s
value, rules and weight read only that candidate’s own input, so whether one input qualifies never depends on another. Comparisons between inputs belong in the combinator.
How nodes evaluate it
- Fetch and decode every input concurrently. With a policy, one input’s failure does not cancel the others.
- Helper inputs. A helper input that failed refuses the round.
- Candidates, in input-name order. A failed input or an expression error is handled by
onError:disqualifydrops the candidate,refuserefuses the round. The first rule that isfalsedisqualifies the candidate. Otherwise it qualifies. - Combine the qualifying candidates into
$aggand$n. A failed constraint makes the result INCONCLUSIVE. inconclusiveIf, in order. The first entryithat holds makes the result INCONCLUSIVE with reason0x10 + i. An entry that errors refuses the round.- Transform, assert, encode. This is the CONCLUSIVE result.
- INCONCLUSIVE. With a fallback, the node evaluates and encodes it (assertions do not run on it). Without one, it refuses.
Outcomes
INCONCLUSIVE is only ever what the policy’s own rules conclude from data that was fetched. Errors are refusals, not verdicts.
Reason codes
The fallback
The fallback is an expression over literals,$reason and $n only: a literal, {"ref": "$reason"}, {"ref": "$n"}, or an if over tests (eq, ne, lt, lte, gt, gte, in, and, or, not) of those. So a policy can sign one value for every INCONCLUSIVE result, or a different value per reason.
The set of values a fallback can produce is known without running it. Each of them must encode under the source’s output (exactly, at its decimals), or the source is rejected. A node therefore never reaches an INCONCLUSIVE result it cannot sign.
Fallback words
The 32-byte words a fallback can sign are its fallback words. They are what the outcome is read from. For example, a fallback of-1 on an int256 output with 2 decimals signs -100 in two’s complement:
fallbackWords(source); the analysis lists them too.
Keeping the fallback distinguishable
A consumer tells the fallback from a result by the value alone, so make the fallback a value no result can be:- pair it with an assertion that excludes it, such as
-1withgte($out, 0)on a price; or - pick a value the transform cannot produce, such as
2on auint256verdict whose transform yields only1or0.
fallback.reachable, with the warning fallbackReachable when a result could encode to a fallback word. It warns and never rejects: mapping INCONCLUSIVE onto a result value can be deliberate.
Reading the outcome
The outcome of a round is read from the signed value:- a value among the source’s fallback words is the fallback: the policy concluded INCONCLUSIVE;
- any other value is conclusive.
outcome: fallback and its reason, but that label is not signed. The gateway uses it only to supply the reason code, and only when it agrees with the value; a label that disagrees is dropped and never costs a signed round. The reason you receive is therefore a hint, not something a verifier can check.
In the SDK, readOutcome(result.payload, source) returns { kind: "conclusive" | "fallback", value }, or null when the attestation is not for that source. On-chain, compare the verified value with the fallback words. See Consume it on-chain.
What INCONCLUSIVE means to you (wait, expire, refund, void) is your contract’s decision. If a round settles something, also guard against outcome shopping: accept only attestations whose timestamp / 1000 falls in your resolution window, and only the first one you accept.
Signing modes
Exact mode (aggregation: null). Every signer must produce the identical message. A node that disqualified a venue the others accepted produces a different message, and the round fails. A fallback is signed only when every signer reaches the same fallback word. Exact mode suits verdicts (bool, bytes32) and single-candidate policies. The analysis warns (exactComposite) on an exact-mode policy with more than one candidate.
Tolerance mode. Each node’s signed round-1 observation carries its outcome: CONCLUSIVE with its value, or INCONCLUSIVE with its fallback word. Every node then applies one rule:
- If at least
signaturesRequiredobservations are CONCLUSIVE, the median of those is signed, as in ordinary tolerance mode. Only CONCLUSIVE in-band nodes sign. - Otherwise, if at least
signaturesRequiredobservations are INCONCLUSIVE with the same fallback word, that word is signed. Only those nodes sign. - Otherwise the round fails.
$reason or $n can give nodes different words; rule 2 needs signaturesRequired of them on one word.
One outcome per round
A node signs at most once per round. The gateway admits a source with a fallback only whensignaturesRequired is above the registry’s redundancy buffer, so the selected set (at most signaturesRequired plus the buffer) cannot hold two disjoint quorums, one for the result and one for the fallback. Both would be under the same sourceId, so a node that signed both would be caught by the existing equivocation rule.
On the current devnet deployment the redundancy buffer is 2 and the minimum quorum is 3, so every admissible quorum qualifies.
A fallback is never signed in a provider round (requireProvider): the gateway rejects a fallback source with requireProvider, and a provider round needs a policy with exactly one candidate.
Over HTTP
A round of a policy source is requested like any other round, at the same price.
A source without a policy has no
outcome field.
Two free endpoints evaluate a policy without signing or charging anything:
POST /v1/source/previewfetches the inputs and evaluates the source the way a node would, twice, a second apart.POST /v1/source/simulateevaluates the source over inputs you supply (a response body, decoded fields, or a failure), with the nodes’ own evaluator. Nothing is fetched.
policy object: each candidate’s qualified, rule (the first false rule) or error (fetch or eval), n, agg, outcome (conclusive or inconclusive), reason, and signed (the fallback is the value). See Preview and simulate.
Receipts
For every round of a policy source, each node keeps a receipt: its own account of what it read and decided. The gateway fetches each node’s receipt shortly after the round (libp2p protocol/molpha/receipt/1.0.0) and stores the receipts with the round in its archive.
An http input is identified by
bodyHash, the keccak256 of the response body exactly as received; a chain input by the block it was pinned to. Two nodes that read the same bytes have the same hash, and anyone holding the body can check it. A receipt never carries a body, a header, a secret or an error message; an input’s error is only its class (fetch, decode or canceled).
What a receipt proves. Nothing on chain. It is not signed: it explains a round, it does not attest one. Use it to see why a round ended as it did, which venue each node could not read, and which rule disqualified a candidate. The attestation’s signature is the only proof.
Where to read it. The round archive at https://indexer.molpha.io serves a round, and its receipts, under its round ID:
receipts lists {gateway, node, nodeAccount, receipt}. A signed report of a policy round also has result (outcome, reason): that is the gateway’s reading, not a signed field. The SDK returns the round ID as result.roundId.
Sources without a policy get no receipt, and neither do private ({{secret.NAME}}) or paid-source rounds, whose inputs belong to one consumer. Nodes keep receipts in memory for a short time (600 seconds by default), so a receipt the gateway did not collect in time is gone.
Limits
Limits are checked before anything is fetched, at the gateway and again at each node. Every node fetches every input, so a three-venue policy costs each node three fetches.
Analysis
analyzeSource in the SDK (and the nodes’ own analysis, which gives the same facts) describes a source without fetching or evaluating it: its inputs and their hosts or chains, the candidates and their roles, the combinator, the fallback words and whether a result can reach them, the expression size, fetches per node, the node capabilities it needs (policy/1, fallback/1, round1/2, tsMs/1) and warnings:
The MCP server exposes it as
analyze_source, and the simulation as simulate_source. See MCP tools.