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

Add ERC165Checker.getSupportedInterfaces #2469

Conversation

conspyrosy
Copy link
Contributor

@conspyrosy conspyrosy commented Jan 12, 2021

Fixes #2429

See the issue, explained there.

Tests work. Linter giving me line errors in windows

Amxx
Amxx previously requested changes Jan 13, 2021
contracts/introspection/ERC165Checker.sol Outdated Show resolved Hide resolved
test/introspection/ERC165Checker.test.js Show resolved Hide resolved
@Amxx
Copy link
Collaborator

Amxx commented Jan 13, 2021

Thank you @conspyrosy for your PR. We really appreciate feeback from the community, and we appreciate it even more when the community members contributes to the codebase with the feature they see as most relevant to them.

I do believe that, by default, newly allocated arrays should contain 0 (@frangio can you confirme this?), which in boolean terms means false.

If so the getSupportedInterface can be shorten to:

function getSupportedInterfaces(address account, bytes4[] memory interfaceIds) internal view returns (bool[] memory) {
    // an array of booleans corresponding to interfaceIds and whether they're supported or not
    bool[] memory interfaceIdsSupported = new bool[](interfaceIds.length);
    
    // query support of ERC165 itself
    if (supportsERC165(account)) {
        // query support of each interface in interfaceIds
        for (uint256 i = 0; i < interfaceIds.length; ++i) {
            interfaceIdsSupported[i] = _supportsERC165Interface(account, interfaceIds[i]);
        }
    }
    
    return interfaceIdsSupported;
}

@frangio
Copy link
Contributor

frangio commented Jan 14, 2021

Thanks @conspyrosy!

I do believe that, by default, newly allocated arrays should contain 0 (@frangio can you confirme this?), which in boolean terms means false.

I'm pretty sure this is the case but I couldn't find it in the documentation for Solidity. I've asked the team to confirm.

@frangio
Copy link
Contributor

frangio commented Jan 14, 2021

The reply from the Solidity team was:

at the Solidity level, all newly allocated data structures are guaranteed to be initialized properly. At the assembly level, you cannot rely on 0x40 pointing to zeroed out memory

In summary, yes we can just initialize a new array.

@frangio frangio changed the title Feature/erc165 get supported interfaces #2429 Add ERC165Checker.getSupportedInterfaces Jan 18, 2021
@conspyrosy
Copy link
Contributor Author

I've only just got round to checking on this, looks like some changes have been made which look good 👍 Let me know if this needs anything from me.

@frangio
Copy link
Contributor

frangio commented Jan 19, 2021

Hi @conspyrosy, no problem. Sorry that we jumped in, we want to ship this in the next release. 🙂

@frangio frangio merged commit c2c08af into OpenZeppelin:master Jan 19, 2021
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

Successfully merging this pull request may close these issues.

Proposal: ERC165Checker - getSupportedInterfaces
4 participants