-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WEB3-144: Fix incorrect encoding used by prove cheatcode (#254)
With the change from `ethers` to `alloy`, we made an error in assuming they'd handle ABI encoding of `Vec<_>` the same. This broke the `prove` cheatcode that is used in the Foundry template tests. We did not catch this error prior to releasing, because we had moved all our tests in this repo over to using `RiscZeroMockVerifier.mockProve` instead and forgot to add test coverage specifically for this cheatcode. This PR fixes the encoding issue and additionally adds a simple test for using `risc0-forge-ffi` in dev mode. Additionally, this PR solves a problem where the FFI cheatcode would fail if `RUST_LOG` is set. --------- Co-authored-by: Wolfgang Welz <[email protected]>
- Loading branch information
Showing
11 changed files
with
232 additions
and
18 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[package] | ||
name = "ffi-guests" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[build-dependencies] | ||
risc0-build = { workspace = true } | ||
|
||
[package.metadata.risc0] | ||
methods = ["echo"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// 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. | ||
|
||
fn main() { | ||
risc0_build::embed_methods(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[package] | ||
name = "echo" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[workspace] | ||
|
||
[dependencies] | ||
risc0-zkvm = { git = "https://github.com/risc0/risc0", branch = "main", default-features = false, features = ["std"] } | ||
|
||
[profile.release] | ||
debug = 1 | ||
lto = "thin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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. | ||
|
||
use std::io::Read; | ||
|
||
use risc0_zkvm::guest::env; | ||
|
||
pub fn main() { | ||
// Read the entire input stream as raw bytes. | ||
let mut message = Vec::<u8>::new(); | ||
env::stdin().read_to_end(&mut message).unwrap(); | ||
|
||
// Commit exactly what the host provided to the journal. | ||
env::commit_slice(message.as_slice()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// 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. | ||
|
||
include!(concat!(env!("OUT_DIR"), "/methods.rs")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// 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. | ||
|
||
use std::process::Command; | ||
|
||
use alloy::{primitives::Bytes, sol_types::SolValue}; | ||
use ffi_guests::{ECHO_ID, ECHO_PATH}; | ||
use risc0_ethereum_contracts::encode_seal; | ||
use risc0_zkvm::{FakeReceipt, InnerReceipt, Receipt, ReceiptClaim}; | ||
|
||
#[test] | ||
fn basic_usage() { | ||
let exe_path = env!("CARGO_BIN_EXE_risc0-forge-ffi"); | ||
let args = ["prove", ECHO_PATH, "0xdeadbeef"]; | ||
println!("{} {:?}", exe_path, args); | ||
let output = Command::new(exe_path) | ||
.env_clear() | ||
// PATH is required so r0vm can be found. | ||
.env("PATH", std::env::var("PATH").unwrap()) | ||
.env("RISC0_DEV_MODE", "1") | ||
.args(args) | ||
.output() | ||
.unwrap(); | ||
|
||
println!("{:#?}", &output); | ||
|
||
let output_bytes = hex::decode(output.stdout).unwrap(); | ||
let (journal, seal) = <(Bytes, Bytes)>::abi_decode(&output_bytes, true).unwrap(); | ||
|
||
assert_eq!(journal, hex::decode("deadbeef").unwrap()); | ||
let expected_receipt = Receipt::new( | ||
InnerReceipt::Fake(FakeReceipt::new(ReceiptClaim::ok( | ||
ECHO_ID, | ||
journal.to_vec(), | ||
))), | ||
journal.into(), | ||
); | ||
let expect_seal = encode_seal(&expected_receipt).unwrap(); | ||
assert_eq!(expect_seal, seal.to_vec()); | ||
} | ||
|
||
// It's important that `risc0-forge-ffi` only send to stdout the output to be consumed by forge | ||
// with the FFI cheatcode. If any extra output is sent, ABI decoding will fail. | ||
#[test] | ||
fn basic_usage_with_rust_log() { | ||
let exe_path = env!("CARGO_BIN_EXE_risc0-forge-ffi"); | ||
let args = ["prove", ECHO_PATH, "0xdeadbeef"]; | ||
println!("{} {:?}", exe_path, args); | ||
let output = Command::new(exe_path) | ||
.env_clear() | ||
// PATH is required so r0vm can be found. | ||
.env("PATH", std::env::var("PATH").unwrap()) | ||
.env("RISC0_DEV_MODE", "1") | ||
.env("RUST_LOG", "debug") | ||
.args(args) | ||
.output() | ||
.unwrap(); | ||
|
||
println!("{:#?}", &output); | ||
|
||
let output_bytes = hex::decode(output.stdout).unwrap(); | ||
let (journal, seal) = <(Bytes, Bytes)>::abi_decode(&output_bytes, true).unwrap(); | ||
|
||
assert_eq!(journal, hex::decode("deadbeef").unwrap()); | ||
let expected_receipt = Receipt::new( | ||
InnerReceipt::Fake(FakeReceipt::new(ReceiptClaim::ok( | ||
ECHO_ID, | ||
journal.to_vec(), | ||
))), | ||
journal.into(), | ||
); | ||
let expect_seal = encode_seal(&expected_receipt).unwrap(); | ||
assert_eq!(expect_seal, seal.to_vec()); | ||
} |