mirror of
https://github.com/dogecoin/dogecoin.git
synced 2026-01-31 10:30:52 +00:00
Check auxpow PoW before the auxpow itself.
This reverses the order in which the auxpow structure and the PoW on it are verified. By checking the PoW first, we make it harder for random nodes to pass data of their choosing into CAuxPow::check. Cherry-picked from: 51cbc1fd GitHub Pull Request: #3725
This commit is contained in:
parent
cebc99a4ec
commit
b85849d0d6
@ -101,6 +101,10 @@ CAuxPow::check(const uint256& hashAuxBlock, int nChainId,
|
||||
!= parentBlock.hashMerkleRoot)
|
||||
return error("Aux POW merkle root incorrect");
|
||||
|
||||
// Check that there is at least one input.
|
||||
if (tx->vin.empty())
|
||||
return error("Aux POW coinbase has no inputs");
|
||||
|
||||
const CScript script = tx->vin[0].scriptSig;
|
||||
|
||||
// Check that the same work is not submitted twice to our chain.
|
||||
|
||||
@ -115,11 +115,12 @@ bool CheckAuxPowProofOfWork(const CBlockHeader& block, const Consensus::Params&
|
||||
if (!block.IsAuxpow())
|
||||
return error("%s : auxpow on block with non-auxpow version", __func__);
|
||||
|
||||
if (!block.auxpow->check(block.GetHash(), block.GetChainId(), params))
|
||||
return error("%s : AUX POW is not valid", __func__);
|
||||
if (!CheckProofOfWork(block.auxpow->getParentBlockPoWHash(), block.nBits, params))
|
||||
return error("%s : AUX proof of work failed", __func__);
|
||||
|
||||
if (!block.auxpow->check(block.GetHash(), block.GetChainId(), params))
|
||||
return error("%s : AUX POW is not valid", __func__);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -203,6 +203,15 @@ BOOST_AUTO_TEST_CASE(check_auxpow)
|
||||
builder.setCoinbase(scr);
|
||||
BOOST_CHECK(builder.get().check(hashAux, ourChainId, params));
|
||||
|
||||
/* An auxpow without any inputs in the parent coinbase tx should be
|
||||
handled gracefully (and be considered invalid). */
|
||||
CMutableTransaction mtx(*builder.parentBlock.vtx[0]);
|
||||
mtx.vin.clear();
|
||||
builder.parentBlock.vtx.clear();
|
||||
builder.parentBlock.vtx.push_back (MakeTransactionRef(std::move (mtx)));
|
||||
builder.parentBlock.hashMerkleRoot = BlockMerkleRoot(builder.parentBlock);
|
||||
BOOST_CHECK(!builder.get().check(hashAux, ourChainId, params));
|
||||
|
||||
/* Check that the auxpow is invalid if we change either the aux block's
|
||||
hash or the chain ID. */
|
||||
uint256 modifiedAux(hashAux);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user