Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zero Knowledge Proofs #2

Merged
merged 30 commits into from
Oct 24, 2024
Merged

Zero Knowledge Proofs #2

merged 30 commits into from
Oct 24, 2024

Conversation

dssei
Copy link
Collaborator

@dssei dssei commented Oct 14, 2024

This PR contains the following zero knowledge proofs:

  • Ciphertext ciphertext equality
  • Ciphertext commitment equality
  • Ciphertext validity
  • Public key validity
  • Range
  • Zero Balance

Tests:

  • unit testing

@dssei dssei marked this pull request as draft October 14, 2024 17:39
@dssei dssei requested a review from mj850 October 14, 2024 17:39
Base automatically changed from feature/init_and_workflows to main October 16, 2024 16:25
@dssei dssei marked this pull request as ready for review October 16, 2024 16:29
Copy link
Contributor

@mj850 mj850 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good, most of the comments are stylistic except for the challenge scalar issue in CiphertextValidityProof

@@ -12,6 +14,11 @@ import (
// H_STRING H is a random point on the elliptic curve that is unrelated to G.
const H_STRING = "gPt25pi0eDphSiXWu0BIeIvyVATCtwhslTqfqvNhW2c"

// GenerateKey generates a new ECDSA key pair.
func GenerateKey() (*ecdsa.PrivateKey, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be useful more as a testing function? Should we still export this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do want to export it we could consider renaming it since it may be misleading

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used for testing, but across multiple packages.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, any way to rename this or move this to some test utils file?

This is exposed to user as elgamal.GenerateKey(), which might be confusing (since it might suggest the generation of a el gamal Private Key or el gamal Public Key). Maybe just rename to GenerateEcdsaKey?

pkg/zkproofs/ciphertext_ciphertext_equality_test.go Outdated Show resolved Hide resolved
pkg/zkproofs/ciphertext_validity.go Outdated Show resolved Hide resolved
}

// VerifyRangeProof verifies the range proof for the given ciphertext
func VerifyRangeProof(proof *RangeProof, ciphertext *elgamal.Ciphertext) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment as above, we could consider adding the upperBound to this method as well, since it should be up to the verifier to determine what upper bound they want to check for (just that the associated proof should not work if it's not meant for that upper bound)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

pkg/zkproofs/ciphertext_validity.go Outdated Show resolved Hide resolved
pkg/zkproofs/ciphertext_validity.go Show resolved Hide resolved
pkg/zkproofs/zero_balance.go Show resolved Hide resolved
pkg/zkproofs/zero_balance.go Outdated Show resolved Hide resolved
@dssei
Copy link
Collaborator Author

dssei commented Oct 17, 2024

@mj850 addressed most comments. Ptal

// Step 0: Recompute the challenge using the Fiat-Shamir heuristic.
transcript := NewProofTranscript()
transcript.AppendMessage("C1", proof.Commitment1.ToAffineCompressed())
transcript.AppendMessage("C2", proof.Commitment2.ToAffineCompressed())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we want to add ct.C and ct.D to the challenge as well so the proof can only be used as for the specific ciphertext.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// the proof cannot be for some other set of values.
transcript := NewProofTranscript()
transcript.AppendMessage("C1", Commitment1.ToAffineCompressed())
transcript.AppendMessage("C2", Commitment2.ToAffineCompressed())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think we need to add ciphertext.C and ciphertext.D to the challenge transcript here as well to bind the proof to the specific ciphertext.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -0,0 +1,39 @@
package zkproofs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Should we rename this file to proof_transcript.go

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@dssei
Copy link
Collaborator Author

dssei commented Oct 22, 2024

@mj850 addressed comments, please have another look

Copy link
Contributor

@mj850 mj850 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved!

Still have minor nit in pkg/encryption/elgamal/common.go, lmk what you think there

@dssei dssei merged commit 878abf6 into main Oct 24, 2024
11 checks passed
@dssei dssei deleted the zk branch October 24, 2024 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants