diff --git a/README.md b/README.md index c833cabaf..f58feb61a 100644 --- a/README.md +++ b/README.md @@ -30,10 +30,23 @@ For local proof verification, follow these steps: 1. Run the verifier locally on example proof using the following command: +By `default`, the verifier is configured for `layout_type`=`recursive` and `hash_type`=`keccak` for verifier unfriendly commitment layers. ```bash +scarb build && cargo run --release --bin runner -- target/dev/cairo_verifier.sierra.json < examples/proofs/recursive/example_proof.json ``` +You can easily change configuration by specifying features in scarb build command + +```bash +scarb build --no-default-features --features=, +``` + +`layout_type`: [`dex`, `recursive`, `recursive_with_poseidon`, `small`, `starknet`, `starknet_with_keccak`] +`hash_type`: [`keccak`, `blake2s`] + +All the example_proof's are using `hash_type`=`keccak` + ### Starknet Proof Verification To verify proofs on Starknet, proceed with the following steps: @@ -41,29 +54,18 @@ To verify proofs on Starknet, proceed with the following steps: 1. Prepare calldata of example proof for sncast: ```bash -cargo run --release --bin snfoundry_proof_serializer < examples/proofs/recursive/example_proof.json > examples/starknet/calldata +cargo run --release --bin snfoundry_proof_serializer < examples/proofs//example_proof.json > examples/starknet/calldata ``` 2. Call the function with calldata on the Starknet contract: ```bash cd examples/starknet -./1-verify-proof.sh 0x487810706cc0dfdba0c82403d98e9d32dc36793ed2b731231e5ea19f00c5861 calldata +./1-verify-proof.sh calldata ``` [List of deployed Verifier Contracts](deployed_contracts.md) -## Configure Verifier - -By default, the verifier is configured for recursive layout and keccak hash for verifier unfriendly commitment layers. You can easily change that by using the configure python script (this script is in Experimental stage): - -```bash -python configure.py -l recursive -s keccak -``` - -layout types: [dex, recursive, recursive_with_poseidon, small, starknet, starknet_with_keccak] -hash types: [keccak, blake2s] - ## Creating a Proof To create a proof, perform the following steps: diff --git a/configure.py b/configure.py deleted file mode 100644 index 95a4da6b6..000000000 --- a/configure.py +++ /dev/null @@ -1,50 +0,0 @@ -import argparse -import sys -import inquirer -from pathlib import Path -from utils import process_file - -LAYOUT_TYPES = ("dex", "recursive", "recursive_with_poseidon", "small", "starknet", "starknet_with_keccak") -HASH_TYPES = ("keccak", "blake2s") - - -def select_types() -> str: - """Prompts the user to select a type.""" - questions = [ - inquirer.List("layout_type", message="Select layout", choices=LAYOUT_TYPES), - inquirer.List("hash_type", message="Select hash", choices=HASH_TYPES), - ] - answers = inquirer.prompt(questions) - return (answers["layout_type"], answers["hash_type"]) - - -def main(layout_type=None, hash_type=None): - """Main function for processing files.""" - if layout_type is None or hash_type is None: - layout_type, hash_type = select_types() - - if layout_type.lower() not in LAYOUT_TYPES: - print(f"Invalid layout type: {layout_type}") - sys.exit(1) - - if hash_type.lower() not in HASH_TYPES: - print(f"Invalid hash type: {hash_type}") - sys.exit(1) - - current_directory = Path("src") - for file_path in current_directory.rglob("*.cairo"): - if file_path.is_file(): - process_file(file_path, [layout_type.upper(), hash_type.upper()]) - - -if __name__ == "__main__": - parser = argparse.ArgumentParser(description="Process files based on block type.") - parser.add_argument( - "-l", "--layout_type", type=str, help=f"Type of layouts {LAYOUT_TYPES}" - ) - parser.add_argument( - "-s", "--hash_type", type=str, help=f"Type of hashes {HASH_TYPES}" - ) - args = parser.parse_args() - - main(args.layout_type, args.hash_type) diff --git a/test_layouts.py b/test_layouts.py deleted file mode 100644 index dcf520372..000000000 --- a/test_layouts.py +++ /dev/null @@ -1,68 +0,0 @@ -import subprocess -import argparse -from colorama import Fore, Style - - -# Function to execute commands and log the process -def log_and_run(commands, description, cwd=None): - full_command = " && ".join(commands) - - try: - print(f"{Fore.YELLOW}Starting: {description}...{Style.RESET_ALL}") - print(f"{Fore.CYAN}Command: {full_command}{Style.RESET_ALL}") - - # Execute the command - result = subprocess.run( - full_command, shell=True, check=True, cwd=cwd, text=True - ) - - print(f"{Fore.GREEN}Success: {description} completed!\n{Style.RESET_ALL}") - except subprocess.CalledProcessError as e: - print( - f"{Fore.RED}Error running command '{full_command}': {e}\n{Style.RESET_ALL}" - ) - - -# List of layouts to test -LAYOUTS = ["dex", "recursive", "recursive_with_poseidon", "small", "starknet", "starknet_with_keccak"] - - -# Main function to run the tests and optionally restore the src folder -def main(restore_src=None): - for layout in LAYOUTS: - log_and_run( - [ - f"python configure.py -l {layout} -s keccak", - "scarb build", - f"cargo run --release --bin runner -- target/dev/cairo_verifier.sierra.json < examples/proofs/{layout}/example_proof.json", - ], - f"Testing {layout.lower()} layout", - cwd=".", - ) - - # Check if src folder restoration is required - if restore_src is None: - response = input("Do you want to restore the src folder? (y/n): ") - restore_src = response.lower() == "y" - - # Restore the src folder if requested - if restore_src: - log_and_run(["git restore src/"], "Restoring src folder", cwd=".") - - -# Entry point of the script -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description="Test cairo1-verifier layouts on example proofs" - ) - - # Define command-line arguments - parser.add_argument( - "-r", "--restore-src", action="store_true", help="Restore src folder after run" - ) - - # Parse the arguments - args = parser.parse_args() - - # Run main function with the specified arguments - main(args.restore_src) diff --git a/utils.py b/utils.py deleted file mode 100644 index 894895c10..000000000 --- a/utils.py +++ /dev/null @@ -1,64 +0,0 @@ -import re - - -def process_block(lines: list[str], types: list[str]): - """Processes a block of lines based on the given types.""" - in_block = False - modified_lines = [] - - for line in lines: - begin_match = re.match(r"^(\s*)// === ([A-Z_0-9]+) BEGIN ===", line) - end_match = re.match(r"^(\s*)// === ([A-Z_0-9]+) END ===", line) - - if begin_match: - in_block = True - indent = begin_match.group(1) - current_block_type = begin_match.group(2) - modified_lines.append(line) - continue - elif end_match: - in_block = False - modified_lines.append(line) - continue - - if in_block and line.strip() != "": - if current_block_type in types: - # Remove comment if exists - if line.lstrip().startswith("// "): - modified_lines.append(indent + line.lstrip()[3:]) - else: - modified_lines.append(line) - else: - # Add comment if does not exist - if not line.lstrip().startswith("// "): - line_indent = len(line) - len(line.lstrip()) - subtracted_indent = min(len(indent), line_indent) - modified_lines.append(indent + "// " + line[subtracted_indent:]) - else: - modified_lines.append(line) - else: - modified_lines.append(line) - - return modified_lines - - -def read_file(file_path: str) -> list[str]: - """Reads a file and returns its content as a list of lines.""" - try: - with open(file_path, "r", encoding="utf-8") as file: - return file.readlines() - except UnicodeDecodeError: - print(f"Skipping file due to encoding issue: {file_path}") - return [] - - -def process_file(file_path, types: list[str]) -> None: - """Processes a file based on the given types.""" - lines = read_file(file_path) - if not lines: - return - - modified_lines = process_block(lines, types) - - with open(file_path, "w", encoding="utf-8") as file: - file.writelines(modified_lines)