Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bitcoin: bump 0.28.0 -> 0.29.1 #147

Merged
merged 5 commits into from Oct 4, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Expand Up @@ -22,7 +22,7 @@ jobs:
- rust: nightly
env:
DUMMY: true
- rust: 1.36.0
- rust: 1.41.1
env:
PIN_VERSIONS: true
steps:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,12 @@
# unreleased

- the feature "serde-feature" is now renamed to just "serde"
- update MSRV to 1.41.1
- breaking change in serde in how the Nonce is serialized
- `Block`, `BlockHeader`, `PeginData`, `PegoutData` loose the Default impl
- update rust-bitcoin to 0.29.1
- update secp256k1-zkp to 0.7.0
- update bitcoin_hases to 0.11.0

# 0.19.2 - 2022-06-16

Expand Down
20 changes: 10 additions & 10 deletions Cargo.toml
Expand Up @@ -14,37 +14,37 @@ default = [ "json-contract" ]
integration = [ "elementsd" ]

json-contract = [ "serde_json" ]
"serde-feature" = [
"bitcoin/use-serde",
"serde" = [
"bitcoin/serde",
"secp256k1-zkp/use-serde",
"serde"
"actual-serde"
]
"fuzztarget" = []

[dependencies]
bitcoin = "0.28.0"
secp256k1-zkp = { version = "0.6.0", features = [ "global-context", "bitcoin_hashes" ] }
bitcoin = "0.29.1"
secp256k1-zkp = { version = "0.7.0", features = [ "global-context", "bitcoin_hashes" ] }
slip21 = "0.2.0"

# While this dependency is included in bitcoin, we need this to use the macros.
# We should probably try keep this one in sync with the bitcoin version,
# to avoid requiring two version of bitcoin_hashes.
bitcoin_hashes = "0.10.0"
bitcoin_hashes = "0.11.0"

# Used for ContractHash::from_json_contract.
serde_json = { version = "1.0", optional = true }

serde = { version = "1.0", features=["derive"], optional = true }
actual-serde = { package="serde", version = "1.0", features=["derive"], optional = true }

# This should be an optional dev-dependency (only needed for integration tests),
# but dev-dependency cannot be optional, and without optionality older toolchain try to compile it and fails
elementsd = {version = "0.5.0", features=["0_21_0","bitcoind_22_0"], optional = true }
elementsd = {version = "0.6.0", features=["0_21_0","bitcoind_22_0"], optional = true }

[dev-dependencies]
rand = "0.6.5"
rand = "0.8"
serde_test = "1.0"
serde_json = "1.0"
serde_cbor = "0.8" # older than latest version to support 1.36
serde_cbor = "0.8" # older than latest version to support 1.41.1
ryu = "<1.0.5"
bincode = "1.3"
base64 = "0.13.0"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -10,4 +10,4 @@ structures and network messages related to Elements

## Minimum Supported Rust Version (MSRV)

This library should always compile with any combination of features on **Rust 1.36**.
This library should always compile with any combination of features on **Rust 1.41.1**.
2 changes: 1 addition & 1 deletion contrib/test.sh
@@ -1,6 +1,6 @@
#!/bin/sh -ex

FEATURES="serde-feature"
FEATURES="serde"

# Use toolchain if explicitly specified
if [ -n "$TOOLCHAIN" ]
Expand Down
4 changes: 2 additions & 2 deletions examples/pset_blind_coinjoin.rs
Expand Up @@ -72,7 +72,7 @@ fn parse_txout(txout_info: &str) -> (TxOut, Secrets, pset::Input) {
bitcoin::Denomination::Bitcoin,
)
.unwrap()
.as_sat(),
.to_sat(),
asset: AssetId::from_hex(&v["asset"].as_str().unwrap()).unwrap(),
},
};
Expand Down Expand Up @@ -324,4 +324,4 @@ impl rand::RngCore for CrappyRng {
}
}

impl rand::CryptoRng for CrappyRng {}
impl rand::CryptoRng for CrappyRng {}
2 changes: 1 addition & 1 deletion examples/raw_blind.rs
Expand Up @@ -68,7 +68,7 @@ fn parse_txout(txout_info: &str) -> (TxOut, Secrets, pset::Input) {
bitcoin::Denomination::Bitcoin,
)
.unwrap()
.as_sat(),
.to_sat(),
asset: AssetId::from_hex(&v["asset"].as_str().unwrap()).unwrap(),
},
};
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Expand Up @@ -15,7 +15,7 @@ honggfuzz_fuzz = ["honggfuzz"]
[dependencies]
honggfuzz = { version = "0.5", optional = true, default-features = false }
afl = { version = "0.11", optional = true }
elements = { path = "..", features = ["fuzztarget", "serde-feature"] }
elements = { path = "..", features = ["fuzztarget", "serde"] }

