Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .github/actions/setup-and-build/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion forester-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion forester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
9 changes: 6 additions & 3 deletions js/compressed-token/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
]
}
}
}
Expand Down
1 change: 0 additions & 1 deletion js/stateless.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 0 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion program-libs/batched-merkle-tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
3 changes: 3 additions & 0 deletions program-libs/compressed-account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand Down
3 changes: 1 addition & 2 deletions program-libs/compressed-account/src/compressed_account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions program-libs/compressed-account/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion program-libs/concurrent-merkle-tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
8 changes: 5 additions & 3 deletions program-libs/hasher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"
Expand All @@ -43,3 +44,4 @@ check-cfg = [
[dev-dependencies]
rand = { workspace = true }
num-bigint = { workspace = true, features = ["rand"] }
light-poseidon = { workspace = true }
6 changes: 6 additions & 0 deletions program-libs/hasher/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "poseidon")]
use light_poseidon::PoseidonError;
use thiserror::Error;

Expand All @@ -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}")]
Expand All @@ -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`
Expand All @@ -33,6 +37,7 @@ impl From<HasherError> 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),
Expand All @@ -41,6 +46,7 @@ impl From<HasherError> for u32 {
HasherError::EmptyInput => 7007,
HasherError::BorshError => 7008,
HasherError::OptionHashToFieldSizeZero => 7009,
HasherError::PoseidonFeatureNotEnabled => 7010,
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions program-libs/hasher/src/hash_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion program-libs/hasher/src/hash_to_field_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,15 @@ 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;
let bigint = BigUint::from_bytes_be(bytes);
bigint < ark_bn254::Fr::MODULUS.into()
}

#[cfg(feature = "poseidon")]
#[cfg(test)]
mod tests {
use ark_ff::PrimeField;
Expand Down
17 changes: 11 additions & 6 deletions program-libs/hasher/src/poseidon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub enum PoseidonSyscallError {
#[error("Unexpected error")]
Unexpected,
}

impl From<u64> for PoseidonSyscallError {
fn from(error: u64) -> Self {
match error {
Expand Down Expand Up @@ -84,19 +85,23 @@ impl Hasher for Poseidon {
Self::hashv(&[val])
}

fn hashv(vals: &[&[u8]]) -> Result<Hash, HasherError> {
fn hashv(_vals: &[&[u8]]) -> Result<Hash, HasherError> {
// 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::<Fr>::new_circom(vals.len())?;
let res = hasher.hash_bytes_be(vals)?;
let mut hasher = Poseidon::<Fr>::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")]
{
Expand All @@ -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,
)
};
Expand Down
2 changes: 1 addition & 1 deletion program-libs/indexed-array/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion program-libs/indexed-merkle-tree/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion program-tests/account-compression-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion program-tests/batched-merkle-tree-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion program-tests/create-address-test-program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion program-tests/registry-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Loading
Loading