Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5e02514
A standard for interface detection, fixes #165
fulldecent Feb 13, 2018
7558488
Discuss optional interfaces per @dete advice
fulldecent Feb 13, 2018
224822c
Add two competing implementations
fulldecent Feb 14, 2018
4b7b916
Add author email addresses per latest EIP-X
fulldecent Feb 14, 2018
6e4394d
Update caching contract
fulldecent Feb 15, 2018
d39b388
Add author Konrad Feldmeier
fulldecent Feb 15, 2018
50f59da
Updated to use staticcall
fulldecent Feb 16, 2018
529ce1b
Update cache to use explicit return values of 32 byte length
fulldecent Feb 16, 2018
26c9118
"uses less than"
fulldecent Feb 16, 2018
ad70b8d
Function selectors are defined by Ethereum, not Solidity
fulldecent Feb 16, 2018
3928548
Remove authors @VoR0220 @Souptacular @GriffGreen
fulldecent Feb 16, 2018
b97350c
Copyediting review
fulldecent Feb 17, 2018
881f577
Bytes, version 0.4.20, thanks @veox
fulldecent Feb 19, 2018
734d68b
Use 32-byte words
fulldecent Feb 19, 2018
b675b4b
Update zero padding, thank you @veox
fulldecent Feb 20, 2018
12fe0b5
Switch from a cache to a query contract, cache is out of scope
fulldecent Feb 20, 2018
1947d2f
Complete Homer implementation
fulldecent Feb 20, 2018
490ce29
not a cache
fulldecent Feb 20, 2018
4ecf584
32 bytes input
fulldecent Feb 21, 2018
50ad36b
Hex, not string
fulldecent Feb 21, 2018
e902727
Nibbles are not bytes, duh
fulldecent Feb 21, 2018
d47923b
Update link
fulldecent Feb 21, 2018
03c67d2
interfaced -> interacted
fulldecent Feb 21, 2018
2cb6f91
Update eip-165.md
nicksavers Feb 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add two competing implementations
  • Loading branch information
fulldecent authored Feb 14, 2018
commit 224822c743be51ff6b2762a1958507b4ea81637c
61 changes: 57 additions & 4 deletions EIPS/eip-165.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ contract Selector {
}
```

Note: interfaces do not permit optional functions, therefore, the interface identity will not include them.

Note: an ERC standard may define multiple interfaces to separate core functionality from optional features. For example, [one draft standard defines](https://github.com/ethereum/EIPs/pull/841) ERC721, ERC721Metadata and ERC721Enumerable interfaces.
Note: interfaces do not permit optional functions, therefore, the interface identity will not them.

### How a Contract will Publish the Interfaces it Implements

A contract that is compliant with ERC-165 shall implement the following function:
A contract that is compliant with ERC-165 shall implement the following interface (referred as `ERC165.sol`):

```solidity
pragma solidity ^0.4.19;
Expand Down Expand Up @@ -116,6 +114,61 @@ XXXXXXXX HELP NEEDED XXXXXXXXX

## Implementation

This approach uses a `view` function implementation of `supportsInterface`. The execution cost is 478 gas for any input. But contract initialization requires storing each interface (`SSTORE` is 20,000 gas).

```solidity
pragma solidity ^0.4.19;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps 0.4.20 here also?..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


import "./ERC165.sol";

interface Simpson {
function is2D() external returns (bool);
function skinColor() external returns (string);
}

contract Lisa is ERC165, Simpson {
mapping(bytes4 => bool) supportedInterfaces;

function Lisa() public {
supportedInterfaces[this.supportsInterface.selector] = true;
supportedInterfaces[this.is2D.selector ^ this.skinColor.selector] = true;
}

function supportsInterface(bytes4 interfaceID) external view returns (bool) {
return supportedInterfaces[interfaceID];
}

// ... is usually 2D
// skin color is yellow
}
```

Following is a `pure` function implementation of `supportsInterface`. The worst-case execution cost is 236 gas, but increases linearly with a higher number of supported interfaces.

```solidity
pragma solidity ^0.4.19;

import "./ERC165.sol";

interface Simpson {
function is2D() external returns (bool);
function skinColor() external returns (string);
}

contract Homer is ERC165, Simpson {
function supportsInterface(bytes4 interfaceID) external view returns (bool) {
return
interfaceID == this.supportsInterface.selector || // ERC165
interfaceID == this.is2D.selector
^ this.skinColor.selector; // Simpson
}
}
```

With three or more supported interfaces (including ERC165 itself as a required supported interface), the mapping table approach (for any case) costs less gas than the worst case for pure approach.



XXXXXX IN PROGRES XXXXXX [https://github.com/jbaylina/EIP165Cache](https://github.com/jbaylina/EIP165Cache)

## Copyright
Expand Down