Skip to content

Commit 28f530c

Browse files
committed
Reuse block signing code for signet and elements
It won't work unless bitcoin/bitcoin@e416403#r30586628 is addressed In... bool BlockSignatureCreator::CreateSig(const SigningProvider& provider, std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const 46+ vchSig.push_back((unsigned char)SIGHASH_ALL); "If we don't push here we don't need to pop in e416403#diff-be2905e2f5218ecdbe4e55637dac75f3R1430 do we?"
1 parent 34ceacb commit 28f530c

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

src/pow.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,39 @@ 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+
if (hash == params.hashGenesisBlock) return true;
61+
const auto& payload = g_blockheader_payload_map.at(hash);
62+
CScript solution = CScript(payload.begin(), payload.end());
63+
return HashVerifyScript(solution, params.parent_chain_signblockscript, BLOCK_VERIFY_FLAGS, hash);
64+
}
65+
4366
bool fNegative;
4467
bool fOverflow;
4568
arith_uint256 bnTarget;
4669

4770
bnTarget.SetCompact(nBits, &fNegative, &fOverflow);
4871

4972
// Check range
50-
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(Params().GetConsensus().parentChainPowLimit))
73+
if (fNegative || bnTarget == 0 || fOverflow || bnTarget > UintToArith256(params.parentChainPowLimit))
5174
return false;
5275

5376
// Check proof of work matches claimed amount

src/pow.h

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3717,7 +3717,7 @@ UniValue createrawpegin(const JSONRPCRequest& request)
37173717
Sidechain::Bitcoin::CTransaction tx_aux;
37183718
Sidechain::Bitcoin::CMerkleBlock merkleBlock;
37193719
ret = createrawpegin(request, txBTCRef, tx_aux, merkleBlock);
3720-
if (!CheckBitcoinProof(merkleBlock.header.GetHash(), merkleBlock.header.nBits)) {
3720+
if (!CheckBitcoinProof(merkleBlock.header.GetHash(), merkleBlock.header.nBits, Params().GetConsensus())) {
37213721
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid tx out proof");
37223722
}
37233723
} else {

0 commit comments

Comments
 (0)