Skip to content

Commit

Permalink
Merge branch 'main' into fix/execution-failure
Browse files Browse the repository at this point in the history
  • Loading branch information
Wollac authored Oct 4, 2024
2 parents e54e803 + ee1c455 commit 61cdd87
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ You can install [Steel] with `cargo add risc0-steel`, check out the examples in
[template]: https://github.com/risc0/bonsai-foundry-template
[dev.risczero.com]: https://dev.risczero.com
[risc0-quickstart]: https://dev.risczero.com/api/zkvm/quickstart
[bonsai-quickstart]: https://dev.risczero.com/api/bonsai/quickstart
[bonsai-quickstart]: https://dev.risczero.com/bonsai
[alloy]: https://github.com/alloy-rs
9 changes: 8 additions & 1 deletion contracts/src/test/RiscZeroCheats.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ import {Strings2} from "./utils/Strings2.sol";
abstract contract RiscZeroCheats is CommonBase {
using Strings2 for bytes;

/// @dev Journal and Seal struct used to decode the journal and seal from the `risc0-forge-ffi` `prove` command.
struct JournalSeal {
bytes journal;
bytes seal;
}

/// @notice Returns whether we are using the prover and verifier in dev-mode, or fully verifying.
/// @dev This environment variable, along with the respective options in the zkVM, are controlled
/// with the `RISC0_DEV_MODE` environment variable.
Expand Down Expand Up @@ -64,7 +70,8 @@ abstract contract RiscZeroCheats is CommonBase {
imageRunnerInput[i++] = "prove";
imageRunnerInput[i++] = elf_path;
imageRunnerInput[i++] = input.toHexString();
return abi.decode(vm.ffi(imageRunnerInput), (bytes, bytes));
JournalSeal memory journalSeal = abi.decode(vm.ffi(imageRunnerInput), (JournalSeal));
return (journalSeal.journal, journalSeal.seal);
}

/// @notice Deploy either a test or fully verifying `RiscZeroGroth16Verifier` depending on `devMode()`.
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ Explore a more advanced interaction between [Steel] and a custom Ethereum smart
This example shows how the [Steel] library can be used to call multiple view functions of a contract.
This example generates a proof of a [Compound] cToken's APR (Annual Percentage Rate), showcasing the potential for on-chain verification of complex financial metrics.

[coprocessor]: https://www.risczero.com/news/a-guide-to-zk-coprocessors-for-scalability
[coprocessor]: https://risczero.com/blog/a-guide-to-zk-coprocessors-for-scalability
[Steel]: ../steel
[Compound]: https://compound.finance/
2 changes: 1 addition & 1 deletion examples/erc20-counter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ When you're ready, follow the [deployment guide] to get your application running
[Sepolia]: https://www.alchemy.com/overviews/sepolia-testnet
[deployment guide]: ./deployment-guide.md
[Rust]: https://doc.rust-lang.org/cargo/getting-started/installation.html
[Counter]: ./contracts/Counter.sol
[Counter]: ./contracts/src/Counter.sol
[Steel]: https://www.risczero.com/blog/introducing-steel
2 changes: 1 addition & 1 deletion examples/erc20-counter/apps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ Options:
```

[publisher]: ./src/bin/publisher.rs
[Counter]: ../contracts/Counter.sol
[Counter]: ../contracts/src/Counter.sol
4 changes: 2 additions & 2 deletions examples/erc20-counter/methods/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ Each will have a corresponding image ID, which is a hash identifying the program
[guest programs]: https://dev.risczero.com/terminology#guest-program
[on-chain logic]: ../contracts/
[guest/src/bin]: ./guest/src/bin/
[Guest Code 101]: https://dev.risczero.com/zkvm/developer-guide/guest-code-101
[RISC Zero examples]: https://github.com/risc0/tree/v0.18.0/examples
[Guest Code 101]: https://dev.risczero.com/api/zkvm/guest-code-101
[RISC Zero examples]: https://github.com/risc0/risc0/tree/main/examples
2 changes: 1 addition & 1 deletion examples/erc20/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ To get started, you need to have Rust installed. If you haven't done so, follow

Next, you will also need to have the `cargo-risczero` tool installed following the instructions [here][install-risczero].

You'll also need access to an Ethereum Sepolia RPC endpoint. You can for example use [ethereum-sepolia-rpc.publicnode.com](https://ethereum-sepolia-rpc.publicnode.com) or a commercial RPC provider like [Alchemy](www.alchemy.com).
You'll also need access to an Ethereum Sepolia RPC endpoint. You can for example use [ethereum-sepolia-rpc.publicnode.com](https://ethereum-sepolia-rpc.publicnode.com) or a commercial RPC provider like [Alchemy](https://www.alchemy.com/).

## Run the example

Expand Down
2 changes: 1 addition & 1 deletion examples/governance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ This hash accumulator (`ballotHash`) is a commitment that allows offchain voting
[Governor]: https://docs.openzeppelin.com/contracts/4.x/governance
[instructions]: ./instructions.md
[journal]: https://dev.risczero.com/terminology#journal
[RiscZeroGovernor.sol]: ./contracts/RiscZeroGovernor.sol
[RiscZeroGovernor.sol]: ./contracts/src/RiscZeroGovernor.sol
[verifier contract]: https://dev.risczero.com/api/blockchain-integration/contracts/verifier
[What does Risc Zero enable]: https://dev.risczero.com/api/use-cases
[zkVM]: https://dev.risczero.com/zkvm
Expand Down
2 changes: 1 addition & 1 deletion examples/token-stats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ To get started, you need to have Rust installed. If you haven't done so, follow

Next, you will also need to have the `cargo-risczero` tool installed following the instructions [here][install-risczero].

You'll also need access to an Ethereum Mainnet RPC endpoint. You can for example use [ethereum-rpc.publicnode.com](https://ethereum-rpc.publicnode.com/) or a commercial RPC provider like [Alchemy](www.alchemy.com).
You'll also need access to an Ethereum Mainnet RPC endpoint. You can for example use [ethereum-rpc.publicnode.com](https://ethereum-rpc.publicnode.com/) or a commercial RPC provider like [Alchemy](https://www.alchemy.com/).

## Run the example

Expand Down
2 changes: 0 additions & 2 deletions ffi/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# RISC Zero Forge FFI

This tool provides a Command Line Interface (CLI) enabling the communication between the [Foundry Forge ffi cheatcode](https://book.getfoundry.sh/cheatcodes/ffi) and the RISC Zero zkVM.

The [BonsaiCheat](../contracts/src/BonsaiCheats.sol) contract shows an example of how to integrate this tool.
22 changes: 22 additions & 0 deletions ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2024 RISC Zero, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

alloy::sol! {
/// Journal and Seal as returned by the `prove` command.
#[sol(all_derives)]
struct JournalSeal {
bytes journal;
bytes seal;
}
}
8 changes: 6 additions & 2 deletions ffi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ use std::{
os::unix::io::{AsRawFd, FromRawFd},
};

use alloy::{primitives::Bytes, sol_types::SolValue};
use alloy::sol_types::SolValue;
use anyhow::{ensure, Context, Result};
use clap::Parser;
use risc0_ethereum_contracts::encode_seal;
use risc0_forge_ffi::JournalSeal;
use risc0_zkvm::{default_prover, ExecutorEnv, ProverOpts, VerifierContext};

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -64,7 +65,10 @@ pub fn main() -> Result<()> {
fn prove_ffi(elf_path: String, input: Vec<u8>) -> Result<Vec<u8>> {
let elf = std::fs::read(elf_path).expect("failed to read guest ELF");
let (journal, seal) = prove(&elf, &input)?;
let calldata = (Bytes(journal.into()), Bytes(seal.into()));
let calldata = JournalSeal {
journal: journal.into(),
seal: seal.into(),
};
Ok(calldata.abi_encode())
}

Expand Down
11 changes: 8 additions & 3 deletions ffi/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

use std::process::Command;

use alloy::{primitives::Bytes, sol_types::SolValue};
use alloy::sol_types::SolValue;
use ffi_guests::{ECHO_ID, ECHO_PATH};
use risc0_ethereum_contracts::encode_seal;
use risc0_forge_ffi::JournalSeal;
use risc0_zkvm::{FakeReceipt, InnerReceipt, Receipt, ReceiptClaim};

#[test]
Expand All @@ -36,7 +37,9 @@ fn basic_usage() {
println!("{:#?}", &output);

let output_bytes = hex::decode(output.stdout).unwrap();
let (journal, seal) = <(Bytes, Bytes)>::abi_decode(&output_bytes, true).unwrap();
let journal_seal = <JournalSeal>::abi_decode(&output_bytes, true).unwrap();
let journal = journal_seal.journal;
let seal = journal_seal.seal;

assert_eq!(journal, hex::decode("deadbeef").unwrap());
let expected_receipt = Receipt::new(
Expand Down Expand Up @@ -70,7 +73,9 @@ fn basic_usage_with_rust_log() {
println!("{:#?}", &output);

let output_bytes = hex::decode(output.stdout).unwrap();
let (journal, seal) = <(Bytes, Bytes)>::abi_decode(&output_bytes, true).unwrap();
let journal_seal = <JournalSeal>::abi_decode(&output_bytes, true).unwrap();
let journal = journal_seal.journal;
let seal = journal_seal.seal;

assert_eq!(journal, hex::decode("deadbeef").unwrap());
let expected_receipt = Receipt::new(
Expand Down

0 comments on commit 61cdd87

Please sign in to comment.