Skip to content

Commit c313185

Browse files
committed
feat: zisk example and makefile targets to interact with zisk proofs
1 parent f0ee298 commit c313185

5 files changed

Lines changed: 98 additions & 3 deletions

File tree

Makefile

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,18 +279,27 @@ proof_aggregator_start_gpu: is_aggregator_set reset_last_aggregated_block ./aggr
279279
proof_aggregator_start_gpu_ethereum_package: is_aggregator_set reset_last_aggregated_block ./aggregation_mode/target/release/proof_aggregator_gpu ## Starts proof aggregator with proving activated in ethereum package. Parameters: AGGREGATOR=<sp1|risc0>
280280
AGGREGATOR=$(AGGREGATOR) SP1_PROVER=cuda ./aggregation_mode/target/release/proof_aggregator_gpu config-files/config-proof-aggregator-ethereum-package.yaml
281281

282-
verify_aggregated_proof_sp1:
282+
verify_aggregated_proof_sp1:
283283
@echo "Verifying SP1 in aggregated proofs on $(NETWORK)..."
284284
@cd aggregation_mode/cli/ && \
285-
cargo run verify-on-chain \
285+
cargo run verify-on-chain sp1 \
286286
--network $(NETWORK) \
287287
--beacon-url $(BEACON_URL) \
288288
--rpc-url $(RPC_URL) \
289289
--from-block $(FROM_BLOCK) \
290-
--proving-system SP1 \
291290
--vk-hash ../../scripts/test_files/sp1/sp1_fibonacci_5_0_0.vk \
292291
--public-inputs ../../scripts/test_files/sp1/sp1_fibonacci_5_0_0.pub
293292

293+
verify_aggregated_proof_zisk:
294+
@echo "Verifying Zisk in aggregated proofs on $(NETWORK)..."
295+
@cd aggregation_mode/cli/ && \
296+
cargo run verify-on-chain zisk \
297+
--network $(NETWORK) \
298+
--beacon-url $(BEACON_URL) \
299+
--rpc-url $(RPC_URL) \
300+
--from-block $(FROM_BLOCK) \
301+
--proof ../../scripts/test_files/zisk/sha_hasher/proof/vadcop_final_proof.bin
302+
294303
proof_aggregator_install: ## Install the aggregation mode with proving enabled
295304
cargo install --path aggregation_mode/proof_aggregator --features prove,gpu --bin proof_aggregator_gpu --locked
296305

@@ -335,6 +344,11 @@ agg_mode_gateway_send_sp1_proof:
335344
--vk scripts/test_files/sp1/sp1_fibonacci_5_0_0_vk.bin \
336345
--private-key "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
337346

347+
agg_mode_gateway_send_zisk_proof:
348+
@cargo run --manifest-path aggregation_mode/cli/Cargo.toml -- submit zisk \
349+
--proof scripts/test_files/zisk/sha_hasher/proof/vadcop_final_proof.bin \
350+
--private-key "0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d"
351+
338352
agg_mode_install_cli: ## Install the aggregation mode CLI
339353
@cargo install --path aggregation_mode/cli
340354

@@ -877,6 +891,12 @@ aligned_get_user_balance_holesky:
877891
--user_addr $(USER_ADDR)
878892

879893
__GENERATE_PROOFS__: ## ____
894+
895+
generate_zisk_proof:
896+
@cd scripts/test_files/zisk && cargo-zisk build --release && \
897+
cargo-zisk rom-setup -e target/riscv64ima-zisk-zkvm-elf/release/sha_hasher && \
898+
cargo-zisk prove -e target/riscv64ima-zisk-zkvm-elf/release/sha_hasher -i build/input.bin -o proof -a -y
899+
880900
generate_sp1_fibonacci_proof: ## Run the SP1 Fibonacci proof generator script
881901
@cd scripts/test_files/sp1/fibonacci_proof_generator/script && RUST_LOG=info cargo run --release
882902
@echo "Fibonacci proof and ELF generated in scripts/test_files/sp1 folder"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
target
3+
Cargo.lock
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "sha_hasher"
3+
version = "0.1.0"
4+
edition = "2021"
5+
default-run = "sha_hasher"
6+
7+
[dependencies]
8+
byteorder = "1.5.0"
9+
sha2 = "0.10.8"
10+
ziskos = { git = "https://github.com/0xPolygonHermez/zisk.git" }
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use std::fs::{self, File};
2+
use std::io::{self, Write};
3+
use std::path::Path;
4+
5+
// Define constants for the directory and input file name
6+
const OUTPUT_DIR: &str = "build/";
7+
const FILE_NAME: &str = "input.bin";
8+
9+
fn main() -> io::Result<()> {
10+
let n: u64 = 20;
11+
12+
// Ensure the output directory exists
13+
let output_dir = Path::new(OUTPUT_DIR);
14+
if !output_dir.exists() {
15+
// Create the directory and any necessary parent directories
16+
fs::create_dir_all(output_dir)?;
17+
}
18+
19+
// Create the file and write the 'n' value in little-endian format
20+
let file_path = output_dir.join(FILE_NAME);
21+
let mut file = File::create(&file_path)?;
22+
file.write_all(&n.to_le_bytes())?;
23+
24+
Ok(())
25+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// This example program takes a number `n` as input and computes the SHA-256 hash `n` times sequentially.
2+
3+
// Mark the main function as the entry point for ZisK
4+
#![no_main]
5+
ziskos::entrypoint!(main);
6+
7+
use sha2::{Digest, Sha256};
8+
use std::convert::TryInto;
9+
use ziskos::{read_input_slice, set_output};
10+
use byteorder::ByteOrder;
11+
12+
fn main() {
13+
// Read the input data as a byte array from ziskos
14+
let input = read_input_slice();
15+
16+
// Convert the input data to a u64 integer
17+
let n: u64 = match input.as_ref().try_into() {
18+
Ok(input_bytes) => u64::from_le_bytes(input_bytes),
19+
Err(e) => panic!("Invalid input, error: {}", e),
20+
};
21+
22+
let mut hash = [0u8; 32];
23+
24+
// Compute SHA-256 hashing 'n' times
25+
for _ in 0..n {
26+
let mut hasher = Sha256::new();
27+
hasher.update(hash);
28+
let digest = &hasher.finalize();
29+
hash = Into::<[u8; 32]>::into(*digest);
30+
}
31+
32+
// Split 'hash' value into chunks of 32 bits and write them to ziskos output
33+
for i in 0..8 {
34+
let val = byteorder::BigEndian::read_u32(&mut hash[i * 4..i * 4 + 4]);
35+
set_output(i, val);
36+
}
37+
}

0 commit comments

Comments
 (0)