Compare commits

...

10 Commits

Author SHA1 Message Date
9bad5b5ccf
Sohail/fix duplicate token entry base 0.4.0 (#3)
* feat: remove unique token check from register fn

* tests: add duplicate entry test

- add FOO
- add FOO

* bump: v0.4.1
2022-06-23 12:22:57 +03:00
lash
179a6d4e03
Upgrade deps 2022-04-20 22:01:28 +00:00
lash
f3f69c937f
Mo better docs 2022-02-21 16:24:18 +00:00
lash
5413295dc7
Clearer docs 2022-02-21 16:22:26 +00:00
lash
f299d9921a
Add readme 2022-02-21 16:13:42 +00:00
lash
1961da25ab
Upgrade eth-address-index 2022-02-21 08:23:51 +00:00
lash
24e697ad37
Add changelog file 2022-02-20 05:22:14 +00:00
lash
397c1310f7
Correct token index identifier generation 2022-01-14 10:12:15 +00:00
nolash
8d67bcdfd2
Bump deps 2021-12-22 20:30:20 +00:00
nolash
be175dc8d3
Remove useless proofs from set function in contract 2021-11-15 14:46:56 +01:00
12 changed files with 172 additions and 67 deletions

5
python/CHANGELOG Normal file
View File

@ -0,0 +1,5 @@
- 0.3.0
* Upgrade eth-address-index aliasing -a for --declarator-address
- 0.2.7
* Replace --declarator-address with -a for view cli cmd
* Update compiled bytecode for python package

31
python/README.md Normal file
View File

@ -0,0 +1,31 @@
# Okota
Okota implements smart contract registries for the CIC network with the [Address Declarator](https://gitlab.com/cicnet/eth-address-index) backend.
For every entry added to the registry, a declaration is added aswell.
In all the below:
* `contract_address` is the address of the deployed Address Declarator contract.
* `subject_address` is the address a declaration is being made about.
* `declarer` is the entity making a declaration about the `subject_address`.
* `proof` a 256-bit proof
## Contract declaration translations
| registry call | declarer | subject | proof |
|---|---|---|---|
| ContractRegistry.set(registry\_identifier, contract\_address) | sender | contract\_address | registry\_identifier |
| AccountsIndex.register(wallet\_address) | sender | wallet\_address | token address of accounts index |
| TokenRegistry.registry(token\_address) | sender | token\_address | sha256(token symbol) |
## Query the declarator with CLI
`eth-accounts-index-view -e <contract_address> -a <declarer_address> <subject_address>`
## Add arbitrary other proofs with CLI
`eth-accounts-index-add -e <contract_address> -y <declarer_keyfile> -a <subject_address> <proof>`

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -23,9 +23,8 @@ from chainlib.jsonrpc import JSONRPCRequest
from chainlib.eth.constant import ZERO_ADDRESS
from hexathon import (
add_0x,
strip_0x,
)
from cic_contracts.registry import to_identifier
# local imports
from .interface import (
#TokenUniqueSymbolIndex,
@ -38,6 +37,13 @@ moddir = os.path.dirname(__file__)
datadir = os.path.join(moddir, '..', 'data')
def to_identifier(txt):
identifier_bytes = txt.upper().encode('utf-8')
h = hashlib.sha256()
identifier_bytes = h.update(identifier_bytes)
identifier = h.digest()
return identifier.hex()
#class TokenUniqueSymbolIndexAddressDeclarator(TokenUniqueSymbolIndex):
class TokenUniqueSymbolIndexAddressDeclarator(CICTokenIndex):

View File

@ -1,9 +1,9 @@
confini~=0.5.1
funga-eth~=0.5.1
chainlib-eth~=0.0.10
eth_erc20~=0.1.2
eth-address-index~=0.2.4
eth-accounts-index~=0.1.2
eth-token-index~=0.2.4
eth-contract-registry~=0.6.3
cic-contracts~=0.0.5
confini~=0.6.0
funga-eth~=0.6.0
chainlib-eth>=0.1.0b1,<0.2.0
eth_erc20~=0.3.0
eth-address-index~=0.5.0
eth-accounts-index~=0.2.0
#eth-token-index~=0.3.0
eth-contract-registry~=0.8.0
cic-contracts~=0.1.0

View File

@ -1,6 +1,6 @@
[metadata]
name = okota
version = 0.2.5a1
version = 0.4.1
description = Registries for CIC using the eth-address-index backend
author = Louis Holbrook
author_email = dev@holbrook.no

View File

@ -49,7 +49,7 @@ class TestContractRegistry(TestAddressDeclaratorBase):
bogus_hash_two = bytearray(32)
bogus_hash_two[0] = 0x01
bogus_hash_two_hex = add_0x(bogus_hash_two.hex())
(tx_hash_hex, o) = c.set(self.registry_address, self.accounts[0], 'FOO', self.registry_address, str(self.chain_spec), bogus_hash_two_hex)
(tx_hash_hex, o) = c.set(self.registry_address, self.accounts[0], 'FOO', self.registry_address)
r = self.rpc.do(o)
o = receipt(r)
rcpt = self.rpc.do(o)
@ -75,18 +75,18 @@ class TestContractRegistry(TestAddressDeclaratorBase):
h = hashlib.sha256()
h.update(str(self.chain_spec).encode('utf-8'))
chain_description_hash = h.digest()
h = hashlib.sha256()
h.update(z)
h.update(chain_description_hash)
z = h.digest()
self.assertEqual(z.hex(), proofs[1])
h = hashlib.sha256()
h.update(z)
h.update(bogus_hash_two)
z = h.digest()
self.assertEqual(z.hex(), proofs[2])
#
# h = hashlib.sha256()
# h.update(z)
# h.update(chain_description_hash)
# z = h.digest()
# self.assertEqual(z.hex(), proofs[1])
#
# h = hashlib.sha256()
# h.update(z)
# h.update(bogus_hash_two)
# z = h.digest()
# self.assertEqual(z.hex(), proofs[2])

View File

@ -25,7 +25,7 @@ from okota.token_index.index import (
# test imports
from eth_address_declarator.unittest import TestAddressDeclaratorBase
logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(level=logging.INFO)
logg = logging.getLogger()
testdir = os.path.dirname(__file__)
@ -54,12 +54,11 @@ class TestTokenIndex(TestAddressDeclaratorBase):
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
def test_register(self):
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
c = CICTokenIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
logg.info('using token index {}'.format(self.token_index_address))
(tx_hash_hex, o) = c.add(self.token_index_address, self.accounts[0], self.foo_token_address)
self.rpc.do(o)
e = unpack(bytes.fromhex(strip_0x(o['params'][0])), self.chain_spec)
@ -87,13 +86,46 @@ class TestTokenIndex(TestAddressDeclaratorBase):
o = c.declaration(self.address, self.accounts[0], self.foo_token_address, sender_address=self.accounts[0])
r = self.rpc.do(o)
proofs = c.parse_declaration(r)
h = hashlib.sha256()
h.update('FOO'.encode('utf-8'))
z = h.digest()
identifier = to_identifier('FOO')
#h = hashlib.sha256()
#h.update('FOO'.encode('utf-8'))
#z = h.digest()
self.assertEqual(proofs[0], z.hex())
#self.assertEqual(proofs[0], z.hex())
self.assertEqual(proofs[0], identifier)
identifier = to_identifier('foo')
self.assertEqual(proofs[0], identifier)
def test_duplicate_entry(self):
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
gft = GiftableToken(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
(tx_hash_hex, o) = gft.constructor(self.accounts[0], 'FooTokenRedeploy', 'FOO', 6)
self.rpc.do(o)
o = receipt(tx_hash_hex)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
self.foo_token_address_redeploy = r['contract_address']
logg.info('second foo token deployed with address {}'.format(self.foo_token_address_redeploy))
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
c = CICTokenIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
logg.info('using token index {}'.format(self.token_index_address))
(tx_hash_hex, o) = c.add(self.token_index_address, self.accounts[0], self.foo_token_address_redeploy)
self.rpc.do(o)
e = unpack(bytes.fromhex(strip_0x(o['params'][0])), self.chain_spec)
o = receipt(tx_hash_hex)
r = self.rpc.do(o)
self.assertEqual(r['status'], 1)
o = c.address_of(self.token_index_address, 'FOO', sender_address=self.accounts[0])
r = self.rpc.do(o)
address = c.parse_address_of(r)
self.assertEqual(address, strip_0x(self.foo_token_address_redeploy))
if __name__ == '__main__':
unittest.main()

View File

@ -24,7 +24,7 @@ contract ContractRegistryAddressDeclarator {
addressDeclarator = _addressDeclarator;
}
function set(bytes32 _identifier, address _address, bytes32 _chainDescriptor, bytes32 _chainConfig) public returns (bool) {
function set(bytes32 _identifier, address _address) public returns (bool) { //, bytes32 _chainDescriptor, bytes32 _chainConfig) public returns (bool) {
require(msg.sender == owner);
require(entries[_identifier] == address(0));
@ -51,38 +51,72 @@ contract ContractRegistryAddressDeclarator {
require(ok);
require(r[31] == 0x01);
buf = new bytes(64);
for (i = 0; i < 32; i++) {
buf[i] = identifierHash[i];
}
for (i = 0; i < 32; i++) {
buf[i+32] = _chainDescriptor[i];
}
identifierHash = sha256(buf);
(ok, r) = addressDeclarator.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _address, identifierHash));
require(ok);
require(r[31] == 0x01);
for (i = 0; i < 32; i++) {
buf[i] = identifierHash[i];
}
for (i = 0; i < 32; i++) {
buf[i+32] = _chainConfig[i];
}
identifierHash = sha256(buf);
(ok, r) = addressDeclarator.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _address, identifierHash));
require(ok);
require(r[31] == 0x01);
entries[_identifier] = _address;
chainIdentifiers[_identifier] = _chainDescriptor;
chainConfigs[_chainDescriptor] = _chainConfig;
///chainIdentifiers[_identifier] = _chainDescriptor;
//chainConfigs[_chainDescriptor] = _chainConfig;
return true;
}
// function set(bytes32 _identifier, address _address, bytes32 _chainDescriptor, bytes32 _chainConfig) public returns (bool) {
// require(msg.sender == owner);
// require(entries[_identifier] == address(0));
//
// bool ok;
// bytes memory r;
// bool found = false;
// bytes32 identifierHash;
// bytes memory buf;
// uint8 i;
//
// for (i = 0; i < identifiers.length; i++) {
// if (identifiers[i] == _identifier) {
// found = true;
// }
// }
// require(found, 'ERR_IDENTIFIER');
//
// buf = new bytes(32);
// for (i = 0; i < 32; i++) {
// buf[i] = _identifier[i];
// }
// identifierHash = sha256(buf);
// (ok, r) = addressDeclarator.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _address, identifierHash));
// require(ok);
// require(r[31] == 0x01);
//
// buf = new bytes(64);
// for (i = 0; i < 32; i++) {
// buf[i] = identifierHash[i];
// }
// for (i = 0; i < 32; i++) {
// buf[i+32] = _chainDescriptor[i];
// }
//
// identifierHash = sha256(buf);
// (ok, r) = addressDeclarator.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _address, identifierHash));
// require(ok);
// require(r[31] == 0x01);
//
//
// for (i = 0; i < 32; i++) {
// buf[i] = identifierHash[i];
// }
// for (i = 0; i < 32; i++) {
// buf[i+32] = _chainConfig[i];
// }
// identifierHash = sha256(buf);
// (ok, r) = addressDeclarator.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _address, identifierHash));
// require(ok);
// require(r[31] == 0x01);
//
// entries[_identifier] = _address;
// chainIdentifiers[_identifier] = _chainDescriptor;
// chainConfigs[_chainDescriptor] = _chainConfig;
//
// return true;
// }
//
// Implements EIP 173
function transferOwnership(address _newOwner) public returns (bool) {
require(msg.sender == owner);

View File

@ -55,9 +55,6 @@ contract TokenUniqueSymbolIndexAddressDeclarator {
require(ok);
require(r[31] == 0x01);
idx = registry[token_symbol_key];
require(idx == 0);
registry[token_symbol_key] = tokens.length;
tokens.push(_token);