Skip to content

Commit

Permalink
wip: calldata for fallback and receive
Browse files Browse the repository at this point in the history
  • Loading branch information
daejunpark committed Sep 12, 2024
1 parent 2392a63 commit f71571b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/halmos/cheatcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,23 @@ def create_calldata_generic(

results = []

# empty calldata for receive() and empty fallback() function calls
results.append(ByteVec(Concat(con(32), con(0))))

This comment has been minimized.

Copy link
@karmacoma-eth

karmacoma-eth Sep 12, 2024

Collaborator

would be better to avoid z3 objects when we can:

ByteVec(int(32).to_bytes(32) + int(0).to_bytes(32))

# dummy calldata for nonempty fallback() call
fallback_selector = BitVec("fallback_selector", 4 * 8) # see below for additional constraints
fallback_data_size = 1024 # TODO: configurable
fallback_data = BitVec("fallback_data", fallback_data_size * 8)
results.append(ByteVec(Concat(con(32), con(4+fallback_data_size), fallback_selector, fallback_data)))

This comment has been minimized.

Copy link
@karmacoma-eth

karmacoma-eth Sep 12, 2024

Collaborator

not as neat as the previous one, but could also do this:

fallback_data = ByteVec()
fallback_data.append(int(32).to_bytes(32) + int(4+fallback_data_size).to_bytes(32))
fallback_data.append(fallback_selector)
fallback_data.append(fallback_data)

for funsig in methodIdentifiers:
funname = funsig.split("(")[0]
funselector = methodIdentifiers[funsig]
funinfo = FunctionInfo(funname, funsig, funselector)

# assume fallback_selector differs from all existing selectors
ex.path.append(fallback_selector != con(int(funselector, 16), 32))

This comment has been minimized.

Copy link
@karmacoma-eth

karmacoma-eth Sep 12, 2024

Collaborator

I don't think we need to call con explicitly here, do we?


if not include_view:
fun_abi = find_abi(abi, funinfo)
if fun_abi["stateMutability"] in ["pure", "view"]:
Expand Down
10 changes: 10 additions & 0 deletions tests/regression/test/HalmosCheatCode.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,16 @@ contract HalmosCheatCodeTest is SymTest, Test {
}

contract Mock {
// fallback(bytes calldata input) external payable returns (bytes memory output) { }
fallback() external payable {
console.log("fallback");
console.log(msg.data.length);
}

receive() external payable {
console.log("receive");
}

function f_pure() public pure returns (bytes4) {
return this.f_pure.selector;
}
Expand Down

0 comments on commit f71571b

Please sign in to comment.