Skip to main content

Module diff

Module diff 

Source
Expand description

State Diff Engine: field-level change tracking.

Captures before/after snapshots of account data and computes diffs. Use cases:

  • Audit trails
  • Test assertions
  • Post-mutation invariant verification
  • Debugging state transitions

§Usage

// Capture before state
let snap = StateSnapshot::<256>::capture(account_data);

// ... mutations happen ...

// Compute diff
let diff = snap.diff(account_data);
if diff.has_changes() {
    let regions = diff.changed_regions::<8>();
    let mut i = 0;
    while i < regions.len() {
        if let Some(r) = regions.get(i) {
            // r.offset, r.length
        }
        i += 1;
    }
}

§Design

Snapshots are stack-allocated using const generics. The maximum snapshot size is a compile-time parameter. For accounts larger than the snapshot buffer, only the first N bytes are captured. Use was_truncated() to detect this.

Structs§

ChangedRegion
A contiguous region of changed bytes.
ChangedRegionIter
Iterator over changed regions.
ChangedRegions
Stack-allocated list of changed regions.
StateDiff
A diff between two states of account data.
StateSnapshot
A stack-allocated snapshot of account data.

Functions§

field_diff_mask
Build a field-level diff report for a known layout.