Skip to content

Commit 980997f

Browse files
authored
Refactor ProverClient::execute to borrow stdin (#418)
1 parent c6a8833 commit 980997f

File tree

13 files changed

+19
-19
lines changed

13 files changed

+19
-19
lines changed

crates/sdk/src/action.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct Execute<'a> {
1515
prover: &'a dyn Prover<DefaultProverComponents>,
1616
context_builder: ZKMContextBuilder<'a>,
1717
elf: &'a [u8],
18-
stdin: ZKMStdin,
18+
stdin: &'a ZKMStdin,
1919
}
2020

2121
impl<'a> Execute<'a> {
@@ -26,7 +26,7 @@ impl<'a> Execute<'a> {
2626
pub fn new(
2727
prover: &'a dyn Prover<DefaultProverComponents>,
2828
elf: &'a [u8],
29-
stdin: ZKMStdin,
29+
stdin: &'a ZKMStdin,
3030
) -> Self {
3131
Self { prover, elf, stdin, context_builder: Default::default() }
3232
}
@@ -35,7 +35,7 @@ impl<'a> Execute<'a> {
3535
pub fn run(self) -> Result<(ZKMPublicValues, ExecutionReport)> {
3636
let Self { prover, elf, stdin, mut context_builder } = self;
3737
let context = context_builder.build();
38-
Ok(prover.zkm_prover().execute(elf, &stdin, context)?)
38+
Ok(prover.zkm_prover().execute(elf, stdin, context)?)
3939
}
4040

4141
/// Add a runtime [Hook](super::Hook) into the context.

crates/sdk/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ impl ProverClient {
199199
/// stdin.write(&10usize);
200200
///
201201
/// // Execute the program on the inputs.
202-
/// let (public_values, report) = client.execute(elf, stdin).run().unwrap();
202+
/// let (public_values, report) = client.execute(elf, &stdin).run().unwrap();
203203
/// ```
204-
pub fn execute<'a>(&'a self, elf: &'a [u8], stdin: ZKMStdin) -> action::Execute<'a> {
204+
pub fn execute<'a>(&'a self, elf: &'a [u8], stdin: &'a ZKMStdin) -> action::Execute<'a> {
205205
action::Execute::new(self.prover.as_ref(), elf, stdin)
206206
}
207207

@@ -397,7 +397,7 @@ mod tests {
397397
let elf = test_artifacts::FIBONACCI_ELF;
398398
let mut stdin = ZKMStdin::new();
399399
stdin.write(&10usize);
400-
let (_, _report) = client.execute(elf, stdin).run().unwrap();
400+
let (_, _report) = client.execute(elf, &stdin).run().unwrap();
401401
// tracing::info!("gas = {}", report.estimate_gas());
402402
}
403403

@@ -409,7 +409,7 @@ mod tests {
409409
let elf = test_artifacts::PANIC_ELF;
410410
let mut stdin = ZKMStdin::new();
411411
stdin.write(&10usize);
412-
client.execute(elf, stdin).run().unwrap();
412+
client.execute(elf, &stdin).run().unwrap();
413413
}
414414

415415
#[should_panic]
@@ -420,7 +420,7 @@ mod tests {
420420
let elf = test_artifacts::PANIC_ELF;
421421
let mut stdin = ZKMStdin::new();
422422
stdin.write(&10usize);
423-
client.execute(elf, stdin).max_cycles(1).run().unwrap();
423+
client.execute(elf, &stdin).max_cycles(1).run().unwrap();
424424
}
425425

426426
#[test]

examples/bitcoin/host/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
let (pk, vk) = client.setup(BTC_ELF);
1818

1919
// Execute the guest using the `ProverClient.execute` method, without generating a proof.
20-
let (_, report) = client.execute(BTC_ELF, stdin.clone()).run().unwrap();
20+
let (_, report) = client.execute(BTC_ELF, &stdin).run().unwrap();
2121
println!("executed program with {} cycles", report.total_instruction_count());
2222

2323
let proof = client.prove(&pk, stdin).run().expect("proving failed");

examples/fibonacci/host/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919
let client = ProverClient::new();
2020

2121
// Execute the guest using the `ProverClient.execute` method, without generating a proof.
22-
let (_, report) = client.execute(ELF, stdin.clone()).run().unwrap();
22+
let (_, report) = client.execute(ELF, &stdin).run().unwrap();
2323
println!("executed program with {} cycles", report.total_instruction_count());
2424

2525
// Generate the proof for the given guest and input.

examples/fibonacci_c_lib/host/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ fn main() {
1919
let client = ProverClient::new();
2020

2121
// Execute the guest using the `ProverClient.execute` method, without generating a proof.
22-
let (_, report) = client.execute(ELF, stdin.clone()).run().unwrap();
22+
let (_, report) = client.execute(ELF, &stdin).run().unwrap();
2323
println!("executed program with {} cycles", report.total_instruction_count());
2424

2525
// Generate the proof for the given guest and input.

examples/keccak-precompile/host/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn prove_keccak_rust() {
2727
let client = ProverClient::new();
2828

2929
// Execute the program using the `ProverClient.execute` method, without generating a proof.
30-
let (_, report) = client.execute(ELF, stdin.clone()).run().unwrap();
30+
let (_, report) = client.execute(ELF, &stdin).run().unwrap();
3131
println!("executed program with {} cycles", report.total_instruction_count());
3232

3333
// Generate the proof for the given program and input.

examples/large-sum/host/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn main() {
2222
let client = ProverClient::new();
2323

2424
// Execute the guest using the `ProverClient.execute` method, without generating a proof.
25-
let (_, report) = client.execute(ELF, stdin.clone()).run().unwrap();
25+
let (_, report) = client.execute(ELF, &stdin).run().unwrap();
2626
println!("executed program with {} cycles", report.total_instruction_count());
2727

2828
// Generate the proof for the given guest and input.

examples/poseidon2/host/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
let client = ProverClient::new();
1818

1919
// Execute the guest using the `ProverClient.execute` method, without generating a proof.
20-
let (_, report) = client.execute(ELF, stdin.clone()).run().unwrap();
20+
let (_, report) = client.execute(ELF, &stdin).run().unwrap();
2121
println!("executed program with {} cycles", report.total_instruction_count());
2222

2323
// Generate the proof for the given guest and input.

examples/rsa/host/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn main() {
5555
let (pk, vk) = client.setup(RSA_ELF);
5656

5757
// Execute the guest using the `ProverClient.execute` method, without generating a proof.
58-
let (_, report) = client.execute(RSA_ELF, stdin.clone()).run().unwrap();
58+
let (_, report) = client.execute(RSA_ELF, &stdin).run().unwrap();
5959
println!("executed program with {} cycles", report.total_instruction_count());
6060

6161
let proof = client.prove(&pk, stdin).run().expect("proving failed");

examples/simple-go/host/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn prove_simple_go() {
1515
let client = ProverClient::new();
1616

1717
// Execute the guest using the `ProverClient.execute` method, without generating a proof.
18-
let (_, report) = client.execute(ELF, stdin.clone()).run().unwrap();
18+
let (_, report) = client.execute(ELF, &stdin).run().unwrap();
1919
println!("executed program with {} cycles", report.total_instruction_count());
2020

2121
// Generate the proof for the given guest and input.

0 commit comments

Comments
 (0)