Bonsai REST SDK

A library to handle HTTP REST requests to the Bonsai-alpha prover interface

Example Usage

```rust use std::time::Duration; use bonsaialphasdk::Client; use anyhow::{Result, Context}; use risc0zkvm::serde::tovec;

// serialize a given input for the guest let inputdata = tovec(&inputdata).unwrap(); let inputdata = bytemuck::castslice(&inputdata).to_vec();

// Construct the bonsaisdk client from the BONSAI_API_URL and // BONSAI_API_URL env vars. let client = Client::fromenv()?;

// Upload the ELF file of the guest to the prover let elfpath = Path::new(METHODNAMEPATH); let imgid = client.uploadimgfile(elfpath)?; // Optionally you can upload a MemoryImage as well, but bincode encoded: // let program = Program::loadelf(METHODNAMEELF, MEMSIZE as u32)?; // let image = MemoryImage::new(&program, PAGESIZE as u32)?; // let image = bincode::serialize(&image).context("Failed to serialize memoryimg")?; // client.upload_img(image)?

// Upload the serialized input let inputid = client.uploadinput(inputdata)?; // Start the prover session by referencing the imgid and inputid let session = client.createsession(imgid, inputid)?;

// Monitor the status of the prover session waiting for possible exit status loop { // Fetch the session status let res = session.status(&client)?; if res.status == "RUNNING" { // If its still running, continue waiting println!("Current status: {} - continue polling...", res.status); std::thread::sleep(Duration::fromsecs(POLLINTERVALSEC)); continue; } if res.status == "SUCCEEDED" { // If the session has been successful download the receipt let receipturl = res .receipturl .context("API error, missing receipt on completed session")?; println!("Session completed, downloading: {}", receipturl);

    let receipt_buf = client.download(&receipt_url)?;
    // Deserialize the receipt
    let receipt: SessionRollupReceipt = bincode::deserialize(&receipt_buf)?;

    // verify the the receipt
    receipt
        .verify(METHOD_NAME_ID)
        .context("Receipt verification failed")?;
    println!("Receipt verified locally!")
} else {
    bail!("Workflow exited: {}", res.status);
}

break;

} ```