Skip to content

Commit

Permalink
feat: port op-proposer from Optimism fork (#78)
Browse files Browse the repository at this point in the history
* move over op proposer

* wip

* wip

* forge install: forge-std

v1.9.2

* forge install: openzeppelin-contracts

v5.0.2

* forge install: optimism

v1.9.0

* forge install: sp1-contracts

v1.1.0

* wip

* forge install: sp1-contracts

v1.1.0

* wip

* forge install: sp1-contracts

v1.1.0

* add

* forge install: sp1-contracts

* wip

* add

* forge install: openzeppelin-contracts

v4.7.3

* add

* forge install: openzeppelin-contracts

v4.7.3

* create bindings

* add

* add op-proposer-go

* fix

* fix

* fix

* add

* add

* fix

* fix

* remove run docker compose

* clean up

* fix: forge fmt

* update ci

* refactor: simplify `op-proposer` logic (#79)

* wip

* add

* fix l1Client

* add

* add comments

* update

* update

* fix: precompile override

* add value

* docs

---------

Co-authored-by: Ubuntu <ubuntu@op-mainnet-archive-1.maas>

* modify

* fix

* fix

* add

* fix

* add build

---------

Co-authored-by: Ubuntu <ubuntu@op-mainnet-archive-1.maas>
  • Loading branch information
ratankaliani and Ubuntu authored Aug 30, 2024
1 parent edcbc28 commit 8c86a57
Show file tree
Hide file tree
Showing 85 changed files with 10,544 additions and 377 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target
/data
/execution-reports
18 changes: 11 additions & 7 deletions .env.server.example
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# Configuration for running the OP Proposer + SP1 Server
L1_RPC=
L1_BEACON_RPC=
L2_RPC=
L2_NODE_RPC=

# Note: These are used because of how the OP Proposer loads the txMgr config in the Optimism monorepo.
L1_ETH_RPC=
BEACON_RPC=
ROLLUP_RPC=


# op-proposer configuration
POLL_INTERVAL=
ROLLUP_RPC=
L2OO_ADDRESS=
PRIVATE_KEY=
L1_ETH_RPC=
BEACON_RPC=
L2_CHAIN_ID=
MAX_CONCURRENT_PROOF_REQUESTS=
MAX_BLOCK_RANGE_PER_SPAN_PROOF=30
KONA_SERVER_URL=http://op-succinct-server:3000
OP_SUCCINCT_SERVER_URL=http://op-succinct-server:3000

# SP1 Configuration for the Server
L1_RPC=
L1_BEACON_RPC=
L2_RPC=
PROVER_NETWORK_RPC=
SP1_PRIVATE_KEY=
SP1_PROVER=network
Expand Down
20 changes: 19 additions & 1 deletion .github/workflows/op_proposer.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ on:

jobs:
test_op_proposer_go:
runs-on: ubuntu-latest
runs-on:
- runs-on
- runner=16cpu-linux-x64
- run-id=${{ github.run_id }}
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -25,3 +28,18 @@ jobs:
L2_NODE_RPC: ${{ secrets.L2_NODE_RPC }}
L1_RPC: ${{ secrets.L1_RPC }}
L1_BEACON_RPC: ${{ secrets.L1_BEACON_RPC }}
docker-compose-test:
name: Docker Compose Test
runs-on:
- runs-on
- runner=64cpu-linux-x64
- run-id=${{ github.run_id }}
steps:
- uses: actions/checkout@v4

- name: Set up Docker Compose
uses: docker/setup-buildx-action@v1

- name: Build Docker Compose setup
run: |
docker compose build
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: CI

on:
push:
pull_request:
branches:
- main
workflow_dispatch:

env:
Expand All @@ -26,20 +27,26 @@ jobs:
version: nightly

- name: Show Forge version
working-directory: contracts/
run: |
forge --version
- name: Run Forge fmt
working-directory: contracts/
run: |
forge fmt --check
forge fmt --check src/ test/ script/
id: fmt

- name: Run Forge build
working-directory: contracts/
run: |
forge build --sizes
id: build

- name: Run Forge tests
working-directory: contracts/
run: |
forge test -vvv
id: test
env:
L2_NODE_RPC: ${{ secrets.L2_NODE_RPC }}
13 changes: 10 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ data
# zip
**.zip

# vscode
.vscode

# .env
.env
.env.server
Expand All @@ -18,11 +21,15 @@ data
**.txt
!LICENSE.txt

# DB data
db/

# Reports
execution-reports/

# Rollup Config
**/rollup-config.json

# DB
db/proofs.db

**/bin/op-proposer

artifact_*
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "contracts/lib/forge-std"]
path = contracts/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "contracts/lib/optimism"]
path = contracts/lib/optimism
url = https://github.com/ethereum-optimism/optimism
[submodule "contracts/lib/sp1-contracts"]
path = contracts/lib/sp1-contracts
url = https://github.com/zobront/sp1-contracts
[submodule "contracts/lib/openzeppelin-contracts"]
path = contracts/lib/openzeppelin-contracts
url = https://github.com/openzeppelin/openzeppelin-contracts
21 changes: 0 additions & 21 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Standalone repo to use Kona & SP1 to verify OP Stack blocks.
- `client-utils`: A suite of utilities for the client program.
- `host-utils`: A suite of utilities for constructing the host which runs the OP Succinct program.

