Skip to content

Commit 8b6391a

Browse files
committed
feat: write program vk_hash
1 parent e66b833 commit 8b6391a

7 files changed

Lines changed: 53 additions & 22 deletions

File tree

examples/L2/Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/L2/Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,10 @@
33
SHELL := /bin/bash
44

55
run:
6-
@cd crates/l2 && cargo run --release
6+
@cd crates/l2 && cargo run --release --bin main
7+
8+
print_program_id:
9+
@cd crates/l2 && cargo run --release --bin write_program_id
10+
@cat ./crates/l2/programs_ids.json
11+
12+

examples/L2/contracts/script/StateTransitionDeployer.sol

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/L2/crates/l2/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ serde_json = { workspace = true }
99
types = { workspace = true }
1010
lambdaworks-crypto = { workspace = true }
1111
primitive-types = { workspace = true}
12+
tracing = { version = "0.1", features = ["log"] }
13+
tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }
1214
rand = "0.8"
1315
sp1-sdk = "4.1.7"
1416
sp1_state_transition_program = { path = "./zkvm_programs/sp1/" }
@@ -18,6 +20,14 @@ futures-util = "0.3"
1820
tokio = "1.44"
1921
alloy = { version = "0.14", features = ["full", "providers"] }
2022

23+
[[bin]]
24+
name = "main"
25+
path = "./src/main.rs"
26+
27+
[[bin]]
28+
name = "write_program_id"
29+
path = "./zkvm_programs/bin/write_program_ids.rs"
30+
2131
[build-dependencies]
2232
sp1-build = { version = "4.1.7" }
2333

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"sp1_vk_hash": "0x5961f68d41b2798f4dab05184d8f9cda39637d28097819906033c2f10b365ab1"
3+
}

examples/L2/crates/l2/zkvm_programs/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ members = ["sp1"]
77

88
[workspace.dependencies]
99
types = { path = "../../types"}
10+
tracing = { version = "0.1", features = ["log"] }
11+
tracing-subscriber = { version = "0.3.0", features = ["env-filter"] }
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use alloy::hex::hex;
2+
use serde_json::json;
3+
use sp1_sdk::{HashableKey, Prover};
4+
use std::{fs, path::Path};
5+
use tracing::info;
6+
use tracing_subscriber::FmtSubscriber;
7+
8+
const SP1_PROGRAM_ELF: &[u8] = include_bytes!("../sp1/elf/sp1_state_transition_program");
9+
10+
fn main() {
11+
let subscriber = FmtSubscriber::builder().finish();
12+
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
13+
14+
info!("About to write sp1 program vk hash bytes");
15+
let client = sp1_sdk::ProverClient::builder().cpu().build();
16+
let (_pk, vk) = client.setup(SP1_PROGRAM_ELF);
17+
let sp1_vk_hash = vk.hash_bytes();
18+
let sp1_vk_hash_hex = hex::encode(sp1_vk_hash);
19+
20+
let dest_path = Path::new("programs_ids.json");
21+
let json_data = json!({
22+
"sp1_vk_hash": format!("0x{}", sp1_vk_hash_hex),
23+
});
24+
25+
// Write to the file
26+
fs::write(dest_path, serde_json::to_string_pretty(&json_data).unwrap()).unwrap();
27+
28+
info!("Program ids written to {:?}", dest_path);
29+
}

0 commit comments

Comments
 (0)