Skip to content

Commit

Permalink
Merge #90: Update simplicity
Browse files Browse the repository at this point in the history
d2f77b5 feat: Add default CompiledProgram (Christian Lewe)
976c6c4 test: Build code with all feature combinations (Christian Lewe)
444ac2c fix: Print hex values with leading 0x (Christian Lewe)
3ffe26c fix: Run fuzzer CI after stable tests (Christian Lewe)
c8000ce chore: Update simplicity (Christian Lewe)
46b8fd1 chore: Bump MSRV to 1.63.0 (Christian Lewe)

Pull request description:

  Bump the MSRV, update rust-simplicity and add some new CI. ~~Add the foundations for enabling codecov for the repo.~~

ACKs for top commit:
  apoelstra:
    ACK d2f77b5 successfully ran local tests

Tree-SHA512: b2cb878adbfa2070458272ded561095fad301d177c19942d8ae37b7b3fbc3b7c63da22e25519b33465a75925ef7845a587bdebe1cea6dcf0304c55b3075d2568
  • Loading branch information
apoelstra committed Sep 28, 2024
2 parents 18f98dc + d2f77b5 commit 40a9c32
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 18 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ jobs:
test-fuzz:
name: Test - fuzzer
runs-on: ubuntu-latest
needs: test-stable

steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions bitcoind-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.61.0"
msrv = "1.63.0"
2 changes: 1 addition & 1 deletion codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 13 additions & 4 deletions codegen/src/jet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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`.
Expand Down Expand Up @@ -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] = [
Expand Down
4 changes: 3 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
defaultRust
pkgs.just
pkgs.gdb
pkgs.cargo-hack
] ++ (
if with_elements then [ elementsd-simplicity ] else []
);
Expand All @@ -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
];
};
Expand Down
5 changes: 5 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,6 +24,7 @@ check:
rustc --version
just fmtcheck
just lint
just build_features
just test

# Run fuzz test for 30 seconds
Expand Down
2 changes: 1 addition & 1 deletion src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WitnessName, ResolvedType>);

impl DeclaredWitnesses {
Expand Down
6 changes: 5 additions & 1 deletion src/jet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ pub fn source_type(jet: Elements) -> Vec<AliasedType> {
/*
* Bitcoin (without primitives)
*/
Elements::TapdataInit => vec![],
Elements::ParseLock | Elements::ParseSequence => vec![U32.into()],
/*
* ==============================
Expand Down Expand Up @@ -444,6 +445,7 @@ pub fn source_type(jet: Elements) -> Vec<AliasedType> {
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
*/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
4 changes: 2 additions & 2 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ impl fmt::Display for UIntValue {
UIntValue::U16(n) => <u16 as fmt::Display>::fmt(n, f),
UIntValue::U32(n) => <u32 as fmt::Display>::fmt(n, f),
UIntValue::U64(n) => <u64 as fmt::Display>::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()),
}
}
}
Expand Down

0 comments on commit 40a9c32

Please sign in to comment.