diff --git a/Cargo.toml b/Cargo.toml index 52689c6c5..316288b36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] bech32 = { version = "0.8.1", default-features = false } bitcoin_hashes = { version = "0.10.0", default-features = false } -secp256k1 = { git = "https://github.com/rust-bitcoin/rust-secp256k1", default-features = false, rev="f7cae46fc7733522cb84ef1b1ee1d1ed0cec2fd3" } +secp256k1 = { default-features = false, features = ["bitcoin_hashes"], version="0.24.2" } core2 = { version = "0.3.0", optional = true, default-features = false } rustversion = { version="1.0.9"} @@ -52,7 +52,7 @@ hex = { version= "0.4", optional = true} [dev-dependencies] serde_json = "<1.0.45" serde_test = "1" -secp256k1 = { git = "https://github.com/rust-bitcoin/rust-secp256k1", features = [ "recovery", "rand-std" ], rev="f7cae46fc7733522cb84ef1b1ee1d1ed0cec2fd3" } +secp256k1 = { features = [ "recovery", "rand-std", "bitcoin_hashes" ], version="0.24.2" } bincode = "1.3.1" # We need to pin ryu (transitive dep from serde_json) to stay compatible with Rust 1.22.0 ryu = "<1.0.5" diff --git a/README.md b/README.md index 74b20e755..30d759041 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@

Rust Dash

- Rust Bitcoin logo by Hunter Trujillo, see license and source files under /logo + Rust Dash logo by Rostislav Gorbachenko, UX engineer at Dash Core Group, see license and source files under /logo

