frangio / hardhat-exposed

Automatically expose internal Solidity functions for smart contract testing.
82 stars 13 forks source link

Fix function clash for non-storage arguments #34

Closed Amxx closed 4 months ago

Amxx commented 4 months ago

This is caused by getFunctionId not resolving the UDVT.

Given the following solidity code:

library UdvtConflict {
    type myFirstType is bytes32;
    type mySecondType is bytes32;

    function unwrap(myFirstType t) internal pure returns (bytes32) {
        return myFirstType.unwrap(t);
    }

    function unwrap(mySecondType t) internal pure returns (bytes32) {
        return mySecondType.unwrap(t);
    }
}

getFunctionId will return

The system doesn't see them as colliding, when in fact they do collide.

frangio commented 4 months ago

The issue was more general as only storage arguments were previously handled, which are converted to uint256 indices and thus are particularly likely to cause conflicts. Other types like contract types can also cause conflicts and were not handled correctly.

I've generalized the fix so that we get the "ABI type" of every argument, which in the case of UDVT is the underlying, and use types that have different ABI and source-level types to disambiguate.