Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another round of suggestions for the no-relay template #82

Merged
merged 13 commits into from
Feb 22, 2024
Merged
50 changes: 31 additions & 19 deletions Cargo.lock

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

11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ bytemuck = { version = "1.14" }
ethers = { version = "2.0" }
hex = { version = "0.4" }
log = { version = "0.4" }
methods = { path = "./methods", package = "bonsai-starter-methods" }
# DO NOT MERGE: Figure out what reference to use for this. Cherry pick to the release branch?
risc0-build = { git = "https://github.com/risc0/risc0", rev = "7f73166", features = ["docker"] }
risc0-ethereum-contracts = { git = "https://github.com/risc0/risc0-ethereum" }
methods = { path = "./methods" }
# NOTE: Using a git rev temporarily to get an unreleased version of risc0-build.
# Once the referenced commit is in a released version of risc0-build, this will go back to using a version.
risc0-build = { git = "https://github.com/risc0/risc0", rev = "7f731662", features = ["docker"] }
# DO NOT MERGE: Provide a release branch to use as the reference here, and for the submodule ref.
risc0-build-ethereum = { git = "https://github.com/risc0/risc0-ethereum", rev = "971a74e8" }
risc0-ethereum-contracts = { git = "https://github.com/risc0/risc0-ethereum", rev = "971a74e8" }
risc0-zkvm = { version = "0.20", default-features = false }
risc0-zkp = { version = "0.20", default-features = false }
serde = { version = "1.0", features = ["derive", "std"] }
Expand Down
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Bonsai Foundry Template
# RISC Zero Foundry Template

> **Note: This software is not production ready. Do not use in production.**

Expand All @@ -12,7 +12,7 @@ Prove computation with the [RISC Zero zkVM] and verify the results in your Ether

Here is a simplified overview of how devs can integrate RISC Zero, with [Bonsai] proving, into their Ethereum smart contracts:

![Bonsai Foundry Template Diagram](images/bonsai-foundry-template.png)
![RISC Zero Foundry Template Diagram](images/risc0-foundry-template.png)

1. Run your application logic in the [RISC Zero zkVM]. The provided [publisher] app sends an off-chain proof request to the [Bonsai] proving service.
2. [Bonsai] generates the program result, written to the [journal], and a SNARK proof of its correctness.
Expand Down Expand Up @@ -46,7 +46,7 @@ Now you have all the tools you need to develop and deploy an application with [R

First, install the RISC Zero toolchain using the [instructions above](#dependencies).

Now, you can initialize a new Bonsai project at a location of your choosing:
Now, you can initialize a new RISC Zero project at a location of your choosing:

```sh
forge init -t risc0/bonsai-foundry-template ./my-project
Expand All @@ -61,6 +61,22 @@ Your new project consists of:
- a [publisher] which makes proving requests to [Bonsai] and posts the proof to Ethereum.
We provide an example implementation, but your dApp interface or application servers could act as the publisher.

### Build the Code

- Builds for zkVM program, the publisher app, and any other Rust code.

```sh
cargo build
```

- Build your Solidity smart contracts

> NOTE: `cargo build` needs to run first to generate the `ImageID.sol` contract.

```sh
forge build
```

### Run the Tests

- Tests your zkVM program.
Expand Down Expand Up @@ -120,7 +136,8 @@ Below are the primary files in the project directory
│ └── bin
│ └── publisher.rs // Example app to publish program results into your app contract
├── contracts
│ └── EvenNumber.sol // Basic example contract for you to modify
│ ├── EvenNumber.sol // Basic example contract for you to modify
│ └── ImageID.sol // Generated contract with the image ID for your zkVM program
├── methods
│ ├── Cargo.toml
│ ├── guest
Expand All @@ -132,7 +149,7 @@ Below are the primary files in the project directory
│ └── lib.rs // Compiled image IDs and tests for your guest programs
└── tests
├── EvenNumber.t.sol // Tests for the basic example contract
└── MockRiscZeroVerifier.sol // RISC Zero Verifier mock contract
└── Elf.sol // Generated contract with paths the guest program ELF files.
```

[Bonsai]: https://dev.bonsai.xyz/
Expand Down
2 changes: 1 addition & 1 deletion apps/src/bin/publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use apps::{BonsaiProver, TxSender};
use clap::Parser;
use methods::IS_EVEN_ELF;

// `IEvenNumber`` interface automatically generated via the alloy `sol!` macro.
// `IEvenNumber` interface automatically generated via the alloy `sol!` macro.
sol! {
interface IEvenNumber {
function set(uint256 x, bytes32 post_state_digest, bytes calldata seal);
Expand Down
12 changes: 6 additions & 6 deletions apps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ impl BonsaiProver {
let receipt: Receipt = bincode::deserialize(&receipt_buf)?;

break receipt;
} else {
panic!(
"Workflow exited: {} - | err: {}",
res.status,
res.error_msg.unwrap_or_default()
);
}

panic!(
"Workflow exited: {} - | err: {}",
res.status,
res.error_msg.unwrap_or_default()
);
};

// Fetch the snark.
Expand Down
14 changes: 7 additions & 7 deletions contracts/EvenNumber.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,26 @@

pragma solidity ^0.8.20;

import {IRiscZeroVerifier} from "bonsai/IRiscZeroVerifier.sol";
import {IRiscZeroVerifier} from "risc0/IRiscZeroVerifier.sol";
import {ImageID} from "./ImageID.sol"; // auto-generated contract after running `cargo build`.

/// @title A starter application using Bonsai.
/// @title A starter application using RISC Zero.
/// @notice This basic application holds a number, guaranteed to be even.
/// @dev This contract demonstrates one pattern for offloading the computation of an expensive
/// or difficult to implement function to a RISC Zero guest running on Bonsai.
contract EvenNumber {
/// @notice RISC Zero verifier contract address.
IRiscZeroVerifier immutable verifier;
IRiscZeroVerifier public immutable verifier;
/// @notice Image ID of the only zkVM binary to accept verification from.
bytes32 immutable imageId;
bytes32 public constant imageId = ImageID.IS_EVEN_ID;

/// @notice A number that is guaranteed, by the RISC Zero zkVM, to be even.
/// It can be set by calling the `set` function.
uint256 number;
uint256 public number;

/// @notice Initialize the contract, binding it to a specified RISC Zero verifier and guest image.
/// @notice Initialize the contract, binding it to a specified RISC Zero verifier.
constructor(IRiscZeroVerifier _verifier) {
verifier = _verifier;
imageId = ImageID.IS_EVEN_ID;
number = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Specifically:
- `ImageID.sol`: contains the ImageIDs for the guests implemented in the [methods] directory.
- `Elf.sol`: contains the path of the guest binaries implemented in the [methods] directory. This contract is saved in the `tests` directory in the root of this template.

The Solidity libraries for Bonsai can be found at [github.com/risc0/risc0-ethereum].
The Solidity libraries for RISC Zero can be found at [github.com/risc0/risc0-ethereum].

Contracts are built and tested with [forge], which is part of the [Foundry] toolkit.
Tests are defined in the `tests` directory in the root of this template.
Expand Down
File renamed without changes
3 changes: 2 additions & 1 deletion methods/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "bonsai-starter-methods"
name = "methods"
version = { workspace = true }
edition = { workspace = true }

Expand All @@ -9,6 +9,7 @@ methods = ["guest"]
[build-dependencies]
hex = { workspace = true }
risc0-build = { workspace = true }
risc0-build-ethereum = { workspace = true }
risc0-zkp = { workspace = true }

[dev-dependencies]
Expand Down
Loading
Loading