1+ use std:: time:: { Duration , Instant } ;
12use zkm_sdk:: { include_elf, utils, ProverClient , ZKMProofWithPublicValues , ZKMStdin } ;
23
34/// The ELF we want to execute inside the zkVM.
45const ELF : & [ u8 ] = include_elf ! ( "fibonacci" ) ;
56
6- fn main ( ) {
7+ fn fib ( ) {
78 // Setup logging.
89 utils:: setup_logger ( ) ;
910
1011 // Create an input stream and write '1000' to it.
11- let n = 1000u32 ;
12+ let n = 100000u32 ;
1213
1314 // The input stream that the guest will read from using `zkm_zkvm::io::read`. Note that the
1415 // types of the elements in the input stream must match the types being read in the guest.
@@ -24,8 +25,11 @@ fn main() {
2425
2526 // Generate the proof for the given guest and input.
2627 let ( pk, vk) = client. setup ( ELF ) ;
28+ let start = Instant :: now ( ) ;
2729 let mut proof = client. prove ( & pk, stdin) . run ( ) . unwrap ( ) ;
28-
30+ let end = Instant :: now ( ) ;
31+ let duration = end. duration_since ( start) ;
32+ println ! ( "benchmark_sha2 end, duration: {:?}" , duration. as_secs_f64( ) ) ;
2933 println ! ( "generated proof" ) ;
3034
3135 // Read and verify the output.
@@ -52,3 +56,51 @@ fn main() {
5256
5357 println ! ( "successfully generated and verified proof for the program!" )
5458}
59+
60+ fn sha2 ( num_bytes : usize ) {
61+ // Setup logging.
62+ utils:: setup_logger ( ) ;
63+
64+ // The input stream that the guest will read from using `zkm_zkvm::io::read`. Note that the
65+ // types of the elements in the input stream must match the types being read in the guest.
66+ let mut stdin = ZKMStdin :: new ( ) ;
67+ let input = vec ! [ 5u8 ; num_bytes] ;
68+ stdin. write ( & input) ;
69+
70+ // Create a `ProverClient` method.
71+ let client = ProverClient :: new ( ) ;
72+
73+ // Execute the guest using the `ProverClient.execute` method, without generating a proof.
74+ let ( _, report) = client. execute ( ELF , stdin. clone ( ) ) . run ( ) . unwrap ( ) ;
75+ println ! ( "executed program with {} cycles" , report. total_instruction_count( ) ) ;
76+
77+ /*
78+ // Generate the proof for the given guest and input.
79+ let (pk, vk) = client.setup(ELF);
80+ let start = Instant::now();
81+ let mut proof = client.prove(&pk, stdin).run().unwrap();
82+ let end = Instant::now();
83+ let duration = end.duration_since(start);
84+ println!("benchmark_sha2 end, duration: {:?}", duration.as_secs_f64());
85+
86+ println!("generated proof");
87+
88+ // Verify proof and public values
89+ client.verify(&proof, &vk).expect("verification failed");
90+
91+ // Test a round trip of proof serialization and deserialization.
92+ proof.save("proof-with-pis.bin").expect("saving proof failed");
93+ let deserialized_proof =
94+ ZKMProofWithPublicValues::load("proof-with-pis.bin").expect("loading proof failed");
95+
96+ // Verify the deserialized proof.
97+ client.verify(&deserialized_proof, &vk).expect("verification failed");
98+ */
99+ println ! ( "successfully generated and verified proof for the program!" )
100+ }
101+
102+ fn main ( ) {
103+ sha2 ( 256 ) ;
104+ sha2 ( 512 ) ;
105+ sha2 ( 1048 ) ;
106+ }
0 commit comments