**`sp1-kona`**
**`op-succinct`**
- `native-host`: The host program which runs the `op-succinct` program natively using `kona`.
- `zkvm-host`: The host program which runs the `op-succinct` program in the SP1 zkVM.
- `client-programs`: The programs proven in SP1.
Expand Down
2 changes: 1 addition & 1 deletion client-programs/aggregation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::collections::HashMap;
/// should verify the proof matches the arbitrary vkey digest stored in the contract. This means
/// that the aggregate program would no longer need to update this value.
const MULTI_BLOCK_PROGRAM_VKEY_DIGEST: [u32; 8] =
[227309663, 1637133225, 136526498, 1878261023, 2013043842, 450616441, 575447582, 1643259779];
[1172625895, 1280247262, 651076015, 321432881, 243715685, 1565992912, 1444792760, 1908047081];

/// Verify that the L1 heads in the boot infos are in the header chain.
fn verify_l1_heads(agg_inputs: &AggregationInputs, headers: &[Header]) {
Expand Down
12 changes: 5 additions & 7 deletions client-programs/range/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ fn main() {
let boot = Arc::new(BootInfo::load(oracle.as_ref()).await.unwrap());
}
}
// Note: On some blocks, key not found in cache errors occur due to the precompiles. For
// recent blocks this isn't an issue, but we should look into this more in the future.
let precompile_overrides = ZKVMPrecompileOverride::default();

