feat: add InductiveSmartContract with UTXO chain backward verification#5
Open
feat: add InductiveSmartContract with UTXO chain backward verification#5
Conversation
Implement the third contract base class that extends StatefulSmartContract with mathematical induction on the UTXO chain. Each transaction verifies its parent had the same covenant code and consistent lineage metadata, enabling a verifier to confirm the full chain back to genesis by inspecting only two consecutive transactions. Changes across all three compilers (TypeScript, Go, Rust): - Parser: detect InductiveSmartContract, inject internal fields (_genesisOutpoint, _parentOutpoint, _grandparentOutpoint) - Validator: allow new parent class, reject reserved field names - Typecheck: add implicit parentTx param, exclude internal fields from addOutput arg count - ANF lowering: inject checkPreimage, parent tx hash verification, genesis detection, chain consistency assertions, internal field updates - New IR node: extract_parent_output for raw Bitcoin tx parsing - Stack lowering: implement extract_parent_output via OP_SPLIT chains - Optimizer: add extract_parent_output to constant fold pass-through SDKs (TypeScript, Go, Rust): detect parentTx ABI param, fetch raw parent tx from provider, prepend to unlocking script. Mock packages: add InductiveSmartContract type (Go struct, Rust struct). Includes InductiveToken example with vitest tests and multi-format conformance test (TS, Solidity, Move, Go, Rust). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Explains the chain verification problem, the induction-based solution, compiler-injected fields and verification sequence, genesis detection, parent output extraction, transaction flow examples, and SDK integration. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Describes the chain integrity theorem, its proof structure (base case, inductive step, chain linking), the three cryptographic axioms required, and notes that a Coq/Lean formalization would be ~200 lines. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Derive output index dynamically from the outpoint in the BIP-143 preimage instead of hardcoding index 0. This enables methods like transfer that create multiple outputs (recipient + change) where the change UTXO at index 1 can be correctly verified in the next transaction. Changes across all 3 compilers (TS, Go, Rust): - ANF lowering: extract vout from outpoint via right() + OP_BIN2NUM - Stack lowering: unrolled output-skipping loop (up to 4 outputs) - ANF lowering: fix Go/Rust to auto-append internal fields to addOutput and reorder internal field updates before developer body - Add unpack to unary_op opcode maps SDK multi-output support (TS, Go, Rust): - CallOptions.outputs accepts multiple OutputSpec with per-output state - BuildCallTransaction creates multiple continuation outputs - ContinuationOutputIndex controls which output to track - State save/restore during multi-output script building Tests: 9 new Go SDK multi-output tests, all 1306 TS tests pass
8fddf16 to
e48908e
Compare
Resolve 24 conflicts, keeping both InductiveSmartContract features and main's Python compiler, property initializers, and SDK improvements. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ontract Replace the full raw parent transaction parameter with 4 constant-size implicit parameters (_parentHashState, _parentTailBlock1, _parentTailBlock2, _parentRawTailLen) totaling 161 bytes. The contract completes the parent txid hash on-chain using sha256Compress, preventing exponential tx growth. Changes across all 4 compilers (TS, Go, Rust, Python): - Remove ExtractParentOutput ANF node and stack lowering (~250 lines each) - Replace parentTx with partial SHA-256 verification in ANF lowering - Extract internal fields from tail blocks using arithmetic offsets - Add InductiveSmartContract support to Python compiler (new) - Add Python conformance test (inductive.runar.py) SDK changes (TS, Go, Rust, Python): - Add sha256Compress utility + computePartialSha256ForInductive - Auto-detect inductive methods via _parentHashState ABI param - Compute and push 4 implicit params in unlock script Documentation: - Rewrite docs/inductive-contracts.md with partial SHA-256 approach - Remove working document (partial-sha256-inductive-contracts.md) - Update CLAUDE.md contract model section and conformance count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
InductiveSmartContractas a third contract base class extendingStatefulSmartContractwith backward verification via mathematical induction on the UTXO chain (BOLT-style)Mechanism
The compiler auto-injects three internal state fields (
_genesisOutpoint,_parentOutpoint,_grandparentOutpoint) and verification logic at method entry:hash256(parentTx) === left(extractOutpoint(txPreimage), 32)Files changed (40 modified, 7 new)
extract_parent_output— raw Bitcoin tx parsing via OP_SPLIT chainsexamples/ts/inductive-token/— InductiveToken contract + vitest testsconformance/tests/inductive/— 5 format variants (TS, Sol, Move, Go, Rust)Test plan
pnpm run build— all 6 packages compilenpx vitest run— 1306 tests pass (74 test files), including new InductiveToken testscd compilers/go && go test ./...— all Go compiler tests passcd compilers/rust && cargo test— all 108 Rust compiler tests pass--update-golden)🤖 Generated with Claude Code