-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
870 additions
and
0 deletions.
There are no files selected for viewing
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,20 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = ["common", "l1-to-l2", "l2", "l2-to-l1"] | ||
|
||
# Always optimize; otherwise tests take excessively long. | ||
[profile.dev] | ||
opt-level = 3 | ||
|
||
[profile.release] | ||
debug = 1 | ||
lto = true | ||
|
||
[workspace.dependencies] | ||
risc0-zkvm = { git = "https://github.com/risc0/risc0", branch = "main" } | ||
risc0-build = { git = "https://github.com/risc0/risc0", branch = "main" } | ||
op-steel = { path = "../../crates/op-steel" } | ||
risc0-steel = { path = "../../crates/steel" } | ||
risc0-ethereum-contracts = { path = "../../contracts" } | ||
examples-common = { path = "common" } | ||
alloy = { version = "0.4" } |
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,12 @@ | ||
[package] | ||
name = "examples-common" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
alloy = { workspace = true, features = ["consensus", "node-bindings"] } | ||
anyhow = "1.0" | ||
log = "0.4" | ||
risc0-ethereum-contracts = { workspace = true } | ||
risc0-zkvm = { workspace = true } | ||
url = "2.5" |
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,39 @@ | ||
use alloy::providers::ProviderBuilder; | ||
use anyhow::Context; | ||
use risc0_zkvm::{sha::Digest, Receipt}; | ||
use url::Url; | ||
|
||
pub async fn verify_on_chain( | ||
receipt: Receipt, | ||
image_id: Digest, | ||
rpc_url: Url, | ||
) -> anyhow::Result<()> { | ||
log::info!("Validating the receipt on {}...", rpc_url); | ||
|
||
let seal = risc0_ethereum_contracts::encode_seal(&receipt).context("encode_seal failed")?; | ||
let journal = receipt.journal.bytes; | ||
|
||
let provider = ProviderBuilder::new() | ||
.with_recommended_fillers() | ||
.on_anvil_with_wallet_and_config(|anvil| anvil.fork(rpc_url)); | ||
|
||
alloy::sol!( | ||
#[sol(rpc)] | ||
Verifier, | ||
"../contracts/out/Verifier.sol/Verifier.json" | ||
); | ||
|
||
let verifier = Verifier::deploy(provider) | ||
.await | ||
.context("failed to deploy Verifier")?; | ||
let verify = verifier.verify( | ||
journal.into(), | ||
seal.into(), | ||
<[u8; 32]>::from(image_id).into(), | ||
); | ||
log::debug!("Calling {} {}", verifier.address(), verify.calldata()); | ||
verify.call().await?; | ||
log::info!("Receipt validated"); | ||
|
||
Ok(()) | ||
} |
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,14 @@ | ||
# Compiler files | ||
cache/ | ||
out/ | ||
|
||
# Ignores development broadcast logs | ||
!/broadcast | ||
/broadcast/*/31337/ | ||
/broadcast/**/dry-run/ | ||
|
||
# Docs | ||
docs/ | ||
|
||
# Dotenv file | ||
.env |
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,6 @@ | ||
[profile.default] | ||
src = "src" | ||
out = "out" | ||
libs = ["../../../contracts/src/", "../../../lib/"] | ||
|
||
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options |
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,3 @@ | ||
forge-std/=../../../lib/forge-std/ | ||
openzeppelin/=../../../lib/openzeppelin-contracts/ | ||
risc0/=../../../contracts/src/ |
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,55 @@ | ||
// 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. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
pragma solidity ^0.8.9; | ||
|
||
import {ControlID, RiscZeroGroth16Verifier} from "risc0/groth16/RiscZeroGroth16Verifier.sol"; | ||
import {RiscZeroVerifierRouter, IRiscZeroVerifier} from "risc0/RiscZeroVerifierRouter.sol"; | ||
import {RiscZeroMockVerifier} from "risc0/test/RiscZeroMockVerifier.sol"; | ||
import {Steel} from "risc0/steel/Steel.sol"; | ||
import {OpCommitmentValidator} from "risc0/steel/OpSteel.sol"; | ||
|
||
contract Verifier is OpCommitmentValidator { | ||
address internal constant MAINNET_OPTIMISM_PORTAL_PROXY = address(0xbEb5Fc579115071764c7423A4f12eDde41f106Ed); | ||
|
||
IRiscZeroVerifier public immutable riscZeroVerifier; | ||
|
||
constructor() OpCommitmentValidator(MAINNET_OPTIMISM_PORTAL_PROXY) { | ||
RiscZeroVerifierRouter router = new RiscZeroVerifierRouter(address(this)); | ||
|
||
RiscZeroGroth16Verifier verifier = | ||
new RiscZeroGroth16Verifier(ControlID.CONTROL_ROOT, ControlID.BN254_CONTROL_ID); | ||
router.addVerifier(verifier.SELECTOR(), verifier); | ||
|
||
RiscZeroMockVerifier mock = new RiscZeroMockVerifier(bytes4(0)); | ||
router.addVerifier(mock.SELECTOR(), mock); | ||
|
||
riscZeroVerifier = router; | ||
} | ||
|
||
function verify(bytes calldata journal, bytes calldata seal, bytes32 imageID) | ||
external | ||
view | ||
returns (bytes memory payload) | ||
{ | ||
Steel.Commitment memory commitment = abi.decode(journal[:96], (Steel.Commitment)); | ||
require(validateCommitment(commitment), "Invalid commitment"); | ||
|
||
riscZeroVerifier.verify(seal, imageID, sha256(journal)); | ||
|
||
return journal[64:]; | ||
} | ||
} |
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,21 @@ | ||
[package] | ||
name = "l1-to-l2" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
alloy = { workspace = true, features = ["full"] } | ||
anyhow = "1.0.89" | ||
clap = { version = "4.5.18", features = ["derive", "env"] } | ||
examples-common = { workspace = true, optional = true } | ||
l1-to-l2-core = { path = "core" } | ||
l1-to-l2-methods = { path = "methods" } | ||
log = "0.4" | ||
op-steel = { workspace = true, features = ["host"] } | ||
risc0-zkvm = { workspace = true, features = ["client"] } | ||
tokio = { version = "1.40", features = ["full"] } | ||
tracing-subscriber = { version = "0.3", features = ["env-filter"] } | ||
url = "2.5" | ||
|
||
[features] | ||
verify = ["dep:examples-common"] |
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,8 @@ | ||
[package] | ||
name = "l1-to-l2-core" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
alloy-primitives = "0.8" | ||
alloy-sol-types = "0.8" |
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,18 @@ | ||
use alloy_primitives::{address, Address}; | ||
use alloy_sol_types::sol; | ||
|
||
sol! { | ||
interface IERC20 { | ||
function balanceOf(address account) external view returns (uint); | ||
} | ||
} | ||
|
||
/// Function to call, implements the `SolCall` trait. | ||
pub const CALL: IERC20::balanceOfCall = IERC20::balanceOfCall { | ||
account: address!("F977814e90dA44bFA03b6295A0616a897441aceC"), | ||
}; | ||
|
||
/// Address of the deployed contract to call the function on (USDT contract on Eth Mainnet). | ||
pub const CONTRACT: Address = address!("dAC17F958D2ee523a2206206994597C13D831ec7"); | ||
|
||
pub const CALLER: Address = Address::ZERO; |
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 = "l1-to-l2-methods" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[build-dependencies] | ||
risc0-build = { workspace = true } | ||
|
||
[package.metadata.risc0] | ||
methods = ["guest"] |
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,17 @@ | ||
[package] | ||
name = "l1-to-l2-guest" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[workspace] | ||
|
||
[dependencies] | ||
l1-to-l2-core = { path = "../../core" } | ||
risc0-steel = { path = "../../../../../crates/steel" } | ||
risc0-zkvm = { git = "https://github.com/risc0/risc0", branch = "main", default-features = false, features = ["std"] } | ||
|
||
[patch.crates-io] | ||
# use optimized risc0 circuit | ||
crypto-bigint = { git = "https://github.com/risc0/RustCrypto-crypto-bigint", tag = "v0.5.5-risczero.0" } | ||
k256 = { git = "https://github.com/risc0/RustCrypto-elliptic-curves", tag = "k256/v0.13.3-risczero.0" } | ||
sha2 = { git = "https://github.com/risc0/RustCrypto-hashes", tag = "sha2-v0.10.8-risczero.0" } |
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,41 @@ | ||
// 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. | ||
|
||
#![allow(unused_doc_comments)] | ||
#![no_main] | ||
|
||
use l1_to_l2_core::{CALL, CALLER, CONTRACT}; | ||
use risc0_steel::{ | ||
ethereum::{EthEvmInput, ETH_MAINNET_CHAIN_SPEC}, | ||
Contract, | ||
}; | ||
use risc0_zkvm::guest::env; | ||
|
||
risc0_zkvm::guest::entry!(main); | ||
|
||
fn main() { | ||
// Read the input from the guest environment. | ||
let input: EthEvmInput = env::read(); | ||
|
||
// Create the environment and add the commitment. | ||
let env = input.into_env().with_chain_spec(Ð_MAINNET_CHAIN_SPEC); | ||
env::commit_slice(&env.commitment().abi_encode()); | ||
|
||
// Execute the call. | ||
let contract = Contract::new(CONTRACT, &env); | ||
let returns = contract.call_builder(&CALL).from(CALLER).call(); | ||
|
||
// Commit the result. | ||
env::commit(&returns._0) | ||
} |
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")); |
Oops, something went wrong.