Repository navigation
v1.1: formal-verification findings and fixes - #4
Conversation
Add crates/core/src/findings.rs, a #[cfg(test)] module with one test per core finding from the formalver verification (F-1, F-2, F-2b, F-3, F-4, F-5, F-6) and one for the cancel error name (div-cancel-terminal-name). Each test asserts what v1.0.0 returns today, including the faulty results, so CI stays green and each v1.1 fix flips the test that pins it. No non-test code changes; lib.rs only wires the module. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/verification-findings.md lists the findings of the formalver verification (difflabai/formalver PR #31): what happens, which doc line it contradicts, a core call sequence, the reproducer test and where the formal evidence lives. It also covers the docs-vs-code items, the measured minimum prepaid gas at the maximum state, and the version u32::MAX preview/submit observation. Linked from the README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Trace 207 replays F-3 on a smaller config than the gpu fixture the reproducer uses, so label it "(a smaller config)" as F-4 and F-6 already do; the test doc comments for traces 207, 210 and 211 say the same. The Evidence paragraphs cite TLC, Lean, Prolog, shell and sandbox results from formalver strategy.md section 4. Say so, mark the per-trace equality claims "reported", and state that only the findings.rs tests run here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… diff list Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…error text (NT-F1)
scripts/build.sh now builds both Wasm files with RUSTFLAGS="--cfg near"
(and unsets CARGO_ENCODED_RUSTFLAGS). Without the flag near-sdk's
panic_str traps without calling panic_utf8, so every failed call lost
its error name. A small wasm import-section parser in the manifest step
fails the build unless each Wasm imports env.panic_utf8, and
artifacts/build.json records the flags and each Wasm's sorted imports.
The sandbox helper fail() takes the expected panic text and asserts the
failure carries it ("Pending", "Unauthorized", "only lock may execute",
"Method on_result is private"). Run against the v1.0.0 plain build it
fails on the bare unreachable trap, so it now catches NT-F1.
api.md deployment step 1 and the README build note describe the flag.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…1, F-2, F-2b) envelope() now counts each open record's release (-reserve x units) as well as its completion, and check_bounds compares each metric's interval violation with min(violation now, violation at the candidate). Together they keep every open record resolvable: a Reserved record can always be cancelled, and a dispatched one settled either way. Admission is stricter. A reservation that by itself cures a violated metric is refused; recovery must come from completion. An admission that is in bounds only while another record's reservation stays in place is refused too. In the risk fixture a hedge next to an open credit position is now at most 6 units, not 8. findings.rs: the F-1, F-2 and F-2b reproducers become regression tests (f1_hedge_that_cures_by_reservation_is_refused, f1_recovery_by_completion_is_admitted_and_live, f2_hedge_cannot_rely_on_an_unexecuted_position, f2_reserved_position_can_always_be_cancelled, f2b_release_stays_in_the_value_range). New assert_live helper and live_all_on_random_runs: 300 seeded configs x 60 calls, checking after every call LIVE, HARD-STEP, INV-RES, preview/submit agreement and atomic errors. It fails on v1.0.0 and on either half of the fix alone. Docs: spec admission, recovery, release and risk text; handoff RISK row, new LIVE row and nuances; README boundary; implementation-plan steps 4-5. Scenario exports are unchanged. Not formally re-verified. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Config::validate rejects a recipe whose actor is its executor (InvalidConfig). Submit and dispatch need the actor; settle needs the executor. With the two distinct, no account both starts and attests one recipe's work. The owner may still be an actor or an executor. The F-4 reproducer becomes f4_actor_cannot_be_its_own_executor: both v1.0.0 mutations are rejected, owner-as-actor with an independent executor works, and all six fixtures validate. spec and api deployment step 3 say the two accounts must differ. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
observe returns Pending only when the values differ and a record is open. The owner can always restate the current values: values and records stay, the snapshot timestamp is renewed and the version moves by one, so submit and dispatch resume after max_age. New values still wait for every record to be terminal. The F-6 reproducer becomes f6_owner_refreshes_the_snapshot_with_records_open. The F-5 reproducer's observe line changes from Pending to Arithmetic (a restatement now reaches the version bump; F-5 rewrites that test next). live_all_on_random_runs also checks that an observe with a record open changes no value or record. spec, api, implementation-plan, README and handoff describe the refresh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
New VERSION_CAP = u32::MAX - 3 * MAX_RECORDS. submit (last guard in candidate, so preview reports it), dispatch, set_paused and observe fail Arithmetic from the cap on. Acknowledgment, settlement and cancellation keep the plain checked increment. An open record needs at most three more increments and there are at most 256 records, so they never overflow and every open record still resolves at the cap. The F-5 reproducers become f5_open_records_resolve_above_the_version_cap and f5_paused_pool_at_the_cap_still_settles; new f5_reserve_is_exactly_enough resolves 256 Dispatched records from the cap by the longest path and ends at exactly u32::MAX. spec, api and handoff describe the reserve; the handoff's liveness premise no longer names the version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…v-cancel, div-ack) cancel of a Completed record returns InvalidState, the name settle uses for conflicting terminal evidence. Dispatched, Active and Unknown keep Pending (the executor's evidence is pending); a repeated cancel stays an Ok no-op. The div-cancel reproducer becomes cancel_names_conflicting_and_in_flight_states (every status, by the actor, the owner and a stranger; the pool is unchanged). spec and api now say that calls which change nothing (repeated settlement or cancel, an acknowledgment that does not change the status, a late acknowledgment) return Ok without a version change; the code already did. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and logs unknown ids (NT-F2, NT-F4) reconcile is &self, so near-sdk generates no nonpayable check for it; it now requires a zero deposit with near-sdk's own message. on_result drops #[callback_result] and reads the promise result itself: anything but one JSON string of at most 64 bytes (a failure, a number, null, an object, invalid bytes, a longer result, a result count other than 1) is "unknown" and the record goes Unknown. A result for an id with no record is logged with error NotFound instead of panicking. Pool::record is now public; it still indexes by id. Tests: nt_f2_reconcile_rejects_deposit, reconcile_without_deposit_is_open_to_anyone, nt_f4_non_string_result_becomes_unknown (16 result shapes, incl. the 64/65 byte bound), nt_f4_result_for_unknown_id_is_logged; sandbox: a 1 yocto reconcile fails with the deposit message. api.md lines 3, 18 and 34. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…all imports (NT-F3) Both contracts create their promises with env::promise_create, promise_then and promise_return instead of near_sdk::Promise, whose action code linked 15 host functions for deploy, keys, transfer, stake, accounts and global contracts. Same targets, arguments, deposit (0), static gas (execute 30 + on_result 30, status 10 + on_result 30, settle 40) and unused-gas weight (0); new unit tests pin these receipts and pass on both the old Promise code and the new code. dispatch, reconcile, finish and confirm_not_executed return () in Rust; on chain the result is still the callback's (promise_return). build.sh now also fails if a wasm imports any of the 15, or any promise_batch_* function. Imports: contract 36 -> 18, executor 32 -> 13. Docs: handoff boundary checks, api.md build step, README build note. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… records (F-3) The pool keeps its 256 most recent records. A submit into a full window prunes the oldest record when it is terminal and fails Full while it is open. Ids keep counting (records[k].id == first_id + k) and a pruned id is NotFound for every call. Prerequisites read completed_units, a lifetime per-recipe count updated by settle(true), so pruning cannot undo them. The contract looks records up by id in dispatch and reconcile, and get_commitments pages by id. The synthetic executor forgets a job once its id is 256 behind the newest id it executed for the lock: execute of such an id returns "cancelled" and starts nothing, confirm_not_executed fails "stale id". Only execute moves the newest id. Job cap 512. The F-3 reproducer becomes f3_window_frees_terminal_records_and_keeps_ids. New: f3_prerequisites_survive_pruning, window_on_random_runs, contract and executor window tests, and a 300-record sandbox run through the executor. arithmetic_and_record_limits expects Full only with an open oldest record. Scenario traces gain first_id and completed_units when they are regenerated in the next commit. Tested, not formally re-verified. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sm (gas) The six trace.json files gain only "first_id": 0 and "completed_units" in every serialized pool (276 lines added, none removed); every decision, reason, value and version is unchanged. config.json files are unchanged. api.md gets a Gas section. A scratch sandbox test adapted from formalver's RES-1 measured the v1.1 wasm at a maximum-size state (32 metrics, 64 terms, 32 recipes, 256 retained records, all open; executor at 256 jobs). Least prepaid gas that succeeds: dispatch 70, reconcile 46, finish and confirm_not_executed 43 Tgas; largest single receipt 14.81 Tgas (submit with 255 open records). Recommended: 100, 60, 60 and 30 Tgas. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…6, NT-F1 to NT-F4) Workspace version 1.1.0; Cargo.lock refreshed with cargo update -w (only the five workspace crates change). New CHANGELOG.md with 1.1.0 (Fixed, Changed, Docs) and the 1.0.0 baseline. docs/verification-findings.md gets a status line per finding with its fixing commit and regression tests. README, spec, api, judges-guide and nearhackathon.md say this is v1.1.0: the formal results apply to v1.0.0 (a4bb5c3), and v1.1.0 fixes the findings but has not been re-verified. The wasm code sections are byte-identical to the build measured for the gas table; only the embedded NEP-330 version string and symbol names change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Resolves the nearhackathon.md conflict. Keeps main's Submission, Formal verification and Live site rows and its "part of the submission" sentence, and keeps the v1.1 sentence: the formal results apply to v1.0.0, and v1.1.0 fixes the findings, tested but not re-verified. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The import check only named known action imports. A host function such as promise_yield_create or promise_set_refund_to, or one a later near-sdk adds, would have passed. build.sh now also fails on any import that is not on the reviewed list: the current 18 contract and 13 executor imports, all env functions. A non-function import carries its kind, so it cannot match. The denylist stays as a second guard. The Wasm files and their hashes are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NT-F4 was tested with the mock runtime only, because the bundled executor always returns strings. A hand-assembled Wasm executor (one import, env.value_return) now returns the JSON number 5 from execute and a 70-byte JSON string from status. Through the deployed lock, dispatch and reconcile both succeed, log outcome "unknown", and leave the record Unknown with its reservation held; the executor account's settle(false) then releases it. With a valid string the test fails, so it sees the result. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The docs said the oldest record "can always be closed". That holds for a Reserved record, which its actor or the owner can cancel. A Dispatched, Active or Unknown record closes only when its executor reports, so a silent executor holds submit at Full even if the other 255 records are terminal. README, api.md, the handoff, CHANGELOG and the F-1 and F-3 status lines now say so. No code change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The site still said the verification reports F-1 and F-2, with no word that v1.1.0 fixes them, and still described 256 lifetime commitments and rotating the pool. Each verification sentence now says the formal work covers v1.0.0 and that v1.1.0 fixes the findings, tested but not yet formally re-verified. The limits sentence describes the window. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (NT-F2) - verification-findings.md: the Formal evidence paragraph still said only the reproducer tests run here. They are regression tests now, beside the new unit, build and sandbox tests; the formal results were not re-run and do not cover v1.1.0. The commit hashes are named as PR #4 commits, which the PR keeps listing even after a squash merge. - api.md: the events and their format version, which stays 1.0.0 because no event shape changed. The read methods (get_pool, preview, get_commitments, executor status and get_jobs) have no deposit check, so a transaction to them keeps a deposit; do not attach one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (gas) The gas table in api.md came from a scratch test outside the repository, so it could not be reproduced here, and the executor at its 512-job cap was not measured. crates/sandbox/tests/res1.rs is that test, adapted to read the build.sh Wasm and write artifacts/res1.json. It takes about eight minutes, so it is #[ignore] and sandbox.sh skips it; run it with --ignored. It now also fills the executor to 512 jobs (operator confirmations of ids the lock has not assigned) and checks that one more fails "full". At 512 jobs: finish needs 44 Tgas (43 at 256), status burns 2.29 of its 10 Tgas and execute 3.64 of its 30. The documented 60 Tgas still holds. Every v1.1 figure measured before was reproduced exactly (dispatch 70, reconcile 46, confirm and finish 43, worst receipt 14.81). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
api.md said one execute "of a higher id" frees the executor's space. The RES-1 run shows an execute of an id below the confirmed ones frees only one job (512 before and after). Only an execute of an id at least as high as the confirmed ones brings it to at most 256 jobs. While the executor is full, a failed execute leaves its record Unknown and confirm_not_executed fails "full". If failures continue until the lock's 256 records are such records or terminal, with none Reserved, no execute can arrive again; only a settle signed with the executor account's key resolves them. api.md now says so. No code change; the synthetic executor keeps the design's rule. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner decisions needed before this leaves draft (details under "Owner decisions to confirm" in the description):
Please merge with a merge commit: v1.1.0 is tested (unit, seeded random, sandbox) but not formally re-verified; the formal results apply to v1.0.0. 🤖 Generated with Claude Code |
…F-3) SECURITY.md still said terminal records are retained for replay protection. Since the window (1f01d43) the pool prunes its oldest terminal record; ids keep counting, and replay protection is the version. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…E (F-3) The handoff's EXEC row said the executor never refuses an id whose record the lock retains. At its 512-job cap it does: confirm_not_executed fails `full`, and with failing executes the lock can stay at `Full` until the executor account signs a settle. The row now states the exception, a nuance bullet explains it, and the CHANGELOG and README name the limit. docs/api.md already described it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…(F-3) The window (F-3) adds first_id and completed_units to the lock's pool and newest to the executor, so v1.0.0 state does not load under v1.1.0 code. The CHANGELOG and the deployment steps in docs/api.md now say so: deploy fresh accounts, no migration is provided. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The findings summary, README and judges' guide said every finding is fixed. For F-4, v1.1.0 rejects only a recipe whose actor is its executor; the owner may still be a recipe's executor (owner question 3 on PR #4). The F-4 Status paragraph already said so; the summary row, the page's Status line, the CHANGELOG and the two overviews now say it too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
api.md said each figure is the least that succeeded plus at least 10 Tgas, rounded up; that rule gives 80 for dispatch, not the 100 in the table. It now gives the margins actually used (dispatch 30, reconcile 14, finish and confirm_not_executed 16, other calls 15 over the largest receipt). The findings page said v1.1 was measured at "the same configuration" as v1.0.0, but the open records differ: all 256 for dispatch and reconcile, 251 to 254 for the executor calls (v1.0.0: 225). Figures from artifacts/res1.json of the ffed738 run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…F-3) Wraps the CHANGELOG record-window bullet and two findings paragraphs that had one over-long line each. The F-3 status now says the executor holds at most 512 jobs and links to api.md for when that blocks confirmations. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One more owner decision, added to the description as question 4:
The commits after |
Summary of ChangesHello @gabehamilton, I'm the pr-review agent. I've reviewed this pull request — here's a summary to help you and other reviewers get up to speed, with the full code review to follow. This PR delivers the v1.1 follow-up to the external verification findings. The core now admits work against a conservative envelope of all open-record outcomes, retains a sliding window of 256 terminal-prunable records, reserves versions so open records can resolve near u32 exhaustion, and tracks completed prerequisites across pruning. The NEAR wrapper and synthetic executor are updated to match that state model, including safer promise-result decoding and bounded executor retention. The implementation is accompanied by focused core regressions, seeded state-machine tests, real-Wasm integration coverage, regenerated scenario traces, build-time Wasm import validation, and documentation that explicitly limits the formal-verification claims to v1.0.0. Highlights
Changelog
Automated review by the pr-review agent (Codex CLI + GPT-5.6 Terra). Reply on any review thread to discuss a finding. |
gabehamilton
left a comment
There was a problem hiding this comment.
Code Review
The PR implements its stated v1.1 safety and liveness fixes coherently across the core state machine, NEAR shell, executor, regression tests, scenario artifacts, and documentation. I traced the changed public paths for record lookup, dispatch/reconciliation callbacks, settlement, pruning, prerequisites, and executor retention; the changed callers consistently use stable ids rather than record-vector positions. I found no concrete correctness, security, concurrency, performance, or test-coverage defect in the changed code that meets the reporting bar. The environment lacks Cargo, so Rust tests could not be executed here; static diff checks and JavaScript syntax checks completed successfully.
No inline findings were raised. Note for reviewers: Validated with git diff --check and node --check for ui/app.js and ui/live.js. Focused cargo tests could not run because the cargo executable is unavailable in the provided environment.
Owner decision Q4 on PR #4. `finish` and `confirm_not_executed` now chain a private callback `on_settled({id})` (10 Tgas) on the lock's `settle` (40 Tgas). When the lock accepted the settle, `on_settled` raises `newest` to `id` and forgets every job 256 or more below it, as `execute` does: the lock accepts a settle only for a record it retains, so every id 256 or more below was already pruned. A refused settle changes nothing and the job stays (no rollback). The call still returns the lock's `settle`, so the transaction outcome (success, or the lock's error) is unchanged. Accepted confirmations now keep the executor at 256 jobs plus those in flight; the 512-job cap needs at least 256 jobs above `newest`, i.e. refused confirmations or callbacks not yet run. - scripts/build.sh: the executor may import promise_then, promise_results_count and promise_result (13 -> 16). - Unit tests: settle + on_settled receipts for both methods; accepted, refused and missing results; the finish retry path; refused jobs kept until 256 past their id; 1,000 accepted confirmations hold 256 jobs; the cap with full and partial windows; callback order. - docs/spec.md: the forgetting rule. Contract Wasm unchanged (e6383aab...); executor Wasm b92f1469... Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s (D-1) On the real host: 300 records whose execute fails (panic mode), each confirmed not executed. After the confirmation of id N the executor holds jobs max(0, N-255)..=N (v1.1.0 before 4d69f19 held 257 at N = 256 and would reach its 512-job cap). The lock ends with first_id 44 and 256 Cancelled records; the executor with jobs 44..=299. Also on the host: the confirmation's receipts (executor call and on_settled, lock settle); a refused confirmation fails with the lock's `NotFound`, its on_settled runs and changes nothing, the job stays; owner -> `Method on_settled is private`, the executor account -> `not a settle callback`; a Reserved record confirmed too early (`InvalidState`) is cancelled at dispatch, then `finish(id, false)` is accepted and its on_settled forgets job 44; the next record runs end to end. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (gas) `finish` and `confirm_not_executed` now create three receipts: the executor's call, the lock's `settle` (40 Tgas) and the executor's `on_settled` (10 Tgas). `Gas::add` takes one budget per receipt, so both callbacks are checked against their static gas. Sections E and F assert the new receipt shape (executor call and on_settled succeed; the lock's settle succeeds, or in F fails NotFound) and that every measured on_settled burns under 6 Tgas. F still reaches 512 jobs through 256 confirmations the lock refuses; the comment says honest use no longer gets there. `finish` at 512 jobs measures the costliest on_settled (accepted, scans 512 jobs). artifacts/res1.json gains the on_settled figures, the margin and the confirm minimum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RES-1 (crates/sandbox/tests/res1.rs) at b954c50, 524 s, pass. The figures apply to these Wasm files (scripts/build.sh at b954c50, clean tree, rustc 1.98.1, --cfg near): pool_contract.wasm e6383aabed62dcf694ac2f97da4520a0 19b18c9db637b1ee2afc7180c697e2ea (unchanged since 34ec9d4) and pool_executor.wasm b92f146919be69f36f517edc10f1e04e6ee96430ba0d745e44221 32615634e83 (new in 4d69f19). A later change to either Wasm voids them. - finish and confirm_not_executed: least 55 Tgas (finish with 512 jobs 56; was 43 and 44). Attach 70 (was 60); margin 14 or more. - on_settled burnt 2.47 of its 10 Tgas, 3.68 with 512 jobs, 3.66 after a refused settle. - dispatch 70, reconcile 46 and the largest receipt (14.81) unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… (D-1, F-3) After 4d69f19 the executor forgets a job once the newest id the lock has vouched for (sent to execute, or accepted a settle for) is 256 or more past it. Job ids are distinct, so at most 256 jobs sit at or below that id, and honest use holds 256 jobs plus confirmations in flight. The 512-job cap needs at least 256 jobs above it (more if fewer sit at or below): refused confirmations (operator error; a far typo keeps its job for good, no method removes it) or callbacks not yet run. - docs/api.md (Executor protocol): on_settled, the forgetting rule, the result is still the lock's settle, what the lock refuses, the Reserved-too-early recovery (finish(id, false)), the cap and the exits from the wedge; 16 executor imports. - docs/verification-handoff.md: EXEC row, record-window and job-cap nuances, on_settled in the boundary checks, 16 imports. - README limits, findings F-3 and NT-F3 status, CHANGELOG executor retention, import count and on-chain results of finish and confirm_not_executed (the lock's settle, not a callback's). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…utor (F-1, F-3, F-4) The repository owner answered PR #4's questions: the record window (F-3, 1f01d43) and the stricter admission (F-1, F-2, 59e404f) are accepted as implemented, and the owner may remain a recipe's executor (F-4; v1.1.0 rejects only actor == executor, no code change). The docs now state these as the owner's decisions, not open questions: findings Status, F-4 row and F-4 Status; README; judges guide; CHANGELOG F-4 entry and "Confirmed by the repository owner" on the admission and window bullets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Owner decisions recorded (PR body and docs updated):
New commits for question 4:
|
…ttle counts (D-1) Doc comments and tests only; the executor Wasm is unchanged (b92f146919be69f36f517edc10f1e04e6ee96430ba0d745e4422132615634e83, rebuilt with scripts/build.sh and compared). The edits above the test module keep their line counts, so no panic location moves. - `newest` and `execute` docs: the newest id is the largest one for which the lock's `execute` created a job, or whose `settle` it accepted. An `execute` of an id that already has a job (a repeat, or a confirmation's) returns the stored status and moves nothing. - `confirm_not_executed` doc: the lock also refuses another executor's recipe (`Unauthorized`). - `on_settled`: a success with a value counts (`Err(TooLong)`). - New test `d1_a_settle_success_with_a_value_counts_as_accepted`; a mutant that advances only on `Ok` fails it. - `d1_finish_moves_newest_too` now checks that the lock's `execute` of a refused confirmation's id answers "cancelled" and moves nothing; a mutant that advances before the stored-job return fails it. - The mock cannot see which promise `notify` returns; a test doc names the sandbox test that checks it. Sandbox comment at the dispatch of 300 says why job 44 stays. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…als (D-1, gas) - api.md, spec.md, handoff (EXEC row, record-window bullet), CHANGELOG, README, findings F-3: the executor's newest id is the largest id for which the lock's `execute` created a job, or whose `settle` the lock accepted; an `execute` of an id that already has a job moves nothing (it was "the largest id the lock has sent to `execute`"). - api.md and the handoff's job-cap bullet: the lock also refuses a confirmation of another executor's recipe (`Unauthorized`). - Gas: the 55 Tgas for `confirm_not_executed` was swept with 254 jobs (`finish` with 256); `finish` with 512 jobs needs 56, and `confirm_not_executed`'s executor receipt at the cap burnt the same 4.39 Tgas, so count on 56 for both there. CHANGELOG: least measured 55; 56 for `finish` with 512 jobs. Attach stays 70. No figure re-measured: the Wasm is unchanged. - README: the forgetting rule is stated with the newest id, not "once the lock has pruned its record". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he record Unknown (D-1) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary of ChangesHello @gabehamilton, I'm the pr-review agent. I've reviewed this pull request (re-review of commits 4be9dab..6fcbd56) — here's a summary to help you and other reviewers get up to speed, with the full code review to follow. This v1.1 PR turns the reported verification findings into concrete core, contract, executor, test, and documentation changes. Its highest-risk new path is the synthetic executor: finish and confirm_not_executed persist evidence, invoke the lock settle call, return that settle promise to preserve caller-visible success/failure, and separately schedule a private callback to advance retention only after a successful settle. Highlights
Changelog
Automated review by the pr-review agent (Codex CLI + GPT-5.6 Terra). Reply on any review thread to discuss a finding. |
gabehamilton
left a comment
There was a problem hiding this comment.
Code Review
The PR’s intent is to make the v1.1 verification fixes operationally safe, especially by ensuring successful executor confirmations cannot fill retention indefinitely while refused settlements do not falsely advance the watermark. The focused executor implementation follows that model: it authenticates the callback, distinguishes failed promise results, preserves the lock settle result, and uses a shared monotonic pruning helper. I found no actionable correctness, security, concurrency, performance, testing, maintainability, or documentation defect in the reviewed changes.
The new executor commits (private on_settled callback chained after settle, settle promise returned, shared advance helper) look correct on review; a manual read of the 4be9dab..6fcbd56 executor and build.sh diff found no defects either. Targeted Rust tests were not run in the review sandbox (no cargo available).
Summary
An outside verification (difflabai/formalver, draft PR #31,
projects/shared-pool/atb9c495b) checked this contract ata4bb5c3. The core, contract and executor there are byte-identical to v1.0.0 (80fb89e), so every finding applies to v1.0.0.This PR documents the findings and fixes them as v1.1.0. Each fix commit rewrites the test that pinned its finding into a regression test of the fixed behaviour. The repository owner has answered the four questions below. Question 4 adds a change to the synthetic executor (
4d69f19tocc0e95c).docs/verification-findings.md(each finding has a Status line with its commit and tests).CHANGELOG.md.Not re-verified. The formal results (TLA+, Lean, Prolog, conformance traces) apply to v1.0.0. v1.1.0 has not been formally re-verified. Its fixes are checked by unit tests, seeded random tests and the sandbox suite in this repository.
Owner decisions
Questions 1 to 3 came from the design's open questions; question 4 came up in review. The repository owner answered all four.
1f01d43: accepted as implemented. v1.0.0 chose "256 lifetime commitments, no pruning, rotate the deployment". v1.1.0 keeps a window of the 256 most recent records and prunes the oldest once it is terminal; older history stays in the event log. The cost stays: while the oldest retained record is open, submit failsFull, even if the other 255 are terminal (see Known limits).59e404f: accepted as implemented. In a disturbed state a reservation can no longer reduce a violated metric; only a completion can. A request that is in bounds only while another open record's reservation stays in place is refused. In theriskfixture, with one credit position open, the largest admitted selloff hedge is 6 units, not 8.dc774f8: the owner may be a recipe's executor. This is the owner's decision, not an open question. v1.1.0 rejects only a recipe whose actor is its executor; there is no code change. The README, the findings page, the judges' guide and the CHANGELOG say so (171a65f).4d69f19(code, unit tests),4e1a4e1(sandbox test),b954c50ande583781(gas), ande0aad49and171a65f(docs); review fixes in765465b(doc comments and unit tests; the Wasm is unchanged) andcc0e95c(docs).finishandconfirm_not_executedstill record the job's outcome first and then call the lock'ssettle. They now chain a new private callback,on_settled, to that call. If the lock accepted,on_settledraises the executor's newest id, asexecutedoes, and the executor forgets every job 256 or more behind it. An accepted settle proves the lock held that record, so it has pruned every id 256 or more below. The transaction's outcome is unchanged: both methods still return the lock'ssettle, so a refusal still reports the lock's error (such asNotFound). A confirmation the lock refuses changes nothing else and keeps its job (see Known limits). The executor gains three imports (promise_result,promise_results_count,promise_then; 16 in all), andfinishandconfirm_not_executednow need 70 Tgas attached.Please merge with a merge commit, not a squash. The findings page cites the commits of this PR by hash.
Findings and fixes
59e404f59e404fexecutethat created a job or an acceptedsettle, is 256 or more past it (question 4).1f01d43,4d69f19newrejects a recipe whose actor is its executor (InvalidConfig). The owner may be an executor (owner's decision).dc774f8VERSION_CAP = u32::MAX - 768; acknowledgment, settlement and cancellation always remain available.da431883eaf1cbbuild.shsets--cfg nearand fails if a Wasm does not importenv.panic_utf8.effd174reconcilerejects a deposit.1d441c5build.shfails on any import outside the reviewed list (18 contract, 16 executor).3598902,2a1506c,4d69f19on_resultreads the raw result; anything but one JSON string of at most 64 bytes becomes Unknown. Tested on the mock runtime and, through a hand-made Wasm executor, in the sandbox.1d441c5,d9f6605InvalidState; the ack no-op is documented.138ef98What changes for callers
get_poolgainsfirst_idandcompleted_units.get_commitments.fromis an id. A pruned id isNotFound, including a repeated executorsettle(v1.0.0 returned Ok).cancelof a Completed record failsInvalidState(wasPending).VERSION_CAP, submit, dispatch,set_pausedandobservefailArithmetic;previewreports it.newrejectsactor == executor. The owner may still be a recipe's executor (question 3).executecreated a job, or whosesettlefrom this executor the lock accepted. Anexecuteof an id that already has a job (a repeat, or a confirmation's) returns the stored status and moves nothing. The new private callbackon_settled({id})records the second kind; only the executor itself can call it.executeof a forgotten id returns"cancelled";confirm_not_executedof one failsstale id;finishfailsunknown job. At most 512 jobs.finishandconfirm_not_executedattach 40 Tgas to the lock'ssettleand 10 toon_settled; attach 70 Tgas to them.dispatch,reconcile,finishandconfirm_not_executedreturn()in Rust; on chain the result is still that of the promise each returns:on_resultfordispatchandreconcile, the lock'ssettleforfinishandconfirm_not_executed.Pool+2 fields, executor +1. A v1.0.0 deployment cannot be upgraded in place; deploy fresh accounts (no migration, nothing is deployed). Event shapes and the event format version (1.0.0) are unchanged.Known limits
Fullfrom the window (question 1, accepted): while the oldest retained record is dispatched and its executor stays silent, submit failsFull.on_settledhas not run. The lock refuses a confirmation of an unassigned or pruned id (NotFound), of a record still Reserved (InvalidState), of one whose other outcome is recorded (InvalidState), or of another executor's recipe (Unauthorized). Such a job is forgotten only once the newest id is 256 or more past its id.u32::MAX) keeps its job for good: no executor method removes a job, so only replacing the executor account's state clears it.finish(id, false)is accepted and moves the newest id (tested in the sandbox).confirm_not_executedfailsfull. If executes then keep failing, the wedge described indocs/api.md(Executor protocol) can still form: their records stay Unknown, and once one of them is the oldest of 256, submit failsFull. The exits are as indocs/api.md: asettlesigned with the executor account's key, or an acceptedfinish(id, false)of a refused job whose record the lock now holds as cancelled or open.on_settledran out of gas, the newest id would not move for that id until the lock accepts or executes a higher one. RES-1 measuredon_settledat 3.68 of its 10 Tgas with 512 jobs.Gas
docs/api.mdnow has a gas table, measured on the v1.1.0 Wasm in near-sandbox 2.13.4 at the largest state (32 metrics, 64 terms, 32 recipes, 256 retained records: all open fordispatchandreconcile, 251 to 254 for the executor calls). Forfinishthe executor held 256 jobs, and then 512, its cap. Each Attach figure is a round number at least 10 Tgas above the least that succeeded. The test iscrates/sandbox/tests/res1.rs. It takes about eight minutes, soscripts/sandbox.shskips it; run it withcargo test -p pool-sandbox --locked --test res1 -- --ignored --nocaptureafterscripts/build.sh.dispatchreconcilefinish,confirm_not_executedconfirm_not_executedwith 254 jobs,finishwith 256);finishwith 512 jobs: 56submit,cancel,settle,observe,set_pausedconfirm_not_executedwas not swept near the cap; its executor receipt from 511 to 512 jobs burnt 4.39 Tgas, the same asfinish's with 512 jobs, so count on 56 for both there. These were first measured with a scratch copy of the test; the in-repo test reproduced every figure and added the 512-job ones. Question 4 changed the executor, so RES-1 was re-run atb954c50:dispatch,reconcileand the largest receipt are unchanged, and the executor calls need 12 Tgas more (they were 43 and 44, under an Attach of 60), because they now attach 10 Tgas toon_settled. The contract Wasm has not changed since34ec9d4(e6383aab...). The executor Wasm isb92f1469...from4d69f19(it was72aea30b...); later commits do not change it.Checks
scripts/check.sh(fmt, tests with and without default features, clippy-D warnings,node --check) passes after every commit. For question 4 it ran at4d69f19,4e1a4e1,b954c50,171a65fand765465b;e583781,e0aad49and the headcc0e95cchange only Markdown.scripts/build.shatb954c50and at the headcc0e95c: 18 contract and 16 executor imports, the same two Wasm hashes (765465bchanges only executor comments and tests, keeping every line above the tests in place, so no panic location moves). The previous allowlist (13 executor imports) fails on the new executor Wasm and names the three new imports.scripts/sandbox.shwith near-sandbox 2.13.4: passes at4e1a4e1(5 tests, 507 s: six fixtures through the real gate; unknown outcomes, stale requests, reconcile and its deposit check; non-string executor results; a window of 300 records through the executor; and the new test that confirmed failed executes keep the executor at 256 jobs, with a refused confirmation, the private callback, and a Reserved record confirmed too early, then recovered withfinish). Later commits change only comments, unit tests, the ignored RES-1 test and docs; both Wasm hashes are unchanged since4d69f19.72aea30b...) it fails at "executor jobs after the confirmation of 256: 257 jobs"; withon_settledchained only forconfirm_not_executed, it fails at "finish moved the newest id". Five unit mutations each fail the unit tests written for them: advance on a refused settle, a no-op callback, advance without forgetting, the callback only for confirmations, and rollback on a refusal. Two more for the review fixes:on_settledadvancing only on an empty success, andexecuteadvancing for an id that already has a job.res1.rs, ignored by default): passes atb954c50(524 s).Next
v1.1.0after merge.🤖 Generated with Claude Code