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
- Bump
simplicityhl to the unreleased
- Fix the breakages:
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.
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
simplicityhlto theunreleasedCompiledProgram::newargument inProgram::loadDefaultTracker::buildchange inProgramLogger::make_tracker.Configurable jet selection in
Simplex.tomlThe flag goes in the existing
[build]table:JetTypeenum (Core,Bitcoin,Elements), deserialized as lowercase, defaulting toElements.jetfield toBuildConfig.JetTypetoBox<dyn ast::JetHinter>deriver.Compiler jet selection
JetTypetoProgram::load:Programneeds to know itsJetTypesoload,execute,get_envandfinalizeuse the same type.jet_hinterintoProgramLogger::make_trackerand switch itsDefaultTracker::new(debug_symbols)toDefaultTracker::build(debug_symbols, jet.hinter()); the call is inProgram::execute.General Core, Bitcoin and Elements Jet Sets
Codebase Changes
JetEnvironmentSmplxtrait withJetEnvironmentas supertrait, it should have environment-specific methods and transaction finalization for specific environments as inProgram::get_env,Program::executeandProgram::finalize.CoreJetEnvSmplx,BitcoinJetEnvSmplxandElementsJetEnvSmplxtraits withJetEnvironmentSmplxas supertrait.Programshould have generic parameter ofJetEnvironmentSmplxtrait.ProgramTrait::get_envshould return a reference to theJetEnvironmentSmplxtrait object.JetTypefromBuildConfiginto the generated program.ElementsEnvinProgram::get_envand the Elements-only finalization inProgram::finalizefor the active environment (CoreEnv,BitcoinEnvorElementsTxEnv).Provider & network
SimplicityNetworkcurrently models onlyLiquid,LiquidTestnetandElementsRegtest, all built onelements::AssetId,BlockHashandAddressParams. It should have Bitcoin variants for mainnet, testnet, signet and regtest, and a Core variant.policy_asset()returns anelements::AssetId, but Bitcoin and Core have no asset, so it should return anOption.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 BitcoinNetworkKindinstead.ElementsRpc, re-exported at provider/mod.rs#15, is an Elements node client. Its methodssend_to_address,sweep_initialfreecoins,generate_blocksandrescan_blockchainshould move behind an RPC trait chosen by type.assetandvaluefields thatSimplexProviderand Esplora parse from each UTXO should be read only for the Elements type, because Bitcoin Esplora does not return them.Signer & key management
Signerholds aSimplicityNetworkand is built entirely onelements_miniscript, includingConfidentialDescriptorandslip77::MasterBlindingKey. It should be abstracted over the jet type.sign_programbuilds its message from the Elementssighash_all(), andsign_inputuses the ElementsSighashCache. Both should select the sighash by environment.send,finalize,finalize_strict(#237) andestimate_txall pay the fee in the policy asset throughpolicy_asset()andcalculate_fee_delta. The fee model should branch by type.get_confidential_addressandmaster_slip77are confidential only and should stay behind the Elements type, whileget_addressshould choose its address parameters by type.Transaction building
transactionmodule is built around the ElementsPartiallySignedTransaction, so it should become generic over the type or have a Bitcoin PSBT builder.UTXOwraps the ElementsTxOutandTxOutSecrets, and its confidential accessorsexplicit_assetandunblinded_assetshould stay behind the Elements type.PartialInputcarries theamount,assetandsecretsfields, and theIssuanceInputenum covers issuance and reissuance. All of these are Elements-only and should be locked by jet type as such.PartialOutputkeeps anassetfield and ablinding_keyfield and emitsOutput::new_explicit(..)at #53, which should likewise be locked behind the Elements type.Regtest & test harness
get_elementsd_bin_argsstartselementsdwith Elements-only. A matchingbitcoindargument builder should be added without those flags.Regtest::from_confighardwiresSimplicityNetwork::default_regtest(), andprepare_signerfunds the signer throughElementsRpc::sweep_initialfreecoins,generate_blocksandsend_to_address.TestContext::setupmatches the network namesLiquid,LiquidTestnetandElementsRegtestat #131. It should accept the Bitcoin networks too, andNetworkUtilsshould become type aware.Config::validate_networkallowlist and the check inConfig::validatethat only permits RPC onElementsRegtestshould 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.