def test_chunk_iteration(): chunk_number = COLLATION_SIZE // CHUNK_SIZE test_chunks = [ zpad_left(int_to_big_endian(i), CHUNK_SIZE) for i in range(chunk_number) ] chunks = test_chunks body = b"".join(chunks) for recovered, original in zip_longest(iterate_chunks(body), chunks, fillvalue=None): assert recovered is not None and original is not None assert recovered == original chunks = test_chunks[:-2] body = b"".join(chunks) with pytest.raises(ValidationError): next(iterate_chunks(body)) chunks = test_chunks body = b"".join(chunks)[:-2] with pytest.raises(ValidationError): next(iterate_chunks(body)) chunks = test_chunks body = b"".join(chunks) + b"\x00" with pytest.raises(ValidationError): next(iterate_chunks(body)) chunks = test_chunks + [b"\x00" * CHUNK_SIZE] body = b"".join(chunks) with pytest.raises(ValidationError): next(iterate_chunks(body))
def modexp(computation): """ https://github.com/ethereum/EIPs/pull/198 """ gas_fee = _compute_modexp_gas_fee(computation.msg.data) computation.consume_gas(gas_fee, reason='MODEXP Precompile') result = _modexp(computation.msg.data) _, _, modulus_length = _extract_lengths(computation.msg.data) result_bytes = zpad_left(int_to_big_endian(result), to_size=modulus_length) computation.output = result_bytes return computation
def modexp(computation: BaseComputation) -> BaseComputation: """ https://github.com/ethereum/EIPs/pull/198 """ gas_fee = _compute_modexp_gas_fee(computation.msg.data) computation.consume_gas(gas_fee, reason='MODEXP Precompile') result = _modexp(computation.msg.data) _, _, modulus_length = _extract_lengths(computation.msg.data) # Modulo 0 is undefined, return zero # https://math.stackexchange.com/questions/516251/why-is-n-mod-0-undefined result_bytes = b'' if modulus_length == 0 else zpad_left( int_to_big_endian(result), to_size=modulus_length) computation.output = result_bytes return computation