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
5 changes: 1 addition & 4 deletions Cargo.lock

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

16 changes: 16 additions & 0 deletions program-libs/compressed-account/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ use light_hasher::hash_to_field_size::hashv_to_bn254_field_size_be_const_array;

use crate::{CompressedAccountError, Pubkey};

/// A seed used to derive compressed account addresses.
#[derive(Debug, PartialEq, Clone, Copy)]
pub struct AddressSeed(pub [u8; 32]);

impl From<[u8; 32]> for AddressSeed {
fn from(value: [u8; 32]) -> Self {
AddressSeed(value)
}
}

impl From<AddressSeed> for [u8; 32] {
fn from(address_seed: AddressSeed) -> Self {
address_seed.0
}
}

pub fn derive_address_legacy(
merkle_tree_pubkey: &Pubkey,
seed: &[u8; 32],
Expand Down
11 changes: 10 additions & 1 deletion program-libs/compressed-account/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
use light_macros::pubkey_array;

/// ID of the account-compression program.
pub const ACCOUNT_COMPRESSION_PROGRAM_ID: [u8; 32] =
pubkey_array!("compr6CUsB5m2jS4Y3831ztGSTnDpnKJTKS95d64XVq");
pub const SYSTEM_PROGRAM_ID: [u8; 32] =
/// ID of the light-system program.
pub const LIGHT_SYSTEM_PROGRAM_ID: [u8; 32] =
pubkey_array!("SySTEM1eSU2p4BGQfQpimFEWWSC1XDFeun3Nqzz3rT7");
#[deprecated(since = "0.9.0", note = "Use LIGHT_SYSTEM_PROGRAM_ID instead")]
pub const SYSTEM_PROGRAM_ID: [u8; 32] = LIGHT_SYSTEM_PROGRAM_ID;
pub const REGISTERED_PROGRAM_PDA: [u8; 32] =
pubkey_array!("35hkDgaAKwMCaxRz2ocSZ6NaUrtKkyNqU6c4RV3tYJRh");
pub const ACCOUNT_COMPRESSION_AUTHORITY_PDA: [u8; 32] =
pubkey_array!("HwXnGK3tPkkVY6P439H2p68AxpeuWXd5PcrAxFpbmfbA");
/// Seed of the CPI authority.
pub const CPI_AUTHORITY_PDA_SEED: &[u8] = b"cpi_authority";

pub const CREATE_CPI_CONTEXT_ACCOUNT: [u8; 8] = [233, 112, 71, 66, 121, 33, 178, 188];

pub const ADDRESS_MERKLE_TREE_ACCOUNT_DISCRIMINATOR: [u8; 8] = [11, 161, 175, 9, 212, 229, 73, 73];
Expand Down
47 changes: 47 additions & 0 deletions program-libs/compressed-account/src/instruction_data/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,53 @@ impl NewAddressParamsAssignedPacked {
}
}

/// Packed address tree info for instruction data.
/// Contains indices to address tree accounts and root index.
#[repr(C)]
#[cfg_attr(
all(feature = "std", feature = "anchor"),
derive(anchor_lang::AnchorDeserialize, anchor_lang::AnchorSerialize)
)]
#[cfg_attr(
not(feature = "anchor"),
derive(borsh::BorshDeserialize, borsh::BorshSerialize)
)]
#[derive(Debug, Clone, Copy, PartialEq, Default, ZeroCopyMut, light_zero_copy::ZeroCopy)]
pub struct PackedAddressTreeInfo {
pub address_merkle_tree_pubkey_index: u8,
pub address_queue_pubkey_index: u8,
pub root_index: u16,
}

impl PackedAddressTreeInfo {
pub fn into_new_address_params_packed(
self,
seed: crate::address::AddressSeed,
) -> NewAddressParamsPacked {
NewAddressParamsPacked {
address_merkle_tree_account_index: self.address_merkle_tree_pubkey_index,
address_queue_account_index: self.address_queue_pubkey_index,
address_merkle_tree_root_index: self.root_index,
seed: seed.0,
}
}

pub fn into_new_address_params_assigned_packed(
self,
seed: crate::address::AddressSeed,
assigned_account_index: Option<u8>,
) -> NewAddressParamsAssignedPacked {
NewAddressParamsAssignedPacked {
address_merkle_tree_account_index: self.address_merkle_tree_pubkey_index,
address_queue_account_index: self.address_queue_pubkey_index,
address_merkle_tree_root_index: self.root_index,
seed: seed.0,
assigned_account_index: assigned_account_index.unwrap_or_default(),
assigned_to_account: assigned_account_index.is_some(),
}
}
}

