def compile_to_ir(code: str): try: result = optimizer.optimize(parse_to_lll(code)) except Exception as e: return jsonify(error=get_error(e)), 400 return jsonify(result=str(result))
def test_sha3_32(): lll = ['sha3_32', 0] evm = [ 'PUSH1', 0, 'PUSH1', 192, 'MSTORE', 'PUSH1', 32, 'PUSH1', 192, 'SHA3' ] assert compile_lll.compile_to_assembly(LLLnode.from_list(lll)) == evm assert compile_lll.compile_to_assembly( optimizer.optimize(LLLnode.from_list(lll))) == evm
def compile_all(code: str): try: result_abi = compiler.mk_full_signature(code) except Exception as e: return jsonify(error=get_error(e)), 400 try: result_ir = optimizer.optimize(parse_to_lll(code)) except Exception as e: return jsonify(error=get_error(e)), 400 try: result_bytecode = '0x' + compiler.compile(code).hex() except Exception as e: return jsonify(error=get_error(e)), 400 return jsonify(result_abi=result_abi, result_ir=str(result_ir), result_bytecode=result_bytecode)
def compile(): source = request.form.get('source', '') try: abi = compiler.mk_full_signature(source) abi_code = 200 except Exception as e: abi = str(e) abi_code = 500 try: json_abi = json.dumps(compiler.mk_full_signature(source)) json_abi_code = 200 except Exception as e: json_abi = str(e) json_abi_code = 500 try: bytecode = '0x' + compiler.compile(source).hex() bytecode_code = 200 except Exception as e: bytecode = str(e) bytecode_code = 500 try: ir = optimizer.optimize(parse_to_lll(source)) ir = str(ir) ir_code = 200 except Exception as e: ir = str(e) ir_code = 500 r_dict = { 'result': { 'abi': abi, 'abi_code': abi_code, 'json': json_abi, 'json_code': json_abi_code, 'bytecode': bytecode, 'bytecode_code': bytecode_code, 'lll': ir, 'lll_code': ir_code } } return make_response(jsonify(r_dict), 200)
def lll_compiler(lll): lll = optimizer.optimize(LLLnode.from_list(lll)) byte_code = compile_lll.assembly_to_evm(compile_lll.compile_to_assembly(lll)) t.s.tx(to=b'', data=byte_code)
[ 'mstore', add(sub(data, ['mload', position_offset]), ['mload', i]), add(['mload', add(positions, ['mload', i])], ['mload', position_offset]) ], # ~mstore(data - positionOffset + i, ~mload(positions + i) + positionOffset) ['mstore', i, sub(['mload', i], 32)], ] ], [ 'mstore', sub(data, 32), add(['mload', position_offset], ['mload', data_pos]) ], [ 'return', sub(data, ['mload', position_offset]), add(['mload', position_offset], ['mload', data_pos]) ] ], [0] ] ] ]) rlp_decoder_lll = optimizer.optimize(rlp_decoder_lll) rlp_decoder_bytes = compile_lll.assembly_to_evm( compile_lll.compile_to_assembly(rlp_decoder_lll))