Skip to content

Commit

Permalink
Continuations, part 1 (risc0#461)
Browse files Browse the repository at this point in the history
Breaking Changes:
* Drop the `image_id` parameter to the `risc0_zkvm::Prover`. The Prover already computes the image_id from the supplied ELF binary.
* Replace `risc0_zkvm::MemoryImage::root` with `risc0_zkvm::MemoryImage::get_root()`, which computes the root merkle tree entry on-demand.
* Drop `VerificationError::SealJournalLengthMismatch`.
* Rename `VerificationError::JournalSealRootMismatch` to `VerificationError::JournalDigestMismatch`

Updates:
* New rv32im circuit which includes continuations support
* Add `env::pause` to the guest environment API
* Add a test for pause/continue

TODO:
* Implement system initiated splits
  • Loading branch information
flaub authored Mar 24, 2023
1 parent 396356f commit 0464535
Show file tree
Hide file tree
Showing 46 changed files with 187,630 additions and 160,990 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
fetch-depth: 0
- uses: ./.github/actions/rustup
- name: Install cargo-sort
uses: risc0/cargo-install@v1
uses: risc0/cargo-install@2cfb0024938d23011106cbf127b393bc83fddba1
with:
crate: cargo-sort
version: "1.0"
Expand Down
4 changes: 2 additions & 2 deletions examples/chess/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn main() {
};

// Make the prover.
let mut prover = Prover::new(CHECKMATE_ELF, CHECKMATE_ID).unwrap();
let mut prover = Prover::new(CHECKMATE_ELF).unwrap();

prover.add_input_u32_slice(&to_vec(&inputs).expect("Should be serializable"));

Expand Down Expand Up @@ -79,7 +79,7 @@ mod tests {
};

// Make the prover.
let mut prover = Prover::new(CHECKMATE_ELF, CHECKMATE_ID).unwrap();
let mut prover = Prover::new(CHECKMATE_ELF).unwrap();
prover.add_input_u32_slice(&to_vec(&inputs).expect("Should be serializable"));

// Run prover & generate receipt
Expand Down
2 changes: 1 addition & 1 deletion examples/digital-signature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn sign(pass_str: impl AsRef<[u8]>, msg_str: impl AsRef<[u8]>) -> Result<Sig
msg: msg,
};

