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

Confidential Transfer Support in @solana/spl-token #6338

Open
ixmorrow opened this issue Mar 6, 2024 · 5 comments
Open

Confidential Transfer Support in @solana/spl-token #6338

ixmorrow opened this issue Mar 6, 2024 · 5 comments

Comments

@ixmorrow
Copy link

ixmorrow commented Mar 6, 2024

I have been messing with confidential transfers on the client side recently and ran into some issues with the @solana/spl-token API that I'd like to highlight here.

  1. getMintLen() does not return the correct byte size for a mint with the confidential transfer extension.
  • This method seems to be the suggested way for determining how much space to allocate when creating an account with extensions from the client side. Using this function with the ExtensionType.ConfidentialTransferMint type as input returns a size of 267 bytes.
  • 267 bytes does not seem to be the correct size for a mint with the ConfidentialTransfer extension. Attempting to initialize a mint account with 267 bytes allocated will result in an error when you eventually call the InitializeMint instruction on the Token22 program.
  • The correct amount of bytes is 235. Allocating a buffer of exactly 235 bytes when creating the account will pass this check.
    • You can even test this by running the commandline example in the Confidential Transfer quick start guide and inspecting the transaction in an explorer.
spl-token --program-id TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb create-token --enable-confidential-transfers auto
  1. There is virtually no support for any of the Confidential Transfer instructions or any of the relevant types in the @solana/spl-token API. I assume this is intentional, but I have begun implementing the API following the same format as the other Token Extension methods for my own use cases. Which is a bit of a pain so far and I'm not sure if this is completely viable. I am curious why they are not supported yet and if there are plans to implement them?

  2. It seems like the "Configure a token account for confidential transfers" commandline example does not even work in the Confidential Transfers quick start guide.. I get a "Transaction simulation failed: Attempt to load a program that does not exist" RPC error. I'm at least able to invoke the ConfidentialTransfer::ConfigureAccount instruction via typescript on devnet, so I thought this error response was odd. But that might be unrelated.

Commandline RPC Error:

Error: Client(Error { request: Some(SendTransaction), kind: RpcError(RpcResponseError { code: -32002, message: "Transaction simulation failed: Attempt to load a program that does not exist", data: SendTransactionPreflightFailure(RpcSimulateTransactionResult { err: Some(ProgramAccountNotFound), logs: Some([]), accounts: None, units_consumed: Some(0), return_data: None }) }) })

Repo with my code.

@samkim-crypto
Copy link
Contributor

I apologize for the late response on this. The wrong size for the confidential transfer mint and accounts in token-js will be fixed once #6487 is merged.

There has been some delay with supporting confidential transfers in token-js as we plan to compile the zk logic with wasm. We hope to have them all supported within a couple of weeks.

Also, unfortunately, it is currently not possible to run the confidential transfers outside of tests since the zk proof verification program is behind a feature-gate (solana-labs/solana#32613). We are working hard to get the program activated, so please stay tuned.

@huckym
Copy link

huckym commented Apr 22, 2024

I am building the token-2022 program from the master branch, locally and running the local validator like this:

solana-test-validator -r
--bpf-program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb
/target/deploy/spl_token_2022.so

I can create the mint with the confidential transfer extension enabled and can deposit into confidential account, apply pending balance and can verify the encrypted available/pending balances on the explorer fine.
transfer and withdraw fail, however, with zkproof errors. Am I missing something in the build process or is something broken?

transfer error:
+ spl-token transfer --confidential 5WTfhiKQpEoisZmVca29tSKyPFqkDzRxuhoXujm34qQA 10 34DYPAVxjs4trEyHnbBhtKiNttTXzkyeqYusKsCLWTrY Confidential Transfer 10 tokens Sender: H4Ngfi9uMWzdKXd3WS6TbxCGQxhvnrK3pmFo84HrcMPN Recipient: 34DYPAVxjs4trEyHnbBhtKiNttTXzkyeqYusKsCLWTrY Error: Client(Error { request: Some(SendTransaction), kind: RpcError(RpcResponseError { code: -32002, message: "Transaction simulation failed: Error processing Instruction 0: invalid instruction data", data: SendTransactionPreflightFailure(RpcSimulateTransactionResult { err: Some(InstructionError(0, InvalidInstructionData)), logs: Some(["Program ZkTokenProof1111111111111111111111111111111 invoke [1]", "VerifyBatchedRangeProof128", "proof_verification failed: RangeProof(AlgebraicRelation)", "Program ZkTokenProof1111111111111111111111111111111 failed: invalid instruction data"]), accounts: None, units_consumed: Some(200000), return_data: None }) }) })

withdraw error:
+ spl-token withdraw-confidential-tokens 5WTfhiKQpEoisZmVca29tSKyPFqkDzRxuhoXujm34qQA 20 Withdrawing 20 confidential tokens Error: Client(Error { request: Some(SendTransaction), kind: RpcError(RpcResponseError { code: -32002, message: "Transaction simulation failed: Error processing Instruction 0: invalid instruction data", data: SendTransactionPreflightFailure(RpcSimulateTransactionResult { err: Some(InstructionError(0, InvalidInstructionData)), logs: Some(["Program ZkTokenProof1111111111111111111111111111111 invoke [1]", "VerifyWithdraw", "proof_verification failed: RangeProof(AlgebraicRelation)", "Program ZkTokenProof1111111111111111111111111111111 failed: invalid instruction data"]), accounts: None, units_consumed: Some(110000), return_data: None }) }) })

@joncinque @samkim-crypto

@samkim-crypto
Copy link
Contributor

Can you verify if the same error happens with the latest spl-token-cli build, which is 3.4.0? These type of errors were reported with 3.3.0, but should be fixed with the latest cli release.

@huckym
Copy link

huckym commented Apr 22, 2024

yes, that was indeed the error with 3.3.0. Just built and tried with 3.4.0 and both transfer/withdraw work fine too. Thanks for your quick pointer.
Are audit keys supported yet?

@samkim-crypto
Copy link
Contributor

Audit keys are supported in the program, but we have not added the functionality to decrypt yet. That will be coming very soon.

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

No branches or pull requests

3 participants