Skip to content

Commit a94c35b

Browse files
committed
feat: zisk write program ids
1 parent c3311d3 commit a94c35b

12 files changed

Lines changed: 310 additions & 253 deletions

aggregation_mode/proof_aggregator/aggregation_programs/Cargo.lock

Lines changed: 203 additions & 240 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.

aggregation_mode/proof_aggregator/aggregation_programs/zisk/src/chunk_aggregator_main.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ use lambdaworks_crypto::merkle_tree::merkle::MerkleTree;
55
use zisk_aggregation_program::{ChunkAggregatorInput, Hash32};
66

77
// Generated with `make proof_aggregator_write_program_ids` and copied from program_ids.json
8-
pub const USER_PROOFS_AGGREGATOR_PROGRAM_VK_HASH: [u8; 32] = [
9-
86, 146, 102, 198, 206, 75, 142, 66, 123, 251, 236, 150, 2, 205, 75, 142, 237, 255, 93, 54, 2,
10-
16, 190, 188, 246, 3, 188, 241, 235, 64, 220, 228,
8+
pub const USER_PROOFS_AGGREGATOR_PROGRAM_ROM_ROOT: [u64; 4] = [
9+
9552917093105913802,
10+
7845128850459495418,
11+
6121665346010988278,
12+
15056293071596476132,
1113
];
1214

1315
pub fn main() {
@@ -18,12 +20,6 @@ pub fn main() {
1820

1921
// Verify the proofs.
2022
for (proof, leaves_commitment) in input.proofs_and_leaves_commitment {
21-
// Ensure the aggregated chunk originates from the user proofs aggregation program.
22-
// This validation step guarantees that the proof was genuinely verified
23-
// by this program. Without this check, a different program using the
24-
// same public inputs could bypass verification.
25-
assert!(proof.vk.clone() == USER_PROOFS_AGGREGATOR_PROGRAM_VK_HASH);
26-
2723
let proof_words = bytemuck::cast_slice::<u8, u64>(&proof.proof);
2824

2925
// Reading public inputs as done in the verify of the lib at https://github.com/0xPolygonHermez/zisk/blob/maint/checkouts/pil2-proofman-3d49384e4e2f0af7/78497c5/verifier/src/verifier.rs#L66-L73
@@ -32,12 +28,24 @@ pub fn main() {
3228
p += 1;
3329

3430
// we should end up with a vector of length 4 as the public input is a 256 bits digest
31+
let mut rom_vkey: [u64; 4] = [0_u64; 4];
3532
let mut publics = Vec::new();
36-
for _ in 0..n_public_inputs {
33+
for i in 0..n_public_inputs {
34+
// The first 4 entries are the rom vkey
35+
if i < 4 {
36+
rom_vkey[i as usize] = proof_words[p];
37+
}
38+
3739
publics.push(proof_words[p]);
3840
p += 1;
3941
}
4042

43+
// Ensure the aggregated chunk originates from the user proofs aggregation program.
44+
// This validation step guarantees that the proof was genuinely verified
45+
// by this program. Without this check, a different program using the
46+
// same public inputs could bypass verification.
47+
assert!(rom_vkey == USER_PROOFS_AGGREGATOR_PROGRAM_ROM_ROOT);
48+
4149
let merkle_root_words: [u64; 4] = publics
4250
.try_into()
4351
.expect("Public input to be the hash of the chunk tree");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
�Q�P�[��YDHX/�Uks�`~=��u� �
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
��U�{ǒ������l��;2��T�֮�Ʋ��

aggregation_mode/proof_aggregator/bin/write_program_image_id_vk_hash.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use alloy::hex;
2-
use proof_aggregator::aggregators::{risc0_aggregator, sp1_aggregator};
2+
use proof_aggregator::aggregators::{risc0_aggregator, sp1_aggregator, zisk_aggregator};
33
use serde_json::json;
44
use sp1_sdk::HashableKey;
55
use std::{fs, path::Path};
@@ -16,7 +16,9 @@ fn main() {
1616
let subscriber = FmtSubscriber::builder().finish();
1717
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
1818

19-
info!("About to write sp1 programs vk hash bytes + risc0 programs image id bytes");
19+
info!(
20+
"About to write sp1 programs vk hash bytes + risc0 programs image id bytes + zisk rom vk"
21+
);
2022
let sp1_user_proofs_aggregator_vk_hash =
2123
sp1_aggregator::vk_from_elf(SP1_USER_PROOFS_AGGREGATOR_PROGRAM_ELF).bytes32_raw();
2224
let sp1_user_proofs_aggregator_vk_hash_words =
@@ -29,6 +31,9 @@ fn main() {
2931
let risc0_chunk_aggregator_image_id_bytes =
3032
risc0_aggregator::RISC0_CHUNK_AGGREGATOR_PROGRAM_ID_BYTES;
3133

34+
let zisk_user_proofs_aggregator_rom_vk = zisk_aggregator::USER_PROOFS_PROGRAM_ROM_VK;
35+
let zisk_chunk_aggregator_rom_vk_hex = hex::encode(zisk_aggregator::CHUNK_PROGRAM_ROM_VK_BYTES);
36+
3237
let sp1_user_proofs_aggregator_vk_hash_hex = hex::encode(sp1_user_proofs_aggregator_vk_hash);
3338
let sp1_chunk_aggregator_vk_hash_hex = hex::encode(sp1_chunk_aggregator_vk_hash);
3439
let risc0_user_proofs_aggregator_image_id_hex =
@@ -44,6 +49,8 @@ fn main() {
4449
"risc0_user_proofs_aggregator_image_id": format!("0x{}", risc0_user_proofs_aggregator_image_id_hex),
4550
"risc0_user_proofs_aggregator_image_id_bytes": format!("{:?}", risc0_user_proofs_aggregator_image_id_bytes),
4651
"risc0_chunk_aggregator_image_id": format!("0x{}", risc0_chunk_aggregator_imaged_id_hex),
52+
"zisk_user_proofs_aggregator_rom_vk": format!("{:?}", zisk_user_proofs_aggregator_rom_vk),
53+
"zisk_chunk_aggregator_rom_vk_hex": format!("0x{}", zisk_chunk_aggregator_rom_vk_hex)
4754
});
4855

4956
// Write to the file

aggregation_mode/proof_aggregator/build.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,14 @@ fn main() {
5858
let zisk_rustc_path = rustc_path_for("zisk");
5959

6060
let mut build_command = std::process::Command::new("cargo-zisk");
61+
6162
let mut user_proof_aggregator_rom_setup_command = std::process::Command::new("cargo-zisk");
6263
let mut chunk_aggregator_rom_setup_command = std::process::Command::new("cargo-zisk");
6364

65+
let mut user_proof_aggregator_rom_vk_command = std::process::Command::new("cargo-zisk");
66+
let mut chunk_aggregator_rom_vk_command = std::process::Command::new("cargo-zisk");
67+
68+
// Zisk build elf command
6469
build_command
6570
.env("RUSTC", &zisk_rustc_path)
6671
.args(["build", "--release"])
@@ -74,6 +79,7 @@ fn main() {
7479
panic!("Failed to build zisk elfs");
7580
}
7681

82+
// Zisk rom-setup commands
7783
let user_proof_aggregator_rom_setup_status = user_proof_aggregator_rom_setup_command
7884
.args([
7985
"rom-setup",
@@ -104,6 +110,41 @@ fn main() {
104110
panic!("Failed to execute rom-setup command on chunk aggregator program");
105111
}
106112

113+
// Zisk rom-vkey commands
114+
let user_proofs_aggregator_rom_vkey_status = user_proof_aggregator_rom_vk_command
115+
.args([
116+
"rom-vkey",
117+
"--elf",
118+
"./target/riscv64ima-zisk-zkvm-elf/release/zisk_user_proofs_aggregator_program",
119+
"-o",
120+
"zisk/vk/zisk_user_proofs_aggregator_program",
121+
])
122+
.env("RUSTC", &zisk_rustc_path)
123+
.current_dir("./aggregation_programs/")
124+
.status()
125+
.unwrap();
126+
127+
if !user_proofs_aggregator_rom_vkey_status.success() {
128+
panic!("Failed to execute rom-vkey command on user proofs aggregator program");
129+
}
130+
131+
let chunk_aggregator_rom_vkey_status = chunk_aggregator_rom_vk_command
132+
.args([
133+
"rom-vkey",
134+
"--elf",
135+
"./target/riscv64ima-zisk-zkvm-elf/release/zisk_chunk_aggregator_program",
136+
"-o",
137+
"zisk/vk/zisk_chunk_aggregator_program",
138+
])
139+
.env("RUSTC", &zisk_rustc_path)
140+
.current_dir("./aggregation_programs/")
141+
.status()
142+
.unwrap();
143+
144+
if !chunk_aggregator_rom_vkey_status.success() {
145+
panic!("Failed to execute rom-vkey command on chunk aggregator program");
146+
}
147+
107148
let _ = std::fs::create_dir("./aggregation_programs/zisk/elf");
108149

109150
std::fs::copy(

aggregation_mode/proof_aggregator/programs_ids.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
"risc0_user_proofs_aggregator_image_id_bytes": "[86, 146, 102, 198, 206, 75, 142, 66, 123, 251, 236, 150, 2, 205, 75, 142, 237, 255, 93, 54, 2, 16, 190, 188, 246, 3, 188, 241, 235, 64, 220, 228]",
55
"sp1_chunk_aggregator_vk_hash": "0x00d6e32a34f68ea643362b96615591c94ee0bf99ee871740ab2337966a4f77af",
66
"sp1_user_proofs_aggregator_vk_hash": "0x00a0fe3e73d4dd5f66369c60629213c8a037da04f8f68724c8a15ed1d20a0d5e",
7-
"sp1_user_proofs_aggregator_vk_hash_words": "[1350508345, 1966561241, 1188269068, 690044042, 29282343, 1675238547, 289586595, 1376390494]"
7+
"sp1_user_proofs_aggregator_vk_hash_words": "[1350508345, 1966561241, 1188269068, 690044042, 29282343, 1675238547, 289586595, 1376390494]",
8+
"zisk_chunk_aggregator_rom_vk_hex": "0xfd518d50ee1b5bfe9e594448582fc8556b7313e2607e3d1f10a1d475800912b0",
9+
"zisk_user_proofs_aggregator_rom_vk": "[9552917093105913802, 7845128850459495418, 6121665346010988278, 15056293071596476132]"
810
}

aggregation_mode/proof_aggregator/scripts/build_programs.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ RISC0_USER_PROOFS_AGGREGATOR_IMAGE_ID_BYTES=`jq -r .risc0_user_proofs_aggregator
1010
RISC0_LINE="pub const USER_PROOFS_AGGREGATOR_PROGRAM_IMAGE_ID: [u8; 32] = $RISC0_USER_PROOFS_AGGREGATOR_IMAGE_ID_BYTES;\n"
1111
sed -i '' -e "/^pub const USER_PROOFS_AGGREGATOR_PROGRAM_IMAGE_ID.*/{N;N;N;s|.*|$RISC0_LINE|;}" aggregation_programs/risc0/src/chunk_aggregator_main.rs
1212

13+
ZISK_USER_PROOFS_AGGREGATOR_ROM_VK=`jq -r .zisk_user_proofs_aggregator_rom_vk programs_ids.json`
14+
ZISK_LINE="pub const USER_PROOFS_AGGREGATOR_PROGRAM_ROM_ROOT: [u64; 4] = $ZISK_USER_PROOFS_AGGREGATOR_ROM_VK;\n"
15+
sed -i '' -e "/^pub const USER_PROOFS_AGGREGATOR_PROGRAM_ROM_ROOT.*/{N;N;N;N;N;s|.*|$ZISK_LINE|;}" aggregation_programs/zisk/src/chunk_aggregator_main.rs
16+
1317
cd aggregation_programs
1418
cargo fmt --all
1519

0 commit comments

Comments
 (0)