diff --git a/.github/actions/setup-and-build/action.yml b/.github/actions/setup-and-build/action.yml index 4c705e6cb5..e90cac95d2 100644 --- a/.github/actions/setup-and-build/action.yml +++ b/.github/actions/setup-and-build/action.yml @@ -112,19 +112,6 @@ runs: shell: bash run: bash scripts/devenv/install-photon.sh - - name: Cache proving keys - if: "!contains(inputs.skip-components, 'proving-keys')" - id: cache-keys - uses: actions/cache@v4 - with: - path: prover/server/proving-keys - key: ${{ runner.os }}-proving-keys-${{ inputs.cache-suffix }}${{ inputs.cache-suffix && '-' || '' }}${{ hashFiles('prover/server/prover/common/key_downloader.go', 'prover/server/prover/common/proving_keys_utils.go') }} - - - name: Download proving keys - if: "!contains(inputs.skip-components, 'proving-keys') && steps.cache-keys.outputs.cache-hit != 'true'" - shell: bash - run: bash scripts/devenv/download-gnark-keys.sh - - name: Set Light Protocol environment variables shell: bash run: | diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index fb187c2ad9..6eb3b703e6 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -48,7 +48,7 @@ jobs: cargo test -p aligned-sized cargo test -p light-hasher --all-features cargo test -p light-compressed-account --all-features - cargo test -p light-compressed-account --features new-unique + cargo test -p light-compressed-account --features new-unique,poseidon cargo test -p light-account-checks --all-features cargo test -p light-verifier --all-features cargo test -p light-merkle-tree-metadata --all-features diff --git a/cli/package.json b/cli/package.json index 949dd9d85e..c66d143ba6 100644 --- a/cli/package.json +++ b/cli/package.json @@ -54,7 +54,6 @@ }, "devDependencies": { "@eslint/js": "9.36.0", - "@lightprotocol/programs": "workspace:*", "@oclif/test": "^4.1.14", "@solana/spl-token": "^0.3.11", "@types/bn.js": "^5.1.5", diff --git a/forester-utils/Cargo.toml b/forester-utils/Cargo.toml index 792397a5f0..3efd38a2a7 100644 --- a/forester-utils/Cargo.toml +++ b/forester-utils/Cargo.toml @@ -15,7 +15,7 @@ v2 = ["light-client/v2"] [dependencies] light-hash-set = { workspace = true } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } light-concurrent-merkle-tree = { workspace = true } light-indexed-merkle-tree = { workspace = true } light-compressed-account = { workspace = true } diff --git a/forester/Cargo.toml b/forester/Cargo.toml index 7d0a390285..c13571ca6d 100644 --- a/forester/Cargo.toml +++ b/forester/Cargo.toml @@ -16,7 +16,7 @@ light-batched-merkle-tree = { workspace = true } light-compressed-account = { workspace = true } light-system-program-anchor = { workspace = true, features = ["cpi"] } light-hash-set = { workspace = true, features = ["solana"] } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } light-merkle-tree-reference = { workspace = true } light-registry = { workspace = true } photon-api = { workspace = true } diff --git a/js/compressed-token/package.json b/js/compressed-token/package.json index cc39208a27..77834ab3f6 100644 --- a/js/compressed-token/package.json +++ b/js/compressed-token/package.json @@ -43,7 +43,6 @@ "@esbuild-plugins/node-globals-polyfill": "^0.2.3", "@eslint/js": "9.36.0", "@lightprotocol/hasher.rs": "0.2.1", - "@lightprotocol/programs": "workspace:*", "@rollup/plugin-alias": "^5.1.0", "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-commonjs": "^26.0.1", @@ -135,10 +134,14 @@ ] }, "build-ci": { - "dependsOn": ["@lightprotocol/stateless.js:build-ci"] + "dependsOn": [ + "@lightprotocol/stateless.js:build-ci" + ] }, "test-ci": { - "dependsOn": ["@lightprotocol/stateless.js:test-ci"] + "dependsOn": [ + "@lightprotocol/stateless.js:test-ci" + ] } } } diff --git a/js/stateless.js/package.json b/js/stateless.js/package.json index 1e25bec9ce..7202b6bfec 100644 --- a/js/stateless.js/package.json +++ b/js/stateless.js/package.json @@ -54,7 +54,6 @@ "@esbuild-plugins/node-globals-polyfill": "^0.2.3", "@eslint/js": "9.36.0", "@lightprotocol/hasher.rs": "0.2.1", - "@lightprotocol/programs": "workspace:*", "@playwright/test": "^1.47.1", "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-commonjs": "^26.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0c21d46fab..659a490ab3 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -105,9 +105,6 @@ importers: '@eslint/js': specifier: 9.36.0 version: 9.36.0 - '@lightprotocol/programs': - specifier: workspace:* - version: link:../programs '@oclif/test': specifier: ^4.1.14 version: 4.1.14(@oclif/core@4.5.4) @@ -211,9 +208,6 @@ importers: '@lightprotocol/hasher.rs': specifier: 0.2.1 version: 0.2.1 - '@lightprotocol/programs': - specifier: workspace:* - version: link:../../programs '@rollup/plugin-alias': specifier: ^5.1.0 version: 5.1.0(rollup@4.21.3) @@ -353,9 +347,6 @@ importers: '@lightprotocol/hasher.rs': specifier: 0.2.1 version: 0.2.1 - '@lightprotocol/programs': - specifier: workspace:* - version: link:../../programs '@playwright/test': specifier: ^1.47.1 version: 1.47.1 diff --git a/program-libs/batched-merkle-tree/Cargo.toml b/program-libs/batched-merkle-tree/Cargo.toml index d6f8898c32..b5e34ff720 100644 --- a/program-libs/batched-merkle-tree/Cargo.toml +++ b/program-libs/batched-merkle-tree/Cargo.toml @@ -42,7 +42,7 @@ solana-sysvar = { workspace = true, optional = true } solana-msg = { workspace = true } solana-account-info = { workspace = true, optional = true } light-zero-copy = { workspace = true, features = ["std"] } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } light-bloom-filter = { workspace = true } light-verifier = { workspace = true } thiserror = { workspace = true } diff --git a/program-libs/compressed-account/Cargo.toml b/program-libs/compressed-account/Cargo.toml index 947db87414..874e4b2799 100644 --- a/program-libs/compressed-account/Cargo.toml +++ b/program-libs/compressed-account/Cargo.toml @@ -15,11 +15,13 @@ bytemuck-des = ["bytemuck"] new-unique = ["dep:solana-pubkey"] profile-program = [] profile-heap = ["dep:light-heap"] +poseidon = ["dep:light-poseidon", "light-hasher/poseidon"] [dependencies] thiserror = { workspace = true } zerocopy = { workspace = true, features = ["derive"] } light-hasher = { workspace = true } +light-poseidon = { workspace = true, optional = true } light-zero-copy = { workspace = true, features = ["std", "mut", "derive"] } light-macros = { workspace = true } pinocchio = { workspace = true, optional = true } @@ -36,6 +38,7 @@ light-heap = { workspace = true, optional = true } [dev-dependencies] rand = { workspace = true } light-poseidon = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } borsh = { workspace = true } ark-ff = { workspace = true } ark-bn254 = { workspace = true } diff --git a/program-libs/compressed-account/src/compressed_account.rs b/program-libs/compressed-account/src/compressed_account.rs index 9656a24282..aea089341a 100644 --- a/program-libs/compressed-account/src/compressed_account.rs +++ b/program-libs/compressed-account/src/compressed_account.rs @@ -390,8 +390,7 @@ impl ZCompressedAccount<'_> { } } -#[cfg(not(feature = "pinocchio"))] -#[cfg(test)] +#[cfg(all(not(feature = "pinocchio"), test, feature = "poseidon"))] mod tests { use light_hasher::Poseidon; use light_zero_copy::traits::ZeroCopyAt; diff --git a/program-libs/compressed-account/src/lib.rs b/program-libs/compressed-account/src/lib.rs index d16620f074..807aa73f14 100644 --- a/program-libs/compressed-account/src/lib.rs +++ b/program-libs/compressed-account/src/lib.rs @@ -10,6 +10,7 @@ pub mod compressed_account; pub mod constants; pub mod discriminators; pub use light_hasher::hash_chain; +#[cfg(feature = "poseidon")] pub mod indexer_event; pub mod instruction_data; pub mod nullifier; diff --git a/program-libs/concurrent-merkle-tree/Cargo.toml b/program-libs/concurrent-merkle-tree/Cargo.toml index f8eb39f814..7c12401f08 100644 --- a/program-libs/concurrent-merkle-tree/Cargo.toml +++ b/program-libs/concurrent-merkle-tree/Cargo.toml @@ -14,7 +14,7 @@ pinocchio = ["dep:pinocchio", "light-hasher/pinocchio"] [dependencies] borsh = { workspace = true } light-bounded-vec = { workspace = true, features = ["solana"] } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"]} memoffset = "0.9" solana-program-error = { workspace = true, optional = true } pinocchio = { workspace = true, optional = true } diff --git a/program-libs/hasher/Cargo.toml b/program-libs/hasher/Cargo.toml index 8fccbe472a..10a7256043 100644 --- a/program-libs/hasher/Cargo.toml +++ b/program-libs/hasher/Cargo.toml @@ -11,10 +11,11 @@ default = [] solana = ["solana-program-error", "solana-pubkey"] pinocchio = ["dep:pinocchio"] zero-copy = ["dep:zerocopy"] +poseidon = ["dep:light-poseidon", "dep:ark-bn254", "dep:ark-ff"] [dependencies] -light-poseidon = { workspace = true } +light-poseidon = { workspace = true, optional = true } thiserror = { workspace = true } arrayvec = { workspace = true } num-bigint = { workspace = true } @@ -28,10 +29,10 @@ borsh = { workspace = true } solana-nostd-keccak = "0.1.3" [target.'cfg(not(target_os = "solana"))'.dependencies] -ark-bn254 = { workspace = true } +ark-bn254 = { workspace = true, optional = true } sha2 = "0.10" sha3 = "0.10" -ark-ff = { workspace = true } +ark-ff = { workspace = true, optional = true } [lints.rust.unexpected_cfgs] level = "allow" @@ -43,3 +44,4 @@ check-cfg = [ [dev-dependencies] rand = { workspace = true } num-bigint = { workspace = true, features = ["rand"] } +light-poseidon = { workspace = true } diff --git a/program-libs/hasher/src/errors.rs b/program-libs/hasher/src/errors.rs index dcba85c721..050fac1f12 100644 --- a/program-libs/hasher/src/errors.rs +++ b/program-libs/hasher/src/errors.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "poseidon")] use light_poseidon::PoseidonError; use thiserror::Error; @@ -7,6 +8,7 @@ use crate::poseidon::PoseidonSyscallError; pub enum HasherError { #[error("Integer overflow, value too large")] IntegerOverflow, + #[cfg(feature = "poseidon")] #[error("Poseidon hasher error: {0}")] Poseidon(#[from] PoseidonError), #[error("Poseidon syscall error: {0}")] @@ -25,6 +27,8 @@ pub enum HasherError { "Option hash to field size returned [0u8;32], a collision with None for an Option type." )] OptionHashToFieldSizeZero, + #[error("Poseidon feature is not enabled. Without feature poseidon only syscalls are accessible in target os solana")] + PoseidonFeatureNotEnabled, } // NOTE(vadorovsky): Unfortunately, we need to do it by hand. `num_derive::ToPrimitive` @@ -33,6 +37,7 @@ impl From for u32 { fn from(e: HasherError) -> u32 { match e { HasherError::IntegerOverflow => 7001, + #[cfg(feature = "poseidon")] HasherError::Poseidon(_) => 7002, HasherError::PoseidonSyscall(e) => (u64::from(e)).try_into().unwrap_or(7003), HasherError::UnknownSolanaSyscall(e) => e.try_into().unwrap_or(7004), @@ -41,6 +46,7 @@ impl From for u32 { HasherError::EmptyInput => 7007, HasherError::BorshError => 7008, HasherError::OptionHashToFieldSizeZero => 7009, + HasherError::PoseidonFeatureNotEnabled => 7010, } } } diff --git a/program-libs/hasher/src/hash_chain.rs b/program-libs/hasher/src/hash_chain.rs index 5f1c7587d5..b1ea9fd997 100644 --- a/program-libs/hasher/src/hash_chain.rs +++ b/program-libs/hasher/src/hash_chain.rs @@ -71,12 +71,9 @@ pub fn create_two_inputs_hash_chain( #[cfg(test)] mod hash_chain_tests { - use ark_ff::PrimeField; - use light_poseidon::PoseidonError; - use num_bigint::BigUint; use super::*; - use crate::{bigint::bigint_to_be_bytes_array, Hasher, HasherError, Poseidon}; + use crate::{Hasher, HasherError, Poseidon}; /// Tests for `create_hash_chain_from_slice` function: /// Functional tests: @@ -175,9 +172,14 @@ mod hash_chain_tests { let result = create_hash_chain_from_slice(&inputs).unwrap(); assert_eq!(result, [0u8; 32], "Empty input should return zero hash"); } - // 5. Failing - input larger than modulus + #[cfg(feature = "poseidon")] { + use ark_ff::PrimeField; + use light_poseidon::PoseidonError; + use num_bigint::BigUint; + + use crate::bigint::bigint_to_be_bytes_array; let modulus: BigUint = ark_bn254::Fr::MODULUS.into(); let modulus_bytes: [u8; 32] = bigint_to_be_bytes_array(&modulus).unwrap(); let huge_input = vec![modulus_bytes, modulus_bytes]; diff --git a/program-libs/hasher/src/hash_to_field_size.rs b/program-libs/hasher/src/hash_to_field_size.rs index 2e7b67c4d3..08c203ac4e 100644 --- a/program-libs/hasher/src/hash_to_field_size.rs +++ b/program-libs/hasher/src/hash_to_field_size.rs @@ -92,7 +92,7 @@ pub fn hash_to_bn254_field_size_be(bytes: &[u8]) -> [u8; 32] { hashv_to_bn254_field_size_be_const_array::<2>(&[bytes]).unwrap() } -#[cfg(not(target_os = "solana"))] +#[cfg(all(not(target_os = "solana"), feature = "poseidon"))] pub fn is_smaller_than_bn254_field_size_be(bytes: &[u8; 32]) -> bool { use ark_ff::PrimeField; use num_bigint::BigUint; @@ -100,6 +100,7 @@ pub fn is_smaller_than_bn254_field_size_be(bytes: &[u8; 32]) -> bool { bigint < ark_bn254::Fr::MODULUS.into() } +#[cfg(feature = "poseidon")] #[cfg(test)] mod tests { use ark_ff::PrimeField; diff --git a/program-libs/hasher/src/poseidon.rs b/program-libs/hasher/src/poseidon.rs index b13d4a6a83..3c9f92b6fb 100644 --- a/program-libs/hasher/src/poseidon.rs +++ b/program-libs/hasher/src/poseidon.rs @@ -36,6 +36,7 @@ pub enum PoseidonSyscallError { #[error("Unexpected error")] Unexpected, } + impl From for PoseidonSyscallError { fn from(error: u64) -> Self { match error { @@ -84,19 +85,23 @@ impl Hasher for Poseidon { Self::hashv(&[val]) } - fn hashv(vals: &[&[u8]]) -> Result { + fn hashv(_vals: &[&[u8]]) -> Result { // Perform the calculation inline, calling this from within a program is // not supported. - #[cfg(not(target_os = "solana"))] + #[cfg(all(not(target_os = "solana"), feature = "poseidon"))] { use ark_bn254::Fr; use light_poseidon::{Poseidon, PoseidonBytesHasher}; - let mut hasher = Poseidon::::new_circom(vals.len())?; - let res = hasher.hash_bytes_be(vals)?; + let mut hasher = Poseidon::::new_circom(_vals.len())?; + let res = hasher.hash_bytes_be(_vals)?; Ok(res) } + #[cfg(all(not(target_os = "solana"), not(feature = "poseidon")))] + { + Err(HasherError::PoseidonFeatureNotEnabled) + } // Call via a system call to perform the calculation. #[cfg(target_os = "solana")] { @@ -113,8 +118,8 @@ impl Hasher for Poseidon { crate::syscalls::sol_poseidon( 0, // bn254 0, // big-endian - vals as *const _ as *const u8, - vals.len() as u64, + _vals as *const _ as *const u8, + _vals.len() as u64, &mut hash_result as *mut _ as *mut u8, ) }; diff --git a/program-libs/indexed-array/Cargo.toml b/program-libs/indexed-array/Cargo.toml index 2d97b73842..18b01a319b 100644 --- a/program-libs/indexed-array/Cargo.toml +++ b/program-libs/indexed-array/Cargo.toml @@ -7,7 +7,7 @@ license = "Apache-2.0" edition = "2021" [dependencies] -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"]} num-bigint = { workspace = true } num-traits = { workspace = true } thiserror = { workspace = true } diff --git a/program-libs/indexed-merkle-tree/Cargo.toml b/program-libs/indexed-merkle-tree/Cargo.toml index 5dc158ed2d..0629fe0405 100644 --- a/program-libs/indexed-merkle-tree/Cargo.toml +++ b/program-libs/indexed-merkle-tree/Cargo.toml @@ -22,7 +22,7 @@ pinocchio = [ [dependencies] light-bounded-vec = { workspace = true } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"]} light-concurrent-merkle-tree = { workspace = true } light-merkle-tree-reference = { workspace = true } num-bigint = { workspace = true } diff --git a/program-tests/account-compression-test/Cargo.toml b/program-tests/account-compression-test/Cargo.toml index efc50b01e5..1629a9701a 100644 --- a/program-tests/account-compression-test/Cargo.toml +++ b/program-tests/account-compression-test/Cargo.toml @@ -32,7 +32,7 @@ num-bigint = { workspace = true } anchor-spl = { workspace = true } anchor-lang = { workspace = true } account-compression = { workspace = true } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } light-hash-set = { workspace = true } light-concurrent-merkle-tree = { workspace = true } light-indexed-merkle-tree = { workspace = true } diff --git a/program-tests/batched-merkle-tree-test/Cargo.toml b/program-tests/batched-merkle-tree-test/Cargo.toml index 1d733ae546..bb0b434421 100644 --- a/program-tests/batched-merkle-tree-test/Cargo.toml +++ b/program-tests/batched-merkle-tree-test/Cargo.toml @@ -17,7 +17,7 @@ serial_test = { workspace = true } light-account-checks = { workspace = true, features = ["test-only"] } light-compressed-account = { workspace = true, features = ["new-unique"] } light-test-utils = { workspace = true, features = ["test-only"] } -light-hasher = { workspace = true, features = ["solana"] } +light-hasher = { workspace = true, features = ["solana", "poseidon"] } light-bloom-filter = { workspace = true, features = ["solana"] } light-zero-copy = { workspace = true } solana-pubkey = { workspace = true } diff --git a/program-tests/create-address-test-program/Cargo.toml b/program-tests/create-address-test-program/Cargo.toml index ba7ed0438e..8ca8807c53 100644 --- a/program-tests/create-address-test-program/Cargo.toml +++ b/program-tests/create-address-test-program/Cargo.toml @@ -20,7 +20,7 @@ test-sbf = [] default = [] [dependencies] -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } anchor-lang = { workspace = true } light-system-program-anchor = { workspace = true, features = ["cpi"] } account-compression = { workspace = true, features = ["cpi"] } diff --git a/program-tests/registry-test/Cargo.toml b/program-tests/registry-test/Cargo.toml index 42bd2846d0..ea60e6494f 100644 --- a/program-tests/registry-test/Cargo.toml +++ b/program-tests/registry-test/Cargo.toml @@ -30,7 +30,7 @@ anchor-lang = { workspace = true } forester-utils = { workspace = true } light-registry = { workspace = true } account-compression = { workspace = true } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } light-compressed-account = { workspace = true } solana-sdk = { workspace = true } serial_test = { workspace = true } diff --git a/program-tests/system-cpi-test/Cargo.toml b/program-tests/system-cpi-test/Cargo.toml index dde01c17c3..5e7c6bf40d 100644 --- a/program-tests/system-cpi-test/Cargo.toml +++ b/program-tests/system-cpi-test/Cargo.toml @@ -27,7 +27,7 @@ light-compressed-token = { workspace = true, features = ["cpi"] } light-system-program-anchor = { workspace = true, features = ["cpi"] } light-registry = { workspace = true, features = ["cpi"] } account-compression = { workspace = true, features = ["cpi"] } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } light-compressed-account = { workspace = true, features = ["anchor"] } light-batched-merkle-tree = { workspace = true } light-merkle-tree-metadata = { workspace = true, features = ["anchor"] } diff --git a/program-tests/system-cpi-v2-test/Cargo.toml b/program-tests/system-cpi-v2-test/Cargo.toml index 8093e50f65..479d3a4562 100644 --- a/program-tests/system-cpi-v2-test/Cargo.toml +++ b/program-tests/system-cpi-v2-test/Cargo.toml @@ -22,7 +22,7 @@ light-compressed-token = { workspace = true, features = ["cpi"] } light-system-program-anchor = { workspace = true, features = ["cpi"] } light-registry = { workspace = true, features = ["cpi"] } account-compression = { workspace = true, features = ["cpi"] } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } light-compressed-account = { workspace = true, features = ["anchor"] } light-batched-merkle-tree = { workspace = true } light-merkle-tree-metadata = { workspace = true, features = ["anchor"] } diff --git a/program-tests/system-test/Cargo.toml b/program-tests/system-test/Cargo.toml index 3ef28c6aa1..adfd219486 100644 --- a/program-tests/system-test/Cargo.toml +++ b/program-tests/system-test/Cargo.toml @@ -32,7 +32,7 @@ light-prover-client = { workspace = true, features = ["devenv"] } anchor-lang = { workspace = true } light-system-program-anchor = { workspace = true, features = ["cpi"] } account-compression = { workspace = true, features = ["cpi"] } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } light-compressed-account = { workspace = true, features = ["anchor"] } light-client = { workspace = true, features = ["devenv"] } light-sdk = { workspace = true, features = ["anchor"] } diff --git a/program-tests/utils/Cargo.toml b/program-tests/utils/Cargo.toml index 00cb536fc3..24d47e0746 100644 --- a/program-tests/utils/Cargo.toml +++ b/program-tests/utils/Cargo.toml @@ -25,7 +25,7 @@ light-system-program-anchor = { workspace = true, features = ["cpi"] } light-registry = { workspace = true, features = ["cpi"] } spl-token = { workspace = true, features = ["no-entrypoint"] } light-prover-client = { workspace = true, features = ["devenv"] } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } light-merkle-tree-reference = { workspace = true } light-concurrent-merkle-tree = { workspace = true } light-indexed-merkle-tree = { workspace = true } diff --git a/programs/compressed-token/Cargo.toml b/programs/compressed-token/Cargo.toml index 1ed38de11d..5c06961132 100644 --- a/programs/compressed-token/Cargo.toml +++ b/programs/compressed-token/Cargo.toml @@ -45,6 +45,7 @@ solana-sdk = { workspace = true } [dev-dependencies] rand = { workspace = true } num-bigint = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } [lints.rust.unexpected_cfgs] level = "allow" diff --git a/prover/client/Cargo.toml b/prover/client/Cargo.toml index bd9c03af58..0579cde9a5 100644 --- a/prover/client/Cargo.toml +++ b/prover/client/Cargo.toml @@ -12,7 +12,7 @@ devenv = [] [dependencies] -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } light-indexed-array = { workspace = true } light-sparse-merkle-tree = { workspace = true } diff --git a/sdk-libs/client/Cargo.toml b/sdk-libs/client/Cargo.toml index d34ffae81d..8fd84bdf39 100644 --- a/sdk-libs/client/Cargo.toml +++ b/sdk-libs/client/Cargo.toml @@ -41,8 +41,8 @@ light-merkle-tree-metadata = { workspace = true, features = ["solana"] } light-concurrent-merkle-tree = { workspace = true } light-indexed-merkle-tree = { workspace = true } light-sdk = { workspace = true } -light-hasher = { workspace = true } -light-compressed-account = { workspace = true, features = ["solana"] } +light-hasher = { workspace = true, features = ["poseidon"] } +light-compressed-account = { workspace = true, features = ["solana", "poseidon"] } photon-api = { workspace = true } light-prover-client = { workspace = true } diff --git a/sdk-libs/macros/Cargo.toml b/sdk-libs/macros/Cargo.toml index 3f61f81045..5465202979 100644 --- a/sdk-libs/macros/Cargo.toml +++ b/sdk-libs/macros/Cargo.toml @@ -17,7 +17,6 @@ syn = { workspace = true } solana-pubkey = { workspace = true, features = ["curve25519", "sha2"] } light-hasher = { workspace = true } -light-poseidon = { workspace = true } [dev-dependencies] light-compressed-account = { workspace = true } @@ -27,6 +26,8 @@ solana-pubkey = { workspace = true, features = ["borsh"] } borsh = { workspace = true } light-macros = { workspace = true } light-account-checks = { workspace = true } +light-hasher = { workspace = true , features = ["poseidon"]} +light-poseidon = { workspace = true } [lib] proc-macro = true diff --git a/sdk-libs/program-test/Cargo.toml b/sdk-libs/program-test/Cargo.toml index 0654e51991..657c4b2bae 100644 --- a/sdk-libs/program-test/Cargo.toml +++ b/sdk-libs/program-test/Cargo.toml @@ -17,8 +17,8 @@ light-indexed-array = { workspace = true } light-merkle-tree-reference = { workspace = true } light-merkle-tree-metadata = { workspace = true, features = ["anchor"] } light-concurrent-merkle-tree = { workspace = true, optional = true } -light-hasher = { workspace = true } -light-compressed-account = { workspace = true, features = ["anchor"] } +light-hasher = { workspace = true, features = ["poseidon"] } +light-compressed-account = { workspace = true, features = ["anchor", "poseidon"] } light-batched-merkle-tree = { workspace = true, features = ["test-only"], optional = true } # unreleased diff --git a/sdk-libs/program-test/src/utils/setup_light_programs.rs b/sdk-libs/program-test/src/utils/setup_light_programs.rs index eaddcc43d0..e88d22aa4a 100644 --- a/sdk-libs/program-test/src/utils/setup_light_programs.rs +++ b/sdk-libs/program-test/src/utils/setup_light_programs.rs @@ -69,7 +69,7 @@ pub fn setup_light_programs( .inspect_err(|_| { println!("Program light_compressed_token bin not found in {}", path); })?; - let path = format!("{}/spl_noop.so", light_bin_path); + let path = format!("{}spl_noop.so", light_bin_path); program_test .add_program_from_file(NOOP_PROGRAM_ID, path.clone()) .inspect_err(|_| { diff --git a/sdk-libs/sdk-pinocchio/Cargo.toml b/sdk-libs/sdk-pinocchio/Cargo.toml index 1408334c4a..2b0135848f 100644 --- a/sdk-libs/sdk-pinocchio/Cargo.toml +++ b/sdk-libs/sdk-pinocchio/Cargo.toml @@ -12,7 +12,7 @@ v2 = ["light-sdk-types/v2"] [dependencies] pinocchio = { workspace = true } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } light-account-checks = { workspace = true, features = ["pinocchio"] } light-macros = { workspace = true } light-sdk-macros = { workspace = true } diff --git a/sdk-libs/sdk-types/Cargo.toml b/sdk-libs/sdk-types/Cargo.toml index c188eb902b..46d0bcd2fd 100644 --- a/sdk-libs/sdk-types/Cargo.toml +++ b/sdk-libs/sdk-types/Cargo.toml @@ -10,6 +10,7 @@ description = "Core types for Light Protocol SDK" anchor = ["anchor-lang", "light-compressed-account/anchor"] v2 = [] cpi-context = [] +poseidon = ["light-hasher/poseidon", "light-compressed-account/poseidon"] [dependencies] anchor-lang = { workspace = true, optional = true } diff --git a/sdk-libs/sdk/Cargo.toml b/sdk-libs/sdk/Cargo.toml index 99d1583d9b..660403910d 100644 --- a/sdk-libs/sdk/Cargo.toml +++ b/sdk-libs/sdk/Cargo.toml @@ -21,6 +21,7 @@ anchor = [ v2 = ["light-sdk-types/v2"] cpi-context = ["light-sdk-types/cpi-context"] devnet = [] +poseidon = ["light-hasher/poseidon", "light-compressed-account/poseidon"] [dependencies] diff --git a/sdk-libs/sdk/src/account.rs b/sdk-libs/sdk/src/account.rs index dbad5e1c57..4ee5a7c093 100644 --- a/sdk-libs/sdk/src/account.rs +++ b/sdk-libs/sdk/src/account.rs @@ -128,9 +128,11 @@ use light_compressed_account::{ use light_sdk_types::instruction::account_meta::CompressedAccountMetaTrait; use solana_pubkey::Pubkey; +#[cfg(feature = "poseidon")] +use crate::light_hasher::Poseidon; use crate::{ error::LightSdkError, - light_hasher::{DataHasher, Hasher, Poseidon, Sha256}, + light_hasher::{DataHasher, Hasher, Sha256}, AnchorDeserialize, AnchorSerialize, LightDiscriminator, }; @@ -151,6 +153,7 @@ pub mod sha { /// Poseidon hashed Light Account. /// Poseidon hashing is zk friendly and enables you to do zk proofs over your compressed account data. +#[cfg(feature = "poseidon")] pub mod poseidon { use super::*; /// Light Account type using Poseidon hashing. diff --git a/sdk-libs/sdk/src/cpi/instruction.rs b/sdk-libs/sdk/src/cpi/instruction.rs index afb46815d3..c5a9d2e9e0 100644 --- a/sdk-libs/sdk/src/cpi/instruction.rs +++ b/sdk-libs/sdk/src/cpi/instruction.rs @@ -1,8 +1,9 @@ use light_compressed_account::instruction_data::compressed_proof::ValidityProof; +#[cfg(feature = "poseidon")] +use crate::DataHasher; use crate::{ - account::LightAccount, AnchorDeserialize, AnchorSerialize, DataHasher, LightDiscriminator, - ProgramError, + account::LightAccount, AnchorDeserialize, AnchorSerialize, LightDiscriminator, ProgramError, }; /// Trait for Light CPI instruction types @@ -39,6 +40,7 @@ pub trait LightCpiInstruction: Sized { /// /// # Type Parameters /// * `A` - The compressed account data type that implements DataHasher + #[cfg(feature = "poseidon")] #[must_use = "with_light_account_poseidon returns a new value"] fn with_light_account_poseidon( self, diff --git a/sdk-libs/sdk/src/cpi/v1/invoke.rs b/sdk-libs/sdk/src/cpi/v1/invoke.rs index ee16ad021b..e32c507f0e 100644 --- a/sdk-libs/sdk/src/cpi/v1/invoke.rs +++ b/sdk-libs/sdk/src/cpi/v1/invoke.rs @@ -2,12 +2,14 @@ use light_compressed_account::instruction_data::{ compressed_proof::ValidityProof, invoke_cpi::InstructionDataInvokeCpi, }; +#[cfg(feature = "poseidon")] +use crate::{account::poseidon::LightAccount as LightAccountPoseidon, DataHasher}; use crate::{ - account::{poseidon::LightAccount as LightAccountPoseidon, LightAccount}, + account::LightAccount, cpi::{instruction::LightCpiInstruction, invoke::LightInstructionData, CpiSigner}, error::LightSdkError, instruction::account_info::CompressedAccountInfoTrait, - AnchorDeserialize, AnchorSerialize, DataHasher, LightDiscriminator, ProgramError, + AnchorDeserialize, AnchorSerialize, LightDiscriminator, ProgramError, }; /// Light system program CPI instruction data builder. @@ -256,6 +258,7 @@ impl LightCpiInstruction for LightSystemProgramCpi { Ok(self) } + #[cfg(feature = "poseidon")] fn with_light_account_poseidon( mut self, account: LightAccountPoseidon<'_, A>, diff --git a/sdk-libs/sdk/src/cpi/v2/invoke.rs b/sdk-libs/sdk/src/cpi/v2/invoke.rs index 60841eecdd..8991a10893 100644 --- a/sdk-libs/sdk/src/cpi/v2/invoke.rs +++ b/sdk-libs/sdk/src/cpi/v2/invoke.rs @@ -6,13 +6,14 @@ use light_sdk_types::CpiSigner; #[cfg(feature = "cpi-context")] use super::lowlevel::CompressedCpiContext; use super::lowlevel::{to_account_metas, InAccount, InstructionDataInvokeCpiWithReadOnly}; +#[cfg(feature = "poseidon")] +use crate::{account::poseidon::LightAccount as LightAccountPoseidon, DataHasher}; use crate::{ - account::{poseidon::LightAccount as LightAccountPoseidon, LightAccount}, + account::LightAccount, cpi::{account::CpiAccountsTrait, instruction::LightCpiInstruction, v2::CpiAccounts}, error::LightSdkError, instruction::account_info::CompressedAccountInfoTrait, - AccountInfo, AccountMeta, AnchorDeserialize, AnchorSerialize, DataHasher, LightDiscriminator, - ProgramError, + AccountInfo, AccountMeta, AnchorDeserialize, AnchorSerialize, LightDiscriminator, ProgramError, }; impl<'info> CpiAccountsTrait<'info> for CpiAccounts<'_, 'info> { @@ -94,6 +95,7 @@ impl LightCpiInstruction for InstructionDataInvokeCpiWithReadOnly { Ok(self) } + #[cfg(feature = "poseidon")] fn with_light_account_poseidon( mut self, account: LightAccountPoseidon<'_, A>, @@ -218,6 +220,7 @@ impl LightCpiInstruction for InstructionDataInvokeCpiWithAccountInfo { Ok(self) } + #[cfg(feature = "poseidon")] fn with_light_account_poseidon( mut self, account: crate::account::poseidon::LightAccount<'_, A>, diff --git a/sdk-libs/sdk/src/lib.rs b/sdk-libs/sdk/src/lib.rs index 4b46e329a6..340b5842e0 100644 --- a/sdk-libs/sdk/src/lib.rs +++ b/sdk-libs/sdk/src/lib.rs @@ -158,6 +158,7 @@ use anchor_lang::{AnchorDeserialize, AnchorSerialize}; use borsh::{BorshDeserialize as AnchorDeserialize, BorshSerialize as AnchorSerialize}; pub use light_account_checks::{self, discriminator::Discriminator as LightDiscriminator}; pub use light_hasher; +#[cfg(feature = "poseidon")] use light_hasher::DataHasher; pub use light_sdk_macros::{ derive_light_cpi_signer, light_system_accounts, LightDiscriminator, LightHasher, diff --git a/sdk-tests/client-test/Cargo.toml b/sdk-tests/client-test/Cargo.toml index 1db3f4c4bd..2cf913b10d 100644 --- a/sdk-tests/client-test/Cargo.toml +++ b/sdk-tests/client-test/Cargo.toml @@ -23,7 +23,7 @@ light-sdk = { workspace = true } light-sdk-pinocchio = { workspace = true } light-sdk-types = { workspace = true } light-zero-copy = { workspace = true } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } light-compressed-account = { workspace = true } light-compressed-token = { workspace = true } light-indexed-array = { workspace = true } diff --git a/sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/Cargo.toml b/sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/Cargo.toml index 82448e4f90..f7709e8bcb 100644 --- a/sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/Cargo.toml +++ b/sdk-tests/sdk-anchor-test/programs/sdk-anchor-test/Cargo.toml @@ -22,9 +22,9 @@ idl-build = ["anchor-lang/idl-build", "light-sdk/idl-build"] [dependencies] # Needs to be imported for LightHasher -light-hasher = { workspace = true, features = ["solana"] } +light-hasher = { workspace = true, features = ["solana", "poseidon"] } anchor-lang = { workspace = true } -light-sdk = { workspace = true, features = ["anchor", "v2"] } +light-sdk = { workspace = true, features = ["anchor", "v2", "poseidon"] } light-sdk-types = { workspace = true } serial_test = { workspace = true } diff --git a/sdk-tests/sdk-native-test/Cargo.toml b/sdk-tests/sdk-native-test/Cargo.toml index 942bf05e84..1b1ab3d5f2 100644 --- a/sdk-tests/sdk-native-test/Cargo.toml +++ b/sdk-tests/sdk-native-test/Cargo.toml @@ -22,7 +22,7 @@ default = [] [dependencies] light-sdk = { workspace = true, features = ["v2"] } light-sdk-types = { workspace = true } -light-hasher = { workspace = true, features = ["solana"] } +light-hasher = { workspace = true, features = ["solana", "poseidon"] } solana-program = { workspace = true } light-macros = { workspace = true, features = ["solana"] } borsh = { workspace = true } diff --git a/sdk-tests/sdk-pinocchio-v1-test/Cargo.toml b/sdk-tests/sdk-pinocchio-v1-test/Cargo.toml index b8ee71e2f1..793a4badb2 100644 --- a/sdk-tests/sdk-pinocchio-v1-test/Cargo.toml +++ b/sdk-tests/sdk-pinocchio-v1-test/Cargo.toml @@ -22,7 +22,7 @@ default = [] [dependencies] light-sdk-pinocchio = { workspace = true } light-sdk-types = { workspace = true } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } pinocchio = { workspace = true } light-macros = { workspace = true } borsh = { workspace = true } @@ -31,7 +31,7 @@ borsh = { workspace = true } light-program-test = { workspace = true, features = ["devenv"] } tokio = { workspace = true } solana-sdk = { workspace = true } -light-hasher = { workspace = true, features = ["solana"] } +light-hasher = { workspace = true, features = ["solana", "poseidon"] } light-compressed-account = { workspace = true, features = ["solana"] } light-sdk = { workspace = true } diff --git a/sdk-tests/sdk-pinocchio-v2-test/Cargo.toml b/sdk-tests/sdk-pinocchio-v2-test/Cargo.toml index 8789dfb2d3..315903417e 100644 --- a/sdk-tests/sdk-pinocchio-v2-test/Cargo.toml +++ b/sdk-tests/sdk-pinocchio-v2-test/Cargo.toml @@ -22,7 +22,7 @@ default = [] [dependencies] light-sdk-pinocchio = { workspace = true, features = ["v2"] } light-sdk-types = { workspace = true, features = ["v2"] } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } pinocchio = { workspace = true } light-macros = { workspace = true } borsh = { workspace = true } @@ -31,7 +31,7 @@ borsh = { workspace = true } light-program-test = { workspace = true, features = ["devenv"] } tokio = { workspace = true } solana-sdk = { workspace = true } -light-hasher = { workspace = true, features = ["solana"] } +light-hasher = { workspace = true, features = ["solana", "poseidon"] } light-compressed-account = { workspace = true, features = ["solana"] } light-sdk = { workspace = true, features = ["v2"] } diff --git a/sdk-tests/sdk-v1-native-test/Cargo.toml b/sdk-tests/sdk-v1-native-test/Cargo.toml index a69e035b32..29effbc096 100644 --- a/sdk-tests/sdk-v1-native-test/Cargo.toml +++ b/sdk-tests/sdk-v1-native-test/Cargo.toml @@ -22,7 +22,7 @@ default = [] [dependencies] light-sdk = { workspace = true } light-sdk-types = { workspace = true } -light-hasher = { workspace = true, features = ["solana"] } +light-hasher = { workspace = true, features = ["solana", "poseidon"] } solana-program = { workspace = true } light-macros = { workspace = true, features = ["solana"] } borsh = { workspace = true } diff --git a/sparse-merkle-tree/Cargo.toml b/sparse-merkle-tree/Cargo.toml index 1eb4656c2d..66cfd0d081 100644 --- a/sparse-merkle-tree/Cargo.toml +++ b/sparse-merkle-tree/Cargo.toml @@ -7,7 +7,7 @@ license = "Apache-2.0" edition = "2021" [dependencies] -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } num-bigint = { workspace = true } num-traits = { workspace = true } thiserror = { workspace = true } diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index a96212b98f..107f55af94 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -13,7 +13,7 @@ clap = { version = "4", features = ["derive"] } groth16-solana = { workspace = true } light-concurrent-merkle-tree = { workspace = true } light-hash-set = { workspace = true } -light-hasher = { workspace = true } +light-hasher = { workspace = true, features = ["poseidon"] } light-indexed-merkle-tree = { workspace = true } light-compressed-account = { workspace = true } light-merkle-tree-metadata = { workspace = true }