Skip to content

fix(zk-tls): keep witness pins and prover errors honest - #248

Closed
nicolasLuduena wants to merge 10 commits into
mainfrom
fix/211-zk-tls-cleanup
Closed

nicolasLuduena wants to merge 10 commits into
mainfrom
fix/211-zk-tls-cleanup

Conversation

@nicolasLuduena

@nicolasLuduena nicolasLuduena commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #211: six zk-tls fixes found while reviewing #201, #202 and #209.

Prover errors no longer carry the witness's text

proveReq used to pass a prover's error through unchanged, so text from the witness or the source reached the caller. collect already dropped it. The check now lives in proveWith, which both share:

 proveWith(provers, attestor, request)
-  evidence = parse(await prover.prove(copyRequest(request)))
+  try
+    proved = await prover.prove(copyRequest(request))
+  catch error
+    if error is a ZkFetchProverError with reason transport or no-match
+      throw new ZkFetchProverError(reason)        # no message text, no cause
+    throw Error("zkFetch prover for attestor <id> failed")
+  evidence = parse(proved)

A prover can't edit the client's policy

copyRequest now also copies publicHeaders and each responseMatches and responseRedactions entry. A custom prover that mutated those objects used to change the policy for every later prove. Nested context values are still shared; that is #236.

Empty redactions are refused

zkFetchPolicySchema refuses a redaction with no non-empty regex, jsonPath or xPath. {} and { regex: '' } used to pass the schema, and Reclaim's attestor-core then threw Expected either xPath, jsonPath or regex for redaction on every prove with a 2xx response. I checked that offline against the installed attestor-core 5.1.6.

The witness script reinstalls when the pin moves

 start-witnesses.sh
   check out PINNED_REF (or WITNESS_REF)
-  if node_modules/re2 is missing
+  if node_modules/.thoth-installed-ref != HEAD
     npm install
+    write HEAD to the stamp          # only after the install succeeds

Changing the ref used to start the new source on the old node_modules. Deleting node_modules deletes the stamp, so the next run installs from scratch.

One pinned commit, checked by a test

witness-pin.test.ts gets a VERIFIED_PINS table: attestor-core version → the commit verified with the live check. The test now fails unless the script's PINNED_REF is that commit, no two versions share a commit, and the attestor guide checks the same commit out.

The guide's manual setup used to run git clone --depth 1, which takes whatever upstream's default branch is. It now clones with --filter=blob:none and runs git checkout --detach f451eb3c3038efcf7c11b2497d7540d8f1e95752, the script's pin.

Docs

The dApp guide shows * as the JSON escape for a literal *; it used to show a bare *.

Review findings outside #211 are filed as #231 to #236.

Evidence

New offline tests. live.test.ts stays opt-in.

pipeline.test.ts
  rethrows $thrown from proveReq without the remote text
    (ZkFetchProverError with a remote cause, plain Error, non-Error value, unknown runtime reason)
  keeps the policy's rules and the caller's headers out of a prover's reach
law.test.ts
  refuses a redaction that names no regex, jsonPath or xPath
start-witnesses.test.ts
  reinstalls the dependencies when the pinned commit changes
witness-pin.test.ts
  pins the full commit verified for that version
  checks out the script's commit in the attestor guide's manual setup
  moves the commit with every version
  • Before: the reinstall test, run against main's start-witnesses.sh, fails. The script checks out the new commit, skips the install and starts witnesses without the new commit's dependency.
    After: it passes. The script reinstalls, the dependency is there, and the stamp records the new commit. A failed npm install leaves the stamp alone, so the next run tries again.

  • Before: a Dependabot bump that set PINNED_VERSION but not PINNED_REF passed witness-pin.test.ts.
    After: each kind of pin drift fails:

    Drift Failing test
    PINNED_REF off by one character pins the full commit verified for that version; checks out the script's commit in the guide
    manifest at 5.1.7, script at 5.1.6 pins the witness to the attestor-core version @txpipe/thoth-zk-tls depends on
    guide checks out main checks out the script's commit in the guide
    VERIFIED_PINS lists another commit pins the full commit verified for that version
    5.1.7 everywhere, no verified commit for it pins the full commit verified for that version
    two versions share a commit moves the commit with every version

The guide's clone and checkout, run against upstream:

HEAD is now at f451eb3 [FIX] update TLS lib (#124)
package.json version at the pin: 5.1.4

5.1.4 is expected: upstream never bumped package.json, and this commit is the source of the npm 5.1.6 release, as the script's header says.

No verification skill in this repo.

Merge Danger

Door: two-way

Library code, a dev script and docs. Nothing deployed or stored.

Blast Radius: zk-tls consumers

  • Code that reads the message or cause of a proveReq error now gets only the reason, or the id of the attestor whose prover failed.
  • A policy with an empty redaction now fails when the client starts, where before it failed on every prove.
  • Existing witness clones have no stamp, so the first npm run witnesses after this merges reinstalls once.

@nicolasLuduena nicolasLuduena changed the title fix(zk-tls): harden prover errors, policy isolation and witness pins fix(zk-tls): keep witness pins and prover errors honest Nov 12, 2026
Resolve conflicts with the @txpipe/thoth-* rename and the main-side zk-tls
changes: keep EvidenceTooDeepError in proveWith's @throws, keep both the
empty-redaction and slot-name rules in zkFetchPolicySchema's doc, and use
@txpipe/thoth-zk-tls in the attestor guide and witness-pin test.
@nicolasLuduena

Copy link
Copy Markdown
Member Author

Split into #291, #292, #293 and #294, one fix each. Together they make the same change as this PR.

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.

zk-tls: witness script and docs cleanup found while reviewing #201, #202 and #209

1 participant