@@ -5,7 +5,7 @@ use hex_literal::hex;
55// These constants represent the RISC-V ELF and the image ID generated by risc0-build.
66// The ELF is used for proving and the ID is used for verification.
77use methods:: { GUEST_ENCRYPT_ELF , GUEST_ENCRYPT_ID } ;
8- use risc0_zkvm:: { default_prover, ExecutorEnv } ;
8+ use risc0_zkvm:: { default_prover, sha :: Digest , ExecutorEnv } ;
99
1010fn main ( ) {
1111 // Initialize tracing. In order to view logs, run `RUST_LOG=info cargo run`
@@ -22,19 +22,13 @@ fn main() {
2222 let plaintext = hex ! ( "00010203 04050607 08090A0B 0C0D0E0F" ) ;
2323 println ! ( "Plaintext bytes: {:?}" , plaintext) ;
2424
25- // Key and IV must be references to the `GenericArray` type.
26- // Here we use the `Into` trait to convert arrays into it.
27- let mut cipher = ChaCha20 :: new ( & key. into ( ) , & nonce. into ( ) ) ;
28- // Generate raw keystream bytes
29- let mut keystream = [ 0u8 ; 16 ] ; // ChaCha20 generates keystream in 64-byte blocks, but this can be any number of bits.
30- cipher. apply_keystream ( & mut keystream) ; // keystream XOR with 0s = keystream
31- println ! ( "Keystream bytes: {:?}" , keystream) ;
32-
3325 // zkVM
3426 let env = ExecutorEnv :: builder ( )
35- . write ( & plaintext)
27+ . write ( & key)
28+ . unwrap ( )
29+ . write ( & nonce)
3630 . unwrap ( )
37- . write ( & keystream )
31+ . write ( & plaintext )
3832 . unwrap ( )
3933 . build ( )
4034 . unwrap ( ) ;
@@ -49,23 +43,26 @@ fn main() {
4943 // extract the receipt.
5044 let receipt = prove_info. receipt ;
5145
52- let mut output: [ u8 ; 16 ] = receipt. journal . decode ( ) . unwrap ( ) ;
53- println ! ( "zkVM output bytes: {:?}" , output) ;
46+ let mut output: ( Digest , [ u8 ; 16 ] ) = receipt. journal . decode ( ) . unwrap ( ) ;
47+ println ! ( "zkVM -> plaintext hash: {:?}" , output. 0 ) ;
48+ println ! ( "zkVM -> ciphertext bytes: {:?}" , output. 1 ) ;
5449
5550 let ciphertext = hex ! ( "e405626e 4f1236b3 670ee428 332ea20e" ) ;
5651 println ! ( "expected output bytes: {:?}" , ciphertext) ;
5752
5853 // The receipt was verified at the end of proving, but the below code is an
5954 // example of how someone else could verify this receipt.
60- receipt
61- . verify ( GUEST_ENCRYPT_ID )
62- . unwrap ( ) ;
55+ receipt. verify ( GUEST_ENCRYPT_ID ) . unwrap ( ) ;
6356 println ! ( "Reciept from zkVM OK!" ) ;
64-
57+
58+ // Key and IV must be references to the `GenericArray` type.
59+ // Here we use the `Into` trait to convert arrays into it.
60+ let mut cipher = ChaCha20 :: new ( & key. into ( ) , & nonce. into ( ) ) ;
61+
6562 // ChaCha ciphers support seeking
6663 cipher. seek ( 0u32 ) ;
6764
6865 // decrypt ciphertext by applying keystream again
69- cipher. apply_keystream ( & mut output) ;
70- assert_eq ! ( output, plaintext) ;
66+ cipher. apply_keystream ( & mut output. 1 ) ;
67+ assert_eq ! ( output. 1 , plaintext) ;
7168}
0 commit comments