hush_checkPOW: verify RandomX at the recovered height on the peer-accept path
A block arriving over P2P reaches ProcessNewBlock(0,0,...) (the net BLOCK handler), and both CheckBlock() calls on that accept path -- in ProcessNewBlock and in AcceptBlock -- pass fCheckPOW=0, so CheckBlockHeader's RandomX check never runs there. The only real-height PoW gate before the block becomes a setBlockIndexCandidate is hush_checkPOW(0,pblock,height), and for a peer block height is 0: CheckRandomXSolution ran at height 0 (where RandomXValidationRequired is false, so it is skipped), the real height was then recovered from hashPrevBlock, but RandomX was never re-checked. So a block with a forged RandomX solution (only a grindable SHA256 target) could become a candidate with its RandomX never verified at its real height, and trip the MAX_REORG_LENGTH reorg guard before the connect-time check would reject it -- the cheap half of the reorg-shutdown DoS. Re-run CheckRandomXSolution at the recovered height before returning. It is a no-op wherever the first call was (algo gate, activation height -- regtest is far below it -- HUSH_LOADINGBLOCKS during IBD/reindex, the last in-index checkpoint, and the thread-local miner self-check skip), so it only adds one light-mode verification on the height==0 peer-accept path, which previously did no real-height RandomX work at all. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1713,6 +1713,22 @@ int32_t hush_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height)
|
||||
height = pprev->GetHeight() + 1;
|
||||
if ( height == 0 )
|
||||
return(0);
|
||||
// The CheckRandomXSolution() above ran with height==0, where RandomXValidationRequired(0)
|
||||
// is false, so RandomX was NOT verified. Re-verify now that the real height is recovered
|
||||
// from hashPrevBlock. Without this, a peer block entering via ProcessNewBlock(0,0,...) (the
|
||||
// net BLOCK handler, main.cpp) becomes a setBlockIndexCandidate with its PoW never checked
|
||||
// at its real height: both CheckBlock() calls on that accept path pass fCheckPOW=0, so
|
||||
// CheckBlockHeader's RandomX check never runs there -- this hush_checkPOW(0,...) is the ONLY
|
||||
// real-height PoW gate before candidacy. A forged-RandomX fork could then trip the reorg
|
||||
// guard before the connect-time check rejects it. This is a no-op wherever the first call
|
||||
// was already a no-op: RandomXValidationRequired() gates on algo, the activation height
|
||||
// (regtest heights are far below it), HUSH_LOADINGBLOCKS (IBD/reindex), and the last
|
||||
// in-index checkpoint, and the thread-local fSkipRandomXValidation still skips the miner self-check.
|
||||
if ( !CheckRandomXSolution(pblock, height) )
|
||||
{
|
||||
fprintf(stderr,"hush_checkPOW slowflag.%d ht.%d CheckRandomXSolution failed (post height-recovery)\n",slowflag,height);
|
||||
return(-1);
|
||||
}
|
||||
}
|
||||
|
||||
if ( (SMART_CHAIN_SYMBOL[0] != 0) && bhash > bnTarget ) {
|
||||
|
||||
Reference in New Issue
Block a user