ethereum / py-evm

A Python implementation of the Ethereum Virtual Machine
https://py-evm.readthedocs.io/en/latest/
MIT License
2.26k stars 650 forks source link

'pc' should be changed to 'program_counter' in the __slots__ of CodeStream class #2109

Closed imtypist closed 1 year ago

imtypist commented 1 year ago

pc should be changed to program_counter in the __slots__ of CodeStream class. Although it does not raise errors (since program_counter is inherited from CodeStreamAPI), I think should correct it.

class CodeStream(CodeStreamAPI):
    __slots__ = [
        "_length_cache",
        "_raw_code_bytes",
        "invalid_positions",
        "valid_positions",
        "pc",
    ]

    logger = logging.getLogger("eth.vm.CodeStream")

    def __init__(self, code_bytes: bytes) -> None:
        validate_is_bytes(code_bytes, title="CodeStream bytes")
        # in order to avoid method overhead when setting/accessing pc, we no longer
        # fence the pc (Program Counter) into 0 <= pc <= len(code_bytes).
        # We now let it float free.
        # NOTE: Setting pc to a negative value has undefined behavior.
        self.program_counter = 0
        self._raw_code_bytes = code_bytes
        self._length_cache = len(code_bytes)
        self.invalid_positions: Set[int] = set()
        self.valid_positions: Set[int] = set()

https://github.com/ethereum/py-evm/blob/8aa9eb51944b4dcf6b365eb032ac674fed933c09/eth/vm/code_stream.py#LL21C1-L42C47

pacrob commented 1 year ago

Good catch, thanks @imtypist ! PR incoming.