Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Proof Gatekeeper Agent — zkVerify Agent Games

Service agent untuk event Proof Gatekeeper (zkVerify Agent Games). Node.js 22 + express + snarkjs.

Status

  • ✅ Service berjalan di port 8787 (bound 0.0.0.0) + tunnel cloudflared quick tunnel.
  • ✅ Self-test 11/11 lulus (preflight, HMAC, semua branch keputusan, proof Groth16 lokal).

Endpoint publik yang akan didaftarkan

https://shareholders-therapeutic-competitors-hypothetical.trycloudflare.com/agent

⚠️ URL trycloudflare.com quick tunnel berubah setiap kali tunnel di-restart. Jika tunnel mati, jalankan ulang:

cd /root/agentgames && ./cloudflared tunnel --url http://localhost:8787 --no-autoupdate

lalu ambil URL https://<subdomain>.trycloudflare.com dari output/log, dan update registrasi di dashboard. Daftarkan path penuh /agent (bukan root).

Health check lokal: curl http://localhost:8787/health → 200. Cek lewat tunnel: curl https://<tunnel>/health → 200.

Cara set secret (WAJIB sebelum registrasi/preflight platform)

  1. Dashboard Agent Games → Rotate Secret → salin plaintext sekali tampil.
  2. Edit /root/agentgames/.env, isi:
    AGENT_GAMES_HMAC_SECRET=<plaintext dari dashboard>
    KURIER_API_KEY=<opsional, untuk submit proof ke zkVerify via Kurier>
    SUBMIT_TO_ZKVERIFY=1   # opsional: aktifkan submit Kurier & tunggu Finalized
    
  3. Restart service: pkill -f 'node server.js' lalu jalankan lagi:
    cd /root/agentgames && (setsid node server.js > service.log 2>&1 < /dev/null &) && ./cloudflared tunnel --url http://localhost:8787 --no-autoupdate &
    (Saat ini .env berisi placeholder PLACEHOLDER_SET_AGENT_GAMES_HMAC_SECRET — secret asli belum ada; service tetap jalan dan menerima inbound, tapi preflight platform akan gagal signature sampai secret asli diisi. Jangan pernah commit .env.)

Cara preflight (lokal)

cd /root/agentgames
BASE_URL=http://localhost:8787 node selftest.js
# atau lewat tunnel publik:
BASE_URL=https://<tunnel>.trycloudflare.com node selftest.js

Output wajib: baris preflight ... {"ok":true,"protocolVersion":"v1"} dengan respSig: true. Preflight platform: setelah registrasi + Rotate Secret, platform otomatis mengirim agent-games.preflight.v1 ke endpoint; agent membalas {ok:true,protocolVersion:"v1"} ditandatangani HMAC.

Arsitektur & keputusan

  • POST /agent: verifikasi HMAC-SHA256 (x-agent-games-signature) atas raw body sebelum parse (timing-safe). Mismatch → 401 INVALID_SIGNATURE.
  • agent-games.preflight.v1 → {ok:true,protocolVersion:"v1"} (signed).
  • agent-games.proof-gatekeeper.v1 → keputusan deterministik (bukan model) sesuai security checklist /build:
    • DEADLINE_EXCEEDED — deadline_at lewat (fail closed).
    • PROOF_REUSED — proof_tx sama dipakai task_id berbeda (replay task sama idempotent).
    • VK_SUBSTITUTION — proof_vk ≠ registered_vk.
    • BALANCE_BELOW_MIN — public_balance < minimum.
    • AMOUNT_EXCEEDS_MAX — amount > max_transfer.
    • INSUFFICIENT_BALANCE — amount > public_balance.
    • RECIPIENT_MISMATCH — recipient ≠ condition_recipient.
    • CIRCUIT_EXPIRED — current_block ≥ expiry_block.
    • APPROVE → witness + Groth16 proof lokal (snarkjs, gatekeeper.wasm + gatekeeper_final.zkey, verified lokal terhadap vk.json) → respons {decision, reason_code, proof, public_signals, proof_tx} (HMAC-signed, raw body).
    • Semua keputusan APPROVE/REJECT konsisten dengan assertion circuit (decision=1 ⟺ semua cek lolos).
  • opsional SUBMIT_TO_ZKVERIFY=1 + KURIER_API_KEY: proof disubmit ke Kurier (POST /submit-proof/{key}, vk hash terdaftar 0x6b79c6...77b0) dan dipolling sampai Finalized (timeout 45s, fail-closed).
  • Encoding field: string numerik → BigInt; 0x… → BigInt hex; string lain → sha256 mod BN254 prime (dokumentasikan bila platform memakai encoding berbeda).

Semantik circuit (direverse dari gatekeeper.wasm, 13 input publik)

decision=1 iff: publicBalance≥minimum ∧ amount≤maxTransfer ∧ amount≤publicBalance ∧ recipient==conditionRecipient ∧ proofVkHash==registeredVkHash ∧ currentBlock<expiryBlock (strict). decision=0 hanya valid bila ≥1 cek gagal.

File penting (/root/agentgames/)

  • server.js — service utama (port 8787).
  • selftest.js — harness replay 11 kasus (preflight, bad-sig, approve+proof, 6 reason codes, reuse).
  • gatekeeper.wasm, gatekeeper_final.zkey — circuit artifacts resmi dari /build.
  • vk.json — verification key (diekstrak dari zkey, nPublic=13).
  • .env (secret, jangan commit), .env.example, .gitignore.
  • service.log — log inbound (tidak pernah mencatat secret).
  • cloudflared — binary tunnel quick tunnel.
  • package.json, node_modules/ (snarkjs, express).

Belum dikerjakan (butuh user)

  • Set AGENT_GAMES_HMAC_SECRET asli dari Rotate Secret dashboard.
  • Registrasi endpoint di platform (dikerjakan user, bukan agent).
  • Kurier API key jika ingin submission on-chain Finalized.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages