Skip to content

Commit

Permalink
bitcoin: bump 0.28.0 -> 0.29.1
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RCasatta committed Sep 27, 2022
1 parent 3edf8da commit bb3e55b
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 20 deletions.
13 changes: 7 additions & 6 deletions Cargo.toml
Expand Up @@ -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 }
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/pset_blind_coinjoin.rs
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/raw_blind.rs
Expand Up @@ -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();
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
2 changes: 1 addition & 1 deletion src/confidential.rs
Expand Up @@ -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")
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
9 changes: 8 additions & 1 deletion 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,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
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() }
}
}

/// 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
2 changes: 1 addition & 1 deletion src/pset/mod.rs
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);

let pset_hex = "70736574ff01020402000000010401010105010201fb04020000000001017a0bb9325c276764451bbc2eb82a4c8c4bb6f4007ba803e5a5ba72d0cd7c09848e1a091622d935953bf06e0b7393239c68c6f810a00fe19d11c6ae343cffd3037077da02535fe4ad0fcd675cd0f62bf73b60a554dc1569b80f1f76a2bbfc9f00d439bf4b160014d2cbec8783bd01c9f178348b08500a830a89a7f9010e20805131ba6b37165c026eed9325ac56059ba872fd569e3ed462734098688b4770010f0400000000000103088c83b50d0000000007fc04707365740220230f4f5d4b7c6fa845806ee4f67713459e1b69e8e60fcee2e4940c7a0d5de1b20104220020e5793ad956ee91ebf3543b37d110701118ed4078ffa0d477eacb8885e486ad8507fc047073657406210212bf0ea45b733dfde8ecb5e896306c4165c666c99fc5d1ab887f71393a975cea07fc047073657408040000000000010308f40100000000000007fc04707365740220230f4f5d4b7c6fa845806ee4f67713459e1b69e8e60fcee2e4940c7a0d5de1b201040000";
let mut pset : PartiallySignedTransaction = encode::deserialize(&Vec::<u8>::from_hex(&pset_hex).unwrap()[..]).unwrap();
Expand Down
2 changes: 2 additions & 0 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,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();
Expand Down
2 changes: 1 addition & 1 deletion src/sighash.rs
Expand Up @@ -503,7 +503,7 @@ impl<R: Deref<Target = Transaction>> SigHashCache<R> {
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();

Expand Down
6 changes: 4 additions & 2 deletions src/taproot.rs
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/transaction.rs
Expand Up @@ -73,7 +73,7 @@ impl OutPoint {
#[inline]
pub fn null() -> OutPoint {
OutPoint {
txid: Default::default(),
txid: Txid::all_zeros(),
vout: u32::max_value(),
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit bb3e55b

Please sign in to comment.