Skip to content

Commit

Permalink
Replace comments with features
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Mar 26, 2024
1 parent f5da118 commit 9fc1b46
Show file tree
Hide file tree
Showing 20 changed files with 468 additions and 485 deletions.
34 changes: 17 additions & 17 deletions src/air/layouts.cairo
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// === DEX BEGIN ===
// mod dex;
// === DEX END ===
// === RECURSIVE BEGIN ===
#[cfg(feature: 'dex')]
mod dex;

#[cfg(feature: 'recursive')]
mod recursive;
// === RECURSIVE END ===
// === RECURSIVE_WITH_POSEIDON BEGIN ===
// mod recursive_with_poseidon;
// === RECURSIVE_WITH_POSEIDON END ===
// === SMALL BEGIN ===
// mod small;
// === SMALL END ===
// === STARKNET BEGIN ===
// mod starknet;
// === STARKNET END ===
// === STARKNET_WITH_KECCAK BEGIN ===
// mod starknet_with_keccak;
// === STARKNET_WITH_KECCAK END ===

#[cfg(feature: 'recursive_with_poseidon')]
mod recursive_with_poseidon;

#[cfg(feature: 'small')]
mod small;

#[cfg(feature: 'starknet')]
mod starknet;

#[cfg(feature: 'starknet_with_keccak')]
mod starknet_with_keccak;



35 changes: 18 additions & 17 deletions src/common/hasher.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,39 @@ use cairo_verifier::common::{
flip_endianness::FlipEndiannessTrait
};

// === BLAKE2S BEGIN ===
// fn hash_n_bytes(mut data: Array<u8>, n: u8, hash_len: bool) -> u256 {
// if hash_len {
// data.append(n);
// }
// blake2s_u8(data)
// }
// fn hash_truncated(data: Array<u32>) -> felt252 {
// truncated_blake2s(data)
// }
// fn hash(data: Array<u32>) -> u256 {
// blake2s(data)
// }
// === BLAKE2S END ===
#[cfg(feature: 'blake2s')]
fn hash_n_bytes(mut data: Array<u8>, n: u8, hash_len: bool) -> u256 {
if hash_len {
data.append(n);
}
blake2s_u8(data)
}
#[cfg(feature: 'blake2s')]
fn hash_truncated(data: Array<u32>) -> felt252 {
truncated_blake2s(data)
}
#[cfg(feature: 'blake2s')]
fn hash(data: Array<u32>) -> u256 {
blake2s(data)
}

// === KECCAK BEGIN ===
#[cfg(feature: 'keccak')]
fn hash_n_bytes(mut data: Array<u64>, n: u8, hash_len: bool) -> u256 {
if hash_len {
keccak::cairo_keccak(ref data, n.into(), 1)
} else {
keccak::cairo_keccak(ref data, 0, 0)
}
}
#[cfg(feature: 'keccak')]
fn hash_truncated(mut data: Array<u64>) -> felt252 {
(keccak::cairo_keccak(ref data, 0, 0)
.flip_endianness() % 0x10000000000000000000000000000000000000000)
.try_into()
.unwrap()
}
#[cfg(feature: 'keccak')]
fn hash(mut data: Array<u64>) -> u256 {
keccak::cairo_keccak(ref data, 0, 0)
}
// === KECCAK END ===


