From 83eae008187337c4b6c7b7e3f43bcde28a6a64ee Mon Sep 17 00:00:00 2001 From: nolash Date: Tue, 29 Dec 2020 21:51:37 +0100 Subject: [PATCH] Add ERC165 calculator --- AddressDeclarator.sol | 15 +++++++++++++++ Dockerfile | 2 +- Faucet.sol | 3 ++- RegistryClient.sol | 3 ++- RegistryStandard.sol | 12 ++++++++++++ RegistryStandard.txt | 3 +++ TokenEndorsement.sol | 3 +++ TokenRegistryClient.sol | 18 ++++++++++++++++++ calculate_erc165.py | 16 ++++++++++++++++ 9 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 AddressDeclarator.sol create mode 100644 RegistryStandard.sol create mode 100644 RegistryStandard.txt create mode 100644 TokenEndorsement.sol create mode 100644 TokenRegistryClient.sol create mode 100644 calculate_erc165.py diff --git a/AddressDeclarator.sol b/AddressDeclarator.sol new file mode 100644 index 0000000..c4a78d3 --- /dev/null +++ b/AddressDeclarator.sol @@ -0,0 +1,15 @@ +pragma solidity >=0.6.12; + +// Author: Louis Holbrook 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 +// SPDX-License-Identifier: GPL-3.0-or-later +// File-version: 1 +// Description: The ERC20 standard interface as specified in EIP20 (sha256:9f843cbb25a737c9351b0b6a6f54b86864490d0d5284f6877b4929d481d34312) + +interface AddressDeclarator { + function addDeclaration(address _address, bytes32 _proof) external returns ( bytes32 ); + function declaratorCount(address _objectAddress) external view returns ( uint256 ); + function declaratorAddressAt(address _targetAddress, uint256 _idx) external view returns ( address ); + function declaration(address _subjectAddress, address _objectAddress) external view returns ( bytes32[] memory ); + function declarationCount(address _subjectAddress) external view returns ( uint256 ); + function declarationAddressAt(address _subjectAddress, uint256 _idx) external view returns ( address ); +} diff --git a/Dockerfile b/Dockerfile index 3deaadb..bbf5385 100644 --- a/Dockerfile +++ b/Dockerfile @@ -21,4 +21,4 @@ RUN cd cic-contracts && \ LABEL authors="Louis Holbrook 0826EDA1702D1E87C6E2875121D2E7BB88C2A746" LABEL spdx-license-identifier="GPL-3.0-or-later" LABEL description="Ethereum smart contract interfaces used by the CIC component suite" -LABEL version="1" +LABEL version="3" diff --git a/Faucet.sol b/Faucet.sol index 958040a..faa123e 100644 --- a/Faucet.sol +++ b/Faucet.sol @@ -2,7 +2,7 @@ pragma solidity >=0.6.12; // Author: Louis Holbrook 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 // SPDX-License-Identifier: GPL-3.0-or-later -// File-version: 2 +// File-version: 3 interface Faucet { @@ -13,4 +13,5 @@ interface Faucet { function token() external view returns (address); function setAmount(uint256 _amount) external returns (bool); function giveTo(address _recipient) external returns (bool); + function gimme() external returns (bool); } diff --git a/RegistryClient.sol b/RegistryClient.sol index a5c4e5d..279a1dc 100644 --- a/RegistryClient.sol +++ b/RegistryClient.sol @@ -2,9 +2,10 @@ pragma solidity >=0.6.12; // Author: Louis Holbrook 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 // SPDX-License-Identifier: GPL-3.0-or-later -// File-version: 1 +// File-version: 2 interface RegistryClient { + function registryCount() external view returns (uint256); function addressOf(bytes32) external view returns (address); } diff --git a/RegistryStandard.sol b/RegistryStandard.sol new file mode 100644 index 0000000..e85507e --- /dev/null +++ b/RegistryStandard.sol @@ -0,0 +1,12 @@ +pragma solidity >=0.6.12; + +// Author: Louis Holbrook 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 +// SPDX-License-Identifier: GPL-3.0-or-later +// File-version: 1 + + +interface RegistryStandard { + function registryCount() external view returns (uint256); + function addressOf(bytes32) external view returns (address); + function register(bytes32,address) external view returns (bool); +} diff --git a/RegistryStandard.txt b/RegistryStandard.txt new file mode 100644 index 0000000..43e8f5e --- /dev/null +++ b/RegistryStandard.txt @@ -0,0 +1,3 @@ +registryCount() +addressOf(bytes32) +register(bytes32,address) diff --git a/TokenEndorsement.sol b/TokenEndorsement.sol new file mode 100644 index 0000000..4f4155a --- /dev/null +++ b/TokenEndorsement.sol @@ -0,0 +1,3 @@ +interface TokenEndorser { + function getBySymbol(address _tokenAddress) external view returns ( bytes32 ); +} diff --git a/TokenRegistryClient.sol b/TokenRegistryClient.sol new file mode 100644 index 0000000..eb91256 --- /dev/null +++ b/TokenRegistryClient.sol @@ -0,0 +1,18 @@ +pragma solidity >=0.6.12; + +// Author: Louis Holbrook 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 +// SPDX-License-Identifier: GPL-3.0-or-later +// File-version: 1 +// Description: The ERC20 standard interface as specified in EIP20 (sha256:9f843cbb25a737c9351b0b6a6f54b86864490d0d5284f6877b4929d481d34312) + + +// TODO: Rename everything to something more generic +interface TokenEndorser { + function endorsement(bytes32) external view returns ( bytes32 ); + function tokenIndex(address) external view returns ( uint256 ); + function endorser(address, uint256) external view returns ( uint256 ); + function endorserTokenCount(address) external view returns ( uint256 ); + function tokenSymbolIndex(string memory) external view returns ( address ); + function tokens(uint256) external view returns ( address ); + function add(address _token, bytes32 _data) external returns ( bool ); +} diff --git a/calculate_erc165.py b/calculate_erc165.py new file mode 100644 index 0000000..dcf1cfa --- /dev/null +++ b/calculate_erc165.py @@ -0,0 +1,16 @@ +import sys +import web3 + +f = open(sys.argv[1], 'r') +z = b'' +for i in range(32): + z += b'\x00' +while True: + l = f.readline() + if l == '': + break + print('line {}'.format(l)) + h = web3.Web3.keccak(text=l) + z = bytes([a ^ b for a, b in zip(h, z)]) + print(h.hex(), z.hex()) +f.close()