Commit Graph

67 Commits

Author SHA1 Message Date
samkim-crypto 91186d3860
[zk-token-sdk] replace hard-coded constants with constant variables (#32274)
* add ristretto and scalar byte length constants

* add serialization and deserialization helper functions

* remove hard-coded constants in the `sigma` module

* remove hard-coded constants in the `encryption` module

* remove hard-coded constants in the `zk-token-elgamal` module

* Apply suggestions from code review

Co-authored-by: Tyera <tyera@solana.com>

* fix docs for range proof constants

* Apply suggestions from code review

Co-authored-by: Tyera <tyera@solana.com>

* clippy

---------

Co-authored-by: Tyera <tyera@solana.com>
2023-06-29 07:03:26 +09:00
samkim-crypto 1452ed7044
[zk-token-sdk] Make `ElGamalKeypair` fields private (#32190)
* 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`
2023-06-22 10:28:13 +09:00
samkim-crypto d654715adf
[zk-token-sdk] remove non-pod structs `TransferPubkeys` and `TransferWithFeePubkeys` (#32042)
* remove decoded `TransferWithFeePubkeys`

* remove decoded `TransferPubkey`

* rename `TransferPubkeys` and `TransferWithFeePubkeys` fields

* relocate `TransferPubkeys` and `TransferWithFeePubkeys`

* reorder proof verify parameters for transfer and transfer with fee

* clippy
2023-06-20 07:07:30 +09:00
samkim-crypto 428283c9ef
[zk-token-sdk] Refactor pod `FeeParameters` conversion and remove manual byte conversion for the type (#32149)
* replace `decoded::TransferAmountCiphertext` to `DecodedTransferAmountCiphertext`

* refactor pod convert logic for fee parameters

* remove manual byte conversions for `FeeParameters`

* fix error from rebase
2023-06-18 07:51:49 +09:00
samkim-crypto 37f51e8376
[zk-token-sdk] Define `FeeEncryption` as a wrapper around `GroupedElGamalCiphertext` (#32144)
* define `FeeEncryption` as a wrapper around `GroupedElGamalCiphertext`

* define pod `FeeEncryption` as a wrapper around `GroupedElGamalCiphertext2Handles`

* update proof data computation

* add comments about unwraps
2023-06-16 17:53:36 +09:00
samkim-crypto 84e28c27f3
[zk-token-sdk] Refactor ciphertext validity sigma proof and rename `ValidityProof` to `GroupedCiphertextValidityProof` (#32040)
* rename `CiphertextValidityProof` to `GroupedCiphertext2HandlesValidityProof`

* rename `AggregatedValidityProof` to `BatchedGroupedCiphertext2HandlesValidityProof`

* refactor `validity_proof` module into separate modules

* update test names

* update `aggregated` variable names

* update transcript function names

* Update zk-token-sdk/src/sigma_proofs/batched_grouped_ciphertext_validity_proof.rs

Co-authored-by: Tyera <teulberg@gmail.com>

* Update zk-token-sdk/src/sigma_proofs/grouped_ciphertext_validity_proof.rs

Co-authored-by: Tyera <teulberg@gmail.com>

* Reword constructor docs

---------

Co-authored-by: Tyera <teulberg@gmail.com>
2023-06-13 12:06:24 +09:00
samkim-crypto c10d3d12a8
[zk-token-sdk] rename `TransferAmountEncryption` to `TransferAmountCiphertext` and define it as a wrapper around `GroupedElGamalCiphertext` (#32026)
* define `TransferAmountEncryption` as a wrapper around `GroupedElGamalCiphertext`

* implement `From<GroupedElGamalCiphertext<3>>` for `GroupedElGamalCiphertext3Handles`

* define pod `TransferAmountEncryption` as a wrapper around pod `GroupedElGamalCiphertext3Handles`

* derive `Copy`, `Debug`, `Eq`, and `PartialEq` traits for `TransferAmountEncryption`

* rename `TransferAmountEncryption` to `TransferAmountCiphertext`

* clippy

* fix target arch

* add comment on why it is safe to unwrap
2023-06-13 08:55:11 +09:00
samkim-crypto 169fc2a1e6
[zk-token-sdk] Rename `RangeProof{64,128,256}` to `RangeProofU{64,128,256}` (#31910)
rename `RangeProof{64,128,256}` to `RangeProofU{64,128,256}`
2023-06-02 15:59:25 +09:00
samkim-crypto 9216ff8c3e
[zk-token-sdk] Refactor transfer instruction (#31848)
* refactor `instruction::transfer` and `instruction::transfer_with_fee` into separate submodule

* rename `transfer.rs` to `transfer_without_fee.rs` to satisfy clippy

* refactor transfer encryptions into separate submodule

* refactor `FeeParameters` to parent transfer module

* refactor `Role` and ciphertext arithmetic specific to transfer instruction into transfer submodule

* fix visibility

* cargo fmt

* change `transfer_with_fee` and `transfer_without_fee` to `with_fee` and `without_fee`

* fix rebase errors
2023-06-01 06:55:23 +09:00
samkim-crypto 502f118931
[zk-token-sdk] Add `GroupedElGamalCiphertext` type (#31849)
* add `GroupedElGamalCiphertext` type

* add `GroupedElGamalCiphertext` type in `zk_token_elgamal::pod`

* cargo fmt

* Apply suggestions from code review

Co-authored-by: Tyera <teulberg@gmail.com>

* cargo fmt

* add explanation on `expected_byte_length`

* use `checked_add` and `checked_mul`

---------

Co-authored-by: Tyera <teulberg@gmail.com>
2023-05-31 10:01:44 +09:00
samkim-crypto e4fe9335e7
[zk-token-sdk] Refactor `zk-token-elgamal` conversion code for authenticated encryption, range proof, and sigma proof types (#31855)
* refactor convert logic for `AeCiphertext`

* refactor convert logic for `RangeProof`

* refactor convert logic for sigma proof types

* Apply suggestions from code review

Co-authored-by: Tyera <teulberg@gmail.com>

---------

Co-authored-by: Tyera <teulberg@gmail.com>
2023-05-31 08:12:38 +09:00
samkim-crypto f7b34e46ce
[zk-token-sdk] Refactor `zk-token-elgamal` conversion code for `elgamal` and `pedersen` pod types (#31846)
* refactor `DecryptHandle` into `pod::elgamal` from `pod::pedersen`

* refactor conversion for elgamal

* refactor conversion for pedersen

* change variable names

* add brief description of the types

* fix variable names in comments
2023-05-29 12:32:53 +09:00
samkim-crypto 24a4563484
[zk-token-sdk] Update equality proof abbreviated module names to non-abbreviated names (#31851)
* rename `sigma_proof::ctxt_comm_equality_proof` to non-abbreviated name

* rename `sigma_proof::ctxt_ctxt_equality_proof` to non-abbreviated name

* rename `instruction::ctxt_ctxt_equality` to non-abbreviated name
2023-05-29 09:49:17 +09:00
samkim-crypto 6d28fd455b
[zk-token-sdk] Refactor `zk-token-elgamal` pod types (#31814)
* move `pod.rs` to separate submodule

* refactor `ElGamalCiphertext` and `ElGamalPubkey` to separate submodule

* refactor `PedersenCommitment` and `DecryptHandle` to separate submodule

* refactor pod sigma proof types to separate submodule

* refactor pod range proof types to separate submodule

* refactor `AeCiphertext` into a separate submodule

* refactor instruction-related pod types to separate submodule

* Apply suggestions from code review

Co-authored-by: Tyera <teulberg@gmail.com>

---------

Co-authored-by: Tyera <teulberg@gmail.com>
2023-05-26 17:59:12 +09:00
samkim-crypto f9b0691eb4
[zk-token-sdk] rename and restructure `CloseAccount` and `WithdrawWithheld` proof instructions (#31608)
* rename and restruct ProofInstruction::VerifyCloseAccount to ProofInstruction::VerifyZeroBalance

* rename `PubkeySigmaProof` to `PubkeyValidityProof`

* refactor equality proofs into separate modules

* rename and restructure ProofInstruction::VerifyWithdrawWithheld to ProofInstruction::VerifyCiphertextCiphertextEquality

* add and reorg documentation for the proof instructions

* generalize ciphertext-ciphertext equality proof data constructor

* Update zk-token-sdk/src/instruction/ctxt_ctxt_equality.rs

Co-authored-by: Jon Cinque <joncinque@pm.me>

---------

Co-authored-by: Jon Cinque <joncinque@pm.me>
2023-05-18 08:43:00 +09:00
Illia Bobyr 43c0f05ca0
Bumps base64 from 0.13.1 to 0.21.0. (#31522)
Changes:

  marshallpierce/rust-base64@v0.13.1...v0.21.0

`base64::{encode,decode}` are now deprecated in favor of an API that
explicitly selects an `Engine`.  Migrated all calls to the new API.
2023-05-11 11:34:58 -07:00
samkim-crypto 2d58bb287d
[zk-token-sdk] Add option to create proof context state in the proof verification program (#29996)
* extend verifiable trait

* add PodBool

* implement ZkProofData trait

* add proof context program to zk-token-proof program

* update tests  for close account

* add close account instruction

* reorganize tests

* complete tests

* clean up and add docs

* clean up pod

* add proof program state

* update tests

* move proof program tests as separate module

* clippy

* cargo sort

* cargo fmt

* re-organize visibility

* add context state description

* update maintainer reference

* change `VerifyProofData` and `ProofContextState` to pod

* add tests for mixing proof types

* add tests for self owned context state accounts

* cargo fmt

* remove unnecessary scoping and add comments on scopes

* re-organize proof instructions

* clippy

* update zk-token-proof-test to 1.16.0

* upgrade spl-token-2022 to 0.6.1

* reoganize proof type

* cargo lock

* remove ZkProofContext trait
2023-03-16 07:35:20 +09:00
samkim-crypto ae57a14ef6
[zk-token-sdk] reorganize errors (#29005)
* reorganize error using DRY principle

* rename error `Format` to `Deserialization`

* Rename `EncryptionError` to `DiscreteLogError`

* resolve errors from rebase

* resolve clippy

* change `ProofInstructionError` to `ProofError`
2022-12-01 20:29:14 +09:00
samkim-crypto 11efaf75a4
[zk-token-sdk] divide fee encryption into two ciphertexts (#28472)
* divide fee encryption into two ciphertexts

* clippy

* update range proof

* add fee ciphertext decryption

* clean up split_u64 function

* remove unnecessary casting
2022-11-30 15:11:38 +09:00
samkim-crypto f1e7ffba0c
[zk-token-sdk] use canonical decoding for scalars (#28870)
use canonical decoding for scalars
2022-11-18 15:11:06 +09:00
samkim-crypto 491ec1e275
[zk-token-sdk] clean up pod ciphertext arithmetic operations (#28470)
* clean up pod ciphertext arithmetic operations

* rename add_ciphertext to add
2022-10-19 17:36:57 +09:00
samkim-crypto 00b1d0930f
[zk-token-sdk] Restructure proof error types (#28407)
* add pubkey sigma proof

* cargo fmt

* add EncryptionError

* add encryption errors
2022-10-16 07:06:57 +09:00
samkim-crypto bc927097ce
[zk-token-sdk] add pubkey proof (#28392)
* add pubkey proof

* add pubkey sigma proof

* add docs for the sigma proof functions

* add pod public key sigma proof

* add public-key validity proof instruction

* add public-key validity proof instruction

* add VerifyPubkeyValidity instruction

* cargo fmt
2022-10-14 20:15:20 +09:00
Tyera Eulberg 2114136e59
Add Display implementations for various ConfidentialTransfer pod structs (#26783) 2022-07-25 21:09:41 -06:00
samkim-crypto 930fe8ad10
Zk token ops using curve25519 syscalls (#25935)
* zk-token-sdk: use curve25519 syscalls for ElGamal arithmetic

* zk-token-sdk: clippy

* adjust curve25519 syscall costs

* cargo fmt
2022-06-13 22:39:07 +09:00
Alessandro Decina 2c8a3f39a6
Consolidate syscalls under solana_program::syscalls, implement static syscalls (sbfv2) (#24188)
Move all syscall declarations under solana_program::syscalls. If the target
supports static syscalls (sbfv2), then actually define them statically to avoid
dynamic relocations.
2022-05-26 23:01:55 +10:00
samkim-crypto d33cb2fa54
zk-token-sdk: implement convert traits for elgamal ciphertexts and ristretto points (#25549) 2022-05-26 05:46:29 +09:00
Michael Vines b05c7d91ed Fix derive_partial_eq_without_eq clippy lint 2022-05-22 22:22:21 -07:00
Dmitri Makarov 569b00025c fix: replace rust cfg annotations that use bpf by target_os solana 2022-05-18 20:39:43 -07:00
samkim-crypto d2b23da9ea
Zk token sdk clean decryption (#23478)
* zk-token-sdk: add decryption for pod elgamal ciphertexts

* zk-token-sdk: add decryption for pod elgamal ciphertexts

* zk-token-sdk: cargo fmt

* zk-token-sdk: minor update to docs

* zk-token-sdk: minor

* zk-token-sdk: fix bpf build error

* zk-token-sdk: more simplifying discrete log

* zk-token-sdk: fmt

* zk-token-sdk: minor update to doc
2022-03-04 15:57:19 -04:00
samkim-crypto 8d53ea81e9
zk-token-sdk: change variable names to use suffix rather than prefix (#23474)
* zk-token-sdk: change variable names to use suffix rather than prefix for type

* zk-token-sdk: cargo fmt
2022-03-03 15:07:27 -05:00
samkim-crypto b4100a9b5d
Add additional zkp for fee (#23112)
* zk-token-sdk: add equality proof for fee

* zk-token-sdk: tweak some naming conventions for readability

* zk-token-sdk: add verify withdraw withheld instruction

* zk-token-sdk: add test for withdraw withheld verification

* zk-token-sdk: more renaming of variables for readability

* zk-token-sdk: cargo fmt

* zk-token-sdk: minor

* zk-token-sdk: resolve bpf compilation warnings

* zk-token-sdk: minor update to doc
2022-02-17 12:45:07 -05:00
samkim-crypto 7873175764
zk-token-sdk: fix pod for zk-token transfer (#22957) 2022-02-08 12:09:50 -05:00
samkim-crypto 65f8f43665
Zk instructions pass (#22851)
* zk-token-sdk: re-organize transcript

* zk-token-sdk: add pod ElGamal group encryption

* zk-token-sdk: add transcript domain separators for sigma proofs

* zk-token-sdk: clean up transfer tx decryption

* zk-token-sdk: resolve encoding issues for transfer

* zk-token-sdk: fix transfer test

* zk-token-sdk: clean up transcript for close account and withdraw instructions

* zk-token-sdk: add transfer with fee instruction

* zk-token-sdk: add transfer with fee instruction

* zk-token-sdk: add pod for cryptographic structs needed for fee

* zk-token-sdk: add pod for fee sigma proof

* zk-token-sdk: fix test for transfer with fee instruction

* zk-token-sdk: add range proof verification for transfer with fee

* zk-token-sdk: add transfer amount decryption for transfer-with-fee

* zk-token-sdk: add proof generation error for instruction

* zk-token-sdk: cargo fmt and clippy

* zk-token-sdk: fix bpf build
2022-02-01 14:11:28 -05:00
samkim-crypto 5cef4c0a4c
Sigma pass (#22801)
* zk-token-sdk: add zeroize and reference arithmetic to zero-balance proof

* zk-token-sdk: add zeroize and reference arithmetic to equality proof

* zk-token-sdk: add zeroize and reference arithmetic to validity proof

* zk-token-sdk: add aggregated validity proof

* zk-token-sdk: use subtle choice for fee

* zk-token-sdk: add test for fee proof

* zk-token-sdk: add documentation for sigma protocols

* zk-token-sdk: add edge case tests for equality proof

* zk-token-sdk: add edge case tests for zero-balance proof

* zk-token-sdk: add edge case tests for validity proof

* zk-token-sdk: add some docs for fee sigma proof

* zk-token-sdk: clippy
2022-01-27 19:53:15 -05:00
samkim-crypto d8cbb2a952
Elgamal pass (#22632)
* zk-token-sdk: change G and H to static and optimize pedersen arithmetic

* zk-token-sdk: remove unnecessary copy in elgamal arithmetic

* zk-token-sdk: fix elgamal tests for new syntax

* zk-token-sdk: use lazy-static for pedersen base

* zk-token-sdk: add dlog test for elgamal decryption

* zk-token-sdk: reflect changes in elgamal in the rest of the sdk

* zk-token-sdk: rustfmt and clippy

* zk-token-sdk: some documentation for elgamal and pedersen

* zk-token-sdk: minor remove whitespace

* zk-token-sdk: update lock files

* zk-token-sdk: change random() to new_rand()

* zk-token-sdk: add explanation for suppressing clippy::op_ref
2022-01-21 20:56:27 -05:00
Tyera Eulberg 7be533a770
Add zeroed default for ElGamalCiphertext (#22639) 2022-01-21 19:52:36 +00:00
samkim-crypto 41fb98c771
zk-token_sdk: define defaults for pod ElGamal/AES ciphertexts (#22532) 2022-01-20 16:27:31 -05:00
Sam Kim 5b41d62f8a feat: fix clippy for new error types 2022-01-05 08:51:18 -08:00
Sam Kim 0944abc0e2 feat: update error types for sdk 2022-01-05 08:51:18 -08:00
Sam Kim 584c63bcc4 refactor: CloseAccount now uses zero-balance-proof 2022-01-05 08:51:18 -08:00
Sam Kim c26fa1d0e9 refactor: create pod struct for ZeroBalanceProof 2022-01-05 08:51:18 -08:00
Sam Kim c6cd0a5591 refactor: group equality and validity proofs in sigma_proofs module 2022-01-05 08:51:18 -08:00
Sam Kim 9a43fbe3b2 clean up authenticated encryption implementation and also rename aes to auth_encryption 2022-01-05 08:51:18 -08:00
Sam Kim 7a568482de cargo fmt and fix clippy 2022-01-05 08:51:18 -08:00
Sam Kim 30871784e4 incorporate validity proof into transfer proof 2022-01-05 08:51:18 -08:00
Sam Kim 6c329e2431 add equality proof struct 2022-01-05 08:51:18 -08:00
Michael Vines aba8c2f4af reformat imports 2022-01-05 08:51:18 -08:00
Sam Kim defdf8da72 change AESCiphertext to AesCiphertext 2022-01-05 08:51:18 -08:00
Sam Kim 3721eda23e serialization for aes 2022-01-05 08:51:18 -08:00