Skip to content

Commit 8f9e743

Browse files
wip
1 parent f9f0646 commit 8f9e743

File tree

17 files changed

+391
-294
lines changed

17 files changed

+391
-294
lines changed

program-libs/ctoken-types/src/instructions/create_compressed_mint.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ pub struct CompressedMintWithContext {
3838
pub mint: CompressedMintInstructionData,
3939
}
4040

41+
// /// Anchor-compatible version of CompressedMintWithContext without ZeroCopy derive
42+
// #[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize)]
43+
// pub struct CompressedMintWithContextAnchor {
44+
// pub leaf_index: u32,
45+
// pub prove_by_index: bool,
46+
// pub root_index: u16,
47+
// pub address: [u8; 32],
48+
// pub mint: CompressedMintInstructionDataAnchor,
49+
// }
50+
4151
#[derive(Debug, PartialEq, Eq, Clone, AnchorSerialize, AnchorDeserialize, ZeroCopy)]
4252
pub struct CompressedMintInstructionData {
4353
/// Version for upgradability
@@ -60,6 +70,56 @@ pub struct CompressedMintInstructionData {
6070
pub extensions: Option<Vec<ExtensionInstructionData>>,
6171
}
6272

73+
// /// Anchor-compatible version of CompressedMintInstructionData without ZeroCopy derive
74+
// /// Note: extensions field is omitted to avoid serialization issues
75+
// #[derive(Debug, PartialEq, Eq, Clone, AnchorSerialize, AnchorDeserialize)]
76+
// pub struct CompressedMintInstructionDataAnchor {
77+
// /// Version for upgradability
78+
// pub version: u8,
79+
// /// Pda with seed address of compressed mint
80+
// pub spl_mint: Pubkey,
81+
// /// Total supply of tokens.
82+
// pub supply: u64,
83+
// /// Number of base 10 digits to the right of the decimal place.
84+
// pub decimals: u8,
85+
// /// Extension, necessary for mint to.
86+
// pub is_decompressed: bool,
87+
// /// Optional authority used to mint new tokens. The mint authority may only
88+
// /// be provided during mint creation. If no mint authority is present
89+
// /// then the mint has a fixed supply and no further tokens may be
90+
// /// minted.
91+
// pub mint_authority: Option<Pubkey>,
92+
// /// Optional authority to freeze token accounts.
93+
// pub freeze_authority: Option<Pubkey>,
94+
// }
95+
96+
// impl From<CompressedMintInstructionDataAnchor> for CompressedMintInstructionData {
97+
// fn from(anchor_data: CompressedMintInstructionDataAnchor) -> Self {
98+
// Self {
99+
// version: anchor_data.version,
100+
// spl_mint: anchor_data.spl_mint,
101+
// supply: anchor_data.supply,
102+
// decimals: anchor_data.decimals,
103+
// is_decompressed: anchor_data.is_decompressed,
104+
// mint_authority: anchor_data.mint_authority,
105+
// freeze_authority: anchor_data.freeze_authority,
106+
// extensions: None, // Extensions not supported in Anchor-compatible version
107+
// }
108+
// }
109+
// // }
110+
111+
// impl From<CompressedMintWithContextAnchor> for CompressedMintWithContext {
112+
// fn from(anchor_context: CompressedMintWithContextAnchor) -> Self {
113+
// Self {
114+
// leaf_index: anchor_context.leaf_index,
115+
// prove_by_index: anchor_context.prove_by_index,
116+
// root_index: anchor_context.root_index,
117+
// address: anchor_context.address,
118+
// mint: anchor_context.mint.into(),
119+
// }
120+
// }
121+
// }
122+
63123
impl TryFrom<CompressedMint> for CompressedMintInstructionData {
64124
type Error = CTokenError;
65125

program-tests/sdk-token-test/tests/pda_ctoken.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use light_ctoken_types::{
2020
},
2121
state::extensions::{AdditionalMetadata, Metadata},
2222
COMPRESSED_TOKEN_PROGRAM_ID,
23-
};ompressed mint created
23+
};
2424
use light_program_test::{LightProgramTest, ProgramTestConfig, Rpc, RpcError};
2525

2626
use anchor_lang::solana_program::program_pack::Pack;

prover/server/prover/proving_keys_utils.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ func GetKeys(keysDir string, runMode RunMode, circuits []string) []string {
157157
keysDir + "non-inclusion_26_2.key",
158158
keysDir + "non-inclusion_40_1.key",
159159
keysDir + "non-inclusion_40_2.key",
160+
keysDir + "non-inclusion_40_3.key",
160161
}
161162

