Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ jobs:
c_rust_merkle,
decode_natural,
decode_program,
parse_compile,
]
steps:
- name: Install test dependencies
Expand Down
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ edition = "2018"
[features]
default = [ "bitcoin", "elements" ]
test-utils = ["simplicity-sys/test-utils"]
serde = ["actual-serde", "bitcoin/serde", "elements-miniscript/serde"]
serde = ["actual-serde", "bitcoin/serde", "elements/serde"]

[lib]
name = "simplicity"
Expand All @@ -19,7 +19,6 @@ path = "src/lib.rs"
bitcoin = { version = "0.30.0", optional = true }
byteorder = "1.3"
elements = { version = "0.22.0", optional = true }
elements-miniscript = "0.2.0"
hashes = { package = "bitcoin_hashes", version = "0.12" }
hex = { package = "hex-conservative", version = "0.1.1" }
simplicity-sys = { version = "0.1.0", path = "./simplicity-sys" }
Expand Down
4 changes: 0 additions & 4 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,3 @@ path = "fuzz_targets/decode_natural.rs"
[[bin]]
name = "decode_program"
path = "fuzz_targets/decode_program.rs"

[[bin]]
name = "parse_compile"
path = "fuzz_targets/parse_compile.rs"
66 changes: 0 additions & 66 deletions fuzz/fuzz_targets/parse_compile.rs

This file was deleted.

4 changes: 2 additions & 2 deletions fuzz/generate-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ honggfuzz = { version = "0.5.55", default-features = false }
simplicity = { path = ".." }

[patch.crates-io.bitcoin_hashes]
git = "https://github.com/apoelstra/bitcoin_hashes"
branch = "2023-04--fuzzcfg"
git = "https://github.com/apoelstra/rust-bitcoin"
tag = "2023-07--0.30.1-with-fuzzcfg"
EOF

for targetFile in $(listTargetFiles); do
Expand Down
16 changes: 1 addition & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@ pub extern crate elements;

/// Re-export of byteorder crate
pub extern crate byteorder;
/// Re-export of elements_miniscript crate
pub extern crate elements_miniscript;
/// Re-export of hashes crate
pub extern crate hashes;
/// Re-export of hex crate
pub extern crate hex;

use elements_miniscript as miniscript;

#[macro_use]
mod macros;

Expand All @@ -59,7 +55,7 @@ pub use bit_encoding::BitWriter;
pub use bit_encoding::{BitIter, EarlyEndOfStreamError};

#[cfg(feature = "elements")]
pub use crate::policy::{Descriptor, Policy};
pub use crate::policy::{Policy, SimplicityKey, ToXOnlyPubkey, Translator};

pub use crate::bit_machine::BitMachine;
pub use crate::encode::{encode_natural, encode_value, encode_witness};
Expand Down Expand Up @@ -95,8 +91,6 @@ pub enum Error {
InconsistentWitnessLength,
/// Tried to parse a jet but the name wasn't recognized
InvalidJetName(String),
/// Miniscript error
MiniscriptError(miniscript::Error),
/// Policy error
#[cfg(feature = "elements")]
Policy(policy::Error),
Expand All @@ -119,7 +113,6 @@ impl fmt::Display for Error {
}
Error::InvalidJetName(s) => write!(f, "unknown jet `{}`", s),
Error::NoMoreWitnesses => f.write_str("no more witness data available"),
Error::MiniscriptError(ref e) => fmt::Display::fmt(e, f),
#[cfg(feature = "elements")]
Error::Policy(ref e) => fmt::Display::fmt(e, f),
}
Expand All @@ -137,7 +130,6 @@ impl std::error::Error for Error {
Error::IncompleteFinalization => None,
Error::InconsistentWitnessLength => None,
Error::InvalidJetName(..) => None,
Error::MiniscriptError(ref e) => Some(e),
#[cfg(feature = "elements")]
Error::Policy(ref e) => Some(e),
}
Expand All @@ -162,12 +154,6 @@ impl From<crate::types::Error> for Error {
}
}

impl From<miniscript::Error> for Error {
fn from(e: miniscript::Error) -> Error {
Error::MiniscriptError(e)
}
}

#[cfg(feature = "elements")]
impl From<policy::Error> for Error {
fn from(e: policy::Error) -> Error {
Expand Down
102 changes: 0 additions & 102 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,105 +14,3 @@ macro_rules! decode_bits {
}
};
}

