Skip to content

Commit 310c1aa

Browse files
committed
update readme and makefile
1 parent aa708fc commit 310c1aa

File tree

10 files changed

+158
-82
lines changed

10 files changed

+158
-82
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@ target/
22
elf/
33
cache/
44

5-
*.pb
6-
*.trace
5+
*.trace_profile
76
*.proof

Makefile

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ CARGO_INSTALL_EXTRA_FLAGS ?=
1414
# List of features to use for building
1515
FEATURES ?=
1616

17+
# List of programs
18+
PROGRAMS ?= fibonacci,sha2-chain,schnorr-sig-verify
19+
20+
# ZkVm to use
21+
ZKVM ?= sp1
22+
1723
##@ Help
1824

1925
.PHONY: help
@@ -57,29 +63,24 @@ sec: ## Check for security advisories on any dependencies.
5763
##@ Prover
5864

5965
.PHONY: report
60-
report: prover-clean ## Generate proof report for programs
61-
cargo run --release -- --programs fibonacci,sha2-chain,schnorr-sig-verify
66+
report: prover-clean ## Generate proof report for programs for all supported ZkVm
67+
cargo run --release -- --programs $(PROGRAMS)
6268

6369
.PHONY: report-sp1
64-
report-sp1: prover-clean ## Generate SP1 proof report for programs
65-
cargo run --release --no-default-features -F sp1-mock -- --programs fibonacci,sha2-chain,schnorr-sig-verify
70+
report-sp1: prover-clean ## Generate SP1 proof report for given programs
71+
cargo run --release --no-default-features -F sp1-mock -- --programs $(PROGRAMS)
6672

6773
.PHONY: report-risc0
68-
report-risc0: prover-clean ## Generate Risc0 proof report for programs
69-
cargo run --release --no-default-features -F risc0-mock -- --programs fibonacci,sha2-chain,schnorr-sig-verify
70-
71-
.PHONY: proof-sp1-fibonacci
72-
proof-sp1-fibonacci: prover-clean ## Generate SP1 Groth16 proof for fibonacci program
73-
cargo run --release --no-default-features -F sp1 -- --programs fibonacci
74-
75-
.PHONY: proof-risc0-fibonacci
76-
proof-risc0-fibonacci: prover-clean ## Generate Risc0 Groth16 proof for fibonacci program
77-
cargo run --release --no-default-features -F risc0 -- --programs fibonacci
74+
report-risc0: prover-clean ## Generate Risc0 proof report for given programs
75+
cargo run --release --no-default-features -F risc0-mock -- --programs $(PROGRAMS)
7876

77+
.PHONY: proof
78+
proof: ## Generate proof for the given program using the given ZkVm
79+
ZKVM_PROOF_DUMP=1 cargo run --release --no-default-features -F $(ZKVM) -- --programs $(PROGRAMS)
7980

8081
.PHONY: prover-clean
8182
prover-clean: ## Cleans up proofs and profiling data generated
82-
rm -rf *.trace
83+
rm -rf *.trace_profile
8384
rm -rf *.proof
8485

8586
##@ Code Quality

README.md

Lines changed: 124 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,134 @@ Currently, the repository supports the following ZKVMs:
2626

2727
---
2828

29-
## Usage
29+
# Usage Guide
3030