Library with support for de/serialization, parsing and executing on data-structures and network messages related to Dash Core payment chain. @@ -23,7 +23,7 @@ Supports (or should support) -* De/serialization of Bitcoin protocol network messages +* De/serialization of Dash protocol network messages * De/serialization of blocks and transactions * Script de/serialization * Private keys and address creation, de/serialization and validation (including full BIP32 support) @@ -82,7 +82,7 @@ versions than the current stable one (see MSRV section). The library can be built and tested using [`cargo`](https://github.com/rust-lang/cargo/): ``` -git clone git@github.com:rust-bitcoin/rust-bitcoin.git +git clone git@github.com:dashpay/rust-dashcore.git cd rust-bitcoin cargo build ``` diff --git a/logo/README.md b/logo/README.md index 71a563dba..bf474d35e 100644 --- a/logo/README.md +++ b/logo/README.md @@ -1,17 +1,17 @@ -# Rust Bitcoin Logo +# Rust Dash Logo ## Files Included are: -- [rust-bitcoin-inkscape.svg](./rust-bitcoin-inkscape.svg) - The Inkscape source file with the things used to make the logo in case adjustments are desired -- [rust-bitcoin-optimized.svg](./rust-bitcoin-optimized.svg) - An optimized SVG for embedding or rendering at any size desired -- [rust-bitcoin.png](./rust-bitcoin.png) - The PNG logo rendered at 300px used by this project -- [rust-bitcoin-large.png](./rust-bitcoin-large.png) - A larger size 1024px x 1024px for convenience for embedding in presentations +- [rust-dash-together.png](./rust-dash-together.png) - The PNG logo rendered at 938×834px used by this project +- [rust-dash.png](./rust-dash.png) - A PNG logo rendered at 938×834px of just the Dash Logo +- [rust-dash-together.svg](./rust-dash-together.svg) - An optimized SVG for embedding or rendering at any size desired +- [rust-dash.svg](./rust-dash.svg) - An optimized SVG for embedding or rendering at any size desired ## Author -Hunter Trujillo, @cryptoquick on [Twitter](https://twitter.com/cryptoquick), [GitHub](https://github.com/cryptoquick), and Telegram. +Rostislav Gorbachenko . ## License @@ -20,13 +20,3 @@ Licensed in the public domain under [CC0 1.0 Universal Public Domain Dedication] Bitcoin Logo is licensed under the CC Public Domain Dedication: and Rust Logo is licensed under CC-BY, which allows reuse and modifications for any purpose, as long as distributors give appropriate credit and indicate changes have been made. See here: - -## Acknowledgements - -Acknowledgement for the runners up in this PR: https://github.com/rust-bitcoin/rust-bitcoin/pull/891#issuecomment-1074476858 - -In particular, the Rust Bitcoin Wizard gear was an incredibly inspired piece of art. Also, the meshed gears design was beloved by some but not all. - -Thank you to the Rust Bitcoin maintainers and community, your timely responses and guidance was appreciated. - -Also, thank you to the voters on the Rust in Bitcoin Telegram group: . diff --git a/logo/rust-bitcoin-inkscape.svg b/logo/rust-bitcoin-inkscape.svg deleted file mode 100644 index 9b504a344..000000000 --- a/logo/rust-bitcoin-inkscape.svg +++ /dev/null @@ -1,244 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/logo/rust-bitcoin-large.png b/logo/rust-bitcoin-large.png deleted file mode 100644 index f0cce3403..000000000 Binary files a/logo/rust-bitcoin-large.png and /dev/null differ diff --git a/logo/rust-bitcoin-optimized.svg b/logo/rust-bitcoin-optimized.svg deleted file mode 100644 index 31cf374ba..000000000 --- a/logo/rust-bitcoin-optimized.svg +++ /dev/null @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/logo/rust-bitcoin.png b/logo/rust-bitcoin.png deleted file mode 100644 index 0f59dd168..000000000 Binary files a/logo/rust-bitcoin.png and /dev/null differ diff --git a/logo/rust-dash-together.png b/logo/rust-dash-together.png new file mode 100644 index 000000000..ed534d5ab Binary files /dev/null and b/logo/rust-dash-together.png differ diff --git a/logo/rust-dash-together.svg b/logo/rust-dash-together.svg new file mode 100644 index 000000000..6d808e9d5 --- /dev/null +++ b/logo/rust-dash-together.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/logo/rust-dash.png b/logo/rust-dash.png new file mode 100644 index 000000000..8b55afbae Binary files /dev/null and b/logo/rust-dash.png differ diff --git a/logo/rust-dash.svg b/logo/rust-dash.svg new file mode 100644 index 000000000..c79c6dbe8 --- /dev/null +++ b/logo/rust-dash.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/src/consensus/encode.rs b/src/consensus/encode.rs index 42315aefe..8597ff755 100644 --- a/src/consensus/encode.rs +++ b/src/consensus/encode.rs @@ -1100,7 +1100,7 @@ mod tests { data.clear(); data64.clear(); - let len = thread_rng().gen_range(1, 256); + let len = thread_rng().gen_range(1..256); data.resize(len, 0u8); data64.resize(len, 0u64); let mut arr33 = [0u8; 33]; diff --git a/src/util/bip32.rs b/src/util/bip32.rs index 18bb7b7a1..08932cb7c 100644 --- a/src/util/bip32.rs +++ b/src/util/bip32.rs @@ -595,15 +595,15 @@ impl ExtendedPrivKey { hmac_engine.input(&endian::u32_to_array_be(u32::from(i))); let hmac_result: Hmac = Hmac::from_engine(hmac_engine); - let mut sk = secp256k1::SecretKey::from_slice(&hmac_result[..32])?; - sk.add_assign(&self.private_key[..])?; + let sk = secp256k1::SecretKey::from_slice(&hmac_result[..32]).expect("statistically impossible to hit"); + let tweaked = sk.add_tweak(&self.private_key.into()).expect("statistically impossible to hit"); Ok(ExtendedPrivKey { network: self.network, depth: self.depth + 1, parent_fingerprint: self.fingerprint(secp), child_number: i, - private_key: sk, + private_key: tweaked, chain_code: ChainCode::from(&hmac_result[32..]) }) } @@ -736,15 +736,14 @@ impl ExtendedPubKey { i: ChildNumber, ) -> Result { let (sk, chain_code) = self.ckd_pub_tweak(i)?; - let mut pk = self.public_key; - pk.add_exp_assign(secp, &sk[..])?; + let tweaked = self.public_key.add_exp_tweak(secp, &sk.into())?; Ok(ExtendedPubKey { network: self.network, depth: self.depth + 1, parent_fingerprint: self.fingerprint(), child_number: i, - public_key: pk, + public_key: tweaked, chain_code, }) } diff --git a/src/util/merkleblock.rs b/src/util/merkleblock.rs index 970f2008d..ed3db8959 100644 --- a/src/util/merkleblock.rs +++ b/src/util/merkleblock.rs @@ -713,7 +713,7 @@ mod tests { impl PartialMerkleTree { /// Flip one bit in one of the hashes - this should break the authentication fn damage(&mut self, rng: &mut ThreadRng) { - let n = rng.gen_range(0, self.hashes.len()); + let n = rng.gen_range(0..self.hashes.len()); let bit = rng.gen::(); let hashes = &mut self.hashes; let mut hash = hashes[n].into_inner(); diff --git a/src/util/schnorr.rs b/src/util/schnorr.rs index 166f9c383..59d67ac5d 100644 --- a/src/util/schnorr.rs +++ b/src/util/schnorr.rs @@ -25,7 +25,6 @@ use core::fmt; use prelude::*; use secp256k1::{self, Secp256k1, Verification, constants}; -use hashes::Hash; use util::taproot::{TapBranchHash, TapTweakHash}; use SchnorrSighashType; @@ -112,11 +111,10 @@ impl TapTweak for UntweakedPublicKey { /// # Returns /// The tweaked key and its parity. fn tap_tweak(self, secp: &Secp256k1, merkle_root: Option) -> (TweakedPublicKey, secp256k1::Parity) { - let tweak_value = TapTweakHash::from_key_and_tweak(self, merkle_root).into_inner(); - let mut output_key = self.clone(); - let parity = output_key.tweak_add_assign(&secp, &tweak_value).expect("Tap tweak failed"); + let tweak = TapTweakHash::from_key_and_tweak(self, merkle_root).to_scalar(); + let (output_key, parity) = self.add_tweak(secp, &tweak).expect("Tap tweak failed"); - debug_assert!(self.tweak_add_check(&secp, &output_key, parity, tweak_value)); + debug_assert!(self.tweak_add_check(secp, &output_key, parity, tweak)); (TweakedPublicKey(output_key), parity) } @@ -141,11 +139,11 @@ impl TapTweak for UntweakedKeyPair { /// /// # Returns /// The tweaked key and its parity. - fn tap_tweak(mut self, secp: &Secp256k1, merkle_root: Option) -> TweakedKeyPair { - let pubkey = ::XOnlyPublicKey::from_keypair(&self); - let tweak_value = TapTweakHash::from_key_and_tweak(pubkey, merkle_root).into_inner(); - self.tweak_add_assign(&secp, &tweak_value).expect("Tap tweak failed"); - TweakedKeyPair(self) + fn tap_tweak(self, secp: &Secp256k1, merkle_root: Option) -> TweakedKeyPair { + let (pubkey, _parity) = crate::XOnlyPublicKey::from_keypair(&self); + let tweak = TapTweakHash::from_key_and_tweak(pubkey, merkle_root).to_scalar(); + let tweaked = self.add_xonly_tweak(secp, &tweak).expect("Tap tweak failed"); + TweakedKeyPair(tweaked) } fn dangerous_assume_tweaked(self) -> TweakedKeyPair { diff --git a/src/util/sighash.rs b/src/util/sighash.rs index 0fe1a37dd..4436dd2c6 100644 --- a/src/util/sighash.rs +++ b/src/util/sighash.rs @@ -1121,11 +1121,10 @@ mod tests { }; // tests - let keypair = secp256k1::KeyPair::from_secret_key(&secp, internal_priv_key); - let internal_key = XOnlyPublicKey::from_keypair(&keypair); + let keypair = secp256k1::KeyPair::from_secret_key(secp, &internal_priv_key); + let (internal_key, _parity) = XOnlyPublicKey::from_keypair(&keypair); let tweak = TapTweakHash::from_key_and_tweak(internal_key, merkle_root); - let mut tweaked_keypair = keypair; - tweaked_keypair.tweak_add_assign(&secp, &tweak).unwrap(); + let tweaked_keypair = keypair.add_xonly_tweak(secp, &tweak.to_scalar()).unwrap(); let mut sig_msg = Vec::new(); cache.taproot_encode_signing_data_to( &mut sig_msg, diff --git a/src/util/taproot.rs b/src/util/taproot.rs index 0d131001c..d3a0b3b01 100644 --- a/src/util/taproot.rs +++ b/src/util/taproot.rs @@ -18,7 +18,7 @@ use prelude::*; use io; -use secp256k1::{self, Secp256k1}; +use secp256k1::{self, Secp256k1, Scalar}; use core::fmt; use core::cmp::Reverse; @@ -115,6 +115,12 @@ impl TapTweakHash { } TapTweakHash::from_engine(eng) } + + /// Converts a `TapTweakHash` into a `Scalar` ready for use with key tweaking API. + pub fn to_scalar(&self) -> Scalar { + // This is statistically extremely unlikely to panic. + Scalar::from_be_bytes(self.into_inner()).expect("hash value greater than curve order") + } } impl TapLeafHash { @@ -839,12 +845,12 @@ impl ControlBlock { ); } // compute the taptweak - let tweak = TapTweakHash::from_key_and_tweak(self.internal_key, Some(curr_hash)); + let tweak = TapTweakHash::from_key_and_tweak(self.internal_key, Some(curr_hash)).to_scalar(); self.internal_key.tweak_add_check( secp, &output_key, self.output_key_parity, - tweak.into_inner(), + tweak, ) } }