This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
[zk-token-sdk] Make ElGamalKeypair
fields private
#32190
Merged
samkim-crypto
merged 7 commits into
solana-labs:master
from
samkim-crypto:zk-token-sdk/elgamal-keypair-visibility
Jun 22, 2023
Merged
[zk-token-sdk] Make ElGamalKeypair
fields private
#32190
samkim-crypto
merged 7 commits into
solana-labs:master
from
samkim-crypto:zk-token-sdk/elgamal-keypair-visibility
Jun 22, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Codecov Report
@@ Coverage Diff @@
## master #32190 +/- ##
=========================================
- Coverage 82.0% 82.0% -0.1%
=========================================
Files 769 769
Lines 209137 209208 +71
=========================================
+ Hits 171587 171633 +46
- Misses 37550 37575 +25 |
samkim-crypto
added
v1.16
PRs that should be backported to v1.16
and removed
work in progress
This isn't quite right yet
labels
Jun 20, 2023
CriesofCarrots
approved these changes
Jun 22, 2023
mergify bot
pushed a commit
that referenced
this pull request
Jun 22, 2023
* make `ElGamalKeypair` fields private * update the rest of `zk-token-sdk` for the visibility update * update `zk-token-proof-tests` for the visibility update * update `zk-keygen` for the visibility update * update `zk-token-proof` benches for the updated visibility * cargo fmt * rename `ElGamalKeypair::new` to `ElGamalKeypair::new_for_tests` (cherry picked from commit 1452ed7) # Conflicts: # programs/zk-token-proof/benches/verify_proofs.rs
HaoranYi
pushed a commit
to HaoranYi/solana
that referenced
this pull request
Jun 22, 2023
* make `ElGamalKeypair` fields private * update the rest of `zk-token-sdk` for the visibility update * update `zk-token-proof-tests` for the visibility update * update `zk-keygen` for the visibility update * update `zk-token-proof` benches for the updated visibility * cargo fmt * rename `ElGamalKeypair::new` to `ElGamalKeypair::new_for_tests`
samkim-crypto
added a commit
that referenced
this pull request
Jun 24, 2023
* make `ElGamalKeypair` fields private * update the rest of `zk-token-sdk` for the visibility update * update `zk-token-proof-tests` for the visibility update * update `zk-keygen` for the visibility update * update `zk-token-proof` benches for the updated visibility * cargo fmt * rename `ElGamalKeypair::new` to `ElGamalKeypair::new_for_tests` (cherry picked from commit 1452ed7) # Conflicts: # programs/zk-token-proof/benches/verify_proofs.rs
samkim-crypto
added a commit
that referenced
this pull request
Jun 25, 2023
* make `ElGamalKeypair` fields private * update the rest of `zk-token-sdk` for the visibility update * update `zk-token-proof-tests` for the visibility update * update `zk-keygen` for the visibility update * update `zk-token-proof` benches for the updated visibility * cargo fmt * rename `ElGamalKeypair::new` to `ElGamalKeypair::new_for_tests` (cherry picked from commit 1452ed7) # Conflicts: # programs/zk-token-proof/benches/verify_proofs.rs
samkim-crypto
pushed a commit
that referenced
this pull request
Jun 25, 2023
wen-coding
pushed a commit
to wen-coding/solana
that referenced
this pull request
Aug 15, 2023
* make `ElGamalKeypair` fields private * update the rest of `zk-token-sdk` for the visibility update * update `zk-token-proof-tests` for the visibility update * update `zk-keygen` for the visibility update * update `zk-token-proof` benches for the updated visibility * cargo fmt * rename `ElGamalKeypair::new` to `ElGamalKeypair::new_for_tests`
wen-coding
pushed a commit
to wen-coding/solana
that referenced
this pull request
Aug 15, 2023
* make `ElGamalKeypair` fields private * update the rest of `zk-token-sdk` for the visibility update * update `zk-token-proof-tests` for the visibility update * update `zk-keygen` for the visibility update * update `zk-token-proof` benches for the updated visibility * cargo fmt * rename `ElGamalKeypair::new` to `ElGamalKeypair::new_for_tests`
wen-coding
pushed a commit
to wen-coding/solana
that referenced
this pull request
Aug 15, 2023
* make `ElGamalKeypair` fields private * update the rest of `zk-token-sdk` for the visibility update * update `zk-token-proof-tests` for the visibility update * update `zk-keygen` for the visibility update * update `zk-token-proof` benches for the updated visibility * cargo fmt * rename `ElGamalKeypair::new` to `ElGamalKeypair::new_for_tests`
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Currently, the fields
public
andsecret
in the typeElGamalKeypair
are all public. This is somewhat unnatural and could also cause security issues since thesecret
component implementsCopy
allowing downstream to copy/clone the secret key in memory under the hood.Summary of Changes
public
andsecret
fields inElGamalKeypair
to be privateElGamalKeypair
and getters for its private fieldsI referenced the interface for
Keypair
in the sdk. There, we have the interfaceand
In this PR, I made both getters to return references to
ElGamalSecretKey
andElGamalPubkey
. For secret key, it obviously makes sense to return a reference. For the pubkey part, I thought returning a refernce is more flexible than returning a fully ownedElGamalPubkey
sinceElGamalPubkey
implementsCopy
and hence, the returned variable from the getter can always be dereferenced immediately.But when I was updating the rest of the crates, encountered some occurrences in tests like
which does not compile because the output of
ElGamalKeypair::new_rand()
is freed immediately after its call andrandom_elgamal_pubkey
becomes a dangling pointer. The snippet would work if the getter returned a fully-ownedElGamalPubkey
.With returning a reference, the snippet above has to become
I think generating a random
ElGamalPubkey
without generating a correspondingElGamalSecretKey
will be very rare in practice other than in tests, so I think this is more minor for downstream.But one other example is
There are some issues like these that make the code slightly less ergonomic. I thought about this a bit and I thought going with returning
&ElGamalPubkey
is still the way to go, but I'd be happy to discuss.This is a follow-up to #31468 (comment).
Fixes #