Skip to content

Commit

Permalink
trace rendering: extract selector from calldata
Browse files Browse the repository at this point in the history
Before:

    CREATE Context::<500 bytes of initcode>
        CALL Context::0x318b04f10000000000000000000000000000000000000000000000000000000000000009
            CALL HEVM_ADDRESS::0xca669fa70000000000000000000000000000000000000000000000000000000000000000
            ↩ 0x
        ↩ CALL 0x (error: HalmosException('You have an active prank already.'))

After:

    CREATE Context::<500 bytes of initcode>
        CALL Context::call0(0x0000000000000000000000000000000000000000000000000000000000000009)
            CALL HEVM_ADDRESS::prank(0x0000000000000000000000000000000000000000000000000000000000000000)
            ↩ 0x
        ↩ CALL 0x (error: HalmosException('You have an active prank already.'))
  • Loading branch information
karmacoma-eth committed Aug 9, 2024
1 parent f7ff1f8 commit 0bb908d
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 0bb908d

Please sign in to comment.