Skip to content

Commit

Permalink
Feature/verify all bangkok (#168)
Browse files Browse the repository at this point in the history
* Make rom trace generation based on ordered keys

* Improver verify_all script

---------

Co-authored-by: zkronos73 <[email protected]>
  • Loading branch information
fractasy and zkronos73 authored Nov 20, 2024
1 parent 46efd80 commit 03d8f53
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 11 deletions.
3 changes: 2 additions & 1 deletion state-machines/rom/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ proofman = { workspace = true }

log = { workspace = true }
rayon = { workspace = true }
itertools = "0.13.0"

[features]
default = []
no_lib_link = ["proofman-common/no_lib_link", "proofman/no_lib_link"]
no_lib_link = ["proofman-common/no_lib_link", "proofman/no_lib_link"]
10 changes: 8 additions & 2 deletions state-machines/rom/src/rom.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{path::PathBuf, sync::Arc};

use itertools::Itertools;
use p3_field::Field;
use proofman::{WitnessComponent, WitnessManager};
use proofman_common::{AirInstance, BufferAllocator, SetupCtx};
Expand Down Expand Up @@ -164,9 +165,13 @@ impl<F: Field> RomSM<F> {
.expect("RomSM::compute_trace() failed mapping buffer to ROMSRow");

// For every instruction in the rom, fill its corresponding ROM trace
for (i, inst_builder) in rom.insts.clone().into_iter().enumerate() {
//for (i, inst_builder) in rom.insts.clone().into_iter().enumerate() {
let keys = rom.insts.keys();
let sorted_keys = keys.sorted();
let mut i = 0;
for key in sorted_keys {
// Get the Zisk instruction
let inst = inst_builder.1.i;
let inst = &rom.insts[key].i;

// Calculate the multiplicity, i.e. the number of times this pc is used in this
// execution
Expand Down Expand Up @@ -246,6 +251,7 @@ impl<F: Field> RomSM<F> {
inst.get_flags(),
multiplicity,
);*/
i += 1;
}

// Padd with zeroes
Expand Down
72 changes: 64 additions & 8 deletions tools/verify_all.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,87 @@
#!/bin/bash -x
#!/bin/bash

echo "Verify all ELF files found in a directory"

if [ "$#" -ne 1 ]; then
echo "Usage: $0 <dirname>"
# Check that at least one argument has been passed
if [ "$#" -lt 1 ]; then
echo "Usage: $0 <dirname> [-l/--list -b/--begin <first_file> -e/--end <last_file>]"
exit 1
fi

# Get the first argument as the directory path
if [[ "$1" != "" ]]; then
DIR="$1"
else
DIR=.
fi

shift
echo "Verifying ELF files found in directory ${DIR}"

ELF_FILES=`find $DIR -name my.elf`
# Parse optional arguments
LIST=0
BEGIN=0
END=0
while [[ "$#" -gt 0 ]]; do
case $1 in
-l|--list) LIST=1 ;;
-b|--begin) BEGIN=$2; shift; ;;
-e|--end) END=$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 "Beginning at file ${END}";
fi

# If just listing, exit
if [ $LIST -eq 1 ]; then
echo "Exiting after listing files";
exit 0;
fi

# Record the number of files
MAX_COUNTER=${COUNTER}

# Create and empty input file
INPUT_FILE="/tmp/empty_input.bin"
touch $INPUT_FILE

# For all files
COUNTER=0

for ELF_FILE in $ELF_FILES
do
# Increase file counter
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

# Varify the contraints for this file
echo ""
echo "Verifying file ${COUNTER}: ${ELF_FILE}"
echo "Verifying file ${COUNTER} of ${MAX_COUNTER}: ${ELF_FILE}"
(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)
COUNTER=$((COUNTER+1))
done

0 comments on commit 03d8f53

Please sign in to comment.