Skip to content

Commit 0a6419f

Browse files
fix(aggregation-mode): hardcode image_id and vk_hash from solidity contract (#1910)
Co-authored-by: Julian Arce <[email protected]>
1 parent 3b38eb5 commit 0a6419f

19 files changed

+155
-41
lines changed

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,13 @@ reset_last_aggregated_block:
171171
@echo '{"last_aggregated_block":0}' > config-files/proof-aggregator.last_aggregated_block.json
172172

173173
start_proof_aggregator_dev: is_aggregator_set reset_last_aggregated_block ## Starts proof aggregator with mock proofs (DEV mode)
174-
AGGREGATOR=$(AGGREGATOR) RISC0_DEV_MODE=1 cargo run --manifest-path ./aggregation_mode/Cargo.toml --release -- config-files/config-proof-aggregator-mock.yaml
174+
AGGREGATOR=$(AGGREGATOR) RISC0_DEV_MODE=1 cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --bin proof_aggregator -- config-files/config-proof-aggregator-mock.yaml
175175

176176
start_proof_aggregator: is_aggregator_set reset_last_aggregated_block ## Starts proof aggregator with proving activated
177-
AGGREGATOR=$(AGGREGATOR) cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove -- config-files/config-proof-aggregator.yaml
177+
AGGREGATOR=$(AGGREGATOR) cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove --bin proof_aggregator -- config-files/config-proof-aggregator.yaml
178178

179179
start_proof_aggregator_gpu: is_aggregator_set reset_last_aggregated_block ## Starts proof aggregator with proving + GPU acceleration (CUDA)
180-
AGGREGATOR=$(AGGREGATOR) SP1_PROVER=cuda cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove,gpu -- config-files/config-proof-aggregator.yaml
180+
AGGREGATOR=$(AGGREGATOR) SP1_PROVER=cuda cargo run --manifest-path ./aggregation_mode/Cargo.toml --release --features prove,gpu --bin proof_aggregator -- config-files/config-proof-aggregator.yaml
181181

182182
verify_aggregated_proof_sp1_holesky_stage:
183183
@echo "Verifying SP1 in aggregated proofs on holesky..."
@@ -204,7 +204,11 @@ verify_aggregated_proof_risc0_holesky_stage:
204204
--rpc_url https://ethereum-holesky-rpc.publicnode.com
205205

206206
install_aggregation_mode: ## Install the aggregation mode with proving enabled
207-
cargo install --path aggregation_mode --features prove,gpu
207+
cargo install --path aggregation_mode --features prove,gpu --bin proof_aggregator
208+
209+
agg_mode_write_program_ids: ## Write proof aggregator zkvm programs ids
210+
@cd aggregation_mode && \
211+
cargo run --release --bin write_program_image_id_vk_hash
208212

209213
_AGGREGATOR_:
210214

aggregation_mode/Cargo.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ name = "proof_aggregator"
33
version = "0.1.0"
44
edition = "2021"
55

6-
76
[dependencies]
87
serde = { version = "1.0.203", features = ["derive"] }
98
serde_json = "1.0.117"
@@ -41,3 +40,11 @@ opt-level = 3
4140
default = []
4241
prove = []
4342
gpu = ["risc0-zkvm/cuda"]
43+
44+
[[bin]]
45+
name = "proof_aggregator"
46+
path = "./src/main.rs"
47+
48+
[[bin]]
49+
name = "write_program_image_id_vk_hash"
50+
path = "./bin/write_program_image_id_vk_hash.rs"

aggregation_mode/abi/AlignedProofAggregationService.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use alloy::hex::hex;
2+
use proof_aggregator::aggregators::{
3+
risc0_aggregator::RISC0_AGGREGATOR_PROGRAM_ID_BYTES, sp1_aggregator,
4+
};
5+
use serde_json::json;
6+
use sp1_sdk::HashableKey;
7+
use std::{env, fs, path::Path};
8+
use tracing::info;
9+
use tracing_subscriber::FmtSubscriber;
10+
11+
const SP1_PROGRAM_ELF: &[u8] =
12+
include_bytes!("../aggregation_programs/sp1/elf/sp1_aggregator_program");
13+
14+
include!(concat!(env!("OUT_DIR"), "/methods.rs"));
15+
16+
fn main() {
17+
let subscriber = FmtSubscriber::builder().finish();
18+
tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
19+
20+
info!("About to write sp1 programs vk hash bytes + risc0 programs image id bytes");
21+
let sp1_vk_hash = sp1_aggregator::vk_from_elf(SP1_PROGRAM_ELF).bytes32_raw();
22+
let risc0_image_id_bytes = RISC0_AGGREGATOR_PROGRAM_ID_BYTES;
23+
24+
let sp1_vk_hash_hex = hex::encode(sp1_vk_hash);
25+
let risc0_image_id_hex = hex::encode(risc0_image_id_bytes);
26+
27+
let dest_path = Path::new("programs_ids.json");
28+
29+
let json_data = json!({
30+
"sp1_vk_hash": format!("0x{}", sp1_vk_hash_hex),
31+
"risc0_image_id": format!("0x{}", risc0_image_id_hex),
32+
});
33+
34+
// Write to the file
35+
fs::write(dest_path, serde_json::to_string_pretty(&json_data).unwrap()).unwrap();
36+
37+
info!("Program ids written to {:?}", dest_path);
38+
}

aggregation_mode/programs_ids.json

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

aggregation_mode/src/aggregators/risc0_aggregator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use risc0_zkvm::{default_prover, ExecutorEnv, ProverOpts, Receipt};
44
use sha3::{Digest, Keccak256};
55

66
/// Byte representation of the aggregator image_id, converted from `[u32; 8]` to `[u8; 32]`.
7-
const RISC0_AGGREGATOR_PROGRAM_ID_BYTES: [u8; 32] = {
7+
pub const RISC0_AGGREGATOR_PROGRAM_ID_BYTES: [u8; 32] = {
88
let mut res = [0u8; 32];
99
let mut i = 0;
1010
while i < 8 {

aggregation_mode/src/backend/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use config::Config;
2020
use fetcher::{ProofsFetcher, ProofsFetcherError};
2121
use merkle_tree::compute_proofs_merkle_root;
2222
use risc0_ethereum_contracts::encode_seal;
23-
use sp1_sdk::HashableKey;
2423
use std::str::FromStr;
2524
use tracing::{error, info, warn};
2625
use types::{AlignedProofAggregationService, AlignedProofAggregationServiceContract};
@@ -154,7 +153,6 @@ impl ProofAggregator {
154153
self.proof_aggregation_service
155154
.verifySP1(
156155
blob_versioned_hash.into(),
157-
proof.vk().bytes32_raw().into(),
158156
proof.proof_with_pub_values.public_values.to_vec().into(),
159157
proof.proof_with_pub_values.bytes().into(),
160158
)
@@ -170,7 +168,6 @@ impl ProofAggregator {
170168
.verifyRisc0(
171169
blob_versioned_hash.into(),
172170
encoded_seal.into(),
173-
proof.image_id.into(),
174171
proof.receipt.journal.bytes.into(),
175172
)
176173
.sidecar(blob)

contracts/script/deploy/AlignedProofAggregationServiceDeployer.s.sol

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ contract AlignedProofAggregationServiceDeployer is Script {
1212

1313
address alignedAggregatorAddress = stdJson.readAddress(config_data, ".address.alignedAggregatorAddress");
1414
address sp1VerifierAddress = stdJson.readAddress(config_data, ".address.sp1VerifierAddress");
15+
bytes32 sp1AggregationProgramVKHash =
16+
stdJson.readBytes32(config_data, ".programs_id.sp1AggregationProgramVKHash");
1517
address risc0VerifierAddress = stdJson.readAddress(config_data, ".address.risc0VerifierAddress");
18+
bytes32 risc0AggregationProgramImageId =
19+
stdJson.readBytes32(config_data, ".programs_id.risc0AggregationProgramImageId");
1620

1721
address ownerAddress = stdJson.readAddress(config_data, ".permissions.owner");
1822

@@ -23,11 +27,13 @@ contract AlignedProofAggregationServiceDeployer is Script {
2327
ERC1967Proxy proxy = new ERC1967Proxy(
2428
address(alignedProofAggregationService),
2529
abi.encodeWithSignature(
26-
"initialize(address,address,address,address)",
30+
"initialize(address,address,address,address,bytes32,bytes32)",
2731
ownerAddress,
2832
alignedAggregatorAddress,
2933
sp1VerifierAddress,
30-
risc0VerifierAddress
34+
risc0VerifierAddress,
35+
risc0AggregationProgramImageId,
36+
sp1AggregationProgramVKHash
3137
)
3238
);
3339

contracts/script/deploy/config/devnet/proof-aggregator-service.devnet.config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
"alignedAggregatorAddress": "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720",
66
"alignedAggregatorAddressPrivateKey": "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6"
77
},
8+
"programs_id": {
9+
"sp1AggregationProgramVKHash": "0x00eb8139c8360fc371b9a6decdec55ba01aaae0f4739f68139e0b3d40397d1d6",
10+
"risc0AggregationProgramImageId": "0xa2966b3e63b5e73848dd3fb8ff1e03ac68ca10fa961ca0c0d8dbbb0a85b60acd"
11+
},
812
"permissions": {
913
"owner": "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955"
1014
}

contracts/script/deploy/config/devnet/proof-aggregator-service.devnet.mock.config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
"alignedAggregatorAddress": "0xa0Ee7A142d267C1f36714E4a8F75612F20a79720",
66
"alignedAggregatorAddressPrivateKey": "0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6"
77
},
8+
"programs_id": {
9+
"sp1AggregationProgramVKHash": "0x00eb8139c8360fc371b9a6decdec55ba01aaae0f4739f68139e0b3d40397d1d6",
10+
"risc0AggregationProgramImageId": "0xa2966b3e63b5e73848dd3fb8ff1e03ac68ca10fa961ca0c0d8dbbb0a85b60acd"
11+
},
812
"permissions": {
913
"owner": "0x14dC79964da2C08b23698B3D3cc7Ca32193d9955"
1014
}

0 commit comments

Comments
 (0)