Skip to content

fix(contract): keep recorded evidence apart from current metadata - #13

Merged
Canvinus merged 7 commits into
mainfrom
fix/recorded-evidence
Nov 28, 2026
Merged

Canvinus merged 7 commits into
mainfrom
fix/recorded-evidence

Conversation

@Canvinus

@Canvinus Canvinus commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Why

QA of main at c63cdc6 found four problems on the contract page. Each one breaks the AGENTS.md rule that a recorded verification stays distinct from what is deployed now, and that a failed read shows as unknown.

  1. The Evidence tab mixes current metadata into recorded evidence. Root cause: the page took the repository, commit and contract_path from the contract's NEP-330 metadata read at the latest final block. That metadata describes the code deployed now. The registry record (set_contract in verifier-back) stores only cid, code_hash, block_height and lang. None of the 276 live records on either network has a github field, and no record names the crate that was built. So after a redeploy, "How this verdict was reached" named the new commit, and the source tree opened the new build's folder as if it were the verified one. Of the 117 records whose snapshot keeps a git checkout and whose contract still publishes metadata, 22 now name a different commit. For example, intents.near was verified from near/intents@a2dd140, but the Evidence tab showed @16d04f6.
  2. Contract-supplied metadata can blank the page. Root cause: the metadata was cast to a TypeScript type and rendered without checks, and nothing contained render errors. On main, {"version":{},"standards":[null]} produces Next's "Application error" page with TypeError: Cannot read properties of null (reading 'standard').
  3. A failed metadata read becomes a confident wrong message. Root cause: every RPC error except unavailable was mapped to "doesn't expose contract_source_metadata" and cached for 60 s. That includes a panic inside the method. A failed read also fell back to rootPath='/', so the tree could state facts about the wrong folder and ignore a ?file= link.
  4. Tests existed, but nothing ran them. There was no test script and no CI.

Change

Recorded evidence comes only from the record (fixes 1).

  • The Evidence tab's repository and commit come from the record's own github (validated), or else from the git checkout stored in the recorded snapshot. The backend clones and checks out the verified commit before adding the folder to IPFS, so the checkout is part of the content-addressed record, not live data.
  • The checkout is parsed strictly. It must have a detached .git/HEAD (40 lowercase hex) and exactly one [remote "origin"] with exactly one plain url, and that URL must name a GitHub repository (https://github.com/o/r, [email protected]:o/r, ssh://[email protected]/o/r, optional .git). Anything else gives Not recorded, with the reason; nothing is guessed. That includes:
    • a case variant such as Origin, a second origin or a second url;
    • quoting, comments, [url …] rewrites, includes, or the old [remote.origin] syntax;
    • credentials, queries, or a web path such as /o/r/tree/main.
  • Evidence no longer links an "entry file". The registry doesn't record which crate was built, and the same repository and commit don't identify it, because one commit can hold several crates.
  • The current metadata stays on the Build tab, titled "Current build metadata (NEP-330)" and labelled as describing the code deployed now. It says whether its source is the same repository and commit as the verified snapshot, and links its folder on GitHub at its own commit.
  • The source tree opens the folder named in the current metadata always under a label: "Showing contracts/defuse/, the folder named in the contract's current metadata. The verification record doesn't name the crate that was built, so this may not be the verified crate." This applies even when the commit matches. "Show snapshot root" switches to the root, and from there "Open contracts/defuse/" returns.

Records with no github field. That is every current record, so this decides what every page shows:

  • The snapshot has a git checkout (133 of 276 records, the newer ones): the Evidence tab shows that repository and commit, marked "From the git checkout stored in the verified snapshot."
  • The snapshot has no checkout (older snapshots): the Evidence tab says Not recorded and points to the Build tab.

Rejected alternatives:

  • Trusting current metadata when the code hash matches. This doesn't prove anything: NEP-330's own reference implementation stores the metadata in contract state, so it can change without a redeploy.
  • Reading the metadata at the recorded block. Public dRPC isn't archival and returns UNKNOWN_BLOCK, and the provider is out of scope.
  • Always opening the snapshot root. That would hide the source for the 181 of 255 contracts with metadata that build from a sub-folder.

Typed NEP-330 metadata and an error boundary (fixes 2).

  • utils/contractMetadata.ts parses the metadata once. Fields with the wrong type are dropped and flagged ("Published with the wrong type; not shown"), standards are de-duplicated so React keys stay unique, build_command must be all strings, and contract_path must be a plain relative path.
  • PaneBoundary wraps each workspace pane, so a render error shows "Couldn't display …" with a retry while the verdict, header and tabs stay.

Unknown reads stay unknown (fixes 3).

  • utils/near/view.ts classifies a structured error by its cause name. A contract execution error is classified by the top-level FunctionCallError variant in vm_error (or after the legacy message prefix), matched whole: MethodResolveError(MethodNotFound) means method_not_found, CompilationError(CodeDoesNotExist { … }) means no code. Legacy messages are matched whole, never as fragments, so a GuestPanic whose message mentions MethodNotFound is a failed call.
  • Only a missing method, missing code or a missing account means "no metadata". A panic, an RPC failure or a malformed response is unknown: it gets "Try again" and is never cached.
  • The tree's folder choice depends only on the current metadata, the ?file= link the workspace was opened with, and the reader's choice.
    • Picking a file in the tree updates ?file= but never moves the tree.
    • The opened-with link and the folder choice belong to one record view (network + account). A network switch for the same account ("Check Testnet", Back/Forward) starts fresh from the address it lands on.
    • A link moves the tree only when the default folder wouldn't list it, so a pick reloaded later doesn't move it either.
    • Such a link opens its own folder at once, without waiting for or needing the metadata, and "Show snapshot root" is always offered from there.
    • A linked file the listing doesn't show (deeper than one folder) is opened directly. If that fails, the tree says it "couldn't open" the file, with a retry, rather than that the file is absent.
  • With the metadata read failed and nothing listable at the snapshot root, the tree says the source folder is unknown until the metadata can be read, with a retry. It never says "No .rs or .toml files".
  • A folder listing reply is unreadable unless it is { structure: [...] } (or a bare array) whose every entry is a complete link: a string name and an integer UnixFS type 0–5, or the older name/type/path shape, with no lone surrogates. An unreadable reply means unknown with a retry, never an empty folder, so a malformed .git entry can't become "no git checkout". Failed and partial listings (a sub-folder couldn't be read) are never cached; a partial listing says so, with a retry.
  • A contract_path that isn't text (a lone surrogate) is flagged and not used, and the Build tab's GitHub folder link returns no link rather than throwing.