let l1_provider = OracleL1ChainProvider::new(boot.clone(), oracle.clone());
Expand Down Expand Up @@ -122,6 +120,11 @@ fn main() {
let new_block_number = new_block_header.number;
assert_eq!(new_block_number, payload.parent.block_info.number + 1);

// Increment last_block_num and check if we have reached the claim block.
if new_block_number == boot.l2_claim_block {
break 'step;
}

// Generate the Payload Envelope, which can be used to derive cached data.
let l2_payload_envelope: L2ExecutionPayloadEnvelope = OpBlock {
header: new_block_header.clone(),
Expand All @@ -144,11 +147,6 @@ fn main() {
.update_cache(new_block_header, l2_payload_envelope, &boot.rollup_config)
.unwrap();

// Increment last_block_num and check if we have reached the claim block.
if new_block_number == boot.l2_claim_block {
break 'step;
}

// Update data for the next iteration.
driver.update_safe_head(
l2_block_info,
Expand Down
2 changes: 2 additions & 0 deletions contracts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Rollup RPC URL
L2_NODE_RPC=
2 changes: 1 addition & 1 deletion contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/

Expand Down
14 changes: 12 additions & 2 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ The `contracts/` directory consists of two things:

2) The `ZKUpgrader.s.sol` script, which deploys the `ZKL2OutputOracle.sol` implementation contract, upgrades an existing `L2OutputOracleProxy` to point to it, and initializes the new contract with values from `zkconfig.json`.

## Deploy
3) The `ZKDeployer.s.sol` script, which deploys the `ZKL2OutputOracle.sol` implementation contract, upgrades an existing `L2OutputOracleProxy` to point to it, and initializes the new contract with values from `zkconfig.json`.

To deploy and upgrade the contract, run the following command (where `ADMIN_PK` is the private key of the admin address for the L1 proxy contracts):
## Deploy Fresh Proxy

For OP Sepolia, you can deploy a fresh proxy with the following command:

```shell
forge script script/ZKDeployer.s.sol:ZKDeployer --rpc-url <L1_RPC> --private-key <ADMIN_PK> --verify --verifier etherscan --etherscan-api-key <ETHERSCAN_API_KEY> --broadcast --slow -vvvv --ffi
```

## Upgrade Existing Proxy

To deploy and upgrade the contract for existing chains, run the following command (where `ADMIN_PK` is the private key of the admin address for the L1 proxy contracts):

```shell
forge script script/ZKUpgrader.s.sol:ZKUpgrader --rpc-url <L1_RPC> --private-key <ADMIN_PK> --verify --verifier etherscan --etherscan-api-key <ETHERSCAN_API_KEY> --broadcast --slow --vvvv
Expand Down
22 changes: 18 additions & 4 deletions contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@
src = "src"
out = "out"
libs = ["lib"]
ffi = true
fs_permissions = [
{ access = "read", path = "zkconfig.json" }
remappings = [
# Use openzeppelin-contracts v4.7.3 as the some contracts are not compatible with 0.8.15
"@openzeppelin/=lib/openzeppelin-contracts/",
"@optimism/=lib/optimism/packages/contracts-bedrock/",
"@forge-std/=lib/forge-std/src/",
# Note: Use zobront/sp1-contracts as the current version for SP1 contracts is not compatible with the hard
# version for 0.8.15 on some Optimism contracts.
"@sp1-contracts/=lib/sp1-contracts/contracts/",
"@rari-capital/=lib/optimism/packages/contracts-bedrock/lib/",
# Optimism repo uses absolute imports, so we need to have remappings for the paths we use.
"src/libraries/=lib/optimism/packages/contracts-bedrock/src/libraries/",
"src/L1/=lib/optimism/packages/contracts-bedrock/src/L1/",
"src/L2/=lib/optimism/packages/contracts-bedrock/src/L2/",
]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
# Enable read-write access to zkconfig.json
fs_permissions = [{ access = "read-write", path = "./zkconfig.json" }]

dotenv = ".env"
# See more config options https://github.com/foundry-rs/foundry/tree/master/config
13 changes: 6 additions & 7 deletions contracts/script/ZKDeployer.s.sol
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { Script } from "forge-std/Script.sol";
import { ZKL2OutputOracle } from "src/ZKL2OutputOracle.sol";
import { Utils } from "test/helpers/Utils.sol";
import { Proxy } from "@optimism/src/universal/Proxy.sol";
pragma solidity ^0.8.15;

import {Script} from "forge-std/Script.sol";
import {ZKL2OutputOracle} from "../src/ZKL2OutputOracle.sol";
import {Utils} from "../test/helpers/Utils.sol";
import {Proxy} from "@optimism/src/universal/Proxy.sol";

contract ZKDeployer is Script, Utils {
function run() public {
vm.startBroadcast();

Config memory config = readJson("zkconfig.json");
Config memory config = readJsonWithRPCFromEnv("zkconfig.json");
config.l2OutputOracleProxy = address(new Proxy(msg.sender));

address zkL2OutputOracleImpl = address(new ZKL2OutputOracle());
Expand Down
9 changes: 4 additions & 5 deletions contracts/script/ZKUpgrader.s.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import { Script } from "forge-std/Script.sol";
import { ZKL2OutputOracle } from "src/ZKL2OutputOracle.sol";
import { Utils } from "test/helpers/Utils.sol";
pragma solidity ^0.8.15;

import {Script} from "forge-std/Script.sol";
import {ZKL2OutputOracle} from "../src/ZKL2OutputOracle.sol";
import {Utils} from "../test/helpers/Utils.sol";

contract ZKUpgrader is Script, Utils {
function run() public {
Expand Down
Loading

0 comments on commit 8c86a57

Please sign in to comment.