diff --git a/src/ethereum_test_tools/vm/opcode.py b/src/ethereum_test_tools/vm/opcode.py index d456eee4ef..1b9ffc6e4b 100644 --- a/src/ethereum_test_tools/vm/opcode.py +++ b/src/ethereum_test_tools/vm/opcode.py @@ -24,6 +24,12 @@ def _get_int_size(n: int) -> int: _push_opcodes_byte_list = [bytes([0x5F + x]) for x in range(33)] +class Special_Codes(Enum): + """ + """ + NAN = 0, + OOG = 1, + class Opcode(bytes): """ @@ -43,6 +49,7 @@ class Opcode(bytes): pushed_stack_items: int min_stack_height: int data_portion_length: int + special_code: Special_Codes _name_: str def __new__( @@ -53,6 +60,7 @@ def __new__( pushed_stack_items: int = 0, min_stack_height: int = 0, data_portion_length: int = 0, + special_code: Special_Codes = Special_Codes.NAN, ): """ Creates a new opcode instance. @@ -67,6 +75,7 @@ def __new__( obj.pushed_stack_items = pushed_stack_items obj.min_stack_height = min_stack_height obj.data_portion_length = data_portion_length + obj.special_code = special_code return obj def __call__(self, *args_t: Union[int, bytes, str, "Opcode", FixedSizeBytes]) -> bytes: @@ -107,6 +116,12 @@ def __call__(self, *args_t: Union[int, bytes, str, "Opcode", FixedSizeBytes]) -> pre_opcode_bytecode = bytes() data_portion = bytes() + if self.special_code == Special_Codes.OOG: + # This operation will result in gasprice = 19073514453125027 + # Add a little more and geth report gasprice = 30 with oog exception + # Make it 0 - 1 and geth report gasprice > u64 error + return Opcodes.SHA3(0, 100000000000) + if self.data_portion_length > 0: # For opcodes with a data portion, the first argument is the data # and the rest of the arguments form the stack. @@ -188,6 +203,13 @@ def __str__(self) -> str: """ return self._name_ + def __eq__(self, other): + """ + Required to differentiate between SELFDESTRUCT and SENDALL type of cases + """ + if not isinstance(other, Opcode): + return NotImplemented + return (self._name_ == other._name_) OpcodeCallArg = Union[int, bytes, Opcode] @@ -373,3 +395,4 @@ class Opcodes(Opcode, Enum): SELFDESTRUCT = Opcode(0xFF, popped_stack_items=1) SENDALL = Opcode(0xFF, popped_stack_items=1) + OOG = Opcode(0xFF, popped_stack_items=2, special_code=Special_Codes.OOG)