Shake256 demo using R0#13
Open
moudyellaz wants to merge 24 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Purpose
This PR adds a minimal end-to-end SHAKE256 XOR-encryption demo on RISC Zero.
⚙️ Approach
This demo proves the correct execution of a simple stream encryption built from
SHAKE256. We derive an encryption key with an NSSA-style KDF (SHA-256 over domain-separated inputs), then useSHAKE256to expand that key + context info into a keystream and XOR it with the plaintext.Note: this is encryption-only (no MAC); don’t use in production without integrity/authentication. Also, never reuse the same (key, info) pair for two different messages.
Flow
Guest (inside zkVM) —
methods/guest/src/main.rsReads
EncInputfrom the zkVM environment:ss_bytes: [u8; 32]epk_bytes: Vec<u8>(33 bytes expected)ipk_bytes: Vec<u8>(33 bytes expected)commitment: [u8; 32]out_index: u32Builds
info = epk_bytes || ipk_bytes || commitment.Derives
k_enc = SHA256("NSSA/v0.1/KDF-SHA256" || ss || epk || ipk || commitment || out_index_le).Runs
SHAKE256over a domain string +k_enc+infoto get a keystream, XORs with the demo plaintext, and commits the ciphertext to the journal.Host / Prover —
src/main.rsBuilds an
ExecutorEnvwithEncInputand invokesdefault_prover().prove(env, GUEST_ELF).Receives a receipt containing:
Verifier —
src/main.rsreceipt.verify(GUEST_ID).GUEST_ID.Why this matters
SHAKE256keystream is straightforward; the difficult part is trust.Files
methods/guest/src/main.rs— guest logic (#[entry]function), KDF + SHAKE256 XORsrc/lib.rs— shared types (EncInput), KDF / SHAKE helpers (host-side re-exports)src/main.rs— host runner (prove + verify + read journal)build.rs— emitsmethods.rs(guest image bindings)Cargo.toml(guest) —tiny-keccakwithfeatures = ["shake"]Notes / Gotchas
tiny-keccak’sShake(features = ["shake"]) on the guest side.sha2. Where bothDigestandUpdateare in scope, we disambiguate withsha2::Digest::update(...).receipt.receipt.journal.bytesis a field (use.clone()/to_vec()as needed).🧪 How to Run
From repo root:
# Build and run the demo cargo clean -p shake256-demo cargo build -p shake256-demo cargo run -p shake256-demo --releaseOutput (example): the host prints the ciphertext hex and verifies the receipt against
GUEST_ID.🔗 Dependencies
The encryption section in NSSA v0.1 specs.
Guest
Cargo.tomlrequires:🔜 Future Work
cargo bench.cargo test+ example run.📋 PR Completion Checklist