예제 #1
0
    def write(self, start_position, size, value):
        """
        Write `value` into memory.
        """
        if size:
            validate_uint256(start_position)
            validate_uint256(size)
            validate_is_bytes(value)
            validate_length(value, length=size)
            validate_lte(start_position + size, maximum=len(self))

            self.bytes = (
                self.bytes[:start_position] +
                bytearray(value) +
                self.bytes[start_position + size:]
            )
예제 #2
0
파일: memory.py 프로젝트: firefox0x/py-evm
    def write(self, start_position, size, value):
        """
        Write `value` into memory.
        """
        if size:
            validate_uint256(start_position)
            validate_uint256(size)
            validate_is_bytes(value)
            validate_length(value, length=size)
            validate_lte(start_position + size, maximum=len(self))

            if len(self.bytes) < start_position + size:
                self.bytes.extend(itertools.repeat(
                    0,
                    len(self.bytes) - (start_position + size),
                ))

            for idx, v in enumerate(value):
                self.bytes[start_position + idx] = v
예제 #3
0
def memory_write(self, start_position, size, value):
    """
    Write `value` into memory.
    """
    if size:
        validate_uint256(start_position)
        validate_uint256(size)
        validate_is_bytes(value)
        validate_length(value, length=size)
        validate_lte(start_position + size, maximum=len(self))

        if len(self.bytes) < start_position + size:
            self.bytes.extend(
                itertools.repeat(
                    0,
                    len(self.bytes) - (start_position + size),
                ))

        for idx, v in enumerate(value):
            self.bytes[start_position + idx] = v
예제 #4
0
def check_pow(block_number, mining_hash, mix_hash, nonce, difficulty):
    validate_length(mix_hash, 32)
    validate_length(mining_hash, 32)
    validate_length(nonce, 8)
    cache = get_cache(block_number)
    mining_output = hashimoto_light(block_number, cache, mining_hash,
                                    big_endian_to_int(nonce))
    if mining_output[b'mix digest'] != mix_hash:
        raise ValidationError("mix hash mistmatch; {0} != {1}".format(
            encode_hex(mining_output[b'mix digest']), encode_hex(mix_hash)))
    result = big_endian_to_int(mining_output[b'result'])
    validate_lte(result, 2**256 // difficulty)
예제 #5
0
파일: pow.py 프로젝트: firefox0x/py-evm
def check_pow(block_number, mining_hash, mix_hash, nonce, difficulty):
    validate_length(mix_hash, 32, title="Mix Hash")
    validate_length(mining_hash, 32, title="Mining Hash")
    validate_length(nonce, 8, title="POW Nonce")
    cache = get_cache(block_number)
    mining_output = hashimoto_light(
        block_number, cache, mining_hash, big_endian_to_int(nonce))
    if mining_output[b'mix digest'] != mix_hash:
        raise ValidationError("mix hash mismatch; {0} != {1}".format(
            encode_hex(mining_output[b'mix digest']), encode_hex(mix_hash)))
    result = big_endian_to_int(mining_output[b'result'])
    validate_lte(result, 2**256 // difficulty, title="POW Difficulty")
예제 #6
0
def check_pow(block_number: int, mining_hash: Hash32, mix_hash: Hash32,
              nonce: bytes, difficulty: int) -> None:
    validate_length(mix_hash, 32, title="Mix Hash")
    validate_length(mining_hash, 32, title="Mining Hash")
    validate_length(nonce, 8, title="POW Nonce")
    cache = get_cache(block_number)
    mining_output = hashimoto_light(block_number, cache, mining_hash,
                                    big_endian_to_int(nonce))
    if mining_output[b'mix digest'] != mix_hash:
        raise ValidationError("mix hash mismatch; {0} != {1}".format(
            encode_hex(mining_output[b'mix digest']), encode_hex(mix_hash)))
    result = big_endian_to_int(mining_output[b'result'])
    validate_lte(result, 2**256 // difficulty, title="POW Difficulty")
예제 #7
0
def test_validate_length(value, length, is_valid):
    if is_valid:
        validate_length(value, length)
    else:
        with pytest.raises(ValidationError):
            validate_length(value, length)
예제 #8
0
def test_validate_length(value, length, is_valid):
    if is_valid:
        validate_length(value, length)
    else:
        with pytest.raises(ValidationError):
            validate_length(value, length)