Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,9 @@ Everything below runs offline, with no deployed contracts, except three fork sui
|---|---|---|
| Contracts: unit, fuzz, E2E, upgrade, deploy-script, handover and 22 invariants | 799 | `forge test` |
| Oracle | 1514 | `cd oracle && node --test` |
| SDK | 381 | `cd packages/sdk && npx vitest run` |
| SDK | 385 | `cd packages/sdk && npx vitest run` |

Counts are individual tests, so each of the 22 invariants counts once. The contracts were counted on 15 November 2026, the SDK on 13 November and the oracle on 14 November. Without a fork URL, 787 of the contract tests run and 12 skip. Run after `npm run build`, 372 of the SDK's 381 pass and 9 skip: the 8 integration tests, which need a live deployment, and one check that runs only in CI. Without a build, the 9 built-package tests skip too. Vitest strips types without checking them, so `npm run typecheck` in `packages/sdk` checks the tests against the SDK's types as well as the sources. [`scripts/mutation`](scripts/mutation/README.md) holds the harnesses that measure whether these tests would catch a deliberate break in the contracts or deploy scripts.
Counts are individual tests, so each of the 22 invariants counts once. The contracts were counted on 15 November 2026, the SDK on 15 November and the oracle on 14 November. Without a fork URL, 787 of the contract tests run and 12 skip. Run after `npm run build`, 376 of the SDK's 385 pass and 9 skip: the 8 integration tests, which need a live deployment, and one check that runs only in CI. Without a build, the 9 built-package tests skip too. Vitest strips types without checking them, so `npm run typecheck` in `packages/sdk` checks the tests against the SDK's types as well as the sources. [`scripts/mutation`](scripts/mutation/README.md) holds the harnesses that measure whether these tests would catch a deliberate break in the contracts or deploy scripts.

Merges to `main` carry `[skip ci]`, to save CI minutes, so the push to `main` does not run the suites again. A change to code runs them on its pull request and merges only once every job there has passed; a docs-only change is checked locally with `node scripts/check-docs.mjs`. Each is checked against the `main` its branch started from, so two changes merged close together can still break `main`. That happened once, on 11 November 2026, and the next merge fixed it. The rule that every job must pass dates from 14 November 2026: before it, #281, #282 and #288 merged with their oracle job failing, and #283 and #297 fixed the tests that failed. On 13 November the oracle and SDK suites were run on `main` at `eaccb91` and passed.

Expand Down
2 changes: 1 addition & 1 deletion docs/whitepaper.md
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ apply to a fresh deployment, not to the testnet.

**Test coverage**, as of 15 November 2026: 799 contract tests across 36 Foundry test files
including fuzz and invariant tests (the two slash drill suites fork Arc testnet themselves, and
the twelve in `SplitAuthorityFork` skip without `--fork-url`), 1514 oracle tests and 381 in the SDK (9 skip
the twelve in `SplitAuthorityFork` skip without `--fork-url`), 1514 oracle tests and 385 in the SDK (9 skip
outside CI and without a live deployment; every test that runs passes). CI runs Foundry, the oracle and
SDK suites, and Slither static analysis on every push, plus a documentation check that
fails when the site states something the contracts do not.
Expand Down
27 changes: 27 additions & 0 deletions packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
# Changelog

## 1.0.0-alpha.21

### Fixed: `sigvara_verify_evidence` missed a finalized root a few payments behind a long list

To bound what a hostile oracle could cost, the tool tried fewer settlement cut-offs as a list grew, five at 2,000
payments, so a busy agent whose finalized root was ten payments behind its list read as not reproduced. Each
cut-off rebuilt its tree from nothing, though neighbouring cut-offs share all but a few pairs.

`matchEvidenceRoot` now hashes every tree it tries through one memo of pairs and skips a cut-off that counts the
same payments as the one before. Its new `hashBudget` limits the pairs it hashes: past it no further cut-off is
tried, though the first always is. Its new `memo` lets several matches over one list share their work. The tool
tries up to 64 cut-offs again, within 20,000 hashes, and its finalized and pending matches share one memo. On 2,000
payments with the root ten behind, the match finds it after 2,064 hashes; the old bound gave up after 11,984, and
the old code unbounded took 23,933. A list ordered so that its trees share little still stops at the budget, and
the result says the search reached its limit. `evidenceRoot` and `evidenceLayers` take an optional pair function
and work as before without one.

