ava-labs / subnet-evm

Launch your own EVM as an Avalanche Subnet
https://docs.avax.network/subnets/create-a-fuji-subnet
GNU Lesser General Public License v3.0
245 stars 225 forks source link

Test Framework / Fuzzing for ABI Package vs. Solidity Packing / Unpacking #769

Open aaronbuchwald opened 1 year ago

aaronbuchwald commented 1 year ago

After migrating an upstream change from geth here: https://github.com/ava-labs/subnet-evm/pull/750 (upstream PR here: https://github.com/ethereum/go-ethereum/pull/26568) we discussed adding better testing coverage to the ABI package.

We should set up a test framework that packs/unpacks Solidity types using the ABI vs. an actual Solidity contract returning an encoded type vs. unpacking a byte array into a specific type to ensure that the behaviors match.

We should set this framework up, so that we can easily run differential fuzzing between the ABI package and a generated Solidity contract that packs / unpacks the relevant types to search for any further edge cases / discrepancies that may exist.

ceyonur commented 1 year ago

We have discussed it with @aaronbuchwald and we lean towards these two solutions:

Test with Web3 Libraries:

Pros:

Cons:

Call precompile contract inside solidity contract:

- We can create a solidity function for different inputs as following:
function encode(string memory _string1, uint _uint, string memory _string2) public pure returns (bytes memory) {
        result = abi.encode(_string1, _uint, _string2)
        precompileResult = precompile.encode(_string1, _uint, _string2)
        require(result == precompileResult)
    }

where the precompile contract is also generated to perform same encoding with abi packers.

Cons: