29个版本 (8个破坏性版本)

1.1.0-rc.2 2024年8月22日
0.9.1 2024年8月9日
0.9.0 2024年7月11日
0.7.0 2024年3月12日
0.2.0 2023年7月11日

666网络编程

Download history 2125/week @ 2024-05-03 2453/week @ 2024-05-10 2670/week @ 2024-05-17 1620/week @ 2024-05-24 2031/week @ 2024-05-31 2018/week @ 2024-06-07 1969/week @ 2024-06-14 2380/week @ 2024-06-21 2105/week @ 2024-06-28 2881/week @ 2024-07-05 3140/week @ 2024-07-12 2815/week @ 2024-07-19 3431/week @ 2024-07-26 3190/week @ 2024-08-02 2997/week @ 2024-08-09 2140/week @ 2024-08-16

12,221 每月下载
用于 4 crates

Apache-2.0

555KB
27K SLoC

用于处理发送到Bonsai-alpha证明者接口的HTTP REST请求的库

模块提供了阻塞和非阻塞(异步)版本。

示例用法

use std::time::Duration;

use anyhow::Result;
use bonsai_sdk::blocking::Client;
use methods::{METHOD_ELF, METHOD_ID};
use risc0_zkvm::{compute_image_id, serde::to_vec, Receipt};

fn run_bonsai(input_data: Vec<u8>) -> Result<()> {
    let client = Client::from_env(risc0_zkvm::VERSION)?;

    // Compute the image_id, then upload the ELF with the image_id as its key.
    let image_id = hex::encode(compute_image_id(METHOD_ELF)?);
    client.upload_img(&image_id, METHOD_ELF.to_vec())?;

    // Prepare input data and upload it.
    let input_data = to_vec(&input_data).unwrap();
    let input_data = bytemuck::cast_slice(&input_data).to_vec();
    let input_id = client.upload_input(input_data)?;

    // Add a list of assumptions
    let assumptions: Vec<String> = vec![];

    // Wether to run in execute only mode
    let execute_only = false;

    // Start a session running the prover
    let session = client.create_session(image_id, input_id, assumptions, execute_only)?;
    loop {
        let res = session.status(&client)?;
        if res.status == "RUNNING" {
            eprintln!(
                "Current status: {} - state: {} - continue polling...",
                res.status,
                res.state.unwrap_or_default()
            );
            std::thread::sleep(Duration::from_secs(15));
            continue;
        }
        if res.status == "SUCCEEDED" {
            // Download the receipt, containing the output
            let receipt_url = res
                .receipt_url
                .expect("API error, missing receipt on completed session");

            let receipt_buf = client.download(&receipt_url)?;
            let receipt: Receipt = bincode::deserialize(&receipt_buf)?;
            receipt
                .verify(METHOD_ID)
                .expect("Receipt verification failed");
        } else {
            panic!(
                "Workflow exited: {} - | err: {}",
                res.status,
                res.error_msg.unwrap_or_default()
            );
        }

        break;
    }

    // Optionally run stark2snark
    // run_stark2snark(session.uuid)?;

    Ok(())
}

STARK到SNARK

在生成STARK证明后,可以将证明转换为SNARK。

示例

use std::time::Duration;

use anyhow::Result;
use bonsai_sdk::blocking::Client;

fn run_stark2snark(session_id: String) -> Result<()> {
    let client = Client::from_env(risc0_zkvm::VERSION)?;

    let snark_session = client.create_snark(session_id)?;
    eprintln!("Created snark session: {}", snark_session.uuid);
    loop {
        let res = snark_session.status(&client)?;
        match res.status.as_str() {
            "RUNNING" => {
                eprintln!("Current status: {} - continue polling...", res.status,);
                std::thread::sleep(Duration::from_secs(15));
                continue;
            }
            "SUCCEEDED" => {
                let snark_receipt = res.output;
                eprintln!("Snark proof!: {snark_receipt:?}");
                break;
            }
            _ => {
                panic!(
                    "Workflow exited: {} err: {}",
                    res.status,
                    res.error_msg.unwrap_or_default()
                );
            }
        }
    }
    Ok(())
}

依赖项

~11–24MB
~370K SLoC