Skip to content
Open
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 external/photon
8 changes: 3 additions & 5 deletions sdk-libs/client/src/interface/account_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ impl AccountInterface {
}

/// Create a cold account interface for a PDA/mint.
///
/// `data.data` contains the full on-chain account bytes as-is (no reassembly needed).
pub fn cold(key: Pubkey, compressed: CompressedAccount, owner: Pubkey) -> Self {
let data = compressed
.data
.as_ref()
.map(|d| {
let mut buf = d.discriminator.to_vec();
buf.extend_from_slice(&d.data);
buf
})
.map(|d| d.data.clone())
.unwrap_or_default();

Self {
Expand Down
9 changes: 7 additions & 2 deletions sdk-libs/sdk-types/src/interface/program/compression/pda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//! These functions are generic over account types and can be reused by the macro.
//! The compress flow uses a dispatch callback pattern (same as decompress).

use alloc::vec::Vec;

use light_account_checks::AccountInfoTrait;
use light_compressed_account::{
address::derive_address,
Expand Down Expand Up @@ -111,8 +113,11 @@ where
*compressed_data.compression_info_mut()? =
crate::interface::account::compression_info::CompressionInfo::compressed();

// Hash the data (discriminator NOT included per protocol convention)
let data_bytes = borsh::to_vec(&compressed_data).map_err(|_| LightSdkTypesError::Borsh)?;
// Serialize with disc prefix: disc(8) + borsh(struct) — mirrors on-chain layout.
let borsh_bytes = borsh::to_vec(&compressed_data).map_err(|_| LightSdkTypesError::Borsh)?;
let mut data_bytes = Vec::with_capacity(8 + borsh_bytes.len());
data_bytes.extend_from_slice(&A::LIGHT_DISCRIMINATOR);
data_bytes.extend_from_slice(&borsh_bytes);
let mut output_data_hash = Sha256::hash(&data_bytes).map_err(LightSdkTypesError::Hasher)?;
output_data_hash[0] = 0; // Zero first byte per protocol convention

Expand Down
10 changes: 7 additions & 3 deletions sdk-libs/sdk-types/src/interface/program/decompression/pda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,15 @@ where
return Ok(());
}

// 5. Hash with canonical CompressionInfo::compressed() for input verification
let data_bytes = account_data
// 5. Hash with canonical CompressionInfo::compressed() for input verification.
// data = disc(8) + borsh(struct) — mirrors on-chain layout.
let borsh_bytes = account_data
.try_to_vec()
.map_err(|_| LightSdkTypesError::Borsh)?;
let data_len = data_bytes.len();
let data_len = borsh_bytes.len();
let mut data_bytes = Vec::with_capacity(8 + data_len);
data_bytes.extend_from_slice(&<Data<SEED_COUNT, P> as LightDiscriminator>::LIGHT_DISCRIMINATOR);
data_bytes.extend_from_slice(&borsh_bytes);
let mut input_data_hash = Sha256BE::hash(&data_bytes)?;
input_data_hash[0] = 0; // Zero first byte per protocol convention

Expand Down
Loading