From c797cd4ecd20a296a95e9d97986de168b2b8fa21 Mon Sep 17 00:00:00 2001 From: hecmas Date: Thu, 19 Dec 2024 17:25:40 +0000 Subject: [PATCH 1/3] Verify all tools update to handle one elf and multiple inputs --- tools/verify_all.sh | 239 ++++++++++++++++++++++++++++++++------------ 1 file changed, 173 insertions(+), 66 deletions(-) diff --git a/tools/verify_all.sh b/tools/verify_all.sh index 09abe5b5..6fdfbde4 100755 --- a/tools/verify_all.sh +++ b/tools/verify_all.sh @@ -1,96 +1,203 @@ #!/bin/bash -echo "Verify all ELF files found in a directory" - # Check that at least one argument has been passed if [ "$#" -lt 1 ]; then - echo "Usage: $0 [-l/--list -b/--begin -e/--end -d/--debug]" + echo "Usage: $0 [-l|--list] [-b|--begin ] [-e|--end ] [-d|--debug] [-i|--inputs ]" exit 1 fi -# Get the first argument as the directory path -if [[ "$1" != "" ]]; then - DIR="$1" +# Initialize variables +list=0 +begin=0 +end=0 +debug=0 +input_path="" +elf_mode=0 +default_input="/tmp/empty_input.bin" # Default input file + +# Check if the first argument is a file or directory +if [[ -f "$1" ]]; then + elf_file="$1" + elf_mode=1 +elif [[ -d "$1" ]]; then + dir="$1" else - DIR=. + echo "Invalid input. The first argument must be a directory or an ELF file." + exit 1 fi shift -echo "Verifying ELF files found in directory ${DIR}" # Parse optional arguments -LIST=0 -BEGIN=0 -END=0 -DEBUG=0 while [[ "$#" -gt 0 ]]; do case $1 in - -l|--list) LIST=1 ;; - -b|--begin) BEGIN=$2; shift; ;; - -e|--end) END=$2; shift; ;; - -d|--debug) DEBUG=1 ;; + -l|--list) list=1 ;; + -b|--begin) begin=$2; shift ;; + -e|--end) end=$2; shift ;; + -d|--debug) debug=1 ;; + -i|--inputs) input_path="$2"; shift ;; *) echo "Unknown parameter passed: $1"; exit 1 ;; esac shift done -ELF_FILES=`find $DIR -type f -name my.elf |sort` - -# List files with their corresponding index -COUNTER=0 -for ELF_FILE in $ELF_FILES -do - COUNTER=$((COUNTER+1)) - echo "File ${COUNTER}: ${ELF_FILE}" -done - -# Log begin and end options, if provided -if [ $BEGIN -ne 0 ]; then - echo "Beginning at file ${BEGIN}"; -fi -if [ $END -ne 0 ]; then - echo "Ending at file ${END}"; +# Ensure the default input file exists +if [[ ! -f $default_input ]]; then + touch "$default_input" fi -# If just listing, exit -if [ $LIST -eq 1 ]; then - echo "Exiting after listing files"; - exit 0; -fi +# Function to verify an ELF file with one or more input files +verify_elf_with_inputs() { + local elf_file=$1 + local input_path=$2 + local input_counter=0 + local input_total=0 + + echo "Verifying ELF file: $elf_file" + + if [[ -z $input_path ]]; then + # No input path provided, use the default input file + echo "Using default input file: $default_input" + + if [[ $debug -eq 1 ]]; then + # Run with debug flag + (cargo build --release && cd ../pil2-proofman; \ + cargo run --release --bin proofman-cli verify-constraints \ + --witness-lib ../zisk/target/release/libzisk_witness.so \ + --rom "$elf_file" -i "$default_input" \ + --proving-key ../zisk/build/provingKey -d) + else + # Run without debug flag + (cargo build --release && cd ../pil2-proofman; \ + cargo run --release --bin proofman-cli verify-constraints \ + --witness-lib ../zisk/target/release/libzisk_witness.so \ + --rom "$elf_file" -i "$default_input" \ + --proving-key ../zisk/build/provingKey) + fi + elif [[ -f $input_path ]]; then + # Single input file provided + echo "Using input file: $input_path" + + if [[ $debug -eq 1 ]]; then + # Run with debug flag + (cargo build --release && cd ../pil2-proofman; \ + cargo run --release --bin proofman-cli verify-constraints \ + --witness-lib ../zisk/target/release/libzisk_witness.so \ + --rom "$elf_file" -i "$input_path" \ + --proving-key ../zisk/build/provingKey -d) + else + # Run without debug flag + (cargo build --release && cd ../pil2-proofman; \ + cargo run --release --bin proofman-cli verify-constraints \ + --witness-lib ../zisk/target/release/libzisk_witness.so \ + --rom "$elf_file" -i "$input_path" \ + --proving-key ../zisk/build/provingKey) + fi + elif [[ -d $input_path ]]; then + # Directory of input files provided + input_files=$(find "$input_path" -type f | sort) + input_total=$(echo "$input_files" | wc -l) + if [[ -z "$input_files" ]]; then + echo "No input files found in directory: $input_path" + return + fi + + for input_file in $input_files; do + input_counter=$((input_counter + 1)) + echo "Using input $input_counter of $input_total: $input_file" + + if [[ $debug -eq 1 ]]; then + # Run with debug flag + (cargo build --release && cd ../pil2-proofman; \ + cargo run --release --bin proofman-cli verify-constraints \ + --witness-lib ../zisk/target/release/libzisk_witness.so \ + --rom "$elf_file" -i "$input_file" \ + --proving-key ../zisk/build/provingKey -d) + else + # Run without debug flag + (cargo build --release && cd ../pil2-proofman; \ + cargo run --release --bin proofman-cli verify-constraints \ + --witness-lib ../zisk/target/release/libzisk_witness.so \ + --rom "$elf_file" -i "$input_file" \ + --proving-key ../zisk/build/provingKey) + fi + done + else + echo "Invalid input path: $input_path" + exit 1 + fi +} -# Record the number of files -MAX_COUNTER=${COUNTER} +# Logic for multiple ELF files in a directory +if [[ $elf_mode -eq 0 ]]; then + echo "Verifying ELF files found in directory: $dir" -# Create an empty input file -INPUT_FILE="/tmp/empty_input.bin" -touch $INPUT_FILE + # Find ELF files in the directory + elf_files=$(find "$dir" -type f -name my.elf | sort) + if [[ -z "$elf_files" ]]; then + echo "No ELF files found in directory: $dir" + exit 0 + fi -# For all files -COUNTER=0 -for ELF_FILE in $ELF_FILES -do - # Increase file counter - COUNTER=$((COUNTER+1)) + # List files with their corresponding index + counter=0 + for elf_file in $elf_files; do + counter=$((counter + 1)) + echo "File $counter: $elf_file" + done - # Skip files lower than BEGIN - if [ $BEGIN -ne 0 ] && [ $COUNTER -lt $BEGIN ]; then - continue; + # Log begin and end options, if provided + if [ $begin -ne 0 ]; then + echo "Beginning at file $begin" fi - - # Skip files higher than END - if [ $END -ne 0 ] && [ $COUNTER -gt $END ]; then - continue; + if [ $end -ne 0 ]; then + echo "Ending at file $end" fi - # Varify the contraints for this file - echo "" - echo "Verifying file ${COUNTER} of ${MAX_COUNTER}: ${ELF_FILE}" - - if [ $DEBUG -eq 1 ]; then - # Run with debug flag - (cargo build --release && cd ../pil2-proofman; cargo run --release --bin proofman-cli verify-constraints --witness-lib ../zisk/target/release/libzisk_witness.so --rom $ELF_FILE -i $INPUT_FILE --proving-key ../zisk/build/provingKey -d) - else - # Run without debug flag - (cargo build --release && cd ../pil2-proofman; cargo run --release --bin proofman-cli verify-constraints --witness-lib ../zisk/target/release/libzisk_witness.so --rom $ELF_FILE -i $INPUT_FILE --proving-key ../zisk/build/provingKey) + # If just listing, exit + if [ $list -eq 1 ]; then + echo "Exiting after listing files" + exit 0 fi -done + + # Record the number of files + max_counter=$counter + + # For all ELF files + counter=0 + for elf_file in $elf_files; do + counter=$((counter + 1)) + + # Skip files lower than begin + if [ $begin -ne 0 ] && [ $counter -lt $begin ]; then + continue + fi + + # Skip files higher than end + if [ $end -ne 0 ] && [ $counter -gt $end ]; then + continue + fi + + echo "" + echo "Verifying file $counter of $max_counter: $elf_file" + + if [ $debug -eq 1 ]; then + # Run with debug flag + (cargo build --release && cd ../pil2-proofman; \ + cargo run --release --bin proofman-cli verify-constraints \ + --witness-lib ../zisk/target/release/libzisk_witness.so \ + --rom "$elf_file" -i "$default_input" \ + --proving-key ../zisk/build/provingKey -d) + else + # Run without debug flag + (cargo build --release && cd ../pil2-proofman; \ + cargo run --release --bin proofman-cli verify-constraints \ + --witness-lib ../zisk/target/release/libzisk_witness.so \ + --rom "$elf_file" -i "$default_input" \ + --proving-key ../zisk/build/provingKey) + fi + done +else + # Logic for single ELF file with input directory or file + verify_elf_with_inputs "$elf_file" "$input_path" +fi From 791e37ffc325a88ef5ef842dafe10688070e9397 Mon Sep 17 00:00:00 2001 From: hecmas Date: Thu, 19 Dec 2024 18:27:41 +0000 Subject: [PATCH 2/3] Bug in input data and rom data fixed --- state-machines/mem/src/input_data_sm.rs | 4 +--- state-machines/mem/src/rom_data.rs | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/state-machines/mem/src/input_data_sm.rs b/state-machines/mem/src/input_data_sm.rs index 2717e1e6..4b2b6183 100644 --- a/state-machines/mem/src/input_data_sm.rs +++ b/state-machines/mem/src/input_data_sm.rs @@ -36,7 +36,6 @@ pub struct InputDataSM { // STD std: Arc>, - num_rows: usize, // Count of registered predecessors registered_predecessors: AtomicU32, } @@ -49,7 +48,6 @@ impl InputDataSM { let input_data_sm = Self { wcm: wcm.clone(), std: std.clone(), - num_rows: air.num_rows(), registered_predecessors: AtomicU32::new(0), }; let input_data_sm = Arc::new(input_data_sm); @@ -377,7 +375,7 @@ impl MemModule for InputDataSM { vec![(INPUT_ADDR as u32, (INPUT_ADDR + MAX_INPUT_SIZE - 1) as u32)] } fn get_flush_input_size(&self) -> u32 { - self.num_rows as u32 + 0 } } diff --git a/state-machines/mem/src/rom_data.rs b/state-machines/mem/src/rom_data.rs index 57243430..8951eb1d 100644 --- a/state-machines/mem/src/rom_data.rs +++ b/state-machines/mem/src/rom_data.rs @@ -32,7 +32,6 @@ pub struct RomDataSM { // STD std: Arc>, - num_rows: usize, // Count of registered predecessors registered_predecessors: AtomicU32, } @@ -45,7 +44,6 @@ impl RomDataSM { let rom_data_sm = Self { wcm: wcm.clone(), std: std.clone(), - num_rows: air.num_rows(), registered_predecessors: AtomicU32::new(0), }; let rom_data_sm = Arc::new(rom_data_sm); @@ -332,7 +330,7 @@ impl MemModule for RomDataSM { vec![(ROM_ADDR as u32, ROM_ADDR_MAX as u32)] } fn get_flush_input_size(&self) -> u32 { - self.num_rows as u32 + 0 } } From cd4f409436c46f6ee3f5b4a7e8299dcee88a387b Mon Sep 17 00:00:00 2001 From: hecmas Date: Fri, 20 Dec 2024 08:00:32 +0000 Subject: [PATCH 3/3] cargo fmt --- state-machines/mem/src/input_data_sm.rs | 7 ++----- state-machines/mem/src/rom_data.rs | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/state-machines/mem/src/input_data_sm.rs b/state-machines/mem/src/input_data_sm.rs index 4b2b6183..ae75b82a 100644 --- a/state-machines/mem/src/input_data_sm.rs +++ b/state-machines/mem/src/input_data_sm.rs @@ -45,11 +45,8 @@ impl InputDataSM { pub fn new(wcm: Arc>, std: Arc>) -> Arc { let pctx = wcm.get_pctx(); let air = pctx.pilout.get_air(ZISK_AIRGROUP_ID, INPUT_DATA_AIR_IDS[0]); - let input_data_sm = Self { - wcm: wcm.clone(), - std: std.clone(), - registered_predecessors: AtomicU32::new(0), - }; + let input_data_sm = + Self { wcm: wcm.clone(), std: std.clone(), registered_predecessors: AtomicU32::new(0) }; let input_data_sm = Arc::new(input_data_sm); wcm.register_component( diff --git a/state-machines/mem/src/rom_data.rs b/state-machines/mem/src/rom_data.rs index 8951eb1d..bac99dfb 100644 --- a/state-machines/mem/src/rom_data.rs +++ b/state-machines/mem/src/rom_data.rs @@ -41,11 +41,8 @@ impl RomDataSM { pub fn new(wcm: Arc>, std: Arc>) -> Arc { let pctx = wcm.get_pctx(); let air = pctx.pilout.get_air(ZISK_AIRGROUP_ID, ROM_DATA_AIR_IDS[0]); - let rom_data_sm = Self { - wcm: wcm.clone(), - std: std.clone(), - registered_predecessors: AtomicU32::new(0), - }; + let rom_data_sm = + Self { wcm: wcm.clone(), std: std.clone(), registered_predecessors: AtomicU32::new(0) }; let rom_data_sm = Arc::new(rom_data_sm); wcm.register_component(rom_data_sm.clone(), Some(ZISK_AIRGROUP_ID), Some(ROM_DATA_AIR_IDS));