diff --git a/Cargo.toml b/Cargo.toml index 54973e1f..2d46000f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,21 +15,22 @@ 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.6.0", features = [ "global-context", "bitcoin_hashes" ] } +secp256k1-zkp = { git = "https://github.com/RCasatta/rust-secp256k1-zkp", branch="bump_secp", 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 +39,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.36 diff --git a/examples/pset_blind_coinjoin.rs b/examples/pset_blind_coinjoin.rs index c0a7ab42..6307b42a 100644 --- a/examples/pset_blind_coinjoin.rs +++ b/examples/pset_blind_coinjoin.rs @@ -139,7 +139,7 @@ fn main() { // 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 txouts = txout_data(); let (btc_txout, btc_txout_secrets, btc_inp) = txouts[0].clone(); diff --git a/examples/raw_blind.rs b/examples/raw_blind.rs index 5e907a1d..bca3afb9 100644 --- a/examples/raw_blind.rs +++ b/examples/raw_blind.rs @@ -139,7 +139,7 @@ fn main() { // 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 txouts = txout_data(); let (btc_txout, btc_txout_secrets, btc_inp) = txouts[0].clone(); 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..927c1d2e 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") 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,