Skip to content

Commit ed45bf8

Browse files
fix: update feed quorum info to no longer give an error if there are no chain lock signatures. (#71)
* update json library * fix * bump version
1 parent cbe12c1 commit ed45bf8

File tree

15 files changed

+46
-90
lines changed

15 files changed

+46
-90
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ members = ["dash", "hashes", "internals", "fuzz", "rpc-client", "rpc-json", "rpc
33
resolver = "2"
44

55
[workspace.package]
6-
version = "0.39.3"
6+
version = "0.39.4"
77

88
[patch.crates-io.dashcore_hashes]
99
path = "hashes"

dash/src/blockdata/script/push_bytes.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ pub use primitive::*;
99
use crate::prelude::*;
1010

1111
/// This module only contains required operations so that outside functions wouldn't accidentally
12-
/// break invariants. Therefore auditing this module should be sufficient.
12+
/// break invariants. Therefore, auditing this module should be sufficient.
1313
mod primitive {
1414
use core::convert::{TryFrom, TryInto};
15-
#[cfg(feature = "rust_v_1_53")]
16-
use core::ops::Bound;
1715
use core::ops::{
1816
Index, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive,
1917
};
@@ -54,7 +52,7 @@ mod primitive {
5452
///
5553
/// The caller is responsible for checking that the length is less than the [`LIMIT`].
5654
unsafe fn from_slice_unchecked(bytes: &[u8]) -> &Self {
57-
&*(bytes as *const [u8] as *const PushBytes)
55+
unsafe { &*(bytes as *const [u8] as *const PushBytes) }
5856
}
5957

6058
/// Creates `&mut Self` without checking the length.
@@ -63,7 +61,7 @@ mod primitive {
6361
///
6462
/// The caller is responsible for checking that the length is less than the [`LIMIT`].
6563
unsafe fn from_mut_slice_unchecked(bytes: &mut [u8]) -> &mut Self {
66-
&mut *(bytes as *mut [u8] as *mut PushBytes)
64+
unsafe { &mut *(bytes as *mut [u8] as *mut PushBytes) }
6765
}
6866

6967
/// Creates an empty `PushBytes`.
@@ -111,9 +109,6 @@ mod primitive {
111109
RangeInclusive<usize>,
112110
RangeToInclusive<usize>
113111
);
114-
#[cfg(feature = "rust_v_1_53")]
115-
#[cfg_attr(docsrs, doc(cfg(feature = "rust_v_1_53")))]
116-
delegate_index!((Bound<usize>, Bound<usize>));
117112

118113
impl Index<usize> for PushBytes {
119114
type Output = u8;

dash/src/consensus/encode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ impl<T: Encodable> Encodable for rc::Rc<T> {
892892
}
893893

894894
/// Note: This will fail to compile on old Rust for targets that don't support atomics
895-
#[cfg(any(not(rust_v_1_60), target_has_atomic = "ptr"))]
895+
#[cfg(target_has_atomic = "ptr")]
896896
impl<T: Encodable> Encodable for sync::Arc<T> {
897897
fn consensus_encode<W: io::Write + ?Sized>(&self, w: &mut W) -> Result<usize, io::Error> {
898898
(**self).consensus_encode(w)

dash/src/crypto/sighash.rs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,6 @@ pub(crate) const UINT256_ONE: [u8; 32] = [
3636
0, 0, 0, 0, 0, 0, 0, 0
3737
];
3838

39-
macro_rules! impl_thirty_two_byte_hash {
40-
($ty:ident) => {
41-
impl secp256k1::ThirtyTwoByteHash for $ty {
42-
fn into_32(self) -> [u8; 32] {
43-
self.to_byte_array()
44-
}
45-
}
46-
};
47-
}
48-
4939
hash_newtype! {
5040
/// Hash of a transaction according to the legacy signature algorithm.
5141
#[hash_newtype(forward)]
@@ -56,9 +46,6 @@ hash_newtype! {
5646
pub struct SegwitV0Sighash(sha256d::Hash);
5747
}
5848

59-
impl_thirty_two_byte_hash!(LegacySighash);
60-
impl_thirty_two_byte_hash!(SegwitV0Sighash);
61-
6249
sha256t_hash_newtype! {
6350
pub struct TapSighashTag = hash_str("TapSighash");
6451

@@ -69,8 +56,6 @@ sha256t_hash_newtype! {
6956
pub struct TapSighash(_);
7057
}
7158

72-
impl_thirty_two_byte_hash!(TapSighash);
73-
7459
/// Efficiently calculates signature hash message for legacy, segwit and taproot inputs.
7560
#[derive(Debug)]
7661
pub struct SighashCache<T: Borrow<Transaction>> {
@@ -1723,7 +1708,7 @@ mod tests {
17231708
.taproot_signature_hash(tx_ind, &Prevouts::All(&utxos), None, None, hash_ty)
17241709
.unwrap();
17251710

1726-
let msg = secp256k1::Message::from(sighash);
1711+
let msg = secp256k1::Message::from_digest(sighash.to_byte_array());
17271712
let key_spend_sig =
17281713
secp.sign_schnorr_with_aux_rand(msg.as_ref(), &tweaked_keypair, &[0u8; 32]);
17291714

dash/src/psbt/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ use core::{cmp, fmt};
1111
#[cfg(feature = "std")]
1212
use std::collections::{HashMap, HashSet};
1313

14-
use internals::write_err;
15-
use secp256k1::{Message, Secp256k1, Signing};
16-
1714
use crate::Amount;
1815
use crate::bip32::{self, ExtendedPrivKey, ExtendedPubKey, KeySource};
1916
use crate::blockdata::script::ScriptBuf;
@@ -24,6 +21,9 @@ use crate::crypto::key::{PrivateKey, PublicKey};
2421
use crate::prelude::*;
2522
pub use crate::sighash::Prevouts;
2623
use crate::sighash::{self, EcdsaSighashType, SighashCache};
24+
use hashes::Hash;
25+
use internals::write_err;
26+
use secp256k1::{Message, Secp256k1, Signing};
2727

2828
#[macro_use]
2929
mod macros;
@@ -333,20 +333,20 @@ impl PartiallySignedTransaction {
333333
match self.output_type(input_index)? {
334334
Bare => {
335335
let sighash = cache.legacy_signature_hash(input_index, spk, hash_ty.to_u32())?;
336-
Ok((Message::from(sighash), hash_ty))
336+
Ok((Message::from_digest(sighash.to_byte_array()), hash_ty))
337337
}
338338
Sh => {
339339
let script_code =
340340
input.redeem_script.as_ref().ok_or(SignError::MissingRedeemScript)?;
341341
let sighash =
342342
cache.legacy_signature_hash(input_index, script_code, hash_ty.to_u32())?;
343-
Ok((Message::from(sighash), hash_ty))
343+
Ok((Message::from_digest(sighash.to_byte_array()), hash_ty))
344344
}
345345
Wpkh => {
346346
let script_code = ScriptBuf::p2wpkh_script_code(spk).ok_or(SignError::NotWpkh)?;
347347
let sighash =
348348
cache.segwit_signature_hash(input_index, &script_code, utxo.value, hash_ty)?;
349-
Ok((Message::from(sighash), hash_ty))
349+
Ok((Message::from_digest(sighash.to_byte_array()), hash_ty))
350350
}
351351
ShWpkh => {
352352
let script_code = ScriptBuf::p2wpkh_script_code(
@@ -355,14 +355,14 @@ impl PartiallySignedTransaction {
355355
.ok_or(SignError::NotWpkh)?;
356356
let sighash =
357357
cache.segwit_signature_hash(input_index, &script_code, utxo.value, hash_ty)?;
358-
Ok((Message::from(sighash), hash_ty))
358+
Ok((Message::from_digest(sighash.to_byte_array()), hash_ty))
359359
}
360360
Wsh | ShWsh => {
361361
let script_code =
362362
input.witness_script.as_ref().ok_or(SignError::MissingWitnessScript)?;
363363
let sighash =
364364
cache.segwit_signature_hash(input_index, script_code, utxo.value, hash_ty)?;
365-
Ok((Message::from(sighash), hash_ty))
365+
Ok((Message::from_digest(sighash.to_byte_array()), hash_ty))
366366
}
367367
Tr => {
368368
// This PSBT signing API is WIP, taproot to come shortly.

dash/src/sign_message.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub const DASH_SIGNED_MSG_PREFIX: &[u8] = b"\x19DarkCoin Signed Message:\n";
3434
mod message_signing {
3535
use core::fmt;
3636

37-
use hashes::sha256d;
37+
use hashes::{Hash, sha256d};
3838
use internals::write_err;
3939
use secp256k1;
4040
use secp256k1::ecdsa::{RecoverableSignature, RecoveryId};
@@ -153,7 +153,7 @@ mod message_signing {
153153
secp_ctx: &secp256k1::Secp256k1<C>,
154154
msg_hash: sha256d::Hash,
155155
) -> Result<PublicKey, MessageSignatureError> {
156-
let msg = secp256k1::Message::from(msg_hash);
156+
let msg = secp256k1::Message::from_digest(msg_hash.to_byte_array());
157157
let pubkey = secp_ctx.recover_ecdsa(&msg, &self.signature)?;
158158
Ok(PublicKey {
159159
inner: pubkey,
@@ -252,18 +252,18 @@ mod tests {
252252

253253
let secp = secp256k1::Secp256k1::new();
254254
let message = "rust-dash MessageSignature test";
255-
let msg_hash = super::signed_msg_hash(message);
256-
let msg = secp256k1::Message::from(msg_hash);
255+
let msg_hash = signed_msg_hash(message);
256+
let msg = secp256k1::Message::from_digest(msg_hash.to_byte_array());
257257

258258
let privkey = secp256k1::SecretKey::new(&mut secp256k1::rand::thread_rng());
259259
let secp_sig = secp.sign_ecdsa_recoverable(&msg, &privkey);
260-
let signature = super::MessageSignature {
260+
let signature = MessageSignature {
261261
signature: secp_sig,
262262
compressed: true,
263263
};
264264

265265
assert_eq!(signature.to_base64(), signature.to_string());
266-
let signature2 = super::MessageSignature::from_str(&signature.to_string()).unwrap();
266+
let signature2 = MessageSignature::from_str(&signature.to_string()).unwrap();
267267
let pubkey = signature2.recover_pubkey(&secp, msg_hash).unwrap();
268268
assert!(pubkey.compressed);
269269
assert_eq!(pubkey.inner, secp256k1::PublicKey::from_secret_key(&secp, &privkey));

dash/src/sml/masternode_list_engine/mod.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -444,13 +444,7 @@ impl MasternodeListEngine {
444444

445445
self.known_snapshots
446446
.insert(mn_list_diff_at_h_minus_3c.block_hash, quorum_snapshot_at_h_minus_3c);
447-
let mn_list_diff_at_h_minus_3c_block_hash = mn_list_diff_at_h_minus_3c.block_hash;
448-
self.apply_diff(mn_list_diff_at_h_minus_3c, None, false, None)?.ok_or(
449-
QuorumValidationError::RequiredRotatedChainLockSigNotPresent(
450-
3,
451-
mn_list_diff_at_h_minus_3c_block_hash,
452-
),
453-
)?;
447+
self.apply_diff(mn_list_diff_at_h_minus_3c, None, false, None)?;
454448
self.known_snapshots
455449
.insert(mn_list_diff_at_h_minus_2c.block_hash, quorum_snapshot_at_h_minus_2c);
456450
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 {
462456
let mn_list_diff_at_h_block_hash = mn_list_diff_h.block_hash;
463457
let maybe_sigm0 = self.apply_diff(mn_list_diff_h, None, false, None)?;
464458

465-
let sigs = if maybe_sigm2.is_some() && maybe_sigm1.is_some() && maybe_sigm0.is_some() {
466-
Some([maybe_sigm2.unwrap(), maybe_sigm1.unwrap(), maybe_sigm0.unwrap()])
467-
} else {
468-
None
459+
let sigs = match (maybe_sigm2, maybe_sigm1, maybe_sigm0) {
460+
(Some(s2), Some(s1), Some(s0)) => Some([s2, s1, s0]),
461+
_ => None,
469462
};
470463

471464
let mn_list_diff_tip_block_hash = mn_list_diff_tip.block_hash;
472-
let sigmtip = self
473-
.apply_diff(mn_list_diff_tip, None, verify_tip_non_rotated_quorums, sigs)?
474-
.ok_or(QuorumValidationError::RequiredRotatedChainLockSigNotPresent(
475-
0,
476-
mn_list_diff_tip_block_hash,
477-
))?;
465+
let maybe_sigmtip =
466+
self.apply_diff(mn_list_diff_tip, None, verify_tip_non_rotated_quorums, sigs)?;
478467

479468
let qualified_last_commitment_per_index = last_commitment_per_index
480469
.into_iter()
@@ -486,24 +475,30 @@ impl MasternodeListEngine {
486475
} else {
487476
let sigm2 = maybe_sigm2.ok_or(
488477
QuorumValidationError::RequiredRotatedChainLockSigNotPresent(
489-
2,
478+
3,
490479
mn_list_diff_at_h_minus_2c_block_hash,
491480
),
492481
)?;
493482

494483
let sigm1 = maybe_sigm1.ok_or(
495484
QuorumValidationError::RequiredRotatedChainLockSigNotPresent(
496-
1,
485+
2,
497486
mn_list_diff_at_h_minus_c_block_hash,
498487
),
499488
)?;
500489

501490
let sigm0 = maybe_sigm0.ok_or(
502491
QuorumValidationError::RequiredRotatedChainLockSigNotPresent(
503-
0,
492+
1,
504493
mn_list_diff_at_h_block_hash,
505494
),
506495
)?;
496+
let sigmtip = maybe_sigmtip.ok_or(
497+
QuorumValidationError::RequiredRotatedChainLockSigNotPresent(
498+
0,
499+
mn_list_diff_tip_block_hash,
500+
),
501+
)?;
507502
let mut qualified_quorum_entry: QualifiedQuorumEntry = quorum_entry.into();
508503
qualified_quorum_entry.verifying_chain_lock_signature =
509504
Some(VerifyingChainLockSignaturesType::Rotating([

fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ cargo-fuzz = true
1212
honggfuzz = { version = "0.5", default-features = false }
1313
dashcore = { path = "../dash", features = [ "serde" ] }
1414

15-
serde = { version = "1.0.103", features = [ "derive" ] }
15+
serde = { version = "1.0.219", features = [ "derive" ] }
1616
serde_json = "1.0"
1717
serde_cbor = "0.9"
1818

fuzz/generate-files.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cargo-fuzz = true
2323
honggfuzz = { version = "0.5", default-features = false }
2424
dash = { path = "../dash", features = [ "serde" ] }
2525
26-
serde = { version = "1.0.103", features = [ "derive" ] }
26+
serde = { version = "1.0.219", features = [ "derive" ] }
2727
serde_json = "1.0"
2828
serde_cbor = "0.9"
2929
EOF

hashes/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ rustdoc-args = ["--cfg", "docsrs"]
2727
[dependencies]
2828
internals = { path = "../internals", package = "dashcore-private" }
2929

30-
core2 = { version = "0.3.0", default-features = false, optional = true }
30+
core2 = { version = "0.4.0", default-features = false, optional = true }
3131
# Only enable this if you explicitly do not want to use "std", otherwise enable "serde-std".
32-
serde = { version = "1.0", default-features = false, optional = true }
32+
serde = { version = "1.0.219", default-features = false, optional = true }
3333
# Do NOT use this as a feature! Use the `schemars` feature instead. Can only be used with "std" enabled.
3434
actual-schemars = { package = "schemars", version = "<=0.8.3", optional = true }
3535
# Do NOT enable this dependency, this is just to pin dyn-clone (transitive dep from schemars)

0 commit comments

Comments
 (0)