Skip to content

docs: Authenticated trie integration spec — Phase 1B state-proof endpoint#119

Open
ottobot-ai wants to merge 1 commit intoscasplte2:mainfrom
ottobot-ai:docs/authenticated-trie-integration-spec
Open

docs: Authenticated trie integration spec — Phase 1B state-proof endpoint#119
ottobot-ai wants to merge 1 commit intoscasplte2:mainfrom
ottobot-ai:docs/authenticated-trie-integration-spec

Conversation

@ottobot-ai
Copy link
Collaborator

Summary

Specification for Design: Authenticated trie integration for OttoChain state (Trello card 699fa07f).

Covers the full design for Phase 1B: exposing MPT inclusion proofs so clients can trustlessly verify fiber state without downloading the full CalculatedState.

What This Spec Covers

Phase 1B: GET /v1/state-machines/{fiberId}/state-proof?field={field}

Depends on PR #117 (adds stateRoot per-fiber and metagraphStateRoot to CalculatedState).

  • Two-level proof chain: field proof → per-fiber stateRoot → metagraph-level metagraphStateRoot (same value returned by hashCalculatedState)
  • Stateless MPT: StatelessMerklePatriciaProducer (recomputes trie from stateData on each request, <5ms for typical 5-leaf fiber)
  • Bridge proxy: GET /fiber/:fiberId/state-proof → ML0 transparent pass-through
  • TypeScript verifier: verifyStateProof(proof, root) ~30 lines using crypto.subtle
  • RFC 8785 canonicalization warning for cross-language verifiers (UTF-16BE key sort vs simple lexicographic)

API Contract

GET /v1/state-machines/{fiberId}/state-proof?field=balance

200 OK:
{
  "fiberId": "550e8400-e29b-41d4-a716-446655440000",
  "field": "balance",
  "value": {"var": 1000},
  "stateRoot": "abc123...",
  "metagraphStateRoot": "def456...",
  "fieldProof": { "path": "...", "witness": [...] },
  "metagraphProof": { "path": "...", "witness": [...] }
}

TDD Tests

22 tests in 5 groups:

  • Group 1: Route registration (3 tests)
  • Group 2: Error cases (4 tests)
  • Group 3: Proof format (5 tests)
  • Group 4: Proof correctness — Scala round-trip via MerklePatriciaVerifier (5 tests)
  • Group 5: Cross-language TypeScript verifier (5 tests)

Files: modules/l0/src/test/scala/xyz/kd5ujc/metagraph_l0/StateProofRouteSuite.scala + ottochain-sdk/src/__tests__/state-proof-verifier.test.ts

Open Questions for James

  1. Batch field proofs — support ?fields=balance,owner in Phase 1B or defer?
  2. PR chore(main): release 0.6.4 #61 disposition — close once Phase 1B merges, or keep open for Phase 3 exploration?
  3. Rate limiting on proof endpoint (public, no secrets)?

Acceptance Criteria

See spec for all 10 ACs. Key ones:

  • AC-2a/b: Both proof levels verify via MerklePatriciaVerifier
  • AC-3: metagraphStateRoot equals hashCalculatedState output
  • AC-8: TypeScript verifyStateProof() passes cross-language tests

Related

…oint

Spec for Design card 699fa07f. Covers:
- ML0 GET /v1/state-machines/{fiberId}/state-proof?field=X endpoint
- Two-level MPT proof chain (field → stateRoot → metagraphStateRoot)
- TypeScript verifyStateProof() client implementation (~30 lines)
- RFC 8785 canonicalization notes for cross-language verifiers
- 22 TDD tests in 5 groups (17 Scala + 5 TypeScript)
- 10 acceptance criteria
- Phase 1B blocked on PR scasplte2#117 merge

Depends on PR scasplte2#117 (feat/metagraph-phase1-state-roots)
ottobot-ai added a commit that referenced this pull request Feb 26, 2026
- Add 17 Scala test cases covering:
  * StateRoot generation from stateData fields
  * MetagraphStateRoot integration with fiber states
  * ML0 state proof endpoint (GET /v1/state-machines/:fiberId/state-proof)
  * Two-level MPT proof chain validation
  * RFC 8785 canonicalization and error handling

- Tests follow TDD methodology: all tests fail with 'Feature not implemented' errors
- Based on authenticated-trie-integration-spec.md (PR #119)
- Ready for implementation phase after spec review approval
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