# Prevent this from interfering with workspaces
[workspace]
Expand Down
4 changes: 2 additions & 2 deletions src/blind.rs
Expand Up @@ -210,7 +210,7 @@ impl RangeProofMessage {
}

/// Information about Transaction Input Asset
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "actual_serde"))]
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
pub struct TxOutSecrets {
/// Asset
Expand Down Expand Up @@ -1008,7 +1008,7 @@ mod tests {
let spent_utxo_secrets = TxOutSecrets {
asset: AssetId::from_hex("b2e15d0d7a0c94e4e2ce0fe6e8691b9e451377f6e46e8045a86f7c4b5d4f0f23").unwrap(),
asset_bf: AssetBlindingFactor::from_hex("a5b3d111cdaa5fc111e2723df4caf315864f25fb4610cc737f10d5a55cd4096f").unwrap(),
value: bitcoin::Amount::from_str_in("20999997.97999114", bitcoin::Denomination::Bitcoin).unwrap().as_sat(),
value: bitcoin::Amount::from_str_in("20999997.97999114", bitcoin::Denomination::Bitcoin).unwrap().to_sat(),
value_bf: ValueBlindingFactor::from_hex("e36a4de359469f547571d117bc5509fb74fba73c84b0cdd6f4edfa7ff7fa457d").unwrap(),
};

Expand Down
4 changes: 2 additions & 2 deletions src/block.rs
Expand Up @@ -202,7 +202,7 @@ impl Default for ExtData {
}

/// Elements block header
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct BlockHeader {
/// Version - should be 0x20000000 except when versionbits signalling
pub version: u32,
Expand Down Expand Up @@ -355,7 +355,7 @@ impl Decodable for BlockHeader {
}

/// Elements block
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct Block {
/// Header of the block
pub header: BlockHeader,
Expand Down
30 changes: 16 additions & 14 deletions src/confidential.rs
Expand Up @@ -957,14 +957,13 @@ impl AddAssign for ValueBlindingFactor {
// for scalar arethematic, we need to abuse secret key
// operations for this
let sk2 = SecretKey::from_slice(self.into_inner().as_ref()).expect("Valid key");
let mut sk = SecretKey::from_slice(other.into_inner().as_ref()).expect("Valid key");
let sk = SecretKey::from_slice(other.into_inner().as_ref()).expect("Valid key");
// The only reason that secret key addition can fail
// is when the keys add up to zero since we have already checked
// keys are in valid secret keys
if sk.add_assign(sk2.as_ref()).is_err() {
*self = Self::zero();
} else {
*self = ValueBlindingFactor::from_slice(sk.as_ref()).expect("Valid Tweak")
match sk.add_tweak(&sk2.into()) {
Ok(sk_tweaked) => *self = ValueBlindingFactor::from_slice(sk_tweaked.as_ref()).expect("Valid Tweak"),
Err(_) => *self = Self::zero(),
}
}
}
Expand All @@ -977,8 +976,7 @@ impl Neg for ValueBlindingFactor {
if self.0.as_ref() == &[0u8; 32] {
self
} else {
let mut sk = SecretKey::from_slice(self.into_inner().as_ref()).expect("Valid key");
sk.negate_assign();
let sk = SecretKey::from_slice(self.into_inner().as_ref()).expect("Valid key").negate();
ValueBlindingFactor::from_slice(sk.as_ref()).expect("Valid Tweak")
}
}
Expand Down Expand Up @@ -1374,13 +1372,17 @@ mod tests {
&[
Token::Seq { len: Some(2) },
Token::U8(2),
Token::Bytes(
&[
2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
]
),
Token::Tuple { len: 33 },
Token::U8(2), Token::U8(1), Token::U8(1), Token::U8(1),
Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1),
Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1),
Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1),
Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1),
Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1),
Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1),
Token::U8(1), Token::U8(1), Token::U8(1), Token::U8(1),
Token::U8(1),
Token::TupleEnd,
Token::SeqEnd
]
);
Expand Down
8 changes: 7 additions & 1 deletion src/dynafed.rs
Expand Up @@ -590,6 +590,8 @@ mod tests {
use bitcoin::hashes::hex::ToHex;
use bitcoin::hashes::sha256;

use crate::{BlockHash, TxMerkleNode};

use super::*;

#[test]
Expand Down Expand Up @@ -655,7 +657,11 @@ mod tests {
proposed: full_entry,
signblock_witness: vec![],
},
..Default::default()
version: Default::default(),
prev_blockhash: BlockHash::all_zeros(),
merkle_root: TxMerkleNode::all_zeros(),
time: Default::default(),
height: Default::default(),
};
assert_eq!(
header.calculate_dynafed_params_root().unwrap().to_hex(),
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -30,7 +30,7 @@ pub extern crate bitcoin;
extern crate bitcoin_hashes as just_imported_for_the_macros;
extern crate slip21;
pub extern crate secp256k1_zkp;
#[cfg(feature = "serde")] #[macro_use] extern crate serde;
#[cfg(feature = "serde")] #[macro_use] extern crate actual_serde as serde;
#[cfg(all(test, feature = "serde"))] extern crate serde_test;

#[cfg(test)] extern crate rand;
Expand Down
4 changes: 2 additions & 2 deletions src/pset/map/global.rs
Expand Up @@ -56,7 +56,7 @@ const PSBT_ELEMENTS_GLOBAL_TX_MODIFIABLE: u8 = 0x01;

/// Global transaction data
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "actual_serde"))]
pub struct TxData {
/// Transaction version. Must be 2.
pub version: u32,
Expand Down Expand Up @@ -91,7 +91,7 @@ impl Default for TxData{

/// A key-value map for global data.
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "actual_serde"))]
pub struct Global {
/// Global transaction data
#[cfg_attr(feature = "serde", serde(flatten))]
Expand Down
11 changes: 9 additions & 2 deletions src/pset/map/input.rs
Expand Up @@ -24,6 +24,7 @@ use crate::encode::{self, Decodable};
use crate::confidential;
use bitcoin::util::bip32::KeySource;
use bitcoin::{self, PublicKey};
use hashes::Hash;
use crate::hashes::{self, hash160, ripemd160, sha256, sha256d};
use crate::pset::map::Map;
use crate::pset::raw;
Expand Down Expand Up @@ -146,8 +147,8 @@ const PSBT_ELEMENTS_IN_ISSUANCE_BLIND_VALUE_PROOF: u8 = 0x0f;
const PSBT_ELEMENTS_IN_ISSUANCE_BLIND_INFLATION_KEYS_PROOF: u8 = 0x10;
/// A key-value map for an input of the corresponding index in the unsigned
/// transaction.
#[derive(Clone, Default, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "actual_serde"))]
pub struct Input {
/// The non-witness transaction this input spends from. Should only be
/// [std::option::Option::Some] for inputs which spend non-segwit outputs or
Expand Down Expand Up @@ -260,6 +261,12 @@ pub struct Input {
pub unknown: BTreeMap<raw::Key, Vec<u8>>,
}

impl Default for Input {
fn default() -> Self {
Self { non_witness_utxo: Default::default(), witness_utxo: Default::default(), partial_sigs: Default::default(), sighash_type: Default::default(), redeem_script: Default::default(), witness_script: Default::default(), bip32_derivation: Default::default(), final_script_sig: Default::default(), final_script_witness: Default::default(), ripemd160_preimages: Default::default(), sha256_preimages: Default::default(), hash160_preimages: Default::default(), hash256_preimages: Default::default(), previous_txid: Txid::all_zeros(), previous_output_index: Default::default(), sequence: Default::default(), required_time_locktime: Default::default(), required_height_locktime: Default::default(), tap_key_sig: Default::default(), tap_script_sigs: Default::default(), tap_scripts: Default::default(), tap_key_origins: Default::default(), tap_internal_key: Default::default(), tap_merkle_root: Default::default(), issuance_value_amount: Default::default(), issuance_value_comm: Default::default(), issuance_value_rangeproof: Default::default(), issuance_keys_rangeproof: Default::default(), pegin_tx: Default::default(), pegin_txout_proof: Default::default(), pegin_genesis_hash: Default::default(), pegin_claim_script: Default::default(), pegin_value: Default::default(), pegin_witness: Default::default(), issuance_inflation_keys: Default::default(), issuance_inflation_keys_comm: Default::default(), issuance_blinding_nonce: Default::default(), issuance_asset_entropy: Default::default(), in_utxo_rangeproof: Default::default(), in_issuance_blind_value_proof: Default::default(), in_issuance_blind_inflation_keys_proof: Default::default(), proprietary: Default::default(), unknown: Default::default() }
RCasatta marked this conversation as resolved.
Show resolved Hide resolved
}
}

/// A Signature hash type for the corresponding input. As of taproot upgrade, the signature hash
/// type can be either [`SigHashType`] or [`SchnorrSigHashType`] but it is not possible to know
/// directly which signature hash type the user is dealing with. Therefore, the user is responsible
Expand Down
4 changes: 2 additions & 2 deletions src/pset/map/output.rs
Expand Up @@ -87,7 +87,7 @@ const PSBT_ELEMENTS_OUT_BLIND_ASSET_PROOF: u8 = 0x10;
/// A key-value map for an output of the corresponding index in the unsigned
/// transaction.
#[derive(Clone, Default, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "actual_serde"))]
pub struct Output {
/// The redeem script for this output.
pub redeem_script: Option<Script>,
Expand Down Expand Up @@ -140,7 +140,7 @@ pub struct Output {

/// Taproot Tree representing a finalized [`TaprootBuilder`] (a complete binary tree)
#[derive(Clone, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "actual_serde"))]
pub struct TapTree(pub(crate) TaprootBuilder);

impl PartialEq for TapTree {
Expand Down
6 changes: 3 additions & 3 deletions src/pset/mod.rs
Expand Up @@ -47,7 +47,7 @@ use self::map::Map;

/// A Partially Signed Transaction.
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "actual_serde"))]
pub struct PartiallySignedTransaction {
/// The key-value pairs for all global data.
pub global: Global,
Expand Down Expand Up @@ -733,7 +733,7 @@ mod tests {
// Initially secp context and rng global state
let secp = secp256k1_zkp::Secp256k1::new();
#[allow(deprecated)]
let mut rng = rand::ChaChaRng::seed_from_u64(0);
let mut rng = rand::rngs::StdRng::seed_from_u64(0);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to docs StdRng use ChaCha, I think it's equivalent

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as it's deterministic anything should work here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've errors in examples in comparison against test vectors ( pset_blind_coinjoin.rs and raw_blind.rs) which I think it's because those are not equivalent...

  left: `Global { tx_data: TxData { version: 2, fallback_locktime: None, input_count: 2, output_count: 5, tx_modifiable: None }, version: 2, xpub: {}, scalars: [Tweak(a9fe9d44d70fd0efea5c2313c7235b02475b81bd243d2004b853821cee0b2047)], elements_tx_modifiable_flag: None, proprietary: {}, unknown: {} }`,
 right: `Global { tx_data: TxData { version: 2, fallback_locktime: None, input_count: 2, output_count: 5, tx_modifiable: None }, version: 2, xpub: {}, scalars: [Tweak(0f56f3a1f798b585d605591085469b0e3d0c3f46c3bdf230773056302acccdb8)], elements_tx_modifiable_flag: None, proprietary: {}, unknown: {} }`', examples/pset_blind_coinjoin.rs:274:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I can't keep rand 0.6 because it would break against secp256k1_zkp which is now 0.8

Any suggestion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can look into finding an equivalent here. 0.8 rand should have some equivalent PRNG.

Copy link
Collaborator Author

@RCasatta RCasatta Sep 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a deprecation notice on rand 0.6 referring to using the rand_chacha crate (luckily wee need only as dev-dep), I tested it and it looks compatible:

  let mut rng = rand_chacha::ChaChaRng::seed_from_u64(0);
    assert_eq!(rng.next_u32(), 2180380594);

    let mut rng = rand::ChaChaRng::seed_from_u64(0);
    assert_eq!(rng.gen::<u32>(), 2180380594);

    let mut rng = rand::rngs::StdRng::seed_from_u64(0);
    assert_eq!(rng.gen::<u32>(),3384286946);

So I added c187bbb

and raw_blind.rs example works, however, pset_blind_coinjoin.rs still doesn't!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm tempted to add a commit which removes the rand_chacha dep, sticks in some custom crappy RNG, and updates the test vectors. We'd still have a commit that used rand_chacha so that readers could check that the change in tests was only due to the change in RNG, rather than anything else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe that should just be a separate PR..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pset_blind_coinjoin.rs still doesn't!

FYI this was due to wrongdoing in the "fix warning" commit


let pset_hex = "70736574ff01020402000000010401010105010201fb04020000000001017a0bb9325c276764451bbc2eb82a4c8c4bb6f4007ba803e5a5ba72d0cd7c09848e1a091622d935953bf06e0b7393239c68c6f810a00fe19d11c6ae343cffd3037077da02535fe4ad0fcd675cd0f62bf73b60a554dc1569b80f1f76a2bbfc9f00d439bf4b160014d2cbec8783bd01c9f178348b08500a830a89a7f9010e20805131ba6b37165c026eed9325ac56059ba872fd569e3ed462734098688b4770010f0400000000000103088c83b50d0000000007fc04707365740220230f4f5d4b7c6fa845806ee4f67713459e1b69e8e60fcee2e4940c7a0d5de1b20104220020e5793ad956ee91ebf3543b37d110701118ed4078ffa0d477eacb8885e486ad8507fc047073657406210212bf0ea45b733dfde8ecb5e896306c4165c666c99fc5d1ab887f71393a975cea07fc047073657408040000000000010308f40100000000000007fc04707365740220230f4f5d4b7c6fa845806ee4f67713459e1b69e8e60fcee2e4940c7a0d5de1b201040000";
let mut pset : PartiallySignedTransaction = encode::deserialize(&Vec::<u8>::from_hex(&pset_hex).unwrap()[..]).unwrap();
Expand All @@ -754,7 +754,7 @@ mod tests {
bitcoin::Denomination::Bitcoin,
)
.unwrap()
.as_sat(),
.to_sat(),
asset: AssetId::from_hex(&v["asset"].as_str().unwrap()).unwrap(),
};

Expand Down
6 changes: 3 additions & 3 deletions src/pset/raw.rs
Expand Up @@ -25,7 +25,7 @@ use super::Error;
use crate::VarInt;
/// A PSET key in its raw byte form.
#[derive(Debug, PartialEq, Hash, Eq, Clone, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "actual_serde"))]
pub struct Key {
/// The type of this PSET key.
pub type_value: u8,
Expand All @@ -48,7 +48,7 @@ impl Key{

/// A PSET key-value pair in its raw byte form.
#[derive(Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "actual_serde"))]
pub struct Pair {
/// The key of this key-value pair.
pub key: Key,
Expand All @@ -63,7 +63,7 @@ pub type ProprietaryType = u8;
/// Proprietary keys (i.e. keys starting with 0xFC byte) with their internal
/// structure according to BIP 174.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "actual_serde"))]
pub struct ProprietaryKey<Subtype = ProprietaryType> where Subtype: Copy + From<u8> + Into<u8> {
/// Proprietary type prefix used for grouping together keys under some
/// application and avoid namespace collision
Expand Down
7 changes: 4 additions & 3 deletions src/schnorr.rs
Expand Up @@ -19,6 +19,7 @@

use std::fmt;

use secp256k1_zkp::Scalar;
pub use secp256k1_zkp::{XOnlyPublicKey, KeyPair};
use secp256k1_zkp::{self, Secp256k1, Verification, constants::SCHNORR_SIGNATURE_SIZE};
use crate::hashes::{Hash, HashEngine};
Expand Down Expand Up @@ -58,10 +59,10 @@ impl TapTweak for UntweakedPublicKey {
engine.input(&self.serialize());
merkle_root.map(|hash| engine.input(&hash));
let tweak_value: [u8; 32] = TapTweakHash::from_engine(engine).into_inner();
let tweak_value = Scalar::from_be_bytes(tweak_value).expect("hash value greater than curve order");

//Tweak the internal key by the tweak value
let mut output_key = self.clone();
let parity = output_key.tweak_add_assign(&secp, &tweak_value).expect("Tap tweak failed");
let (output_key, parity) = self.clone().add_tweak(secp, &tweak_value).expect("Tap tweak failed");
debug_assert!(self.tweak_add_check(&secp, &output_key, parity, tweak_value));

(TweakedPublicKey(output_key), parity)
Expand Down Expand Up @@ -93,7 +94,7 @@ impl TweakedPublicKey {

/// A BIP340-341 serialized schnorr signature with the corresponding hash type.
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(crate = "actual_serde"))]
pub struct SchnorrSig {
/// The underlying schnorr signature
pub sig: secp256k1_zkp::schnorr::Signature,
Expand Down