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

WEB3-329: chore: Add op-steel readme #425

Merged
merged 7 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions crates/op-steel/README.md
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This README does a good job of discussing mechanics. It may not be immediately clear to the reader they can use this for cross-chain Steel queries / cross-chain communication. It might be good to highlight that, as I think its the most common use case for this work.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# OP-Steel

A Rust library for integrating Optimism's Layer 2 blockchain with Steel, RISC Zero's production-ready smart contract execution prover.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to say "OP Stack Later 2 blockchain", or is that not accurate? "Optimism's" might make people think its only for OP Mainnet. But maybe this is not a real concern.


## Overview

OP-Steel extends [Steel](https://github.com/risc0/risc0-ethereum/tree/main/crates/steel) to work with Optimism's Layer 2 blockchain and any OP Stack-compatible chains. Steel provides a generic tool to interact with EVM-compatible chains, enabling offchain execution of EVM apps while preserving onchain security through execution proofs.

While you can use Steel directly to query and verify on the same chain (including OP chains), OP-Steel makes this process more convenient by including pre-configured OP network settings. The main advantage of OP-Steel, however, is its ability to perform **cross-chain queries** between Optimism and Ethereum, a feature not available in Steel alone.

## Features

- **Steel Integration**:
- Leverage Steel's execution proving system for Optimism L2 operations
- Generate verifiable proofs of correct smart contract execution
- Maintain onchain security while performing computation offchain
- **Cross-Chain Queries**:
- Perform cross-chain queries between Optimism and Ethereum
- Seamlessly verify OP contract execution on Ethereum L1
- **Dispute Game Integration**:
- Find and validate dispute games
- Support for latest, finalized, and specific game indices
- Automatic verification against the L1 `OptimismPortal` contract
- **OP Stack Compatibility**:
- Use OP-Steel with OP-Mainnet and any OP Stack-compatible chains

## Usage

Usage of OP-Steel is very similar to Steel. See the [Steel README](https://github.com/risc0/risc0-ethereum/tree/main/crates/steel#readme) for more details.

### Querying and Verifying on the Same Chain

If you only need to query and verify on the same chain (e.g., OP-Mainnet), you can use Steel directly. However, OP-Steel simplifies this process by providing pre-configured OP network settings.

```rust
// Create an OP environment
let env = OpEvmEnv::builder()
.rpc(Url::parse("https://optimism-rpc.publicnode.com")?)
.build()
.await?
// Apply chain configuration
.with_chain_spec(&OP_MAINNET_CHAIN_SPEC);

// Implement steel functionality
let contract = Contract::new(CONTRACT, &env);
contract.call_builder(&CALL).from(CALLER).call();

// Convert to input format for the guest
let input = env.into_input().await?;
```

### Cross-Chain Queries (OP to Ethereum)

OP-Steel enables cross-chain queries, such as verifying OP contract execution on Ethereum L1. This is a key feature that Steel alone does not provide.

```rust
// Create an OP environment referencing a dispute game
let env = OpEvmEnv::builder()
.dispute_game_from_rpc(
portal_address,
"https://ethereum-rpc.publicnode.com".parse()?
)
.rpc("https://optimism-rpc.publicnode.com".parse()?)
.game_index(DisputeGameIndex::Latest)
.build()
.await?;

// Implement steel functionality
let contract = Contract::new(CONTRACT, &env);
contract.call_builder(&CALL).from(CALLER).call();

// Convert to input format for the guest
let input = env.into_input().await?;
```

## Learn More

- [Steel Documentation](https://github.com/risc0/risc0-ethereum/tree/main/crates/steel#readme) - Learn about the core Steel system
- [RISC Zero Developer Docs](https://dev.risczero.com/api/) - Detailed documentation about the underlying zkVM
- [Optimism Documentation](https://community.optimism.io/) - Learn about Optimism's L2 system
37 changes: 30 additions & 7 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,45 @@
# Examples
This directory includes three example uses of Steel. Each example demonstrates a different concept of Steel.

## [ERC20 Balance Query](./erc20/README.md)
This directory includes three example uses of Steel. Each example demonstrates a different concept of Steel.

This introductory example illustrates how to use [Steel] to directly query the `balanceOf` function of any ERC20 token contract, providing a verifiable proof of a user's token balance.
### [ERC20 Balance Query](./erc20/README.md)

## [ERC20 Counter with Off-Chain Proofs](./erc20-counter/README.md)
This introductory example illustrates how to use [Steel] to directly query the `balanceOf` function of any ERC20 token
contract, providing a verifiable proof of a user's token balance.

### [ERC20 Counter with Off-Chain Proofs](./erc20-counter/README.md)

Explore a more advanced interaction between [Steel] and a custom Ethereum smart contract. This counter contract utilizes
off-chain [Steel] proofs to:

Explore a more advanced interaction between [Steel] and a custom Ethereum smart contract. This counter contract utilizes off-chain [Steel] proofs to:
- Increment a counter based on user-submitted proofs.
- Verify ERC20 token ownership (minimum 1 token required) before incrementing.
- Leverage RISC Zero as a [coprocessor] for efficient proof generation and verification.

## [Compound Token Stats (APR Proof)](./token-stats/README.md)
### [Compound Token Stats (APR Proof)](./token-stats/README.md)

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.
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.

## ERC20 Balance Query using [op-steel]

### [L2 Execution - L2 Verification](./op/l2)

This example shows how to use [op-steel] to query the `balanceOf` function of an ERC20 token on OP, providing a proof
that can be verified on OP.

### [L1 Execution - L2 Verification](./op/l1-to-l2)

This example shows how to use [op-steel] to query the `balanceOf` function of an ERC20 token on Ethereum and how the
generated proof can be verified on OP.

### [L2 Execution - L1 Verification](./op/l2-to-l1)

This example shows how to use [op-steel] to query the `balanceOf` function of an ERC20 token on OP and how the generated
proof can be verified on Ethereum.

[coprocessor]: https://risczero.com/blog/a-guide-to-zk-coprocessors-for-scalability
[Steel]: ../crates/steel
[Compound]: https://compound.finance/
[op-steel]: ../crates/op-steel
Loading