Skip to content

Commit 9a9d9d0

Browse files
author
tilo-14
committed
fmt
1 parent b06a90f commit 9a9d9d0

6 files changed

Lines changed: 186 additions & 53 deletions

File tree

scripts/format.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ cargo +nightly fmt --manifest-path counter/anchor/Cargo.toml
88
cargo +nightly fmt --manifest-path counter/native/Cargo.toml
99
cargo +nightly fmt --manifest-path counter/pinocchio/Cargo.toml
1010
cargo +nightly fmt --manifest-path account-comparison/Cargo.toml
11+
cargo +nightly fmt --manifest-path zk/nullifier/Cargo.toml
12+
cargo +nightly fmt --manifest-path zk/zk-id/Cargo.toml
1113

1214
# Run clippy on each project individually
1315
cargo clippy --manifest-path create-and-update/Cargo.toml \
@@ -59,3 +61,23 @@ cargo clippy --manifest-path account-comparison/Cargo.toml \
5961
-A unexpected-cfgs \
6062
-A clippy::doc_lazy_continuation \
6163
-D warnings
64+
65+
cargo clippy --manifest-path zk/nullifier/Cargo.toml \
66+
--no-deps \
67+
--all-features \
68+
-- -A clippy::result_large_err \
69+
-A clippy::empty-docs \
70+
-A clippy::to-string-trait-impl \
71+
-A unexpected-cfgs \
72+
-A clippy::doc_lazy_continuation \
73+
-D warnings
74+
75+
cargo clippy --manifest-path zk/zk-id/Cargo.toml \
76+
--no-deps \
77+
--all-features \
78+
-- -A clippy::result_large_err \
79+
-A clippy::empty-docs \
80+
-A clippy::to-string-trait-impl \
81+
-A unexpected-cfgs \
82+
-A clippy::doc_lazy_continuation \
83+
-D warnings

scripts/lint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ cd counter/pinocchio && cargo fmt --check && cd ../..
2020
echo "Checking account-comparison..."
2121
cd account-comparison && cargo fmt --check && cd ..
2222

23+
echo "Checking zk/nullifier..."
24+
cd zk/nullifier && cargo fmt --check && cd ../..
25+
26+
echo "Checking zk/zk-id..."
27+
cd zk/zk-id && cargo fmt --check && cd ../..
28+
2329
echo "Running clippy..."
2430

2531
# Run clippy for each crate
@@ -38,4 +44,10 @@ cargo clippy --manifest-path counter/pinocchio/Cargo.toml --all-targets --all-fe
3844
echo "Running clippy on account-comparison..."
3945
cargo clippy --manifest-path account-comparison/Cargo.toml --all-targets --all-features -- -D warnings
4046

47+
echo "Running clippy on zk/nullifier..."
48+
cargo clippy --manifest-path zk/nullifier/Cargo.toml --all-targets --all-features -- -D warnings
49+
50+
echo "Running clippy on zk/zk-id..."
51+
cargo clippy --manifest-path zk/zk-id/Cargo.toml --all-targets --all-features -- -D warnings
52+
4153
echo "Lint checks completed successfully!"

zk/nullifier/programs/nullifier/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
use anchor_lang::prelude::*;
55
use nullifier_creation::{create_nullifiers, NullifierInstructionData};
66

7-
87
declare_id!("Bw8aty8LJY5Kg2b6djghjWGwt6cBc1tVQUoreUehvVq4");
98

10-
119
#[program]
1210
pub mod nullifier {
1311
use super::*;
@@ -44,9 +42,6 @@ pub struct CreateNullifierAccounts<'info> {
4442
pub signer: Signer<'info>,
4543
}
4644

