From 50a7e1a2614894546d7e2985fa672282c3ebea71 Mon Sep 17 00:00:00 2001 From: David Rusu Date: Thu, 30 May 2024 16:57:19 +0400 Subject: [PATCH] cl/ptx: 1-to-1 test is passing, but still, not quite finished --- coordination-layer/note.py | 19 +++++++++---------- coordination-layer/partial_transaction.py | 13 ++++++------- coordination-layer/test_transfer.py | 15 ++++++++------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/coordination-layer/note.py b/coordination-layer/note.py index 37eba21..571297a 100644 --- a/coordination-layer/note.py +++ b/coordination-layer/note.py @@ -66,9 +66,16 @@ class InnerNote: assert isinstance(self.rand, Field), f"rand is {type(self.rand)}" def verify_death(self, death_cm: Field, death_proof: Proof) -> bool: - constraint = [d for d in self.death_constraints if d.hash() == deah_cm][0] + constraint = [d for d in self.death_constraints if d.hash() == death_cm] + if len(constraint) == 0: + # given commitment was not one of the allowed death constraints + return False + + constraint = constraint[0] + # TODO: verifying the death constraint should include a commitment to the - # partial transaction. + # partial transaction so that the death constraint can make statements + # regarding the entire transaction. return constraint.verify(death_proof) def verify_birth(self, birth_proof: Proof) -> bool: @@ -156,11 +163,3 @@ class SecretNote: to the nf_pk in the public note commitment. """ return prf("NULLIFIER", self.nonce, self.nf_sk) - - # TODO: is this used? - def zero(self, rand): - """ - Returns the pederson commitment to zero using the same blinding as the balance - commitment. - """ - return pederson_commit(0, self.blinding(rand), self.note.fungibility_domain) diff --git a/coordination-layer/partial_transaction.py b/coordination-layer/partial_transaction.py index f580bfb..d70603f 100644 --- a/coordination-layer/partial_transaction.py +++ b/coordination-layer/partial_transaction.py @@ -9,10 +9,12 @@ from crypto import Field, Point @dataclass class InputNote: note: SecretNote + death_cm: Field # commitment to the death constraint we are using death_proof: Proof def verify(self): - return self.note.verify_death(self.death_proof) + # TODO: note.note is ugly + return self.note.note.verify_death(self.death_cm, self.death_proof) @dataclass @@ -21,7 +23,8 @@ class OutputNote: birth_proof: Proof def verify(self): - return self.note.verify_birth(self.birth_proof) + # TODO: note.note is ugly + return self.note.note.verify_birth(self.birth_proof) # TODO: is this used? @@ -43,7 +46,7 @@ class PartialTransaction: def verify(self) -> bool: valid_inputs = all(i.verify() for i in self.inputs) valid_outputs = all(o.verify() for o in self.outputs) - return valid_inputs and valid_output + return valid_inputs and valid_outputs def balance(self) -> Point: output_balance = sum( @@ -56,10 +59,6 @@ class PartialTransaction: ) return output_balance + input_balance.negate() - # TODO: do we need this? - def blinding(self) -> Field: - return sum(outputs.blinding(self.rand)) - sum(outputs.blinding(self.rand)) - def zero(self) -> Field: output_zero = sum( (n.note.zero(self.rand) for n in self.outputs), diff --git a/coordination-layer/test_transfer.py b/coordination-layer/test_transfer.py index cc7b88b..aef08bc 100644 --- a/coordination-layer/test_transfer.py +++ b/coordination-layer/test_transfer.py @@ -6,7 +6,7 @@ from note import InnerNote, PublicNote, SecretNote, nf_pk from partial_transaction import PartialTransaction, InputNote, OutputNote from transaction_bundle import TransactionBundle -import constraints +from constraints import Vacuous class TestTransfer(TestCase): @@ -28,8 +28,8 @@ class TestTransfer(TestCase): note=InnerNote( value=100, unit="NMO", - birth_constraint=constraints.Vacuous(), - death_constraints=[constraints.Vacuous()], + birth_constraint=Vacuous(), + death_constraints=[Vacuous()], state=Field.zero(), nonce=Field.random(), rand=Field.random(), @@ -42,8 +42,8 @@ class TestTransfer(TestCase): note=InnerNote( value=100, unit="NMO", - birth_constraint=constraints.Vacuous(), - death_constraints=[constraints.Vacuous()], + birth_constraint=Vacuous(), + death_constraints=[Vacuous()], state=Field.zero(), nonce=Field.random(), rand=Field.random(), @@ -63,13 +63,14 @@ class TestTransfer(TestCase): inputs=[ InputNote( note=alices_note, - death_proof=constraints.Vacuous().prove(), + death_cm=Vacuous().hash(), + death_proof=Vacuous().prove(), ) ], outputs=[ OutputNote( note=bobs_note, - birth_proof=constraints.Vacuous().prove(), + birth_proof=Vacuous().prove(), ) ], rand=tx_rand,