Fewer requests; nothing waits on the checkout read.

  • The checkout is read only when the Evidence or Build tab is open, with a 10 s client-side timeout (then unknown, with a retry). The Source tab never reads it.
  • A root listing that hasn't answered when the read times out is dropped, so Try again sends a new request.
  • Each folder listing is one shared request per snapshot and folder, kept once read, and .git is never listed. A failed request removes only its own cache entry.
  • See Validation for the request counts.

Tests and CI (fixes 4).

  • Adds npm test.
  • Adds .github/workflows/ci.yml: pull requests and pushes to main, Node 24.x, actions/checkout@v4 and actions/setup-node@v4 in the verifier-back style, running npm ci, lint, build and test with contents: read.
  • AGENTS.md now lists npm test.
  • Deviation from the brief: the script is node --test "tests/**/*.test.cjs". node --test tests/ fails on Node 24.22.3 (Cannot find module …/tests) because Node loads the directory as a module.
  • New tests:
    • tests/metadata.test.cjs: parsing (including lone-surrogate paths), load states, error classification including panics that mention MethodNotFound, caching.
    • tests/evidence.test.cjs: snapshot and checkout parsing including the ambiguous cases, the same-source rule, folder choice, links and in-tree picks, the unknown-folder state.
    • tests/sourceFiles.test.cjs: malformed vs empty listings and malformed entries, no caching of failures, the timeout and an expired stalled root listing, the shared root listing, never listing .git, partial listings.
  • The modules the tests load use only type-only @/ imports.

Production notes.

  • No dependency, engines or env changes.
  • The home page's first-load JS is 215 kB, up from 214 kB.

Review fixes

Round 1 (review of 1a29685):

  1. Same owner/repo/sha doesn't prove the crate. The metadata folder is never "verified": it is always labelled, and the Evidence entry-file link is gone.
  2. Substring classification. Errors are now classified by type and whole message, as above.
  3. A legacy ?file= link with metadata unavailable. The link opens its own folder and its file; there is no empty-state claim.
  4. Lenient checkout parsing. Origin, URL and HEAD are parsed strictly, as above.
  5. A malformed structure reply was treated as empty and cached. It is now unknown with a retry, and never cached.
  6. The checkout read blocked browsing and had no timeout; the request count was too high. The Source tab doesn't read the checkout, the read has a 10 s timeout, listings are shared, and .git is never listed.