### Fixed: the verifier asked the RPC its chain id with every wave of reads

ethers sent `eth_chainId` beside every wave of reads, to notice a node that changes chains: 21 to 29% of the calls
the SDK made. `SigvaraVerifier` now builds its provider with `staticNetwork` and asks once, before its first read,
which the new `getRpcChainId` also returns. A verifier given a `chainId` refuses every read from an RPC that serves
another chain, with a `NETWORK_ERROR` naming both; it used to read whichever chain the URL served. A failed ask is
asked again on the next read. `sigvara-mcp` takes its own chain check from the verifier, so a first
`sigvara_check_agent` makes 14 calls, one of them `eth_chainId`, where it made 18 with five of them, and later
ones do not ask again. `rpcChainId` moved to the verifier and is still exported from `dist/mcp`.

## 1.0.0-alpha.20

### Added: the band an agent's score is in
Expand Down
7 changes: 4 additions & 3 deletions packages/sdk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,8 @@ contract. The oracle's answer is untrusted:
- It is read to at most 4 MB, with no redirects followed.
- It is refused unless it names the agent asked about, or if it lists more than 2,000 payments.
- Only the fields a leaf commits to, and the oracle's `outcomeSource` label from two fixed values, are returned.
- Matching a long list tries fewer settlement cut-offs, newest first, so a hostile list costs about a second,
not a minute.
- Matching a root hashes each pair of nodes once across all the settlement cut-offs it tries, and tries no more
once it has hashed 20,000, so a hostile list costs about a second, not a minute.

The server is also a module, for a host that runs its own transport:

