Skip to content

Commit

Permalink
fix: hexify for extract and const terms
Browse files Browse the repository at this point in the history
  • Loading branch information
daejunpark committed Jan 10, 2025
1 parent 606ac51 commit 890f4c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/halmos/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
is_bool,
is_bv,
is_bv_value,
is_const,
is_not,
simplify,
substitute,
Expand Down Expand Up @@ -454,7 +455,12 @@ def hexify(x, contract_name: str = None):
f"0x{x.as_long():0{num_bytes * 2}x}", contract_name
)
elif is_app(x):
return f"{str(x.decl())}({', '.join(map(partial(hexify, contract_name=contract_name), x.children()))})"
params_and_children = (
f"({', '.join(map(partial(hexify, contract_name=contract_name), x.params() + x.children()))})"
if not is_const(x)
else ""
)
return f"{str(x.decl())}{params_and_children}"
else:
return hexify(str(x), contract_name)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_decode_mixed_bytecode():
)

disassembly = " ".join([str(insn) for insn in insns])
assert disassembly == "PUSH20 x() PUSH0 MSTORE PUSH1 0x14 PUSH1 0x0c RETURN"
assert disassembly == "PUSH20 x PUSH0 MSTORE PUSH1 0x14 PUSH1 0x0c RETURN"

# jump destination scanning
assert contract.valid_jump_destinations() == set()
Expand Down Expand Up @@ -141,7 +141,7 @@ def test_decode_hex():
def test_decode():
code = Contract(Concat(BitVecVal(EVM.PUSH32, 8), BitVec("x", 256)))
assert len(code) == 33
assert str(code.decode_instruction(0)) == "PUSH32 x()"
assert str(code.decode_instruction(0)) == "PUSH32 x"
assert str(code.decode_instruction(33)) == "STOP"

code = Contract(BitVec("x", 256))
Expand All @@ -150,7 +150,7 @@ def test_decode():

code = Contract(Concat(BitVecVal(EVM.PUSH3, 8), BitVec("x", 16)))
assert (
str(code.decode_instruction(0)) == "PUSH3 Concat(x(), 0x00)"
str(code.decode_instruction(0)) == "PUSH3 Concat(x, 0x00)"
) # 'PUSH3 ERROR x (1 bytes missed)'


Expand Down

0 comments on commit 890f4c7

Please sign in to comment.