Skip to content

Commit 280b4c5

Browse files
ratankalianiUbuntu
and
Ubuntu
authored
wip: debugging failed proofs (#106)
* debug failed proofs * got compilation, working, still issues * wip * wip * add * push --------- Co-authored-by: Ubuntu <[email protected]>
1 parent 0594844 commit 280b4c5

File tree

18 files changed

+300
-149
lines changed

18 files changed

+300
-149
lines changed

Cargo.lock

+87-71
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+23-9
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,27 @@ kzg-rs = { version = "0.2.2" }
4040
# TODO: Change to stable tag when released.
4141
# Note: Explicitly needed to downgrade superchain-primitives to 0.3.1.
4242
# cargo update -p [email protected] --precise 0.3.1
43-
kona-common = { git = "https://github.com/ethereum-optimism/kona", branch = "main" }
44-
kona-common-proc = { git = "https://github.com/ethereum-optimism/kona", branch = "main" }
45-
kona-preimage = { git = "https://github.com/ethereum-optimism/kona", branch = "main", features = [
43+
kona-common = { git = "https://github.com/moongate-forks/kona", branch = "ratan/add-converter" }
44+
kona-common-proc = { git = "https://github.com/moongate-forks/kona", branch = "ratan/add-converter" }
45+
kona-preimage = { git = "https://github.com/moongate-forks/kona", branch = "ratan/add-converter", features = [
4646
"rkyv",
4747
] }
48-
kona-primitives = { git = "https://github.com/ethereum-optimism/kona", branch = "main" }
49-
kona-mpt = { git = "https://github.com/ethereum-optimism/kona", branch = "main" }
50-
kona-derive = { git = "https://github.com/ethereum-optimism/kona", branch = "main", default-features = false }
51-
kona-executor = { git = "https://github.com/ethereum-optimism/kona", branch = "main" }
52-
kona-client = { git = "https://github.com/ethereum-optimism/kona", branch = "main" }
53-
kona-host = { git = "https://github.com/ethereum-optimism/kona", branch = "main" }
48+
kona-primitives = { git = "https://github.com/moongate-forks/kona", branch = "ratan/add-converter" }
49+
kona-mpt = { git = "https://github.com/moongate-forks/kona", branch = "ratan/add-converter" }
50+
kona-derive = { git = "https://github.com/moongate-forks/kona", branch = "ratan/add-converter", default-features = false }
51+
kona-executor = { git = "https://github.com/moongate-forks/kona", branch = "ratan/add-converter" }
52+
kona-client = { git = "https://github.com/moongate-forks/kona", branch = "ratan/add-converter" }
53+
kona-host = { git = "https://github.com/moongate-forks/kona", branch = "ratan/add-converter" }
54+
# kona-common = { path = "../kona/crates/common" }
55+
# kona-common-proc = { path = "../kona/crates/common-proc" }
56+
# kona-preimage = { path = "../kona/crates/preimage", features = ["rkyv"] }
57+
# kona-primitives = { path = "../kona/crates/primitives" }
58+
# kona-mpt = { path = "../kona/crates/mpt" }
59+
# kona-derive = { path = "../kona/crates/derive", default-features = false }
60+
# kona-executor = { path = "../kona/crates/executor" }
61+
# kona-client = { path = "../kona/bin/client" }
62+
# kona-host = { path = "../kona/bin/host" }
63+
5464

5565
# op-succinct
5666
op-succinct-prove = { path = "scripts/prove" }
@@ -97,3 +107,7 @@ bn = { git = "https://github.com/0xWOLAND/bn.git", package = "substrate-bn" }
97107
# Note: Patch alloy-primitives to use sha3 instead of tiny-keccak. Reduces cycle count for Keccak by 50%.
98108
sha3 = { git = "https://github.com/sp1-patches/RustCrypto-hashes", package = "sha3", branch = "patch-sha3-v0.10.8" }
99109
alloy-primitives = { git = "https://github.com/sp1-patches/alloy-core", branch = "patch-v0.7.7" }
110+
111+
# Patch op-alloy-protocol for recent exports for compatibility with kona.
112+
# TODO: Can remove later.
113+
op-alloy-protocol = { git = "https://github.com/alloy-rs/op-alloy" }

elf/range-elf

-928 KB
Binary file not shown.

proposer/op/proposer/db/db.go

+2
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ func (db *ProofDB) TryCreateAggProofFromSpanProofs(from, minTo uint64) (bool, ui
366366
start := from
367367
var end uint64
368368
for {
369+
fmt.Println("querying for span proof that starts at", start)
369370
spanProof, err := tx.ProofRequest.Query().
370371
Where(
371372
proofrequest.TypeEQ(proofrequest.TypeSPAN),
@@ -379,6 +380,7 @@ func (db *ProofDB) TryCreateAggProofFromSpanProofs(from, minTo uint64) (bool, ui
379380
}
380381
return false, 0, fmt.Errorf("failed to query SPAN proof: %w", err)
381382
}
383+
fmt.Println("found span proof", start, spanProof.EndBlock)
382384
end = spanProof.EndBlock
383385
start = end + 1
384386
}

proposer/op/proposer/driver.go

+29-29
Original file line numberDiff line numberDiff line change
@@ -559,22 +559,22 @@ func (l *L2OutputSubmitter) loopL2OO(ctx context.Context) {
559559
for {
560560
select {
561561
case <-ticker.C:
562-
// 1) Queue up any span batches that are ready to prove.
563-
// This is done by checking the chain for completed channels and pulling span batches out.
564-
// We break apart span batches if they exceed the max size, and gracefully handle bugs in span batch decoding.
565-
// We add ranges to be proven to the DB as "UNREQ" so they are queued up to request later.
566-
l.Log.Info("Stage 1: Deriving Span Batches...")
567-
err := l.DeriveNewSpanBatches(ctx)
568-
if err != nil {
569-
l.Log.Error("failed to add next span batches to db", "err", err)
570-
continue
571-
}
562+
// // 1) Queue up any span batches that are ready to prove.
563+
// // This is done by checking the chain for completed channels and pulling span batches out.
564+
// // We break apart span batches if they exceed the max size, and gracefully handle bugs in span batch decoding.
565+
// // We add ranges to be proven to the DB as "UNREQ" so they are queued up to request later.
566+
// l.Log.Info("Stage 1: Deriving Span Batches...")
567+
// err := l.DeriveNewSpanBatches(ctx)
568+
// if err != nil {
569+
// l.Log.Error("failed to add next span batches to db", "err", err)
570+
// continue
571+
// }
572572

573573
// 2) Check the statuses of all requested proofs.
574574
// If it's successfully returned, we validate that we have it on disk and set status = "COMPLETE".
575575
// If it fails or times out, we set status = "FAILED" (and, if it's a span proof, split the request in half to try again).
576576
l.Log.Info("Stage 2: Processing Pending Proofs...")
577-
err = l.ProcessPendingProofs()
577+
err := l.ProcessPendingProofs()
578578
if err != nil {
579579
l.Log.Error("failed to update requested proofs", "err", err)
580580
continue
@@ -590,24 +590,24 @@ func (l *L2OutputSubmitter) loopL2OO(ctx context.Context) {
590590
continue
591591
}
592592

593-
// 4) Request all unrequested proofs from the prover network.
594-
// Any DB entry with status = "UNREQ" means it's queued up and ready.
595-
// We request all of these (both span and agg) from the prover network.
596-
// For agg proofs, we also checkpoint the blockhash in advance.
597-
l.Log.Info("Stage 4: Requesting Queued Proofs...")
598-
err = l.RequestQueuedProofs(ctx)
599-
if err != nil {
600-
l.Log.Error("failed to request unrequested proofs", "err", err)
601-
continue
602-
}
603-
604-
// 5) Submit agg proofs on chain.
605-
// If we have a completed agg proof waiting in the DB, we submit them on chain.
606-
l.Log.Info("Stage 5: Submitting Agg Proofs...")
607-
err = l.SubmitAggProofs(ctx)
608-
if err != nil {
609-
l.Log.Error("failed to submit agg proofs", "err", err)
610-
}
593+
// // 4) Request all unrequested proofs from the prover network.
594+
// // Any DB entry with status = "UNREQ" means it's queued up and ready.
595+
// // We request all of these (both span and agg) from the prover network.
596+
// // For agg proofs, we also checkpoint the blockhash in advance.
597+
// l.Log.Info("Stage 4: Requesting Queued Proofs...")
598+
// err = l.RequestQueuedProofs(ctx)
599+
// if err != nil {
600+
// l.Log.Error("failed to request unrequested proofs", "err", err)
601+
// continue
602+
// }
603+
604+
// // 5) Submit agg proofs on chain.
605+
// // If we have a completed agg proof waiting in the DB, we submit them on chain.
606+
// l.Log.Info("Stage 5: Submitting Agg Proofs...")
607+
// err = l.SubmitAggProofs(ctx)
608+
// if err != nil {
609+
// l.Log.Error("failed to submit agg proofs", "err", err)
610+
// }
611611
case <-l.done:
612612
return
613613
}

proposer/succinct/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn main() {
6161
// Note: Don't comment this out, because the Docker program depends on the native program
6262
// for range being built.
6363
build_native_program(program);
64-
// build_zkvm_program(program);
64+
build_zkvm_program(program);
6565
}
6666

6767
// build_zkvm_program("aggregation");
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12

python-db-explorations/README.md

Whitespace-only changes.

python-db-explorations/hello.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def main():
2+
print("Hello from python-db-explorations!")
3+
4+
5+
if __name__ == "__main__":
6+
main()

python-db-explorations/pyproject.toml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[project]
2+
name = "python-db-explorations"
3+
version = "0.1.0"
4+
description = "Add your description here"
5+
readme = "README.md"
6+
requires-python = ">=3.12"
7+
dependencies = []
8+
9+
[project.scripts]
10+
query-proofs = "query_proofs.py"
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import sqlite3
2+
from enum import Enum
3+
4+
class ProofType(Enum):
5+
SPAN = 1
6+
AGG = 2
7+
8+
class ProofStatus(Enum):
9+
UNREQ = 1
10+
REQ = 2
11+
COMPLETE = 3
12+
FAILED = 4
13+
14+
def query_span_proofs(db_path, start_block):
15+
conn = sqlite3.connect(db_path)
16+
cursor = conn.cursor()
17+
18+
# query = """
19+
# SELECT * FROM proof_requests
20+
# WHERE type = ? AND status = ? AND start_block = ?
21+
# """
22+
# cursor.execute(query, (ProofType.SPAN.value, ProofStatus.COMPLETE.value, start_block))
23+
24+
query = """
25+
SELECT * FROM proof_requests
26+
WHERE type = 'SPAN' AND start_block = ?
27+
"""
28+
cursor.execute(query, (start_block,))
29+
30+
results = cursor.fetchall()
31+
if results:
32+
first_result = results[0]
33+
# print(f"ID: {first_result[0]}")
34+
# print(f"Type: {first_result[1]}")
35+
# print(f"Start Block: {first_result[2]}")
36+
# print(f"End Block: {first_result[3]}")
37+
# print(f"Status: {first_result[4]}")
38+
# print(f"Request Added Time: {first_result[5]}")
39+
# print(f"Prover Request ID: {first_result[6]}")
40+
# print(f"Proof Request Time: {first_result[7]}")
41+
# print(f"L1 Block Number: {first_result[8]}")
42+
# print(f"L1 Block Hash: {first_result[9]}")
43+
# print(f"Proof: {first_result[10]}")
44+
45+
# print("Results:", results)
46+
conn.close()
47+
48+
return results
49+
50+
if __name__ == "__main__":
51+
print("Querying span proofs")
52+
db_path = "../db/proofs.db"
53+
54+
start_block = 16843141 # Replace with the desired start block
55+
for i in range(1000):
56+
57+
proofs = query_span_proofs(db_path, start_block)
58+
59+
for proof in proofs:
60+
print(f"Proof ID: {proof[0]}, Start Block: {proof[2]}, End Block: {proof[3]}, Status: {proof[4]}, Prover Request ID: {proof[6]}")
61+
start_block += 1

python-db-explorations/uv.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2024-08-01"
2+
channel = "1.79"
33
components = ["llvm-tools", "rustc-dev"]

scripts/prove/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,4 @@ rayon = "1.10.0"
6262
[build-dependencies]
6363
sp1-build = { workspace = true }
6464
op-succinct-host-utils = { workspace = true }
65+
cargo_metadata.workspace = true

scripts/prove/build.rs

+63-31
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,71 @@
1-
// use std::process::Command;
1+
use std::process::Command;
22

3-
// use sp1_build::{build_program_with_args, BuildArgs};
3+
use sp1_build::{build_program_with_args, BuildArgs};
44

55
/// Build a native program.
6-
// fn build_native_program(program: &str) {
7-
// let status = Command::new("cargo")
8-
// .args(["build", "--workspace", "--bin", program, "--profile", "release-client-lto"])
9-
// .status()
10-
// .expect("Failed to execute cargo build command");
11-
12-
// if !status.success() {
13-
// panic!("Failed to build {}", program);
14-
// }
15-
16-
// println!("cargo:warning={} built with release-client-lto profile", program);
17-
// }
18-
19-
// /// Build a program for the zkVM.
20-
// fn build_zkvm_program(program: &str) {
21-
// build_program_with_args(
22-
// &format!("../../programs/{}", program),
23-
// BuildArgs {
24-
// elf_name: format!("{}-elf", program),
25-
// // docker: true,
26-
// ..Default::default()
27-
// },
28-
// );
29-
// }
6+
fn build_native_program(program: &str) {
7+
let status = Command::new("cargo")
8+
.args(["build", "--workspace", "--bin", program, "--profile", "release-client-lto"])
9+
.status()
10+
.expect("Failed to execute cargo build command");
11+
12+
if !status.success() {
13+
panic!("Failed to build {}", program);
14+
}
15+
16+
println!("cargo:warning={} built with release-client-lto profile", program);
17+
}
18+
19+
/// Build the native host runner to a separate target directory to avoid build lockups.
20+
fn build_native_host_runner() {
21+
let metadata =
22+
cargo_metadata::MetadataCommand::new().exec().expect("Failed to get cargo metadata");
23+
let target_dir = metadata.target_directory.join("native_host_runner");
24+
25+
let status = Command::new("cargo")
26+
.args([
27+
"build",
28+
"--workspace",
29+
"--bin",
30+
"native_host_runner",
31+
"--release",
32+
"--target-dir",
33+
target_dir.as_ref(),
34+
])
35+
.status()
36+
.expect("Failed to execute cargo build command");
37+
if !status.success() {
38+
panic!("Failed to build native_host_runner");
39+
}
40+
41+
println!("cargo:warning=native_host_runner built with release profile",);
42+
}
43+
44+
/// Build a program for the zkVM.
45+
#[allow(dead_code)]
46+
fn build_zkvm_program(program: &str) {
47+
build_program_with_args(
48+
&format!("../../programs/{}", program),
49+
BuildArgs {
50+
elf_name: format!("{}-elf", program),
51+
// docker: true,
52+
..Default::default()
53+
},
54+
);
55+
}
3056

3157
fn main() {
32-
// let programs = vec!["range"];
33-
// for program in programs {
34-
// build_native_program(program);
35-
// build_zkvm_program(program);
36-
// }
58+
let programs = vec!["range"];
59+
60+
for program in programs {
61+
// Note: Don't comment this out, because the Docker program depends on the native program
62+
// for range being built.
63+
build_native_program(program);
64+
build_zkvm_program(program);
65+
}
3766

3867
// build_zkvm_program("aggregation");
68+
// Note: Don't comment this out, because the Docker program depends on the native host runner
69+
// being built.
70+
build_native_host_runner();
3971
}

utils/host/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ alloy-sol-types.workspace = true
1212
op-succinct-client-utils.workspace = true
1313
rkyv.workspace = true
1414
kona-host.workspace = true
15+
kona-preimage.workspace = true
1516
sp1-sdk.workspace = true
1617
anyhow.workspace = true
1718
cargo_metadata.workspace = true

utils/host/src/helpers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn load_kv_store(data_dir: &PathBuf) -> HashMap<[u8; 32], Vec<u8>, BytesHash
1313
if path.is_file() {
1414
// Extract the file name
1515
let file_name = path.file_stem().unwrap().to_str().unwrap();
16-
16+
println!("File name: {:?}", file_name);
1717
// Convert the file name to PreimageKey
1818
if let Ok(key) = hex::decode(file_name) {
1919
// Read the file contents

0 commit comments

Comments
 (0)