#[cfg_attr(
all(feature = "std", feature = "anchor"),
derive(anchor_lang::AnchorDeserialize, anchor_lang::AnchorSerialize)
Expand Down
3 changes: 1 addition & 2 deletions program-libs/compressible/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ license = "MIT"
[features]
default = ["solana"]
solana = ["dep:solana-program-error", "light-compressed-account/solana", "light-account-checks/solana", "solana-sysvar", "solana-msg"]
anchor = ["anchor-lang", "light-compressed-account/anchor", "light-compressed-account/std", "light-account-checks/solana", "light-sdk-types/anchor"]
anchor = ["anchor-lang", "light-compressed-account/anchor", "light-compressed-account/std", "light-account-checks/solana"]
pinocchio = ["dep:pinocchio", "light-compressed-account/pinocchio", "light-account-checks/pinocchio"]
profile-program = []
profile-heap = ["dep:light-heap"]
Expand All @@ -32,7 +32,6 @@ light-program-profiler = { workspace = true }
light-heap = { workspace = true, optional = true }
light-account-checks = { workspace= true }
light-compressed-account = { workspace= true }
light-sdk-types = { workspace = true, features = ["std"] }
aligned-sized = { workspace= true }
solana-sysvar = {workspace = true, optional = true}

Expand Down
5 changes: 3 additions & 2 deletions program-libs/compressible/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ pub mod rent;
use anchor_lang::{AnchorDeserialize, AnchorSerialize};
#[cfg(not(feature = "anchor"))]
use borsh::{BorshDeserialize as AnchorDeserialize, BorshSerialize as AnchorSerialize};
use light_compressed_account::instruction_data::compressed_proof::ValidityProof;
use light_sdk_types::instruction::PackedAddressTreeInfo;
use light_compressed_account::instruction_data::{
compressed_proof::ValidityProof, data::PackedAddressTreeInfo,
};

