Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ common = { path = "common" }
chacha20 = "0.9.1"
hex-literal = "1.0.0"

lz4_flex = "0.11"

risc0-zkvm = { version = "2.0", default-features = false, features = ['std'] }
risc0-build = "2.0"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
Expand Down
1 change: 1 addition & 0 deletions host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ hex-literal.workspace = true
risc0-zkvm = { workspace = true, default-features = true }
tracing-subscriber.workspace = true
serde.workspace = true
lz4_flex.workspace = true

[features]
cuda = ["risc0-zkvm/cuda"]
6 changes: 5 additions & 1 deletion host/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use chacha20::cipher::{KeyIvInit, StreamCipher};
use chacha20::ChaCha20;

use lz4_flex::decompress_size_prepended;
// These constants represent the RISC-V ELF and the image ID generated by risc0-build.
// The ELF is used for proving and the ID is used for verification.
use methods::GUEST_ENCRYPT_ELF;
Expand Down Expand Up @@ -74,7 +75,10 @@ fn main() {
// decrypt ciphertext by applying keystream again
cipher.apply_keystream(&mut output_buffer);

assert_eq!(output_buffer, plaintext);
let decompressed_output =
decompress_size_prepended(&output_buffer).expect("Unable to decompress output");

assert_eq!(decompressed_output, plaintext);
println!("Decryption of zkVM ciphertext matches input!");
println!(
"Output size to publish to DA = {} bytes (seal), {} bytes (ciphertext)",
Expand Down
2 changes: 2 additions & 0 deletions methods/guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ edition.workspace = true
[dependencies]
common.workspace = true

lz4_flex.workspace = true

risc0-zkvm = { workspace = true, default-features = false, features = ['std'] }
chacha20.workspace = true
6 changes: 4 additions & 2 deletions methods/guest/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use chacha20::cipher::{KeyIvInit, StreamCipher};
use chacha20::ChaCha20;
use lz4_flex::compress_prepend_size;
use risc0_zkvm::{
guest::env,
sha::{Impl, Sha256},
Expand All @@ -25,15 +26,16 @@ fn main() {
// TODO:
// - Hash key and/or nonce & commit?

let mut compressed_input = compress_prepend_size(&buffer);
// Key and IV must be references to the `GenericArray` type.
// Here we use the `Into` trait to convert arrays into it.
let mut cipher = ChaCha20::new(&key.into(), &nonce.into());

// Write ciphertext into buffer by applying keystream to plaintext
cipher.apply_keystream(&mut buffer);
cipher.apply_keystream(&mut compressed_input);

// write public output to the journal
env::commit_slice(&buffer);
env::commit_slice(&compressed_input);

let end = env::cycle_count();
eprintln!("*-*-*-* CYCLE COUNT: {}", end - start);
Expand Down