mirror of
https://github.com/dashpay/dash.git
synced 2024-12-29 05:49:11 +01:00
8a1ec935a0
* scripted-diff: Replace #include "" with #include <> (ryanofsky) -BEGIN VERIFY SCRIPT- for f in \ src/*.cpp \ src/*.h \ src/bench/*.cpp \ src/bench/*.h \ src/compat/*.cpp \ src/compat/*.h \ src/consensus/*.cpp \ src/consensus/*.h \ src/crypto/*.cpp \ src/crypto/*.h \ src/crypto/ctaes/*.h \ src/policy/*.cpp \ src/policy/*.h \ src/primitives/*.cpp \ src/primitives/*.h \ src/qt/*.cpp \ src/qt/*.h \ src/qt/test/*.cpp \ src/qt/test/*.h \ src/rpc/*.cpp \ src/rpc/*.h \ src/script/*.cpp \ src/script/*.h \ src/support/*.cpp \ src/support/*.h \ src/support/allocators/*.h \ src/test/*.cpp \ src/test/*.h \ src/wallet/*.cpp \ src/wallet/*.h \ src/wallet/test/*.cpp \ src/wallet/test/*.h \ src/zmq/*.cpp \ src/zmq/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT- Signed-off-by: Pasta <pasta@dashboost.org> * scripted-diff: Replace #include "" with #include <> (Dash Specific) -BEGIN VERIFY SCRIPT- for f in \ src/bls/*.cpp \ src/bls/*.h \ src/evo/*.cpp \ src/evo/*.h \ src/governance/*.cpp \ src/governance/*.h \ src/llmq/*.cpp \ src/llmq/*.h \ src/masternode/*.cpp \ src/masternode/*.h \ src/privatesend/*.cpp \ src/privatesend/*.h do base=${f%/*}/ relbase=${base#src/} sed -i "s:#include \"\(.*\)\"\(.*\):if test -e \$base'\\1'; then echo \"#include <\"\$relbase\"\\1>\\2\"; else echo \"#include <\\1>\\2\"; fi:e" $f done -END VERIFY SCRIPT- Signed-off-by: Pasta <pasta@dashboost.org> * build: Remove -I for everything but project root Remove -I from build system for everything but the project root, and built-in dependencies. Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/Makefile.test.include * qt: refactor: Use absolute include paths in .ui files * qt: refactor: Changes to make include paths absolute This makes all include paths in the GUI absolute. Many changes are involved as every single source file in src/qt/ assumes to be able to use relative includes. Signed-off-by: Pasta <pasta@dashboost.org> # Conflicts: # src/qt/dash.cpp # src/qt/optionsmodel.cpp # src/qt/test/rpcnestedtests.cpp * test: refactor: Use absolute include paths for test data files * Recommend #include<> syntax in developer notes * refactor: Include obj/build.h instead of build.h * END BACKPORT #11651 Remove trailing whitespace causing travis failure * fix backport 11651 Signed-off-by: Pasta <pasta@dashboost.org> * More of 11651 * fix blockchain.cpp Signed-off-by: pasta <pasta@dashboost.org> * Add missing "qt/" in includes * Add missing "test/" in includes * Fix trailing whitespaces Co-authored-by: Wladimir J. van der Laan <laanwj@gmail.com> Co-authored-by: Russell Yanofsky <russ@yanofsky.org> Co-authored-by: MeshCollider <dobsonsa68@gmail.com> Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
181 lines
5.8 KiB
C++
181 lines
5.8 KiB
C++
// Copyright (c) 2018-2019 The Dash Core developers
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <llmq/quorums_commitment.h>
|
|
#include <llmq/quorums_utils.h>
|
|
|
|
#include <chainparams.h>
|
|
#include <validation.h>
|
|
|
|
#include <evo/specialtx.h>
|
|
|
|
namespace llmq
|
|
{
|
|
|
|
CFinalCommitment::CFinalCommitment(const Consensus::LLMQParams& params, const uint256& _quorumHash) :
|
|
llmqType(params.type),
|
|
quorumHash(_quorumHash),
|
|
signers(params.size),
|
|
validMembers(params.size)
|
|
{
|
|
}
|
|
|
|
#define LogPrintfFinalCommitment(...) do { \
|
|
LogPrintStr(strprintf("CFinalCommitment::%s -- %s", __func__, tinyformat::format(__VA_ARGS__))); \
|
|
} while(0)
|
|
|
|
bool CFinalCommitment::Verify(const std::vector<CDeterministicMNCPtr>& members, bool checkSigs) const
|
|
{
|
|
if (nVersion == 0 || nVersion > CURRENT_VERSION) {
|
|
return false;
|
|
}
|
|
|
|
if (!Params().GetConsensus().llmqs.count((Consensus::LLMQType)llmqType)) {
|
|
LogPrintfFinalCommitment("invalid llmqType=%d\n", llmqType);
|
|
return false;
|
|
}
|
|
const auto& params = Params().GetConsensus().llmqs.at((Consensus::LLMQType)llmqType);
|
|
|
|
if (!VerifySizes(params)) {
|
|
return false;
|
|
}
|
|
|
|
if (CountValidMembers() < params.minSize) {
|
|
LogPrintfFinalCommitment("invalid validMembers count. validMembersCount=%d\n", CountValidMembers());
|
|
return false;
|
|
}
|
|
if (CountSigners() < params.minSize) {
|
|
LogPrintfFinalCommitment("invalid signers count. signersCount=%d\n", CountSigners());
|
|
return false;
|
|
}
|
|
if (!quorumPublicKey.IsValid()) {
|
|
LogPrintfFinalCommitment("invalid quorumPublicKey\n");
|
|
return false;
|
|
}
|
|
if (quorumVvecHash.IsNull()) {
|
|
LogPrintfFinalCommitment("invalid quorumVvecHash\n");
|
|
return false;
|
|
}
|
|
if (!membersSig.IsValid()) {
|
|
LogPrintfFinalCommitment("invalid membersSig\n");
|
|
return false;
|
|
}
|
|
if (!quorumSig.IsValid()) {
|
|
LogPrintfFinalCommitment("invalid vvecSig\n");
|
|
return false;
|
|
}
|
|
|
|
for (size_t i = members.size(); i < params.size; i++) {
|
|
if (validMembers[i]) {
|
|
LogPrintfFinalCommitment("invalid validMembers bitset. bit %d should not be set\n", i);
|
|
return false;
|
|
}
|
|
if (signers[i]) {
|
|
LogPrintfFinalCommitment("invalid signers bitset. bit %d should not be set\n", i);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// sigs are only checked when the block is processed
|
|
if (checkSigs) {
|
|
uint256 commitmentHash = CLLMQUtils::BuildCommitmentHash(params.type, quorumHash, validMembers, quorumPublicKey, quorumVvecHash);
|
|
|
|
std::vector<CBLSPublicKey> memberPubKeys;
|
|
for (size_t i = 0; i < members.size(); i++) {
|
|
if (!signers[i]) {
|
|
continue;
|
|
}
|
|
memberPubKeys.emplace_back(members[i]->pdmnState->pubKeyOperator.Get());
|
|
}
|
|
|
|
if (!membersSig.VerifySecureAggregated(memberPubKeys, commitmentHash)) {
|
|
LogPrintfFinalCommitment("invalid aggregated members signature\n");
|
|
return false;
|
|
}
|
|
|
|
if (!quorumSig.VerifyInsecure(quorumPublicKey, commitmentHash)) {
|
|
LogPrintfFinalCommitment("invalid quorum signature\n");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CFinalCommitment::VerifyNull() const
|
|
{
|
|
if (!Params().GetConsensus().llmqs.count((Consensus::LLMQType)llmqType)) {
|
|
LogPrintfFinalCommitment("invalid llmqType=%d\n", llmqType);
|
|
return false;
|
|
}
|
|
const auto& params = Params().GetConsensus().llmqs.at((Consensus::LLMQType)llmqType);
|
|
|
|
if (!IsNull() || !VerifySizes(params)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CFinalCommitment::VerifySizes(const Consensus::LLMQParams& params) const
|
|
{
|
|
if (signers.size() != params.size) {
|
|
LogPrintfFinalCommitment("invalid signers.size=%d\n", signers.size());
|
|
return false;
|
|
}
|
|
if (validMembers.size() != params.size) {
|
|
LogPrintfFinalCommitment("invalid signers.size=%d\n", signers.size());
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool CheckLLMQCommitment(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state)
|
|
{
|
|
CFinalCommitmentTxPayload qcTx;
|
|
if (!GetTxPayload(tx, qcTx)) {
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-qc-payload");
|
|
}
|
|
|
|
if (qcTx.nVersion == 0 || qcTx.nVersion > CFinalCommitmentTxPayload::CURRENT_VERSION) {
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-qc-version");
|
|
}
|
|
|
|
if (qcTx.nHeight != pindexPrev->nHeight + 1) {
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-qc-height");
|
|
}
|
|
|
|
if (!mapBlockIndex.count(qcTx.commitment.quorumHash)) {
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-qc-quorum-hash");
|
|
}
|
|
|
|
const CBlockIndex* pindexQuorum = mapBlockIndex[qcTx.commitment.quorumHash];
|
|
|
|
if (pindexQuorum != pindexPrev->GetAncestor(pindexQuorum->nHeight)) {
|
|
// not part of active chain
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-qc-quorum-hash");
|
|
}
|
|
|
|
if (!Params().GetConsensus().llmqs.count((Consensus::LLMQType)qcTx.commitment.llmqType)) {
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-qc-type");
|
|
}
|
|
const auto& params = Params().GetConsensus().llmqs.at((Consensus::LLMQType)qcTx.commitment.llmqType);
|
|
|
|
if (qcTx.commitment.IsNull()) {
|
|
if (!qcTx.commitment.VerifyNull()) {
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-qc-invalid-null");
|
|
}
|
|
return true;
|
|
}
|
|
|
|
auto members = CLLMQUtils::GetAllQuorumMembers(params.type, pindexQuorum);
|
|
if (!qcTx.commitment.Verify(members, false)) {
|
|
return state.DoS(100, false, REJECT_INVALID, "bad-qc-invalid");
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
} // namespace llmq
|