let mut prover = Prover::new(SIGN_ELF, SIGN_ID)?;
let mut prover = Prover::new(SIGN_ELF)?;
let vec = to_vec(&params).unwrap();
prover.add_input_u32_slice(vec.as_slice());
let receipt = prover.run()?;
Expand Down
2 changes: 1 addition & 1 deletion examples/evm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async fn main() {

let zkdb = trace_db.create_zkdb();

let mut prover = Prover::new(EVM_ELF, EVM_ID).expect("Failed to construct prover");
let mut prover = Prover::new(EVM_ELF).expect("Failed to construct prover");

prover.add_input_u32_slice(&to_vec(&env).unwrap());
prover.add_input_u32_slice(&to_vec(&zkdb).unwrap());
Expand Down
4 changes: 2 additions & 2 deletions examples/factors/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn main() {

// Multiply them inside the ZKP
// First, we make the prover, loading the 'multiply' method
let mut prover = Prover::new(MULTIPLY_ELF, MULTIPLY_ID).expect(
let mut prover = Prover::new(MULTIPLY_ELF).expect(
"Prover should be constructed from valid method source code and corresponding method ID",
);

Expand Down Expand Up @@ -66,7 +66,7 @@ mod tests {

#[test]
fn run_factors() {
let mut prover = Prover::new(MULTIPLY_ELF, MULTIPLY_ID).expect(
let mut prover = Prover::new(MULTIPLY_ELF).expect(
"Prover should be constructed from valid method source code and corresponding method ID",
);

Expand Down
4 changes: 2 additions & 2 deletions examples/json/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn main() {
let data = include_str!("../res/example.json");

// Make the prover.
let mut prover = Prover::new(SEARCH_JSON_ELF, SEARCH_JSON_ID)
let mut prover = Prover::new(SEARCH_JSON_ELF)
.expect("Prover should be constructed from matching method code & ID");

prover.add_input_u32_slice(&to_vec(&data).expect("should be serializable"));
Expand Down Expand Up @@ -55,7 +55,7 @@ mod tests {
let data = include_str!("../res/example.json");

// Make the prover.
let mut prover = Prover::new(SEARCH_JSON_ELF, SEARCH_JSON_ID)
let mut prover = Prover::new(SEARCH_JSON_ELF)
.expect("Prover should be constructed from matching method code & ID");
prover.add_input_u32_slice(&to_vec(&data).expect("should be serializable"));

Expand Down
4 changes: 2 additions & 2 deletions examples/password-checker/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn main() {
};

// a new prover is created to run the pw_checker method
let mut prover = Prover::new(PW_CHECKER_ELF, PW_CHECKER_ID).unwrap();
let mut prover = Prover::new(PW_CHECKER_ELF).unwrap();

// Adding input to the prover makes it readable by the guest
let vec = to_vec(&request).unwrap();
Expand Down Expand Up @@ -65,7 +65,7 @@ mod tests {
};

// a new prover is created to run the pw_checker method
let mut prover = Prover::new(PW_CHECKER_ELF, PW_CHECKER_ID).unwrap();
let mut prover = Prover::new(PW_CHECKER_ELF).unwrap();

// Adding input to the prover makes it readable by the guest
let vec = to_vec(&request).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion examples/sha/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use sha_methods::{HASH_ELF, HASH_ID};

fn provably_hash(input: &str) -> Receipt {
// Make the prover.
let mut prover = Prover::new(HASH_ELF, HASH_ID)
let mut prover = Prover::new(HASH_ELF)
.expect("Prover should be constructed from matching code and method ID");

prover.add_input_u32_slice(&to_vec(input).expect("input string should serialize"));
Expand Down
4 changes: 2 additions & 2 deletions examples/waldo/src/bin/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use waldo_core::{
merkle::SYS_VECTOR_ORACLE,
PrivateInput,
};
use waldo_methods::{IMAGE_CROP_ELF, IMAGE_CROP_ID};
use waldo_methods::IMAGE_CROP_ELF;

#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
Expand Down Expand Up @@ -107,7 +107,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// the Merkle tree.
let prover_opts = ProverOpts::default()
.with_sendrecv_callback(SYS_VECTOR_ORACLE, img_merkle_tree.vector_oracle_callback());
let mut prover = Prover::new_with_opts(IMAGE_CROP_ELF, IMAGE_CROP_ID, prover_opts)?;
let mut prover = Prover::new_with_opts(IMAGE_CROP_ELF, prover_opts)?;

// Give the private input to the guest, including Waldo's location.
let input = PrivateInput {
Expand Down
2 changes: 1 addition & 1 deletion examples/wordle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'a> Server<'a> {
}

pub fn check_round(&self, guess_word: &str) -> Receipt {
let mut prover = Prover::new(WORDLE_ELF, WORDLE_ID).expect("failed to construct prover");
let mut prover = Prover::new(WORDLE_ELF).expect("failed to construct prover");

prover.add_input_u32_slice(to_vec(self.secret_word).unwrap().as_slice());
prover.add_input_u32_slice(to_vec(&guess_word).unwrap().as_slice());
Expand Down
2 changes: 1 addition & 1 deletion risc0/build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Risc0Method {
let elf = fs::read(&self.elf_path).unwrap();
let program = Program::load_elf(&elf, MEM_SIZE as u32).unwrap();
let image = MemoryImage::new(&program, PAGE_SIZE as u32);
image.root
image.get_root()
}

fn rust_def(&self) -> String {
Expand Down
Loading

0 comments on commit 0464535

Please sign in to comment.