Skip to content

docs: authenticated trie integration spec — Phase 1B state-proof API#119

Merged
scasplte2 merged 2 commits into
scasplte2:mainfrom
ottobot-ai:docs/authenticated-trie-integration-spec
Jun 12, 2026
Merged

docs: authenticated trie integration spec — Phase 1B state-proof API#119
scasplte2 merged 2 commits into
scasplte2:mainfrom
ottobot-ai:docs/authenticated-trie-integration-spec

Conversation

@ottobot-ai

Copy link
Copy Markdown
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

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
@ottobot-ai ottobot-ai force-pushed the docs/authenticated-trie-integration-spec branch from 12310c5 to fc4f628 Compare March 13, 2026 22:20
@ottobot-ai ottobot-ai changed the title docs: Authenticated trie integration spec — Phase 1B state-proof endpoint docs: authenticated trie integration spec — Phase 1B state-proof API Mar 13, 2026
@ottobot-ai

Copy link
Copy Markdown
Collaborator Author

🤖 Quality Score: 80/100

PR Agent Review — Tier 1 Gate

Category Score Notes
Description quality 23/25 Excellent spec: API contract, 22 TDD tests, 10 acceptance criteria, Trello ref
CI status 13/25 Fixes applied: header shortened to 70 chars, PR title lowercased — CI re-running
Content quality 22/25 Spec doc + docker fix + deps bump, coherent and well-structured
Commit compliance 15/15 Fixed: header was 73 chars (>72 limit) — now 70
Hygiene 7/10 Good branch name; no labels yet

Fixes applied: Shortened commit header (73→70 chars), lowercased PR title

Score 80/100 meets threshold (80+). Promoting to human review.

CC: @scasplte2 for final review.

@ottobot-ai ottobot-ai added the tier-2-review Needs human review before merge label Mar 13, 2026
@ottobot-ai ottobot-ai force-pushed the docs/authenticated-trie-integration-spec branch from fc4f628 to af03de9 Compare March 19, 2026 19:46
@ottobot-ai

Copy link
Copy Markdown
Collaborator Author

🔄 Resolved merge conflict and rebased onto main.

Conflict resolved: docker-entrypoint.sh — trivial blank-line conflict from the fix(docker): currency L0 run-rollback commit. Accepted incoming (no blank line).

@ottobot-ai ottobot-ai force-pushed the docs/authenticated-trie-integration-spec branch 2 times, most recently from af393ab to 59fd400 Compare March 24, 2026 00:43
@ottobot-ai ottobot-ai force-pushed the docs/authenticated-trie-integration-spec branch 2 times, most recently from 12310c5 to 201d3d1 Compare March 24, 2026 18:46
@ottobot-ai

Copy link
Copy Markdown
Collaborator Author

🔄 Resolved 1 conflict (blank line in docker-entrypoint.sh) and rebased onto main.

@ottobot-ai ottobot-ai force-pushed the docs/authenticated-trie-integration-spec branch 4 times, most recently from 629defd to 005a8d7 Compare March 24, 2026 23:53
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)
As of tessellation 4.0.0-rc.10:
- DAG L0 (GL0): REQUIRES rollback hash as positional argument
- Currency L0 (ML0/CL0): Does NOT require hash (auto-detects from storage)
- Data L1: Does NOT require hash

The old entrypoint assumed all layers needed the hash for run-rollback,
causing ML0/CL0 restarts to fail with 'Unexpected argument' error.
@ottobot-ai ottobot-ai force-pushed the docs/authenticated-trie-integration-spec branch from 005a8d7 to 5030f6f Compare March 25, 2026 03:53
@scasplte2 scasplte2 merged commit 9a9edae into scasplte2:main Jun 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tier-2-review Needs human review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants