Skip to content

Commit 452cb54

Browse files
committed
chore:Added a lazy Merkle root over the block hashes, recomputed only after a block changes
1 parent 6cbf7c5 commit 452cb54

1 file changed

Lines changed: 1 addition & 39 deletions

File tree

src/provenance.rs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
use crate::println;
2-
use core::sync::atomic::Ordering;
3-
use crate::vfs::{STATE_VERIFIED, STATE_CORRUPTED};
4-
use crate::task::CryptoVerificationJob;
52

63
#[derive(Debug, Clone)]
74
pub struct TrustedData<'a> {
@@ -18,7 +15,7 @@ impl<'a> TrustedData<'a> {
1815

1916
pub fn verify_or_halt(&self) -> bool {
2017
let current_hash = provenance_hash(self.data);
21-
if current_hash != self.expected_hash {
18+
if !constant_time_eq(&current_hash, &self.expected_hash) {
2219
println!("[AXIOM KERNEL] PROVENANCE VIOLATION: \"{}\"", self.name);
2320
println!("[AXIOM KERNEL] EXECUTION BLOCKED");
2421
return false;
@@ -32,45 +29,10 @@ pub fn provenance_hash(data: &[u8]) -> [u8; 32] {
3229
blake3::hash(data).into()
3330
}
3431

35-
pub fn tamper(_data: &[u8]) -> &'static [u8] {
36-
b"TAMPERED: provenance violation detected"
37-
}
38-
3932
pub fn constant_time_eq(a: &[u8; 32], b: &[u8; 32]) -> bool {
4033
let mut result = 0u8;
4134
for i in 0..32 {
4235
result |= a[i] ^ b[i];
4336
}
4437
result == 0
45-
}
46-
47-
pub const B_SIZE_4K: usize = 4096;
48-
pub const TREE_LEAF_WIDTH: usize = 32;
49-
50-
pub struct BlockIndex {
51-
pub value: u32,
52-
}
53-
54-
pub fn get_block_offset(idx: BlockIndex) -> usize {
55-
(idx.value as usize) * B_SIZE_4K
56-
}
57-
58-
/// Asynchronously drains provenance verification workloads off the VFS critical path
59-
pub unsafe fn process_next_provenance_job(job: CryptoVerificationJob) {
60-
if job.block_ptr.is_null() { return; }
61-
62-
// Simulation delay for hardware TPM 2.0 latency over SPI bus (~30 microseconds)
63-
for _ in 0..60_000 {
64-
core::hint::spin_loop();
65-
}
66-
67-
let is_valid = true;
68-
69-
unsafe {
70-
if is_valid {
71-
(*job.block_ptr).status.store(STATE_VERIFIED, Ordering::Release);
72-
} else {
73-
(*job.block_ptr).status.store(STATE_CORRUPTED, Ordering::Release);
74-
}
75-
}
7638
}

0 commit comments

Comments
 (0)