/// Proof data for instruction params when creating new compressed accounts.
/// Used in the INIT flow - pass directly to instruction data.
Expand Down
4 changes: 1 addition & 3 deletions programs/compressed-token/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ light-zero-copy = { workspace = true, features = ["mut", "std", "derive"] }
zerocopy = { workspace = true }
anchor-compressed-token = { path = "../anchor", features = ["cpi"] }
light-account-checks = { workspace = true, features = ["solana", "pinocchio", "msg"] }
light-sdk = { workspace = true }
borsh = { workspace = true }
light-sdk-types = { workspace = true }
light-compressible = { workspace = true, features = ["pinocchio"] }
light-macros = { workspace = true }
solana-pubkey = { workspace = true }
arrayvec = { workspace = true }
tinyvec = { workspace = true }
pinocchio = { workspace = true, features = ["std"] }
light-sdk-pinocchio = { workspace = true }
light-token-interface = { workspace = true, features = ["anchor"] }
light-array-map = { workspace = true }
pinocchio-pubkey = { workspace = true }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use anchor_compressed_token::ErrorCode;
use anchor_lang::solana_program::program_error::ProgramError;
use light_compressed_account::Pubkey;
use light_compressed_account::{
instruction_data::data::ZOutputCompressedAccountWithPackedContextMut, Pubkey,
};
use light_program_profiler::profile;
use light_sdk_pinocchio::instruction::ZOutputCompressedAccountWithPackedContextMut;
use light_token_interface::{
hash_cache::HashCache, instructions::mint_action::ZMintToCompressedAction, state::Mint,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use anchor_lang::solana_program::program_error::ProgramError;
use borsh::BorshSerialize;
use light_compressed_account::instruction_data::with_readonly::ZInAccountMut;
use light_compressed_account::{
compressed_account::PackedMerkleContext, instruction_data::with_readonly::ZInAccountMut,
};
use light_hasher::{sha256::Sha256BE, Hasher};
use light_program_profiler::profile;
use light_sdk::instruction::PackedMerkleContext;
use light_token_interface::state::Mint;
use light_zero_copy::U16;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use anchor_compressed_token::{is_idempotent_early_exit, ErrorCode};
use anchor_lang::prelude::ProgramError;
use light_compressed_account::instruction_data::with_readonly::InstructionDataInvokeCpiWithReadOnly;
use light_sdk::instruction::PackedMerkleContext;
use light_compressed_account::{
compressed_account::PackedMerkleContext,
instruction_data::with_readonly::InstructionDataInvokeCpiWithReadOnly,
};
use light_token_interface::{
hash_cache::HashCache, instructions::mint_action::MintActionCompressedInstructionData,
state::Mint, TokenError,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use anchor_compressed_token::ErrorCode;
use anchor_lang::prelude::ProgramError;
use light_account_checks::packed_accounts::ProgramPackedAccounts;
use light_compressed_account::constants::CPI_AUTHORITY_PDA_SEED;
use light_program_profiler::profile;
use light_sdk_types::CPI_AUTHORITY_PDA_SEED;
use light_token_interface::{
instructions::transfer2::{ZCompression, ZCompressionMode},
is_valid_spl_interface_pda,
Expand Down
3 changes: 2 additions & 1 deletion programs/compressed-token/program/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::mem::ManuallyDrop;

use anchor_lang::solana_program::program_error::ProgramError;
use light_sdk::{cpi::CpiSigner, derive_light_cpi_signer};
use light_compressed_account::CpiSigner;
use light_macros::derive_light_cpi_signer;
use light_token_interface::LIGHT_TOKEN_PROGRAM_ID;
use pinocchio::{account_info::AccountInfo, msg};

Expand Down
4 changes: 2 additions & 2 deletions programs/compressed-token/program/src/shared/cpi.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::mem::MaybeUninit;

use anchor_lang::solana_program::program_error::ProgramError;
use light_program_profiler::profile;
use light_sdk_types::{
use light_compressed_account::constants::{
ACCOUNT_COMPRESSION_AUTHORITY_PDA, ACCOUNT_COMPRESSION_PROGRAM_ID, CPI_AUTHORITY_PDA_SEED,
LIGHT_SYSTEM_PROGRAM_ID, REGISTERED_PROGRAM_PDA,
};
use light_program_profiler::profile;
use pinocchio::{
account_info::{AccountInfo, BorrowState},
cpi::{invoke_signed_unchecked, MAX_CPI_ACCOUNTS},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anchor_lang::solana_program::program_error::ProgramError;
use light_compressed_account::constants::CPI_AUTHORITY_PDA_SEED;
use light_program_profiler::profile;
use light_sdk_types::CPI_AUTHORITY_PDA_SEED;
use pinocchio::{
account_info::AccountInfo,
instruction::{AccountMeta, Instruction, Seed, Signer},
Expand Down
2 changes: 1 addition & 1 deletion programs/compressed-token/program/tests/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn test_rnd_create_compressed_mint_account() {
if parsed_instruction_data.create_mint.is_none() {
let input_account = &mut cpi_instruction_struct.input_compressed_accounts[0];

use light_sdk::instruction::PackedMerkleContext;
use light_compressed_account::compressed_account::PackedMerkleContext;
let merkle_context = PackedMerkleContext {
merkle_tree_pubkey_index,
queue_pubkey_index,
Expand Down
6 changes: 3 additions & 3 deletions programs/compressed-token/program/tests/token_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use anchor_lang::prelude::*;
use borsh::{BorshDeserialize, BorshSerialize};
use light_account_checks::account_info::test_account_info::pinocchio::get_account_info;
use light_array_map::ArrayMap;
use light_compressed_account::instruction_data::with_readonly::{
InAccount, InstructionDataInvokeCpiWithReadOnly,
use light_compressed_account::{
compressed_account::PackedMerkleContext,
instruction_data::with_readonly::{InAccount, InstructionDataInvokeCpiWithReadOnly},
};
use light_compressed_token::{
constants::{
Expand All @@ -19,7 +20,6 @@ use light_compressed_token::{
token_input::set_input_compressed_account,
},
};
use light_sdk::instruction::PackedMerkleContext;
use light_token_interface::{
hash_cache::HashCache, instructions::transfer2::MultiInputTokenDataWithContext,
state::CompressedTokenAccountState,
Expand Down
93 changes: 93 additions & 0 deletions scripts/check-dependency-constraints.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#!/usr/bin/env bash
set -euo pipefail

# Check that program-libs and programs do not depend on sdk-libs crates
# This enforces the architectural constraint that program-libs and programs
# are lower-level and should not depend on higher-level sdk-libs.

echo "Checking dependency constraints..."

# SDK-libs crates that program-libs and programs must NOT depend on
SDK_LIBS_CRATES=(
"light-sdk"
"light-sdk-types"
"light-sdk-macros"
"light-sdk-pinocchio"
"light-token"
"light-token-types"
"light-client"
"light-program-test"
"light-event"
"light-prover-client"
"photon-api"
)

# Crates in program-libs that should not depend on sdk-libs
PROGRAM_LIBS_CRATES=(
"light-account-checks"
"light-batched-merkle-tree"
"light-bloom-filter"
"light-compressed-account"
"light-compressible"
"light-concurrent-merkle-tree"
"light-token-interface"
"light-hash-set"
"light-hasher"
"light-indexed-merkle-tree"
"light-macros"
"light-merkle-tree-metadata"
"light-verifier"
"light-zero-copy"
"light-zero-copy-derive"
"light-heap"
"light-array-map"
"light-indexed-array"
"aligned-sized"
)

# Programs that should not depend on sdk-libs
PROGRAM_CRATES=(
"account-compression"
"light-compressed-token"
"light-registry"
"light-system-program"
)

check_no_sdk_deps() {
local crate="$1"
local tree_output
tree_output=$(cargo tree -p "$crate" --edges normal 2>/dev/null)

for sdk_crate in "${SDK_LIBS_CRATES[@]}"; do
if echo "$tree_output" | grep -q " ${sdk_crate} v"; then
echo "ERROR: $crate depends on sdk-libs crate: $sdk_crate"
return 1
fi
done
return 0
}

CONSTRAINT_FAILED=0

echo "Checking program-libs crates do not depend on sdk-libs..."
for crate in "${PROGRAM_LIBS_CRATES[@]}"; do
if ! check_no_sdk_deps "$crate"; then
CONSTRAINT_FAILED=1
fi
done

echo "Checking programs do not depend on sdk-libs..."
for crate in "${PROGRAM_CRATES[@]}"; do
if ! check_no_sdk_deps "$crate"; then
CONSTRAINT_FAILED=1
fi
done

if [ "$CONSTRAINT_FAILED" -eq 1 ]; then
echo ""
echo "FAILED: Some program-libs or programs depend on sdk-libs crates."
echo "This is not allowed. program-libs and programs must only depend on other program-libs or external crates."
exit 1
fi

echo "All dependency constraints satisfied."
3 changes: 3 additions & 0 deletions scripts/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ npx nx run-many --target=lint --all
cargo +nightly fmt --all -- --check
cargo clippy --workspace --all-features --all-targets -- -D warnings

# Check that program-libs and programs don't depend on sdk-libs
./scripts/check-dependency-constraints.sh

echo "Testing feature combinations..."

# Test no-default-features for all library crates
Expand Down
6 changes: 3 additions & 3 deletions sdk-libs/event/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use light_compressed_account::{
CompressedAccount, CompressedAccountData, PackedCompressedAccountWithMerkleContext,
},
constants::{
ACCOUNT_COMPRESSION_PROGRAM_ID, CREATE_CPI_CONTEXT_ACCOUNT, REGISTERED_PROGRAM_PDA,
SYSTEM_PROGRAM_ID,
ACCOUNT_COMPRESSION_PROGRAM_ID, CREATE_CPI_CONTEXT_ACCOUNT, LIGHT_SYSTEM_PROGRAM_ID,
REGISTERED_PROGRAM_PDA,
},
discriminators::*,
instruction_data::{
Expand Down Expand Up @@ -253,7 +253,7 @@ fn wrap_program_ids(
let discriminator: [u8; 8] = instruction[0..8].try_into().unwrap();
if program_id == &Pubkey::default() {
vec.push(ProgramId::SolanaSystem);
} else if program_id == &SYSTEM_PROGRAM_ID {
} else if program_id == &LIGHT_SYSTEM_PROGRAM_ID {
if discriminator == CREATE_CPI_CONTEXT_ACCOUNT {
vec.push(ProgramId::Unknown);
} else {
Expand Down
Loading
Loading