Example #1
0
def validate_seal(
    block_header: Union[RootBlockHeader, MinorBlockHeader],
    consensus_type: ConsensusType,
    adjusted_diff: int = None,  # for overriding
) -> None:
    diff = adjusted_diff if adjusted_diff is not None else block_header.difficulty
    nonce_bytes = block_header.nonce.to_bytes(8, byteorder="big")
    if consensus_type == ConsensusType.POW_ETHASH:
        if not check_pow(
            block_header.height,
            block_header.get_hash_for_mining(),
            block_header.mixhash,
            nonce_bytes,
            diff,
        ):
            raise ValueError("invalid pow proof")
    elif consensus_type == ConsensusType.POW_QKCHASH:
        if not qkchash_check_pow(
            block_header.get_hash_for_mining(), block_header.mixhash, nonce_bytes, diff
        ):
            raise ValueError("invalid pow proof")
    elif consensus_type == ConsensusType.POW_SHA3SHA3:
        target = (2 ** 256 // (diff or 1) - 1).to_bytes(32, byteorder="big")
        h = sha256(sha256(block_header.get_hash_for_mining() + nonce_bytes))
        if not h < target:
            raise ValueError("invalid pow proof")
Example #2
0
def validate_seal(
        block_header: Header,
        consensus_type: ConsensusType,
        adjusted_diff: int = None,  # for overriding
        **kwargs) -> None:
    diff = adjusted_diff if adjusted_diff is not None else block_header.difficulty
    nonce_bytes = block_header.nonce.to_bytes(8, byteorder="big")
    if consensus_type == ConsensusType.POW_ETHASH:
        if not check_pow(
                block_header.height,
                block_header.get_hash_for_mining(),
                block_header.mixhash,
                nonce_bytes,
                diff,
        ):
            raise ValueError("invalid pow proof")
    elif consensus_type == ConsensusType.POW_QKCHASH:
        if not qkchash_check_pow(
                block_header.height,
                block_header.get_hash_for_mining(),
                block_header.mixhash,
                nonce_bytes,
                diff,
                kwargs.get("qkchash_with_rotation_stats", False),
        ):
            raise ValueError("invalid pow proof")
    elif consensus_type == ConsensusType.POW_DOUBLESHA256:
        target = (2**256 // (diff or 1) - 1).to_bytes(32, byteorder="big")
        h = sha256(sha256(block_header.get_hash_for_mining() + nonce_bytes))
        if not h < target:
            raise ValueError("invalid pow proof")
Example #3
0
def validate_seal(
    block_header: Union[RootBlockHeader, MinorBlockHeader],
    consensus_type: ConsensusType,
) -> None:
    if consensus_type == ConsensusType.POW_ETHASH:
        nonce_bytes = block_header.nonce.to_bytes(8, byteorder="big")
        if not check_pow(
                block_header.height,
                block_header.get_hash_for_mining(),
                block_header.mixhash,
                nonce_bytes,
                block_header.difficulty,
        ):
            raise ValueError("invalid pow proof")
    elif consensus_type == ConsensusType.POW_SHA3SHA3:
        nonce_bytes = block_header.nonce.to_bytes(8, byteorder="big")
        target = (2**256 // (block_header.difficulty or 1) - 1).to_bytes(
            32, byteorder="big")
        h = sha3_256(sha3_256(block_header.get_hash_for_mining() +
                              nonce_bytes))
        if not h < target:
            raise ValueError("invalid pow proof")
Example #4
0
def check_pow(state, header):
    assert ethpow.check_pow(header.number, header.mining_hash, header.mixhash,
                            header.nonce, header.difficulty)
    return True