162163
var appendKeys []string = []string{

sdk-libs/compressed-token-sdk/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition = { workspace = true }
55

66
[features]
77

8-
anchor = ["anchor-lang", "light-compressed-token-types/anchor"]
8+
anchor = ["anchor-lang", "light-compressed-token-types/anchor", "light-ctoken-types/anchor"]
99

1010
[dependencies]
1111
# Light Protocol dependencies

sdk-libs/light-compressible-client/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ impl CompressibleInstruction {
301301
// Setup remaining accounts to get tree infos
302302
let mut remaining_accounts = PackedAccounts::default();
303303
let system_config = SystemAccountMetaConfig::new(*program_id);
304+
304305
let _ = remaining_accounts.add_system_accounts_small(system_config);
305306

306307
for pda in solana_accounts {

sdk-libs/program-test/src/indexer/test_indexer.rs

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ impl Indexer for TestIndexer {
552552
#[cfg(debug_assertions)]
553553
{
554554
if std::env::var("RUST_BACKTRACE").is_ok() {
555-
println!("get_validit_proof: rpc_result {:?}", rpc_result);
555+
println!("get_validity_proof: rpc_result {:?}", rpc_result);
556556
}
557557
}
558558

@@ -2015,14 +2015,14 @@ impl TestIndexer {
20152015
"address_merkle_tree_pubkeys[i]: {:?}",
20162016
address_merkle_tree_pubkeys[i]
20172017
);
2018-
println!("address_merkle_trees: {:?}", self.address_merkle_trees);
2018+
// println!("address_merkle_trees: {:?}", self.address_merkle_trees);
20192019
let address_tree = self
20202020
.address_merkle_trees
20212021
.iter()
20222022
.find(|x| x.accounts.merkle_tree == address_merkle_tree_pubkeys[i])
20232023
.unwrap();
20242024
// TODO: Remove after debugging.
2025-
println!("address_tree: {:?}", address_tree);
2025+
// println!("address_tree: {:?}", address_tree);
20262026
tree_heights.push(address_tree.height());
20272027

20282028
let proof_inputs = address_tree.get_non_inclusion_proof_inputs(address)?;
@@ -2275,28 +2275,47 @@ impl TestIndexer {
22752275
.body(json_payload.clone())
22762276
.send()
22772277
.await;
2278-
if let Ok(response_result) = response_result {
2279-
if response_result.status().is_success() {
2280-
let body = response_result.text().await.unwrap();
2281-
let proof_json = deserialize_gnark_proof_json(&body).unwrap();
2282-
let (proof_a, proof_b, proof_c) = proof_from_json_struct(proof_json);
2283-
let (proof_a, proof_b, proof_c) =
2284-
compress_proof(&proof_a, &proof_b, &proof_c);
2285-
return Ok(ValidityProofWithContext {
2286-
accounts: account_proof_inputs,
2287-
addresses: address_proof_inputs,
2288-
proof: CompressedProof {
2289-
a: proof_a,
2290-
b: proof_b,
2291-
c: proof_c,
2292-
}
2293-
.into(),
2294-
});
2278+
2279+
match response_result {
2280+
Ok(resp) => {
2281+
let status = resp.status();
2282+
if status.is_success() {
2283+
let body = resp.text().await.unwrap();
2284+
let proof_json = deserialize_gnark_proof_json(&body).unwrap();
2285+
let (proof_a, proof_b, proof_c) = proof_from_json_struct(proof_json);
2286+
let (proof_a, proof_b, proof_c) =
2287+
compress_proof(&proof_a, &proof_b, &proof_c);
2288+
return Ok(ValidityProofWithContext {
2289+
accounts: account_proof_inputs,
2290+
addresses: address_proof_inputs,
2291+
proof: CompressedProof {
2292+
a: proof_a,
2293+
b: proof_b,
2294+
c: proof_c,
2295+
}
2296+
.into(),
2297+
});
2298+
}
2299+
2300+
// Non-success HTTP response. Read body for diagnostics and decide whether to retry.
2301+
let body = resp.text().await.unwrap_or_default();
2302+
// Fail fast on 4xx (client errors are usually non-retryable: bad params or missing circuit)
2303+
if status.is_client_error() {
2304+
return Err(IndexerError::CustomError(format!(
2305+
"Prover client error {}: {}",
2306+
status, body
2307+
)));
2308+
}
2309+
// Otherwise, treat as transient and backoff
2310+
println!("Prover non-success {}: {}", status, body);
2311+
retries -= 1;
2312+
tokio::time::sleep(Duration::from_secs(5)).await;
2313+
}
2314+
Err(err) => {
2315+
println!("Request error: {:?}", err);
2316+
retries -= 1;
2317+
tokio::time::sleep(Duration::from_secs(5)).await;
22952318
}
2296-
} else {
2297-
println!("Error: {:#?}", response_result);
2298-
tokio::time::sleep(Duration::from_secs(5)).await;
2299-
retries -= 1;
23002319
}
23012320
}
23022321
Err(IndexerError::CustomError(

sdk-libs/sdk-types/src/cpi_accounts_small.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ use crate::{
77

88
#[repr(usize)]
99
pub enum CompressionCpiAccountIndexSmall {
10-
LightSystemProgram,
11-
Authority, // index 0 - Cpi authority of the custom program, used to invoke the light system program.
12-
RegisteredProgramPda, // index 1 - registered_program_pda
13-
AccountCompressionAuthority, // index 2 - account_compression_authority
14-
AccountCompressionProgram, // index 3 - account_compression_program
15-
SystemProgram, // index 4 - system_program
16-
SolPoolPda, // index 5 - Optional
17-
DecompressionRecipient, // index 6 - Optional
18-
CpiContext, // index 7 - Optional
10+
LightSystemProgram, // index 0 - hardcoded in cpi hence no getter.
11+
Authority, // index 1 - Cpi authority of the custom program, used to invoke the light system program.
12+
RegisteredProgramPda, // index 2 - registered_program_pda
13+
AccountCompressionAuthority, // index 3 - account_compression_authority
14+
AccountCompressionProgram, // index 4 - account_compression_program
15+
SystemProgram, // index 5 - system_program
16+
SolPoolPda, // index 6 - Optional
17+
DecompressionRecipient, // index 7 - Optional
18+
CpiContext, // index 8 - Optional
1919
}
2020

2121
pub const PROGRAM_ACCOUNTS_LEN: usize = 0; // No program accounts in CPI

sdk-libs/sdk-types/src/instruction/tree_info.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
use light_account_checks::AccountInfoTrait;
2-
use light_compressed_account::instruction_data::data::NewAddressParamsPacked;
2+
use light_compressed_account::instruction_data::data::{
3+
NewAddressParamsAssignedPacked, NewAddressParamsPacked,
4+
};
35

4-
use crate::{AnchorDeserialize, AnchorSerialize, CpiAccounts, CpiAccountsSmall};
6+
#[cfg(feature = "v2")]
7+
use crate::CpiAccountsSmall;
8+
9+
use crate::{AnchorDeserialize, AnchorSerialize, CpiAccounts};
510

611
#[derive(Debug, Clone, Copy, AnchorDeserialize, AnchorSerialize, PartialEq, Default)]
712
pub struct PackedStateTreeInfo {
@@ -29,6 +34,23 @@ impl PackedAddressTreeInfo {
2934
}
3035
}
3136

37+
#[cfg(feature = "v2")]
38+
pub fn into_new_address_params_assigned_packed(
39+
self,
40+
seed: [u8; 32],
41+
assigned_to_account: bool,
42+
assigned_account_index: Option<u8>,
43+
) -> NewAddressParamsAssignedPacked {
44+
NewAddressParamsAssignedPacked {
45+
address_merkle_tree_account_index: self.address_merkle_tree_pubkey_index,
46+
address_queue_account_index: self.address_queue_pubkey_index,
47+
address_merkle_tree_root_index: self.root_index,
48+
seed,
49+
assigned_to_account,
50+
assigned_account_index: assigned_account_index.unwrap_or_default(),
51+
}
52+
}
53+
3254
pub fn get_tree_pubkey<T: AccountInfoTrait + Clone>(
3355
&self,
3456
cpi_accounts: &CpiAccounts<'_, T>,
@@ -38,6 +60,7 @@ impl PackedAddressTreeInfo {
3860
Ok(account.pubkey())
3961
}
4062

63+
#[cfg(feature = "v2")]
4164
pub fn get_tree_pubkey_small<T: AccountInfoTrait + Clone>(
4265
&self,
4366
cpi_accounts: &CpiAccountsSmall<'_, T>,

sdk-libs/sdk/src/compressible/compress_account_on_init.rs

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use anchor_lang::{
33
AccountsClose,
44
{prelude::Account, AccountDeserialize, AccountSerialize},
55
};
6+
#[cfg(feature = "anchor")]
7+
use light_compressed_account::instruction_data::data::NewAddressParamsAssignedPacked;
68
use light_hasher::DataHasher;
79
use solana_account_info::AccountInfo;
810
use solana_msg::msg;
@@ -29,7 +31,7 @@ use anchor_lang::Key;
2931
pub fn compress_account_on_init<'info, A>(
3032
solana_account: &mut Account<'info, A>,
3133
address: &[u8; 32],
32-
new_address_param: &PackedNewAddressParams,
34+
new_address_param: &NewAddressParamsAssignedPacked,
3335
output_state_tree_index: u8,
3436
cpi_accounts: CpiAccountsSmall<'_, 'info>,
3537
address_space: &[Pubkey],
@@ -49,7 +51,7 @@ where
4951
{
5052
let mut solana_accounts: [&mut Account<'info, A>; 1] = [solana_account];
5153
let addresses: [[u8; 32]; 1] = [*address];
52-
let new_address_params: [PackedNewAddressParams; 1] = [*new_address_param];
54+
let new_address_params: [NewAddressParamsAssignedPacked; 1] = [*new_address_param];
5355
let output_state_tree_indices: [u8; 1] = [output_state_tree_index];
5456

5557
let compressed_infos = prepare_accounts_for_compression_on_init(
@@ -62,16 +64,8 @@ where
6264
rent_recipient,
6365
)?;
6466

65-
let cpi_inputs = CpiInputs::new_with_assigned_address(
66-
proof,
67-
compressed_infos,
68-
vec![
69-
light_compressed_account::instruction_data::data::NewAddressParamsAssignedPacked::new(
70-
*new_address_param,
71-
None,
72-
),
73-
],
74-
);
67+
let cpi_inputs =
68+
CpiInputs::new_with_assigned_address(proof, compressed_infos, vec![*new_address_param]);
7569

7670
cpi_inputs.invoke_light_system_program_small(cpi_accounts)?;
7771

@@ -104,7 +98,7 @@ where
10498
pub fn prepare_accounts_for_compression_on_init<'info, A>(
10599
solana_accounts: &mut [&mut Account<'info, A>],
106100
addresses: &[[u8; 32]],
107-
new_address_params: &[PackedNewAddressParams],
101+
new_address_params: &[NewAddressParamsAssignedPacked],
108102
output_state_tree_indices: &[u8],
109103
cpi_accounts: &CpiAccountsSmall<'_, 'info>,
110104
address_space: &[Pubkey],
@@ -210,7 +204,7 @@ where
210204
pub fn compress_empty_account_on_init<'info, A>(
211205
solana_account: &mut Account<'info, A>,
212206
address: &[u8; 32],
213-
new_address_param: &PackedNewAddressParams,
207+
new_address_param: &NewAddressParamsAssignedPacked,
214208
output_state_tree_index: u8,
215209
cpi_accounts: CpiAccountsSmall<'_, 'info>,
216210
address_space: &[Pubkey],
@@ -229,7 +223,7 @@ where
229223
{
230224
let mut solana_accounts: [&mut Account<'info, A>; 1] = [solana_account];
231225
let addresses: [[u8; 32]; 1] = [*address];
232-
let new_address_params: [PackedNewAddressParams; 1] = [*new_address_param];
226+
let new_address_params: [NewAddressParamsAssignedPacked; 1] = [*new_address_param];
233227
let output_state_tree_indices: [u8; 1] = [output_state_tree_index];
234228

235229
let compressed_infos = prepare_empty_compressed_accounts_on_init(
@@ -241,16 +235,8 @@ where
241235
address_space,
242236
)?;
243237

244-
let cpi_inputs = CpiInputs::new_with_assigned_address(
245-
proof,
246-
compressed_infos,
247-
vec![
248-
light_compressed_account::instruction_data::data::NewAddressParamsAssignedPacked::new(
249-
*new_address_param,
250-
None,
251-
),
252-
],
253-
);
238+
let cpi_inputs =
239+
CpiInputs::new_with_assigned_address(proof, compressed_infos, vec![*new_address_param]);
254240

255241
cpi_inputs.invoke_light_system_program_small(cpi_accounts)?;
256242

@@ -284,7 +270,7 @@ where
284270
pub fn prepare_empty_compressed_accounts_on_init<'info, A>(
285271
solana_accounts: &mut [&mut Account<'info, A>],
286272
addresses: &[[u8; 32]],
287-
new_address_params: &[PackedNewAddressParams],
273+
new_address_params: &[NewAddressParamsAssignedPacked],
288274
output_state_tree_indices: &[u8],
289275
cpi_accounts: &CpiAccountsSmall<'_, 'info>,
290276
address_space: &[Pubkey],

sdk-tests/anchor-compressible-derived/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,13 @@ pub mod anchor_compressible_derived {
164164
all_compressed_infos.extend(game_compressed_infos);
165165

166166
// Create CPI inputs with all compressed accounts and new addresses
167-
let cpi_inputs = CpiInputs::new_with_address(
167+
let cpi_inputs = CpiInputs::new_with_assigned_address(
168168
compression_params.proof,
169169
all_compressed_infos,
170-
vec![user_new_address_params, game_new_address_params],
170+
vec![
171+
light_compressed_account::instruction_data::data::NewAddressParamsAssignedPacked::new(user_new_address_params, None),
172+
light_compressed_account::instruction_data::data::NewAddressParamsAssignedPacked::new(game_new_address_params, None),
173+
],
171174
);
172175

173176
// Invoke light system program to create all compressed accounts in one

0 commit comments

Comments
 (0)