Skip to content

Commit

Permalink
feat(fault_proof): implement proposer
Browse files Browse the repository at this point in the history
  • Loading branch information
fakedev9999 committed Feb 14, 2025
1 parent 05c9d1b commit 5cfdf89
Show file tree
Hide file tree
Showing 22 changed files with 2,003 additions and 203 deletions.
872 changes: 715 additions & 157 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[workspace]
members = ["utils/*", "programs/*", "scripts/*", "proposer/succinct"]
members = ["utils/*", "programs/*", "scripts/*", "proposer/succinct", "fault_proof"]
resolver = "2"

[workspace.package]
license = "MIT"
edition = "2021"
authors = ["ratankaliani", "zachobront"]
authors = ["ratankaliani", "zachobront", "fakedev9999"]
homepage = "https://succinctlabs.github.io/op-succinct/"
repository = "https://github.com/succinctlabs/op-succinct"

Expand Down
2 changes: 2 additions & 0 deletions book/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
- [Update Contract Parameters](./contracts/update-parameters.md)
- [Modifications to Original `L2OutputOracle`](./contracts/modifications.md)
- [Fault Proofs](./fault_proofs/fault_proof_architecture.md)
- [Deploy FP Contracts](./fault_proofs/deploy.md)
- [How to run the FP Proposer](./fault_proofs/proposer.md)
- [Experimental](./experimental/intro.md)
- [OptimismPortalV2](./experimental/optimism-portal-v2.md)
- [FAQ](./faq.md)
Expand Down
111 changes: 111 additions & 0 deletions book/fault_proofs/deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Deploying OP Succinct Fault Dispute Game

This guide explains how to deploy the OP Succinct Fault Dispute Game contracts using the `DeployOPSuccinctDG.s.sol` script.

## Overview

The deployment script performs the following actions:
1. Deploys the `DisputeGameFactory` implementation and proxy.
2. Deploys a mock SP1 verifier for testing or use a SP1 Verifier Gateway set in the environment variable `SP1_VERIFIER_GATEWAY` for production.
3. Deploys the `OPSuccinctFaultDisputeGame` implementation.
4. Configures the factory with initial bond and game implementation.

## Prerequisites

