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

regression in wasm32 support for latest releases of spl-token-2022 #293

Closed
ifiokjr opened this issue Mar 16, 2025 · 6 comments · Fixed by #298
Closed

regression in wasm32 support for latest releases of spl-token-2022 #293

ifiokjr opened this issue Mar 16, 2025 · 6 comments · Fixed by #298

Comments

@ifiokjr
Copy link
Contributor

ifiokjr commented Mar 16, 2025

Description

The most recent versions of this library don't support wasm32. Running the following leads to an error.

cargo build -p spl-token-2022 --target wasm32-unknown-unknown

This is the error.

   Compiling spl-token-confidential-transfer-proof-generation v0.3.0 (/Users/me/Developer/os/token-2022/confidential-transfer/proof-generation)
   Compiling spl-token-confidential-transfer-ciphertext-arithmetic v0.2.1 (/Users/me/Developer/os/token-2022/confidential-transfer/ciphertext-arithmetic)
error[E0308]: arguments to this function are incorrect
   --> confidential-transfer/proof-generation/src/burn.rs:107:42
    |
107 |     let ciphertext_validity_proof_data = BatchedGroupedCiphertext3HandlesValidityProofData::new(
    |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: expected `&GroupedElGamalCiphertext3Handles`, found `&GroupedElGamalCiphertext<3>`
   --> confidential-transfer/proof-generation/src/burn.rs:111:9
    |
111 |         &burn_amount_ciphertext_lo.0,
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: expected reference `&GroupedElGamalCiphertext3Handles`
               found reference `&GroupedElGamalCiphertext<3>`
note: expected `&GroupedElGamalCiphertext3Handles`, found `&GroupedElGamalCiphertext<3>`
   --> confidential-transfer/proof-generation/src/burn.rs:112:9
    |
112 |         &burn_amount_ciphertext_hi.0,
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: expected reference `&GroupedElGamalCiphertext3Handles`
               found reference `&GroupedElGamalCiphertext<3>`
note: associated function defined here
   --> /Users/me/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/solana-zk-sdk-2.2.1/src/zk_elgamal_proof_program/proof_data/batched_grouped_ciphertext_validity/handles_3.rs:120:12
    |
120 |     pub fn new(
    |            ^^^

error[E0308]: arguments to this function are incorrect
   --> confidential-transfer/proof-generation/src/mint.rs:100:42
    |
100 |     let ciphertext_validity_proof_data = BatchedGroupedCiphertext3HandlesValidityProofData::new(
    |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: expected `&GroupedElGamalCiphertext3Handles`, found `&GroupedElGamalCiphertext<3>`
   --> confidential-transfer/proof-generation/src/mint.rs:104:9
    |
104 |         &mint_amount_grouped_ciphertext_lo.0,
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: expected reference `&GroupedElGamalCiphertext3Handles`
               found reference `&GroupedElGamalCiphertext<3>`
note: expected `&GroupedElGamalCiphertext3Handles`, found `&GroupedElGamalCiphertext<3>`
   --> confidential-transfer/proof-generation/src/mint.rs:105:9
    |
105 |         &mint_amount_grouped_ciphertext_hi.0,
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: expected reference `&GroupedElGamalCiphertext3Handles`
               found reference `&GroupedElGamalCiphertext<3>`
note: associated function defined here
   --> /Users/me/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/solana-zk-sdk-2.2.1/src/zk_elgamal_proof_program/proof_data/batched_grouped_ciphertext_validity/handles_3.rs:120:12
    |
120 |     pub fn new(
    |            ^^^

error[E0308]: arguments to this function are incorrect
   --> confidential-transfer/proof-generation/src/transfer.rs:111:42
    |
111 |     let ciphertext_validity_proof_data = BatchedGroupedCiphertext3HandlesValidityProofData::new(
    |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: expected `&GroupedElGamalCiphertext3Handles`, found `&GroupedElGamalCiphertext<3>`
   --> confidential-transfer/proof-generation/src/transfer.rs:115:9
    |
115 |         &transfer_amount_grouped_ciphertext_lo.0,
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: expected reference `&GroupedElGamalCiphertext3Handles`
               found reference `&GroupedElGamalCiphertext<3>`
note: expected `&GroupedElGamalCiphertext3Handles`, found `&GroupedElGamalCiphertext<3>`
   --> confidential-transfer/proof-generation/src/transfer.rs:116:9
    |
116 |         &transfer_amount_grouped_ciphertext_hi.0,
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: expected reference `&GroupedElGamalCiphertext3Handles`
               found reference `&GroupedElGamalCiphertext<3>`
note: associated function defined here
   --> /Users/me/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/solana-zk-sdk-2.2.1/src/zk_elgamal_proof_program/proof_data/batched_grouped_ciphertext_validity/handles_3.rs:120:12
    |
120 |     pub fn new(
    |            ^^^

error[E0308]: arguments to this function are incorrect
   --> confidential-transfer/proof-generation/src/transfer_with_fee.rs:129:9
    |
129 |         BatchedGroupedCiphertext3HandlesValidityProofData::new(
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: expected `&GroupedElGamalCiphertext3Handles`, found `&GroupedElGamalCiphertext<3>`
   --> confidential-transfer/proof-generation/src/transfer_with_fee.rs:133:13
    |
133 |             &transfer_amount_grouped_ciphertext_lo.0,
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: expected reference `&GroupedElGamalCiphertext3Handles`
               found reference `&GroupedElGamalCiphertext<3>`
note: expected `&GroupedElGamalCiphertext3Handles`, found `&GroupedElGamalCiphertext<3>`
   --> confidential-transfer/proof-generation/src/transfer_with_fee.rs:134:13
    |
134 |             &transfer_amount_grouped_ciphertext_hi.0,
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: expected reference `&GroupedElGamalCiphertext3Handles`
               found reference `&GroupedElGamalCiphertext<3>`
note: associated function defined here
   --> /Users/me/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/solana-zk-sdk-2.2.1/src/zk_elgamal_proof_program/proof_data/batched_grouped_ciphertext_validity/handles_3.rs:120:12
    |
120 |     pub fn new(
    |            ^^^

error[E0308]: arguments to this function are incorrect
   --> confidential-transfer/proof-generation/src/transfer_with_fee.rs:255:9
    |
255 |         BatchedGroupedCiphertext2HandlesValidityProofData::new(
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
note: expected `&GroupedElGamalCiphertext2Handles`, found `&GroupedElGamalCiphertext<2>`
   --> confidential-transfer/proof-generation/src/transfer_with_fee.rs:258:13
    |
258 |             &fee_destination_withdraw_withheld_authority_ciphertext_lo,
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: expected reference `&GroupedElGamalCiphertext2Handles`
               found reference `&GroupedElGamalCiphertext<2>`
note: expected `&GroupedElGamalCiphertext2Handles`, found `&GroupedElGamalCiphertext<2>`
   --> confidential-transfer/proof-generation/src/transfer_with_fee.rs:259:13
    |
259 |             &fee_destination_withdraw_withheld_authority_ciphertext_hi,
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: expected reference `&GroupedElGamalCiphertext2Handles`
               found reference `&GroupedElGamalCiphertext<2>`
note: associated function defined here
   --> /Users/me/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/solana-zk-sdk-2.2.1/src/zk_elgamal_proof_program/proof_data/batched_grouped_ciphertext_validity/handles_2.rs:114:12
    |
114 |     pub fn new(
    |            ^^^

For more information about this error, try `rustc --explain E0308`.
error: could not compile `spl-token-confidential-transfer-proof-generation` (lib) due to 5 previous errors
ifiokjr added a commit to ifiokjr/token-2022 that referenced this issue Mar 17, 2025
- Introduced conditional compilation for WASM target architecture in burn.rs, mint.rs, transfer.rs, and transfer_with_fee.rs.

Fixes solana-program#293
@ifiokjr
Copy link
Contributor Author

ifiokjr commented Mar 21, 2025

Who do I tag to get this merged? Currently wasm support has regressed from solana@2.1 to solana@2.2 without this fix.

@joncinque
Copy link
Contributor

I've tagged the proper reviewer on your PR, and it will be reviewed when he gets a chance.

To be totally clear, we have never made an effort to support wasm builds in the spl-token-2022 crate. It's great that the wasm build has worked, but it shouldn't be considered first-class.

The solana-zk-sdk, however, is explicitly written to support wasm: https://github.com/anza-xyz/agave/tree/master/zk-sdk, so I would recommend using that if you can.

@ifiokjr
Copy link
Contributor Author

ifiokjr commented Mar 22, 2025

The solana-zk-sdk, however, is explicitly written to support wasm: https://github.com/anza-xyz/agave/tree/master/zk-sdk, so I would recommend using that if you can.

@joncinque I'm not sure if I understand how using solana-zk-sdk would help integrate spl-token-2022 structs and types into a wasm codebase.

@ifiokjr
Copy link
Contributor Author

ifiokjr commented Mar 22, 2025

Thanks for tagging @samkim-crypto btw

@samkim-crypto
Copy link
Contributor

There is on-going work on exposing rust types in zk-sdk for JS libraries using wasm-pack. Unfortunately, wasm-pack does not yet support generic constants, so some types like GroupedElGamalCiphertext<3> has been replaced with concrete types like GroupedElGamalCiphertext3Handles for wasm target builds and this is what is causing the build issue.

We can resolve this by updating the confidential-transfer/proof-generation crate to use the new concrete types for wasm target, but there is no clean way to do this since the full GroupedElGamalCiphertext<3> interface has not been exposed yet. To address this properly, we would need to address it for the next version of zk-sdk.

@ifiokjr Can you give some detail on what you are trying to achieve? It is currently wip, but there is going to be JS support for zk-sdk (https://www.npmjs.com/package/@solana/zk-sdk). Another option is to work directly with the zk-sdk crate.

@ifiokjr
Copy link
Contributor Author

ifiokjr commented Mar 24, 2025

@samkim-crypto my library https://github.com/ifiokjr/wasm_solana/tree/main/crates/wasm_client_solana is a wasm32 compatible Solana RPC / PubSub client.

When I say I want wasm32 support, I don't need you to export wasm-bindgen methods, I just mean that it shouldn't break the build in a wasm32 environment.

This means that the community can use your code as building blocks and create wasm32 bindings to their preferred targets.

For example, some might need to build their rust backend code which consumes spl-token-2022 code to run in a deno or cloudflare worker environment via a wasm32 binding. However, the current release would break this.

Unfortunately, wasm-pack does not yet support generic constants, so some types like GroupedElGamalCiphertext<3> has been replaced with concrete types like GroupedElGamalCiphertext3Handles for wasm target builds and this is what is causing the build issue.

This has already been fixed in #298

ifiokjr added a commit to ifiokjr/token-2022 that referenced this issue Mar 25, 2025
- Introduced conditional compilation for WASM target architecture in burn.rs, mint.rs, transfer.rs, and transfer_with_fee.rs.

Fixes solana-program#293
ifiokjr added a commit to ifiokjr/token-2022 that referenced this issue Mar 27, 2025
- Introduced conditional compilation for WASM target architecture in burn.rs, mint.rs, transfer.rs, and transfer_with_fee.rs.

Fixes solana-program#293
samkim-crypto pushed a commit that referenced this issue Mar 27, 2025
* fix: support builds targetting `wasm32`

- Introduced conditional compilation for WASM target architecture in burn.rs, mint.rs, transfer.rs, and transfer_with_fee.rs.

Fixes #293

* ci: add `wasm` build check for `spl-token-2022`

- Introduced a new job in the GitHub Actions workflow to build the Token-2022 for the WASM target architecture.

This should ensure no future regressions.

* style: update formatting

* chore: add WASM build script for programs

- Removed the old `wasm:build` script and introduced `programs:build-wasm` to streamline the build process for WASM targets.
- Added a new `build-wasm.mjs` script to handle the WASM build using Cargo.

* ci: update build script
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 a pull request may close this issue.

3 participants