mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-14 12:43:40 +02:00
CProof (re)setting and validation helper functions
This commit is contained in:
parent
2a3dcde9ac
commit
cd4e553914
3 changed files with 90 additions and 0 deletions
|
|
@ -96,6 +96,7 @@ BITCOIN_CORE_H = \
|
||||||
bech32.h \
|
bech32.h \
|
||||||
bloom.h \
|
bloom.h \
|
||||||
blockencodings.h \
|
blockencodings.h \
|
||||||
|
block_proof.h \
|
||||||
chain.h \
|
chain.h \
|
||||||
chainparams.h \
|
chainparams.h \
|
||||||
chainparamsbase.h \
|
chainparamsbase.h \
|
||||||
|
|
@ -221,6 +222,7 @@ libbitcoin_server_a_SOURCES = \
|
||||||
addrman.cpp \
|
addrman.cpp \
|
||||||
bloom.cpp \
|
bloom.cpp \
|
||||||
blockencodings.cpp \
|
blockencodings.cpp \
|
||||||
|
block_proof.cpp \
|
||||||
chain.cpp \
|
chain.cpp \
|
||||||
checkpoints.cpp \
|
checkpoints.cpp \
|
||||||
consensus/tx_verify.cpp \
|
consensus/tx_verify.cpp \
|
||||||
|
|
|
||||||
62
src/block_proof.cpp
Normal file
62
src/block_proof.cpp
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||||
|
// Copyright (c) 2009-2018 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#include <pow.h>
|
||||||
|
|
||||||
|
#include <chain.h>
|
||||||
|
#include <primitives/block.h>
|
||||||
|
#include <script/interpreter.h>
|
||||||
|
#include <script/generic.hpp>
|
||||||
|
|
||||||
|
bool CheckChallenge(const CBlockHeader& block, const CBlockIndex& indexLast, const Consensus::Params& params)
|
||||||
|
{
|
||||||
|
if (g_signed_blocks) {
|
||||||
|
return block.proof.challenge == indexLast.proof.challenge;
|
||||||
|
} else {
|
||||||
|
return block.nBits == GetNextWorkRequired(&indexLast, &block, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetChallenge(CBlockHeader& block, const CBlockIndex& indexLast, const Consensus::Params& params)
|
||||||
|
{
|
||||||
|
block.proof.challenge = indexLast.proof.challenge;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool CheckProofGeneric(const CBlockHeader& block, const Consensus::Params& params, const CScript& challenge)
|
||||||
|
{
|
||||||
|
if (block.GetHash() == params.hashGenesisBlock)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (block.proof.solution.size() > params.max_block_signature_size) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Some anti-DoS flags, though consensus.max_block_signature_size caps the possible
|
||||||
|
// danger in malleation of the block witness data.
|
||||||
|
unsigned int proof_flags = SCRIPT_VERIFY_P2SH // For cleanstack evalution under segwit flag
|
||||||
|
| SCRIPT_VERIFY_STRICTENC // Minimally-sized DER sigs
|
||||||
|
| SCRIPT_VERIFY_NULLDUMMY // No extra data stuffed into OP_CMS witness
|
||||||
|
| SCRIPT_VERIFY_CLEANSTACK // No extra pushes leftover in witness
|
||||||
|
| SCRIPT_VERIFY_MINIMALDATA // Pushes are minimally-sized
|
||||||
|
| SCRIPT_VERIFY_SIGPUSHONLY // Witness is push-only
|
||||||
|
| SCRIPT_VERIFY_LOW_S // Stop easiest signature fiddling
|
||||||
|
| SCRIPT_VERIFY_WITNESS // Required for cleanstack eval in VerifyScript
|
||||||
|
| SCRIPT_NO_SIGHASH_BYTE; // non-Check(Multi)Sig signatures will not have sighash byte
|
||||||
|
return GenericVerifyScript(block.proof.solution, challenge, proof_flags, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CheckProof(const CBlockHeader& block, const Consensus::Params& params)
|
||||||
|
{
|
||||||
|
if (g_signed_blocks) {
|
||||||
|
return CheckProofGeneric(block, params, params.signblockscript);
|
||||||
|
} else {
|
||||||
|
return CheckProofOfWork(block.GetHash(), block.nBits, params);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetProof(CBlockHeader& block)
|
||||||
|
{
|
||||||
|
block.proof.solution.clear();
|
||||||
|
}
|
||||||
26
src/block_proof.h
Normal file
26
src/block_proof.h
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
||||||
|
// Copyright (c) 2009-2018 The Bitcoin Core developers
|
||||||
|
// Distributed under the MIT software license, see the accompanying
|
||||||
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
|
#ifndef BITCOIN_BLOCK_PROOF_H
|
||||||
|
#define BITCOIN_BLOCK_PROOF_H
|
||||||
|
|
||||||
|
#include <consensus/params.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
class CBlockHeader;
|
||||||
|
class CBlockIndex;
|
||||||
|
class CProof;
|
||||||
|
class CScript;
|
||||||
|
|
||||||
|
// Elements signed chain functionality
|
||||||
|
|
||||||
|
/** Check on header proof, depending on chain type, PoW or signed **/
|
||||||
|
bool CheckProof(const CBlockHeader& block, const Consensus::Params&);
|
||||||
|
void ResetProof(CBlockHeader& block);
|
||||||
|
bool CheckChallenge(const CBlockHeader& block, const CBlockIndex& indexLast, const Consensus::Params&);
|
||||||
|
void ResetChallenge(CBlockHeader& block, const CBlockIndex& indexLast, const Consensus::Params&);
|
||||||
|
|
||||||
|
#endif // BITCOIN_BLOCK_PROOF_H
|
||||||
Loading…
Add table
Add a link
Reference in a new issue