Skip to content

Commit

Permalink
refactor: Simplify persistent finalize (#1157)
Browse files Browse the repository at this point in the history
  • Loading branch information
zlangley authored Jan 6, 2025
1 parent 8f34289 commit 74d3f33
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions crates/vm/src/system/memory/persistent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ struct FinalTouchedLabel<F, const CHUNK: usize> {
label: u32,
init_values: [F; CHUNK],
final_values: [F; CHUNK],
init_exists: bool,
init_hash: [F; CHUNK],
final_hash: [F; CHUNK],
final_timestamp: u32,
Expand Down Expand Up @@ -207,23 +206,17 @@ impl<const CHUNK: usize, F: PrimeField32> PersistentBoundaryChip<F, CHUNK> {
let final_touched_labels = touched_labels
.iter()
.map(|touched_label| {
let (init_exists, initial_hash, init_values) =
match initial_memory.get(touched_label) {
Some(values) => (true, hasher.hash_and_record(values), *values),
None => (
true,
hasher.hash_and_record(&[F::ZERO; CHUNK]),
[F::ZERO; CHUNK],
),
};
let init_values = *initial_memory
.get(touched_label)
.unwrap_or(&[F::ZERO; CHUNK]);
let initial_hash = hasher.hash_and_record(&init_values);
let timestamped_values = final_memory.get(touched_label).unwrap();
let final_hash = hasher.hash_and_record(&timestamped_values.values);
FinalTouchedLabel {
address_space: touched_label.0,
label: touched_label.1,
init_values,
final_values: timestamped_values.values,
init_exists,
init_hash: initial_hash,
final_hash,
final_timestamp: timestamped_values.timestamp,
Expand Down Expand Up @@ -276,11 +269,7 @@ where
leaf_label: Val::<SC>::from_canonical_u32(touched_label.label),
values: touched_label.init_values,
hash: touched_label.init_hash,
timestamp: if touched_label.init_exists {
Val::<SC>::from_canonical_u32(INITIAL_TIMESTAMP)
} else {
Val::<SC>::ZERO
},
timestamp: Val::<SC>::from_canonical_u32(INITIAL_TIMESTAMP),
};

*final_row.borrow_mut() = PersistentBoundaryCols {
Expand Down

0 comments on commit 74d3f33

Please sign in to comment.