Vectorized / dn404

Implementation of a co-joined ERC20 and ERC721 pair.
MIT License
476 stars 158 forks source link

DN404 identification #69

Open ghost opened 9 months ago

ghost commented 9 months ago

Currently, it would be possible to use staticcall for mirrorERC721 in order to detect if the contract is DN404 however this could also cause an issue with abi.decode since it doesn't catch decoding errors effectively

https://github.com/ethereum/solidity/issues/10381

Therefore, the cleanest method would be supporting an arbitrary value for supportsInterface function

https://github.com/Vectorized/dn404/pull/68

Vectorized commented 9 months ago
function _getMirrorERC721(address possibleDN404) internal view returns (address result) {
    assembly {
        mstore(0x00, 0x4ef41efc) // `mirrorERC721()`.
        if and(
            gt(returndatasize(), 0x1f),
            staticcall(gas(), possibleDN404, 0x1c, 0x04, 0x00, 0x20)
        ) {
            // If result is a non-zero address, contract is very likely DN404.
            result := shr(96, mload(0x0c)) 
        }
    }   
}
ghost commented 9 months ago

@Vectorized Would be great if we have a set of functions like this as a library contract

Vectorized commented 9 months ago

Sounds like good suggestion.