Round 2 (re-check of 5c66f38):

  1. A timed-out root listing stayed cached, so Try again waited on the same request. It is now dropped when the read times out.
  2. Picking a file in the tree re-rooted it. Only the link the workspace was opened with can move it, and only when the default folder wouldn't list the file.
  3. A malformed entry became a cached absence. It now makes the listing unknown with a retry.
  4. A plain URL with metadata failing showed the empty state. It now shows an unknown-folder state with a retry.
  5. A lone-surrogate contract_path broke the Build pane. The path is rejected, and the link builder is guarded.
  6. githubEntryPath was unused. It is removed.

Before pushing round 2, I checked my diff against main for other navigation and caching regressions. That found one more: a link's own folder had no way back to the snapshot root, while main always showed the root there. Fixed: "Show snapshot root" is offered there. I missed one: the opened-with link survived a network switch for the same account (round 3).

Round 3 (final re-check of 54b701f):

  1. The opened-with link survived a network switch. The workspace is keyed by account only, so a Mainnet ?file=contracts/ft/src/lib.rs link followed by "Check Testnet" still rooted the Testnet tree at contracts/ft/, showing an empty state. The opened-with link and the folder choice are now keyed by network + account, so a switch starts fresh, as at 5c66f38. The other record state was already keyed by network: the record, metadata and code-check hooks by network + account, the panes by network:cid:tab, and the recorded-source read by network:cid.

Validation

All in the OrbStack VM ss-front-evidence-1128 (Ubuntu 24.04, Node 24.22.3, npm 11.19.1; disk 73 GB free, host load about 3–4), on a fresh tree from git archive of the pushed HEAD c55dd7a:

  • npm ci, npm run lint (no warnings), npm run build and npm test all pass: 44 tests, the 13 existing plus 31 new.
  • Baseline on main: lint, build and the 13 tests pass with an explicit glob; node --test tests/ fails.

Browser checks: next start with NEXT_PUBLIC_API_HOST=https://api.sourcescan.dev, headless Chromium (Playwright 1.65.1, VM only), live public dRPC and IPFS reads. 142/142 checks pass at c55dd7a, in one full run. In round 2 one check had failed: a test artifact where the script clicked the file that was already open, which is a no-op by design. The script now picks another file. On each network, Mainnet and Testnet:

  • Current metadata names the recorded commit (client-eth2.bridge.near, omnidep.testnet):
    • the tree opens the metadata folder under the current-metadata label ("may not be the verified crate"), and the Source tab makes no checkout request;
    • Evidence shows the repository from the snapshot checkout and has no entry-file link;
    • Build says "Same repository and commit" and links the current folder at its commit.
  • Same commit, another crate (fixture: current metadata switched to contracts/near/eth-prover / near/omni-bridge): the Evidence repository is unchanged with no entry-file link, Build says same commit, and the tree folder is labelled as current metadata.
  • Redeployed contract (intents.near, client-eth2.sepolia.testnet):
    • the verdict is a mismatch, and the tree opens the metadata folder under its label;
    • "Show snapshot root" lists the root without listing .git, and "Open …/" returns;
    • Evidence shows the recorded commit (a2dd140892b6, 9783ca494c2c), not the live one, and Build says it differs;
    • no IPFS request is made twice in the whole visit.
  • Snapshot without .git (pyth-oracle.near, repro-fct-67.testnet): Evidence says "Not recorded … the snapshot has no git checkout", and the tree folder is labelled.
  • Legacy /code/<account>: the workspace renders and stays on /code/.
  • Legacy /code/<account>?file=<crate>/src/lib.rs with contract_source_metadata blocked: the file opens; there is no "No .rs or .toml files" claim, and the folder-unknown notice shows.
  • dRPC host blocked: "Couldn't load the verification record"; no match or mismatch text.
  • view_code and contract_source_metadata blocked: the verdict is "Deployed code status unknown", the folder is unknown with a retry, Build is unknown with "Try again", and the retry loads the metadata.
  • .git/HEAD held unanswered: source browsing (with a ?file= link) isn't blocked; Evidence shows "Reading the snapshot…", then after the timeout "Unknown: the snapshot couldn't be read" with "Try again", and the retry reads it.
  • Root structure replied with HTTP 200 {"status":"temporarily unavailable"}: Evidence shows unknown with "Try again", not "Not recorded"; it isn't cached, and the retry reads it.
  • Round 2:
    • Root listing held unanswered: Evidence goes unknown after the timeout, and Try again sends a second root request and reads the checkout.
    • A tree pick with no metadata method: picking a file one folder down opens it and keeps the root listing, and a reload with that ?file= keeps it too.
    • A root listing with {"Name":".git","Hash":"unused"}: unknown with retry, not "no git checkout"; the retry reads it.
    • A plain URL with metadata blocked and nothing listable at the root: "The contract's source folder is unknown…", with no "No .rs or .toml files"; Try again opens the metadata folder.
    • contract_path of "contracts/\ud800": Build renders with the path flagged, and no pane error.
    • A deep link with no metadata method: labelled as the linked file's folder, and "Show snapshot root" lists the root.
  • Round 3, network switch for the same account, both directions:
    • Mainnet link, then Check Testnet (0us40y…, Testnet record only): ?network=mainnet&file=contracts/ft/src/lib.rs shows no Mainnet record. "Check Testnet" opens the Testnet record with the file link dropped, and the tree starts fresh at the metadata folder (contract/, 3 files) instead of contracts/ft/.
    • Testnet link, then Check Mainnet (9873182a…, Mainnet record only): the same flow; the tree starts at the snapshot root (7 files).
    • Against a build of 54b701f, the same two cases fail (the tree is rooted at contracts/ft/ with 0 files), so the check catches the regression.
    • Registry network switch Testnet → Mainnet → Testnet from the navbar: each list shows that network's accounts.

