Skip to content

Commit 25265e7

Browse files
[feat] Add Stateful trait (#20)
* Add Stateful trait * Update Cargo.toml --------- Co-authored-by: Jonathan Wang <[email protected]>
1 parent 9d1c1b2 commit 25265e7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

crates/stark-backend/src/chip.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ pub trait ChipUsageGetter {
3737
}
3838
}
3939

40+
/// A chip whose state could be persisted.
41+
pub trait Stateful<S> {
42+
fn load_state(&mut self, state: S);
43+
fn store_state(&self) -> S;
44+
}
45+
4046
impl<SC: StarkGenericConfig, C: Chip<SC>> Chip<SC> for RefCell<C> {
4147
fn air(&self) -> Arc<dyn AnyRap<SC>> {
4248
self.borrow().air()
@@ -140,3 +146,12 @@ impl<C: ChipUsageGetter> ChipUsageGetter for Mutex<C> {
140146
self.lock().unwrap().trace_width()
141147
}
142148
}
149+
150+
impl<S, C: Stateful<S>> Stateful<S> for RefCell<C> {
151+
fn load_state(&mut self, state: S) {
152+
self.borrow_mut().load_state(state)
153+
}
154+
fn store_state(&self) -> S {
155+
self.borrow_mut().store_state()
156+
}
157+
}

crates/stark-backend/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub mod utils;
4141
/// Verifier implementation
4242
pub mod verifier;
4343

44-
pub use chip::{Chip, ChipUsageGetter};
44+
pub use chip::{Chip, ChipUsageGetter, Stateful};
4545

4646
// Use jemalloc as global allocator for performance
4747
#[cfg(all(feature = "jemalloc", unix, not(test)))]

0 commit comments

Comments
 (0)