Skip to content

Commit

Permalink
Merge pull request dogecoin#3725 from patricklodder/bugfix/auxpow-che…
Browse files Browse the repository at this point in the history
…ck-order

Check auxpow PoW before the auxpow itself.
  • Loading branch information
michilumin authored Nov 30, 2024
2 parents b4a5d2b + 51cbc1f commit e0a8637
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/auxpow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions src/dogecoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions src/test/auxpow_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e0a8637

Please sign in to comment.