Ejemplo n.º 1
0
    def test_ADD_1(self):
        instruction = EVMAsm.disassemble_one(b'\x60\x10')
        self.assertEqual(
            EVMAsm.Instruction(0x60, 'PUSH', 1, 0, 1, 0,
                               'Place 1 byte item on stack.', 16, 0),
            instruction)

        instruction = EVMAsm.assemble_one('PUSH1 0x10')
        EVMAsm.Instruction(0x60, 'PUSH', 1, 0, 1, 0,
                           'Place 1 byte item on stack.', 16, 0)

        instructions1 = EVMAsm.disassemble_all(b'\x30\x31')
        instructions2 = EVMAsm.assemble_all('ADDRESS\nBALANCE')
        self.assertTrue(
            all(a == b for a, b in zip(instructions1, instructions2)))

        # High level simple assembler/disassembler

        bytecode = EVMAsm.assemble_hex("""PUSH1 0x80
               BLOCKHASH
               MSTORE
               PUSH1 0x2
               PUSH2 0x100
            """)
        self.assertEqual(bytecode, '0x608040526002610100')

        asmcode = EVMAsm.disassemble_hex('0x608040526002610100')
        self.assertEqual(
            asmcode,
            '''PUSH1 0x80\nBLOCKHASH\nMSTORE\nPUSH1 0x2\nPUSH2 0x100''')
Ejemplo n.º 2
0
    def test_ADD_1(self):
        instruction = EVMAsm.disassemble_one(b"\x60\x10")
        self.assertEqual(
            EVMAsm.Instruction(0x60, "PUSH", 1, 0, 1, 3,
                               "Place 1 byte item on stack.", 16, 0),
            instruction)

        instruction = EVMAsm.assemble_one("PUSH1 0x10")
        self.assertEqual(
            instruction,
            EVMAsm.Instruction(0x60, "PUSH", 1, 0, 1, 3,
                               "Place 1 byte item on stack.", 16, 0))

        instructions1 = EVMAsm.disassemble_all(b"\x30\x31")
        instructions2 = EVMAsm.assemble_all("ADDRESS\nBALANCE")
        self.assertTrue(
            all(a == b for a, b in zip(instructions1, instructions2)))

        # High level simple assembler/disassembler

        bytecode = EVMAsm.assemble_hex("""PUSH1 0x80
               BLOCKHASH
               MSTORE
               PUSH1 0x2
               PUSH2 0x100
            """)
        self.assertEqual(bytecode, "0x608040526002610100")

        asmcode = EVMAsm.disassemble_hex("0x608040526002610100")
        self.assertEqual(
            asmcode,
            """PUSH1 0x80\nBLOCKHASH\nMSTORE\nPUSH1 0x2\nPUSH2 0x100""")
Ejemplo n.º 3
0
    def assemble_all(assembler: str,
                     pc: int = 0,
                     fork=pyevmasm.DEFAULT_FORK) -> Iterable[EVMInstruction]:
        ''' Assemble a sequence of textual representation of EVM instructions

            :param assembler: assembler code for any number of instructions
            :param pc: program counter of the first instruction in the bytecode(optional)
            :return: An generator of Instruction objects

            Example use::

                >>> evm.EVMAsm.assemble_one("""PUSH1 0x60\n \
                            PUSH1 0x40\n \
                            MSTORE\n \
                            PUSH1 0x2\n \
                            PUSH2 0x108\n \
                            PUSH1 0x0\n \
                            POP\n \
                            SSTORE\n \
                            PUSH1 0x40\n \
                            MLOAD\n \
                            """)

        '''
        instructions = pyevmasm.assemble_all(assembler, pc, fork)
        return EVMAsm.convert_multiple_instructions_to_evminstructions(
            instructions)
Ejemplo n.º 4
0
    print("\treads from stack:", instruction.reads_from_stack)
    print("\twrites to memory:", instruction.writes_to_memory)
    print("\treads from memory:", instruction.reads_from_memory)
    print("\twrites to storage:", instruction.writes_to_storage)
    print("\treads from storage:", instruction.reads_from_storage)
    print("\tis terminator", instruction.is_terminator)


instruction = ea.disassemble_one("\x60\x10")
printi(instruction)

instruction = ea.assemble_one("PUSH1 0x10")
printi(instruction)

for instruction in ea.disassemble_all("\x30\x31"):
    printi(instruction)

for instruction in ea.assemble_all("ADDRESS\nBALANCE"):
    printi(instruction)

# High level simple assembler/disassembler
print(
    ea.assemble_hex("""PUSH1 0x60
                           BLOCKHASH
                           MSTORE
                           PUSH1 0x2
                           PUSH2 0x100
                        """))

print(ea.disassemble_hex("0x606040526002610100"))
Ejemplo n.º 5
0
    print('\treads from memory:', instruction.reads_from_memory)
    print('\twrites to storage:', instruction.writes_to_storage)
    print('\treads from storage:', instruction.reads_from_storage)
    print('\tis terminator', instruction.is_terminator)


instruction = ea.disassemble_one('\x60\x10')
printi(instruction)

instruction = ea.assemble_one('PUSH1 0x10')
printi(instruction)

for instruction in ea.disassemble_all('\x30\x31'):
    printi(instruction)

for instruction in ea.assemble_all('ADDRESS\nBALANCE'):
    printi(instruction)


#High level simple assembler/disassembler
print(ea.assemble_hex(
                        """PUSH1 0x60
                           BLOCKHASH
                           MSTORE
                           PUSH1 0x2
                           PUSH2 0x100
                        """
                     ))


print(ea.disassemble_hex('0x606040526002610100'))