37 changes: 19 additions & 18 deletions src/deserialization/stark.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,6 @@ use cairo_verifier::{
public_input::{ContinuousPageHeader, PublicInput, SegmentInfo},
public_memory::{AddrValue, Page},
},
// === DEX BEGIN ===
// air::layouts::dex::traces::TracesConfig,
// === DEX END ===
// === RECURSIVE BEGIN ===
air::layouts::recursive::traces::TracesConfig,
// === RECURSIVE END ===
// === RECURSIVE_WITH_POSEIDON BEGIN ===
// air::layouts::recursive_with_poseidon::traces::TracesConfig,
// === RECURSIVE_WITH_POSEIDON END ===
// === SMALL BEGIN ===
// air::layouts::small::traces::TracesConfig,
// === SMALL END ===
// === STARKNET BEGIN ===
// air::layouts::starknet::traces::TracesConfig,
// === STARKNET END ===
// === STARKNET_WITH_KECCAK BEGIN ===
// air::layouts::starknet_with_keccak::traces::TracesConfig,
// === STARKNET_WITH_KECCAK END ===
deserialization::{
traces::{
TracesConfigWithSerde, TracesDecommitmentWithSerde, TracesWitnessWithSerde,
Expand All @@ -33,6 +15,25 @@ use cairo_verifier::{
stark::{StarkProof, StarkConfig, StarkUnsentCommitment, StarkWitness},
};

#[cfg(feature: 'dex')]
use cairo_verifier::air::layouts::dex::traces::TracesConfig;

#[cfg(feature: 'recursive')]
use cairo_verifier::air::layouts::recursive::traces::TracesConfig;

#[cfg(feature: 'recursive_with_poseidon')]
use cairo_verifier::air::layouts::recursive_with_poseidon::traces::TracesConfig;

#[cfg(feature: 'small')]
use cairo_verifier::air::layouts::small::traces::TracesConfig;

#[cfg(feature: 'starknet')]
use cairo_verifier::air::layouts::starknet::traces::TracesConfig;

#[cfg(feature: 'starknet_with_keccak')]
use cairo_verifier::air::layouts::starknet_with_keccak::traces::TracesConfig;


#[derive(Drop, Serde)]
struct StarkProofWithSerde {
config: StarkConfigWithSerde,
Expand Down
60 changes: 30 additions & 30 deletions src/deserialization/traces.cairo
Original file line number Diff line number Diff line change
@@ -1,34 +1,4 @@
use cairo_verifier::{
// === DEX BEGIN ===
// air::layouts::dex::{
// traces::TracesConfig, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness}
// },
// === DEX END ===
// === RECURSIVE BEGIN ===
air::layouts::recursive::{
traces::TracesConfig, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness}
},
// === RECURSIVE END ===
// === RECURSIVE_WITH_POSEIDON BEGIN ===
// air::layouts::recursive_with_poseidon::{
// traces::TracesConfig, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness}
// },
// === RECURSIVE_WITH_POSEIDON END ===
// === SMALL BEGIN ===
// air::layouts::small::{
// traces::TracesConfig, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness}
// },
// === SMALL END ===
// === STARKNET BEGIN ===
// air::layouts::starknet::{
// traces::TracesConfig, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness}
// },
// === STARKNET END ===
// === STARKNET_WITH_KECCAK BEGIN ===
// air::layouts::starknet_with_keccak::{
// traces::TracesConfig, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness}
// },
// === STARKNET_WITH_KECCAK END ===
deserialization::{
vector::{
VectorCommitmentConfig, VectorCommitmentWitness, VectorCommitmentConfigWithSerde,
Expand All @@ -44,6 +14,36 @@ use cairo_verifier::{
},
};

#[cfg(feature: 'dex')]
use cairo_verifier::air::layouts::dex::{
traces::TracesConfig, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness}
};

#[cfg(feature: 'recursive')]
use cairo_verifier::air::layouts::recursive::{
traces::TracesConfig, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness}
};

#[cfg(feature: 'recursive_with_poseidon')]
use cairo_verifier::air::layouts::recursive_with_poseidon::{
traces::TracesConfig, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness}
};

#[cfg(feature: 'small')]
use cairo_verifier::air::layouts::small::{
traces::TracesConfig, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness}
};

#[cfg(feature: 'starknet')]
use cairo_verifier::air::layouts::starknet::{
traces::TracesConfig, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness}
};

#[cfg(feature: 'starknet_with_keccak')]
use cairo_verifier::air::layouts::starknet_with_keccak::{
traces::TracesConfig, traces::{TracesUnsentCommitment, TracesDecommitment, TracesWitness}
};

#[derive(Drop, Serde)]
struct TracesConfigWithSerde {
original: TableCommitmentConfigWithSerde,
Expand Down
6 changes: 4 additions & 2 deletions src/fri/tests.cairo
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// === RECURSIVE BEGIN ===
#[cfg(feature: 'recursive')]
mod test_fri_commit;
#[cfg(feature: 'recursive')]
mod test_fri_config;
#[cfg(feature: 'recursive')]
mod test_fri_verify;
// === RECURSIVE END ===

mod test_fri_formula;
mod test_last_layer;
mod test_next_layer;
24 changes: 11 additions & 13 deletions src/fri/tests/test_fri_verify.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@ use cairo_verifier::{
fri::fri::fri_verify, tests::{stone_proof_fibonacci, stone_proof_fibonacci_keccak}
};

// === BLAKE2S BEGIN ===
// #[test]
// #[available_gas(9999999999)]
// fn test_fri_verify() {
// let queries = stone_proof_fibonacci::queries::get().span();
// let commitment = stone_proof_fibonacci::fri::commitment::get();
// let decommitment = stone_proof_fibonacci::fri::decommitment::get();
// let witness = stone_proof_fibonacci::fri::witness::get();
#[cfg(feature: 'blake2s')]
#[test]
#[available_gas(9999999999)]
fn test_fri_verify() {
let queries = stone_proof_fibonacci::queries::get().span();
let commitment = stone_proof_fibonacci::fri::commitment::get();
let decommitment = stone_proof_fibonacci::fri::decommitment::get();
let witness = stone_proof_fibonacci::fri::witness::get();

// fri_verify(queries, commitment, decommitment, witness)
// }
// === BLAKE2S END ===
fri_verify(queries, commitment, decommitment, witness)
}

// === KECCAK BEGIN ===
#[cfg(feature: 'keccak')]
#[test]
#[available_gas(9999999999)]
fn test_fri_verify() {
Expand All @@ -26,6 +25,5 @@ fn test_fri_verify() {

fri_verify(queries, commitment, decommitment, witness)
}
// === KECCAK END ===


51 changes: 25 additions & 26 deletions src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
mod air;
// === RECURSIVE BEGIN ===

#[cfg(feature: 'recursive')]
mod benches;
// === RECURSIVE END ===

mod channel;
mod common;
mod deserialization;
Expand All @@ -14,31 +15,29 @@ mod stark;
mod table_commitment;
mod vector_commitment;

// === RECURSIVE BEGIN ===
#[cfg(feature: 'recursive')]
mod tests;
// === RECURSIVE END ===

use cairo_verifier::{
deserialization::stark::StarkProofWithSerde, stark::{StarkProof, StarkProofImpl},
// === DEX BEGIN ===
// air::layouts::dex::public_input::DexPublicInputImpl as PublicInputImpl,
// === DEX END ===
// === RECURSIVE BEGIN ===
air::layouts::recursive::public_input::RecursivePublicInputImpl as PublicInputImpl,
// === RECURSIVE END ===
// === RECURSIVE_WITH_POSEIDON BEGIN ===
// air::layouts::recursive_with_poseidon::public_input::RecursiveWithPoseidonPublicInputImpl as PublicInputImpl,
// === RECURSIVE_WITH_POSEIDON END ===
// === SMALL BEGIN ===
// air::layouts::small::public_input::SmallPublicInputImpl as PublicInputImpl,
// === SMALL END ===
// === STARKNET BEGIN ===
// air::layouts::starknet::public_input::StarknetPublicInputImpl as PublicInputImpl,
// === STARKNET END ===
// === STARKNET_WITH_KECCAK BEGIN ===
// air::layouts::starknet_with_keccak::public_input::StarknetWithKeccakPublicInputImpl as PublicInputImpl,
// === STARKNET_WITH_KECCAK END ===
};

use cairo_verifier::{deserialization::stark::StarkProofWithSerde, stark::{StarkProof, StarkProofImpl}};

#[cfg(feature: 'dex')]
use cairo_verifier::air::layouts::dex::public_input::{DexPublicInputImpl as PublicInputImpl};

#[cfg(feature: 'recursive')]
use cairo_verifier::air::layouts::recursive::public_input::RecursivePublicInputImpl as PublicInputImpl;

#[cfg(feature: 'recursive_with_poseidon')]
use cairo_verifier::air::layouts::recursive_with_poseidon::public_input::RecursiveWithPoseidonPublicInputImpl as PublicInputImpl;

#[cfg(feature: 'small')]
use cairo_verifier::air::layouts::small::public_input::SmallPublicInputImpl as PublicInputImpl;

#[cfg(feature: 'starknet')]
use cairo_verifier::air::layouts::starknet::public_input::StarknetPublicInputImpl as PublicInputImpl;

#[cfg(feature: 'starknet_with_keccak')]
use cairo_verifier::air::layouts::starknet_with_keccak::public_input::StarknetWithKeccakPublicInputImpl as PublicInputImpl;


const SECURITY_BITS: felt252 = 50;

Expand Down
Loading

0 comments on commit 9fc1b46

Please sign in to comment.