Skip to content

Commit 5458e7c

Browse files
committed
Merge ElementsProject#30: revamp Extension and ExtParam traits
a08a03c msrv fixes (Andrew Poelstra) 9bd330e run cargo fmt (Andrew Poelstra) 928bf29 descriptor: make (almost) all methods generic over the extension type (Andrew Poelstra) 9a4a5a0 rename Transalator to Translator (Andrew Poelstra) a730990 refactor `Descriptor` to be parameterized by Extension, not ExtParam (Andrew Poelstra) 3c64411 extension: introduce TranslateExtParam trait (Andrew Poelstra) dd1a688 remove some no-op covenant conversions (Andrew Poelstra) b3e88cd [MOVE ONLY] covenants: move ExtParams to its own module (Andrew Poelstra) Pull request description: The existing code made `Descriptor` generic over `ExtParam` rather than `Extension`. This made the `Extension` trati basically useless since every `Descriptor` always had `CovenantExt` as its extension type. It also caused me a lot of confusion because I tried to call the `address` method on a `Descriptor<Pk, NoExt>`, which I was able to parse, just not call any methods on. I pulled on this string and 1000 lines later here we are. ACKs for top commit: sanket1729: code review ACK a08a03c. I am attempting to write an extension for Any prevout and APOAS (any prevout any script) just to see what a downstream implementation of an Extension might look like. Tree-SHA512: ff15cde3f84606286af0b3ff504fe6b306789d5a95e50b964a3f62c44d70bb9247520fa870b242cbdeab15760a69d998976be85932def074073672601127f822
2 parents 240b0c5 + a08a03c commit 5458e7c

30 files changed

+495
-571
lines changed

contrib/test.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ set -e
44

55
FEATURES="compiler use-serde rand"
66

7-
# Use toolchain if explicitly specified
8-
if [ -n "$TOOLCHAIN" ]
9-
then
10-
alias cargo="cargo +$TOOLCHAIN"
11-
fi
12-
137
cargo --version
148
rustc --version
159

10+
MSRV=false
11+
if cargo --version | grep "1\.41\.0"; then
12+
MSRV=true
13+
fi
14+
15+
if [ "$MSRV" = true ]; then
16+
cargo update -p url --precise 2.2.2
17+
cargo update -p form_urlencoded --precise 1.0.1
18+
cargo update -p once_cell --precise 1.13.1
19+
fi
20+
1621
# Format if told to
1722
if [ "$DO_FMT" = true ]
1823
then

fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ afl_fuzz = ["afl"]
1212
honggfuzz_fuzz = ["honggfuzz"]
1313

1414
[dependencies]
15-
honggfuzz = { version = "0.5", optional = true }
15+
honggfuzz = { version = "0.5", optional = true, default-features = false }
1616
afl = { version = "0.8", optional = true }
1717
regex = { version = "1.4"}
1818
elements-miniscript = { path = "..", features = ["compiler"] }

