Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 3 additions & 8 deletions dash/src/blockdata/script/push_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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.
Expand All @@ -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`.
Expand Down Expand Up @@ -111,9 +109,6 @@ mod primitive {
RangeInclusive<usize>,
RangeToInclusive<usize>
);
#[cfg(feature = "rust_v_1_53")]
#[cfg_attr(docsrs, doc(cfg(feature = "rust_v_1_53")))]
delegate_index!((Bound<usize>, Bound<usize>));

impl Index<usize> for PushBytes {
type Output = u8;
Expand Down
2 changes: 1 addition & 1 deletion dash/src/consensus/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ impl<T: Encodable> Encodable for rc::Rc<T> {
}

/// 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<T: Encodable> Encodable for sync::Arc<T> {
fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
(**self).consensus_encode(w)
Expand Down
17 changes: 1 addition & 16 deletions dash/src/crypto/sighash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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");

Expand All @@ -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<T: Borrow<Transaction>> {
Expand Down Expand Up @@ -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]);

Expand Down
16 changes: 8 additions & 8 deletions dash/src/psbt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions dash/src/sign_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -153,7 +153,7 @@ mod message_signing {
secp_ctx: &secp256k1::Secp256k1<C>,
msg_hash: sha256d::Hash,
) -> Result<PublicKey, MessageSignatureError> {
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,
Expand Down Expand Up @@ -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));
Expand Down
35 changes: 15 additions & 20 deletions dash/src/sml/masternode_list_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand All @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion fuzz/generate-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions hashes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions hashes/src/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
6 changes: 0 additions & 6 deletions hashes/src/sha256d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 3 additions & 3 deletions rpc-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
13 changes: 3 additions & 10 deletions rpc-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1697,15 +1696,9 @@ impl Client {
impl RpcApi for Client {
/// Call an `cmd` rpc with given `args` list
fn call<T: for<'a> serde::de::Deserialize<'a>>(&self, cmd: &str, args: &[Value]) -> Result<T> {
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::<Result<Vec<_>>>()?;
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));
}
Expand Down
2 changes: 1 addition & 1 deletion rpc-json/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading