src/miner.cpp
//
// ScanScryptHash scans nonces looking for a scrypt hash with many zero bits
//
ScanScryptHash scans nonces looking for a scrypt hash with many zero bits
ScanScryptHash scans nonces looking for a scrypt hash with many zero bits
bool static ScanScryptHash( CBlockHeader blockHeader, uint32_t & nNonce, uint256 * phash,
                            const arith_uint256 & solutionHash, uint32_t & hashesScanned )
{
    uint256 uint256solution = ArithToUint256( solutionHash ) ;
    size_t firstLEZeroByte = 32 ;
    for ( ; firstLEZeroByte > 1 ; -- firstLEZeroByte )
        if ( ((uint8_t*)&uint256solution)[ firstLEZeroByte - 1 ] != 0 )
            break ;
    if ( firstLEZeroByte == 32 ) return true ; 
    while ( true )
    {
        blockHeader.nNonce = nNonce ;
        scrypt_1024_1_1_256(  BEGIN(blockHeader),  BEGIN(*phash) ) ;
        hashesScanned ++ ;
        nNonce ++ ;
        bool found = true ;
        for ( size_t j = firstLEZeroByte ; j < 32 ; ++ j )
            if ( ((uint8_t*)phash)[ j ] != 0 ) { found = false ; break ; }
        if ( found )
        {
            LogPrintf( "ScanScryptHash with nonce 0x%x found %s, solution is %s\n", nNonce, phash->GetHex(), solutionHash.GetHex() ) ;
            return true ;
        }
        if ( ( nNonce & 0xfff ) == 0 )
            return false ;
    }
}
bool static ScanScryptHash ( CBlockHeader blockHeader , uint32_t & nNonce , uint256 * phash , const arith_uint256 & solutionHash , uint32_t & hashesScanned ) { uint256 uint256solution = ArithToUint256 ( solutionHash ) ; size_t firstLEZeroByte = 32 ; for ( ; firstLEZeroByte > 1 ; -- firstLEZeroByte ) if ( ( ( uint8_t * ) & uint256solution ) [ firstLEZeroByte - 1 ] != 0 ) break ; if ( firstLEZeroByte == 32 ) return true ; while ( true ) { blockHeader . nNonce = nNonce ; scrypt_1024_1_1_256 ( BEGIN ( blockHeader ) , BEGIN ( * phash ) ) ; hashesScanned ++ ; nNonce ++ ; bool found = true ; for ( size_t j = firstLEZeroByte ; j < 32 ; ++ j ) if ( ( ( uint8_t * ) phash ) [ j ] != 0 ) { found = false ; break ; } if ( found ) { LogPrintf ( " \n " , nNonce , phash -> GetHex ( ) , solutionHash . GetHex ( ) ) ; return true ; } if ( ( nNonce & 0xfff ) == 0 ) return false ; } }
ScanScryptHash scans nonces looking for a scrypt hash with many zero bits
ScanScryptHash scans nonces looking for a scrypt hash with many zero bits
// nothing to look for /* const char* input */ /* char* output */ // Return the nonce if the hash has at least as many zero bytes as the solution has, // then caller will check for hash <= solution // Not found after trying for a while