Skip to content

Commit

Permalink
feat(op-stack): fault proofs (#1994)
Browse files Browse the repository at this point in the history
* parent 6ef4ac1
author Will Cory <willcory@Wills-MacBook-Pro.local> 1709088652 -0800
committer Will Cory <willcory@Wills-MacBook-Pro.local> 1710517178 -0700

Add portalVersion action to viem/opstack

add test client for tevm matching anvil client

pnpm i @tevm/server

upgrade to versions of @tevm/opstack that don't have deps related bugs

REVERTME temporary hack to make foundry work on my machine

add the test and portal version action

update based on comments

add test client, rename createL1Client, and move to opstack test utils

bun i @tevm/opstack

add test client for tevm matching anvil client

pnpm i @tevm/server

upgrade to versions of @tevm/opstack that don't have deps related bugs

REVERTME temporary hack to make foundry work on my machine

add the test and portal version action

feat: Add forwards compatability to getWithdrawalStatus

first version of things

feat: Update waitForNextL2Output

fix broken lint

update getTimeToFinalize

add a comment

complete and squash

* replace test with optimism devnet test

* WIP

* fix: Build

* fix: lint

* op devnet script

* add address

* chore: refactor

* rename

* rename

* exports

* remove

* refactor

* ci: trigger

* ci: env

* test

* docs

* feat: getL2Output backwards compat

* fix: type

* test: up

* update sidebar

* chore: changeset

---------

Co-authored-by: Will Cory <willcory@Wills-MacBook-Pro.local>
Co-authored-by: Will Cory <willcory10@gmail.com>
  • Loading branch information
3 people authored Mar 24, 2024
1 parent 5a01527 commit 119aea6
Show file tree
Hide file tree
Showing 51 changed files with 3,646 additions and 268 deletions.
12 changes: 12 additions & 0 deletions .changeset/rotten-impalas-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"viem": minor
---

Added support for [Fault Proofs on OP Stack](https://docs.optimism.io/stack/protocol/fault-proofs/overview), and new actions:

- [`getGame`](https://viem.sh/op-stack/actions/getGame) (supersedes `getL2Output`)
- `getGames`
- [`getTimeToNextGame`](https://viem.sh/op-stack/actions/getTimeToNextGame) (supersedes `getTimeToNextL2Output`)
- [`waitForNextGame`](https://viem.sh/op-stack/actions/waitForNextGame) (supersedes `waitForNextL2Output`)

> Note: The above actions are only compatible with OP Stack chains which have upgraded to Fault Proofs.
4 changes: 4 additions & 0 deletions .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,13 @@ jobs:
command: bun run test:ci --shard=${{ matrix.shard }}/${{ matrix.total-shards }}
env:
VITE_ANVIL_BLOCK_NUMBER: ${{ vars.VITE_ANVIL_BLOCK_NUMBER }}
VITE_ANVIL_BLOCK_NUMBER_SEPOLIA: ${{ vars.VITE_ANVIL_BLOCK_NUMBER_SEPOLIA }}
VITE_ANVIL_BLOCK_NUMBER_OPTIMISM_SEPOLIA: ${{ vars.VITE_ANVIL_BLOCK_NUMBER_OPTIMISM_SEPOLIA }}
VITE_ANVIL_BLOCK_TIME: ${{ vars.VITE_ANVIL_BLOCK_TIME }}
VITE_ANVIL_FORK_URL: ${{ secrets.VITE_ANVIL_FORK_URL }}
VITE_ANVIL_FORK_URL_OPTIMISM: ${{ secrets.VITE_ANVIL_FORK_URL_OPTIMISM }}
VITE_ANVIL_FORK_URL_SEPOLIA: ${{ secrets.VITE_ANVIL_FORK_URL_SEPOLIA }}
VITE_ANVIL_FORK_URL_OPTIMISM_SEPOLIA: ${{ secrets.VITE_ANVIL_FORK_URL_OPTIMISM_SEPOLIA }}
VITE_BATCH_MULTICALL: ${{ matrix.multicall }}
VITE_NETWORK_TRANSPORT_MODE: ${{ matrix.transport-mode }}

Expand Down
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"workspaces": ["examples/*", "environments/*", "site", "src", "test"],
"workspaces": [
"examples/*",
"environments/*",
"site",
"src",
"test"
],
"private": true,
"type": "module",
"scripts": {
Expand Down
89 changes: 89 additions & 0 deletions site/pages/op-stack/actions/getGame.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
---
outline: deep
description: Retrieves a valid dispute game on an L2 that occurred after a provided L2 block number.
---

# getGame

Retrieves a valid dispute game on an L2 that occurred after a provided L2 block number. Used for the [Withdrawal](/op-stack/guides/withdrawals) flow.

:::info
This Action is only compatible with OP Stack chains that have upgraded to [Fault Proofs](https://docs.optimism.io/stack/protocol/fault-proofs/overview) and have a deployed [DisputeGameFactoryProxy contract](https://github.com/ethereum-optimism/superchain-registry/blob/main/superchain/extra/addresses/addresses.json).
:::

## Usage

:::code-group

```ts [example.ts]
import { optimism } from 'viem/chains'
import { account, publicClientL1 } from './config'

const game = await publicClientL1.getGame({ // [!code hl]
l2BlockNumber: 69420n, // [!code hl]
targetChain: optimism, // [!code hl]
}) // [!code hl]
```

```ts [config.ts]
import { createPublicClient, custom, http } from 'viem'
import { mainnet, optimism } from 'viem/chains'
import { publicActionsL1 } from 'viem/op-stack'

export const publicClientL1 = createPublicClient({
chain: mainnet,
transport: http()
}).extend(publicActionsL1())
```

:::

## Returns

`GetGameReturnType`

A valid dispute game.

## Parameters

### l2BlockNumber

- **Type:** `bigint`

The L2 block number.

```ts
const game = await publicClientL1.getGame({
l2BlockNumber: 69420n, // [!code focus]
targetChain: optimism,
})
```

### targetChain

- **Type:** [`Chain`](/docs/glossary/types#chain)

The L2 chain.

```ts
const game = await publicClientL1.getGame({
l2BlockNumber,
targetChain: optimism, // [!code focus]
})
```

### disputeGameFactoryAddress (optional)

- **Type:** `Address`
- **Default:** `targetChain.contracts.disputeGameFactory[chainId].address`

The address of the [`DisputeGameFactory` contract](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/dispute/DisputeGameFactory.sol). Defaults to the `DisputeGameFactory` contract specified on the `targetChain`.

If a `disputeGameFactoryAddress` is provided, the `targetChain` parameter becomes optional.

```ts
const game = await publicClientL1.getGame({
l2BlockNumber,
disputeGameFactoryAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed' // [!code focus]
})
```
118 changes: 118 additions & 0 deletions site/pages/op-stack/actions/getGames.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
---
outline: deep
description: Retrieves dispute games for an L2.
---

# getGames

Retrieves dispute games for an L2. Used for the [Withdrawal](/op-stack/guides/withdrawals) flow.

:::info
This Action is only compatible with OP Stack chains that have upgraded to [Fault Proofs](https://docs.optimism.io/stack/protocol/fault-proofs/overview) and have a deployed [DisputeGameFactoryProxy contract](https://github.com/ethereum-optimism/superchain-registry/blob/main/superchain/extra/addresses/addresses.json).
:::

## Usage

:::code-group

```ts [example.ts]
import { optimism } from 'viem/chains'
import { account, publicClientL1 } from './config'

const games = await publicClientL1.getGames({ // [!code hl]
targetChain: optimism, // [!code hl]
}) // [!code hl]
```

```ts [config.ts]
import { createPublicClient, custom, http } from 'viem'
import { mainnet, optimism } from 'viem/chains'
import { publicActionsL1 } from 'viem/op-stack'

export const publicClientL1 = createPublicClient({
chain: mainnet,
transport: http()
}).extend(publicActionsL1())
```

:::

## Returns

`GetGamesReturnType`

Dispute games.

## Parameters

### targetChain

- **Type:** [`Chain`](/docs/glossary/types#chain)

The L2 chain.

```ts
const games = await publicClientL1.getGames({
l2BlockNumber,
targetChain: optimism, // [!code focus]
})
```

### disputeGameFactoryAddress (optional)

- **Type:** `Address`
- **Default:** `targetChain.contracts.disputeGameFactory[chainId].address`

The address of the [`DisputeGameFactory` contract](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/dispute/DisputeGameFactory.sol). Defaults to the `DisputeGameFactory` contract specified on the `targetChain`.

If a `disputeGameFactoryAddress` is provided, the `targetChain` parameter becomes optional.

```ts
const games = await publicClientL1.getGames({
l2BlockNumber,
disputeGameFactoryAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed' // [!code focus]
})
```

### l2BlockNumber (optional)

- **Type:** `bigint`

The L2 block number.

```ts
const games = await publicClientL1.getGames({
l2BlockNumber: 69420n, // [!code focus]
targetChain: optimism,
})
```

### limit (optional)

- **Type:** `number`
- **Default:** `100`

Limit of games to extract.

```ts
const games = await publicClientL1.getGames({
limit: 10, // [!code focus]
targetChain: optimism,
})
```

### portalAddress (optional)

- **Type:** `Address`
- **Default:** `targetChain.contracts.portal[chainId].address`

The address of the [`Portal` contract](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L1/OptimismPortal2.sol). Defaults to the `Portal` contract specified on the `targetChain`.

If a `portalAddress` is provided, the `targetChain` parameter becomes optional.

```ts
const games = await publicClientL1.getGames({
l2BlockNumber,
portalAddress: '0xbEb5Fc579115071764c7423A4f12eDde41f106Ed' // [!code focus]
})
```
6 changes: 6 additions & 0 deletions site/pages/op-stack/actions/getL2Output.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ description: Retrieves the first L2 output proposal that occurred after a provid

Retrieves the first L2 output proposal that occurred after a provided block number. Used for the [Withdrawal](/op-stack/guides/withdrawals) flow.

:::warning
**This Action will be deprecated in the future.**

Use [`getGame`](/op-stack/actions/getGame) for OP Stack chains that have upgraded to [Fault Proofs](https://docs.optimism.io/stack/protocol/fault-proofs/overview) and have a deployed [DisputeGameFactoryProxy contract](https://github.com/ethereum-optimism/superchain-registry/blob/main/superchain/extra/addresses/addresses.json).
:::

## Usage

:::code-group
Expand Down
Loading

0 comments on commit 119aea6

Please sign in to comment.