Once, on Mainnet:

  • Panics in contract_source_metadata all show as unknown with a working retry, not "doesn't expose". Cases: a generic panic, a legacy GuestPanic whose message says "Unexpected MethodNotFound from lookup", and the same panic as a structured CONTRACT_EXECUTION_ERROR.
  • A real MethodResolveError(MethodNotFound) shows as "doesn't expose".
  • Malformed metadata renders with flags and a single badge.
  • A forced render error in the Build pane stays inside the pane.

IPFS proxy requests per visit, counted in the browser at c55dd7a (origin/main measured the same way in the same VM):

Visit main this PR
client-eth2.bridge.near, Source tab 3 3
omnidep.testnet, Source tab 3 3
intents.near (redeployed), Source tab 4 4
client-eth2.sepolia.testnet (redeployed), Source tab 3 3
then opening Evidence 0 +3 (root listing, .git/HEAD, .git/config; once per snapshot)

main makes no Evidence requests because it shows the live metadata's repository there. At 1a29685 the review measured 6 and 16 for the same Source visits.

Against origin/main, the same script reproduces the review's link and panic cases. The ?file= link with metadata unavailable doesn't open, and the "no .rs or .toml files" claim appears. A generic panic shows "doesn't expose".

The new CI workflow passed on this PR at 1a29685 (run 46156984291), at 5c66f38 (run 46160699103) at 54b701f (run 46162181525) and at c55dd7a (run 46162975573): install, lint, build, test. GitHub annotates actions/checkout@v4 and actions/setup-node@v4 as targeting the deprecated Node 20 runtime. They are kept at @v4 to match verifier-back; moving both repos to newer majors is a separate change.

Follow-ups, not in this PR:

  • Have the registry record the source snapshot and contract path, or keep .git in snapshots on purpose, so older records can name their repository and the crate can be shown as verified.
  • /api/proxy-ipfs turns upstream 404s into 500s.

🤖 Generated with Claude Code

Canvinus and others added 2 commits November 28, 2026 15:51
tests/registry.test.cjs had no script and nothing ran it. Add `npm test`
(the Node test runner over tests/**/*.test.cjs) and a GitHub Actions
workflow that runs npm ci, lint, build and test on Node 24 for pull
requests and pushes to main. AGENTS.md lists `npm test` with the other
checks.

