Skip to content

Commit

Permalink
Merge pull request #24 from zksecurity/dev-ci
Browse files Browse the repository at this point in the history
Add integration tests
  • Loading branch information
mellowcroc authored Nov 7, 2024
2 parents 00e2eef + 50b9a25 commit e477995
Show file tree
Hide file tree
Showing 20 changed files with 19,938 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

- name: Increase stack size
run: |
echo "Setting stack size to 4MB"
echo "Setting stack size to 8MB"
echo "RUST_MIN_STACK=4194304" >> $GITHUB_ENV
- name: Run cargo test
Expand Down
54 changes: 52 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,59 @@ on:
push:
branches:
- main
- dev-ci

pull_request:
branches:
- main
- dev-ci

jobs:
build-and-test-macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
components: rustfmt, clippy

- name: Cache cargo
id: cache-cargo
uses: actions/cache@v4
with:
path: ~/.cargo
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- if: steps.cache-cargo.outputs.cache-hit == 'true'
run: echo "cargo cache hit"

- if: steps.cache-cargo.outputs.cache-hit == 'false'
run: echo "cargo cache miss"

- name: Increase stack size
run: |
echo "Setting stack size to 8MB"
echo "RUST_MIN_STACK=8388608" >> $GITHUB_ENV
- name: Run cargo test
run: cargo test --all-features

- name: Run cargo build
run: cargo build --all

- name: Run cargo fmt
run: cargo fmt --all -- --check

- name: Run cargo clippy
run: cargo clippy --all -- -D warnings

- name: Build release
run: cargo build --release

- name: CLI Integration tests
run: ./tests/cli/tests.sh

build-and-test-linux:
runs-on: ubuntu-latest
steps:
Expand All @@ -31,8 +78,8 @@ jobs:

- name: Increase stack size
run: |
echo "Setting stack size to 4MB"
echo "RUST_MIN_STACK=4194304" >> $GITHUB_ENV
echo "Setting stack size to 8MB"
echo "RUST_MIN_STACK=8388608" >> $GITHUB_ENV
- name: Run cargo test
run: cargo test --all-features
Expand All @@ -48,3 +95,6 @@ jobs:

- name: Build release
run: cargo build --release

