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 _compile_source(self):
     """
     Finished.
     Compiles the source solidity code and returns the
         binary, abi, runtime opcode in a dictionary format.
     Returns:
         dictionary containing the above info.
     """
     res = {}
     crytic_compile = self.slither_contract.slither.crytic_compile
     res['abi'] = crytic_compile.abi(self.name)
     res['init_bytecode'] = crytic_compile.bytecode_init(self.name)
     res['runtime_bytecode'] = crytic_compile.bytecode_runtime(self.name)
     res['runtime_opcode'] = disassemble_hex(
         res['runtime_bytecode']).replace('\n', ' ')
     res['runtime_srcmap'] = ';'.join(
         crytic_compile.srcmap_runtime(self.name))
     return res
Ejemplo n.º 4
0
    def disassemble_hex(bytecode: str,
                        pc: int = 0,
                        fork=pyevmasm.DEFAULT_FORK) -> str:
        ''' Disassemble an EVM bytecode

            :param bytecode: canonical representation of an evm bytecode (hexadecimal)
            :param int pc: program counter of the first instruction in the bytecode(optional)
            :type bytecode: str
            :return: the text representation of the assembler code

            Example use::

                >>> EVMAsm.disassemble_hex("0x6060604052600261010")
                ...
                PUSH1 0x60
                BLOCKHASH
                MSTORE
                PUSH1 0x2
                PUSH2 0x100

        '''
        return pyevmasm.disassemble_hex(bytecode, pc, fork)
Ejemplo n.º 5
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.º 6
0

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'))