Example #1
0
def main(inputCode) -> None:

    # create simulator for VM
    sim = Simulator()
    # convert cli string input to tbytes input
    inputAsBytes = tbytes(decode_hex(inputCode))

    if VERBOSE:
        print("Code: " + inputCode)

    # execute raw bytecode
    computation = sim.executeCode(1000000000000, b'', inputAsBytes)

    # check, if error during execution occured
    if computation.is_error:
        origin = computation._error
        exc = VMExecutionError(str(origin), origin)
        raise exc

    if VERBOSE:
        print("Gas used: " + str(computation.get_gas_used()))
        print("Remaining gas: " + str(computation.get_gas_remaining()))

        print(computation.get_log_entries())
        print("Stack: " + str(computation._stack.values))
Example #2
0
    def chain_with_block_validation(self, base_db, funded_address, funded_address_initial_balance):
        """
        Return a Chain object containing just the genesis block.

        The Chain's state includes one funded account, which can be found in the
        funded_address in the chain itself.

        This Chain will perform all validations when importing new blocks, so only
        valid and finalized blocks can be used with it. If you want to test
        importing arbitrarily constructe, not finalized blocks, use the
        chain_without_block_validation fixture instead.
        """
        genesis_params = {
            "bloom": 0,
            "coinbase": to_canonical_address("8888f1f195afa192cfee860698584c030f4c9db1"),
            "difficulty": 131072,
            "extra_data": b"B",
            "gas_limit": 3141592,
            "gas_used": 0,
            "mix_hash": decode_hex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"),  # noqa: E501
            "nonce": decode_hex("0102030405060708"),
            "block_number": 0,
            "parent_hash": decode_hex("0000000000000000000000000000000000000000000000000000000000000000"),  # noqa: E501
            "receipt_root": decode_hex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"),  # noqa: E501
            "timestamp": 1422494849,
            "transaction_root": decode_hex("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421"),  # noqa: E501
            "uncles_hash": decode_hex("1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")  # noqa: E501
        }
        genesis_state = {
            funded_address: {
                "balance": funded_address_initial_balance,
                "nonce": 0,
                "code": b"",
                "storage": {}
            }
        }
        klass = Chain.configure(
            __name__='TestChain',
            vm_configuration=(
                (constants.GENESIS_BLOCK_NUMBER, ByzantiumVM),
            ),
            network_id=1337,
        )
        chain = klass.from_genesis(base_db, genesis_params, genesis_state)
        return chain
Example #3
0
import pytest

from eth.precompiles.modexp import (
    _modexp,
    _compute_modexp_gas_fee,
)
from eth.utils.hexadecimal import (
    decode_hex, )

EIP198_VECTOR_A = decode_hex(
    "0000000000000000000000000000000000000000000000000000000000000001"
    "0000000000000000000000000000000000000000000000000000000000000020"
    "0000000000000000000000000000000000000000000000000000000000000020"
    "03"
    "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e"
    "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f")

EIP198_VECTOR_B = decode_hex(
    "0000000000000000000000000000000000000000000000000000000000000000"
    "0000000000000000000000000000000000000000000000000000000000000020"
    "0000000000000000000000000000000000000000000000000000000000000020"
    "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2e"
    "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f")

EIP198_VECTOR_C = decode_hex(
    "0000000000000000000000000000000000000000000000000000000000000000"
    "0000000000000000000000000000000000000000000000000000000000000020"
    "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
    "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe"
    "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffd")
Example #4
0
def test_round_trip_with_hex_string_start(value):
    intermediate_value = decode_hex(value)
    round_trip_value = encode_hex(intermediate_value)
    assert round_trip_value == value
Example #5
0
def test_basic_hexadecimal_decoding(value, expected):
    actual = decode_hex(value)
    assert actual == expected
Example #6
0
def funded_address_private_key() -> PrivateKey:
    return lazy_key_api.PrivateKey(
        decode_hex('0x45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8')
    )