Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/zkevm-zisk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
build
target
Cargo.lock
15 changes: 15 additions & 0 deletions crates/zkevm-zisk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "sha_hasher"
version = "0.1.0"
edition = "2021"
default-run = "sha_hasher"

[dependencies]
byteorder = "1.5.0"
sha2 = "0.10.8"
ziskos = { git = "https://github.com/0xPolygonHermez/zisk.git" }

# reth-ethereum-primitives = { git = "https://github.com/kevaundray/reth", rev = "96de1f325d8835d589bd505b9f94507904f20963" }
# reth-primitives-traits = { git = "https://github.com/kevaundray/reth", rev = "96de1f325d8835d589bd505b9f94507904f20963" }
# reth-stateless = { git = "https://github.com/kevaundray/reth", rev = "96de1f325d8835d589bd505b9f94507904f20963" }

25 changes: 25 additions & 0 deletions crates/zkevm-zisk/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::fs::{self, File};
use std::io::{self, Write};
use std::path::Path;

// Define constants for the directory and input file name
const OUTPUT_DIR: &str = "build/";
const FILE_NAME: &str = "input.bin";

fn main() -> io::Result<()> {
let n: u64 = 20;

// Ensure the output directory exists
let output_dir = Path::new(OUTPUT_DIR);
if !output_dir.exists() {
// Create the directory and any necessary parent directories
fs::create_dir_all(output_dir)?;
}

// Create the file and write the 'n' value in little-endian format
let file_path = output_dir.join(FILE_NAME);
let mut file = File::create(&file_path)?;
file.write_all(&n.to_le_bytes())?;

Ok(())
}
Empty file added crates/zkevm-zisk/file.patch
Empty file.
40 changes: 40 additions & 0 deletions crates/zkevm-zisk/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// This example program takes a number `n` as input and computes the SHA-256 hash `n` times sequentially.

// Mark the main function as the entry point for ZisK
#![no_main]
ziskos::entrypoint!(main);

use byteorder::ByteOrder;
use sha2::{Digest, Sha256};
use std::convert::TryInto;
use ziskos::{read_input, set_output};

fn main() {
// Read the input data as a byte array from ziskos
let input: Vec<u8> = read_input();

// Convert the input data to a u64 integer
let n: u64 = match input.try_into() {
Ok(input_bytes) => u64::from_le_bytes(input_bytes),
Err(input) => panic!(
"Invalid input length. Expected 8 bytes, got {}",
input.len()
),
};

let mut hash = [0u8; 32];

// Compute SHA-256 hashing 'n' times
for _ in 0..n {
let mut hasher = Sha256::new();
hasher.update(hash);
let digest = &hasher.finalize();
hash = Into::<[u8; 32]>::into(*digest);
}

// Split 'hash' value into chunks of 32 bits and write them to ziskos output
for i in 0..8 {
let val = byteorder::BigEndian::read_u32(&mut hash[i * 4..i * 4 + 4]);
set_output(i, val);
}
}