- name: CLI Integration tests
run: ./tests/cli/tests.sh
67 changes: 46 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ swiftness_air = { git = "https://github.com/zksecurity/integrity-calldata-genera
swiftness_fri = { git = "https://github.com/zksecurity/integrity-calldata-generator" }
swiftness_proof_parser = { git = "https://github.com/zksecurity/integrity-calldata-generator" }
swiftness_stark = { git = "https://github.com/zksecurity/integrity-calldata-generator" }
swiftness = { git = "https://github.com/zksecurity/integrity-calldata-generator" }
starknet-crypto = "0.7.2"
tempfile = "3.10.1"
tempfile = "3.10.1"
thiserror = "1.0.61"
uuid = "1.9.1"

Expand Down
9 changes: 8 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,14 @@ fn download_executables(config: &Config, tmp_dir_path: &Path) {
let tmp_download_dir = tmp_dir_path.join("executables");
std::fs::create_dir_all(&tmp_download_dir).expect("Failed to create tmp_download_dir");

let dist = &DISTS[&(OS.try_into().unwrap(), ARCH.try_into().unwrap())];
// look up the stone-prover distribution for the current OS and architecture
let os = OS.try_into().unwrap();
let arch = ARCH.try_into().unwrap();
let dist = match DISTS.get(&(os, arch)) {
Some(dist) => dist,
None => panic!("Unsupported OS or architecture {}/{}", OS, ARCH),
};

let cairo1_run_url = &dist[0].url;
let cairo1_run_sha256_sum = &dist[0].sha256_sum;
let cairo1_run_zip_file_name = Path::new(cairo1_run_url)
Expand Down
2 changes: 1 addition & 1 deletion src/cairo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub struct CairoRunResult {
pub enum Error {
#[error("Failed to interact with the file system")]
IO(#[from] std::io::Error),
#[error("The cairo program execution failed")]
#[error(transparent)]
Runner(#[from] CairoRunError),
#[error(transparent)]
EncodeTrace(#[from] EncodeTraceError),
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn main() -> anyhow::Result<()> {
match cli {
Cli::Prove(args) => {
let result = run_cairo(&args, &tmp_dir)
.map_err(|e| anyhow::anyhow!("Failed to run cairo1: {}", e))
.map_err(|e| anyhow::anyhow!("Failed to run cairo: {}", e))
.and_then(|run_cairo_result| {
run_stone_prover(
&args,
Expand Down
19 changes: 9 additions & 10 deletions src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ use std::fs::write;
use std::io::BufRead;
use std::path::Path;
use std::path::PathBuf;
use swiftness::transform::{Expr, StarkProofExprs};
use swiftness::transform_stark::TransformTo;
use swiftness_air::layout::*;
use swiftness_fri::{CONST_STATE, VAR_STATE, WITNESS};
use swiftness_proof_parser::{parse, parse_as_exprs, Expr, ParseStarkProof};
use swiftness_proof_parser::parse;
use swiftness_stark::stark;
use thiserror::Error;
use vec252::VecFelt252;
Expand Down Expand Up @@ -70,7 +72,7 @@ pub fn serialize_proof(args: SerializeArgs) -> Result<(), Error> {
Some(SerializationType::monolith) => {
let output = args.output.clone().unwrap();
let input = std::fs::read_to_string(proof_file.clone())?;
let stark_proof: ParseStarkProof = parse_as_exprs(input)?;
let stark_proof: StarkProofExprs = parse(input)?.into();
let config: VecFelt252 =
serde_json::from_str(&stark_proof.config.to_string()).unwrap();
let public_input: VecFelt252 =
Expand Down Expand Up @@ -99,7 +101,7 @@ pub fn serialize_proof(args: SerializeArgs) -> Result<(), Error> {
let output_dir = args.output_dir.clone().unwrap();
let layout = args.layout.unwrap();
let input = std::fs::read_to_string(proof_file.clone())?;
let stark_proof = parse(input.clone())?;
let stark_proof = parse(input.clone())?.transform_to();
let security_bits = stark_proof.config.security_bits();

match layout {
Expand Down Expand Up @@ -132,8 +134,7 @@ pub fn serialize_proof(args: SerializeArgs) -> Result<(), Error> {

let (const_state, mut var_state, mut witness) =
unsafe { (CONST_STATE.clone(), VAR_STATE.clone(), WITNESS.clone()) };
let cairo_version = Felt252::from(0);
let initial = serialize(input, cairo_version)?
let initial = serialize(input)?
.split_whitespace()
.map(|s| Felt::from_dec_str(s).unwrap().to_hex_string())
.join(" ");
Expand Down Expand Up @@ -163,8 +164,8 @@ pub fn serialize_proof(args: SerializeArgs) -> Result<(), Error> {
Ok(())
}

fn serialize(input: String, cairo_version: Felt252) -> Result<String, Error> {
let mut parsed = parse_as_exprs(input)?;
fn serialize(input: String) -> Result<String, Error> {
let mut parsed: StarkProofExprs = parse(input)?.into();

let config: VecFelt252 = serde_json::from_str(&parsed.config.to_string()).unwrap();
let public_input: VecFelt252 = serde_json::from_str(&parsed.public_input.to_string()).unwrap();
Expand Down Expand Up @@ -200,15 +201,13 @@ fn serialize(input: String, cairo_version: Felt252) -> Result<String, Error> {
parsed.witness.0.push(Expr::Array(vec![]));
let witness: VecFelt252 = serde_json::from_str(&parsed.witness.to_string()).unwrap();

let proof = chain!(
let calldata = chain!(
config.into_iter(),
public_input.into_iter(),
unsent_commitment.into_iter(),
witness.into_iter()
);

let calldata = chain!(proof, vec![cairo_version].into_iter());

let calldata_string = calldata
.map(|f| f.to_string())
.collect::<Vec<String>>()
Expand Down
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
);
}
Loading

0 comments on commit e477995

Please sign in to comment.