Skip to content

Commit

Permalink
[PoC] feat: moving to shared store references (#680)
Browse files Browse the repository at this point in the history
* chore: Replace CacheMap with Elsa's FrozenMap

- Removed the `src/cache_map.rs` file and `cache_map` module from the codebase.
- Replaced the use of `CacheMap` with `FrozenMap` from the `elsa` crate in the `PoseidonCache` and `Store` structures across multiple files.
- Added `elsa` dependency, version `1.9.0`, with `indexmap` feature to the `Cargo.toml` file.
- `CacheMap` imports throughout the codebase have been removed and replaced with imports of `elsa::sync::FrozenMap`.

* refactor: use elsa::sync_index_set::FrozenIndexSet

* fix: remove uneeded mutable references to the store

* refactor: convert store HashMap to FrozenMap

* fix: remove a few uneeded references

* fix: adapt hydration to not require &mut

* fix: remove uneeded mutability modifiers

- Removed mutability modifier from `store` variable

* refactor: Refactor code to replace mutable Store references with immutable ones

* adapt LEM infra

* Removed exclusive reference to `hydrate_z_cache` in LEM

* more LEM simplifications

* fix: speed up hydration

* eliminate 'cloned' call on hydration; recover parallel hydration on LEM store

---------

Co-authored-by: Arthur Paulino <arthurleonardo.ap@gmail.com>
Co-authored-by: Gabriel Barreto <gabriel.aquino.barreto@gmail.com>
  • Loading branch information
3 people authored Sep 26, 2023
1 parent d65a71c commit a5101fd
Show file tree
Hide file tree
Showing 37 changed files with 388 additions and 757 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ ansi_term = "0.12.1"
tracing = { workspace = true }
tracing-texray = { workspace = true }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
elsa = { version = "1.9.0", git="https://github.com/lurk-lab/elsa", branch = "sync_index_map", features = ["indexmap"] }
arc-swap = "1.6.0"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
memmap = { version = "0.5.10", package = "memmap2" }
Expand Down
4 changes: 2 additions & 2 deletions benches/end2end.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ fn eval_benchmark(c: &mut Criterion) {
Evaluator::new(
ptr,
empty_sym_env(&bls12_store),
&mut bls12_store,
&bls12_store,
limit,
&lang_bls12,
)
Expand All @@ -220,7 +220,7 @@ fn eval_benchmark(c: &mut Criterion) {
Evaluator::new(
ptr,
empty_sym_env(&pallas_store),
&mut pallas_store,
&pallas_store,
limit,
&lang_pallas,
)
Expand Down
2 changes: 1 addition & 1 deletion benches/sha256_ivc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl<F: LurkField> Coprocessor<F> for Sha256Coprocessor<F> {
self.arity
}

fn simple_evaluate(&self, s: &mut Store<F>, args: &[Ptr<F>]) -> Ptr<F> {
fn simple_evaluate(&self, s: &Store<F>, args: &[Ptr<F>]) -> Ptr<F> {
let mut hasher = <Sha256 as sha2::Digest>::new();

let mut input = vec![0u8; 64 * self.arity];
Expand Down
2 changes: 1 addition & 1 deletion examples/circom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<F: LurkField> CircomGadget<F> for CircomSha256<F> {
vec![a, b]
}

fn simple_evaluate(&self, s: &mut Store<F>, _args: &[Ptr<F>]) -> Ptr<F> {
fn simple_evaluate(&self, s: &Store<F>, _args: &[Ptr<F>]) -> Ptr<F> {
// TODO: actually use the lurk inputs
let expected = Num::Scalar(
F::from_str_vartime(
Expand Down
2 changes: 1 addition & 1 deletion examples/sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<F: LurkField> Coprocessor<F> for Sha256Coprocessor<F> {
0
}

fn simple_evaluate(&self, s: &mut Store<F>, _args: &[Ptr<F>]) -> Ptr<F> {
fn simple_evaluate(&self, s: &Store<F>, _args: &[Ptr<F>]) -> Ptr<F> {
let mut hasher = Sha256::new();

let input = vec![0u8; self.n];
Expand Down
2 changes: 1 addition & 1 deletion examples/sha256_ivc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ impl<F: LurkField> Coprocessor<F> for Sha256Coprocessor<F> {
self.n
}

fn simple_evaluate(&self, s: &mut Store<F>, args: &[Ptr<F>]) -> Ptr<F> {
fn simple_evaluate(&self, s: &Store<F>, args: &[Ptr<F>]) -> Ptr<F> {
let mut hasher = Sha256::new();

let mut input = vec![0u8; 64 * self.n];
Expand Down
2 changes: 1 addition & 1 deletion examples/sha256_nivc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl<F: LurkField> Coprocessor<F> for Sha256Coprocessor<F> {
1
}

fn simple_evaluate(&self, s: &mut Store<F>, args: &[Ptr<F>]) -> Ptr<F> {
fn simple_evaluate(&self, s: &Store<F>, args: &[Ptr<F>]) -> Ptr<F> {
let mut hasher = Sha256::new();

let mut input = vec![0u8; 64];
Expand Down
4 changes: 2 additions & 2 deletions lurk-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ fn impl_enum_coproc(name: &Ident, variants: &DataEnum) -> TokenStream {
}
}

fn evaluate(&self, s: &mut lurk::store::Store<F>, args: lurk::ptr::Ptr<F>, env: lurk::ptr::Ptr<F>, cont: lurk::ptr::ContPtr<F>) -> lurk::eval::IO<F> {
fn evaluate(&self, s: &lurk::store::Store<F>, args: lurk::ptr::Ptr<F>, env: lurk::ptr::Ptr<F>, cont: lurk::ptr::ContPtr<F>) -> lurk::eval::IO<F> {
match self {
#evaluate_arms
}
}

fn simple_evaluate(&self, s: &mut lurk::store::Store<F>, args: &[lurk::ptr::Ptr<F>]) -> lurk::ptr::Ptr<F> {
fn simple_evaluate(&self, s: &lurk::store::Store<F>, args: &[lurk::ptr::Ptr<F>]) -> lurk::ptr::Ptr<F> {
match self {
#simple_evaluate_arms
}
Expand Down
Loading

0 comments on commit a5101fd

Please sign in to comment.