Exemplo n.º 1
0
 def ir_compiler(ir, *args, **kwargs):
     ir = IRnode.from_list(ir)
     if not no_optimize:
         ir = optimizer.optimize(ir)
     bytecode, _ = compile_ir.assembly_to_evm(
         compile_ir.compile_to_assembly(ir, no_optimize=no_optimize))
     abi = kwargs.get("abi") or []
     c = w3.eth.contract(abi=abi, bytecode=bytecode)
     deploy_transaction = c.constructor()
     tx_hash = deploy_transaction.transact()
     address = w3.eth.get_transaction_receipt(tx_hash)["contractAddress"]
     contract = w3.eth.contract(address,
                                abi=abi,
                                bytecode=bytecode,
                                ContractFactoryClass=VyperContract)
     return contract
Exemplo n.º 2
0
def compile_to_ir(input_file, output_formats, show_gas_estimates=False):
    with open(input_file) as fh:
        s_expressions = parse_s_exp(fh.read())

    if show_gas_estimates:
        IRnode.repr_show_gas = True

    compiler_data = {}
    ir = IRnode.from_list(s_expressions[0])
    ir = optimizer.optimize(ir)
    if "ir" in output_formats:
        compiler_data["ir"] = ir

    asm = compile_ir.compile_to_assembly(ir)
    if "asm" in output_formats:
        compiler_data["asm"] = asm

    if "bytecode" in output_formats:
        (bytecode, _srcmap) = compile_ir.assembly_to_evm(asm)
        compiler_data["bytecode"] = "0x" + bytecode.hex()

    return compiler_data
Exemplo n.º 3
0
def generate_assembly(ir_nodes: IRnode, no_optimize: bool = False) -> list:
    """
    Generate assembly instructions from IR.

    Arguments
    ---------
    ir_nodes : str
        Top-level IR nodes. Can be deployment or runtime IR.

    Returns
    -------
    list
        List of assembly instructions.
    """
    assembly = compile_ir.compile_to_assembly(ir_nodes,
                                              no_optimize=no_optimize)

    if _find_nested_opcode(assembly, "DEBUG"):
        warnings.warn(
            "This code contains DEBUG opcodes! The DEBUG opcode will only work in "
            "a supported EVM! It will FAIL on all other nodes!")
    return assembly
Exemplo n.º 4
0
def test_sha3_32():
    ir = ["sha3_32", 0]
    evm = ["PUSH1", 0, "PUSH1", 0, "MSTORE", "PUSH1", 32, "PUSH1", 0, "SHA3"]
    assert compile_ir.compile_to_assembly(IRnode.from_list(ir)) == evm
    assert compile_ir.compile_to_assembly(
        optimizer.optimize(IRnode.from_list(ir))) == evm
Exemplo n.º 5
0
def test_pc_debugger():
    debugger_ir = ["seq", ["mstore", 0, 32], ["pc_debugger"]]
    ir_nodes = IRnode.from_list(debugger_ir)
    _, line_number_map = compile_ir.assembly_to_evm(
        compile_ir.compile_to_assembly(ir_nodes))
    assert line_number_map["pc_breakpoints"][0] == 5