-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e645eef
commit 5aa4498
Showing
5 changed files
with
1,293 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,153 @@ | ||
# Integration tests for the CLI | ||
# tests against | ||
# 1. https://github.com/zksecurity/stark-evm-adapter.git | ||
# 2. https://github.com/HerodotusDev/integrity.git | ||
# 3. https://github.com/zksecurity/integrity-calldata-generator.git -> forked because the CLI implementation also relies on the fork | ||
|
||
#!/bin/bash | ||
set -e | ||
|
||
# Set main directory | ||
MAIN_DIR=$(pwd) | ||
|
||
# Install stone-cli | ||
cargo install --path . | ||
|
||
# Create and verify bootloader proof on Ethereum | ||
echo "Creating and verifying bootloader proof on Ethereum" | ||
|
||
stone-cli prove-bootloader \ | ||
--cairo_programs examples/cairo0/array_sum.json \ | ||
--parameter_file ./tests/configs/bootloader_cpu_air_params.json \ | ||
--output bootloader_proof.json | ||
echo "Proof generated" | ||
|
||
stone-cli verify \ | ||
--proof bootloader_proof.json \ | ||
--annotation_file annotation.json \ | ||
--extra_output_file extra_output.json \ | ||
--stone_version v5 | ||
echo "Proof verified" | ||
|
||
stone-cli serialize-proof \ | ||
--proof bootloader_proof.json \ | ||
--annotation_file annotation.json \ | ||
--extra_output_file extra_output.json \ | ||
--network ethereum \ | ||
--output bootloader_serialized_proof.json | ||
echo "Proof serialized" | ||
|
||
git clone https://github.com/zksecurity/stark-evm-adapter.git | ||
cd $MAIN_DIR/stark-evm-adapter/ | ||
URL=https://rpc.tenderly.co/fork/f4839248-30b4-4451-b1da-93ebb124c73f \ | ||
ANNOTATED_PROOF=../bootloader_serialized_proof.json \ | ||
FACT_TOPOLOGIES=../fact_topologies.json \ | ||
cargo run --example verify_stone_proof | ||
echo "Proof verified on Ethereum" | ||
|
||
# Create and verify proof on Starknet | ||
echo "Creating and verifying proof on Starknet" | ||
cd $MAIN_DIR | ||
stone-cli prove \ | ||
--cairo_program tests/resources/integrity-programs/cairo0_fibonacci_recursive_builtins.json \ | ||
--cairo_version cairo0 \ | ||
--layout recursive \ | ||
--output cairo0_fibonacci_recursive_builtins_stone5_keccak_160_lsb.json \ | ||
--stone_version v5 | ||
echo "Proof generated" | ||
|
||
# Serialize proof | ||
stone-cli serialize-proof \ | ||
--proof cairo0_fibonacci_recursive_builtins_stone5_keccak_160_lsb.json \ | ||
--network starknet \ | ||
--serialization_type monolith \ | ||
--output cairo0_fibonacci_recursive_builtins_stone5_keccak_160_lsb | ||
echo "Monolith proof serialized" | ||
|
||
# Clone integrity repo | ||
if [ ! -d "integrity" ]; then | ||
git clone https://github.com/HerodotusDev/integrity.git | ||
fi | ||
cd $MAIN_DIR/integrity/ | ||
echo "Integrity repo cloned" | ||
|
||
# Install sncast if it doesn't exist | ||
if ! command -v sncast &> /dev/null; then | ||
echo "sncast not found, installing snfoundryup..." | ||
curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh | ||
export PATH="/root/.local/bin:$PATH" | ||
source $HOME/.bashrc | ||
snfoundryup | ||
sncast --version | ||
echo "sncast installed" | ||
fi | ||
|
||
# Create starknet accounts directory and file if they don't exist | ||
mkdir -p ~/.starknet_accounts | ||
|
||
# Write account config to file (monolith proof uses `my-sepolia-account` and split proof uses `my_account`) | ||
cat > ~/.starknet_accounts/starknet_open_zeppelin_accounts.json << 'EOL' | ||
{ | ||
"alpha-sepolia": { | ||
"my-sepolia-account": { | ||
"address": "0x5044ea2b88229bb5a1ff5424ee746ed1a12541b9a1ec14e767d02c67ddb1fc1", | ||
"class_hash": "0xe2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6", | ||
"deployed": true, | ||
"legacy": false, | ||
"private_key": "0x713504d58868bbbf4b6447842b2e797f1a344a364a5298b07e3b9e93eab06dc", | ||
"public_key": "0x144a636155881974dcc21193786db7d879c6edf4646a17d6a5559034ef7a802", | ||
"salt": "0xd1531c0bb45f4634", | ||
"type": "open_zeppelin" | ||
}, | ||
"my_account": { | ||
"address": "0x5dd7aa049cfd03cc0d95ec6d562dda8321f8681e4a9635c57aefa738c8a3661", | ||
"class_hash": "0xe2eb8f5672af4e6a4e8a8f1b44989685e668489b0a25437733756c5a34a1d6", | ||
"deployed": true, | ||
"legacy": false, | ||
"private_key": "0x5908f00352439ab34724e7d50681fe2303c03ac52d0c2f02e2ac254e05bcd8a", | ||
"public_key": "0x7aa593b1fd343fc8079feee02cd253a10b6efeca294b689d94c474a3a6907b9", | ||
"salt": "0x479a8932e6bc52ad", | ||
"type": "open_zeppelin" | ||
} | ||
} | ||
} | ||
EOL | ||
echo "Starknet accounts file created" | ||
|
||
./verify-on-starknet.sh \ | ||
0x16409cfef9b6c3e6002133b61c59d09484594b37b8e4daef7dcba5495a0ef1a \ | ||
../cairo0_fibonacci_recursive_builtins_stone5_keccak_160_lsb \ | ||
recursive \ | ||
keccak_160_lsb \ | ||
stone5 \ | ||
cairo0 | ||
echo "Monolith proof verified on Starknet" | ||
|
||
cd $MAIN_DIR | ||
stone-cli serialize-proof \ | ||
--proof cairo0_fibonacci_recursive_builtins_stone5_keccak_160_lsb.json \ | ||
--network starknet \ | ||
--serialization_type split \ | ||
--output_dir split_proofs \ | ||
--layout recursive | ||
echo "Split proof serialized" | ||
|
||
# Verify split proofs using the integrity-calldata-generator repo | ||
cd $MAIN_DIR | ||
if [ ! -d "integrity-calldata-generator" ]; then | ||
GIT_LFS_SKIP_SMUDGE=1 git clone https://github.com/zksecurity/integrity-calldata-generator | ||
fi | ||
echo "integrity-calldata-generator repo cloned" | ||
|
||
# Copy split proofs to integrity-calldata-generator | ||
cp -r $MAIN_DIR/split_proofs/* $MAIN_DIR/integrity-calldata-generator/cli/calldata/ | ||
|
||
# Generate random job id | ||
JOB_ID=$(shuf -i 1-10000000000000 -n 1) | ||
echo "Generated random job id: $JOB_ID" | ||
|
||
# Run verify.sh | ||
cd $MAIN_DIR/integrity-calldata-generator/cli | ||
./verify.sh $JOB_ID recursive keccak_160_lsb stone5 cairo0 | ||
|
||
# CLI Integration Tests | ||
# (might take a while) | ||
echo "Split proof verified on Starknet" |
43 changes: 43 additions & 0 deletions
43
tests/resources/integrity-programs/cairo0_fibonacci_recursive_builtins.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2023 StarkWare Industries Ltd. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"). | ||
// You may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.starkware.co/open-source-license/ | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions | ||
// and limitations under the License. | ||
|
||
%builtins output pedersen range_check bitwise | ||
func main( | ||
output_ptr: felt*, pedersen_ptr: felt*, range_check_ptr: felt*, bitwise_ptr: felt*) -> ( | ||
output_ptr: felt*, pedersen_ptr: felt*, range_check_ptr: felt*, bitwise_ptr: felt* | ||
) { | ||
alloc_locals; | ||
// Copy fibonacci_claim_index to the output segment. | ||
local fibonacci_claim_index = 10000; | ||
assert output_ptr[0] = fibonacci_claim_index; | ||
let res = fib(1, 1, fibonacci_claim_index); | ||
assert output_ptr[1] = res; | ||
// Return the updated output_ptr. | ||
return ( | ||
output_ptr=&output_ptr[2], pedersen_ptr=pedersen_ptr, range_check_ptr=range_check_ptr, bitwise_ptr=bitwise_ptr | ||
); | ||
} | ||
|
||
func fib(first_element: felt, second_element: felt, n: felt) -> felt { | ||
if (n == 0) { | ||
return second_element; | ||
} | ||
|
||
return fib( | ||
first_element=second_element, second_element=first_element + second_element, n=n - 1 | ||
); | ||
} |
Oops, something went wrong.