- [Foundry](https://book.getfoundry.sh/getting-started/installation) installed
- Access to an Ethereum node (local or network)
- Environment variables properly configured

## Configuration

Create a `.env` file in the contracts directory with the following variables:

### Required Environment Variables

| Variable | Description | Example |
|----------|-------------|---------|
| `GAME_TYPE` | Unique identifier for the game type (uint32) | `42` |
| `MAX_CHALLENGE_DURATION` | Maximum duration for challenges in seconds | `604800` for 7 days |
| `MAX_PROVE_DURATION` | Maximum duration for proving in seconds | `86400` for 1 day |

### SP1 Verifier Configuration
Choose one of the following:

| Variable | Description | Example |
|----------|-------------|---------|
| `USE_SP1_MOCK_VERIFIER` | Set to true to deploy a mock verifier for testing | `true` |
| `SP1_VERIFIER_GATEWAY` | Address of the SP1 verifier gateway for production | `0x...` |

## Deployment

1. Install dependencies:
```bash
forge install
```

2. Change directory to contracts:
```bash
cd contracts
```

3. Build the contracts:
```bash
forge build
```

4. Run the deployment script:
```bash
forge script script/fp/DeployOPSuccinctDG.s.sol --broadcast --rpc-url <RPC_URL> --private-key <PRIVATE_KEY>
```

## Contract Parameters

The deployment script deploys the contract with the following parameters:

- **Initial Bond**: 0.01 ETH (configurable in the script)
- **Proof Reward**: 0.01 ETH (configurable in the script)
- **Genesis Parameters**:
- `rollupConfigHash`: The hash of the rollup configuration.
- `aggregationVkey`: The vkey for the aggregation program.
- `rangeVkeyCommitment`: The 32 byte commitment to the BabyBear representation of the verification key of the range SP1 program.
- `genesisL2BlockNumber`: The genesis L2 block number of the game.
- `genesisL2OutputRoot`: The genesis L2 output root of the game.

## Post-Deployment

After deployment, the script will output the addresses of:
- Factory Proxy
- Game Implementation
- SP1 Verifier

Save these addresses for future reference and configuration of other components (proposer, challenger, etc.).

## Security Considerations

- The deployer address will be set as the factory owner
- Initial parameters are set for testing - adjust for production
- The mock SP1 verifier (SP1_MOCK_VERIFIER=true) should ONLY be used for testing
- For production deployments, always provide a valid SP1_VERIFIER_GATEWAY address. Contract addresses for SP1 Verifier Gateways can be found [here](https://docs.succinct.xyz/docs/verification/onchain/contract-addresses).
- Review and adjust the bond and reward values based on network economics

## Troubleshooting

Common issues and solutions:

1. **Compilation Errors**:
- Ensure Foundry is up to date (run `foundryup` to update)
- Run `forge clean && forge build`

2. **Deployment Failures**:
- Check RPC connection
- Verify sufficient ETH balance
- Confirm gas settings

## Next Steps

After deployment:

1. Update the proposer configuration with the factory address
2. Configure the challenger with the game parameters
3. Test the deployment with a sample game
4. Monitor initial games for correct behavior
154 changes: 154 additions & 0 deletions book/fault_proofs/proposer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Fault Proof Proposer

The fault proof proposer is a component responsible for creating and managing op-succinct fault proof games on the L1 chain. It continuously monitors the L2 chain and creates new dispute games at regular intervals to ensure the validity of L2 state transitions.

## Prerequisites

Before running the proposer, ensure you have:

1. Rust toolchain installed (latest stable version)
2. Access to L1 and L2 network nodes
3. The DisputeGameFactory contract deployed (See [Deploy](./deploy.md))
4. Sufficient ETH balance for:
- Transaction fees
- Game bonds (configurable in the factory)
5. Required environment variables properly configured (see [Configuration](#configuration))

## Overview

The proposer performs several key functions:

1. **Game Creation**: Creates new dispute games for L2 blocks at configurable intervals
2. **Game Resolution**: Optionally resolves unchallenged games after their deadline passes
3. **Chain Monitoring**: Continuously monitors the L2 chain's safe head and creates proposals accordingly

## Configuration

The proposer is configured through various environment variables. Create a `.env.proposer` file in the fault_proof directory:

### Required Environment Variables

| Variable | Description |
|----------|-------------|
| `L1_RPC` | L1 RPC endpoint URL |
| `L2_RPC` | L2 RPC endpoint URL |
| `FACTORY_ADDRESS` | Address of the DisputeGameFactory contract |
| `GAME_TYPE` | Type identifier for the dispute game |
| `PRIVATE_KEY` | Private key for transaction signing |

### Optional Environment Variables

| Variable | Description | Default Value |
|----------|-------------|---------------|
| `PROPOSAL_INTERVAL_IN_BLOCKS` | Number of L2 blocks between proposals | `1000` |
| `FETCH_INTERVAL` | Polling interval in seconds | `30` |
| `ENABLE_GAME_RESOLUTION` | Whether to enable automatic game resolution | `false` |
| `MAX_GAMES_TO_CHECK_FOR_RESOLUTION` | Maximum number of games to check for resolution | `100` |

```env
# Required Configuration
L1_RPC= # L1 RPC endpoint URL
L2_RPC= # L2 RPC endpoint URL
FACTORY_ADDRESS= # Address of the DisputeGameFactory contract (obtained from deployment)
GAME_TYPE= # Type identifier for the dispute game (must match factory configuration)
PRIVATE_KEY= # Private key for transaction signing
# Optional Configuration
PROPOSAL_INTERVAL_IN_BLOCKS=1000 # Number of L2 blocks between proposals
FETCH_INTERVAL=30 # Polling interval in seconds
ENABLE_GAME_RESOLUTION=false # Whether to enable automatic game resolution
MAX_GAMES_TO_CHECK_FOR_RESOLUTION=100 # Maximum number of games to check for resolution
```

### Configuration Steps

1. Deploy the DisputeGameFactory contract following the [deployment guide](./deploy.md)
2. Copy the factory address from the deployment output
3. Create `.env` file with the above configuration
4. Ensure your account has sufficient ETH for bonds and gas

## Running

To run the proposer:
```bash
cargo run --bin proposer
```

The proposer will run indefinitely, creating new games and optionally resolving them based on the configuration.

## Features

### Game Creation
- Creates new dispute games at configurable block intervals.
- Computes L2 output roots for game proposals.
- Ensures proper game sequencing with parent-child relationships.
- Handles bond requirements for game creation.

### Game Resolution
When enabled (`ENABLE_GAME_RESOLUTION=true`), the proposer:
- Monitors unchallenged games
- Resolves games after their challenge period expires
- Respects parent-child game relationships in resolution
- Only resolves games whose parent games are already resolved

### Chain Monitoring
- Monitors the L2 chain's finalized (safe) head
- Creates proposals for new blocks as they become available
- Maintains proper spacing between proposals based on configuration

## Logging

The proposer uses the `tracing` crate for logging with a default level of INFO. You can adjust the log level by setting the `RUST_LOG` environment variable:

```bash
RUST_LOG=debug cargo run --bin proposer
```

## Error Handling

The proposer includes robust error handling for:
- RPC connection issues
- Transaction failures
- Contract interaction errors
- Invalid configurations

Errors are logged with appropriate context to aid in debugging.

## Architecture

The proposer is built around the `OPSuccinctProposer` struct which manages:
- Configuration state.
- Wallet management for transactions.
- Game creation and resolution logic.
- Chain monitoring and interval management.

Key components:
- `ProposerConfig`: Handles environment-based configuration.
- `handle_game_creation`: Main function for proposing new games that:
- Monitors the L2 chain's safe head.
- Determines appropriate block numbers for proposals.
- Creates new games with proper parent-child relationships.
- `handle_game_resolution`: Main function for resolving games that:
- Checks if resolution is enabled.
- Manages resolution of unchallenged games.
- Respects parent-child relationships.
- `run`: Main loop that:
- Runs at configurable intervals.
- Handles both game creation and resolution.
- Provides error isolation between creation and resolution tasks.

### Helper Functions
- `create_game`: Creates individual games with proper bonding.
- `try_resolve_unchallenged_game`: Attempts to resolve a single game.
- `should_attempt_resolution`: Determines if games can be resolved based on parent status.
- `resolve_unchallenged_games`: Manages batch resolution of games.

## Development

When developing or modifying the proposer:
1. Ensure all environment variables are properly set.
2. Test with a local L1/L2 setup first.
3. Monitor logs for proper operation.
4. Test game creation and resolution separately.
5. Verify proper handling of edge cases (network issues, invalid responses, etc.).
6. Note that game creation and resolution are handled independently, with separate error handling.
3 changes: 3 additions & 0 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,7 @@ fs_permissions = [
{ access = "read-write", path = "./opsuccinctl2ooconfig-test.json" }
]

via-ir = true
optimizer = true

# See more config options https://github.com/foundry-rs/foundry/tree/master/config
Loading

0 comments on commit 5cfdf89

Please sign in to comment.