Skip to content

Commit 5442657

Browse files
committed
Reuse block signing code for signet and elements
1 parent 008a542 commit 5442657

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

src/pow.cpp

+24-2
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,38 @@ void ResetChallenge(CBlockHeader& block, const CBlockIndex& indexLast, const Con
3838
block.proof.challenge = indexLast.proof.challenge;
3939
}
4040

41-
bool CheckBitcoinProof(uint256 hash, unsigned int nBits)
41+
static const unsigned int BLOCK_VERIFY_FLAGS = MANDATORY_SCRIPT_VERIFY_FLAGS |
42+
SCRIPT_VERIFY_DERSIG |
43+
SCRIPT_VERIFY_STRICTENC |
44+
SCRIPT_VERIFY_MINIMALDATA |
45+
SCRIPT_VERIFY_NULLDUMMY |
46+
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS |
47+
SCRIPT_VERIFY_CLEANSTACK |
48+
SCRIPT_VERIFY_MINIMALIF |
49+
SCRIPT_VERIFY_NULLFAIL |
50+
SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY |
51+
SCRIPT_VERIFY_CHECKSEQUENCEVERIFY |
52+
SCRIPT_VERIFY_LOW_S |
53+
SCRIPT_VERIFY_WITNESS |
54+
SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM |
55+
SCRIPT_VERIFY_WITNESS_PUBKEYTYPE;
56+
57+
bool CheckBitcoinProof(const uint256& hash, unsigned int nBits, const Consensus::Params& params)
4258
{
59+
if (g_solution_blocks) {
60+
const auto& payload = g_blockheader_payload_map.at(hash);
61+
CScript solution = CScript(payload.begin(), payload.end());
62+
return HashVerifyScript(solution, params.parent_chain_signblockscript, BLOCK_VERIFY_FLAGS, hash);
63+
}
64+
4365
bool fNegative;
4466
bool fOverflow;
4567
arith_uint256 bnTarget;
4668

4769
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
4870

4971
// Check range
50-
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(Params().GetConsensus().parentChainPowLimit))
72+
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.parentChainPowLimit))
5173
return false;
5274

5375
// Check proof of work matches claimed amount

src/pow.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class CWallet;
2020
class uint256;
2121

2222
/** Check whether a block hash satisfies the proof-of-work requirement specified by nBits */
23-
bool CheckBitcoinProof(uint256 hash, unsigned int nBits);
23+
bool CheckBitcoinProof(const uint256& hash, unsigned int nBits, const Consensus::Params& params);
2424
bool CheckProofSignedParent(const CBlockHeader& block, const Consensus::Params& params);
2525
bool CheckProof(const CBlockHeader& block, const Consensus::Params&);
2626
/** Scans nonces looking for a hash with at least some zero bits */

src/script/generic.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ bool GenericVerifyScript(const CScript& scriptSig, const CScript& scriptPubKey,
4949
return VerifyScript(scriptSig, scriptPubKey, NULL, flags, SimpleSignatureChecker(SerializeHash(data)));
5050
}
5151

52+
bool HashVerifyScript(const CScript& scriptSig, const CScript& scriptPubKey, unsigned int flags, const uint256& hash)
53+
{
54+
return VerifyScript(scriptSig, scriptPubKey, NULL, flags, SimpleSignatureChecker(hash));
55+
}
56+
5257
template<typename T>
5358
bool GenericSignScript(const CKeyStore& keystore, const T& data, const CScript& fromPubKey, SignatureData& scriptSig)
5459
{

src/validation.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2539,7 +2539,7 @@ bool IsValidPeginWitness(const CScriptWitness& pegin_witness, const COutPoint& p
25392539
if (!GetBlockAndTxFromMerkleBlock(block_hash, tx_hash, merkle_block_pow, stack[5])) {
25402540
return false;
25412541
}
2542-
if (!CheckBitcoinProof(block_hash, merkle_block_pow.header.nBits)) {
2542+
if (!CheckBitcoinProof(block_hash, merkle_block_pow.header.nBits, Params().GetConsensus())) {
25432543
return false;
25442544
}
25452545

src/wallet/rpcwallet.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3721,7 +3721,7 @@ UniValue createrawpegin(const JSONRPCRequest& request)
37213721
Sidechain::Bitcoin::CTransaction tx_aux;
37223722
Sidechain::Bitcoin::CMerkleBlock merkleBlock;
37233723
ret = createrawpegin(request, txBTCRef, tx_aux, merkleBlock);
3724-
if (!CheckBitcoinProof(merkleBlock.header.GetHash(), merkleBlock.header.nBits)) {
3724+
if (!CheckBitcoinProof(merkleBlock.header.GetHash(), merkleBlock.header.nBits, Params().GetConsensus())) {
37253725
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid tx out proof");
37263726
}
37273727
} else {

0 commit comments

Comments
 (0)