Commit Graph

286 Commits

Author SHA1 Message Date
samkim-crypto 683e1071f7 [zk-token-sdk] Implement `FromStr` for `ElGamalPubkey`, `ElGamalCiphertext`, and `AeCiphertext` (#130)
* add `ParseError` in `zk-token-elgamal`

* implement `FromStr` for `ElGamalPubkey` and `ElGamalCiphertext`

* implement `FromStr` for `AeCiphertext`

* fix target

* cargo fmt

* use constants for byte length check

* make `FromStr` functions available on chain

* use macros for the `FromStr` implementations

* restrict `from_str` macro to `pub(crate)`

* decode directly into array

* cargo fmt

* Apply suggestions from code review

Co-authored-by: Jon C <me@jonc.dev>

* remove unnecessary imports

* remove the need for `ParseError` dependency

---------

Co-authored-by: Jon C <me@jonc.dev>
2024-03-15 22:25:14 -05:00
samkim-crypto b11d41a3f7
[zk-token-sdk] Use checked arithmetic when processing transfer amount (#34130)
* add `try_split_u64`

* add `try_combine_lo_hi_u64`

* add `try` variants of ciphertext arithmetic functions

* use try functions in proof generaiton and verification logic

* deprecate non-`try` functions

* use try functions in proof generaiton and verification logic

* Apply suggestions from code review

Co-authored-by: Jon C <me@jonc.dev>

* cargo fmt

---------

Co-authored-by: Jon C <me@jonc.dev>
2024-01-24 22:27:03 +09:00
samkim-crypto e2c2029ac4
[zk-token-sdk] Restrict a single-bit of 256-bit batched range proof to 128 (#34803)
* fix previous typo

* restrict single-bit of 256-bit batched range proof to 128
2024-01-18 14:37:04 +09:00
samkim-crypto b222fdf3d7
[zk-token-proof] Add functionality to read proof from accounts instead of instruction data (#34750)
* add functionality to read proof from accounts instead of instruction data

* update add tests

* clippy

* clarify instruction data discriminator

* avoid cloning entire proof data

* Update programs/zk-token-proof/src/lib.rs

Co-authored-by: Jon C <me@jonc.dev>

* update `PROOF_OFFSET_LENGTH` to `INSTRUCTION_DATA_LENGTH_WITH_PROOF_ACCOUNT`

* update instruction docs

* add feature gate

* Update sdk/src/feature_set.rs

Co-authored-by: Jon C <me@jonc.dev>

* update feature name `enable_zk_from_account` to `enable_zk_proof_from_account`

* Apply suggestions from code review

Co-authored-by: Jon C <me@jonc.dev>

* clarify the instruction data length more precisely

---------

Co-authored-by: Jon C <me@jonc.dev>
2024-01-13 08:15:44 +09:00
Nick Frostbutter fc2a8794be
[docs] updated readme and fix links (#34565)
* feat: updated readme

* fix: updated links

* fix: proposal links

* fix: more links

* fix: json-rpc links

* fix: more links

* fix: zk links

* fix: managing forks

* fix: links for deprecated methods
2024-01-03 09:06:06 -05:00
Brooks 59dd007899
clippy: zk-token-sdk lints (#34633) 2024-01-02 22:01:42 -05:00
GoodDaisy 03386cc7b9
Fix typos (#34459)
* Fix typos

* Fix typos

* fix typo
2023-12-21 13:06:00 -07:00
samkim-crypto aaccbdd0ae
[zk-token-sdk] Fix range proof transcript seed typo (#34468)
fix range proof transcript seed typo
2023-12-14 13:37:12 -08:00
pandabadger 549c3e7813
Fix a number of typos (#34385)
* Update vote-accounts.md

* Update what-is-a-validator.md

* Update what-is-a-validator.md

* Update accounts-db-replication.md

* Update blockstore-rocksdb-compaction.md

* Update rip-curl.md

* Update ledger-replication-to-implement.md

* Update optimistic_confirmation.md

* Update return-data.md

* Update handle-duplicate-block.md

* Update timely-vote-credits.md

* Update optimistic-transaction-propagation-signal.md

* Update simple-payment-and-state-verification.md

* Update off-chain-message-signing.md

* Update mod.rs

* Update elgamal.rs

* Update ledger.md

* Update deploy-a-program.md

* Update staking-rewards.md

* Update reliable-vote-transmission.md

* Update repair-service.md

* Update abi-management.md

* Update testing-programs.md

* Update docs/src/implemented-proposals/staking-rewards.md

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

---------

Co-authored-by: Tyera <teulberg@gmail.com>
2023-12-12 15:27:29 -05:00
samkim-crypto d21e7edd2b
[zk-token-sdk] Fix transfer with fee edge case error (#34314) 2023-12-07 06:46:57 +09:00
samkim-crypto ded278fb57
[zk-token-sdk] Add range proof generation error types (#34065)
* replace assert statements with `VectorLengthMismatch` error variant

* add a condition to check that the bit lengths are in the correct range

* replace assert statements with `GeneratorLengthMismatch`

* remove unchecked arithmetic

* add `InnerProductLengthMismatch` error

* fix typo

* add a clarifying comment on unwrap safety

* fix typo
2023-11-22 06:50:24 +09:00
samkim-crypto 0e6dd54f81
[zk-token-sdk] Restrict range proof generator length and prevent 0-bit range proof (#34166)
* limit range proof generator length

* forbid 0-bit range proof verification
2023-11-21 08:48:41 +09:00
samkim-crypto e251b8607c
[zk-token-sdk] Add a length check on range proof commitment length (#34165)
add a length check on range proof commitment length
2023-11-21 08:48:15 +09:00
samkim-crypto 0fd4762399
[zk-token-sdk] Re-organize error types (#34034)
* add deserialization error type for encryption

* re-organize sigma proof error types

* re-organize range proof error types

* update pod conversion module

* update instruction error types

* clippy

* fix `thiserror` visibility

* Apply suggestions from code review

Co-authored-by: Jon Cinque <me@jonc.dev>

---------

Co-authored-by: Jon Cinque <me@jonc.dev>
2023-11-17 07:00:47 +09:00
Brooks ea98c0ea36
clippy: Uses .into() when .try_into() is infallible (#34049) 2023-11-13 23:49:35 -05:00
Brooks e9135e2211
clippy: Remove unused import (#34050) 2023-11-13 17:25:11 -05:00
Brooks 725ab37bf4
clippy: Replaces .get(0) with .first() (#34048) 2023-11-13 17:22:17 -05:00
samkim-crypto 381d2254eb
[zk-token-sdk] Check that discrete log compression batch size is greater than 0 (#33699)
check that discrete log compression batch size is greater than 0
2023-10-24 11:11:28 -07:00
samkim-crypto c3d588b3f1
[zk-token-sdk] clean-up range-proof docs (#33803)
* add/fix docs for range proof

* remove pre-compute generators todo

* remove double check generators todo
2023-10-24 07:53:48 -07:00
samkim-crypto dd2b1bb5a0
[zk-token-sdk] Limit max seed length for key derivations (#33700)
* limit max seed length for elgamal keypairs

* limit max seed length for authenticated encryption keys

* Apply suggestions from code review

Co-authored-by: Jon Cinque <me@jonc.dev>

* rename `SeedLengthTooLarge` to `SeedLengthTooLong`

---------

Co-authored-by: Jon Cinque <me@jonc.dev>
2023-10-20 13:02:37 -07:00
ripatel-fd fb80288f88
zk-token-sdk: Fix incorrect mention of OsRng in docs (#33774)
Co-authored-by: Richard Patel <ripatel@jumptrading.com>
2023-10-20 01:14:01 +02:00
samkim-crypto a4ceea32d7
[zk-token-sdk] Allow all zero auditor pubkey in proofs (#33106)
* allow auditor ElGamal public key to be all zero

* remove test components on all zero auditor ElGamal pubkey
2023-09-01 10:26:15 -07:00
Alexander Meißner 9e703f85de
Upgrades Rust to 1.72.0 & nightly-2023-08-25 (#32961)
* allow pedantic invalid cast lint

* allow lint with false-positive triggered by `test-case` crate

* nightly `fmt` correction

* adapt to rust layout changes

* remove dubious test

* Use transmute instead of pointer cast and de/ref when check_aligned is false.

* Renames clippy::integer_arithmetic to clippy::arithmetic_side_effects.

* bump rust nightly to 2023-08-25

* Upgrades Rust to 1.72.0

---------

Co-authored-by: Trent Nelson <trent@solana.com>
2023-09-01 07:26:13 +00:00
Jon Cinque 0fe902ced7
Bump rand to 0.8, rand_chacha to 0.3, getrandom to 0.2 (#32871)
* sdk: Add concurrent support for rand 0.7 and 0.8

* Update rand, rand_chacha, and getrandom versions

* Run command to replace `gen_range`

Run `git grep -l gen_range | xargs sed -i'' -e 's/gen_range(\(\S*\), /gen_range(\1../'

* sdk: Fix users of older `gen_range`

* Replace `hash::new_rand` with `hash::new_with_thread_rng`

Run:
```
git grep -l hash::new_rand | xargs sed -i'' -e 's/hash::new_rand([^)]*/hash::new_with_thread_rng(/'
```

* perf: Use `Keypair::new()` instead of `generate`

* Use older rand version in zk-token-sdk

* program-runtime: Inline random key generation

* bloom: Fix clippy warnings in tests

* streamer: Scope rng usage correctly

* perf: Fix clippy warning

* accounts-db: Map to char to generate a random string

* Remove `from_secret_key_bytes`, it's just `keypair_from_seed`

* ledger: Generate keypairs by hand

* ed25519-tests: Use new rand

* runtime: Use new rand in all tests

* gossip: Clean up clippy and inline keypair generators

* core: Inline keypair generation for tests

* Push sbf lockfile change

* sdk: Sort dependencies correctly

* Remove `hash::new_with_thread_rng`, use `Hash::new_unique()`

* Use Keypair::new where chacha isn't used

* sdk: Fix build by marking rand 0.7 optional

* Hardcode secret key length, add static assertion

* Unify `getrandom` crate usage to fix linking errors

* bloom: Fix tests that require a random hash

* Remove some dependencies, try to unify others

* Remove unnecessary uses of rand and rand_core

* Update lockfiles

* Add back some dependencies to reduce rebuilds

* Increase max rebuilds from 14 to 15

* frozen-abi: Remove `getrandom`

* Bump rebuilds to 17

* Remove getrandom from zk-token-proof
2023-08-21 19:11:21 +02:00
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 5624aaa1e5
[zk-token-sdk](docs) Update docs to include a brief description of how fee sigma proof is computed (#32288)
* function docs to focus on the action they perform

* update docs for fee sigma proof

* add link to zk token proof doc

* Apply suggestions from code review

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

---------

Co-authored-by: Tyera <tyera@solana.com>
2023-06-28 09:55:55 +09:00
samkim-crypto 4bc8f90182
[zk-token-sdk] Add fee sigma proof verification instruction (#32291)
* add fee sigma proof verification instruction

* update proof program processor for fee sigma proof

* update bench for fee sigma proof

* cargo fmt

* clippy

* fix target arch

* add comments to describe fee, delta, and claimed instruction data field
2023-06-28 09:49:56 +09:00
Tyera bde7c174b8
[zk-token-proof] Fix doc typo (#32270)
Fix doc typo
2023-06-24 15:24:22 -07: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 42aa5d243c
[zk-token-proof] Update docs for the ZK Token proof program in `zk-token-sdk` (#32186)
* add docs for the proof program instructions

* add docs for the zk token proof program

* add docs for the instruction data types

* add brief description of the proofs for each of the proof instructions

* Apply suggestions from code review

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

* change `pubkey` or `public-key` in the docs to `public key`

---------

Co-authored-by: Tyera <teulberg@gmail.com>
2023-06-21 20:50:49 +09:00
samkim-crypto 1bc101252c
[zk-token-sdk] Use `TryFrom<&[T]>` for `&[T]` instead of `arrayref` (#31959)
* remove `arrayref` from `auth_encryption`

* remove `arrayref` from `sigma_proofs`

* refactor `canonical_scalar_from_slice`

* remove `arrayref` from `Cargo.toml`

* cargo lock
2023-06-21 06:14:18 +09:00
samkim-crypto 91ec92cd76
[zk-token-sdk] Make `AeCiphertext` inner fields be private (#32188)
make `AeCiphertext` fields and types be private
2023-06-21 06:07:58 +09:00
samkim-crypto 1616123b84
[zk-token-sdk] Make inner scalar and ristretto point of `PedersenOpening` and `PedersenCommitment` private (#32187)
* make `PedersenOpening` inner scalar private

* make `PedersenCommitment` inner point private
2023-06-21 06:07:40 +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 b361fdd399
[zk-token-sdk] Update transcript functions to use full names (#32095)
* fully specify transcript function names `sep` to `separator`

* update names in `sigma_proofs`

* update names in `range_proof`

* update grouped ciphertext validity proofs with new full name
2023-06-13 14:52:15 +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
Yihau Chen e587df1285
ci: update cargo.toml (#31934)
* ci: add missing description and documentation to zk-token-sdk/Cargo.toml

* ci: add missing description back to programs/bpf_loader/Cargo.toml

* ci: add missing description back to banks-client/Cargo.toml
2023-06-02 15:08:07 +00: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 0495051a67
[zk-token-sdk] Add `VerifyGroupedCiphertext2HandlesValidity` and `VerifyBatchedGroupedCiphertext2HandlesValidity` proof instructions (#31816)
* add grouped ciphertext validity proof data

* add batched grouped ciphertext validity proof data

* rename proof contexts and data for consistency

* add grouped ciphertext validity proof instructions

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

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

---------

Co-authored-by: Tyera <teulberg@gmail.com>
2023-06-01 15:58:36 +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 2ebf38efd0
[zk-token-sdk] Add ciphertext-commitment equality proof instruction (#31808)
* add ciphertext-commitment proof data

* add ciphertext-commitment proof instruction

* update proof program processor for ciphertext-commitment equality proof

* cargo fmt

* update compute units

* rename submodule `ctxt_comm_equality` to `ciphertext_commitment_equality`

* update import statements

* fix mixed conflict

* remove `native_programs_consume_cu`
2023-05-27 11:25:29 +09:00
samkim-crypto 93efc13bbf
[zk-token-sdk] Add encryption error variant `SeedLengthTooShort` and remove variant `PubkeyDoesNotExist` (#31840) 2023-05-27 09:14:13 +09:00
samkim-crypto 8c7dc9306f
[zk-token-sdk] Use full variable names (#31828)
* update variable names in `auth_encryption`

* update variable names in `pedersen`
2023-05-27 06:32:13 +09:00