From cbbd455cbb18f5f66d8d3211f77d7acda1756d00 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Thu, 15 Feb 2024 14:28:22 -0800 Subject: [PATCH 1/3] allow proving in wasi --- core/src/stark/prover.rs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/core/src/stark/prover.rs b/core/src/stark/prover.rs index c98f73db8c..87fc8e89d1 100644 --- a/core/src/stark/prover.rs +++ b/core/src/stark/prover.rs @@ -443,14 +443,21 @@ where let data = tracing::info_span!("shard commit main", shard = shard.index) .in_scope(|| Self::commit_main(config, machine, shard, i)); let commitment = data.main_commit.clone(); - let file = tempfile::tempfile().unwrap(); - let data = if num_shards > save_disk_threshold { - tracing::info_span!("saving trace to disk").in_scope(|| { - data.save(file).expect("failed to save shard main data") - }) - } else { - data.to_in_memory() + + #[cfg(target_arch = "wasm32")] + let data = data.to_in_memory(); + #[cfg(not(target_arch = "wasm32"))] + let data = { + let file = tempfile::tempfile().unwrap(); + if num_shards > save_disk_threshold { + tracing::info_span!("saving trace to disk").in_scope(|| { + data.save(file).expect("failed to save shard main data") + }) + } else { + data.to_in_memory() + } }; + (commitment, data) }) .collect::>() From fbb49c2e20d8a98ad76cfcf2c95dd2cb342c991b Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Fri, 23 Feb 2024 20:43:00 -0800 Subject: [PATCH 2/3] dont use tempfile in wasm --- core/src/stark/prover.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/core/src/stark/prover.rs b/core/src/stark/prover.rs index 1801beca02..113156d721 100644 --- a/core/src/stark/prover.rs +++ b/core/src/stark/prover.rs @@ -458,16 +458,18 @@ where let data = tracing::info_span!("shard commit main", shard = index) .in_scope(|| Self::commit_main(config, machine, shard, index)); let commitment = data.main_commit.clone(); - let file = tempfile::tempfile().unwrap(); #[cfg(target_arch = "wasm32")] let data = data.to_in_memory(); #[cfg(not(target_arch = "wasm32"))] - let data = if num_shards > save_disk_threshold { - tracing::info_span!("saving trace to disk").in_scope(|| { - data.save(file).expect("failed to save shard main data") - }) - } else { - data.to_in_memory() + let data = { + let file = tempfile::tempfile().unwrap(); + if num_shards > save_disk_threshold { + tracing::info_span!("saving trace to disk").in_scope(|| { + data.save(file).expect("failed to save shard main data") + }) + } else { + data.to_in_memory() + } }; (commitment, data) }) From 6dbf641c57d992d7418224209d3f33acb3235200 Mon Sep 17 00:00:00 2001 From: dr-frmr Date: Thu, 7 Mar 2024 23:37:09 -0300 Subject: [PATCH 3/3] refactor: minimum change to let prover run in wasm --- core/src/stark/prover.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/core/src/stark/prover.rs b/core/src/stark/prover.rs index f99ded9680..1212dd782b 100644 --- a/core/src/stark/prover.rs +++ b/core/src/stark/prover.rs @@ -463,12 +463,17 @@ where let data = tracing::info_span!("shard commit main", shard = index) .in_scope(|| Self::commit_main(config, machine, shard, index)); let commitment = data.main_commit.clone(); - let file = tempfile::tempfile().unwrap(); let data = if reconstruct_commitments { ShardMainDataWrapper::Empty() } else if num_shards > save_disk_threshold { + #[cfg(target_arch = "wasm32")] + { + data.to_in_memory() + } + #[cfg(not(target_arch = "wasm32"))] tracing::info_span!("saving trace to disk").in_scope(|| { - data.save(file).expect("failed to save shard main data") + data.save(tempfile::tempfile().unwrap()) + .expect("failed to save shard main data") }) } else { data.to_in_memory()