Skip to content

Commit

Permalink
trace rendering: extract selector from calldata (#339)
Browse files Browse the repository at this point in the history
  • Loading branch information
karmacoma-eth authored Aug 13, 2024
1 parent f7ff1f8 commit 5292bd2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 12 additions & 1 deletion src/halmos/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,18 @@ def rendered_trace(context: CallContext) -> str:


def rendered_calldata(calldata: ByteVec, contract_name: str | None = None) -> str:
return hexify(calldata.unwrap(), contract_name) if calldata else "0x"
if not calldata:
return "0x"

if len(calldata) < 4:
return hexify(calldata)

if len(calldata) == 4:
return f"{hexify(calldata.unwrap(), contract_name)}()"

selector = calldata[:4].unwrap()
args = calldata[4:].unwrap()
return f"{hexify(selector, contract_name)}({hexify(args)})"


def render_trace(context: CallContext, file=sys.stdout) -> None:
Expand Down
9 changes: 3 additions & 6 deletions src/halmos/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,9 @@ def __init__(self):
self._deployed_contracts: Dict[str, str] = {}

# Set up some default mappings
self.add_deployed_contract(
"0x7109709ecfa91a80626ff3989d68f67f5b1dd12d", "HEVM_ADDRESS"
)
self.add_deployed_contract(
"0xf3993a62377bcd56ae39d773740a5390411e8bc9", "SVM_ADDRESS"
)
self.add_deployed_contract("0x7109709ecfa91a80626ff3989d68f67f5b1dd12d", "hevm")
self.add_deployed_contract("0xf3993a62377bcd56ae39d773740a5390411e8bc9", "svm")
self.add_deployed_contract("0x636f6e736f6c652e6c6f67", "console")

def add_deployed_contract(
self,
Expand Down

0 comments on commit 5292bd2

Please sign in to comment.