Skip to content
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

[token-2022] Upgrade to zk-sdk #7148

Merged
merged 16 commits into from
Aug 16, 2024

Conversation

samkim-crypto
Copy link
Contributor

@samkim-crypto samkim-crypto commented Aug 14, 2024

Problem

The zk-token-sdk has been deprecated and replaced with zk-sdk in the monorepo, but the token22 program still depends on zk-token-sdk.

Summary of Changes

Updated token22 program to zk-sdk.

1ec4dc8: I first updated the spl-pod crate to zk-sdk. Unfortunately, for the ElGamal Pod types in zk-sdk, there is no proper constructor functions to instantiate them from bytes (will be added in the next major release!). However, these types do implement the FromStr trait, so I used them to initialize these Pod types as a workaround.

23f21dc: Upgraded to use zk-sdk. The changes are mostly just naming substitutions in this PR.

  • The Pod prefix has been added to pod types (e.g. ElGamalPubkey --> PodElGamalPubkey)
  • PubkeyValidityData --> PubkeyValidityProofData
  • ZeroBalanceProofData --> ZeroCiphertextProofData
  • FeeSigmaProofData --> PercentageWithCapProofData

14669ed: Added dependencies to the spl-token-confidential-transfer-* crates:

  • The proof generation, verification, and ciphertext arithmetic logic have been refactored into their separate crates, so I added dependencies to these crates.
  • The spli_proof_generation and ciphertext_extraction crates are now obsolete, so I removed them in confidential_transfer/mod.rs (I forgot to delete the actual files in this commit so I delete them in a later commit). I think it makes sense to refactor out account_info into a separate crate (and removed dependency on spl-token-confidential-transfer-proof-generation, but I will do it in a follow-up PR.
  • The refactored crates have their own error types TokenProofGenerationError and TokenProofExtractionError. I wasn't sure what is the cleanest way to handle these errors, but I ended up instantiating the From trait to convert them into TokenError. Please let me know if you have other suggestions 🙏 .

9fb3f74: The WithdrawProofData is removed in zk-sdk to be replaced with the combination of equality and range proof. I updated the Withdraw instruction accordingly.

cf9eb6c: This is a follow-up to #7127 (comment).

0594847: Made the upgrade to zk-sdk in the token-client. These are mostly naming substitutions and also updating the withdraw instruction for the split proofs.

aad9f2e: I was about to add the create_equality_proof_context_state_for_withdraw and create_range_proof_context_state_for_withdraw functions and then realized that all these create proof context state functions can be unified into a single generic function just like how it is done for the record account functions. I ended up cleaning out the specific constructor functions for the context state accounts.

a0d12ea: Update the program-2022-tests. Should be mostly straightforward. There is a block of code that I meant to be remove, which I just commented out. I removed this block of code in a later commit 🙏 .

9cc5ede: I forgot to update the serialization logic to zk-sdk, so I made the changes. Again, unfortunately, there are no proper constructor functions for the Pod types, so I used the FromStr workaround. Regarding the decryption handles, they are not included in the instruction data any more, so I removed the related logic.

@samkim-crypto samkim-crypto force-pushed the token-2022/zk-sdk branch 5 times, most recently from 70f0372 to 9cc5ede Compare August 15, 2024 01:46
@samkim-crypto samkim-crypto marked this pull request as ready for review August 15, 2024 02:13
Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great overall! just tiny things

Comment on lines 285 to 292
// Unfortunately, the `solana-zk-sdk` does not exporse a constructor interface
// to construct `PodRistrettoPoint` from bytes. As a work-around, encode the
// bytes as base64 string and then convert the string to a
// `PodElGamalCiphertext`.
fn elgamal_pubkey_from_bytes(bytes: &[u8]) -> PodElGamalPubkey {
let string = BASE64_STANDARD.encode(bytes);
std::str::FromStr::from_str(&string).unwrap()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add to the comment saying that this will be possible in the next version and what function to use? Is that 2.1?

Copy link
Contributor Author

@samkim-crypto samkim-crypto Aug 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added! I will also create an issue regarding this very soon.

Comment on lines +452 to +462
#[cfg(not(target_os = "solana"))]
impl From<TokenProofGenerationError> for TokenError {
fn from(e: TokenProofGenerationError) -> Self {
match e {
TokenProofGenerationError::ProofGeneration(_) => TokenError::ProofGeneration,
TokenProofGenerationError::NotEnoughFunds => TokenError::InsufficientFunds,
TokenProofGenerationError::IllegalAmountBitLength => TokenError::IllegalBitLength,
TokenProofGenerationError::FeeCalculation => TokenError::FeeCalculation,
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the errors, this is probably fine. You could do ProofGeneration(#[from] TokenProofGenerationError), like in https://github.com/anza-xyz/agave/blob/ecb44d7bd7bcfcbf1f342eb7eaf2728e7b6eefc5/rpc-client-api/src/client_error.rs#L14, but that might end up being more confusing in the end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah makes sense. ProofGeneration(#[from] TokenProofGenerationError) seems more elegant to me, but this seems to need some restructuring of the existing TokenError unfortunately. It could also end up being more confusing as you suggested.

ciphertext_validity_proof_data: &BatchedGroupedCiphertext3HandlesValidityProofData,
ciphertext_validity_proof_signer: &S,
proof_data: &ZK,
split_instruction: bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this parameter name is a little confusing -- can we call it split_account_creation_and_proof_verification? Or maybe you might have something better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I think split_account_creation_and_proof_verification is also the best I can come up with, so I'll use it. Thanks!

Comment on lines 1069 to 1071
// #[cfg(feature = "zk-ops")]
// #[tokio::test]
// async fn confidential_transfer_withdraw_with_record_account() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you also want to remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh oops! Removed. Thanks!

Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@samkim-crypto samkim-crypto merged commit 3766c63 into solana-labs:master Aug 16, 2024
37 checks passed
@ryoqun
Copy link
Member

ryoqun commented Aug 16, 2024

@samkim-crypto @joncinque cc: @yihau

seems merging this pr into spl repo caused relevant agave's master downstream ci job to fail: https://github.com/anza-xyz/agave/actions/runs/10415342439/job/28845769665#step:5:1467

joncinque added a commit to joncinque/solana that referenced this pull request Aug 16, 2024
#### Problem

With solana-labs/solana-program-library#7148,
spl-token-2022 has moved from using solana-zk-token-sdk to
solana-zk-sdk, which is a major breaking change. Certain agave and
anchor crates are depending on the re-export solana-zk-token-sdk in
spl-token-2022, which is no longer present. This change is causing the
downstream Anchor job to fail, since the patched version of
spl-token-2022 is no longer compatible.

#### Summary of changes

Until new major versions of the SPL crates are available used by the
Agave monorepo, disable the downstream anchor job.
joncinque added a commit to anza-xyz/agave that referenced this pull request Aug 16, 2024
#### Problem

With solana-labs/solana-program-library#7148,
spl-token-2022 has moved from using solana-zk-token-sdk to
solana-zk-sdk, which is a major breaking change. Certain agave and
anchor crates are depending on the re-export solana-zk-token-sdk in
spl-token-2022, which is no longer present. This change is causing the
downstream Anchor job to fail, since the patched version of
spl-token-2022 is no longer compatible.

#### Summary of changes

Until new major versions of the SPL crates are available used by the
Agave monorepo, disable the downstream anchor job.
@joncinque
Copy link
Contributor

Thanks for pointing that out @ryoqun -- I've temporarily disabled the downstream job in anza-xyz/agave#2629

mergify bot pushed a commit to anza-xyz/agave that referenced this pull request Aug 17, 2024
#### Problem

With solana-labs/solana-program-library#7148,
spl-token-2022 has moved from using solana-zk-token-sdk to
solana-zk-sdk, which is a major breaking change. Certain agave and
anchor crates are depending on the re-export solana-zk-token-sdk in
spl-token-2022, which is no longer present. This change is causing the
downstream Anchor job to fail, since the patched version of
spl-token-2022 is no longer compatible.

#### Summary of changes

Until new major versions of the SPL crates are available used by the
Agave monorepo, disable the downstream anchor job.

(cherry picked from commit 3b9e7a3)

# Conflicts:
#	.github/workflows/downstream-project-anchor.yml
joncinque added a commit to anza-xyz/agave that referenced this pull request Aug 17, 2024
* CI: Disable downstream anchor builds (#2629)

#### Problem

With solana-labs/solana-program-library#7148,
spl-token-2022 has moved from using solana-zk-token-sdk to
solana-zk-sdk, which is a major breaking change. Certain agave and
anchor crates are depending on the re-export solana-zk-token-sdk in
spl-token-2022, which is no longer present. This change is causing the
downstream Anchor job to fail, since the patched version of
spl-token-2022 is no longer compatible.

#### Summary of changes

Until new major versions of the SPL crates are available used by the
Agave monorepo, disable the downstream anchor job.

(cherry picked from commit 3b9e7a3)

# Conflicts:
#	.github/workflows/downstream-project-anchor.yml

* Fix merge conflicts

---------

Co-authored-by: Jon C <[email protected]>
joncinque added a commit to joncinque/solana-program-library that referenced this pull request Aug 27, 2024
#### Problem

The publish step is great, but there's still some manual work to add the
changelog and correct title for the created release.

#### Summary of changes

Use git-cliff to generate the release notes. This comes with a very
simple cliff.toml which will do minimal processing, since we don't
follow conventional commits in the repo.

Here's a test run for the given input:

```
$ git-cliff -c ci/cliff.toml "pod-v0.3.0"..master --include-path "libraries/pod/**" --github-repo "solana-labs/solana-program-library"
```

Output:

```
## What's new

- Publish pod v0.3.2 by @github-actions[bot]
- [token-2022] Upgrade to `zk-sdk` (solana-labs#7148) by @samkim-crypto
- Implement `Default` for `PodOption` (solana-labs#7083) by @joncinque
- Bump to 0.3.1 (solana-labs#7075) by @febo
- Improve `PodOption` type (solana-labs#7076) by @febo
- Add `PodU128` type (solana-labs#7012) by @febo
- Add `PodOption` type (solana-labs#6886) by @febo
- Use `bytemuck_derive` explicitly (solana-labs#6928) by @joncinque
```
joncinque added a commit that referenced this pull request Aug 28, 2024
* CI: Add git-cliff step during publish

#### Problem

The publish step is great, but there's still some manual work to add the
changelog and correct title for the created release.

#### Summary of changes

Use git-cliff to generate the release notes. This comes with a very
simple cliff.toml which will do minimal processing, since we don't
follow conventional commits in the repo.

Here's a test run for the given input:

```
$ git-cliff -c ci/cliff.toml "pod-v0.3.0"..master --include-path "libraries/pod/**" --github-repo "solana-labs/solana-program-library"
```

Output:

```
## What's new

- Publish pod v0.3.2 by @github-actions[bot]
- [token-2022] Upgrade to `zk-sdk` (#7148) by @samkim-crypto
- Implement `Default` for `PodOption` (#7083) by @joncinque
- Bump to 0.3.1 (#7075) by @febo
- Improve `PodOption` type (#7076) by @febo
- Add `PodU128` type (#7012) by @febo
- Add `PodOption` type (#6886) by @febo
- Use `bytemuck_derive` explicitly (#6928) by @joncinque
```

* Don't always run the step

* Make the YAML valid

* Trim each commit line to just the first line
ray-kast pushed a commit to abklabs/agave that referenced this pull request Nov 27, 2024
#### Problem

With solana-labs/solana-program-library#7148,
spl-token-2022 has moved from using solana-zk-token-sdk to
solana-zk-sdk, which is a major breaking change. Certain agave and
anchor crates are depending on the re-export solana-zk-token-sdk in
spl-token-2022, which is no longer present. This change is causing the
downstream Anchor job to fail, since the patched version of
spl-token-2022 is no longer compatible.

#### Summary of changes

Until new major versions of the SPL crates are available used by the
Agave monorepo, disable the downstream anchor job.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants