Skip to content

Bound slash evidence, read standing and slash state alone, and verify proofs from calldata - #326

Merged
RunTimeAdmin merged 3 commits into
mainfrom
fix/contract-views-gas
Nov 16, 2026
Merged

RunTimeAdmin merged 3 commits into
mainfrom
fix/contract-views-gas

Conversation

@RunTimeAdmin

Copy link
Copy Markdown
Owner

The contracts' part of the minor findings (17, 18 and 19) from the 15 November performance review. Nothing is deployed by merging: each change waits for an upgrade, in the order below.

What changes

17. Slash evidence was unbounded, and SigvaraReader.trust copied all of it (SigvaraStaking.sol, SigvaraReader.sol)

  • initiateSlash refuses evidence over MAX_EVIDENCE_BYTES (256) with EvidenceTooLong. ADR 0010's evidence form is 98 bytes, and every drill and sim slash is 98 or fewer.
  • A slashState(didHash) view returns the state alone, and the Reader reads it instead of copying the whole proposal. getSlashProposal stays for the keeper, SDK, site and scripts.

18. verifyEvidence copied its calldata proof into memory (SigvaraReputation.sol)

  • MerkleProof.verifyCalldata, with the same verdicts (a fuzz test compares it with verify on genuine and altered proofs).

19. The registries read the whole identity record to use three fields (SigvaraIdentity.sol, SigvaraReputation.sol, SigvaraStaking.sol)

  • standingOf(didHash) returns operator, status and registeredAt. Reputation's _requireScorable and staking's four call sites use it; getIdentity stays.
Call (cold, one transaction each) Before After
Reader trust, slash open, 1 byte of evidence 86,184 68,501
Reader trust, slash open, 256 bytes of evidence 104,554 68,501
verifyEvidence, 11-hash proof 10,654 10,411
depositStake 171,937 167,035
claimWithdrawal 74,185 69,288
disputeSlash 82,204 77,307
finalizeReputation 177,137 172,236

standingOf saves about 4,900 gas a call, not the review's 9.4k: the two fields it skips cost two cold reads and their encoding.

Deploy order on Arc testnet

  1. Identity, at any time. Its live build differs from main only in comments, so this adds standingOf.
  2. Reputation, after identity. Before it, every proposal and finalize would revert.
  3. Staking, after identity and after the slash drill ends on 24 November. Before identity, deposit, withdrawal, claim and dispute would revert; dispute is the dangerous one.
  4. A new Reader, after staking. The Reader at 0x2921b4eE879CdF5793FA273BbDc4E7dF01ABcef8 keeps working throughout, and moving the SDK and site to a new one is its own step.

script/Upgrade.s.sol now refuses a reputation or staking upgrade while the identity proxy cannot answer standingOf. An upgrade through the timelock is not checked by it, so whoever schedules one keeps this order (docs/integration.md says so for the Reader).

Checks

  • 815 forge tests, 803 run and pass, 12 skip without a fork URL (README and whitepaper updated).
  • All 7 gas tests fail on main, each on its own line's cost.
  • forge inspect storageLayout is identical before and after for Identity, Reputation and Staking, struct members included, and the slot-pinning tests pass.
  • Sizes stay under 24,576: Identity 11,896, Reputation 14,929, Staking 16,016, Reader 4,177.
  • check-authz.mjs and check-docs.mjs pass. Mutations R8 and R10 point at the renamed lines.

Left alone: the Reader's own identity read in _trust and SigvaraEpochFees's two calls could use standingOf later.

🤖 Generated with Claude Code

RunTimeAdmin and others added 3 commits November 15, 2026 17:32
…view

- 17: initiateSlash refuses evidence longer than MAX_EVIDENCE_BYTES (256) with
  EvidenceTooLong. Staking gains slashState, the state of the latest proposal
  alone, and the Reader reads it instead of copying the whole proposal with its
  evidence. A trust read of an agent with a slash open falls from 86,184 gas
  (one byte of evidence) and 104,554 (256 bytes) to 68,501 either way.
- 18: verifyEvidence checks the proof with MerkleProof.verifyCalldata instead of
  copying it into memory. An eleven-hash proof falls from 10,654 to 10,411 gas.
- 19: identity gains standingOf (operator, status, registeredAt). Reputation's
  scorability check and staking's deposit, withdrawal, claim and dispute read it
  instead of getIdentity, about 4,900 gas less a call. Upgrade.s.sol refuses a
  reputation or staking upgrade against an identity without it.

No storage is added or moved: forge inspect gives the same layouts for identity,
reputation and staking. On testnet the order is identity, then reputation, then
staking once the drill ends, then a new Reader. getIdentity and getSlashProposal
stay for the keeper, SDK, site and scripts. Mutations R8 and R10 follow the
renamed locals. 815 forge tests, 12 of them skipped without a fork URL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ke, not by gas

CI's forge measured the identity's reads warm under isolate, so the five bounds set between the cold figures
failed there: a finalize read 177,036, the old code's cost. Each test now expects standingOf and no getIdentity,
which fails on the old code in any toolchain. The measured figures stay in the comments.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Main brought #323, #324, #325 and #327; the only conflict was the test-count paragraph in README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RunTimeAdmin
RunTimeAdmin merged commit 949cc17 into main Nov 16, 2026
7 checks passed
@RunTimeAdmin
RunTimeAdmin deleted the fix/contract-views-gas branch November 16, 2026 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant