Skip to content

Commit 0f25882

Browse files
committed
linter
1 parent 0446491 commit 0f25882

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

program-analysis/echidna/advanced/interacting-with-offchain-data-via-ffi.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,34 @@
11
# Interacting with off-chain data using the `ffi` cheatcode
22

3-
43
## Introduction
54

65
Since the implementation of the HEVM cheat codes in Echidna, it is possible to interact with off-chain data by means of the `ffi` cheatcode. This function allows the caller to execute an arbitrary command on the system running Echidna and read its output, enabling the possibility of getting external data into a fuzzing campaign.
76

8-
97
## A word of caution
108

11-
In general, the usage of cheatcodes is not encouraged, since manipulating the EVM execution environment can lead to unpredictable results and false positives or negatives in fuzzing tests.
9+
In general, the usage of cheatcodes is not encouraged, since manipulating the EVM execution environment can lead to unpredictable results and false positives or negatives in fuzzing tests.
1210

1311
This piece of advice becomes more critical when using `ffi`. This cheatcode basically allows arbitrary code execution on the host system, so it's not just the EVM execution environment that can be manipulated. Running malicious or untrusted tests with `ffi` can have disastrous consequences.
1412

1513
The usage of this cheatcode should be extremely limited, well documented, and only reserved for cases where there is not a secure alternative.
1614

17-
1815
## Pre-requisites
1916

2017
If reading the previous section didn't scare you enough and you still want to use `ffi`, you will need to explicitly tell Echidna to allow the cheatcode in the tests. This safety measure makes sure you don't accidentally execute `ffi` code.
2118

22-
To enable the cheatcode, set the 'allowFFI` flag to `true` in your Echidna configuration file:
19+
To enable the cheatcode, set the 'allowFFI`flag to`true` in your Echidna configuration file:
2320

2421
```yaml
2522
allowFFI: true
2623
```
2724
28-
2925
## Uses
3026
3127
Some of the use cases for `ffi` are:
3228

33-
* Making prices or other information available on-chain during a fuzzing campaign. For example, you can use `ffi` to feed an oracle with "live" data.
34-
* Get randomness in a test. As you know, there is no randomness source on-chain, so using this cheatcode you can get a random value from the device running the fuzz tests.
35-
* Integrate with algorithms not ported to Solidity language, or perform comparisons between two implementations. Some examples for this item include signing and hashing, or custom calculations algorithms.
36-
29+
- Making prices or other information available on-chain during a fuzzing campaign. For example, you can use `ffi` to feed an oracle with "live" data.
30+
- Get randomness in a test. As you know, there is no randomness source on-chain, so using this cheatcode you can get a random value from the device running the fuzz tests.
31+
- Integrate with algorithms not ported to Solidity language, or perform comparisons between two implementations. Some examples for this item include signing and hashing, or custom calculations algorithms.
3732

3833
## Example: Call an off-chain program and read its output
3934

@@ -69,7 +64,7 @@ print("0x" + abi_encoded, end="")
6964

7065
You can test this program with various inputs and see what the output is. If it works correctly, the program should output a 512-bit hex string that is the ABI-encoded representation of a 256-bit integer followed by a bytes32.
7166

72-
Now let's create the Solidity contract that will be run by Echidna to interact with the previous script.
67+
Now let's create the Solidity contract that will be run by Echidna to interact with the previous script.
7368

7469
```solidity
7570
pragma solidity ^0.8.0;
@@ -82,7 +77,6 @@ import "@crytic/properties/contracts/util/PropertiesHelper.sol";
8277
8378
contract TestFFI {
8479
function test_ffi(uint256 number) public {
85-
8680
// Prepare the array of executable and parameters
8781
string[] memory inp = new string[](3);
8882
inp[0] = "python3";
@@ -108,4 +102,3 @@ The minimal configuration file for this test is the following:
108102
testMode: "assertion"
109103
allowFFI: true
110104
```
111-

0 commit comments

Comments
 (0)