diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b1c7e5f..2733d61 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -62,6 +62,7 @@ jobs: test-fuzz: name: Test - fuzzer runs-on: ubuntu-latest + needs: test-stable steps: - name: Checkout diff --git a/Cargo.lock b/Cargo.lock index f175d7e..88ff0a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -510,7 +510,7 @@ dependencies = [ [[package]] name = "simplicity-lang" version = "0.2.0" -source = "git+https://github.com/BlockstreamResearch/rust-simplicity?rev=713842937ab0b5e0b1a343e19fdee6634b7a6add#713842937ab0b5e0b1a343e19fdee6634b7a6add" +source = "git+https://github.com/BlockstreamResearch/rust-simplicity?rev=0594aaf004c1a28904e2242d0b319241b1560390#0594aaf004c1a28904e2242d0b319241b1560390" dependencies = [ "bitcoin", "bitcoin_hashes", @@ -526,7 +526,7 @@ dependencies = [ [[package]] name = "simplicity-sys" version = "0.2.0" -source = "git+https://github.com/BlockstreamResearch/rust-simplicity?rev=713842937ab0b5e0b1a343e19fdee6634b7a6add#713842937ab0b5e0b1a343e19fdee6634b7a6add" +source = "git+https://github.com/BlockstreamResearch/rust-simplicity?rev=0594aaf004c1a28904e2242d0b319241b1560390#0594aaf004c1a28904e2242d0b319241b1560390" dependencies = [ "bitcoin_hashes", "cc", diff --git a/Cargo.toml b/Cargo.toml index 0bd12d4..76803cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ homepage = "https://github.com/BlockstreamResearch/simfony/" repository = "https://github.com/BlockstreamResearch/simfony/" description = "Rust-like language that compiles to Simplicity bytecode." edition = "2021" -rust-version = "1.61.0" +rust-version = "1.63.0" [lib] name = "simfony" @@ -24,7 +24,7 @@ pest = "2.1.3" pest_derive = "2.7.1" serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.105" -simplicity-lang = { git = "https://github.com/BlockstreamResearch/rust-simplicity", rev = "713842937ab0b5e0b1a343e19fdee6634b7a6add" } +simplicity-lang = { git = "https://github.com/BlockstreamResearch/rust-simplicity", rev = "0594aaf004c1a28904e2242d0b319241b1560390" } miniscript = "11.0.0" either = "1.12.0" itertools = "0.13.0" diff --git a/README.md b/README.md index 6daba02..b0a1b32 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Take a look at the [example programs](https://github.com/BlockstreamResearch/sim ## MSRV -This crate should compile with any feature combination on **Rust 1.61.0** or higher. +This crate should compile with any feature combination on **Rust 1.63.0** or higher. ## Simplicity's need for a high-level language diff --git a/bitcoind-tests/Cargo.lock b/bitcoind-tests/Cargo.lock index 61ab274..016ca01 100644 --- a/bitcoind-tests/Cargo.lock +++ b/bitcoind-tests/Cargo.lock @@ -769,7 +769,7 @@ dependencies = [ [[package]] name = "simplicity-lang" version = "0.2.0" -source = "git+https://github.com/BlockstreamResearch/rust-simplicity?rev=713842937ab0b5e0b1a343e19fdee6634b7a6add#713842937ab0b5e0b1a343e19fdee6634b7a6add" +source = "git+https://github.com/BlockstreamResearch/rust-simplicity?rev=0594aaf004c1a28904e2242d0b319241b1560390#0594aaf004c1a28904e2242d0b319241b1560390" dependencies = [ "bitcoin 0.31.2", "bitcoin_hashes 0.13.0", @@ -785,7 +785,7 @@ dependencies = [ [[package]] name = "simplicity-sys" version = "0.2.0" -source = "git+https://github.com/BlockstreamResearch/rust-simplicity?rev=713842937ab0b5e0b1a343e19fdee6634b7a6add#713842937ab0b5e0b1a343e19fdee6634b7a6add" +source = "git+https://github.com/BlockstreamResearch/rust-simplicity?rev=0594aaf004c1a28904e2242d0b319241b1560390#0594aaf004c1a28904e2242d0b319241b1560390" dependencies = [ "bitcoin_hashes 0.13.0", "cc", diff --git a/clippy.toml b/clippy.toml index f5fcb56..b3c3a24 100644 --- a/clippy.toml +++ b/clippy.toml @@ -1 +1 @@ -msrv = "1.61.0" +msrv = "1.63.0" diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index 089bb2f..28778e9 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -2,7 +2,7 @@ name = "codegen" version = "0.1.0" edition = "2021" -rust-version = "1.61.0" +rust-version = "1.63.0" description = "Generator of Rust code as interface between Simfony and Rust." publish = false diff --git a/codegen/src/jet.rs b/codegen/src/jet.rs index 79c0fd5..5350445 100644 --- a/codegen/src/jet.rs +++ b/codegen/src/jet.rs @@ -414,6 +414,7 @@ This jet should not be used directly."#, // Bitcoin (without primitives) Elements::ParseLock => "Parse an integer as a consensus-encoded Bitcoin lock time.", Elements::ParseSequence => "Parse an integer as a consensus-encoded Bitcoin sequence number.", + Elements::TapdataInit => r#"Create a SHA256 context, initialized with a "TapData" tag."#, // Signature hash modes Elements::AnnexHash => r#"Continue a SHA256 hash with an optional hash by appending the following: - If there is no hash, then the byte `0x00`. @@ -433,6 +434,14 @@ This builds a taproot from two branches."#, - The lexicographically larger of the two inputs (32 bytes). This builds a taproot from two branches."#, + Elements::BuildTaptweak => r#"Implementation of `taproot_tweak_pubkey` from BIP-0341. + +## Panics +1. The input x-only public key is off curve or exceeds the field size. +2. The internal hash value `t` exceeds the secp256k1 group order. +3. The generated tweaked point is infinity, and thus has no valid x-only public key. + +Note that situations 2 and 3 are cryptographically impossible to occur."#, Elements::InputAmountsHash => "Return the SHA256 hash of the serialization of each input UTXO's asset and amount fields.", Elements::InputAnnexesHash => r#"Return the SHA256 hash of the concatenation of the following for every input: - If the input has no annex, or isn't a taproot spend, then the byte `0x00`. @@ -953,13 +962,13 @@ const DIGITAL_SIGNATURES: [Elements; 1] = [ Elements::Bip0340Verify ]; #[rustfmt::skip] -const BITCOIN: [Elements; 2] = [ - Elements::ParseLock, Elements::ParseSequence +const BITCOIN: [Elements; 3] = [ + Elements::ParseLock, Elements::ParseSequence, Elements::TapdataInit, ]; // Elements #[rustfmt::skip] -const SIGNATURE_HASH_MODES: [Elements; 34] = [ - Elements::AnnexHash, Elements::AssetAmountHash, Elements::BuildTapbranch, Elements::BuildTapleafSimplicity, Elements::InputAmountsHash, Elements::InputAnnexesHash, Elements::InputHash, Elements::InputOutpointsHash, Elements::InputScriptSigsHash, Elements::InputScriptsHash, Elements::InputSequencesHash, Elements::InputUtxoHash, Elements::InputUtxosHash, Elements::InputsHash, Elements::IssuanceAssetAmountsHash, Elements::IssuanceBlindingEntropyHash, Elements::IssuanceHash, Elements::IssuanceRangeProofsHash, Elements::IssuanceTokenAmountsHash, Elements::IssuancesHash, Elements::NonceHash, Elements::OutpointHash, Elements::OutputAmountsHash, Elements::OutputHash, Elements::OutputNoncesHash, Elements::OutputRangeProofsHash, Elements::OutputScriptsHash, Elements::OutputSurjectionProofsHash, Elements::OutputsHash, Elements::SigAllHash, Elements::TapEnvHash, Elements::TapleafHash, Elements::TappathHash, Elements::TxHash +const SIGNATURE_HASH_MODES: [Elements; 35] = [ + Elements::AnnexHash, Elements::AssetAmountHash, Elements::BuildTapbranch, Elements::BuildTapleafSimplicity, Elements::BuildTaptweak, Elements::InputAmountsHash, Elements::InputAnnexesHash, Elements::InputHash, Elements::InputOutpointsHash, Elements::InputScriptSigsHash, Elements::InputScriptsHash, Elements::InputSequencesHash, Elements::InputUtxoHash, Elements::InputUtxosHash, Elements::InputsHash, Elements::IssuanceAssetAmountsHash, Elements::IssuanceBlindingEntropyHash, Elements::IssuanceHash, Elements::IssuanceRangeProofsHash, Elements::IssuanceTokenAmountsHash, Elements::IssuancesHash, Elements::NonceHash, Elements::OutpointHash, Elements::OutputAmountsHash, Elements::OutputHash, Elements::OutputNoncesHash, Elements::OutputRangeProofsHash, Elements::OutputScriptsHash, Elements::OutputSurjectionProofsHash, Elements::OutputsHash, Elements::SigAllHash, Elements::TapEnvHash, Elements::TapleafHash, Elements::TappathHash, Elements::TxHash ]; #[rustfmt::skip] const TIME_LOCKS: [Elements; 9] = [ diff --git a/flake.nix b/flake.nix index 6a2d429..8840745 100644 --- a/flake.nix +++ b/flake.nix @@ -39,6 +39,7 @@ defaultRust pkgs.just pkgs.gdb + pkgs.cargo-hack ] ++ ( if with_elements then [ elementsd-simplicity ] else [] ); @@ -57,11 +58,12 @@ buildInputs = [ (mkRust "stable" "latest" "default" []) pkgs.just + pkgs.cargo-hack ]; }; msrv = pkgs.mkShell { buildInputs = [ - (mkRust "stable" "1.61.0" "minimal" []) + (mkRust "stable" "1.63.0" "minimal" []) pkgs.just ]; }; diff --git a/justfile b/justfile index 3fac561..4b37a21 100644 --- a/justfile +++ b/justfile @@ -10,6 +10,10 @@ fmtcheck: lint: cargo clippy --all-targets --workspace -- --deny warnings +# Build code with all feature combinations +build_features: + cargo hack check --feature-powerset --no-dev-deps + # Run unit tests test: cargo test --workspace @@ -20,6 +24,7 @@ check: rustc --version just fmtcheck just lint + just build_features just test # Run fuzz test for 30 seconds diff --git a/src/ast.rs b/src/ast.rs index 32a1aec..8d97a8f 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -20,7 +20,7 @@ use crate::value::{UIntValue, Value}; use crate::{impl_eq_hash, parse}; /// Map of witness names to their expected type, as declared in the program. -#[derive(Clone, Debug, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq, Default)] pub struct DeclaredWitnesses(HashMap); impl DeclaredWitnesses { diff --git a/src/jet.rs b/src/jet.rs index f088815..cf6a1fc 100644 --- a/src/jet.rs +++ b/src/jet.rs @@ -404,6 +404,7 @@ pub fn source_type(jet: Elements) -> Vec { /* * Bitcoin (without primitives) */ + Elements::TapdataInit => vec![], Elements::ParseLock | Elements::ParseSequence => vec![U32.into()], /* * ============================== @@ -444,6 +445,7 @@ pub fn source_type(jet: Elements) -> Vec { Elements::AnnexHash => vec![Ctx8.into(), option(U256)], Elements::BuildTapleafSimplicity => vec![U256.into()], Elements::BuildTapbranch => vec![U256.into(), U256.into()], + Elements::BuildTaptweak => vec![Pubkey.into(), U256.into()], /* * Time locks */ @@ -911,6 +913,7 @@ pub fn target_type(jet: Elements) -> AliasedType { */ Elements::ParseLock => either(Height, Time), Elements::ParseSequence => option(either(Distance, Duration)), + Elements::TapdataInit => Ctx8.into(), /* * ============================== * Elements jets @@ -943,7 +946,8 @@ pub fn target_type(jet: Elements) -> AliasedType { | Elements::TapleafHash | Elements::TappathHash | Elements::BuildTapleafSimplicity - | Elements::BuildTapbranch => U256.into(), + | Elements::BuildTapbranch + | Elements::BuildTaptweak => U256.into(), Elements::OutpointHash | Elements::AssetAmountHash | Elements::NonceHash diff --git a/src/lib.rs b/src/lib.rs index 30fd4d5..b33c76e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -39,6 +39,17 @@ pub struct CompiledProgram { debug_symbols: DebugSymbols, } +impl Default for CompiledProgram { + fn default() -> Self { + use simplicity::node::CoreConstructible; + Self { + simplicity: ProgNode::unit(&simplicity::types::Context::new()), + witness_types: DeclaredWitnesses::default(), + debug_symbols: DebugSymbols::default(), + } + } +} + impl CompiledProgram { /// Parse and compile a Simfony program from the given string. /// diff --git a/src/value.rs b/src/value.rs index b30e9fc..26b9191 100644 --- a/src/value.rs +++ b/src/value.rs @@ -58,8 +58,8 @@ impl fmt::Display for UIntValue { UIntValue::U16(n) => ::fmt(n, f), UIntValue::U32(n) => ::fmt(n, f), UIntValue::U64(n) => ::fmt(n, f), - UIntValue::U128(n) => write!(f, "{}", n.to_be_bytes().as_hex()), - UIntValue::U256(n) => write!(f, "{}", n.as_ref().as_hex()), + UIntValue::U128(n) => write!(f, "0x{}", n.to_be_bytes().as_hex()), + UIntValue::U256(n) => write!(f, "0x{}", n.as_ref().as_hex()), } } }