47-
48-
49-
5045
pub mod nullifier_creation {
5146
use super::*;
5247
use borsh::{BorshDeserialize, BorshSerialize};
@@ -66,7 +61,6 @@ pub mod nullifier_creation {
6661
AccountNotEnoughKeys,
6762
}
6863

69-
7064
#[derive(Clone, Debug, Default, BorshSerialize, BorshDeserialize, LightDiscriminator)]
7165
pub struct NullifierAccount {}
7266

@@ -142,4 +136,4 @@ pub mod nullifier_creation {
142136

143137
Ok(())
144138
}
145-
}
139+
}

zk/nullifier/programs/nullifier/tests/test.rs

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use anchor_lang::{InstructionData, ToAccountMetas};
2-
use light_program_test::{program_test::LightProgramTest, Indexer, ProgramTestConfig, Rpc, RpcError};
3-
use solana_sdk::{instruction::Instruction, pubkey::Pubkey, signature::Signer};
2+
use light_program_test::{
3+
program_test::LightProgramTest, Indexer, ProgramTestConfig, Rpc, RpcError,
4+
};
45
use nullifier::nullifier_creation::NullifierInstructionData;
6+
use solana_sdk::{instruction::Instruction, pubkey::Pubkey, signature::Signer};
57

68
#[tokio::test]
79
async fn test_create_single_nullifier() {
@@ -11,12 +13,10 @@ async fn test_create_single_nullifier() {
1113

1214
let nullifier = Pubkey::new_unique().to_bytes();
1315

14-
let (data, remaining_accounts) = build_create_nullifier_instruction_data(
15-
&mut rpc,
16-
&[nullifier],
17-
)
18-
.await
19-
.unwrap();
16+
let (data, remaining_accounts) =
17+
build_create_nullifier_instruction_data(&mut rpc, &[nullifier])
18+
.await
19+
.unwrap();
2020

2121
let instruction_data = nullifier::instruction::CreateNullifier {
2222
data,
@@ -38,12 +38,10 @@ async fn test_create_single_nullifier() {
3838
assert_nullifiers_exist(&mut rpc, &[nullifier]).await;
3939

4040
// Duplicate should fail
41-
let (dup_data, dup_remaining_accounts) = build_create_nullifier_instruction_data(
42-
&mut rpc,
43-
&[nullifier],
44-
)
45-
.await
46-
.unwrap();
41+
let (dup_data, dup_remaining_accounts) =
42+
build_create_nullifier_instruction_data(&mut rpc, &[nullifier])
43+
.await
44+
.unwrap();
4745

4846
let dup_instruction_data = nullifier::instruction::CreateNullifier {
4947
data: dup_data,
@@ -72,12 +70,9 @@ async fn test_create_multiple_nullifiers() {
7270

7371
let nullifiers: Vec<[u8; 32]> = (0..3).map(|_| Pubkey::new_unique().to_bytes()).collect();
7472

75-
let (data, remaining_accounts) = build_create_nullifier_instruction_data(
76-
&mut rpc,
77-
&nullifiers,
78-
)
79-
.await
80-
.unwrap();
73+
let (data, remaining_accounts) = build_create_nullifier_instruction_data(&mut rpc, &nullifiers)
74+
.await
75+
.unwrap();
8176

8277
let instruction_data = nullifier::instruction::CreateNullifier {
8378
data,
@@ -132,12 +127,21 @@ where
132127
async fn build_create_nullifier_instruction_data<R>(
133128
rpc: &mut R,
134129
nullifiers: &[[u8; 32]],
135-
) -> Result<(NullifierInstructionData, Vec<solana_sdk::instruction::AccountMeta>), RpcError>
130+
) -> Result<
131+
(
132+
NullifierInstructionData,
133+
Vec<solana_sdk::instruction::AccountMeta>,
134+
),
135+
RpcError,
136+
>
136137
where
137138
R: Rpc + Indexer,
138139
{
139140
use light_program_test::AddressWithTree;
140-
use light_sdk::{address::v2::derive_address, instruction::{PackedAccounts, SystemAccountMetaConfig}};
141+
use light_sdk::{
142+
address::v2::derive_address,
143+
instruction::{PackedAccounts, SystemAccountMetaConfig},
144+
};
141145
use nullifier::nullifier_creation::NULLIFIER_PREFIX;
142146

143147
let address_tree_info = rpc.get_address_tree_v2();
@@ -174,7 +178,8 @@ where
174178
.get_random_state_tree_info()?
175179
.pack_output_tree_index(&mut remaining_accounts)?;
176180

177-
let (remaining_accounts_metas, system_accounts_offset, _) = remaining_accounts.to_account_metas();
181+
let (remaining_accounts_metas, system_accounts_offset, _) =
182+
remaining_accounts.to_account_metas();
178183

179184
let data = NullifierInstructionData {
180185
proof: rpc_result.proof,

zk/zk-id/programs/zk-id/src/lib.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,17 @@ pub mod zk_id {
8585

8686
LightSystemProgramCpi::new_cpi(LIGHT_CPI_SIGNER, proof)
8787
.with_light_account(issuer_account)?
88-
.with_new_addresses(&[address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0))])
88+
.with_new_addresses(&[
89+
address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0))
90+
])
8991
.invoke(light_cpi_accounts)?;
9092

9193
Ok(())
9294
}
9395

9496
/// Creates a new credential compressed account storing a pubkey
9597
/// Requires a valid issuer account - only the issuer can create credentials
98+
#[allow(clippy::too_many_arguments)]
9699
pub fn add_credential<'info>(
97100
ctx: Context<'_, '_, '_, 'info, GenericAnchorAccounts<'info>>,
98101
proof: ValidityProof,
@@ -158,13 +161,16 @@ pub mod zk_id {
158161
LightSystemProgramCpi::new_cpi(LIGHT_CPI_SIGNER, proof)
159162
.with_light_account(issuer_account)?
160163
.with_light_account_poseidon(credential_account)?
161-
.with_new_addresses(&[address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(1))])
164+
.with_new_addresses(&[
165+
address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(1))
166+
])
162167
.invoke(light_cpi_accounts)?;
163168

164169
Ok(())
165170
}
166171

167172
/// Verifies a ZK proof of credential ownership and creates an encrypted event account.
173+
#[allow(clippy::too_many_arguments)]
168174
pub fn zk_verify_credential<'info>(
169175
ctx: Context<'_, '_, '_, 'info, VerifyAccounts<'info>>,
170176
proof: ValidityProof,
@@ -206,8 +212,7 @@ pub mod zk_id {
206212
let expected_root = read_state_merkle_tree_root(
207213
&ctx.accounts.input_merkle_tree.to_account_info(),
208214
input_root_index,
209-
)
210-
.map_err(|e| ProgramError::from(e))?;
215+
)?;
211216

212217
let merkle_tree_pubkey = ctx.accounts.input_merkle_tree.key();
213218
let merkle_tree_hashed =
@@ -232,8 +237,8 @@ pub mod zk_id {
232237
let mut hash_input = Vec::new();
233238
hash_input.extend_from_slice(&(event_account.data.len() as u32).to_le_bytes());
234239
hash_input.extend_from_slice(&event_account.data);
235-
let mut event_data_hash = Sha256::hash(&hash_input)
236-
.map_err(|_| ProgramError::InvalidAccountData)?;
240+
let mut event_data_hash =
241+
Sha256::hash(&hash_input).map_err(|_| ProgramError::InvalidAccountData)?;
237242
event_data_hash[0] = 0; // Ensure hash is in BN254 field
238243

239244
{
@@ -289,7 +294,9 @@ pub mod zk_id {
289294
}
290295
LightSystemProgramCpi::new_cpi(LIGHT_CPI_SIGNER, proof)
291296
.with_light_account(event_account)?
292-
.with_new_addresses(&[address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0))])
297+
.with_new_addresses(&[
298+
address_tree_info.into_new_address_params_assigned_packed(address_seed, Some(0))
299+
])
293300
.invoke(light_cpi_accounts)?;
294301

295302
Ok(())

0 commit comments

Comments
 (0)