Skip to content
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

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

Open
ShaneDuncan602 opened this issue Oct 13, 2023 · 1 comment

Comments

@ShaneDuncan602
Copy link

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
@ggrieco-tob
Copy link
Member

Hi,

This is really an issue in hevm implementation of ffi, not in echidna. Can you please open an issue in their issue tracker and link to this one?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants