From 730072f967b808359d5ede56d73e8c1a92a135b6 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Tue, 27 Sep 2022 15:55:02 +0200 Subject: [PATCH 1/5] bump MSRV to 1.41.1 --- .github/workflows/rust.yml | 2 +- Cargo.toml | 2 +- README.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 3736e0bc..f8c56286 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -22,7 +22,7 @@ jobs: - rust: nightly env: DUMMY: true - - rust: 1.36.0 + - rust: 1.41.1 env: PIN_VERSIONS: true steps: diff --git a/Cargo.toml b/Cargo.toml index 54973e1f..46ea67ad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,7 +44,7 @@ elementsd = {version = "0.5.0", features=["0_21_0","bitcoind_22_0"], optional = rand = "0.6.5" 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" diff --git a/README.md b/README.md index b28a1879..f53f3538 100644 --- a/README.md +++ b/README.md @@ -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**. From 5304cde7ba856c21e8227e830e9f7dff525811f0 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Tue, 27 Sep 2022 15:01:02 +0200 Subject: [PATCH 2/5] bitcoin: bump 0.28.0 -> 0.29.1 bitcoin_hases: bump 0.10.1 -> 0.11.0 rand: bump 0.6.5 -> 0.8 Code changes relate to: * Drop default from structure since hashes has all_zeros() instead of default(), Input manually implements default to minimize changes. * convert arrays to Scalar type --- Cargo.toml | 12 ++++++------ examples/pset_blind_coinjoin.rs | 2 +- src/block.rs | 4 ++-- src/confidential.rs | 20 ++++++++++++-------- src/dynafed.rs | 8 +++++++- src/pset/map/input.rs | 9 ++++++++- src/pset/mod.rs | 2 +- src/schnorr.rs | 2 ++ src/sighash.rs | 2 +- src/taproot.rs | 6 ++++-- src/transaction.rs | 6 +++--- tests/taproot.rs | 4 +++- 12 files changed, 50 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 46ea67ad..79827555 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,21 +15,21 @@ integration = [ "elementsd" ] json-contract = [ "serde_json" ] "serde-feature" = [ - "bitcoin/use-serde", + "bitcoin/serde", "secp256k1-zkp/use-serde", "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 } @@ -38,10 +38,10 @@ 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.41.1 diff --git a/examples/pset_blind_coinjoin.rs b/examples/pset_blind_coinjoin.rs index 52b0c94d..df0986d5 100644 --- a/examples/pset_blind_coinjoin.rs +++ b/examples/pset_blind_coinjoin.rs @@ -324,4 +324,4 @@ impl rand::RngCore for CrappyRng { } } -impl rand::CryptoRng for CrappyRng {} \ No newline at end of file +impl rand::CryptoRng for CrappyRng {} diff --git a/src/block.rs b/src/block.rs index d9d5e89c..cdf2efe2 100644 --- a/src/block.rs +++ b/src/block.rs @@ -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, @@ -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, diff --git a/src/confidential.rs b/src/confidential.rs index e7aff470..3414caad 100644 --- a/src/confidential.rs +++ b/src/confidential.rs @@ -961,7 +961,7 @@ impl AddAssign for ValueBlindingFactor { // 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() { + if sk.add_assign(&sk2.into()).is_err() { *self = Self::zero(); } else { *self = ValueBlindingFactor::from_slice(sk.as_ref()).expect("Valid Tweak") @@ -1374,13 +1374,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 ] ); diff --git a/src/dynafed.rs b/src/dynafed.rs index 0c8b2fc2..66d666b9 100644 --- a/src/dynafed.rs +++ b/src/dynafed.rs @@ -590,6 +590,8 @@ mod tests { use bitcoin::hashes::hex::ToHex; use bitcoin::hashes::sha256; + use crate::{BlockHash, TxMerkleNode}; + use super::*; #[test] @@ -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(), diff --git a/src/pset/map/input.rs b/src/pset/map/input.rs index 84593421..6e254e1b 100644 --- a/src/pset/map/input.rs +++ b/src/pset/map/input.rs @@ -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; @@ -146,7 +147,7 @@ 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)] +#[derive(Clone, Debug, PartialEq)] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Input { /// The non-witness transaction this input spends from. Should only be @@ -260,6 +261,12 @@ pub struct Input { pub unknown: BTreeMap>, } +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() } + } +} + /// 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 diff --git a/src/pset/mod.rs b/src/pset/mod.rs index fb03c25a..4be72ff1 100644 --- a/src/pset/mod.rs +++ b/src/pset/mod.rs @@ -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); let pset_hex = "70736574ff01020402000000010401010105010201fb04020000000001017a0bb9325c276764451bbc2eb82a4c8c4bb6f4007ba803e5a5ba72d0cd7c09848e1a091622d935953bf06e0b7393239c68c6f810a00fe19d11c6ae343cffd3037077da02535fe4ad0fcd675cd0f62bf73b60a554dc1569b80f1f76a2bbfc9f00d439bf4b160014d2cbec8783bd01c9f178348b08500a830a89a7f9010e20805131ba6b37165c026eed9325ac56059ba872fd569e3ed462734098688b4770010f0400000000000103088c83b50d0000000007fc04707365740220230f4f5d4b7c6fa845806ee4f67713459e1b69e8e60fcee2e4940c7a0d5de1b20104220020e5793ad956ee91ebf3543b37d110701118ed4078ffa0d477eacb8885e486ad8507fc047073657406210212bf0ea45b733dfde8ecb5e896306c4165c666c99fc5d1ab887f71393a975cea07fc047073657408040000000000010308f40100000000000007fc04707365740220230f4f5d4b7c6fa845806ee4f67713459e1b69e8e60fcee2e4940c7a0d5de1b201040000"; let mut pset : PartiallySignedTransaction = encode::deserialize(&Vec::::from_hex(&pset_hex).unwrap()[..]).unwrap(); diff --git a/src/schnorr.rs b/src/schnorr.rs index bdbb7913..297b85b7 100644 --- a/src/schnorr.rs +++ b/src/schnorr.rs @@ -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}; @@ -58,6 +59,7 @@ 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(); diff --git a/src/sighash.rs b/src/sighash.rs index 9ff8b6fe..10a33c22 100644 --- a/src/sighash.rs +++ b/src/sighash.rs @@ -503,7 +503,7 @@ impl> SigHashCache { value: confidential::Value, sighash_type: EcdsaSigHashType, ) -> Result<(), encode::Error> { - let zero_hash = sha256d::Hash::default(); + let zero_hash = sha256d::Hash::all_zeros(); let (sighash, anyone_can_pay) = sighash_type.split_anyonecanpay_flag(); diff --git a/src/taproot.rs b/src/taproot.rs index 5210b365..8b1e9004 100644 --- a/src/taproot.rs +++ b/src/taproot.rs @@ -20,7 +20,7 @@ use crate::hashes::{sha256, sha256t, Hash}; use crate::schnorr::{UntweakedPublicKey, TweakedPublicKey, TapTweak}; use crate::Script; use std::collections::{BTreeMap, BTreeSet, BinaryHeap}; -use secp256k1_zkp::{self, Secp256k1}; +use secp256k1_zkp::{self, Secp256k1, Scalar}; use crate::hashes::HashEngine; use crate::encode::Encodable; @@ -736,11 +736,13 @@ impl ControlBlock { } // compute the taptweak let tweak = TapTweakHash::from_key_and_tweak(self.internal_key, Some(curr_hash)); + let tweak = Scalar::from_be_bytes(tweak.into_inner()).expect("hash value greater than curve order"); + self.internal_key.tweak_add_check( secp, output_key.as_inner(), self.output_key_parity, - tweak.into_inner(), + tweak, ) } } diff --git a/src/transaction.rs b/src/transaction.rs index d9daa2bb..4595ba50 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -73,7 +73,7 @@ impl OutPoint { #[inline] pub fn null() -> OutPoint { OutPoint { - txid: Default::default(), + txid: Txid::all_zeros(), vout: u32::max_value(), } } @@ -158,7 +158,7 @@ impl TxInWitness { /// Parsed data from a transaction input's pegin witness -#[derive(Copy, Clone, Default, PartialEq, Eq, Debug, Hash)] +#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] pub struct PeginData<'tx> { /// Reference to the pegin output on the mainchain pub outpoint: bitcoin::OutPoint, @@ -389,7 +389,7 @@ impl TxOutWitness { } /// Information about a pegout -#[derive(Clone, Default, PartialEq, Eq, Debug, Hash)] +#[derive(Clone, PartialEq, Eq, Debug, Hash)] pub struct PegoutData<'txo> { /// Amount to peg out pub value: u64, diff --git a/tests/taproot.rs b/tests/taproot.rs index 6e9c5d02..e9d1a0a0 100644 --- a/tests/taproot.rs +++ b/tests/taproot.rs @@ -11,6 +11,7 @@ use bitcoin::{Amount, XOnlyPublicKey, KeyPair}; use elements::bitcoin::hashes::hex::FromHex; use elements::confidential::{AssetBlindingFactor, ValueBlindingFactor}; use elements::encode::{deserialize, serialize_hex}; +use elements::hashes::Hash; use elements::script::Builder; use elements::secp256k1_zkp; use elements::sighash::{self, SigHashCache}; @@ -48,7 +49,7 @@ fn gen_keypair( rng: &mut rngs::ThreadRng, ) -> (XOnlyPublicKey, KeyPair) { let keypair = KeyPair::new(secp, rng); - let pk = XOnlyPublicKey::from_keypair(&keypair); + let (pk, _) = XOnlyPublicKey::from_keypair(&keypair); (pk, keypair) } @@ -224,6 +225,7 @@ fn taproot_spend_test( test_data.internal_pk, test_data.spend_info.merkle_root(), ); + let tweak = secp256k1_zkp::Scalar::from_be_bytes(tweak.into_inner()).expect("hash value greater than curve order"); output_keypair.tweak_add_assign(&secp, &tweak).unwrap(); let sig = secp.sign_schnorr( &secp256k1_zkp::Message::from_slice(&sighash_msg[..]).unwrap(), From a43e09074193ec7c94334cfd7f7b308b95e1db1a Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Tue, 27 Sep 2022 15:21:20 +0200 Subject: [PATCH 3/5] Fix warnings --- examples/pset_blind_coinjoin.rs | 2 +- examples/raw_blind.rs | 2 +- src/blind.rs | 2 +- src/confidential.rs | 12 +++++------- src/pset/mod.rs | 2 +- src/schnorr.rs | 3 +-- tests/taproot.rs | 7 +++---- 7 files changed, 13 insertions(+), 17 deletions(-) diff --git a/examples/pset_blind_coinjoin.rs b/examples/pset_blind_coinjoin.rs index df0986d5..947bfc15 100644 --- a/examples/pset_blind_coinjoin.rs +++ b/examples/pset_blind_coinjoin.rs @@ -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(), }, }; diff --git a/examples/raw_blind.rs b/examples/raw_blind.rs index ca758a06..2ed66c51 100644 --- a/examples/raw_blind.rs +++ b/examples/raw_blind.rs @@ -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(), }, }; diff --git a/src/blind.rs b/src/blind.rs index 4d20cf15..e2d7da5b 100644 --- a/src/blind.rs +++ b/src/blind.rs @@ -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(), }; diff --git a/src/confidential.rs b/src/confidential.rs index 3414caad..13fadd5a 100644 --- a/src/confidential.rs +++ b/src/confidential.rs @@ -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.into()).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(), } } } @@ -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") } } diff --git a/src/pset/mod.rs b/src/pset/mod.rs index 4be72ff1..43de8a5c 100644 --- a/src/pset/mod.rs +++ b/src/pset/mod.rs @@ -754,7 +754,7 @@ mod tests { bitcoin::Denomination::Bitcoin, ) .unwrap() - .as_sat(), + .to_sat(), asset: AssetId::from_hex(&v["asset"].as_str().unwrap()).unwrap(), }; diff --git a/src/schnorr.rs b/src/schnorr.rs index 297b85b7..03862e3c 100644 --- a/src/schnorr.rs +++ b/src/schnorr.rs @@ -62,8 +62,7 @@ impl TapTweak for UntweakedPublicKey { 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) diff --git a/tests/taproot.rs b/tests/taproot.rs index e9d1a0a0..726ffdd5 100644 --- a/tests/taproot.rs +++ b/tests/taproot.rs @@ -113,7 +113,7 @@ fn funded_tap_txout( &PARAMS, ); let amt = Amount::from_sat(1_000_000); - let txid_hex = elementsd.send_to_address(&addr.to_string(), &amt.as_btc().to_string()); + let txid_hex = elementsd.send_to_address(&addr.to_string(), &amt.to_btc().to_string()); elementsd.generate(1); let tx_hex = elementsd.get_transaction(&txid_hex); @@ -220,16 +220,15 @@ fn taproot_spend_test( ) .unwrap(); - let mut output_keypair = test_data.internal_keypair; // type is copy + let output_keypair = test_data.internal_keypair; // type is copy let tweak = TapTweakHash::from_key_and_tweak( test_data.internal_pk, test_data.spend_info.merkle_root(), ); let tweak = secp256k1_zkp::Scalar::from_be_bytes(tweak.into_inner()).expect("hash value greater than curve order"); - output_keypair.tweak_add_assign(&secp, &tweak).unwrap(); let sig = secp.sign_schnorr( &secp256k1_zkp::Message::from_slice(&sighash_msg[..]).unwrap(), - &output_keypair, + &output_keypair.add_xonly_tweak(&secp, &tweak).unwrap(), ); let schnorr_sig = SchnorrSig { From 7a532523c49eab9c1126491044b0d3991531a8c6 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Fri, 30 Sep 2022 10:37:51 +0200 Subject: [PATCH 4/5] update CHANGELOG --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12fd0f8b..d2c539dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +# unreleased + +- 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 From 6039cc4557ae13647d5fd8d28981d1b96f568dff Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Mon, 3 Oct 2022 11:13:14 +0200 Subject: [PATCH 5/5] Rename serde-feature to serde --- CHANGELOG.md | 1 + Cargo.toml | 6 +++--- contrib/test.sh | 2 +- fuzz/Cargo.toml | 2 +- src/blind.rs | 2 +- src/lib.rs | 2 +- src/pset/map/global.rs | 4 ++-- src/pset/map/input.rs | 2 +- src/pset/map/output.rs | 4 ++-- src/pset/mod.rs | 2 +- src/pset/raw.rs | 6 +++--- src/schnorr.rs | 2 +- src/serde_utils.rs | 2 ++ src/taproot.rs | 11 ++++++----- 14 files changed, 26 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2c539dc..1c585c6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # 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 diff --git a/Cargo.toml b/Cargo.toml index 79827555..53255065 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,10 +14,10 @@ default = [ "json-contract" ] integration = [ "elementsd" ] json-contract = [ "serde_json" ] -"serde-feature" = [ +"serde" = [ "bitcoin/serde", "secp256k1-zkp/use-serde", - "serde" + "actual-serde" ] "fuzztarget" = [] @@ -34,7 +34,7 @@ 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 diff --git a/contrib/test.sh b/contrib/test.sh index 1e187873..d13bc25c 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -1,6 +1,6 @@ #!/bin/sh -ex -FEATURES="serde-feature" +FEATURES="serde" # Use toolchain if explicitly specified if [ -n "$TOOLCHAIN" ] diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index e3b93f11..028baa32 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -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] diff --git a/src/blind.rs b/src/blind.rs index e2d7da5b..cff07475 100644 --- a/src/blind.rs +++ b/src/blind.rs @@ -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 diff --git a/src/lib.rs b/src/lib.rs index 876fd9f9..9ccbff53 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; diff --git a/src/pset/map/global.rs b/src/pset/map/global.rs index 17bb5c7d..76d06a44 100644 --- a/src/pset/map/global.rs +++ b/src/pset/map/global.rs @@ -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, @@ -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))] diff --git a/src/pset/map/input.rs b/src/pset/map/input.rs index 6e254e1b..c7801ff0 100644 --- a/src/pset/map/input.rs +++ b/src/pset/map/input.rs @@ -148,7 +148,7 @@ 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, Debug, PartialEq)] -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +#[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 diff --git a/src/pset/map/output.rs b/src/pset/map/output.rs index 485b7d75..a243734c 100644 --- a/src/pset/map/output.rs +++ b/src/pset/map/output.rs @@ -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