@@ -32,6 +32,7 @@ class EVMAsm(object):
3232 >>> EVMAsm.disassemble_hex('0x606040526002610100')
3333 'PUSH1 0x60\\ nBLOCKHASH\\ nMSTORE\\ nPUSH1 0x2\\ nPUSH2 0x100'
3434 '''
35+
3536 class Instruction (object ):
3637 def __init__ (self , opcode , name , operand_size , pops , pushes , fee , description , operand = None , pc = 0 ):
3738 '''
@@ -89,19 +90,20 @@ def __init__(self, opcode, name, operand_size, pops, pushes, fee, description, o
8990
9091 def __eq__ (self , other ):
9192 ''' Instructions are equal if all features match '''
92- return self ._opcode == other ._opcode and \
93- self ._name == other ._name and \
94- self ._operand == other ._operand and \
95- self ._operand_size == other ._operand_size and \
96- self ._pops == other ._pops and \
97- self ._pushes == other ._pushes and \
98- self ._fee == other ._fee and \
99- self ._pc == other ._pc and \
100- self ._description == other ._description
93+ return self ._opcode == other ._opcode and \
94+ self ._name == other ._name and \
95+ self ._operand == other ._operand and \
96+ self ._operand_size == other ._operand_size and \
97+ self ._pops == other ._pops and \
98+ self ._pushes == other ._pushes and \
99+ self ._fee == other ._fee and \
100+ self ._pc == other ._pc and \
101+ self ._description == other ._description
101102
102103 def __repr__ (self ):
103- output = 'Instruction(0x%x, %r, %d, %d, %d, %d, %r, %r, %r)' % (self ._opcode , self ._name , self ._operand_size ,
104- self ._pops , self ._pushes , self ._fee , self ._description , self ._operand , self ._pc )
104+ output = 'Instruction(0x%x, %r, %d, %d, %d, %d, %r, %r, %r)' % (
105+ self ._opcode , self ._name , self ._operand_size ,
106+ self ._pops , self ._pushes , self ._fee , self ._description , self ._operand , self ._pc )
105107 return output
106108
107109 def __str__ (self ):
@@ -294,7 +296,8 @@ def uses_block_info(self):
294296 @property
295297 def is_arithmetic (self ):
296298 ''' True if the instruction is an arithmetic operation '''
297- return self .semantics in ('ADD' , 'MUL' , 'SUB' , 'DIV' , 'SDIV' , 'MOD' , 'SMOD' , 'ADDMOD' , 'MULMOD' , 'EXP' , 'SIGNEXTEND' )
299+ return self .semantics in (
300+ 'ADD' , 'MUL' , 'SUB' , 'DIV' , 'SDIV' , 'MOD' , 'SMOD' , 'ADDMOD' , 'MULMOD' , 'EXP' , 'SIGNEXTEND' )
298301
299302 # from http://gavwood.com/paper.pdf
300303 _table = { # opcode: (name, immediate_operand_size, pops, pushes, gas, description)
@@ -327,7 +330,8 @@ def is_arithmetic(self):
327330 0x31 : ('BALANCE' , 0 , 1 , 1 , 20 , 'Get balance of the given account.' ),
328331 0x32 : ('ORIGIN' , 0 , 0 , 1 , 2 , 'Get execution origination address.' ),
329332 0x33 : ('CALLER' , 0 , 0 , 1 , 2 , 'Get caller address.' ),
330- 0x34 : ('CALLVALUE' , 0 , 0 , 1 , 2 , 'Get deposited value by the instruction/transaction responsible for this execution.' ),
333+ 0x34 : (
334+ 'CALLVALUE' , 0 , 0 , 1 , 2 , 'Get deposited value by the instruction/transaction responsible for this execution.' ),
331335 0x35 : ('CALLDATALOAD' , 0 , 1 , 1 , 3 , 'Get input data of current environment.' ),
332336 0x36 : ('CALLDATASIZE' , 0 , 0 , 1 , 2 , 'Get size of input data in current environment.' ),
333337 0x37 : ('CALLDATACOPY' , 0 , 3 , 0 , 3 , 'Copy input data in current environment to memory.' ),
@@ -336,7 +340,8 @@ def is_arithmetic(self):
336340 0x3a : ('GASPRICE' , 0 , 0 , 1 , 2 , 'Get price of gas in current environment.' ),
337341 0x3b : ('EXTCODESIZE' , 0 , 1 , 1 , 20 , "Get size of an account's code." ),
338342 0x3c : ('EXTCODECOPY' , 0 , 4 , 0 , 20 , "Copy an account's code to memory." ),
339- 0x3d : ('RETURNDATASIZE' , 0 , 0 , 1 , 2 , 'Get size of output data from the previous call from the current environment' ),
343+ 0x3d : (
344+ 'RETURNDATASIZE' , 0 , 0 , 1 , 2 , 'Get size of output data from the previous call from the current environment' ),
340345 0x3e : ('RETURNDATACOPY' , 0 , 3 , 0 , 3 , 'Copy output data from the previous call to memory' ),
341346 0x40 : ('BLOCKHASH' , 0 , 1 , 1 , 20 , 'Get the hash of one of the 256 most recent complete blocks.' ),
342347 0x41 : ('COINBASE' , 0 , 0 , 1 , 2 , "Get the block's beneficiary address." ),
@@ -354,7 +359,8 @@ def is_arithmetic(self):
354359 0x57 : ('JUMPI' , 0 , 2 , 0 , 10 , 'Conditionally alter the program counter.' ),
355360 0x58 : ('GETPC' , 0 , 0 , 1 , 2 , 'Get the value of the program counter prior to the increment.' ),
356361 0x59 : ('MSIZE' , 0 , 0 , 1 , 2 , 'Get the size of active memory in bytes.' ),
357- 0x5a : ('GAS' , 0 , 0 , 1 , 2 , 'Get the amount of available gas, including the corresponding reduction the amount of available gas.' ),
362+ 0x5a : ('GAS' , 0 , 0 , 1 , 2 ,
363+ 'Get the amount of available gas, including the corresponding reduction the amount of available gas.' ),
358364 0x5b : ('JUMPDEST' , 0 , 0 , 0 , 1 , 'Mark a valid destination for jumps.' ),
359365 0x60 : ('PUSH' , 1 , 0 , 1 , 0 , 'Place 1 byte item on stack.' ),
360366 0x61 : ('PUSH' , 2 , 0 , 1 , 0 , 'Place 2-byte item on stack.' ),
@@ -429,9 +435,11 @@ def is_arithmetic(self):
429435 0xf1 : ('CALL' , 0 , 7 , 1 , 40 , 'Message-call into an account.' ),
430436 0xf2 : ('CALLCODE' , 0 , 7 , 1 , 40 , "Message-call into this account with alternative account's code." ),
431437 0xf3 : ('RETURN' , 0 , 2 , 0 , 0 , 'Halt execution returning output data.' ),
432- 0xf4 : ('DELEGATECALL' , 0 , 6 , 1 , 40 , "Message-call into this account with an alternative account's code, but persisting into this account with an alternative account's code." ),
438+ 0xf4 : ('DELEGATECALL' , 0 , 6 , 1 , 40 ,
439+ "Message-call into this account with an alternative account's code, but persisting into this account with an alternative account's code." ),
433440 0xfa : ('STATICCALL' , 0 , 6 , 1 , 40 , 'Static message-call into an account.' ),
434- 0xfd : ('REVERT' , 0 , 2 , 0 , 0 , 'Stop execution and revert state changes, without consuming all provided gas and providing a reason.' ),
441+ 0xfd : ('REVERT' , 0 , 2 , 0 , 0 ,
442+ 'Stop execution and revert state changes, without consuming all provided gas and providing a reason.' ),
435443 0xfe : ('INVALID' , 0 , 0 , 0 , 0 , 'Designated invalid instruction.' ),
436444 0xff : ('SELFDESTRUCT' , 0 , 1 , 0 , 5000 , 'Halt execution and register account for later deletion.' )
437445 }
@@ -476,7 +484,8 @@ def assemble_one(assembler, pc=0):
476484 assert len (assembler ) == 1
477485 operand = None
478486
479- return EVMAsm .Instruction (opcode , name , operand_size , pops , pushes , gas , description , operand = operand , pc = pc )
487+ return EVMAsm .Instruction (opcode , name , operand_size , pops , pushes , gas , description , operand = operand ,
488+ pc = pc )
480489 except BaseException :
481490 raise Exception ("Something wrong at pc %d" % pc )
482491
@@ -670,4 +679,4 @@ def assemble_hex(asmcode, pc=0):
670679 ...
671680 "0x6060604052600261010"
672681 '''
673- return '0x' + hexlify (EVMAsm .assemble (asmcode , pc = pc ).encode ()).decode ()
682+ return '0x' + hexlify (EVMAsm .assemble (asmcode , pc = pc ).encode ()).decode ()
0 commit comments