Commit Graph

264 Commits

Author SHA1 Message Date
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
samkim-crypto 688fa0bf0f
[zk-token-sdk] Rename variable `tag` to `public_seed` in encryption key `new_from_signer` functions (#31835)
rename `tag` to `public_seed` in `new_from_signer` functions
2023-05-27 05:50:22 +09:00
samkim-crypto ad4d1e5ff2
[zk-token-sdk] Add aggregate range proof instructions (#31793)
* add aggregate range proof instructions data

* add aggregate range proof instruction

* update proof program processor for aggregate range proof instructions

* cargo fmt

* Update zk-token-sdk/src/instruction/aggregate_range_proof/aggregate_range_proof_256.rs

Co-authored-by: mvines <mvines@gmail.com>

* add remark in instruction description that context state account must be pre-allocated

* use `u64::BITS` and `u128::BITS`

* add proof description in `zk_token_proof_instruction.rs`

* rename instruction names to `VerifyBatchedRangeProofU{N}`

* rename module names from `aggregate` to `batched`

* add `tokio::test` that was lost in rebase

---------

Co-authored-by: mvines <mvines@gmail.com>
2023-05-27 05:46:11 +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 bf6e248bb9
[zk-token-sdk] Add function docs for authenticated encryption (#31811)
* add function docs for authenticated encryption

* Apply suggestions from code review

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

---------

Co-authored-by: Tyera <teulberg@gmail.com>
2023-05-26 16:01:07 +09:00
samkim-crypto ef7ca5ee8b
[zk-token-sdk] add range-proof proof instruction (#31788)
* add `VerifyRangeProof` instruction

* update proof program processor for `VerifyRangeProof64`

* specify target arch for `RANGEPROOF64_BIT_LENGTH

* rename `transcript_new` to `new_transcript`

* add constructor for `VerifyRangeProof64`

* add remark in the instruction description that context state account must be pre-allocated

* add proof description in `zk_token_proof_instruction.rs`

* rename `VerifyRangeProof64` to `VerifyRangeProofU64`

* use `u64::BITS`

* Update zk-token-sdk/src/zk_token_proof_instruction.rs

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

* Apply suggestions from code review

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

* fix range proof test

---------

Co-authored-by: Tyera <teulberg@gmail.com>
2023-05-26 15:42:01 +09:00
samkim-crypto fa4c6aa015
[zk-token-sdk] Update random `AeKey` generation to use `OsRng` internally (#31786)
update random `AeKey` generation to use `OsRng` internally
2023-05-24 09:53:22 +09:00
samkim-crypto 19a202873b
[zk-token-sdk] Generalize encryption key derivation from signers (#31784)
* generalize ElGamal keypair derivation from signer

* generalize AeKey derivation from signer

* add `tiny-bip39` as a dev dependency for tests
2023-05-24 09:52:59 +09:00
samkim-crypto 4796e2fd84
[zk-token-sdk] Generate proof transcript directly from proof contexts (#31725)
* generate transcript directly from proof contexts

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

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

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

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

---------

Co-authored-by: Jon Cinque <joncinque@pm.me>
2023-05-20 07:08:40 +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
samkim-crypto 6de581ac08
[clap-v3-utils, sdk, zk-token-sdk] Split `EncodableKey` into `EncodableKey` + `SeedDerivable` (#31668)
* add `SeedDerivable` trait

* implement `SeedDerivable` for `Keypair`

* implement `SeedDerivable` for `ElGamalKeypair`

* update clap-v3-utils to use `EncodableKey + SeedDerivable`

* implement `SeedDerivable` trait for `AeKey`

* implement `EncodableKey` and `SeedDerivable` for `ElGamalSecretKey`

* implement `SeedDerivable` trait for `ElGamalPubkey`
2023-05-17 17:42:35 +09:00
samkim-crypto e14384d8ff
[clap-v3-utils] Add `EncodableKeypair` trait and make `confirm_keypair_pubkey` generic (#31642)
* add `EncodableKeypair` trait

* implement `EncodableKeypair` for `Keypair`

* implement `EncodableKeypair` for `ElGamalKeypair

* make confirm pubkey functions generic

* fix a typo

* Update sdk/src/signer/keypair.rs

Co-authored-by: Trent Nelson <trent.a.b.nelson@gmail.com>

* Update clap-v3-utils/src/keypair.rs

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

* fix a typo

---------

Co-authored-by: Trent Nelson <trent.a.b.nelson@gmail.com>
Co-authored-by: Tyera <teulberg@gmail.com>
2023-05-17 05:37:59 +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
Ryo Onodera 4d4dddcaea
Update to nightly rustc to 2023-04-19 (#31381)
* Update to nightly rustc to 2023-04-19

* pray...

* Not enough pray..

* skip check...

* hope merciful shellcheck

* ci hack...

* Restore ci/test-checks.sh

* Restore debug_assertions with proper workaround...

* small cleanup

* seems this isn't needed?

* Make the workaround more robust...

* Remove now-resolved clippy exception
2023-05-11 15:48:13 +09:00
samkim-crypto 39701fa560
[zk-token-sdk] Refactor encryption error types (#31569)
* reorganize encryption error types

* remove encryption errors module

* cargo fmt
2023-05-11 04:43:25 +09:00
samkim-crypto 21667660e9
[zk-token-sdk, clap-v3-utils] Implement `EncodableKey` for encryption keys (#31496)
* implement EncodableKey for ElGamalKeypair

* implement EncodableKey for AeKey

* add keypair_from_path and keypair_from_seed support for encryption keys

* remove duplicate methods from traits
2023-05-10 06:37:29 +09:00
Tyera 3442f184f7
Remove unneeded `clippy::new_ret_no_self` allows (#31035)
Remove unneeded allows
2023-04-03 20:35:20 -06:00
Tyera 193a6d90fc
Remove unused dependency (#30881) 2023-03-24 02:34:10 +00: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
Yihau Chen af59cced5a
chore: bump bincode to 1.3.3 (#30489) 2023-02-25 02:48:24 +08:00
Yihau Chen df3ef111f7
chore: workspace inheritance (#29893)
* introduce workspace.package

* introduce workspace.dependencies

* read version from root cargo.toml

* pass check when version = { workspace = true }

* don't bump version when version = { workspace = true }

* including workspace Cargo.toml when bump version

* programs/sbf use workspace inheritance

* fix increasing cargo version ignore program/sbf/Cargo.toml
2023-02-23 22:01:54 +08:00
Will Hickey 04a6a631bc
Bump version to v1.16 (#30028) 2023-01-31 17:48:33 -06:00
joeaba a12bf8c003
Update maintainers references (#29997)
* update maintainers references

* chore: update maintainers reference
2023-01-31 08:07:13 -05:00