diff --git a/Cargo.toml b/Cargo.toml index 55551fae2..1c6ac9f95 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ members = ["dash", "hashes", "internals", "fuzz", "rpc-client", "rpc-json", "rpc resolver = "2" [workspace.package] -version = "0.39.3" +version = "0.39.4" [patch.crates-io.dashcore_hashes] path = "hashes" diff --git a/dash/src/blockdata/script/push_bytes.rs b/dash/src/blockdata/script/push_bytes.rs index 85b4268b9..adb2fbe00 100644 --- a/dash/src/blockdata/script/push_bytes.rs +++ b/dash/src/blockdata/script/push_bytes.rs @@ -9,11 +9,9 @@ pub use primitive::*; use crate::prelude::*; /// This module only contains required operations so that outside functions wouldn't accidentally -/// break invariants. Therefore auditing this module should be sufficient. +/// break invariants. Therefore, auditing this module should be sufficient. mod primitive { use core::convert::{TryFrom, TryInto}; - #[cfg(feature = "rust_v_1_53")] - use core::ops::Bound; use core::ops::{ Index, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive, }; @@ -54,7 +52,7 @@ mod primitive { /// /// The caller is responsible for checking that the length is less than the [`LIMIT`]. unsafe fn from_slice_unchecked(bytes: &[u8]) -> &Self { - &*(bytes as *const [u8] as *const PushBytes) + unsafe { &*(bytes as *const [u8] as *const PushBytes) } } /// Creates `&mut Self` without checking the length. @@ -63,7 +61,7 @@ mod primitive { /// /// The caller is responsible for checking that the length is less than the [`LIMIT`]. unsafe fn from_mut_slice_unchecked(bytes: &mut [u8]) -> &mut Self { - &mut *(bytes as *mut [u8] as *mut PushBytes) + unsafe { &mut *(bytes as *mut [u8] as *mut PushBytes) } } /// Creates an empty `PushBytes`. @@ -111,9 +109,6 @@ mod primitive { RangeInclusive, RangeToInclusive ); - #[cfg(feature = "rust_v_1_53")] - #[cfg_attr(docsrs, doc(cfg(feature = "rust_v_1_53")))] - delegate_index!((Bound, Bound)); impl Index for PushBytes { type Output = u8; diff --git a/dash/src/consensus/encode.rs b/dash/src/consensus/encode.rs index 1e90ac141..ac55c3226 100644 --- a/dash/src/consensus/encode.rs +++ b/dash/src/consensus/encode.rs @@ -892,7 +892,7 @@ impl Encodable for rc::Rc { } /// Note: This will fail to compile on old Rust for targets that don't support atomics -#[cfg(any(not(rust_v_1_60), target_has_atomic = "ptr"))] +#[cfg(target_has_atomic = "ptr")] impl Encodable for sync::Arc { fn consensus_encode(&self, w: &mut W) -> Result { (**self).consensus_encode(w) diff --git a/dash/src/crypto/sighash.rs b/dash/src/crypto/sighash.rs index d3c352e0d..26824537e 100644 --- a/dash/src/crypto/sighash.rs +++ b/dash/src/crypto/sighash.rs @@ -36,16 +36,6 @@ pub(crate) const UINT256_ONE: [u8; 32] = [ 0, 0, 0, 0, 0, 0, 0, 0 ]; -macro_rules! impl_thirty_two_byte_hash { - ($ty:ident) => { - impl secp256k1::ThirtyTwoByteHash for $ty { - fn into_32(self) -> [u8; 32] { - self.to_byte_array() - } - } - }; -} - hash_newtype! { /// Hash of a transaction according to the legacy signature algorithm. #[hash_newtype(forward)] @@ -56,9 +46,6 @@ hash_newtype! { pub struct SegwitV0Sighash(sha256d::Hash); } -impl_thirty_two_byte_hash!(LegacySighash); -impl_thirty_two_byte_hash!(SegwitV0Sighash); - sha256t_hash_newtype! { pub struct TapSighashTag = hash_str("TapSighash"); @@ -69,8 +56,6 @@ sha256t_hash_newtype! { pub struct TapSighash(_); } -impl_thirty_two_byte_hash!(TapSighash); - /// Efficiently calculates signature hash message for legacy, segwit and taproot inputs. #[derive(Debug)] pub struct SighashCache> { @@ -1723,7 +1708,7 @@ mod tests { .taproot_signature_hash(tx_ind, &Prevouts::All(&utxos), None, None, hash_ty) .unwrap(); - let msg = secp256k1::Message::from(sighash); + let msg = secp256k1::Message::from_digest(sighash.to_byte_array()); let key_spend_sig = secp.sign_schnorr_with_aux_rand(msg.as_ref(), &tweaked_keypair, &[0u8; 32]); diff --git a/dash/src/psbt/mod.rs b/dash/src/psbt/mod.rs index 5e265f958..49c33f3ec 100644 --- a/dash/src/psbt/mod.rs +++ b/dash/src/psbt/mod.rs @@ -11,9 +11,6 @@ use core::{cmp, fmt}; #[cfg(feature = "std")] use std::collections::{HashMap, HashSet}; -use internals::write_err; -use secp256k1::{Message, Secp256k1, Signing}; - use crate::Amount; use crate::bip32::{self, ExtendedPrivKey, ExtendedPubKey, KeySource}; use crate::blockdata::script::ScriptBuf; @@ -24,6 +21,9 @@ use crate::crypto::key::{PrivateKey, PublicKey}; use crate::prelude::*; pub use crate::sighash::Prevouts; use crate::sighash::{self, EcdsaSighashType, SighashCache}; +use hashes::Hash; +use internals::write_err; +use secp256k1::{Message, Secp256k1, Signing}; #[macro_use] mod macros; @@ -333,20 +333,20 @@ impl PartiallySignedTransaction { match self.output_type(input_index)? { Bare => { let sighash = cache.legacy_signature_hash(input_index, spk, hash_ty.to_u32())?; - Ok((Message::from(sighash), hash_ty)) + Ok((Message::from_digest(sighash.to_byte_array()), hash_ty)) } Sh => { let script_code = input.redeem_script.as_ref().ok_or(SignError::MissingRedeemScript)?; let sighash = cache.legacy_signature_hash(input_index, script_code, hash_ty.to_u32())?; - Ok((Message::from(sighash), hash_ty)) + Ok((Message::from_digest(sighash.to_byte_array()), hash_ty)) } Wpkh => { let script_code = ScriptBuf::p2wpkh_script_code(spk).ok_or(SignError::NotWpkh)?; let sighash = cache.segwit_signature_hash(input_index, &script_code, utxo.value, hash_ty)?; - Ok((Message::from(sighash), hash_ty)) + Ok((Message::from_digest(sighash.to_byte_array()), hash_ty)) } ShWpkh => { let script_code = ScriptBuf::p2wpkh_script_code( @@ -355,14 +355,14 @@ impl PartiallySignedTransaction { .ok_or(SignError::NotWpkh)?; let sighash = cache.segwit_signature_hash(input_index, &script_code, utxo.value, hash_ty)?; - Ok((Message::from(sighash), hash_ty)) + Ok((Message::from_digest(sighash.to_byte_array()), hash_ty)) } Wsh | ShWsh => { let script_code = input.witness_script.as_ref().ok_or(SignError::MissingWitnessScript)?; let sighash = cache.segwit_signature_hash(input_index, script_code, utxo.value, hash_ty)?; - Ok((Message::from(sighash), hash_ty)) + Ok((Message::from_digest(sighash.to_byte_array()), hash_ty)) } Tr => { // This PSBT signing API is WIP, taproot to come shortly. diff --git a/dash/src/sign_message.rs b/dash/src/sign_message.rs index 6da63ded0..98b9fc07d 100644 --- a/dash/src/sign_message.rs +++ b/dash/src/sign_message.rs @@ -34,7 +34,7 @@ pub const DASH_SIGNED_MSG_PREFIX: &[u8] = b"\x19DarkCoin Signed Message:\n"; mod message_signing { use core::fmt; - use hashes::sha256d; + use hashes::{Hash, sha256d}; use internals::write_err; use secp256k1; use secp256k1::ecdsa::{RecoverableSignature, RecoveryId}; @@ -153,7 +153,7 @@ mod message_signing { secp_ctx: &secp256k1::Secp256k1, msg_hash: sha256d::Hash, ) -> Result { - let msg = secp256k1::Message::from(msg_hash); + let msg = secp256k1::Message::from_digest(msg_hash.to_byte_array()); let pubkey = secp_ctx.recover_ecdsa(&msg, &self.signature)?; Ok(PublicKey { inner: pubkey, @@ -252,18 +252,18 @@ mod tests { let secp = secp256k1::Secp256k1::new(); let message = "rust-dash MessageSignature test"; - let msg_hash = super::signed_msg_hash(message); - let msg = secp256k1::Message::from(msg_hash); + let msg_hash = signed_msg_hash(message); + let msg = secp256k1::Message::from_digest(msg_hash.to_byte_array()); let privkey = secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng()); let secp_sig = secp.sign_ecdsa_recoverable(&msg, &privkey); - let signature = super::MessageSignature { + let signature = MessageSignature { signature: secp_sig, compressed: true, }; assert_eq!(signature.to_base64(), signature.to_string()); - let signature2 = super::MessageSignature::from_str(&signature.to_string()).unwrap(); + let signature2 = MessageSignature::from_str(&signature.to_string()).unwrap(); let pubkey = signature2.recover_pubkey(&secp, msg_hash).unwrap(); assert!(pubkey.compressed); assert_eq!(pubkey.inner, secp256k1::PublicKey::from_secret_key(&secp, &privkey)); diff --git a/dash/src/sml/masternode_list_engine/mod.rs b/dash/src/sml/masternode_list_engine/mod.rs index 6efb3c8cf..fd1ac4290 100644 --- a/dash/src/sml/masternode_list_engine/mod.rs +++ b/dash/src/sml/masternode_list_engine/mod.rs @@ -444,13 +444,7 @@ impl MasternodeListEngine { self.known_snapshots .insert(mn_list_diff_at_h_minus_3c.block_hash, quorum_snapshot_at_h_minus_3c); - let mn_list_diff_at_h_minus_3c_block_hash = mn_list_diff_at_h_minus_3c.block_hash; - self.apply_diff(mn_list_diff_at_h_minus_3c, None, false, None)?.ok_or( - QuorumValidationError::RequiredRotatedChainLockSigNotPresent( - 3, - mn_list_diff_at_h_minus_3c_block_hash, - ), - )?; + self.apply_diff(mn_list_diff_at_h_minus_3c, None, false, None)?; self.known_snapshots .insert(mn_list_diff_at_h_minus_2c.block_hash, quorum_snapshot_at_h_minus_2c); let mn_list_diff_at_h_minus_2c_block_hash = mn_list_diff_at_h_minus_2c.block_hash; @@ -462,19 +456,14 @@ impl MasternodeListEngine { let mn_list_diff_at_h_block_hash = mn_list_diff_h.block_hash; let maybe_sigm0 = self.apply_diff(mn_list_diff_h, None, false, None)?; - let sigs = if maybe_sigm2.is_some() && maybe_sigm1.is_some() && maybe_sigm0.is_some() { - Some([maybe_sigm2.unwrap(), maybe_sigm1.unwrap(), maybe_sigm0.unwrap()]) - } else { - None + let sigs = match (maybe_sigm2, maybe_sigm1, maybe_sigm0) { + (Some(s2), Some(s1), Some(s0)) => Some([s2, s1, s0]), + _ => None, }; let mn_list_diff_tip_block_hash = mn_list_diff_tip.block_hash; - let sigmtip = self - .apply_diff(mn_list_diff_tip, None, verify_tip_non_rotated_quorums, sigs)? - .ok_or(QuorumValidationError::RequiredRotatedChainLockSigNotPresent( - 0, - mn_list_diff_tip_block_hash, - ))?; + let maybe_sigmtip = + self.apply_diff(mn_list_diff_tip, None, verify_tip_non_rotated_quorums, sigs)?; let qualified_last_commitment_per_index = last_commitment_per_index .into_iter() @@ -486,24 +475,30 @@ impl MasternodeListEngine { } else { let sigm2 = maybe_sigm2.ok_or( QuorumValidationError::RequiredRotatedChainLockSigNotPresent( - 2, + 3, mn_list_diff_at_h_minus_2c_block_hash, ), )?; let sigm1 = maybe_sigm1.ok_or( QuorumValidationError::RequiredRotatedChainLockSigNotPresent( - 1, + 2, mn_list_diff_at_h_minus_c_block_hash, ), )?; let sigm0 = maybe_sigm0.ok_or( QuorumValidationError::RequiredRotatedChainLockSigNotPresent( - 0, + 1, mn_list_diff_at_h_block_hash, ), )?; + let sigmtip = maybe_sigmtip.ok_or( + QuorumValidationError::RequiredRotatedChainLockSigNotPresent( + 0, + mn_list_diff_tip_block_hash, + ), + )?; let mut qualified_quorum_entry: QualifiedQuorumEntry = quorum_entry.into(); qualified_quorum_entry.verifying_chain_lock_signature = Some(VerifyingChainLockSignaturesType::Rotating([ diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index 0b3798bc4..7a62ced53 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -12,7 +12,7 @@ cargo-fuzz = true honggfuzz = { version = "0.5", default-features = false } dashcore = { path = "../dash", features = [ "serde" ] } -serde = { version = "1.0.103", features = [ "derive" ] } +serde = { version = "1.0.219", features = [ "derive" ] } serde_json = "1.0" serde_cbor = "0.9" diff --git a/fuzz/generate-files.sh b/fuzz/generate-files.sh index 89cc6a889..dbd2498dc 100755 --- a/fuzz/generate-files.sh +++ b/fuzz/generate-files.sh @@ -23,7 +23,7 @@ cargo-fuzz = true honggfuzz = { version = "0.5", default-features = false } dash = { path = "../dash", features = [ "serde" ] } -serde = { version = "1.0.103", features = [ "derive" ] } +serde = { version = "1.0.219", features = [ "derive" ] } serde_json = "1.0" serde_cbor = "0.9" EOF diff --git a/hashes/Cargo.toml b/hashes/Cargo.toml index 1ec98f1ff..07023b674 100644 --- a/hashes/Cargo.toml +++ b/hashes/Cargo.toml @@ -27,9 +27,9 @@ rustdoc-args = ["--cfg", "docsrs"] [dependencies] internals = { path = "../internals", package = "dashcore-private" } -core2 = { version = "0.3.0", default-features = false, optional = true } +core2 = { version = "0.4.0", default-features = false, optional = true } # Only enable this if you explicitly do not want to use "std", otherwise enable "serde-std". -serde = { version = "1.0", default-features = false, optional = true } +serde = { version = "1.0.219", default-features = false, optional = true } # Do NOT use this as a feature! Use the `schemars` feature instead. Can only be used with "std" enabled. actual-schemars = { package = "schemars", version = "<=0.8.3", optional = true } # Do NOT enable this dependency, this is just to pin dyn-clone (transitive dep from schemars) diff --git a/hashes/src/sha256.rs b/hashes/src/sha256.rs index 308c129be..7b56d8c9c 100644 --- a/hashes/src/sha256.rs +++ b/hashes/src/sha256.rs @@ -515,12 +515,6 @@ impl HashEngine { } } -impl secp256k1::ThirtyTwoByteHash for Hash { - fn into_32(self) -> [u8; 32] { - self.0 - } -} - #[cfg(test)] mod tests { use crate::{Hash, HashEngine, sha256}; diff --git a/hashes/src/sha256d.rs b/hashes/src/sha256d.rs index 7e4c393ef..956feaccd 100644 --- a/hashes/src/sha256d.rs +++ b/hashes/src/sha256d.rs @@ -41,12 +41,6 @@ fn from_engine(e: sha256::HashEngine) -> Hash { Hash(ret) } -impl secp256k1::ThirtyTwoByteHash for Hash { - fn into_32(self) -> [u8; 32] { - self.0 - } -} - #[cfg(test)] mod tests { #[test] diff --git a/rpc-client/Cargo.toml b/rpc-client/Cargo.toml index 2b926e7fd..35260fdb5 100644 --- a/rpc-client/Cargo.toml +++ b/rpc-client/Cargo.toml @@ -21,11 +21,11 @@ path = "src/lib.rs" [dependencies] dashcore-rpc-json = { path = "../rpc-json" } -log = "0.4.5" -jsonrpc = "0.14.0" +log = "0.4.27" +jsonrpc = "0.18.0" # Used for deserialization of JSON. -serde = { version = "1.0.132", features = ["derive"] } +serde = { version = "1.0.219", features = ["derive"] } serde_json = { version="1.0", features=["preserve_order"] } hex = { version="0.4", features=["serde"]} diff --git a/rpc-client/src/client.rs b/rpc-client/src/client.rs index 3072c9b6d..12b385c5f 100644 --- a/rpc-client/src/client.rs +++ b/rpc-client/src/client.rs @@ -35,7 +35,6 @@ use dashcore::{ use dashcore_rpc_json::dashcore::bls_sig_utils::BLSSignature; use dashcore_rpc_json::dashcore::{BlockHash, ChainLock}; use dashcore_rpc_json::{ProTxInfo, ProTxListType, QuorumType}; -use hex::ToHex; use log::Level::{Debug, Trace, Warn}; /// Crate-specific Result type, shorthand for `std::result::Result` with our @@ -1697,15 +1696,9 @@ impl Client { impl RpcApi for Client { /// Call an `cmd` rpc with given `args` list fn call serde::de::Deserialize<'a>>(&self, cmd: &str, args: &[Value]) -> Result { - let raw_args: Vec<_> = args - .iter() - .map(|a| { - let json_string = serde_json::to_string(a)?; - serde_json::value::RawValue::from_string(json_string) // we can't use to_raw_value here due to compat with Rust 1.29 - }) - .map(|a| a.map_err(|e| Error::Json(e))) - .collect::>>()?; - let req = self.client.build_request(&cmd, &raw_args); + let raw_args_json = serde_json::to_string(args)?; + let raw_args = Some(serde_json::value::RawValue::from_string(raw_args_json)?); + let req = self.client.build_request(&cmd, raw_args.as_deref()); if log_enabled!(Debug) { debug!(target: "dashcore_rpc", "JSON-RPC request: {} {}", cmd, serde_json::Value::from(args)); } diff --git a/rpc-json/Cargo.toml b/rpc-json/Cargo.toml index 2acd6316a..e725412b5 100644 --- a/rpc-json/Cargo.toml +++ b/rpc-json/Cargo.toml @@ -19,7 +19,7 @@ name = "dashcore_rpc_json" path = "src/lib.rs" [dependencies] -serde = { version = "1.0.132", features = ["derive"] } +serde = { version = "1.0.219", features = ["derive"] } serde_json = { version="1.0", features=["preserve_order"] } serde_with = "2.1.0" serde_repr = "0.1"