Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ApeWorX/evm-trace into feat…
Browse files Browse the repository at this point in the history
…/eth-pydantic-upgrade

# Conflicts:
#	evm_trace/geth.py
  • Loading branch information
bitwise-constructs committed Oct 14, 2024
2 parents c129cd7 + f15b046 commit af95600
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ repos:
- id: isort

- repo: https://github.com/psf/black
rev: 24.4.2
rev: 24.8.0
hooks:
- id: black
name: black

- repo: https://github.com/pycqa/flake8
rev: 7.0.0
rev: 7.1.1
hooks:
- id: flake8

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.0
rev: v1.11.1
hooks:
- id: mypy
additional_dependencies: [types-PyYAML, types-requests, types-setuptools, pydantic]
Expand Down
8 changes: 4 additions & 4 deletions evm_trace/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import TYPE_CHECKING, Optional, Union, cast

from eth_typing import ChecksumAddress
from eth_utils import to_checksum_address
from eth_utils import to_checksum_address, to_hex

from evm_trace.enums import CallType

Expand Down Expand Up @@ -56,11 +56,11 @@ def title(self) -> str:

if hasattr(self.call, "selector"):
# Is an Event-node
selector = self.call.selector.hex() if self.call.selector else None
selector = to_hex(self.call.selector) if self.call.selector else None
return f"{call_type}: {selector}"
# else: Is a CallTreeNode

address_hex_str = self.call.address.hex() if self.call.address else None
address_hex_str = to_hex(self.call.address) if self.call.address else None
try:
address = to_checksum_address(address_hex_str) if address_hex_str else None
except (ImportError, ValueError):
Expand All @@ -80,7 +80,7 @@ def title(self) -> str:
method_id = ""

else:
hex_id = self.call.calldata[:4].hex()
hex_id = to_hex(self.call.calldata[:4])
method_id = f"<{hex_id}>" if hex_id else ""

sep = "." if call_path and method_id else ""
Expand Down
20 changes: 10 additions & 10 deletions evm_trace/geth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from collections.abc import Iterator
from typing import Optional

from eth_pydantic_types import HexBytes20, HexBytes
from eth_utils import to_int
from eth_pydantic_types import HashBytes20, HexBytes
from eth_utils import to_hex, to_int
from pydantic import Field, RootModel, field_validator

from evm_trace.base import BaseModel, CallTreeNode, EventNode
Expand Down Expand Up @@ -49,15 +49,15 @@ class TraceFrame(BaseModel):
storage: dict[HexBytes, HexBytes] = {}
"""Contract storage."""

contract_address: Optional[HexBytes20] = None
contract_address: Optional[HashBytes20] = None
"""The address producing the frame."""

@field_validator("pc", "gas", "gas_cost", "depth", mode="before")
def validate_ints(cls, value):
return int(value, 16) if isinstance(value, str) else value

