cred402/ration-anchor
caelum0x 07136e7b73 feat(near-hackathon): fold Ration's audit-anchor work into this repo as ONE combined NEAR submission
Owner directive (2026-11-11): submit a single project to the NEAR
Hackathon instead of two separate entries from the same person. Vendors
Ration's NEAR audit-anchor work (github.com/caelum0x/ration, commit
cff0ed3 + follow-ups) into ration-anchor/ as a first-class component:

- contracts-near/audit_anchor (NEAR Rust contract, 5/5 cargo tests
  green, target/ deleted)
- signer/ — a new, self-contained Go module (no dependency on Ration's
  other services or go.work) with the hand-rolled NEAR transaction
  signer + JSON-RPC client (cross-checked byte-for-byte against
  near-api-js) and the hash-chained audit ledger it anchors; 15/15 Go
  tests green (go test ./... -race)
- docs/ and media/ — Ration's original pitch deck, demo recordings, and
  submission checklist

Re-verified live via raw NEAR Testnet JSON-RPC this pass:
ration-anchor-286ca315f1.testnet still deployed and queryable, the
deliberate replay-rejection transaction still fails with nearcore's own
"sequence must strictly advance" panic — no redeploy needed.

Provenance notes added throughout (package doc comments, lib.rs header,
README) crediting the origin repo. README.md and HACKATHON.md rewritten
to tell one story: Cred402's SpendGuard enforces the protocol-level
spending limit, the vendored Audit Anchor proves the tamper-evident
spend history, both independently verifiable on NEAR Testnet. No mainnet
claims anywhere (see prior overclaim fix 524f2dd). cred402's own build
(npm run typecheck) and existing tests are untouched.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-11 15:32:24 +03:00
..

Ration audit anchor, now part of Cred402

Provenance: every file under this directory originates from Ration — a separate, real AI-agent spend-control product by the same author — specifically commit cff0ed3 ("feat(near-hackathon): anchor audit-log's hash-chain tip to NEAR Testnet") and the doc/asset follow-up commits on top of it (f6c0503, da8f906, e4b3212, 6b0bf3d, 7dd0b7f, 767ed80). It is vendored here — import paths adjusted, provenance notes added, nothing else changed — as a first-class component of Cred402's single NEAR Hackathon submission (owner decision, 2026-11-11): one project, two NEAR components, one story. Ration's own repo and NEAR Hackathon packet are unaffected; this is a copy, not a move.

Why this lives inside Cred402 now

Cred402's ../contracts-near/spend_guard enforces how much an AI agent may spend — nearcore itself caps spend via a real NEAR Function Call Access Key allowance, a protocol-enforced limit, not just an app-level check.

This directory enforces why it spent, tamper-evidently: every spend decision gets journaled into a real append-only, hash-chained audit trail (signer/store), and the trail's current tip is anchored to a NEAR smart contract (contracts-near/audit_anchor) this work wrote and deployed. A judge, auditor, or counterparty can independently verify on a public blockchain that the trail hasn't been tampered with — and a replayed/stale anchor is mechanically rejected by nearcore itself (proven by a real deliberate replay attempt that failed on-chain, see below), not just by application code.

Together: one NEAR submission demonstrates both halves of a real agent-spend-control story — the limit (SpendGuard) and the history (Audit Anchor) — each independently verifiable on NEAR Testnet.

Layout

ration-anchor/
├── contracts-near/audit_anchor/   on-chain NEAR contract (Rust, near-sdk 5)
│   ├── Cargo.toml / Cargo.lock
│   └── src/lib.rs                 commit_anchor() + 3 read-only views
├── signer/                        self-contained Go module (no deps on
│   │                              Ration's other services or go.work)
│   ├── go.mod                     module github.com/caelum0x/cred402/ration-anchor/signer
│   ├── nearanchor/                hand-rolled NEAR tx signer + JSON-RPC client
│   │   ├── transaction.go/borsh.go/keys.go/base58.go/rpcclient.go/anchor.go/config.go
│   │   └── *_test.go              incl. byte-for-byte near-api-js cross-check vectors
│   ├── store/                     the append-only, hash-chained audit ledger itself
│   └── cmd/near-anchor/main.go    CLI: create-account / deploy / commit / verify / demo
├── docs/                          Ration's original submission docs (pitch deck, demo
│                                  video (720p recording +md transcript), checklist, X-post draft)
└── media/                         Ration's original NEAR-specific demo recordings

Build + test (verified 2026-11-11, this pass)

# Go signer + hash-chained ledger — fully self-contained, pure stdlib,
# no dependency on Ration's other services or its go.work.
cd ration-anchor/signer
go build ./...
go test ./... -race
# -> ok  .../ration-anchor/signer/nearanchor   (8 tests)
# -> ok  .../ration-anchor/signer/store        (10 tests)
# 15/15 total, matching Ration's own "15/15 ledger-core tests" claim.

# NEAR contract (Rust)
cd ../contracts-near/audit_anchor
cargo test --lib -j2
# -> test result: ok. 5 passed; 0 failed
rm -rf target   # keep the repo free of local build artifacts

Live on-chain verification (re-confirmed 2026-11-11, via raw JSON-RPC)

curl -s https://rpc.testnet.fastnear.com -X POST -H "Content-Type: application/json" -d '{
  "jsonrpc": "2.0", "id": "dontcare", "method": "query",
  "params": {
    "request_type": "call_function", "finality": "final",
    "account_id": "ration-anchor-286ca315f1.testnet",
    "method_name": "get_latest_anchor", "args_base64": ""
  }
}'

Decoded result: {"tenant_id":"tenant-integration-test","chain_tip_hash":"761d886a...","sequence":5,...} — the contract is genuinely deployed, queryable, and matches the state already claimed in Ration's own packet; no redeploy was needed.

The deliberate replay-rejection evidence (tx 7v6m81jkbT2K5AjVBbDray9hXWVB2cHvTBWt3Uui469o) was independently re-checked via the NEAR tx RPC method this pass and still returns:

Smart contract panicked: audit_anchor: sequence must strictly advance
past the last anchored sequence (stale or replayed anchor rejected)

— nearcore itself rejects a replayed/stale anchor; this is not just an application-level check.

Honesty notes (never overclaim)

  • Testnet only. Nothing here is deployed to NEAR mainnet. No mainnet claim is made anywhere in this directory or in Cred402's top-level README/HACKATHON.md.
  • Cred402 is not claimed "live" on any chain in production other than Casper Testnet — see the top-level HACKATHON.md's own overclaim-correction history (commit 524f2dd) for why this wording is deliberate and re-checked every pass.
  • ration-anchor-286ca315f1.testnet, ration-demo-23bd92e5.testnet, and ration-video-61849d567f.testnet are disposable NEAR Testnet accounts this work created to run/demo the contract — none of them is a payout wallet.