Skip to content

Commit 5bb0505

Browse files
compressed repr. should store disc as part of data
1 parent 21d7863 commit 5bb0505

4 files changed

Lines changed: 18 additions & 11 deletions

File tree

external/photon

sdk-libs/client/src/interface/account_interface.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,13 @@ impl AccountInterface {
6363
}
6464

6565
/// Create a cold account interface for a PDA/mint.
66+
///
67+
/// `data.data` contains the full on-chain account bytes as-is (no reassembly needed).
6668
pub fn cold(key: Pubkey, compressed: CompressedAccount, owner: Pubkey) -> Self {
6769
let data = compressed
6870
.data
6971
.as_ref()
70-
.map(|d| {
71-
let mut buf = d.discriminator.to_vec();
72-
buf.extend_from_slice(&d.data);
73-
buf
74-
})
72+
.map(|d| d.data.clone())
7573
.unwrap_or_default();
7674

7775
Self {

sdk-libs/sdk-types/src/interface/program/compression/pda.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//! These functions are generic over account types and can be reused by the macro.
44
//! The compress flow uses a dispatch callback pattern (same as decompress).
55
6+
use alloc::vec::Vec;
7+
68
use light_account_checks::AccountInfoTrait;
79
use light_compressed_account::{
810
address::derive_address,
@@ -111,8 +113,11 @@ where
111113
*compressed_data.compression_info_mut()? =
112114
crate::interface::account::compression_info::CompressionInfo::compressed();
113115

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

sdk-libs/sdk-types/src/interface/program/decompression/pda.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,15 @@ where
9292
return Ok(());
9393
}
9494

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

0 commit comments

Comments
 (0)