Compare commits

..

No commits in common. "master" and "732466de2779846791d65bfb88a793a0a1e30fcc" have entirely different histories.

12 changed files with 67 additions and 172 deletions

View File

@ -1,5 +0,0 @@
- 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

View File

@ -1,31 +0,0 @@
# 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,8 +23,9 @@ from chainlib.jsonrpc import JSONRPCRequest
from chainlib.eth.constant import ZERO_ADDRESS from chainlib.eth.constant import ZERO_ADDRESS
from hexathon import ( from hexathon import (
add_0x, add_0x,
strip_0x,
) )
from cic_contracts.registry import to_identifier
# local imports # local imports
from .interface import ( from .interface import (
#TokenUniqueSymbolIndex, #TokenUniqueSymbolIndex,
@ -37,13 +38,6 @@ moddir = os.path.dirname(__file__)
datadir = os.path.join(moddir, '..', 'data') 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(TokenUniqueSymbolIndex):
class TokenUniqueSymbolIndexAddressDeclarator(CICTokenIndex): class TokenUniqueSymbolIndexAddressDeclarator(CICTokenIndex):

View File

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

View File

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

View File

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

View File

@ -25,7 +25,7 @@ from okota.token_index.index import (
# test imports # test imports
from eth_address_declarator.unittest import TestAddressDeclaratorBase from eth_address_declarator.unittest import TestAddressDeclaratorBase
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger() logg = logging.getLogger()
testdir = os.path.dirname(__file__) testdir = os.path.dirname(__file__)
@ -54,11 +54,12 @@ class TestTokenIndex(TestAddressDeclaratorBase):
r = self.rpc.do(o) r = self.rpc.do(o)
self.assertEqual(r['status'], 1) self.assertEqual(r['status'], 1)
def test_register(self): def test_register(self):
nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc) nonce_oracle = RPCNonceOracle(self.accounts[0], self.rpc)
c = CICTokenIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) 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) (tx_hash_hex, o) = c.add(self.token_index_address, self.accounts[0], self.foo_token_address)
self.rpc.do(o) self.rpc.do(o)
e = unpack(bytes.fromhex(strip_0x(o['params'][0])), self.chain_spec) e = unpack(bytes.fromhex(strip_0x(o['params'][0])), self.chain_spec)
@ -86,46 +87,13 @@ class TestTokenIndex(TestAddressDeclaratorBase):
o = c.declaration(self.address, self.accounts[0], self.foo_token_address, sender_address=self.accounts[0]) o = c.declaration(self.address, self.accounts[0], self.foo_token_address, sender_address=self.accounts[0])
r = self.rpc.do(o) r = self.rpc.do(o)
proofs = c.parse_declaration(r) proofs = c.parse_declaration(r)
identifier = to_identifier('FOO') h = hashlib.sha256()
#h = hashlib.sha256() h.update('FOO'.encode('utf-8'))
#h.update('FOO'.encode('utf-8')) z = h.digest()
#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__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -24,7 +24,7 @@ contract ContractRegistryAddressDeclarator {
addressDeclarator = _addressDeclarator; addressDeclarator = _addressDeclarator;
} }
function set(bytes32 _identifier, address _address) public returns (bool) { //, bytes32 _chainDescriptor, bytes32 _chainConfig) public returns (bool) { function set(bytes32 _identifier, address _address, bytes32 _chainDescriptor, bytes32 _chainConfig) public returns (bool) {
require(msg.sender == owner); require(msg.sender == owner);
require(entries[_identifier] == address(0)); require(entries[_identifier] == address(0));
@ -51,72 +51,38 @@ contract ContractRegistryAddressDeclarator {
require(ok); require(ok);
require(r[31] == 0x01); 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; entries[_identifier] = _address;
///chainIdentifiers[_identifier] = _chainDescriptor; chainIdentifiers[_identifier] = _chainDescriptor;
//chainConfigs[_chainDescriptor] = _chainConfig; chainConfigs[_chainDescriptor] = _chainConfig;
return true; 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 // Implements EIP 173
function transferOwnership(address _newOwner) public returns (bool) { function transferOwnership(address _newOwner) public returns (bool) {
require(msg.sender == owner); require(msg.sender == owner);

View File

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