/// Copied from rust-miniscript
///
/// A macro that implements serde serialization and deserialization using the
/// `fmt::Display` and `str::FromStr` traits.
#[cfg(feature = "elements")]
macro_rules! serde_string_impl_pk {
($name:ident, $expecting:expr $(, $gen:ident; $gen_con:ident)*) => {
#[cfg(feature = "serde")]
impl<'de, Pk $(, $gen)*> $crate::serde::Deserialize<'de> for $name<Pk $(, $gen)*>
where
Pk: crate::miniscript::ToPublicKey + core::str::FromStr,
Pk::Sha256: core::str::FromStr,
Pk::Hash256: core::str::FromStr,
Pk::Ripemd160: core::str::FromStr,
Pk::Hash160: core::str::FromStr,
<Pk as core::str::FromStr>::Err: core::fmt::Display,
<<Pk as crate::miniscript::MiniscriptKey>::Sha256 as core::str::FromStr>::Err:
core::fmt::Display,
<<Pk as crate::miniscript::MiniscriptKey>::Hash256 as core::str::FromStr>::Err:
core::fmt::Display,
<<Pk as crate::miniscript::MiniscriptKey>::Ripemd160 as core::str::FromStr>::Err:
core::fmt::Display,
<<Pk as crate::miniscript::MiniscriptKey>::Hash160 as core::str::FromStr>::Err:
core::fmt::Display,
$($gen : $gen_con,)*
{
fn deserialize<D>(deserializer: D) -> Result<$name<Pk $(, $gen)*>, D::Error>
where
D: $crate::serde::de::Deserializer<'de>,
{
use core::fmt::{self, Formatter};
use core::marker::PhantomData;
use core::str::FromStr;

#[allow(unused_parens)]
struct Visitor<Pk $(, $gen)*>(PhantomData<(Pk $(, $gen)*)>);
impl<'de, Pk $(, $gen)*> $crate::serde::de::Visitor<'de> for Visitor<Pk $(, $gen)*>
where
Pk: crate::miniscript::ToPublicKey + core::str::FromStr,
Pk::Sha256: core::str::FromStr,
Pk::Hash256: core::str::FromStr,
Pk::Ripemd160: core::str::FromStr,
Pk::Hash160: core::str::FromStr,
<Pk as core::str::FromStr>::Err: core::fmt::Display,
<<Pk as crate::miniscript::MiniscriptKey>::Sha256 as core::str::FromStr>::Err:
core::fmt::Display,
<<Pk as crate::miniscript::MiniscriptKey>::Hash256 as core::str::FromStr>::Err:
core::fmt::Display,
<<Pk as crate::miniscript::MiniscriptKey>::Ripemd160 as core::str::FromStr>::Err:
core::fmt::Display,
<<Pk as crate::miniscript::MiniscriptKey>::Hash160 as core::str::FromStr>::Err:
core::fmt::Display,
$($gen: $gen_con,)*
{
type Value = $name<Pk $(, $gen)*>;

fn expecting(&self, formatter: &mut Formatter) -> fmt::Result {
formatter.write_str($expecting)
}

fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
where
E: $crate::serde::de::Error,
{
$name::from_str(v).map_err(E::custom)
}

fn visit_borrowed_str<E>(self, v: &'de str) -> Result<Self::Value, E>
where
E: $crate::serde::de::Error,
{
self.visit_str(v)
}

fn visit_string<E>(self, v: String) -> Result<Self::Value, E>
where
E: $crate::serde::de::Error,
{
self.visit_str(&v)
}
}

deserializer.deserialize_str(Visitor(PhantomData))
}
}

#[cfg(feature = "serde")]
impl<'de, Pk $(, $gen)*> $crate::serde::Serialize for $name<Pk $(, $gen)*>
where
Pk: crate::miniscript::ToPublicKey,
$($gen: $gen_con,)*
{
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: $crate::serde::Serializer,
{
serializer.collect_str(&self)
}
}
};
}
14 changes: 7 additions & 7 deletions src/policy/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ use std::sync::Arc;
use std::{fmt, iter, mem};

use crate::jet::Elements;
use crate::miniscript::{MiniscriptKey, ToPublicKey, Translator};
use crate::node::{ConstructNode, NoWitness};
use crate::FailEntropy;
use crate::{SimplicityKey, ToXOnlyPubkey, Translator};

use super::serialize;

Expand All @@ -38,7 +38,7 @@ use super::serialize;
///
/// Furthermore, the policy can be normalized and is amenable to semantic analysis.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
pub enum Policy<Pk: MiniscriptKey> {
pub enum Policy<Pk: SimplicityKey> {
/// Unsatisfiable
Unsatisfiable(FailEntropy),
/// Trivially satisfiable
Expand All @@ -65,11 +65,11 @@ pub enum Policy<Pk: MiniscriptKey> {
Threshold(usize, Vec<Policy<Pk>>),
}

impl<Pk: MiniscriptKey> Policy<Pk> {
impl<Pk: SimplicityKey> Policy<Pk> {
/// Serializes the policy as a Simplicity fragment, with all witness nodes unpopulated.
pub fn serialize_no_witness(&self) -> Arc<ConstructNode<Elements>>
where
Pk: ToPublicKey,
Pk: ToXOnlyPubkey,
{
match *self {
Policy::Unsatisfiable(entropy) => serialize::unsatisfiable(entropy),
Expand Down Expand Up @@ -112,7 +112,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
pub fn translate<T, Q, E>(&self, translator: &mut T) -> Result<Policy<Q>, E>
where
T: Translator<Pk, Q, E>,
Q: MiniscriptKey,
Q: SimplicityKey,
{
match *self {
Policy::Unsatisfiable(entropy) => Ok(Policy::Unsatisfiable(entropy)),
Expand Down Expand Up @@ -217,7 +217,7 @@ impl<Pk: MiniscriptKey> Policy<Pk> {
}
}

impl<Pk: MiniscriptKey> fmt::Debug for Policy<Pk> {
impl<Pk: SimplicityKey> fmt::Debug for Policy<Pk> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Policy::Unsatisfiable(..) => f.write_str("UNSATISFIABLE"),
Expand All @@ -239,7 +239,7 @@ impl<Pk: MiniscriptKey> fmt::Debug for Policy<Pk> {
}
}

impl<Pk: MiniscriptKey> fmt::Display for Policy<Pk> {
impl<Pk: SimplicityKey> fmt::Display for Policy<Pk> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(self, f)
}
Expand Down
Loading