-
Notifications
You must be signed in to change notification settings - Fork 21
[zk-sdk-wasm-js] Add functions to create ElGamal ciphertexts from a pre-specified Pedersen opening #196
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
[zk-sdk-wasm-js] Add functions to create ElGamal ciphertexts from a pre-specified Pedersen opening #196
Conversation
| // Check if the commitment matches what the zk-sdk would create. | ||
| let expected_inner = pedersen::Pedersen::with(amount, &opening.inner); | ||
| assert_eq!(commitment.inner, expected_inner); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a relevant assertion anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I tried to remove instances of functions from the zk-sdk and I thought this was a pretty minor assertion, so I removed it. But I don't think it hurts to keep it, so added it back in!
| #[wasm_bindgen(js_name = "encryptWith")] | ||
| pub fn encrypt_with( | ||
| first_pubkey: &ElGamalPubkey, | ||
| second_pubkey: &ElGamalPubkey, | ||
| amount: u64, | ||
| opening: &PedersenOpening, | ||
| ) -> Self { | ||
| let inner = grouped_elgamal::GroupedElGamal::encrypt_with( | ||
| [&first_pubkey.inner, &second_pubkey.inner], | ||
| amount, | ||
| &opening.inner, | ||
| ); | ||
| Self { inner } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we get a test somewhere for this? Maybe something like:
#[wasm_bindgen_test]
fn test_encrypt_with_decrypts_correctly() {
let keypair = ElGamalKeypair::new_rand();
let amount = 42u64;
let opening = PedersenOpening::new_rand();
let ciphertext = keypair.pubkey().encrypt_with(amount, &opening);
let decrypted = keypair.decrypt_u32(&ciphertext);
assert_eq!(decrypted, Some(42));
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep good idea. Added!
Problem
Currently, it is not possible to generate ciphertext validity proofs and equality proofs purely using JS/TS because there is no way to generate an ElGamal ciphertext using a pre-specified Pedersen opening. This function exists in the
zk-sdk, but there is no wrapper function inside thezk-sdk-wasm-jscrate.Summary of Changes
Added the
encrypt_withfunction to thezk-sdk-wasm-jscrate.The reason why I missed this originally was that some of the unit tests are using functions from the
zk-sdkrather than using functions from thezk-sdk-wasm-js. So I also updated some unit tests to use functions directly fromzk-sdk-wasm-js.