Skip to content

feat(bitcoin): implement native introspection jets (InputValue, NumInputs, etc.)#359

Open
Laz1mov wants to merge 1 commit intoBlockstreamResearch:masterfrom
Laz1mov:feature/bitcoin-introspection-jets
Open

feat(bitcoin): implement native introspection jets (InputValue, NumInputs, etc.)#359
Laz1mov wants to merge 1 commit intoBlockstreamResearch:masterfrom
Laz1mov:feature/bitcoin-introspection-jets

Conversation

@Laz1mov
Copy link
Copy Markdown

@Laz1mov Laz1mov commented Apr 15, 2026

Description

This PR implements the critical Bitcoin introspection jets required for Layer 1 covenants to read transaction state without relying on injected witnesses.

It introduces native, zero-panic Rust implementations for NumInputs, NumOutputs, InputValue, and InputUtxosHash, bridging them securely to the existing FFI c_jet_ptr interface.

Key Contributions

  1. Environment Upgrades: Upgraded BitcoinEnv to maintain the current input index (ix) and the slice of spent_outputs necessary for UTXO inspection.
  2. Cryptographic Parity:
    • Ensured all implemented jets generate the exact CMRs specified in the C reference (primitiveJetNode.inc).
    • InputUtxosHash perfectly mimics the hierarchical C implementation (combining inputValuesHash and inputScriptsHash).
  3. Weight Calibration: Assigned precise milli-weight costs to each jet (e.g., 74, 68, 81, 122 mW) to maintain execution budget integrity within the BitMachine.
  4. Safety: Zero .unwrap() or panics in the execution paths. Memory boundary checks gracefully trigger BitMachineTrap equivalents on out-of-bounds access.

Motivation

Projects building on Simplicity (such as the PRECOP canonical engine) require these jets to transition from "trusted witness" topologies to fully deterministic, mathematically verifiable state transitions.

Testing

  • CMR assertion tests validating parity with C-core.
  • End-to-end BitMachine execution tests using mocked BitcoinEnv data.

Signed-off-by: Laz1m0v 198518978+Laz1m0v@users.noreply.github.com

Adds native Rust implementation and C-FFI bindings for NumInputs, NumOutputs, InputValue, and InputUtxosHash. Updates BitcoinEnv to hold spent_outputs and current index. Ensures perfect CMR and milli-weight parity with the C reference.

Signed-off-by: Laz1m0v <198518978+Laz1m0v@users.noreply.github.com>
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