cl/ptx: 1-to-1 test is passing, but still, not quite finished
This commit is contained in:
parent
8e98d89a0b
commit
50a7e1a261
|
@ -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)
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue