|
1 | | -use chacha20::cipher::{KeyIvInit, StreamCipher}; |
| 1 | +use chacha20::cipher::{KeyIvInit, StreamCipher, StreamCipherSeek}; |
2 | 2 | use chacha20::ChaCha20; |
3 | 3 | use hex_literal::hex; |
4 | 4 |
|
5 | 5 | // These constants represent the RISC-V ELF and the image ID generated by risc0-build. |
6 | 6 | // The ELF is used for proving and the ID is used for verification. |
7 | 7 | use methods::{GUEST_ENCRYPT_ELF, GUEST_ENCRYPT_ID}; |
8 | | -use risc0_zkvm::{default_executor, ExecutorEnv}; |
| 8 | +use risc0_zkvm::{default_prover, ExecutorEnv}; |
9 | 9 |
|
10 | 10 | fn main() { |
11 | 11 | // Initialize tracing. In order to view logs, run `RUST_LOG=info cargo run` |
@@ -40,26 +40,32 @@ fn main() { |
40 | 40 | .unwrap(); |
41 | 41 |
|
42 | 42 | // testing Execution ONLY |
43 | | - let prover = default_executor(); |
| 43 | + let prover = default_prover(); |
44 | 44 |
|
45 | 45 | // Proof information by proving the specified ELF binary. |
46 | 46 | // This struct contains the receipt along with statistics about execution of the guest |
47 | | - let prove_info = prover.execute(env, GUEST_ENCRYPT_ELF).unwrap(); |
| 47 | + let prove_info = prover.prove(env, GUEST_ENCRYPT_ELF).unwrap(); |
48 | 48 |
|
49 | 49 | // extract the receipt. |
50 | | - // let receipt = prove_info.receipt; |
| 50 | + let receipt = prove_info.receipt; |
51 | 51 |
|
52 | | - // let output: [u8; 16] = receipt.journal.decode().unwrap(); |
53 | | - |
54 | | - let output: [u8; 16] = prove_info.journal.decode().unwrap(); |
55 | | - println!("output bytes: {:?}", output); |
| 52 | + let mut output: [u8; 16] = receipt.journal.decode().unwrap(); |
| 53 | + println!("zkVM output bytes: {:?}", output); |
56 | 54 |
|
57 | 55 | let ciphertext = hex!("e405626e 4f1236b3 670ee428 332ea20e"); |
58 | 56 | println!("expected output bytes: {:?}", ciphertext); |
59 | 57 |
|
60 | | - // // The receipt was verified at the end of proving, but the below code is an |
61 | | - // // example of how someone else could verify this receipt. |
62 | | - // receipt |
63 | | - // .verify(GUEST_ENCRYPT_ID) |
64 | | - // .unwrap(); |
| 58 | + // The receipt was verified at the end of proving, but the below code is an |
| 59 | + // example of how someone else could verify this receipt. |
| 60 | + receipt |
| 61 | + .verify(GUEST_ENCRYPT_ID) |
| 62 | + .unwrap(); |
| 63 | + println!("Reciept from zkVM OK!"); |
| 64 | + |
| 65 | + // ChaCha ciphers support seeking |
| 66 | + cipher.seek(0u32); |
| 67 | + |
| 68 | + // decrypt ciphertext by applying keystream again |
| 69 | + cipher.apply_keystream(&mut output); |
| 70 | + assert_eq!(output, plaintext); |
65 | 71 | } |
0 commit comments