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

feat: custom rollup config #69

Merged
merged 64 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
4f14788
BootInfo changes to support custom rollup configs
zobront Aug 22, 2024
d65bcf4
return to upstream kona
zobront Aug 22, 2024
2992885
preserialize rollup config & fetch proper data from op geth
zobront Aug 25, 2024
c3f6bac
just recipe adds hash to zkconfig automatically
zobront Aug 25, 2024
a14232c
contract upgrades
zobront Aug 25, 2024
7c3c3e9
make latestoutputindex internally callable
zobront Aug 25, 2024
d8a06f1
update public values to include rollup config hash (breaks tests, nee…
zobront Aug 25, 2024
8900e6a
pass config bytes with boot info
zobront Aug 27, 2024
ca297da
move fetch rollup config to rust binary
zobront Aug 27, 2024
6c9cee5
gitignore
Aug 27, 2024
7d313dd
merge
Aug 27, 2024
8ea3f76
fix
Aug 27, 2024
34bbb45
fix: client programs
Aug 27, 2024
66f7b3e
fix
Aug 27, 2024
6dab3be
fix
Aug 27, 2024
c26fa5c
add
Aug 27, 2024
a8856a8
add
Aug 27, 2024
64f1b86
fix
Aug 27, 2024
30952c1
add
Aug 27, 2024
2d0ba73
fix
Aug 27, 2024
f6c9c49
fix
Aug 27, 2024
5acfdc9
fix
Aug 27, 2024
d14ea0c
add
ratankaliani Aug 30, 2024
748b202
add
ratankaliani Aug 30, 2024
046a563
fix
ratankaliani Aug 30, 2024
6dd6491
clean
ratankaliani Aug 30, 2024
bff79a7
add
ratankaliani Aug 30, 2024
cadc4e9
bindings
ratankaliani Aug 30, 2024
6fd4e0c
fix
ratankaliani Aug 30, 2024
4ef5b35
test
ratankaliani Aug 30, 2024
c900329
feat: compiles
ratankaliani Sep 9, 2024
5bd10a9
update elf's
ratankaliani Sep 9, 2024
5349962
release
ratankaliani Sep 9, 2024
d3d03b7
automatically update config
ratankaliani Sep 10, 2024
f093956
fetch rollup config
ratankaliani Sep 10, 2024
88d5a4e
feat: generate config from script
ratankaliani Sep 10, 2024
0f07067
feat: remove methods
ratankaliani Sep 10, 2024
e432b5e
fix: forge fmt
ratankaliani Sep 10, 2024
9a299d1
del unused fn
ratankaliani Sep 10, 2024
1f37dad
fetch rollup config
ratankaliani Sep 10, 2024
fc35dc5
add docs
ratankaliani Sep 10, 2024
2c1e532
docs
ratankaliani Sep 10, 2024
8c48aec
docs
ratankaliani Sep 10, 2024
7ff3cd9
docs
ratankaliani Sep 10, 2024
e510118
book removal
ratankaliani Sep 10, 2024
2a43247
fix
ratankaliani Sep 10, 2024
76e6380
fix
ratankaliani Sep 10, 2024
cb2d69f
feat: Use strict types, rather than type mucking
ratankaliani Sep 10, 2024
1611538
fix: Use RPC mode, add rollup config saving
Sep 10, 2024
f081f66
docs: rename to zkl2ooconfig.json
Sep 10, 2024
cf0986f
docs: rm todo
Sep 10, 2024
efa4c9f
add rollup config
ratankaliani Sep 11, 2024
d7be851
fetch
ratankaliani Sep 11, 2024
7513e15
merge
ratankaliani Sep 12, 2024
b654f83
add
ratankaliani Sep 12, 2024
30ea6c4
add
ratankaliani Sep 12, 2024
1abae25
add
ratankaliani Sep 12, 2024
947e4c2
fix
ratankaliani Sep 12, 2024
e61cf3a
clean
ratankaliani Sep 12, 2024
a183645
add
ratankaliani Sep 12, 2024
cedc089
fix: add rollup config path to args
Sep 15, 2024
6aff41b
add
Sep 15, 2024
45384d6
feat: Load OP Stack Rollup Config (#121)
ratankaliani Sep 16, 2024
cfb3d4e
add todo
ratankaliani Sep 17, 2024
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
Prev Previous commit
Next Next commit
fix
  • Loading branch information
Ubuntu committed Aug 27, 2024
commit 2d0ba73d32166717ca2bd116682fd83e6850df51
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ futures = "0.3.30"
serde_cbor = "0.11.2"
log = "0.4.22"
itertools = "0.13.0"
reqwest = "0.12"

# serialization
serde = { version = "1.0.198", features = ["derive"] }
Expand Down
Binary file modified elf/fault-proof-elf
Binary file not shown.
Binary file modified elf/range-elf
Binary file not shown.
1 change: 1 addition & 0 deletions op-succinct-proposer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ base64.workspace = true
tower-http.workspace = true
cargo_metadata.workspace = true
revm.workspace = true
reqwest.workspace = true

[build-dependencies]
sp1-helper = { workspace = true }
118 changes: 72 additions & 46 deletions op-succinct-proposer/bin/fetch_rollup_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,71 @@ use alloy_primitives::B256;
use anyhow::{bail, Context, Result};
use client_utils::boot::hash_rollup_config;
use serde_json::{json, Value};
use sp1_sdk::install::block_on;
use std::env;
use std::fs;
use std::process::Command;

/// Fetch the rollup config from the rollup node and save it to a file.
fn fetch_rollup_config(rollup_rpc: Option<String>, l2_rpc: Option<String>) -> Result<()> {
// Determine RPC URLs
let rollup_rpc = rollup_rpc
.or_else(|| env::var("L2_NODE_RPC").ok())
.context("Must provide rollup rpc as argument or env variable (L2_NODE_RPC)")?;

let l2_rpc = l2_rpc
.or_else(|| env::var("L2_RPC").ok())
.context("Must provide L2 rpc as argument or env variable (L2_RPC)")?;

// TODO: Modify these to not use cast and instead use a RPC client.
// Fetch rollup config.
let rollup_config = Command::new("cast")
.args(["rpc", "--rpc-url", &rollup_rpc, "optimism_rollupConfig"])
.output()?;
fs::write("rollup-config.json", &rollup_config.stdout)?;

// Fetch chain config.
let chain_config = Command::new("cast")
.args(["rpc", "--rpc-url", &l2_rpc, "debug_chainConfig"])
.output()?;
fs::write("chain-config.json", &chain_config.stdout)?;

// Read and parse JSON files
let rollup_json: Value = serde_json::from_str(&fs::read_to_string("rollup-config.json")?)?;
let chain_json: Value = serde_json::from_str(&fs::read_to_string("chain-config.json")?)?;

// Process and merge configs
let merged_config = merge_configs(&rollup_json, &chain_json)?;
fn fetch_rollup_config() -> Result<()> {
let (rollup_rpc, l2_rpc) = get_rpc_urls();

let rollup_config = fetch_rpc_data(&rollup_rpc, "optimism_rollupConfig")?;
let chain_config = fetch_rpc_data(&l2_rpc, "debug_chainConfig")?;

save_config_to_file("rollup-config.json", &rollup_config)?;
save_config_to_file("chain-config.json", &chain_config)?;

let rollup_json: Value = serde_json::from_str(&rollup_config)?;
let chain_json: Value = serde_json::from_str(&chain_config)?;

// Write merged config to file
let merged_config = merge_configs(&rollup_json, &chain_json)?;
let merged_config_str = serde_json::to_string_pretty(&merged_config)?;
fs::write("rollup-config.json", &merged_config_str)?;

// Clean up
save_config_to_file("rollup-config.json", &merged_config_str)?;
fs::remove_file("chain-config.json")?;

println!("Updated rollup config saved to ./rollup-config.json");

// Generate hash
let hash: B256 = hash_rollup_config(&merged_config_str.as_bytes().to_vec());

update_zkconfig_rollup_config_hash(hash)
}

/// Get the rollup RPC URLs.
fn get_rpc_urls() -> (String, String) {
let rollup_rpc = env::var("L2_NODE_RPC")
.expect("Must provide rollup rpc as argument or env variable (L2_NODE_RPC)");
let l2_rpc =
env::var("L2_RPC").expect("Must provide L2 rpc as argument or env variable (L2_RPC)");

(rollup_rpc, l2_rpc)
}

/// Fetch data from the RPC.
fn fetch_rpc_data(rpc_url: &str, method: &str) -> Result<String> {
let client = reqwest::Client::new();
let response = block_on(async {
client
.post(rpc_url)
.json(&json!({
"jsonrpc": "2.0",
"method": method,
"params": [],
"id": 1
}))
.send()
.await?
.json::<serde_json::Value>()
.await
})?;

Ok(response["result"].to_string())
}

fn save_config_to_file(filename: &str, content: &str) -> Result<()> {
fs::write(filename, content)?;
Ok(())
}

/// Update the rollup config hash in the zkconfig.json file.
fn update_zkconfig_rollup_config_hash(hash: B256) -> Result<()> {
let hash_str = format!("0x{:x}", hash);
Expand All @@ -71,6 +86,7 @@ fn update_zkconfig_rollup_config_hash(hash: B256) -> Result<()> {
Ok(())
}

/// Merge the rollup and chain configs.
fn merge_configs(rollup: &Value, chain: &Value) -> Result<Value> {
let elasticity = chain["optimism"]["eip1559Elasticity"]
.as_u64()
Expand All @@ -81,7 +97,16 @@ fn merge_configs(rollup: &Value, chain: &Value) -> Result<Value> {

let mut merged = rollup.clone();

// Merge time fields
merge_time_fields(&mut merged, chain);
set_base_fee_params(&mut merged, elasticity, denominator);
set_canyon_base_fee_params(&mut merged, chain, elasticity);
rename_batcher_addr(&mut merged)?;

Ok(merged)
}

/// Merge the time fields from the chain config into the rollup config.
fn merge_time_fields(merged: &mut Value, chain: &Value) {
for field in &[
"regolithTime",
"canyonTime",
Expand All @@ -95,22 +120,28 @@ fn merge_configs(rollup: &Value, chain: &Value) -> Result<Value> {
merged[field] = json!(value);
}
}
}

// Set base_fee_params
/// Set the base fee params in the rollup config.
fn set_base_fee_params(merged: &mut Value, elasticity: u64, denominator: u64) {
merged["base_fee_params"] = json!({
"elasticity_multiplier": elasticity,
"max_change_denominator": denominator
});
}

// Set canyon_base_fee_params if present
/// Set the canyon base fee params in the rollup config.
fn set_canyon_base_fee_params(merged: &mut Value, chain: &Value, elasticity: u64) {
if let Some(canyon_denominator) = chain["optimism"]["eip1559DenominatorCanyon"].as_u64() {
merged["canyon_base_fee_params"] = json!({
"elasticity_multiplier": elasticity,
"max_change_denominator": canyon_denominator
});
}
}

// Rename batcherAddr to batcherAddress
/// Rename the batcher address in the rollup config.
fn rename_batcher_addr(merged: &mut Value) -> Result<()> {
if let Some(system_config) = merged["genesis"]["system_config"].as_object_mut() {
if let Some(batcher_addr) = system_config.remove("batcherAddr") {
system_config.insert("batcherAddress".to_string(), batcher_addr);
Expand All @@ -120,15 +151,10 @@ fn merge_configs(rollup: &Value, chain: &Value) -> Result<Value> {
} else {
bail!("Invalid structure in rollup config: missing system_config");
}

Ok(merged)
Ok(())
}

fn main() -> Result<()> {
dotenv::dotenv().ok();
let args: Vec<String> = env::args().collect();
let rollup_rpc = args.get(1).cloned();
let l2_rpc = args.get(2).cloned();

fetch_rollup_config(rollup_rpc, l2_rpc)
fetch_rollup_config()
}