Skip to content

Keep a finalized proposal's slots for the next one to overwrite - #316

Merged
RunTimeAdmin merged 1 commit into
mainfrom
fix/finalize-keeps-pending-slots
Nov 15, 2026
Merged

RunTimeAdmin merged 1 commit into
mainfrom
fix/finalize-keeps-pending-slots

Conversation

@RunTimeAdmin

Copy link
Copy Markdown
Owner

Finding 11 from the 15 November performance review. The oracle, SDK and site parts of the other moderate findings are separate PRs.

What changes

finalizeReputation ended with delete pendingScores[didHash]. That earned a refund, and then the agent's next proposal paid about 22,100 gas for each of the six slots it filled from zero, where overwriting a slot that still holds a value costs about 5,000. It now clears exists and leaves the other fields for the next proposal to overwrite. rejectReputation, discardStrandedScore and zeroReputation still delete.

Measured in forge with each call as its own transaction (cold storage, refunds, the 21,000 base):

Steady state Before (propose + finalize) After Change
Oracle-style data, a new lastUpdated each epoch 227,155 + 123,927 = 351,082 121,755 + 130,785 = 252,540 98,542 less (28.1%)
lastUpdated = 0 207,231 + 123,308 = 330,539 118,931 + 130,785 = 249,716 80,823 less (24.5%)
  • The finalize on its own costs about 6,858 more, because its refund is smaller.
  • An agent's first cycle costs 9,477 more, once. After a reject, discard or slash the next proposal pays full price, as before.

What reads differently

getPendingScore (and the public pendingScores getter) after a finalize returns that proposal's fields with exists false, where it returned zeros. Everything in this repo checks exists first: the contract's own paths, the oracle (chain.js, epoch-policy.js, index.js), the watcher, the SDK and the site's four pages. An outside reader that takes proposedAt != 0 to mean "pending" would misread a finalized slot.

Updated to match:

  • docs/incident-operator-key.md step 3 read proposer without checking exists.
  • oracle/RUNBOOK-second-operator.md step 2 looked for an empty slot; it now tests exists (word 8).
  • docs/authorisation-matrix.md said finalize deletes the proposal; three oracle/chain.js comments said an ended slot is zeroed.
  • test/ReputationInvariant.t.sol modelled finalize as a delete, and the invariant that compares whole structs would have failed.
  • scripts/mutation/mutate-invariants.sh: mutation R26 pointed at the deleted line, and would have silently mutated rejectReputation's delete instead.

Deploy

An implementation-only upgrade of SigvaraReputation. No layout change: forge inspect storageLayout is identical before and after, and the slot-pinning tests (test_storageLayout_*, test/Upgrade.t.sol) pass. Nothing else needs to move with it.

Tests

799 forge tests: 787 run and pass, 12 skip without a fork URL (README and whitepaper updated). New, in test/SigvaraReputation.t.sol:

  • after a finalize exists is false, and finalize, reject and discard all revert NoScorePending;
  • a second proposal, from another oracle under another window with zero values, records only its own fields;
  • the gas bound on the next proposal. With the delete restored it fails: 227,155 against a bound of 140,000.

🤖 Generated with Claude Code

finalizeReputation deleted the whole pending struct. That earned a
refund, and then the agent's next proposal paid about 22,100 gas for
each slot it filled from zero. It now clears only exists, which every
reader checks first, and the next proposal writes every field, so
nothing carries over. Rejecting, discarding and zeroing still delete
the slot.

Measured as separate transactions, the next proposal falls from 227,155
to 121,755 gas and a propose and finalize cycle from 351,082 to 252,540;
the finalize alone costs 6,858 more for its smaller refund. Tests pin
that nothing acts on the fields left behind or inherits them, and bound
the next proposal's gas. The invariant model, mutation R26 and the docs
that read a finalized slot as empty follow the change. 799 forge tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RunTimeAdmin
RunTimeAdmin merged commit a101f07 into main Nov 15, 2026
7 checks passed
@RunTimeAdmin
RunTimeAdmin deleted the fix/finalize-keeps-pending-slots branch November 15, 2026 21:55
RunTimeAdmin added a commit that referenced this pull request Nov 15, 2026
Main brought #316, whose test counts share a README paragraph with this branch's. The version moves in
package.json, the lockfile and server.json; the README's "use alpha.20" lines follow once alpha.21 is on npm.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RunTimeAdmin added a commit that referenced this pull request Nov 15, 2026
Main brought #316 and #317, whose test counts share a README and whitepaper line with this branch's. chain.js merged
without a conflict (#316 changed comments only); its tests and the docs check pass on the merged tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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