Skip to content

[Bug-Candidate]: When returning from an ffi action, special characters are not stripped. #1129

@ShaneDuncan602

Description

@ShaneDuncan602

Describe the issue:

When calling a python script to retrieve abi information and return that information to echidna tests, special characters(like \n) are not being stripped and cause data conversion issues. This python script is being used with Foundry tests with no issues because Foundry strips the special characters to keep this from happening.

I think it should have more parity with Foundry test ffi or give more descriptive output.

Code example to reproduce the issue:

python script '
import subprocess
import argparse
import json

from eth_abi import encode

def get_selectors(args):
contract = args.contract

res = subprocess.run(
    ["forge", "inspect", contract, "mi"], capture_output=True)
res = res.stdout.decode()
res = json.loads(res)

selectors = []
for signature in res:
    selector = res[signature]
    selectors.append(bytes.fromhex(selector))

enc = encode(["bytes4[]"], [selectors])
print("0x" + enc.hex())

def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("contract", type=str)
return parser.parse_args()

def main():
args = parse_args()
get_selectors(args)

if name == "main":
main()
'

solidity function that calls script: '
/**
* @dev deploy a facet and return its address
*/
function _deployFacetAndGetSelectors(bytes memory _bytecode, string memory _facetName) internal returns (address _facetAddress, bytes4[] memory _selectors) {
// deploy the facet
assembly {
_facetAddress := create(0, add(_bytecode, 0x20), mload(_bytecode))
}
string[] inputs = ["python3", "script/python/get_selectors.py", ""];
// Get the facet selectors.
inputs[2] = _facetName;
bytes memory res = vm.ffi(inputs);
_selectors = abi.decode(res, (bytes4[]));
return (_facetAddress, _selectors);
}
'

Version:

Echidna 2.2.1
Slither 0.9.1

Relevant log output:

echidna: Internal error: invalid hex bytestring "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000027240f9af0000000000000000000000000000000000000000000000000000000054fd4d5000000000000000000000000000000000000000000000000000000000\n" -- CallStack (from HasCallStack):
  internalError, called at src/EVM/Format.hs:602:10 in hevm-0.51.3-AoN9URJtMgjJhononiOAyj:EVM.Format
CallStack (from HasCallStack):
  error, called at src/EVM/Types.hs:1273:19 in hevm-0.51.3-AoN9URJtMgjJhononiOAyj:EVM.Types
  internalError, called at src/EVM/Format.hs:602:10 in hevm-0.51.3-AoN9URJtMgjJhononiOAyj:EVM.Format

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions