Skip to content

Commit

Permalink
Adopt stark tests for keccak
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Feb 10, 2024
1 parent f159f01 commit 984d7f3
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 22 deletions.
51 changes: 42 additions & 9 deletions src/stark/tests/test_stark_commit.cairo
Original file line number Diff line number Diff line change
@@ -1,34 +1,67 @@
use cairo_verifier::{
stark::stark_commit::stark_commit, channel::channel::ChannelTrait, tests::stone_proof_fibonacci,
stark::stark_commit::stark_commit, channel::channel::ChannelTrait, tests::{stone_proof_fibonacci,stone_proof_fibonacci_keccak}
};

// test data from cairo0-verifier run on stone-prover generated proof
// === BLAKE ONLY BEGIN ===
// #[test]
// #[available_gas(9999999999)]
// fn test_stark_commit() {
// let mut channel = ChannelTrait::new_with_counter(
// u256 { low: 0xba9d17a3ebd900899148b125421c118f, high: 0x87433b8dd90acbfe5abea8474d795191 },
// 0x0
// );

// let public_input = stone_proof_fibonacci::public_input::get();
// let unsent_commitment = stone_proof_fibonacci::stark::unsent_commitment::get();
// let config = stone_proof_fibonacci::stark::config::get();
// let stark_domains = stone_proof_fibonacci::stark::domains::get();

// assert(
// stark_commit(
// ref channel, @public_input, @unsent_commitment, @config, @stark_domains
// ) == stone_proof_fibonacci::stark::commitment::get(),
// 'Invalid value'
// );

// assert(
// channel
// .digest == u256 {
// low: 0x2c31f04a6b9c83c2464b2f1688fc719e, high: 0xe631d91ef56f7e4cc7fe09cff2cc4e94
// },
// 'Invalid value'
// );
// assert(channel.counter == 0, 'Invalid value');
// }
// === BLAKE ONLY END ===

// === KECCAK ONLY BEGIN ===
#[test]
#[available_gas(9999999999)]
fn test_stark_commit() {
let mut channel = ChannelTrait::new_with_counter(
u256 { low: 0xba9d17a3ebd900899148b125421c118f, high: 0x87433b8dd90acbfe5abea8474d795191 },
u256 { low: 0x22b3f4d7841a28271009bef644a84a5e, high: 0x8f17c0c0dcde2144cd36213ab3aaff1b },
0x0
);

let public_input = stone_proof_fibonacci::public_input::get();
let unsent_commitment = stone_proof_fibonacci::stark::unsent_commitment::get();
let config = stone_proof_fibonacci::stark::config::get();
let stark_domains = stone_proof_fibonacci::stark::domains::get();
let public_input = stone_proof_fibonacci_keccak::public_input::get();
let unsent_commitment = stone_proof_fibonacci_keccak::stark::unsent_commitment::get();
let config = stone_proof_fibonacci_keccak::stark::config::get();
let stark_domains = stone_proof_fibonacci_keccak::stark::domains::get();

assert(
stark_commit(
ref channel, @public_input, @unsent_commitment, @config, @stark_domains
) == stone_proof_fibonacci::stark::commitment::get(),
) == stone_proof_fibonacci_keccak::stark::commitment::get(),
'Invalid value'
);

assert(
channel
.digest == u256 {
low: 0x2c31f04a6b9c83c2464b2f1688fc719e, high: 0xe631d91ef56f7e4cc7fe09cff2cc4e94
low: 0x210c99e614db21dcd882b7f3734a477b, high: 0x29786ad320869955ebf8c196e16009e1
},
'Invalid value'
);
assert(channel.counter == 0, 'Invalid value');
}
// === KECCAK ONLY END ===
30 changes: 23 additions & 7 deletions src/stark/tests/test_stark_proof_verify.cairo
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
use cairo_verifier::{stark::{StarkProof, StarkProofTrait}, tests::stone_proof_fibonacci,};
use cairo_verifier::{stark::{StarkProof, StarkProofTrait}, tests::{stone_proof_fibonacci,stone_proof_fibonacci_keccak}};

// test data from cairo0-verifier run on stone-prover generated proof
// === BLAKE ONLY BEGIN ===
// #[test]
// #[available_gas(99999999999)]
// fn test_stark_proof_fibonacci_verify() {
// let stark_proof = StarkProof {
// config: stone_proof_fibonacci::stark::config::get(),
// public_input: stone_proof_fibonacci::public_input::get(),
// unsent_commitment: stone_proof_fibonacci::stark::unsent_commitment::get(),
// witness: stone_proof_fibonacci::stark::witness::get(),
// };

// stark_proof.verify();
// }
// === BLAKE ONLY END ===

// === KECCAK ONLY BEGIN ===
#[test]
#[available_gas(99999999999)]
#[available_gas(9999999999)]
fn test_stark_proof_fibonacci_verify() {
let stark_proof = StarkProof {
config: stone_proof_fibonacci::stark::config::get(),
public_input: stone_proof_fibonacci::public_input::get(),
unsent_commitment: stone_proof_fibonacci::stark::unsent_commitment::get(),
witness: stone_proof_fibonacci::stark::witness::get(),
config: stone_proof_fibonacci_keccak::stark::config::get(),
public_input: stone_proof_fibonacci_keccak::public_input::get(),
unsent_commitment: stone_proof_fibonacci_keccak::stark::unsent_commitment::get(),
witness: stone_proof_fibonacci_keccak::stark::witness::get(),
};

stark_proof.verify();
}
// === KECCAK ONLY END ===
28 changes: 22 additions & 6 deletions src/stark/tests/test_stark_verify.cairo
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
use cairo_verifier::{
stark::stark_verify::stark_verify, air::constants::{NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND},
tests::stone_proof_fibonacci,
tests::{stone_proof_fibonacci,stone_proof_fibonacci_keccak}
};

// test data from cairo0-verifier run on stone-prover generated proof
// === BLAKE ONLY BEGIN ===
// #[test]
// #[available_gas(9999999999)]
// fn test_stark_verify() {
// let queries = stone_proof_fibonacci::queries::get().span();
// let commitment = stone_proof_fibonacci::stark::commitment::get();
// let witness = stone_proof_fibonacci::stark::witness::get();
// let stark_domains = stone_proof_fibonacci::stark::domains::get();

// stark_verify(
// NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND, queries, commitment, witness, stark_domains,
// )
// }
// === BLAKE ONLY END ===

// === KECCAK ONLY BEGIN ===
#[test]
#[available_gas(9999999999)]
fn test_stark_verify() {
let queries = stone_proof_fibonacci::queries::get().span();
let commitment = stone_proof_fibonacci::stark::commitment::get();
let witness = stone_proof_fibonacci::stark::witness::get();
let stark_domains = stone_proof_fibonacci::stark::domains::get();
let queries = stone_proof_fibonacci_keccak::queries::get().span();
let commitment = stone_proof_fibonacci_keccak::stark::commitment::get();
let witness = stone_proof_fibonacci_keccak::stark::witness::get();
let stark_domains = stone_proof_fibonacci_keccak::stark::domains::get();

stark_verify(
NUM_COLUMNS_FIRST, NUM_COLUMNS_SECOND, queries, commitment, witness, stark_domains,
)
}
// === KECCAK ONLY END ===

0 comments on commit 984d7f3

Please sign in to comment.