`node --test tests/` fails on Node 24 (the directory is loaded as a
module), so the script passes an explicit glob.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The Evidence tab and the source tree took the repository, commit and
contract path from the contract's current NEP-330 metadata, so after a
redeploy they showed the new build next to the old verification. The
registry records only the snapshot (cid), code hash and block, so the
recorded repository now comes from the record's github field or from the
git checkout stored in the recorded snapshot. The current metadata stays
on the Build tab, labelled as current, and picks the tree folder only
when it names the same repository and commit; otherwise the folder is
offered as a labelled choice.

NEP-330 metadata is parsed once into a typed shape. Fields with the
wrong type are flagged instead of rendered, duplicate standards are
collapsed, and each workspace pane has an error boundary.

A metadata read that fails (RPC failure or a panic in the method) is
unknown with a retry and is never cached. Only MethodNotFound, missing
code or a missing account count as "no metadata".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vercel

vercel Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
verifier-front Ready Ready Preview Nov 28, 2026 4:02pm UTC

Request Review

Canvinus and others added 2 commits November 28, 2026 16:26
The classifier searched the whole error text for MethodNotFound and
CodeDoesNotExist, so a panic whose message mentioned either became a
cacheable "doesn't expose contract_source_metadata". Structured errors
are now classified by their cause name, and a contract execution error
by the top-level FunctionCallError variant in vm_error (or after the
legacy message prefix), matched as a whole. Legacy messages are matched
whole, never as fragments. Anything else is a failed call: unknown, with
a retry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d crate

Review of #13 found that the same repository and commit don't identify
the crate: one commit can hold several, and the registry records none.
The source tree now opens the folder from the contract's current
metadata only under a "current metadata" label, even when the commit
matches, and Evidence no longer links an entry file.

- The folder choice depends only on the current metadata, the ?file=
  link and the reader's choice. A link opens its own folder without
  waiting for the metadata, and a linked file that the listing doesn't
  show is opened directly; failing that, the tree says it couldn't open
  it rather than that it is absent.
- The snapshot's git checkout is read only for the Evidence and Build
  tabs, with a 10 s timeout, and parsed strictly: one exact
  [remote "origin"] with one plain GitHub repository URL and a detached
  HEAD, else "Not recorded" with the reason.
- A folder listing that isn't a listing is unreadable (unknown, retried),
  not an empty folder; failed and partial listings are never cached.
  Each folder is listed once and shared, and .git is never listed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Canvinus and others added 2 commits November 28, 2026 16:49
Re-check of #13 at 5c66f38:
- A checkout read that timed out left its unanswered root listing in the
  shared cache, so Try again waited on the same request. A listing that
  hasn't answered when the read times out is now dropped, and a failed
  request only removes its own cache entry.
- A listing entry with a name but no valid UnixFS type (for example
  {"Name":".git","Hash":"unused"}) was skipped, so the folder looked like
  it had no git checkout and that absence was cached. Every entry must
  now be a complete link (string name, integer type 0-5, or the older
  name/type/path shape, with no lone surrogates); otherwise the reply is
  unreadable: unknown, with a retry.
- Remove githubEntryPath, unused since the Evidence entry-file link went.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hen unknown

Re-check of #13 at 5c66f38:
- Picking a file in the tree updates ?file=, which was then read as a
  deep link and moved the tree into that file's folder. Only the ?file=
  the workspace was opened with may choose the folder now, and only when
  the default folder wouldn't list it, so a pick (or a reload with it)
  never moves the tree. From a linked file's folder, "Show snapshot root"
  is always offered.
- With the metadata read failed and nothing listable at the root, the
  tree said "No .rs or .toml files at the snapshot root". It now says the
  source folder is unknown until the metadata can be read, with a retry.
- A contract_path with a lone surrogate passed validation and made the
  GitHub folder link throw, replacing the Build pane with its error. Such
  a path is now not a folder (flagged and unused), and the link builder
  returns no link rather than throw.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Final re-check of #13 at 54b701f: the workspace is keyed by account, so
the ?file= link it was opened with survived a network switch for the
same account. A Mainnet link with ?file=contracts/ft/src/lib.rs, then
Check Testnet, still rooted the Testnet tree at contracts/ft/. The
opened-with link and the folder choice now belong to one record view
(network + account): the same view keeps them while the reader picks
files, and a switch starts fresh from the address it lands on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Canvinus
Canvinus merged commit 6e4d37d into main Nov 28, 2026
3 checks passed

This branch was successfully deployed

1 active deployment
Preview — c55dd7a7 Deployed Nov 28, 2026 by vercel[bot]
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