Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/light-examples-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- program: sdk-test-program
sub-tests: '["cargo-test-sbf -p sdk-test"]'
- program: sdk-anchor-test-program
sub-tests: '["cargo-test-sbf -p sdk-anchor-test"]'
sub-tests: '["cargo-test-sbf -p sdk-anchor-test", "cargo-test-sbf -p sdk-pinocchio-test"]'

steps:
- name: Checkout sources
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ jobs:
test_cmd: |
cargo test -p aligned-sized
cargo test -p light-bloom-filter
cargo test -p light-hasher
cargo test -p light-compressed-account
cargo test -p light-account-checks
cargo test -p light-hasher --features solana
cargo test -p light-compressed-account --features new-unique
cargo test -p light-account-checks --features solana
cargo test -p light-verifier
cargo test -p light-merkle-tree-metadata
cargo test -p light-zero-copy --features std
Expand Down
37 changes: 32 additions & 5 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ members = [
"sdk-libs/client",
"sdk-libs/macros",
"sdk-libs/sdk",
"sdk-libs/sdk-pinocchio",
"sdk-libs/photon-api",
"sdk-libs/program-test",
"xtask",
Expand All @@ -38,6 +39,7 @@ members = [
# Issue is that anchor discriminator now returns a slice instead of an array
"program-tests/sdk-anchor-test/programs/sdk-anchor-test",
"program-tests/sdk-test",
"program-tests/sdk-pinocchio-test",
"program-tests/create-address-test-program",
"program-tests/utils",
"program-tests/merkle-tree",
Expand Down
15 changes: 5 additions & 10 deletions examples/anchor/counter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub mod counter {
address_tree_info: PackedAddressTreeInfo,
output_state_tree_index: u8,
) -> Result<()> {
let program_id = crate::ID.into();
// LightAccount::new_init will create an account with empty output state (no input state).
// Modifying the account will modify the output state that when converted to_account_info()
// is hashed with poseidon hashes, serialized with borsh
Expand All @@ -49,7 +48,7 @@ pub mod counter {
let new_address_params = address_tree_info.into_new_address_params_packed(address_seed);

let mut counter = LightAccount::<'_, CounterAccount>::new_init(
&program_id,
&crate::ID,
Some(address),
output_state_tree_index,
);
Expand All @@ -74,15 +73,14 @@ pub mod counter {
counter_value: u64,
account_meta: CompressedAccountMeta,
) -> Result<()> {
let program_id = crate::ID.into();
// LightAccount::new_mut will create an account with input state and output state.
// The input state is hashed immediately when calling new_mut().
// Modifying the account will modify the output state that when converted to_account_info()
// is hashed with poseidon hashes, serialized with borsh
// and created with invoke_light_system_program by invoking the light-system-program.
// The hashing scheme is the account structure derived with LightHasher.
let mut counter = LightAccount::<'_, CounterAccount>::new_mut(
&program_id,
&crate::ID,
&account_meta,
CounterAccount {
owner: ctx.accounts.signer.key(),
Expand Down Expand Up @@ -116,9 +114,8 @@ pub mod counter {
counter_value: u64,
account_meta: CompressedAccountMeta,
) -> Result<()> {
let program_id = crate::ID.into();
let mut counter = LightAccount::<'_, CounterAccount>::new_mut(
&program_id,
&crate::ID,
&account_meta,
CounterAccount {
owner: ctx.accounts.signer.key(),
Expand Down Expand Up @@ -158,9 +155,8 @@ pub mod counter {
counter_value: u64,
account_meta: CompressedAccountMeta,
) -> Result<()> {
let program_id = crate::ID.into();
let mut counter = LightAccount::<'_, CounterAccount>::new_mut(
&program_id,
&crate::ID,
&account_meta,
CounterAccount {
owner: ctx.accounts.signer.key(),
Expand Down Expand Up @@ -195,12 +191,11 @@ pub mod counter {
counter_value: u64,
account_meta: CompressedAccountMetaClose,
) -> Result<()> {
let program_id = crate::ID.into();
// LightAccount::new_close() will create an account with only input state and no output state.
// By providing no output state the account is closed after the instruction.
// The address of a closed account cannot be reused.
let counter = LightAccount::<'_, CounterAccount>::new_close(
&program_id,
&crate::ID,
&account_meta,
CounterAccount {
owner: ctx.accounts.signer.key(),
Expand Down
2 changes: 1 addition & 1 deletion examples/anchor/counter/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// #![cfg(feature = "test-sbf")]
#![cfg(feature = "test-sbf")]

use anchor_lang::{AnchorDeserialize, InstructionData, ToAccountMetas};
use counter::CounterAccount;
Expand Down
1 change: 1 addition & 0 deletions examples/anchor/token-escrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ light-compressed-account = { workspace = true, features = ["anchor"] }

[target.'cfg(not(target_os = "solana"))'.dependencies]
solana-sdk = { workspace = true }
light-test-utils = { workspace = true, features = ["devenv"] }

[dev-dependencies]
light-verifier = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,18 @@ fn create_compressed_pda_data(
let compressed_account_data = CompressedAccountData {
discriminator: 1u64.to_le_bytes(),
data: timelock_compressed_pda.try_to_vec().unwrap(),
data_hash: timelock_compressed_pda
.hash::<Poseidon>()
.map_err(ProgramError::from)?,
data_hash: timelock_compressed_pda.hash::<Poseidon>().unwrap(),
};
let derive_address = derive_address_legacy(
&ctx.remaining_accounts[new_address_params.address_merkle_tree_account_index as usize]
.key(),
.key()
.into(),
&new_address_params.seed,
)
.map_err(|_| ProgramError::InvalidArgument)?;
Ok(OutputCompressedAccountWithPackedContext {
compressed_account: CompressedAccount {
owner: crate::ID,
owner: crate::ID.into(),
lamports: 0,
address: Some(derive_address),
data: Some(compressed_account_data),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

use anchor_lang::{InstructionData, ToAccountMetas};
use light_compressed_account::{
address::{add_and_get_remaining_account_indices, pack_new_address_params},
compressed_account::{pack_merkle_context, CompressedAccount, MerkleContext},
compressed_account::{CompressedAccount, MerkleContext},
instruction_data::{
compressed_proof::CompressedProof, cpi_context::CompressedCpiContext,
data::NewAddressParams,
Expand All @@ -14,6 +13,9 @@ use light_compressed_token::process_transfer::{
transfer_sdk::{create_inputs_and_remaining_accounts_checked, to_account_metas},
TokenTransferOutputData,
};
use light_test_utils::pack::{
add_and_get_remaining_account_indices, pack_merkle_context, pack_new_address_params,
};
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};

use crate::escrow_with_compressed_pda::escrow::PackedInputCompressedPda;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,11 @@ fn create_compressed_pda_data_based_on_diff(
let old_compressed_account_data = CompressedAccountData {
discriminator: 1u64.to_le_bytes(),
data: old_timelock_compressed_pda.try_to_vec().unwrap(),
data_hash: old_timelock_compressed_pda
.hash::<Poseidon>()
.map_err(ProgramError::from)?,
data_hash: old_timelock_compressed_pda.hash::<Poseidon>().unwrap(),
};
let old_compressed_account = OutputCompressedAccountWithPackedContext {
compressed_account: CompressedAccount {
owner: crate::ID,
owner: crate::ID.into(),
lamports: 0,
address: Some(input_compressed_pda.address),
data: Some(old_compressed_account_data),
Expand All @@ -110,13 +108,11 @@ fn create_compressed_pda_data_based_on_diff(
let new_compressed_account_data = CompressedAccountData {
discriminator: 1u64.to_le_bytes(),
data: new_timelock_compressed_pda.try_to_vec().unwrap(),
data_hash: new_timelock_compressed_pda
.hash::<Poseidon>()
.map_err(ProgramError::from)?,
data_hash: new_timelock_compressed_pda.hash::<Poseidon>().unwrap(),
};
let new_state = OutputCompressedAccountWithPackedContext {
compressed_account: CompressedAccount {
owner: crate::ID,
owner: crate::ID.into(),
lamports: 0,
address: Some(input_compressed_pda.address),
data: Some(new_compressed_account_data),
Expand Down Expand Up @@ -171,7 +167,7 @@ fn cpi_compressed_pda_withdrawal<'info>(
},
)
.unwrap();
verify_borsh(&light_accounts, &inputs_struct).map_err(ProgramError::from)?;
verify_borsh(&light_accounts, &inputs_struct).unwrap();

Ok(())
}
Expand Down
6 changes: 4 additions & 2 deletions examples/anchor/token-escrow/src/escrow_with_pda/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use anchor_lang::{InstructionData, ToAccountMetas};
use light_compressed_account::{
address::add_and_get_remaining_account_indices,
compressed_account::{CompressedAccount, MerkleContext},
instruction_data::compressed_proof::CompressedProof,
};
Expand All @@ -14,6 +13,7 @@ use light_compressed_token::process_transfer::{
},
TokenTransferOutputData,
};
use light_test_utils::pack::add_and_get_remaining_account_indices;
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};

use crate::escrow_with_compressed_pda::sdk::get_token_owner_pda;
Expand Down Expand Up @@ -133,7 +133,9 @@ pub fn create_withdrawal_escrow_instruction(
);

let merkle_tree_indices = add_and_get_remaining_account_indices(
input_params.output_compressed_account_merkle_tree_pubkeys,
input_params.output_compressed_account_merkle_tree_pubkeys, // .iter()
// .map(|pubkey| anchor_lang::prelude::Pubkey::from(pubkey))
// .collect::<Vec<_>>()
&mut remaining_accounts,
);

Expand Down
8 changes: 4 additions & 4 deletions examples/anchor/token-escrow/tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ pub async fn perform_escrow(
leaf_index: compressed_input_account_with_context
.merkle_context
.leaf_index,
merkle_tree_pubkey: env.v1_state_trees[0].merkle_tree,
queue_pubkey: env.v1_state_trees[0].nullifier_queue,
merkle_tree_pubkey: env.v1_state_trees[0].merkle_tree.into(),
queue_pubkey: env.v1_state_trees[0].nullifier_queue.into(),
prove_by_index: false,
tree_type: TreeType::StateV1,
}],
Expand Down Expand Up @@ -331,8 +331,8 @@ pub async fn perform_withdrawal(
leaf_index: compressed_input_account_with_context
.merkle_context
.leaf_index,
merkle_tree_pubkey: env.v1_state_trees[0].merkle_tree,
queue_pubkey: env.v1_state_trees[0].nullifier_queue,
merkle_tree_pubkey: env.v1_state_trees[0].merkle_tree.into(),
queue_pubkey: env.v1_state_trees[0].nullifier_queue.into(),
prove_by_index: false,
tree_type: TreeType::StateV1,
}],
Expand Down
Loading
Loading