fuzz/travis-fuzz.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22
set -e
3-
cargo install --force honggfuzz
3+
cargo install --force honggfuzz --no-default-features
44
for TARGET in fuzz_targets/*; do
55
FILENAME=$(basename $TARGET)
66
FILE="${FILENAME%.*}"

src/descriptor/bare.rs

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ use elements::{self, script, secp256k1_zkp, Script};
2525
use super::checksum::{desc_checksum, verify_checksum};
2626
use super::ELMTS_STR;
2727
use crate::expression::{self, FromTree};
28-
use crate::extensions::ExtParam;
2928
use crate::miniscript::context::ScriptContext;
3029
use crate::policy::{semantic, Liftable};
3130
use crate::util::{varint_len, witness_to_scriptsig};
3231
use crate::{
33-
elementssig_to_rawsig, BareCtx, Error, Extension, ForEach, ForEachKey, Miniscript,
34-
MiniscriptKey, Satisfier, ToPublicKey, TranslateExt, TranslatePk, Translator,
32+
elementssig_to_rawsig, BareCtx, Error, ForEach, ForEachKey, Miniscript, MiniscriptKey,
33+
Satisfier, ToPublicKey, TranslatePk, Translator,
3534
};
3635

3736
/// Create a Bare Descriptor. That is descriptor that is
@@ -193,24 +192,6 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Bare<P> {
193192
}
194193
}
195194

196-
impl<PExt, QExt, PArg, QArg, Pk> TranslateExt<PExt, QExt, PArg, QArg> for Bare<Pk>
197-
where
198-
PExt: Extension,
199-
QExt: Extension,
200-
PArg: ExtParam,
201-
QArg: ExtParam,
202-
Pk: MiniscriptKey,
203-
{
204-
type Output = Bare<Pk>;
205-
206-
fn translate_ext<T, E>(&self, _translator: &mut T) -> Result<Self::Output, E>
207-
where
208-
T: crate::ExtTranslator<PArg, QArg, E>,
209-
{
210-
Ok(self.clone())
211-
}
212-
}
213-
214195
/// A bare PkH descriptor at top level
215196
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
216197
pub struct Pkh<Pk: MiniscriptKey> {
@@ -376,21 +357,3 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Pkh<P> {
376357
Ok(Pkh::new(t.pk(&self.pk)?))
377358
}
378359
}
379-
380-
impl<PExt, QExt, PArg, QArg, Pk> TranslateExt<PExt, QExt, PArg, QArg> for Pkh<Pk>
381-
where
382-
PExt: Extension,
383-
QExt: Extension,
384-
PArg: ExtParam,
385-
QArg: ExtParam,
386-
Pk: MiniscriptKey,
387-
{
388-
type Output = Pkh<Pk>;
389-
390-
fn translate_ext<T, E>(&self, _translator: &mut T) -> Result<Self::Output, E>
391-
where
392-
T: crate::ExtTranslator<PArg, QArg, E>,
393-
{
394-
Ok(self.clone())
395-
}
396-
}

src/descriptor/blinded.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use elements::{self, Script};
2525
use super::checksum::{desc_checksum, strip_checksum, verify_checksum};
2626
use super::{Descriptor, TranslatePk};
2727
use crate::expression::{self, FromTree};
28-
use crate::extensions::CovExtArgs;
28+
use crate::extensions::{CovExtArgs, CovenantExt};
2929
use crate::policy::{semantic, Liftable};
3030
use crate::{Error, MiniscriptKey, Satisfier, ToPublicKey, Translator};
3131

@@ -40,12 +40,12 @@ pub struct Blinded<Pk: MiniscriptKey> {
4040
/// permitted at the root level.
4141
///
4242
/// TODO: Add blinding support to descriptor extensions
43-
desc: Descriptor<Pk, CovExtArgs>,
43+
desc: Descriptor<Pk, CovenantExt<CovExtArgs>>,
4444
}
4545

4646
impl<Pk: MiniscriptKey> Blinded<Pk> {
4747
/// Create a new blinded descriptor from a descriptor and blinder
48-
pub fn new(blinder: Pk, desc: Descriptor<Pk, CovExtArgs>) -> Self {
48+
pub fn new(blinder: Pk, desc: Descriptor<Pk, CovenantExt<CovExtArgs>>) -> Self {
4949
Self { blinder, desc }
5050
}
5151

@@ -55,12 +55,12 @@ impl<Pk: MiniscriptKey> Blinded<Pk> {
5555
}
5656

5757
/// get the unblinded descriptor
58-
pub fn as_unblinded(&self) -> &Descriptor<Pk, CovExtArgs> {
58+
pub fn as_unblinded(&self) -> &Descriptor<Pk, CovenantExt<CovExtArgs>> {
5959
&self.desc
6060
}
6161

6262
/// get the unblinded descriptor
63-
pub fn into_unblinded(self) -> Descriptor<Pk, CovExtArgs> {
63+
pub fn into_unblinded(self) -> Descriptor<Pk, CovenantExt<CovExtArgs>> {
6464
self.desc
6565
}
6666
}
@@ -92,7 +92,7 @@ impl_from_tree!(
9292
fn from_tree(top: &expression::Tree<'_>) -> Result<Self, Error> {
9393
if top.name == "blinded" && top.args.len() == 2 {
9494
let blinder = expression::terminal(&top.args[0], |pk| Pk::from_str(pk))?;
95-
let desc = Descriptor::<Pk, CovExtArgs>::from_tree(&top.args[1])?;
95+
let desc = Descriptor::<Pk, CovenantExt<CovExtArgs>>::from_tree(&top.args[1])?;
9696
if top.args[1].name == "blinded" {
9797
return Err(Error::BadDescriptor(
9898
"Blinding only permitted at root level".to_string(),

src/descriptor/csfs_cov/cov.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ use super::super::checksum::{desc_checksum, verify_checksum};
5151
use super::super::ELMTS_STR;
5252
use super::{CovError, CovOperations};
5353
use crate::expression::{self, FromTree};
54-
use crate::extensions::{ExtParam, ParseableExt};
54+
use crate::extensions::ParseableExt;
5555
use crate::miniscript::lex::{lex, Token as Tk, TokenIter};
5656
use crate::miniscript::limits::{
5757
MAX_OPS_PER_SCRIPT, MAX_SCRIPT_SIZE, MAX_STANDARD_P2WSH_SCRIPT_SIZE,
@@ -485,20 +485,18 @@ where
485485
}
486486
}
487487

488-
impl<Pk, Ext, ExtQ, PArg, QArg> TranslateExt<Ext, ExtQ, PArg, QArg> for LegacyCSFSCov<Pk, Ext>
488+
impl<Pk, Ext, ExtQ> TranslateExt<Ext, ExtQ> for LegacyCSFSCov<Pk, Ext>
489489
where
490490
Pk: MiniscriptKey,
491491
Ext: Extension,
492492
ExtQ: Extension,
493-
Ext: TranslateExt<Ext, ExtQ, PArg, QArg, Output = ExtQ>,
494-
PArg: ExtParam,
495-
QArg: ExtParam,
493+
Ext: TranslateExt<Ext, ExtQ, Output = ExtQ>,
496494
{
497495
type Output = LegacyCSFSCov<Pk, ExtQ>;
498496

499497
fn translate_ext<T, E>(&self, translator: &mut T) -> Result<Self::Output, E>
500498
where
501-
T: ExtTranslator<PArg, QArg, E>,
499+
T: ExtTranslator<Ext, ExtQ, E>,
502500
{
503501
Ok(LegacyCSFSCov {
504502
pk: self.pk.clone(),

src/descriptor/csfs_cov/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ mod tests {
182182
}
183183

184184
fn _satisfy_and_interpret(
185-
desc: Descriptor<bitcoin::PublicKey, CovExtArgs>,
185+
desc: Descriptor<bitcoin::PublicKey, CovenantExt<CovExtArgs>>,
186186
cov_sk: secp256k1_zkp::SecretKey,
187187
) -> Result<(), Error> {
188188
assert_eq!(desc.desc_type(), DescriptorType::Cov);

0 commit comments

Comments
 (0)