Skip to content

Commit 5771b62

Browse files
committed
Keep state buffer hashing processor-local
Avoid reaching into the already-reviewed fraud-proof processor for shared hashing. Each instruction now computes the same domain-separated payload hash locally, while only the commit/finalize transition shared by this stack remains under processor/internal.
1 parent 6d0e407 commit 5771b62

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

‎program/src/processor/direct/commit_finalize_from_buffer.rs‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ use wheels::{
1010
layout::Decodable, require_eq, require_eq_keys, require_n_accounts,
1111
};
1212

13-
use crate::processor::{
14-
internal::{
15-
apply_commit_finalize, CommitFinalizeInput, CommitStateUpdate,
16-
},
17-
state_buffer_payload_hash,
13+
use crate::processor::internal::{
14+
apply_commit_finalize, CommitFinalizeInput, CommitStateUpdate,
1815
};
1916

2017
/// Commit and apply one finalized StateBuffer for a Direct cluster.
@@ -148,9 +145,14 @@ fn validate_state_buffer(
148145
);
149146
require_eq!(
150147
buffer.data_hash(),
151-
&state_buffer_payload_hash(buffer.payload().as_slice()),
148+
&account_data_hash(buffer.payload().as_slice()),
152149
ProgramError::InvalidInstructionData
153150
);
154151

155152
Ok(())
156153
}
154+
155+
fn account_data_hash(data: &[u8]) -> [u8; 32] {
156+
solana_sha256_hasher::hashv(&[b"magicblock.account_data.v1", data])
157+
.to_bytes()
158+
}

‎program/src/processor/fraud_proofs/write_state_buffer.rs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use wheels::{
1616

1717
use crate::{
1818
legacy::processor::fast::utils::pda::create_pda_with_rent_exempt_lamports,
19-
processor::state_buffer_payload_hash,
2019
requires::{
2120
is_uninitialized_account, require_initialized_pda,
2221
require_uninitialized_pda, StandardCtx,
@@ -232,7 +231,7 @@ fn write_chunk(
232231
state.total_len() as usize,
233232
ProgramError::InvalidAccountData
234233
);
235-
Some(state_buffer_payload_hash(payload.as_slice()))
234+
Some(account_data_hash(payload.as_slice()))
236235
} else {
237236
None
238237
};
@@ -336,3 +335,8 @@ fn validate_duplicate_chunk(
336335

337336
Ok(())
338337
}
338+
339+
fn account_data_hash(data: &[u8]) -> [u8; 32] {
340+
solana_sha256_hasher::hashv(&[b"magicblock.account_data.v1", data])
341+
.to_bytes()
342+
}

‎program/src/processor/mod.rs‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,3 @@ pub fn process_instruction(
6767
}
6868
}
6969
}
70-
71-
pub(crate) fn state_buffer_payload_hash(payload: &[u8]) -> [u8; 32] {
72-
solana_sha256_hasher::hashv(&[b"magicblock.account_data.v1", payload])
73-
.to_bytes()
74-
}

0 commit comments

Comments
 (0)