Skip to content

Commit 54c7bc0

Browse files
authored
feat: add SP1 proof generation support to ASM runner (#54)
* feat: add SP1 proof generation * test(functional-tests): support SP1 proof generation and increase proof timeout
1 parent 8f22cf0 commit 54c7bc0

File tree

7 files changed

+49
-6
lines changed

7 files changed

+49
-6
lines changed

Cargo.lock

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ zkaleido = { git = "https://github.com/alpenlabs/zkaleido", tag = "v0.1.0-alpha-
138138
zkaleido-native-adapter = { git = "https://github.com/alpenlabs/zkaleido", tag = "v0.1.0-alpha-rc22", features = [
139139
"remote-prover",
140140
] }
141+
zkaleido-sp1-host = { git = "https://github.com/alpenlabs/zkaleido", tag = "v0.1.0-alpha-rc22" }
141142

142143
# external dependencies
143144
anyhow = "1.0.86"

bin/asm-runner/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@ jsonrpsee = { workspace = true, features = ["server", "macros"] }
4242
serde.workspace = true
4343
serde_json.workspace = true
4444
ssz.workspace = true
45+
strata-asm-sp1-guest-builder = { path = "../../guest-builder/sp1", optional = true }
4546
threadpool = "1.8"
4647
tokio.workspace = true
4748
toml.workspace = true
4849
tracing.workspace = true
4950
zkaleido.workspace = true
51+
zkaleido-sp1-host = { workspace = true, optional = true, features = [
52+
"remote-prover",
53+
] }
54+
55+
[features]
56+
sp1 = ["dep:zkaleido-sp1-host", "dep:strata-asm-sp1-guest-builder"]

bin/asm-runner/src/bootstrap.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use anyhow::Result;
44
use bitcoind_async_client::{Auth, Client};
55
use strata_asm_params::AsmParams;
66
use strata_asm_proof_db::SledProofDb;
7-
use strata_asm_proof_impl::program::AsmStfProofProgram;
87
use strata_asm_worker::AsmWorkerBuilder;
98
use strata_tasks::TaskExecutor;
109
use tokio::{
@@ -64,11 +63,26 @@ pub(crate) async fn bootstrap(
6463
let proof_db = SledProofDb::open(&orch_config.proof_db_path)?;
6564
let proof_db_clone = proof_db.clone();
6665

67-
let native_host = AsmStfProofProgram::native_host();
66+
#[cfg(feature = "sp1")]
67+
let host = {
68+
use std::fs;
69+
70+
use strata_asm_sp1_guest_builder::ASM_ELF_PATH;
71+
use zkaleido_sp1_host::SP1Host;
72+
let elf = fs::read(ASM_ELF_PATH)
73+
.unwrap_or_else(|err| panic!("failed to read guest elf at {ASM_ELF_PATH}: {err}"));
74+
SP1Host::init(&elf)
75+
};
76+
77+
#[cfg(not(feature = "sp1"))]
78+
let host = {
79+
use strata_asm_proof_impl::program::AsmStfProofProgram;
80+
AsmStfProofProgram::native_host()
81+
};
6882

6983
let input_builder = InputBuilder::new(asm_manager.clone(), bitcoin_client.clone());
7084
let mut orchestrator =
71-
ProofOrchestrator::new(proof_db, native_host, orch_config, input_builder, rx);
85+
ProofOrchestrator::new(proof_db, host, orch_config, input_builder, rx);
7286

7387
// ZkVmRemoteProver is !Send (#[async_trait(?Send)]), so the orchestrator
7488
// future cannot be spawned on a multi-threaded runtime directly. We run it

functional-tests/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,18 @@ cd functional-tests
2727
./run_test.sh fn_asm_block_test
2828
```
2929

30+
### SP1 proof generation
31+
32+
To run with SP1 proof generation enabled:
33+
34+
```bash
35+
SP1_PROOF_STRATEGY="" NETWORK_PRIVATE_KEY="" CARGO_DEBUG=0 CARGO_FEATURES=sp1 ./run_test.sh fn_asm_proof_test
36+
```
37+
38+
- `SP1_PROOF_STRATEGY` — the SP1 proof fulfillment strategy. See
39+
[FulfillmentStrategy](https://docs.rs/sp1-sdk/5.2.1/sp1_sdk/network/enum.FulfillmentStrategy.html)
40+
for available options.
41+
- `NETWORK_PRIVATE_KEY` — private key for the SP1 network prover (required
42+
when using a network strategy).
43+
3044
Results are written under `functional-tests/_dd/`.

functional-tests/run_test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ else
1616
TARGET_DIR="debug"
1717
fi
1818

19+
if [ -n "${CARGO_FEATURES:-}" ]; then
20+
CARGO_ARGS+=(--features "$CARGO_FEATURES")
21+
fi
22+
1923
cargo build --bin strata-asm-runner ${CARGO_ARGS[@]+"${CARGO_ARGS[@]}"}
2024
TARGET_ROOT="${CARGO_TARGET_DIR:-target}"
2125
if [[ "$TARGET_ROOT" != /* ]]; then

functional-tests/utils/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def check():
8181
return height_holder["height"]
8282

8383

84-
def wait_until_asm_proof_exists(asm_rpc, block_hash: str, timeout: int = 60, step: int = 2):
84+
def wait_until_asm_proof_exists(asm_rpc, block_hash: str, timeout: int = 600, step: int = 2):
8585
"""Wait until an ASM proof exists for the given block hash."""
8686

8787
def check():

0 commit comments

Comments
 (0)