31-
### Generating report of cycle count of different programs
31+
## Generating Report of Cycle Counts for Programs
32+
33+
To generate a report of cycle counts for one or more programs, use the following command:
34+
35+
```bash
36+
make report PROGRAMS=<PROGRAM_NAME>
37+
```
38+
39+
### Notes:
40+
- **Multiple Programs Supported:** You can specify multiple programs by separating them with commas.
41+
- **Example Commands:**
42+
```bash
43+
make report PROGRAMS=fibonacci
44+
make report PROGRAMS=fibonacci,sha2-chain
45+
```
46+
- **Optional Parameter:** If `PROGRAMS` is left empty, the report will be generated for all supported programs.
47+
48+
### Supported Programs
49+
Here is the list of currently supported programs:
50+
- `fibonacci`
51+
- `sha2-chain`
52+
- `schnorr-sig-verify`
53+
54+
## Generating Report for a Specific ZKVM
55+
56+
To generate profiling data for a specific ZKVM, use the following commands:
57+
58+
```bash
59+
make report-<ZkVm>
60+
```
61+
62+
### Example Commands:
63+
- For Risc0:
64+
```bash
65+
make report-risc0
66+
```
67+
- For SP1:
68+
```bash
69+
make report-sp1
70+
```
71+
- Similar to the general `make report`, you can also pass the `PROGRAMS` parameter:
72+
```bash
73+
make report-risc0 PROGRAMS=fibonacci
74+
make report-sp1 PROGRAMS=fibonacci,sha2-chain
75+
```
76+
77+
78+
## Generating Profile Data
79+
80+
To dump profiling data, set the environment variable `ZKVM_PROFILING_DUMP=1` while running any of the above command.
81+
82+
```bash
83+
ZKVM_PROFILING_DUMP=1 make report
84+
```
85+
86+
87+
### Viewing SP1 Profile
88+
89+
The profiling data for SP1 can be viewed using [Samply](https://github.com/mstange/samply). To view the profile:
90+
91+
```bash
92+
samply load <FILENAME>.trace_profile
93+
```
94+
95+
### Viewing Risc0 Profile
96+
97+
The profiling data for Risc0 can be viewed using [pprof](https://github.com/google/pprof). To view the profile:
98+
99+
```bash
100+
go tool pprof -http=127.0.0.1:8000 <FILENAME>.trace_profile
101+
```
102+
103+
## Generating Proof for Program
104+
105+
If proof is required, use the folloing command:
32106

33107
```bash
34-
make report
108+
make proof ZKVM=<ZKVM_NAME> PROGRAMS=<PROGRAM_NAME>
35109
```
110+
> The proofs are dumped by default
111+
112+
### Additional Options:
113+
- **Dump Profiling Data:** To dump proofs, set the environment variable `ZKVM_PROOF_DUMP=1` while running the command:
114+
115+
## Cleaning Up Generated Data
116+
To clean up generated proofs and profiling data, run:
117+
118+
```bash
119+
make prover-clean
120+
```
121+
This will remove all `.trace_profile` and `.proof` files from the current directory.
122+
123+
---
124+
125+
### Example Workflow
126+
1. **Generate Report for All Programs:**
127+
```bash
128+
make report
129+
```
130+
131+
2. **Generate Report for Specific Programs:**
132+
```bash
133+
make report PROGRAMS=fibonacci,sha2-chain
134+
```
135+
136+
3. **Generate SP1 Report for Specific Programs:**
137+
```bash
138+
make report-sp1 PROGRAMS=schnorr-sig-verify
139+
```
140+
141+
4. **Dump Profiling Data for Risc0:**
142+
```bash
143+
ZKVM_PROFILING_DUMP=1 make report-risc0 PROGRAMS=fibonacci
144+
```
145+
146+
5. **Generate and dump Risc0 Proof**
147+
```bash
148+
make proof ZKVM=risc0 PROGRAMS=fibonacci
149+
```
150+
151+
152+
5. **Clean Up Generated Data:**
153+
```bash
154+
make prover-clean
155+
```
156+
36157

37158
---
38159

crates/risc0/src/host.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ impl ZkVmHost for Risc0Host {
7070
.map(|v| v == "1" || v.to_lowercase() == "true")
7171
.unwrap_or(false)
7272
{
73-
std::env::set_var("RISC0_PPROF_OUT", "risc0.trace");
73+
let profiling_file_name = format!("{:?}.trace_profile", self);
74+
std::env::set_var("RISC0_PPROF_OUT", profiling_file_name);
7475
}
7576

7677
// TODO: handle error

crates/sp1/src/host.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,16 @@ impl ZkVmHost for SP1Host {
7676
.map(|v| v == "1" || v.to_lowercase() == "true")
7777
.unwrap_or(false)
7878
{
79-
std::env::set_var("TRACE_FILE", "sp1.trace");
79+
let profiling_file_name = format!("{:?}.trace_profile", self);
80+
std::env::set_var("TRACE_FILE", profiling_file_name);
8081
}
8182

8283
let (output, report) = client.execute(self.get_elf(), &prover_input).run().unwrap();
8384

85+
// Remove the variable after execution to avoid duplication of trace generation in perf
86+
// report
87+
std::env::remove_var("TRACE_FILE");
88+
8489
let public_values = PublicValues::new(output.to_vec());
8590
let total_cycles = report.total_instruction_count();
8691

crates/zkvm/src/host.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ pub trait ZkVmHost: Send + Sync + Clone + Debug + 'static {
2323
proof_type: ProofType,
2424
) -> ZkVmResult<Self::ZkVmProofReceipt>;
2525

26-
/// Executes the guest code within the VM, generating and returning [`ProofReceipt`].
2726
fn prove<'a>(
2827
&self,
2928
input: <Self::Input<'a> as ZkVmInputBuilder<'a>>::Input,
@@ -33,7 +32,12 @@ pub trait ZkVmHost: Send + Sync + Clone + Debug + 'static {
3332
receipt.try_into().map_err(ZkVmError::InvalidProofReceipt)
3433
}
3534

36-
/// Executes the guest code within the VM, generating and returning [`ProofReceipt`].
35+
/// Executes the guest code within the VM.
36+
///
37+
/// # Returns
38+
/// A tuple containing:
39+
/// * `PublicValues` - The public values generated during proof execution.
40+
/// * `u64` - The cycle count for the execution
3741
fn execute<'a>(
3842
&self,
3943
input: <Self::Input<'a> as ZkVmInputBuilder<'a>>::Input,

crates/zkvm/src/prover.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,6 @@ pub trait ZkVmProver {
6464
let (_, cycles) = host.execute(zkvm_input)?;
6565
let execution_time = start.elapsed().as_millis();
6666

67-
if std::env::var("ZKVM_PROFILING_DUMP")
68-
.map(|v| v == "1" || v.to_lowercase() == "true")
69-
.unwrap_or(false)
70-
{
71-
let from = format!("{:?}.profle", host);
72-
let to = format!("{}_{:?}.profile", Self::name(), host);
73-
std::fs::rename(from, to).unwrap();
74-
}
75-
7667
let _ = Self::prove(input, host)?;
7768
let proving_time = start.elapsed().as_millis();
7869

runner/README.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

runner/src/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ pub fn format_header(args: &EvalArgs) -> String {
1919
pub fn format_results(results: &[PerformanceReport], host_name: String) -> String {
2020
let mut table_text = String::new();
2121
table_text.push('\n');
22-
table_text.push_str("| program | cycles | success |\n");
23-
table_text.push_str("|-------------------|-------------|----------|");
22+
table_text.push_str("| program | cycles | success |\n");
23+
table_text.push_str("|---------------------|-------------|----------|");
2424

2525
for result in results.iter() {
2626
table_text.push_str(&format!(
27-
"\n| {:<17} | {:>11} | {:<7} |",
27+
"\n| {:<19} | {:>11} | {:<7} |",
2828
result.program,
2929
result.cycles.to_formatted_string(&Locale::en),
3030
if result.success { "✅" } else { "❌" }

runner/src/programs/sha2.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use strata_zkvm::{ProofReport, ZkVmHost, ZkVmProver};
33

44
fn sha2_prover_perf_report(host: &impl ZkVmHost) -> ProofReport {
55
let input = 5;
6-
ShaChainProver::prove(&input, host).unwrap();
76
ShaChainProver::perf_report(&input, host).unwrap()
87
}
98

0 commit comments

Comments
 (0)