Skip to content

Commit

Permalink
WEB3-329: chore: Add op-steel readme (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wollac authored Feb 3, 2025
1 parent d23a551 commit f260234
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 7 deletions.
80 changes: 80 additions & 0 deletions crates/op-steel/README.md
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.

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

0 comments on commit f260234

Please sign in to comment.