@property
def address(self) -> Optional[HexBytes20]:
def address(self) -> Optional[HashBytes20]:
"""
The address of this CALL frame.
Only returns a value if this frame's opcode is a call-based opcode.
Expand All @@ -66,7 +66,7 @@ def address(self) -> Optional[HexBytes20]:
if not self.contract_address and (
self.op in CALL_OPCODES and CallType.CREATE.value not in self.op
):
self.contract_address = HexBytes20.__eth_pydantic_validate__(self.stack[-2][-20:])
self.contract_address = HashBytes20.__eth_pydantic_validate__(self.stack[-2][-20:])

return self.contract_address

Expand Down Expand Up @@ -116,7 +116,7 @@ def _get_create_frames(frame: TraceFrame, frames: Iterator[dict]) -> list[TraceF
# the first frame after the CREATE with an equal depth.
if len(next_frame_obj.stack) > 0:
raw_addr = HexBytes(next_frame_obj.stack[-1][-40:])
frame.contract_address = HexBytes20.__eth_pydantic_validate__(raw_addr)
frame.contract_address = HashBytes20.__eth_pydantic_validate__(raw_addr)

create_frames.append(next_frame_obj)
break
Expand Down Expand Up @@ -188,7 +188,7 @@ def create_call_node_data(frame: TraceFrame) -> dict:
data: dict = {"address": frame.address, "depth": frame.depth}
if frame.op == CallType.CALL.value:
data["call_type"] = CallType.CALL
data["value"] = int(frame.stack[-3].hex(), 16)
data["value"] = int(to_hex(frame.stack[-3]), 16)
data["calldata"] = frame.memory.get(frame.stack[-4], frame.stack[-5])
elif frame.op == CallType.DELEGATECALL.value:
data["call_type"] = CallType.DELEGATECALL
Expand All @@ -197,10 +197,10 @@ def create_call_node_data(frame: TraceFrame) -> dict:
# `calldata` and `address` are handle in later frames for CREATE and CREATE2.
elif frame.op == CallType.CREATE.value:
data["call_type"] = CallType.CREATE
data["value"] = int(frame.stack[-1].hex(), 16)
data["value"] = int(to_hex(frame.stack[-1]), 16)
elif frame.op == CallType.CREATE2.value:
data["call_type"] = CallType.CREATE2
data["value"] = int(frame.stack[-1].hex(), 16)
data["value"] = int(to_hex(frame.stack[-1]), 16)

else:
data["call_type"] = CallType.STATICCALL
Expand Down Expand Up @@ -274,7 +274,7 @@ def _create_node(
node_kwargs["last_create_depth"].pop()
for subcall in node_kwargs.get("calls", [])[::-1]:
if subcall.call_type in (CallType.CREATE, CallType.CREATE2):
subcall.address = HexBytes20.__eth_pydantic_validate__(frame.stack[-1][-40:])
subcall.address = HashBytes20.__eth_pydantic_validate__(frame.stack[-1][-40:])
if len(frame.stack) >= 5:
subcall.calldata = frame.memory.get(frame.stack[-4], frame.stack[-5])

Expand Down
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exclude =
docs
build
evm_trace/version.py
ignore = E704,W503,PYD002
per-file-ignores =
# The traces have to be formatted this way for the tests.
tests/expected_traces.py: E501
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"eth-hash[pysha3]", # For eth-utils address checksumming
],
"lint": [
"black>=24.4.2,<25", # Auto-formatter and linter
"mypy>=1.10.0,<2", # Static type analyzer
"black>=24.8.0,<25", # Auto-formatter and linter
"mypy>=1.11.1,<2", # Static type analyzer
"types-setuptools", # Needed for mypy type shed
"flake8>=7.0.0,<8", # Style linter
"flake8>=7.1.1,<8", # Style linter
"flake8-breakpoint>=1.1.0,<2", # Detect breakpoints left in code
"flake8-print>=5.0.0,<6", # Detect print statements left in code
"isort>=5.10.1,<6", # Import sorting linter
Expand Down Expand Up @@ -61,10 +61,10 @@
include_package_data=True,
install_requires=[
"pydantic>=2.5.2,<3",
"py-evm>=0.10.0b6,<0.11",
"eth-utils>=2.3.1,<3",
"py-evm>=0.10.1b1,<0.11",
"eth-utils>=2.3.1,<6",
"msgspec>=0.8",
"eth-pydantic-types>=0.1.0a5",
"eth-pydantic-types>=0.1.3,<0.2",
],
python_requires=">=3.9,<4",
extras_require=extras_require,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_geth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from eth_pydantic_types import HexBytes
from eth_utils import to_checksum_address
from eth_utils import to_checksum_address, to_hex
from pydantic import ValidationError

from evm_trace.enums import CallType
Expand Down Expand Up @@ -240,7 +240,7 @@ def test_create_trace_frames_from_geth_create2_struct_logs(
for frame in frames:
if frame.op.startswith("CREATE"):
assert frame.address
address = frame.address.hex()
address = to_hex(frame.address)
assert address.startswith("0x")
assert len(address) == 42
create2_found = create2_found or frame.op == "CREATE2"
Expand Down

0 comments on commit af95600

Please sign in to comment.