File tree Expand file tree Collapse file tree
sdk-types/src/interface/program Expand file tree Collapse file tree Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff line change 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+
68use light_account_checks:: AccountInfoTrait ;
79use 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments