Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Jul 30, 2023
1 parent e4c245b commit 749d5df
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
8 changes: 2 additions & 6 deletions cashu/core/crypto/b_dhke.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def step2_bob_dleq(


def alice_verify_dleq(
e: PrivateKey, s: PrivateKey, A: PublicKey, B_: PublicKey, C_: PublicKey
B_: PublicKey, C_: PublicKey, e: PrivateKey, s: PrivateKey, A: PublicKey
):
R1 = s.pubkey - A.mult(e) # type: ignore
R2 = B_.mult(s) - C_.mult(e) # type: ignore
Expand All @@ -150,11 +150,7 @@ def carol_verify_dleq(
Y: PublicKey = hash_to_curve(secret_msg.encode("utf-8"))
C_: PublicKey = C + A.mult(r) # type: ignore
B_: PublicKey = Y + r.pubkey # type: ignore
return alice_verify_dleq(e, s, A, B_, C_)
# R1 = s.pubkey - A.mult(e) # type: ignore
# R2 = B_.mult(s) - C_.mult(e) # type: ignore
# e_bytes = e.private_key
# return e_bytes == hash_e(R1, R2, A, C_)
return alice_verify_dleq(B_, C_, e, s, A)


# Below is a test of a simple positive and negative case
Expand Down
5 changes: 4 additions & 1 deletion cashu/wallet/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ def verify_proofs_dleq(self, proofs: List[Proof]):
"""Verifies DLEQ proofs in proofs."""
for proof in proofs:
if not proof.dleq:
logger.trace("No DLEQ proof in proof.")
return
logger.debug("Verifying DLEQ proof.")
logger.trace("Verifying DLEQ proof.")
assert self.keys.public_keys
# if not b_dhke.alice_verify_dleq(
# e=PrivateKey(bytes.fromhex(proof.dleq.e), raw=True),
Expand All @@ -166,6 +167,8 @@ def verify_proofs_dleq(self, proofs: List[Proof]):
A=self.keys.public_keys[proof.amount],
):
raise Exception("DLEQ proof invalid.")
else:
logger.debug("DLEQ proof valid.")

def _construct_proofs(
self,
Expand Down
6 changes: 3 additions & 3 deletions tests/test_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def test_dleq_alice_verify_dleq():
raw=True,
)

assert alice_verify_dleq(e, s, A, B_, C_)
assert alice_verify_dleq(B_, C_, e, s, A)


def test_dleq_alice_direct_verify_dleq():
Expand All @@ -274,7 +274,7 @@ def test_dleq_alice_direct_verify_dleq():
),
)
C_, e, s = step2_bob(B_, a)
assert alice_verify_dleq(e, s, A, B_, C_)
assert alice_verify_dleq(B_, C_, e, s, A)


def test_dleq_carol_varify_from_bob():
Expand All @@ -295,7 +295,7 @@ def test_dleq_carol_varify_from_bob():
)
B_, _ = step1_alice(secret_msg, r)
C_, e, s = step2_bob(B_, a)
assert alice_verify_dleq(e, s, A, B_, C_)
assert alice_verify_dleq(B_, C_, e, s, A)
C = step3_alice(C_, r, A)

# carol does not know B_ and C_, but she receives C and r from Alice
Expand Down

0 comments on commit 749d5df

Please sign in to comment.