Add proof processing

This commit is contained in:
nolash 2021-10-11 19:02:42 +02:00
parent 8451285d0d
commit 09fa8f2a4c
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
6 changed files with 43 additions and 12 deletions

View File

@ -55,6 +55,7 @@ class Attachment(Data):
logg.debug('writing {}'.format(k))
writer.write(k, v)
def __str__(self):
s = ''
for i in range(len(self.contents)):

View File

@ -210,7 +210,9 @@ class CICEth:
c = Declarator(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
results = []
for proof in self.proof.get():
(main_proof, all_proofs) = self.proof.get()
for proof in all_proofs:
logg.debug('proof {} '.format(proof))
k = 'address_declarator_' + proof
o = c.add_declaration(contract_address, signer_address, self.token_address, proof, tx_format=self.tx_format)
r = None

View File

@ -81,6 +81,7 @@ class Proof(Data):
hsh = self.hash(b).hex()
self.attachments[hsh] = self.temp_proof_path
logg.debug('cbor of {} is {} hashes to {}'.format(v, b.hex(), hsh))
if self.extra_attachments != None:
a = self.extra_attachments.asdict()
@ -88,8 +89,27 @@ class Proof(Data):
self.attachments[k] = a[k]
hshs = self.__get_ordered_hashes()
return (hsh, hshs)
def process(self, token_address=None, writer=None):
if writer == None:
writer = self.writer
(hsh, hshs) = self.get()
hshs = list(map(strip_0x, hshs))
hshs_bin = list(map(bytes.fromhex, hshs))
hshs_cat = b''.join(hshs_bin)
r = self.hash(hshs_cat)
r_hex = r.hex()
logg.debug('generated proof {} for hashes {}'.format(r_hex, hshs))
writer.write(r_hex, hshs_cat)
return hshs
return r_hex
def __str__(self):

View File

@ -2,3 +2,4 @@ eth-erc20>=0.1.2a3,<0.2.0
eth_tester==0.5.0b3
py-evm==0.3.0a20
rlp==2.0.1
chainlib-eth>=0.0.10a2,<0.1.0

View File

@ -25,7 +25,6 @@ class TestCICBase(unittest.TestCase):
def setUp(self):
super(TestCICBase, self).setUp()
random.seed(42)
self.initial_description = add_0x(random.randbytes(32).hex())
addresses = [
add_0x(random.randbytes(20).hex()),

View File

@ -8,32 +8,40 @@ from cic import Proof
from cic.attachment import Attachment
# test imports
from tests.base_cic import test_data_dir
from tests.base_cic import (
test_data_dir,
TestCICBase,
)
logging.basicConfig(level=logging.DEBUG)
logg = logging.getLogger()
proof_hash = '0f6fc017f29caf512c0feaaf83bc10614b488311cace2973dc248dc24b01e04f'
foo_hash = '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae'
bar_hash = 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9'
root_merged_hash = '1b38b0e9a2cc0895c72e5f460a613bb0f3d88c4a87c1ee2b39a41c64f1dbcd1e'
root_unmerged_hash = '86d0091b98635a45da472388a1204104d7d10ea1199c1bd9c1d235de73a2c285'
class TestProof(unittest.TestCase):
class TestProof(TestCICBase):
def test_proof_serialize(self):
proof_path = os.path.join(test_data_dir, 'proof')
c = Proof(path=proof_path)
v = c.get()
logg.debug('v {}'.format(v))
c = Proof(path=proof_path, writer=self.outputs_writer)
c.load()
v = c.process()
self.assertEqual(v, root_unmerged_hash)
def test_proof_serialize_merge(self):
proof_path = os.path.join(test_data_dir, 'proof')
attach = Attachment(proof_path)
attach = Attachment(proof_path, writer=self.outputs_writer)
attach.load()
c = Proof(path=proof_path, attachments=attach)
v = c.get()
c = Proof(path=proof_path, attachments=attach, writer=self.outputs_writer)
c.load()
v = c.process()
self.assertEqual(v, root_merged_hash)
if __name__ == '__main__':