mirror of
https://github.com/logos-co/nomos-specs.git
synced 2025-02-13 07:46:35 +00:00
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)}"
|
assert isinstance(self.rand, Field), f"rand is {type(self.rand)}"
|
||||||
|
|
||||||
def verify_death(self, death_cm: Field, death_proof: Proof) -> bool:
|
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
|
# 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)
|
return constraint.verify(death_proof)
|
||||||
|
|
||||||
def verify_birth(self, birth_proof: Proof) -> bool:
|
def verify_birth(self, birth_proof: Proof) -> bool:
|
||||||
@ -156,11 +163,3 @@ class SecretNote:
|
|||||||
to the nf_pk in the public note commitment.
|
to the nf_pk in the public note commitment.
|
||||||
"""
|
"""
|
||||||
return prf("NULLIFIER", self.nonce, self.nf_sk)
|
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
|
@dataclass
|
||||||
class InputNote:
|
class InputNote:
|
||||||
note: SecretNote
|
note: SecretNote
|
||||||
|
death_cm: Field # commitment to the death constraint we are using
|
||||||
death_proof: Proof
|
death_proof: Proof
|
||||||
|
|
||||||
def verify(self):
|
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
|
@dataclass
|
||||||
@ -21,7 +23,8 @@ class OutputNote:
|
|||||||
birth_proof: Proof
|
birth_proof: Proof
|
||||||
|
|
||||||
def verify(self):
|
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?
|
# TODO: is this used?
|
||||||
@ -43,7 +46,7 @@ class PartialTransaction:
|
|||||||
def verify(self) -> bool:
|
def verify(self) -> bool:
|
||||||
valid_inputs = all(i.verify() for i in self.inputs)
|
valid_inputs = all(i.verify() for i in self.inputs)
|
||||||
valid_outputs = all(o.verify() for o in self.outputs)
|
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:
|
def balance(self) -> Point:
|
||||||
output_balance = sum(
|
output_balance = sum(
|
||||||
@ -56,10 +59,6 @@ class PartialTransaction:
|
|||||||
)
|
)
|
||||||
return output_balance + input_balance.negate()
|
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:
|
def zero(self) -> Field:
|
||||||
output_zero = sum(
|
output_zero = sum(
|
||||||
(n.note.zero(self.rand) for n in self.outputs),
|
(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 partial_transaction import PartialTransaction, InputNote, OutputNote
|
||||||
from transaction_bundle import TransactionBundle
|
from transaction_bundle import TransactionBundle
|
||||||
|
|
||||||
import constraints
|
from constraints import Vacuous
|
||||||
|
|
||||||
|
|
||||||
class TestTransfer(TestCase):
|
class TestTransfer(TestCase):
|
||||||
@ -28,8 +28,8 @@ class TestTransfer(TestCase):
|
|||||||
note=InnerNote(
|
note=InnerNote(
|
||||||
value=100,
|
value=100,
|
||||||
unit="NMO",
|
unit="NMO",
|
||||||
birth_constraint=constraints.Vacuous(),
|
birth_constraint=Vacuous(),
|
||||||
death_constraints=[constraints.Vacuous()],
|
death_constraints=[Vacuous()],
|
||||||
state=Field.zero(),
|
state=Field.zero(),
|
||||||
nonce=Field.random(),
|
nonce=Field.random(),
|
||||||
rand=Field.random(),
|
rand=Field.random(),
|
||||||
@ -42,8 +42,8 @@ class TestTransfer(TestCase):
|
|||||||
note=InnerNote(
|
note=InnerNote(
|
||||||
value=100,
|
value=100,
|
||||||
unit="NMO",
|
unit="NMO",
|
||||||
birth_constraint=constraints.Vacuous(),
|
birth_constraint=Vacuous(),
|
||||||
death_constraints=[constraints.Vacuous()],
|
death_constraints=[Vacuous()],
|
||||||
state=Field.zero(),
|
state=Field.zero(),
|
||||||
nonce=Field.random(),
|
nonce=Field.random(),
|
||||||
rand=Field.random(),
|
rand=Field.random(),
|
||||||
@ -63,13 +63,14 @@ class TestTransfer(TestCase):
|
|||||||
inputs=[
|
inputs=[
|
||||||
InputNote(
|
InputNote(
|
||||||
note=alices_note,
|
note=alices_note,
|
||||||
death_proof=constraints.Vacuous().prove(),
|
death_cm=Vacuous().hash(),
|
||||||
|
death_proof=Vacuous().prove(),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
outputs=[
|
outputs=[
|
||||||
OutputNote(
|
OutputNote(
|
||||||
note=bobs_note,
|
note=bobs_note,
|
||||||
birth_proof=constraints.Vacuous().prove(),
|
birth_proof=Vacuous().prove(),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
rand=tx_rand,
|
rand=tx_rand,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user