跳到正文
DEV Community· Savana·· 1 小時前AI 評分49

我打造了一個不會自欺的 Proof Gatekeeper,並發現它看不見的陷阱

I Built a Proof Gatekeeper That Can't Lie to Itself — and Found the One Trap It Can't See

AI 導讀

作者為 zkVerify Agent Games Season 01 Creator Track 建立 Proof Gatekeeper,使用官方電路為每項決策生成 Groth16 零知識證明,並在本機完成驗證。11/11 個測試案例通過,證明生成耗時 247–1,415 ms。PROOF_REUSED 無法由電路判定,須由平台透過 seen-set 在鏈下處理;整個測試未涉及主網或實際比賽回合。

正文

zkVerify Agent Games Season 01 — Creator Track entry (#AgentGames)

Everything below ran locally, on my own machine, against the tournament's official circuits. No mainnet transaction, no VFY spent, no live endpoint, no scored rounds played. I will say plainly where the local build ends and the real tournament begins — because that boundary is the most interesting thing I found.


TL;DR

I built the loop the Proof Gatekeeper track asks for: a decision engine that judges proof-backed payment requests, plus a real Groth16 prover that writes a zero-knowledge proof of every decision using zkVerify's official gatekeeper circuit. Then I verified each proof locally against the verification key exported from the official proving key.

  • 11/11 harness cases pass — 1 valid request, 6 traps, 3 boundary cases, 1 distinct valid task. Every decision correct, every provable proof verifies.
  • Prove time 247–1,415 ms, verify time 21–194 ms per case across two full runs — two orders of magnitude inside the arena's 60-second deadline.
  • The circuit refuses to lie. I tried to prove an APPROVE for a threshold trap and a REJECT for a valid task. Both times witness generation failed with an assertion error. No proof was produced at all.
  • One honest failure: the PROOF_REUSED trap cannot be proven by this circuit at all — the proof reference is not a circuit input, so a REJECT for an otherwise-valid task is unprovable. Reuse has to be enforced off-circuit, by the platform's seen-set. That is a real design boundary, and it matters.

If you only take one idea from this article, take this: a zero-knowledge proof does not make an agent honest. It makes a specific claim checkable. The interesting engineering is deciding exactly which claim the proof covers — and admitting what it does not.


1. Why agents need to be verifiable

An AI agent is software that makes decisions and takes actions on its own. That is the whole pitch — and the whole problem. When an agent tells you it approved a payment because the balance was sufficient, the recipient matched, and the proof was genuine, how do you actually know?

Today the answer is usually: you don't. You trust the agent, its operator, or its logs. Logs can be edited. An agent can be confident and wrong. A model can be prompted, confused, or compromised into approving something it should have rejected — and then produce a perfectly fluent explanation of why it did the right thing.

The Proof Gatekeeper track in zkVerify's Agent Games is built around a harder question: can an agent prove its answer was honest? Not explain it. Prove it — in the cryptographic sense, where "prove" means a third party can check the claim mechanically, without trusting the prover.

That is what zero-knowledge proofs are for. A ZK proof lets a prover convince a verifier that a statement is true without revealing the private inputs behind it. In the gatekeeper's case the private input is almost nothing — a random salt — and the point is not secrecy. The point is binding: the proof ties one decision to one task and one set of public inputs, and anyone holding the verification key can check that the decision follows from those inputs. If the decision doesn't follow, no valid proof exists. The circuit is the referee.

2. What zkVerify is

zkVerify is a Layer 1 blockchain built specifically to verify zero-knowledge proofs — a universal proof-verification layer. The idea is to separate heavy ZK verification from general-purpose chains, so verification is fast (the project claims under a second) and cheap across ecosystems and proving schemes. It was developed by Horizen Labs and incubated by YZi Labs (formerly Binance Labs).

  • Mainnet live since 30 September 2025, with the $VFY token live the same day (listed on Binance Alpha, Gate.io, KuCoin, MEXC, Bitget, BitMart). Total supply 1,000,000,000 VFY; ~306M circulating at the time of writing.
  • Agent Games Season 01 ran 21 October – 21 November 2026: four tracks (Proof Gatekeeper, Steal the VFY, Creator Track, Wildcard), 400,000 VFY in total prizes — 100,000 VFY per track, split 50,000 / 30,000 / 20,000 VFY across the top three in each track. Judging for the Creator Track is manual: technical substance, clarity, zkVerify relevance, and originality.
  • Verification itself goes through Kurier (a REST workflow: register the verification key once, submit the proof, poll until Finalized) or zkVerifyJS (direct chain interaction). My build stops one step short of that: I generate and verify proofs locally with snarkjs, which is exactly what an agent does before submitting — the submission step needs an API key and a funded path I did not use, and I won't pretend otherwise.

The tournament's premise is the article's premise: agents compete, proofs decide, and every confirmed result leaves a public record.

3. What the Proof Gatekeeper track asks for

An agent registers a public HTTPS endpoint. During scored rounds the platform POSTs signed JSON task envelopes to that endpoint. Each task is a payment-guard decision: a proof, a verification key, a balance threshold, an expiry block, a recipient, an amount cap — and the agent has 60 seconds to answer APPROVE or REJECT, with a reason code, and a Groth16 proof that its decision is correct.

A task envelope looks like this (from the official build guide):

{
  "type": "agent-games.proof-gatekeeper.v1",
  "task_id": "gk_8d31_...",
  "mode": "competition",
  "issued_at": "<issued-at>",
  "deadline_at": "<deadline-at>",
  "input": {
    "registered_vk": "0x7d...91",
    "proof_vk": "0x13...aa",
    "minimum": "1000",
    "public_balance": "1460",
    "expiry_block": 8430000,
    "current_block": 8420000,
    "recipient": "0xDe42...9f01",
    "condition_recipient": "0xDe42...9f01",
    "amount": "500",
    "max_transfer": "1000",
    "proof_tx": "0xa8...2c"
  }
}

Scoring is unforgiving in exactly the right direction: +12 for a correct decision, −6 for approving a trap, −3 for rejecting a valid request, −2 for a timeout/offline response, −2 if the proof fails to verify, plus a reliability bonus. Approving a trap costs twice as much as wrongly rejecting a valid request — the scoring wants you to fail closed. My decision engine does.

Every task is either a valid condition or one of six traps. Roughly half the tasks are valid; the rest test whether your agent actually checks every field instead of guessing:

# Case Expected
1 Valid condition — everything matches APPROVE
2 VK_SUBSTITUTION — proof's verification key ≠ registered key REJECT
3 PROOF_REUSED — same proof reference seen before REJECT
4 THRESHOLD_MISMATCH — public balance below the minimum REJECT
5 EXPIRED_CONDITION — current block at/past expiry REJECT
6 WRONG_RECIPIENT — recipient ≠ condition recipient REJECT
7 AMOUNT_OVERFLOW — amount above the max transfer REJECT

The official guide also demands the unglamorous parts that decide whether an agent survives a real round: verify the HMAC signature on the raw request body before parsing JSON, sign every response, rotate the platform-issued secret, run the preflight handshake, and fail closed on any timeout or uncertainty. I implemented the decision + proof loop locally; the HTTP endpoint and HMAC plumbing are specified by the guide and I did not deploy them — this machine has no public HTTPS endpoint, and the scored rounds (13–20 November, plus a compensatory round on 21 November) are over. That is a limitation, stated up front, not hidden in a footnote.

4. The circuit nobody documented — and how I verified it

The official guide points you at the circuit files, but the official pages never publish the circuit's input names. You cannot build a proof without knowing what the circuit expects.

So I started from the one source the platform itself serves: https://agentgames.zkverify.io/api/circuit-info. It was live when I checked, and it returns both circuits, their download URLs, and their registered verification-key hashes:

{
  "network": "mainnet",
  "circuits": {
    "gatekeeper": {
      "vkHash": "0x6b79c6012a6d8651f3e13bc4d2a20370280ab49700c90c5316d4168bfbad77b0",
      "artifacts": {
        "wasm": "https://agentgames.zkverify.io/circuits/gatekeeper.wasm",
        "zkey": "https://agentgames.zkverify.io/circuits/gatekeeper_final.zkey"
      }
    },
    "vfyPolicy": {
      "vkHash": "0x6c56509f1c56fd1fd4e9737f906d2220f4b95f1d507f1adf6899085bd74be047",
      "artifacts": {
        "wasm": "https://agentgames.zkverify.io/circuits/vfy-policy.wasm",
        "zkey": "https://agentgames.zkverify.io/circuits/vfy-policy_final.zkey"
      }
    }
  }
}

I downloaded all four artifacts and hashed them before running anything:

File Size (bytes) SHA-256
gatekeeper.wasm 1,755,820 be00aefe3c8ba910951a242f50e55937bf82a0375ad4b69c2ef10629ab92764f
gatekeeper_final.zkey 309,750 adfe95a439a7063a82a4967ef026d2dd6857a4d02c63b3caf63dac02e01af80d
vfy-policy.wasm 2,991,212 bc0998250d2baf75b89deef5306867ffa7085a08d4f7d2caf0dd63a060b134d2
vfy-policy_final.zkey 810,586 f9666a1655279ef27f7fee6d535ac8aa9e39286ac40ff6279fea87c21ab6ce41

The two vfy-policy hashes match, character for character, the hashes published by another participant on 17 November 2026; the gatekeeper hashes match the values published by participants on 15 November. I re-verified the hashes after the build as well — same values. These are the official artifacts, not something I recompiled or modified.

Exporting the verification key from the official zkey with snarkjs 0.7.5 tells me the shape of the thing: Groth16 over BN128, 13 public inputs for gatekeeper (and 9 for vfy-policy, which I verified by hash and key export but did not build against — the Steal the VFY tournament it belongs to is closed). The input signal names are the camelCase versions of the envelope's snake_case fields, plus taskId, salt, and decision — thirteen in total:

registeredVkHash, proofVkHash, minimum, publicBalance, expiryBlock,
currentBlock, recipient, conditionRecipient, amount, maxTransfer,
decision, taskId, salt

I did not take those names on trust: I fed them to snarkjs.groth16.fullProve against the official wasm/zkey, and the proof that came out verifies against the verification key exported from the official zkey. A wrong signal name fails witness generation; a right one produces a proof that verifies. The 11/11 run below is the verification of the interface.

Two encoding details matter, and both are the kind of thing that silently breaks a build:

  1. The vkHash is bigger than the field. A 32-byte hash can exceed the BN128 field prime (21888242871839275222246405745257275088548364400416034343698204186575808495617), so snarkjs rejects it unless it is reduced mod p first. Both VK hashes go through mod p before proving.
  2. Only salt is private. Everything else is a public signal — the proof hides nothing about the task, only the nonce. salt is a fresh random 128-bit value per proof, so two proofs of the same task differ. taskId is sha256(task_id) mod p, which binds the proof to one task. decision is 1 for APPROVE, 0 for REJECT.

5. The decision engine: deterministic, fail-closed

The model may recommend an action; deterministic code enforces the final safety rules. That is the guide's rule, and it is the right one: a language model should never make the final call on moving money.

My decide() runs seven checks in trap-priority order. The first failing check sets the reason code and the answer is REJECT:

function decide(task, seenProofs = new Set()) {
  if (task.proof_vk.toLowerCase() !== task.registered_vk.toLowerCase())
    return { decision: 'REJECT', reason_code: 'VK_SUBSTITUTION' };
  if (seenProofs.has(task.proof_tx.toLowerCase()))
    return { decision: 'REJECT', reason_code: 'PROOF_REUSED' };
  if (BigInt(task.public_balance) < BigInt(task.minimum))
    return { decision: 'REJECT', reason_code: 'THRESHOLD_MISMATCH' };
  if (BigInt(task.current_block) >= BigInt(task.expiry_block))
    return { decision: 'REJECT', reason_code: 'EXPIRED_CONDITION' };
  if (task.recipient.toLowerCase() !== task.condition_recipient.toLowerCase())
    return { decision: 'REJECT', reason_code: 'WRONG_RECIPIENT' };
  if (BigInt(task.amount) > BigInt(task.max_transfer))
    return { decision: 'REJECT', reason_code: 'AMOUNT_OVERFLOW' };
  return { decision: 'APPROVE', reason_code: 'VALID' };
}

The order is deliberate. VK substitution first: if the proof isn't even anchored to the registered key, nothing else in the envelope deserves trust. Reuse second: a replayed proof is an attack even if every field looks clean. Then the arithmetic checks — threshold, expiry, recipient, amount — each a single comparison, each fail-closed. Anything uncertain, anything timed out, anything unparseable: REJECT. Approving a trap costs −6; a wrong REJECT costs −3; the engine is built to prefer the cheaper mistake.

6. The prover: one function, real proofs

const { proof, publicSignals } =
  await snarkjs.groth16.fullProve(input, WASM, ZKEY);
const valid = await snarkjs.groth16.verify(vk, publicSignals, proof);

That is the whole prover. fullProve computes the witness from the 13 inputs, then generates the Groth16 proof (pi_a, pi_b, pi_c, protocol groth16, curve bn128). verify checks it against the verification key exported from the official zkey — the same key the platform registers on mainnet (vkHash 0x6b79…d77b0). The response an agent would send is { decision, reason_code, proof, public_signals }, signed with the platform HMAC secret over the raw body.

A sample of what comes back, for the valid case (truncated — the full values are field elements, 77 digits each):

publicSignals[0..2]: 11949528604187885769859377457520029076479896674594353406002466931425193922732,
                     4836144126773920907502496244340012141761656471453348073975163706578152814510,
                     4836144126773920907502496244340012141761656471453348073975163706578152814510
proof.pi_a[0]:       131628660581546921123933…

Note signals 1 and 2 are identical: registered and proof VK hashes are the same value in the valid case, reduced mod p. That is a small, checkable fingerprint that the encoding is doing what I claim.

7. Results: 11/11, and the one case that broke the pattern

The harness runs 11 cases: the valid request, all six traps, three boundary cases (balance exactly equal to the minimum, amount exactly equal to the cap, current block exactly one before expiry — all must APPROVE), and a second distinct valid task. Each case generates a fresh proof with a fresh salt and verifies it locally. Run on 21 November 2026, Node.js v24, snarkjs 0.7.5, on an ordinary VM:

Case Decision Proof Prove Verify
valid APPROVE / VALID verifies (13 signals) 1,415 ms* 194 ms
trap VK_SUBSTITUTION REJECT verifies 485 ms 25 ms
trap PROOF_REUSED REJECT refused — see below 92 ms to refusal —
trap THRESHOLD_MISMATCH REJECT verifies 478 ms 92 ms
trap EXPIRED_CONDITION REJECT verifies 429 ms 79 ms
trap WRONG_RECIPIENT REJECT verifies 407 ms 82 ms
trap AMOUNT_OVERFLOW REJECT verifies 334 ms 64 ms
edge balance == minimum APPROVE / VALID verifies 406 ms 30 ms
edge amount == maxTransfer APPROVE / VALID verifies 474 ms 92 ms
edge current == expiry − 1 APPROVE / VALID verifies 419 ms 30 ms
valid distinct task APPROVE / VALID verifies 395 ms 169 ms

*First proof of the run includes warm-up; across two full runs prove times ranged 247–1,415 ms (mean ≈ 485 ms in the second run) and verify times 21–194 ms. Either way: roughly 0.3–1.5 seconds per decision, against a 60-second arena budget. Proving is not the bottleneck. The network, the HMAC handshake, and the decision logic are where a real agent wins or loses time.

11/11 harness cases pass — decision correct in every case, and every proof the circuit can produce verifies.

The negative tests: trying to make the circuit lie

I then tried to cheat my own build, twice:

  • (a) APPROVE a threshold trap (balance 999 < minimum 1000) → witness generation failed: Error: Assert Failed. Error in template GatekeeperEvaluation_79 line: 102. No proof produced.
  • (b) REJECT a fully valid task → same assertion failure, same line. No proof produced.

The circuit computes the decision from the inputs and constrains the claimed decision to match. A mismatched decision is not a bad proof — it is no proof. That is the property the whole tournament rests on, and it held on the first try, in about 100 ms per attempt.

The honest failure: PROOF_REUSED

Case 3 is the exception that taught me the most. The decision engine correctly returns REJECT / PROOF_REUSED — the proof reference was already seen. But when the prover tries to prove that REJECT, witness generation fails with the same assertion error as the cheating attempts.

Why? Look at the 13 inputs again: proof_tx is not one of them. The circuit receives the task's fields, the decision bit, a task ID, and a salt — but nothing that says "this proof was already used." From the circuit's point of view, the task is perfectly valid, so the only decision it will attest is APPROVE. A REJECT for an otherwise-valid task is, to the circuit, indistinguishable from a lie.

So reuse cannot be proven by this circuit. It has to be enforced off-circuit — by the platform remembering every proof_tx it has seen, and by the agent keeping its own seen-set (which mine does). The proof guarantees the decision follows from the task's fields; it says nothing about history. That is not a bug in my build. It is a boundary in the design, and any gatekeeper that claims its proofs cover replay protection without an off-circuit seen-set is overclaiming.

The same honesty applies in the other direction: a proof verifies that the decision follows from the inputs as given. It does not prove the inputs themselves are true — a platform that feeds a gatekeeper a false balance gets a correctly-proven wrong answer. Verification is necessary, not sufficient. The guide says this explicitly in its Security section, and my build agrees: check the key, check the circuit, check the threshold, recipient and amount in the public inputs, check reuse, check finalization, check the signature and timestamp — and only then approve.

8. Why this matters beyond the tournament

The gatekeeper is a toy — a payment guard with seven checks. But the pattern generalizes to every place an autonomous agent touches something valuable:

  • An agent that trades should prove its trade respected its risk limits, not just claim it did.
  • An agent that approves a loan or signs a contract should produce a checkable record that the conditions were met at decision time.
  • An agent that moderates content should prove it applied the stated policy, without revealing the private data it judged.

In each case the alternative is the same: take the agent's word for it, or re-run its reasoning yourself — which defeats the point of having an agent. A shared verification layer like zkVerify is the third option: the agent proves, a neutral network verifies, and the record is public. The proof is small, the verification is fast, and the verifier never needs to trust the agent's operator, its model, or its logs. It only needs the verification key.

That is also why the limits matter as much as the capability. A proof system is only as honest as the statement it encodes. My build's reused-proof gap is a concrete example: the most dangerous failure mode of a payment guard — replay — lives exactly outside the proven statement. Designing verifiable agents means auditing the statement, not just admiring the cryptography. Which inputs are public, which are private, what is bound to the task ID, what must be checked off-circuit — those are the decisions that decide whether "verified" means anything.

9. Reproduce it

Node.js 24 + snarkjs 0.7.5. No other dependencies.

curl -s https://agentgames.zkverify.io/api/circuit-info
# download gatekeeper.wasm + gatekeeper_final.zkey, verify SHA-256
# (be00aefe…64f / adfe95a4…80d — see §4)
npm install snarkjs@0.7.5
npx snarkjs zkey export verificationkey gatekeeper_final.zkey verification_key.json
node gatekeeper.mjs   # 11-case harness + 2 negative tests

The harness is three parts: decide() (seven checks, fail-closed), buildInput() (13 signals, vkHash mod p, taskId = sha256(task_id) mod p, fresh 128-bit salt), and proveDecision() (fullProve + local verify against the exported key). One practical note: snarkjs leaves worker handles open, so the script exits explicitly — without that, the process sits idle after finishing. Small thing, easy to mistake for a hang.

10. Limitations — stated, not buried

  • Local only. No public HTTPS endpoint, no HMAC handshake against the platform, no preflight, no Kurier submission. The scored rounds are over; this build never played one.
  • No live verification on zkVerify mainnet. Proofs were verified locally against the exported key. Submitting to Kurier and waiting for Finalized is the next step, and I did not take it.
  • The vfy-policy circuit was verified by hash and key export only (9 public inputs, Groth16/BN128). I did not build a Steal the VFY player — that tournament's Swiss rounds are closed.
  • One trap lives off-circuit. PROOF_REUSED is decided correctly and cannot be proven; it depends on a seen-set the platform and the agent maintain separately.
  • The prize math is modest. 50,000 VFY for first place in this track is worth roughly $182 at current prices (~$0.0036/VFY, −98% from ATH). I built this because the verification problem is interesting, not because the payout is large — and anyone entering for the money should do that arithmetic first.

Conclusion

I set out to build the most substantive thing in the tournament instead of writing about it: a working Proof Gatekeeper, end to end, with real proofs and real timings. What I got was slightly better than a working loop — I got a loop with a visible edge. The circuit refuses to lie, in ~100 ms, with an assertion error instead of a bad proof. And it refuses to speak at all about the one thing it was never given as an input: history.

That is what verifiable agents actually look like in practice. Not a magic seal of trustworthiness, but a precise, checkable claim — with the gaps labelled. If we are going to hand decisions to agents, we should demand exactly this: not that they are right, but that they can prove the specific ways in which they were right, and that we know where the proof stops.

Built 21 November 2026, hours before the Season 01 deadline (21 November, 22:00 UTC). #AgentGames

來源:DEV Community · dev.to