feat: use m_protxHash instead of masternodeOutpoint for hashing dsq and dstx after v19 activation (#5404)

## Issue being fixed or feature implemented
Should fix #5401 with minimal potential coinjoin service interruption
(~1 minute around v19 fork point) for up to date clients. Fully
backwards compatible prior to v19 activation. Old clients won't be able
to mix after v19 activation though until they implement similar changes.
_EDIT: Actually, this is already the case cause bls sigs are going to
change too._ And I think we should also be able to finally drop
`masternodeOutpoint` from `CCoinJoinQueue` and `CCoinJoinBroadcastTx`
once v19 is active because of that which would be a nice bonus.

cc @HashEngineering

## What was done?
re-use v19 activation to switch `GetSignatureHash` logic

## How Has This Been Tested?
mixing on mainnet

## Breaking Changes
mixing won't work on current testnet until MNs are updated 

## Checklist:
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
- [x] I have assigned this pull request to a milestone _(for repository
code-owners and collaborators only)_
This commit is contained in:
UdjinM6 2023-06-11 08:41:02 +03:00 committed by GitHub
parent 12d50c806d
commit 599fd87723
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 15 deletions

View File

@ -41,22 +41,22 @@ bool CCoinJoinEntry::AddScriptSig(const CTxIn& txin)
return false;
}
uint256 CCoinJoinQueue::GetSignatureHash() const
uint256 CCoinJoinQueue::GetSignatureHash(bool legacy) const
{
return SerializeHash(*this);
int version = legacy ? COINJOIN_PROTX_HASH_PROTO_VERSION - 1 : PROTOCOL_VERSION;
return SerializeHash(*this, SER_GETHASH, version);
}
bool CCoinJoinQueue::Sign()
{
if (!fMasternodeMode) return false;
uint256 hash = GetSignatureHash();
bool legacy_bls_scheme = !llmq::utils::IsV19Active(::ChainActive().Tip());
uint256 hash = GetSignatureHash(legacy_bls_scheme);
CBLSSignature sig = WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.blsKeyOperator->Sign(hash));
if (!sig.IsValid()) {
return false;
}
bool legacy_bls_scheme = !llmq::utils::IsV19Active(::ChainActive().Tip());
vchSig = sig.ToByteVector(legacy_bls_scheme);
return true;
@ -64,7 +64,8 @@ bool CCoinJoinQueue::Sign()
bool CCoinJoinQueue::CheckSignature(const CBLSPublicKey& blsPubKey) const
{
if (!CBLSSignature(vchSig).VerifyInsecure(blsPubKey, GetSignatureHash())) {
bool legacy_bls_scheme = !llmq::utils::IsV19Active(::ChainActive().Tip());
if (!CBLSSignature(vchSig).VerifyInsecure(blsPubKey, GetSignatureHash(legacy_bls_scheme))) {
LogPrint(BCLog::COINJOIN, "CCoinJoinQueue::CheckSignature -- VerifyInsecure() failed\n");
return false;
}
@ -89,21 +90,22 @@ bool CCoinJoinQueue::IsTimeOutOfBounds(int64_t current_time) const
nTime - current_time > COINJOIN_QUEUE_TIMEOUT;
}
uint256 CCoinJoinBroadcastTx::GetSignatureHash() const
uint256 CCoinJoinBroadcastTx::GetSignatureHash(bool legacy) const
{
return SerializeHash(*this);
int version = legacy ? COINJOIN_PROTX_HASH_PROTO_VERSION - 1 : PROTOCOL_VERSION;
return SerializeHash(*this, SER_GETHASH, version);
}
bool CCoinJoinBroadcastTx::Sign()
{
if (!fMasternodeMode) return false;
uint256 hash = GetSignatureHash();
bool legacy_bls_scheme = !llmq::utils::IsV19Active(::ChainActive().Tip());
uint256 hash = GetSignatureHash(legacy_bls_scheme);
CBLSSignature sig = WITH_LOCK(activeMasternodeInfoCs, return activeMasternodeInfo.blsKeyOperator->Sign(hash));
if (!sig.IsValid()) {
return false;
}
bool legacy_bls_scheme = !llmq::utils::IsV19Active(::ChainActive().Tip());
vchSig = sig.ToByteVector(legacy_bls_scheme);
return true;
@ -111,7 +113,8 @@ bool CCoinJoinBroadcastTx::Sign()
bool CCoinJoinBroadcastTx::CheckSignature(const CBLSPublicKey& blsPubKey) const
{
if (!CBLSSignature(vchSig).VerifyInsecure(blsPubKey, GetSignatureHash())) {
bool legacy_bls_scheme = !llmq::utils::IsV19Active(::ChainActive().Tip());
if (!CBLSSignature(vchSig).VerifyInsecure(blsPubKey, GetSignatureHash(legacy_bls_scheme))) {
LogPrint(BCLog::COINJOIN, "CCoinJoinBroadcastTx::CheckSignature -- VerifyInsecure() failed\n");
return false;
}

View File

@ -219,7 +219,7 @@ public:
{
READWRITE(obj.nDenom);
if (s.GetVersion() < COINJOIN_PROTX_HASH_PROTO_VERSION || (s.GetType() & SER_GETHASH)) {
if (s.GetVersion() < COINJOIN_PROTX_HASH_PROTO_VERSION) {
READWRITE(obj.masternodeOutpoint);
} else {
READWRITE(obj.m_protxHash);
@ -230,7 +230,7 @@ public:
}
}
[[nodiscard]] uint256 GetSignatureHash() const;
[[nodiscard]] uint256 GetSignatureHash(bool legacy) const;
/** Sign this mixing transaction
* return true if all conditions are met:
* 1) we have an active Masternode,
@ -292,7 +292,7 @@ public:
{
READWRITE(obj.tx);
if (s.GetVersion() < COINJOIN_PROTX_HASH_PROTO_VERSION || (s.GetType() & SER_GETHASH)) {
if (s.GetVersion() < COINJOIN_PROTX_HASH_PROTO_VERSION) {
READWRITE(obj.masternodeOutpoint);
} else {
READWRITE(obj.m_protxHash);
@ -317,7 +317,7 @@ public:
return *this != CCoinJoinBroadcastTx();
}
[[nodiscard]] uint256 GetSignatureHash() const;
[[nodiscard]] uint256 GetSignatureHash(bool legacy) const;
bool Sign();
[[nodiscard]] bool CheckSignature(const CBLSPublicKey& blsPubKey) const;