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 @@ -600,11 +600,11 @@ Everything below runs offline, with no deployed contracts, except three fork sui

| Suite | Count | Command |
|---|---|---|
| Contracts: unit, fuzz, E2E, upgrade, deploy-script, handover and 22 invariants | 799 | `forge test` |
| Contracts: unit, fuzz, E2E, upgrade, deploy-script, handover and 22 invariants | 815 | `forge test` |
| Oracle | 1544 | `cd oracle && node --test` |
| SDK | 392 | `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 15 November and the oracle on 15 November. Without a fork URL, 787 of the contract tests run and 12 skip. Run after `npm run build`, 383 of the SDK's 392 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 15 November. Without a fork URL, 803 of the contract tests run and 12 skip. Run after `npm run build`, 383 of the SDK's 392 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
3 changes: 2 additions & 1 deletion docs/adr/0010-what-can-be-slashed.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ The contract takes one address, and it cannot be zero, the reporter, a committee

`evidenceHash` is free-form, so no contract change is needed. The bytes read
`sigvara/slash/v1;ground=A1;sha256=<hash of the package>`, and the package is published when the slash is
filed, as the drill's log was.
filed, as the drill's log was. `initiateSlash` refuses more than 256 bytes (`MAX_EVIDENCE_BYTES`), and this
form takes about a hundred.

### 7. Wrongful slashes and stolen keys

Expand Down
2 changes: 1 addition & 1 deletion docs/authorisation-matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ README's [Access Control Summary](../README.md#access-control-summary).
| `grantRole(bytes32,address)` | `inherited` | `-` | The caller holds `getRoleAdmin(role)`. `initialize` makes `UPGRADER_ROLE` the admin of `UPGRADER_ROLE` and `SLASHING_COMMITTEE_ROLE`; `DEFAULT_ADMIN_ROLE` administers itself and `GUARDIAN_ROLE` (OpenZeppelin default). | Grants `role` to `account` if not already held. Emits `RoleGranted`. |
| `initialize(address,address,address,address,uint256,uint256,uint256)` | `initializer` | `-` | Once per proxy, by any account (the implementation's initializers are disabled). Nonzero `admin`, token and registries; `minimumStake_` nonzero; challenge period 3 to 10 days; unbonding period 1 to 90 days. | Grants `admin` `DEFAULT_ADMIN_ROLE` and `UPGRADER_ROLE`; makes `UPGRADER_ROLE` the admin of `UPGRADER_ROLE` and `SLASHING_COMMITTEE_ROLE`; stores registries, token and the three parameters. Grants no committee member or guardian. Emits `RoleGranted`, `RoleAdminChanged`, `Initialized`. |
| `initializeV2(uint256)` | `reinitializer:2`, `role:DEFAULT_ADMIN_ROLE` | `-` | A `DEFAULT_ADMIN_ROLE` holder, once: initializer version 2 must be unconsumed, which is still true after a fresh `initialize`, so `Deploy.s.sol` calls it at once and `check-mainnet.sh` checks it ran. Period 1 to 90 days. | Sets `unbondingPeriod` and consumes version 2. Emits `UnbondingPeriodUpdated` and `Initialized(2)`. |
| `initiateSlash(bytes32,address,bytes)` | `role:SLASHING_COMMITTEE_ROLE` | `-` | A `SLASHING_COMMITTEE_ROLE` holder. Victim nonzero, not the caller, not any committee member, not a `DEFAULT_ADMIN_ROLE` holder; active plus queued stake nonzero; no `Pending` or `Disputed` proposal; one `challengePeriod` since the last drop; evidence not previously rejected by the admin. | Writes a `Pending` proposal (reporter, victim, evidence, `challengeDeadline` = now + `challengePeriod`), replacing any closed one; suspends the agent in `SigvaraIdentity` and freezes withdrawals. Emits `SlashInitiated`. |
| `initiateSlash(bytes32,address,bytes)` | `role:SLASHING_COMMITTEE_ROLE` | `-` | A `SLASHING_COMMITTEE_ROLE` holder. Victim nonzero, not the caller, not any committee member, not a `DEFAULT_ADMIN_ROLE` holder; active plus queued stake nonzero; no `Pending` or `Disputed` proposal; one `challengePeriod` since the last drop; evidence at most `MAX_EVIDENCE_BYTES` (256) long and not previously rejected by the admin. | Writes a `Pending` proposal (reporter, victim, evidence, `challengeDeadline` = now + `challengePeriod`), replacing any closed one; suspends the agent in `SigvaraIdentity` and freezes withdrawals. Emits `SlashInitiated`. |
| `initiateWithdrawal(bytes32,uint256)` | `checked` | `-` | The agent's current operator. Stake and `amount` nonzero; no withdrawal already queued; no `Pending` or `Disputed` slash; `amount` at most the stake; an `Active` agent must keep at least `minimumStake`. | Moves `amount` from the stake into the unbonding queue, sets `unbondingAt` and fixes `unbondingClaimableAt` at now plus `unbondingPeriod`. Queued stake stays slashable. Emits `WithdrawalInitiated`. |
| `pauseInflows()` | `checked` | `-` | A `GUARDIAN_ROLE` holder (`_checkGuardian`). No pause running, and `PAUSE_DURATION` plus `PAUSE_COOLDOWN` (4 days) since the previous pause began, even if it was lifted early. | Closes `depositStake`, the only `inflows`-guarded function, for 3 days; it reopens by itself. Withdrawals, claims, disputes, slashing and admin calls stay open. Records `lastPausedAt`. Emits `InflowsPaused`. |
| `renounceRole(bytes32,address)` | `inherited` | `-` | Only the account itself: `callerConfirmation` must equal the caller. | Removes `role` from the caller if held. Emits `RoleRevoked`. If the last `UPGRADER_ROLE` holder renounces, upgrades and committee grants end for good. |
Expand Down
6 changes: 6 additions & 0 deletions docs/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,12 @@ running older code than the interfaces expect. Registry addresses are in
`deployments/<chainId>.json`, which does not list a reader. If a registry upgrade ever changes
a function the reader calls, deploy a new reader.

A reader built from the current source reads the slash state with staking's `slashState`, which
copies one field where `getSlashProposal` copied the whole proposal and its evidence. A staking
proxy running code from before that view cannot answer it, and every `trust` call for a
registered agent would revert, so deploy such a reader only after staking is upgraded, with
`SMOKE_AGENT` set. The reader already on Arc testnet calls `getSlashProposal`, which stays.

## Example

[`examples/gated-marketplace/GatedMarketplace.sol`](../examples/gated-marketplace/GatedMarketplace.sol)
Expand Down
2 changes: 1 addition & 1 deletion docs/whitepaper.md
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ roles, and administers `UPGRADER_ROLE`), and the timelocked role grants describe
apply to a fresh deployment, not to the testnet.
`node scripts/record-implementations.mjs --check` shows what is live.

**Test coverage**, as of 15 November 2026: 799 contract tests across 36 Foundry test files
**Test coverage**, as of 15 November 2026: 815 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`), 1544 oracle tests and 392 in the SDK (9 skip
outside CI and without a live deployment; every test that runs passes). CI runs Foundry, the oracle and
Expand Down
16 changes: 15 additions & 1 deletion script/Upgrade.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ contract Upgrade is Script {
* upgrade landed. The tests never caught it because they deploy both
* contracts from the same source every time; only a live pair can be skewed.
*
* The contracts are now tolerant of the skew as well. This is the second
* The contracts are now tolerant of that skew as well. This is the second
* layer: refuse the ordering rather than quietly degrade into it.
*
* For standingOf, which reputation and staking read on their write paths, this
* check is the only layer. They do not fall back to getIdentity, because
* upgrading identity first is safe: it only adds the view.
*/
function _checkDependencies(string memory target, address proxy) internal view {
bytes32 t = keccak256(bytes(target));
Expand All @@ -129,6 +133,11 @@ contract Upgrade is Script {
if (!_answers(identity, abi.encodeWithSignature("operatorChangedAt(bytes32)", bytes32(0)))) {
revert DependencyMissing("reputation", "identity.operatorChangedAt: upgrade identity first", identity);
}
// Every proposal and finalize reads the agent through standingOf, so against an
// identity without it the oracle could write no score at all.
if (!_answers(identity, abi.encodeWithSignature("standingOf(bytes32)", bytes32(0)))) {
revert DependencyMissing("reputation", "identity.standingOf: upgrade identity first", identity);
}
}

if (t == keccak256("staking")) {
Expand All @@ -139,6 +148,11 @@ contract Upgrade is Script {
if (!_answers(identity, abi.encodeWithSignature("stakeView()"))) {
revert DependencyMissing("staking", "identity.stakeView: upgrade identity first", identity);
}
// Deposits, withdrawals, claims and disputes read the agent through standingOf,
// so against an identity without it each of them would revert.
if (!_answers(identity, abi.encodeWithSignature("standingOf(bytes32)", bytes32(0)))) {
revert DependencyMissing("staking", "identity.standingOf: upgrade identity first", identity);
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/mutation/mutate-invariants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ runl R7 $RS $R 'function _propose(' '_requireBondedOracle();' '_requireBondedOr
# R8 and R10 are expected survivors. A slash zeroes the stake and a slashed agent cannot bond again, and a hash nobody
# registered holds no stake, so the bond check refuses the same proposals and only the name of the error differs. The
# invariants check what is refused, not why; E2E.t.sol and SigvaraReputation.t.sol pin the names.
runl R8 $RS $R 'function _requireScorable(' 'if (id.status == SigvaraIdentity.AgentStatus.Slashed)' 'id.status == SigvaraIdentity.AgentStatus.Slashed' 'false' 'a slashed agent can be scored'
runl R8 $RS $R 'function _requireScorable(' 'if (status == SigvaraIdentity.AgentStatus.Slashed)' 'status == SigvaraIdentity.AgentStatus.Slashed' 'false' 'a slashed agent can be scored'
runl R9 $RS $R 'function _requireScorable(' 'if (!stakeView.hasMinimumStake(didHash))' '!stakeView.hasMinimumStake(didHash)' 'false' 'an unbonded agent can be scored'
runl R10 $RS $R 'function _requireScorable(' 'if (id.registeredAt == 0)' 'id.registeredAt == 0' 'false' 'an unregistered hash can be scored'
runl R10 $RS $R 'function _requireScorable(' 'if (registeredAt == 0)' 'registeredAt == 0' 'false' 'an unregistered hash can be scored'
runl R11 $RS $R 'function proposeReputation(' 'onlyRole(ORACLE_ROLE)' 'onlyRole(ORACLE_ROLE)' '' 'anyone can propose'
runl R12 $RS $R 'function proposeReputation(' 'whenInflowsOpen' 'whenInflowsOpen' '' 'a pause does not stop proposals'
runl R13 $RS $R 'function proposeIfEmpty(' 'if (existing.exists && _proposerStillAuthorized(existing.proposer))' '_proposerStillAuthorized(existing.proposer)' 'false' 'proposeIfEmpty replaces a live proposal'
Expand Down
18 changes: 18 additions & 0 deletions src/SigvaraIdentity.sol
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,24 @@ contract SigvaraIdentity is Initializable, TimelockedGrants, UUPSUpgradeable, In
return identities[didHash];
}

/**
* @notice Who operates the agent, its status, and when it was registered. registeredAt is zero
* for a didHash that was never registered, and status then reads Active, the zero value,
* so check registeredAt first.
* @dev The three fields the reputation and staking registries act on. getIdentity copies all
* five out of storage, and the agent address and the Ed25519 key are two storage reads
* those callers never use. Both registries call this, so a live identity proxy runs this
* code before either of them does; script/Upgrade.s.sol refuses the other order.
*/
function standingOf(bytes32 didHash)
external
view
returns (address operator, AgentStatus status, uint256 registeredAt)
{
AgentIdentity storage id = identities[didHash];
return (id.operator, id.status, id.registeredAt);
}

function isActive(bytes32 didHash) external view returns (bool) {
AgentIdentity storage id = identities[didHash];
return id.registeredAt != 0 && id.status == AgentStatus.Active;
Expand Down
2 changes: 1 addition & 1 deletion src/SigvaraReader.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ contract SigvaraReader is ISigvaraReader {
t.score = reputation.getTotalScore(didHash);
t.earned = reputation.getEarnedScore(didHash);
t.stake = staking.getStake(didHash);
t.slash = staking.getSlashProposal(didHash).state;
t.slash = staking.slashState(didHash);
t.collateralized = staking.hasMinimumStake(didHash);
t.scoreUpdatedAt = reputation.getReputation(didHash).lastUpdated;
}
Expand Down
10 changes: 6 additions & 4 deletions src/SigvaraReputation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -657,9 +657,9 @@ contract SigvaraReputation is Initializable, TimelockedGrants, UUPSUpgradeable,
SigvaraIdentity registry = identityRegistry;
if (address(registry) == address(0)) revert IdentityRegistryNotSet();

SigvaraIdentity.AgentIdentity memory id = registry.getIdentity(didHash);
if (id.registeredAt == 0) revert AgentNotRegistered(didHash);
if (id.status == SigvaraIdentity.AgentStatus.Slashed) revert AgentSlashed(didHash);
(, SigvaraIdentity.AgentStatus status, uint256 registeredAt) = registry.standingOf(didHash);
if (registeredAt == 0) revert AgentNotRegistered(didHash);
if (status == SigvaraIdentity.AgentStatus.Slashed) revert AgentSlashed(didHash);

IStakeView stakeView = registry.stakeView();
if (address(stakeView) == address(0)) revert StakeViewNotSet();
Expand Down Expand Up @@ -818,7 +818,9 @@ contract SigvaraReputation is Initializable, TimelockedGrants, UUPSUpgradeable,
{
bytes32 root = evidenceRoots[didHash];
if (root == bytes32(0)) return false;
return MerkleProof.verify(proof, root, leaf);
// Reads the proof where it lies. verify takes it from memory, so the proof was copied
// there first, for the same answer.
return MerkleProof.verifyCalldata(proof, root, leaf);
}

/// @notice The score as computed, before maturity is applied. Max 100.
Expand Down
Loading
Loading