⚙️ CAIRO RUNE DIFFICULTY: Adept Behavioral

The Memento

Capturing and restoring the STARK VM state.

✧ GANG OF FOUR LINEAGE & ARCANUM ✧
GOF DESIGN PATTERN: Memento
ARCANUM SCHOOL: Chronomancy // Restoration
SCRIBE / ARCHON: Joshua Edward McLaughlin Cox
CANONICAL REGISTRATION:
// CAIRO PATTERN //
#[derive(Copy, Drop)]
struct VmState { pc: u32, ap: u32, fp: u32 }

#[derive(Copy, Drop)]
struct Memento { state: VmState }

#[derive(Copy, Drop)]
struct Vm { state: VmState }
trait IVm {
    fn save(self: @Vm) -> Memento;
    fn restore(ref self: Vm, memento: Memento);
}

impl VmImpl of IVm {
    fn save(self: @Vm) -> Memento { Memento { state: *self.state } }
    fn restore(ref self: Vm, memento: Memento) { self.state = memento.state; }
}

A chronological anchor, allowing the provers to step back in time to a previously captured state matrix.

Runic Tags: #cairo #design-pattern #memento