Skip to content

SMPLX Dynamic General Jets Model Implementation Plan #99

Description

@ivanlele

Due to the upcoming abstraction of jets in SimplicityHL, corresponding changes need to be made to the Simplex codebase. This issue proposes a new flag to explicitly specify the jet type and outlines the changes required to implement it.

Dependency upgrade

Configurable jet selection in Simplex.toml

The flag goes in the existing [build] table:

[build]
src_dir = "./simf"
simf_files = ["*.simf"]
out_dir = "./src/artifacts"
jet = "elements"   # "core" | "bitcoin" | "elements"  (default: "elements")
  • Add a JetType enum (Core, Bitcoin, Elements), deserialized as lowercase, defaulting to Elements.
  • Add a jet field to BuildConfig.
  • Document it in README.md and Simplex.default.toml.
  • Add one JetType to Box<dyn ast::JetHinter> deriver.

Compiler jet selection

CompiledProgram::new(
    self.source,
    self.arguments.build_arguments()
    GlobalConfig::get_include_debug_symbols(),
    jet_hinter
)
  • Program needs to know its JetType so load, execute, get_env and finalize use the same type.
  • Thread jet_hinter into ProgramLogger::make_tracker and switch its DefaultTracker::new(debug_symbols) to DefaultTracker::build(debug_symbols, jet.hinter()); the call is in Program::execute.

General Core, Bitcoin and Elements Jet Sets

Codebase Changes

  • Create a new JetEnvironmentSmplx trait with JetEnvironment as supertrait, it should have environment-specific methods and transaction finalization for specific environments as in Program::get_env, Program::execute and Program::finalize.
  • Create new CoreJetEnvSmplx, BitcoinJetEnvSmplx and ElementsJetEnvSmplx traits with JetEnvironmentSmplx as supertrait.
  • Program should have generic parameter of JetEnvironmentSmplx trait.
  • Method such as ProgramTrait::get_env should return a reference to the JetEnvironmentSmplx trait object.
  • Pass the JetType from BuildConfig into the generated program.
  • Swap the Elements-only ElementsEnv in Program::get_env and the Elements-only finalization in Program::finalize for the active environment (CoreEnv, BitcoinEnv or ElementsTxEnv).

Provider & network

  • SimplicityNetwork currently models only Liquid, LiquidTestnet and ElementsRegtest, all built on elements::AssetId, BlockHash and AddressParams. It should have Bitcoin variants for mainnet, testnet, signet and regtest, and a Core variant.
  • policy_asset() returns an elements::AssetId, but Bitcoin and Core have no asset, so it should return an Option.
  • genesis_block_hash() reads the Liquid genesis constants near network.rs#16. The Bitcoin genesis hashes should sit alongside them.
  • address_params() returns an &elements::AddressParams. For the Bitcoin type it should return the Bitcoin NetworkKind instead.
  • ElementsRpc, re-exported at provider/mod.rs#15, is an Elements node client. Its methods send_to_address, sweep_initialfreecoins, generate_blocks and rescan_blockchain should move behind an RPC trait chosen by type.
  • The confidential asset and value fields that SimplexProvider and Esplora parse from each UTXO should be read only for the Elements type, because Bitcoin Esplora does not return them.

Signer & key management

  • Signer holds a SimplicityNetwork and is built entirely on elements_miniscript, including ConfidentialDescriptor and slip77::MasterBlindingKey. It should be abstracted over the jet type.
  • sign_program builds its message from the Elements sighash_all(), and sign_input uses the Elements SighashCache. Both should select the sighash by environment.
  • send, finalize, finalize_strict (#237) and estimate_tx all pay the fee in the policy asset through policy_asset() and calculate_fee_delta. The fee model should branch by type.
  • get_confidential_address and master_slip77 are confidential only and should stay behind the Elements type, while get_address should choose its address parameters by type.

Transaction building

  • The transaction module is built around the Elements PartiallySignedTransaction, so it should become generic over the type or have a Bitcoin PSBT builder.
  • UTXO wraps the Elements TxOut and TxOutSecrets, and its confidential accessors explicit_asset and unblinded_asset should stay behind the Elements type.
  • PartialInput carries the amount, asset and secrets fields, and the IssuanceInput enum covers issuance and reissuance. All of these are Elements-only and should be locked by jet type as such.
  • PartialOutput keeps an asset field and a blinding_key field and emits Output::new_explicit(..) at #53, which should likewise be locked behind the Elements type.

Regtest & test harness

  • get_elementsd_bin_args starts elementsd with Elements-only. A matching bitcoind argument builder should be added without those flags.
  • Regtest::from_config hardwires SimplicityNetwork::default_regtest(), and prepare_signer funds the signer through ElementsRpc::sweep_initialfreecoins, generate_blocks and send_to_address.
  • TestContext::setup matches the network names Liquid, LiquidTestnet and ElementsRegtest at #131. It should accept the Bitcoin networks too, and NetworkUtils should become type aware.
  • The CLI Config::validate_network allowlist and the check in Config::validate that only permits RPC on ElementsRegtest should both be extended for the Bitcoin networks. A cross check should also reject a jet that does not match its network, so that an Elements jet requires an Elements network and a Bitcoin jet requires a Bitcoin network.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions