mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-21 07:39:08 +01:00
Merge #18267: BIP-325: Signet [consensus]
8258c4c007test: some sanity checks for consensus logic (Anthony Towns)e47ad375bftest: basic signet tests (Karl-Johan Alm)4c189abdc4test: add small signet fuzzer (practicalswift)ec9b25d046test: signet network selection tests (Karl-Johan Alm)3efe298dccsignet: hard-coded parameters for Signet Global Network VI (2020-09-07) (Karl-Johan Alm)c7898bca4eqt: update QT to support signet network (Karl-Johan Alm)a8de47a1c9consensus: add signet validation (Karl-Johan Alm)e8990f1214add signet chain and accompanying parameters (Karl-Johan Alm)404682b7cdadd signet basic support (signet.cpp) (Karl-Johan Alm)a2147d7dadvalidation: move GetWitnessCommitmentIndex to consensus/validation (Karl-Johan Alm) Pull request description: This PR is a part of BIP-325 (https://github.com/bitcoin/bips/blob/master/bip-0325.mediawiki), and is a sub-PR of #16411. * Signet consensus (this) * Signet RPC tools (pending) * Signet utility scripts (contrib/signet) (pending) ACKs for top commit: jonatack: re-ACK8258c4c007per `git diff dbeea65 8258c4c`, only change since last review is updated `-signet*` config option naming. fjahr: re-ACK8258c4claanwj: ACK8258c4c007MarcoFalke: Approach ACK8258c4c007🌵 Tree-SHA512: 5d158add96755910837feafa8214e13695b769a6aec3a2da753cf672618bef377fac43b0f4b772a87b25dd9f0c1c9b29f2789785d7a7d47a155cdcf48f7c975d
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include <script/script.h>
|
||||
#include <script/sigcache.h>
|
||||
#include <shutdown.h>
|
||||
#include <signet.h>
|
||||
#include <timedata.h>
|
||||
#include <tinyformat.h>
|
||||
#include <txdb.h>
|
||||
@@ -1169,6 +1170,11 @@ bool ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos, const Consensus::P
|
||||
if (!CheckProofOfWork(block.GetHash(), block.nBits, consensusParams))
|
||||
return error("ReadBlockFromDisk: Errors in block header at %s", pos.ToString());
|
||||
|
||||
// Signet only: check block solution
|
||||
if (consensusParams.signet_blocks && !CheckSignetBlockSolution(block, consensusParams)) {
|
||||
return error("ReadBlockFromDisk: Errors in block solution at %s", pos.ToString());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3346,6 +3352,11 @@ bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensu
|
||||
if (!CheckBlockHeader(block, state, consensusParams, fCheckPOW))
|
||||
return false;
|
||||
|
||||
// Signet only: check block solution
|
||||
if (consensusParams.signet_blocks && fCheckPOW && !CheckSignetBlockSolution(block, consensusParams)) {
|
||||
return state.Invalid(BlockValidationResult::BLOCK_CONSENSUS, "bad-signet-blksig", "signet block signature validation failure");
|
||||
}
|
||||
|
||||
// Check the merkle root.
|
||||
if (fCheckMerkleRoot) {
|
||||
bool mutated;
|
||||
@@ -3409,31 +3420,11 @@ bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& pa
|
||||
return (height >= params.SegwitHeight);
|
||||
}
|
||||
|
||||
int GetWitnessCommitmentIndex(const CBlock& block)
|
||||
{
|
||||
int commitpos = -1;
|
||||
if (!block.vtx.empty()) {
|
||||
for (size_t o = 0; o < block.vtx[0]->vout.size(); o++) {
|
||||
const CTxOut& vout = block.vtx[0]->vout[o];
|
||||
if (vout.scriptPubKey.size() >= MINIMUM_WITNESS_COMMITMENT &&
|
||||
vout.scriptPubKey[0] == OP_RETURN &&
|
||||
vout.scriptPubKey[1] == 0x24 &&
|
||||
vout.scriptPubKey[2] == 0xaa &&
|
||||
vout.scriptPubKey[3] == 0x21 &&
|
||||
vout.scriptPubKey[4] == 0xa9 &&
|
||||
vout.scriptPubKey[5] == 0xed) {
|
||||
commitpos = o;
|
||||
}
|
||||
}
|
||||
}
|
||||
return commitpos;
|
||||
}
|
||||
|
||||
void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams)
|
||||
{
|
||||
int commitpos = GetWitnessCommitmentIndex(block);
|
||||
static const std::vector<unsigned char> nonce(32, 0x00);
|
||||
if (commitpos != -1 && IsWitnessEnabled(pindexPrev, consensusParams) && !block.vtx[0]->HasWitness()) {
|
||||
if (commitpos != NO_WITNESS_COMMITMENT && IsWitnessEnabled(pindexPrev, consensusParams) && !block.vtx[0]->HasWitness()) {
|
||||
CMutableTransaction tx(*block.vtx[0]);
|
||||
tx.vin[0].scriptWitness.stack.resize(1);
|
||||
tx.vin[0].scriptWitness.stack[0] = nonce;
|
||||
@@ -3447,7 +3438,7 @@ std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBloc
|
||||
int commitpos = GetWitnessCommitmentIndex(block);
|
||||
std::vector<unsigned char> ret(32, 0x00);
|
||||
if (consensusParams.SegwitHeight != std::numeric_limits<int>::max()) {
|
||||
if (commitpos == -1) {
|
||||
if (commitpos == NO_WITNESS_COMMITMENT) {
|
||||
uint256 witnessroot = BlockWitnessMerkleRoot(block, nullptr);
|
||||
CHash256().Write(witnessroot).Write(ret).Finalize(witnessroot);
|
||||
CTxOut out;
|
||||
@@ -3585,7 +3576,7 @@ static bool ContextualCheckBlock(const CBlock& block, BlockValidationState& stat
|
||||
bool fHaveWitness = false;
|
||||
if (nHeight >= consensusParams.SegwitHeight) {
|
||||
int commitpos = GetWitnessCommitmentIndex(block);
|
||||
if (commitpos != -1) {
|
||||
if (commitpos != NO_WITNESS_COMMITMENT) {
|
||||
bool malleated = false;
|
||||
uint256 hashWitness = BlockWitnessMerkleRoot(block, &malleated);
|
||||
// The malleation check is ignored; as the transaction tree itself
|
||||
|
||||
Reference in New Issue
Block a user