Expand All @@ -513,7 +513,8 @@ const reply = await server.handle({ jsonrpc: '2.0', id: 1, method: 'tools/list'
```

Built from `rpcUrl` like this, it checks the chain as the command does. Given a `verifier` of your own, it
checks the chain only if you also pass `readChainId`.
checks the chain itself only if you also pass `readChainId`, though a `SigvaraVerifier` built with a `chainId`
refuses to read from another chain in any case.

## Links

Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sigvara/protocol-sdk",
"version": "1.0.0-alpha.20",
"version": "1.0.0-alpha.21",
"mcpName": "io.github.RunTimeAdmin/sigvara",
"description": "TypeScript SDK for Sigvara. On-chain agent identity, reputation, and A2A challenge-response authentication.",
"main": "dist/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/server.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"subfolder": "packages/sdk"
},
"websiteUrl": "https://sigvara.xyz",
"version": "1.0.0-alpha.20",
"version": "1.0.0-alpha.21",
"packages": [
{
"registryType": "npm",
"identifier": "@sigvara/protocol-sdk",
"version": "1.0.0-alpha.20",
"version": "1.0.0-alpha.21",
"transport": {
"type": "stdio"
}
Expand Down
57 changes: 44 additions & 13 deletions packages/sdk/src/evidence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,30 @@ export function hashPair(a: string, b: string): string {
: ethers.keccak256(ethers.concat([b, a]));
}

/** Every layer of the tree, leaves first. Empty for no leaves. */
export function evidenceLayers(leaves: string[]): string[][] {
/**
* Every layer of the tree, leaves first. Empty for no leaves. `pair` hashes two nodes into their parent, and
* must give what hashPair gives: matchEvidenceRoot passes a memo of it.
*/
export function evidenceLayers(leaves: string[], pair: (a: string, b: string) => string = hashPair): string[][] {
if (!leaves.length) return [];
const layers = [leaves.slice()];
let level = leaves.slice();
while (level.length > 1) {
const next: string[] = [];
for (let i = 0; i < level.length; i += 2) next.push(i + 1 < level.length ? hashPair(level[i], level[i + 1]) : level[i]);
for (let i = 0; i < level.length; i += 2) next.push(i + 1 < level.length ? pair(level[i], level[i + 1]) : level[i]);
layers.push(next);
level = next;
}
return layers;
}

/** The root over these leaves, in order. The zero hash for none, which the contract treats as no root. */
export function evidenceRoot(leaves: string[]): string {
/**
* The root over these leaves, in order. The zero hash for none, which the contract treats as no root. `pair` is
* as for evidenceLayers.
*/
export function evidenceRoot(leaves: string[], pair: (a: string, b: string) => string = hashPair): string {
if (!leaves.length) return ZERO_ROOT;
const layers = evidenceLayers(leaves);
const layers = evidenceLayers(leaves, pair);
return layers[layers.length - 1][0];
}

Expand Down Expand Up @@ -130,11 +136,20 @@ export interface RootMatch {
* reproduces it, as the explorer's matchRoot does (site/assets/explorer.js).
*
* A proposal commits to the payments settled by the time it was made, and a payer can sign an outcome after
* that. So the root is tried against every payment, against those counted by each cut-off, and against both
* with every payer-signed outcome read as not reported. With `at` (a proposal's time, in seconds) only that
* cut-off is tried. Each try rebuilds a tree, so the work is about (cut-offs tried) times (payments) times two;
* a caller facing a long list from a source it does not trust lowers `maxCuts`. `leaves`, when given, are the
* records' leaves as served, already built. Throws if a record cannot be a leaf at all.
* that. So the root is tried against every payment, against those counted by each of up to `maxCuts` cut-offs,
* and against both with every payer-signed outcome read as not reported. With `at` (a proposal's time, in
* seconds) only that cut-off is tried. `leaves`, when given, are the records' leaves as served, already built.
* Throws if a record cannot be a leaf at all.
*
* Neighbouring cut-offs count nearly the same payments in the same order, so their trees share every pair to the
* left of where they first differ. Every tree here is hashed through one memo of pairs, so a cut-off costs only
* the pairs no tree before it held: on a list in settlement order, whose lower cut-offs leave out its last
* payments, at most one a level of each tree, eleven at 2,000 payments. A cut-off that counts the same payments as
* the one before it is skipped. `hashBudget` bounds the pairs hashed: once past it no further cut-off is tried,
* though the first always is, in full. A caller facing a long list from a source it does not trust sets one, since
* a list ordered so that its trees share little costs a whole tree per cut-off. `memo`, when given, is that memo,
* so matches over the same list can share it; each pair hashed adds one entry, and only what a call adds counts
* against its budget.
*
* `delays` (chain id to seconds, as /evidence serves them) says how much later a payment chain's payment enters a
* score than its settlement. `evidenceCut` (also from /evidence, present when a chain is on) says a proposal's
Expand All @@ -145,12 +160,14 @@ export interface RootMatch {
export function matchEvidenceRoot(
records: EvidenceRecord[],
committed: string,
{ at, maxCuts = 64, leaves, delays = {}, evidenceCut = null }: {
{ at, maxCuts = 64, leaves, delays = {}, evidenceCut = null, hashBudget = Infinity, memo = new Map<string, string>() }: {
at?: number;
maxCuts?: number;
leaves?: string[];
delays?: Record<number, number>;
evidenceCut?: { quantumSeconds: number; windowSeconds: number } | null;
hashBudget?: number;
memo?: Map<string, string>;
} = {},
): RootMatch | null {
if (!HASH.test(committed)) return null;
Expand All @@ -170,13 +187,27 @@ export function matchEvidenceRoot(
const cuts = at !== undefined
? [Number(at), ...quantized.filter((t) => t < Number(at))]
: [Infinity, ...[...new Set(counts)].sort((a, b) => b - a).slice(0, maxCuts)];
const start = memo.size;
const pair = (a: string, b: string) => {
const key = a + b;
let parent = memo.get(key);
if (parent === undefined) memo.set(key, (parent = hashPair(a, b)));
return parent;
};
let tried: number[] | null = null;
for (const cut of cuts) {
// The memo grows by one for each pair hashed. The first cut-off is tried whatever the budget.
if (tried && memo.size - start > hashBudget) break;
const indexes = records.map((_, i) => (counts[i] <= cut ? i : -1)).filter((i) => i >= 0);
// The cut-offs only go down, so one that counts as many payments as the last one tried counts the same ones,
// whose trees did not match.
if (tried && indexes.length === tried.length) continue;
tried = indexes;
const tries: [string[], boolean][] = [[asServed, false]];
if (indexes.some((i) => signed[i])) tries.push([unsetLeaves, true]);
for (const [leaves, unset] of tries) {
const picked = indexes.map((i) => leaves[i]);
if (evidenceRoot(picked).toLowerCase() === want) return { indexes, leaves: picked, cut, unset };
if (evidenceRoot(picked, pair).toLowerCase() === want) return { indexes, leaves: picked, cut, unset };
}
}
return null;
Expand Down
Loading
Loading