-
Notifications
You must be signed in to change notification settings - Fork 362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to use the FFI cheatcode from HEVM in Echidna #750
Conversation
Gave it a quick try, but as soon as I add
Same contract works as expected with foundry:
Source: testMode: assertion
seqLen: 1
allowFFI: true // SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
address constant HEVM_ADDRESS = 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D;
interface CheatCodes {
// Performs a foreign function call via terminal
function ffi(string[] calldata) external returns (bytes memory);
}
contract Test {
function test(bytes memory input) external {
string[] memory inputs = new string[](3);
inputs[0] = "echo";
inputs[1] = "-n";
// ABI encoded "gm", as a string
inputs[2] = "0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002676d000000000000000000000000000000000000000000000000000000000000";
bytes memory res = CheatCodes(HEVM_ADDRESS).ffi(inputs);
string memory output = abi.decode(res, (string));
// Should fail.
assert(keccak256(bytes(output)) == keccak256("gm2"));
}
} |
testMode: assertion
seqLen: 1
allowFFI: true
initialize: echidna.json After adding an initialization file it's no longer stuck at startup but then the FFI call apparently reverts and the assertion that is supposed to fail does not. (same behavior as if Ah, I assume it's because of this? (Right (ethenoInit :: [Etheno])) -> do
-- Execute contract creations and initial transactions,
let initVM = foldM execEthenoTxs () ethenoInit
- (_, vm') <- runStateT initVM initialVM
+ (_, vm') <- runStateT initVM (initialVM False) -- No FFI is allowed here Is using FFI with init files really not possible? (Asking because foundry allows something similar via |
You don't need to add echidna initiation here. However, hevm seems to be crashing for some reason:
I'm investigating this issue. |
Thanks! I'd like to use the echidna |
Uhm, I see. I will keep working on ths PR to include that feature. Btw, it seems that FFI is implemented using oracles in HEVM: This can take a little longer to implement, but it still should be doable soon. |
I don't know anything about Haskell but let me know if I can help somehow |
@patrickd- can you re-try using the latest commit in this branch? It should work with the example (but the .json initialization is still need to be fixed before you can use it) |
The only difference to foundry that I noticed is that in Echidna the stdout hex always needs to be prefixed with But that's not much of an issue.. besides that everything seems to be working as expected! |
Just push the code to allow ffi when using a json initialization. However, the code is very preliminary, so consider this like an a beta code that will be improved in the future before merging it. |
Awesome! Everything seems to work fine at least. I'll let you know if I notice any issues |
This PR allows to use the FFI cheatcode from HEVM in Echidna if the
allowFFI: true
is used in the configuration yaml. This is disabled by default.