Skip to content

Commit

Permalink
Rename cairo_version => memory_verification
Browse files Browse the repository at this point in the history
  • Loading branch information
fmkra committed Nov 8, 2024
1 parent d9e5e56 commit 00cee89
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 50 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/proof_verification_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
cairo_version: ['cairo0', 'cairo1']
memory_verification: ['cairo0', 'cairo1']
layout: ['recursive', 'recursive_with_poseidon', 'small', 'dex', 'starknet', 'starknet_with_keccak']
hash_function: ['keccak']
hasher_bit_length: ['160_lsb']
Expand All @@ -34,4 +34,4 @@ jobs:
run: scarb build --no-default-features --features monolith,${{ matrix.layout }},${{ matrix.hash_function }}

- name: Run verification
run: cargo run --release --bin runner -- --program target/dev/integrity.sierra.json --cairo-version ${{ matrix.cairo_version == 'cairo0' && 'strict' || 'cairo1' }} --stone-version ${{ matrix.stone_version }} --hasher-bit-length ${{ matrix.hasher_bit_length }} < examples/proofs/${{ matrix.layout }}/${{ matrix.cairo_version }}_${{ matrix.stone_version }}_${{ matrix.hash_function }}_${{ matrix.hasher_bit_length }}_example_proof.json
run: cargo run --release --bin runner -- --program target/dev/integrity.sierra.json --cairo-version ${{ matrix.memory_verification == 'cairo0' && 'strict' || 'cairo1' }} --stone-version ${{ matrix.stone_version }} --hasher-bit-length ${{ matrix.hasher_bit_length }} < examples/proofs/${{ matrix.layout }}/${{ matrix.memory_verification }}_${{ matrix.stone_version }}_${{ matrix.hash_function }}_${{ matrix.hasher_bit_length }}_example_proof.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ verifier types: [`monolith`, `split`]

There are also additional settings that can be configured at runtime:

`cairo_version`: [`cairo0`, `cairo1`]<br />
`memory_verification`: [`cairo0`, `cairo1`]<br /> TODO CHANGE
`stone_version`: [`stone5`, `stone6`]<br />
hasher bit length: [`160_lsb`, `248_lsb`]

Expand Down
12 changes: 6 additions & 6 deletions runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ use clap::ValueEnum;
pub use vec252::VecFelt252;

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum CairoVersion {
pub enum MemoryVerification {
Strict = 0,
Relaxed = 1,
Cairo1 = 2,
}

impl From<CairoVersion> for Felt252 {
fn from(value: CairoVersion) -> Self {
impl From<MemoryVerification> for Felt252 {
fn from(value: MemoryVerification) -> Self {
match value {
CairoVersion::Strict => Felt252::from(0),
CairoVersion::Relaxed => Felt252::from(1),
CairoVersion::Cairo1 => Felt252::from(2),
MemoryVerification::Strict => Felt252::from(0),
MemoryVerification::Relaxed => Felt252::from(1),
MemoryVerification::Cairo1 => Felt252::from(2),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use cairo_lang_sierra::program::VersionedProgram;
use cairo_lang_utils::ordered_hash_map::OrderedHashMap;
use clap::Parser;
use itertools::{chain, Itertools};
use runner::{CairoVersion, HasherBitLength, StoneVersion};
use runner::{HasherBitLength, MemoryVerification, StoneVersion};
use std::{
fs,
io::{stdin, Read},
Expand All @@ -25,7 +25,7 @@ struct Cli {
program: String,
/// Cairo version - public memory pattern
#[clap(value_enum, short, long)]
cairo_version: CairoVersion,
memory_verification: MemoryVerification,
/// Stone version
#[clap(value_enum, short, long)]
stone_version: StoneVersion,
Expand Down Expand Up @@ -71,7 +71,7 @@ fn main() -> anyhow::Result<()> {
let func = runner.find_function(ENTRYPOINT).unwrap();
let args = &[
Arg::Array(proof.into_iter().map(Arg::Value).collect_vec()),
Arg::Value(cli.cairo_version.into()),
Arg::Value(cli.memory_verification.into()),
Arg::Value(cli.hasher_bit_length.into()),
Arg::Value(cli.stone_version.into()),
];
Expand Down
4 changes: 2 additions & 2 deletions src/air/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,12 @@ fn verify_relaxed_public_input(public_input: @PublicInput) -> (felt252, felt252)
mod tests {
use super::get_public_input_hash;
use integrity::tests::stone_proof_fibonacci_keccak::public_input::get;
use integrity::settings::{VerifierSettings, CairoVersion, HasherBitLength, StoneVersion};
use integrity::settings::{VerifierSettings, MemoryVerification, HasherBitLength, StoneVersion};
#[test]
#[available_gas(9999999999)]
fn test_get_public_input_hash() {
let settings = VerifierSettings {
cairo_version: 2, // cairo1
memory_verification: 2, // cairo1
hasher_bit_length: HasherBitLength::Lsb160,
stone_version: StoneVersion::Stone5,
};
Expand Down
4 changes: 2 additions & 2 deletions src/benches/air/traces/decommit.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use integrity::{
channel::channel::ChannelImpl, air::layouts::recursive::{traces::traces_decommit},
tests::stone_proof_fibonacci,
settings::{VerifierSettings, HasherBitLength, StoneVersion, CairoVersion},
settings::{VerifierSettings, HasherBitLength, StoneVersion, MemoryVerification},
};

fn bench_air_traces_decommit() {
Expand All @@ -11,7 +11,7 @@ fn bench_air_traces_decommit() {
let witness = stone_proof_fibonacci::traces::witness::get();

let settings = VerifierSettings {
cairo_version: 0, // strict
memory_verification: 0, // strict
hasher_bit_length: HasherBitLength::Lsb160,
stone_version: StoneVersion::Stone5,
};
Expand Down
2 changes: 1 addition & 1 deletion src/benches/stark/stark_proof_verify.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn bench_stark_proof_verify() {
};

let settings = VerifierSettings {
cairo_version: 0, // strict
memory_verification: 0, // strict
hasher_bit_length: HasherBitLength::Lsb160,
stone_version: StoneVersion::Stone5,
};
Expand Down
2 changes: 1 addition & 1 deletion src/benches/stark/verify.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn bench_stark_verify() {
let stark_domains = stone_proof_fibonacci_keccak::stark::domains::get();

let settings = VerifierSettings {
cairo_version: 0, // strict
memory_verification: 0, // strict
hasher_bit_length: HasherBitLength::Lsb160,
stone_version: StoneVersion::Stone5,
};
Expand Down
3 changes: 2 additions & 1 deletion src/contracts/fact_registry.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ mod FactRegistry {
}
}

#[abi(embed_v0)]
impl FactRegistryImpl of IFactRegistry<ContractState> {
fn get_all_verifications_for_fact_hash(
self: @ContractState, fact_hash: FactHash
Expand Down Expand Up @@ -291,7 +292,7 @@ mod FactRegistry {
.update(verifier_config.layout)
.update(verifier_config.hasher)
.update(verifier_config.stone_version)
.update(verifier_config.cairo_version)
.update(verifier_config.memory_verification)
.finalize();

let verification_hash = PoseidonImpl::new()
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/proxy.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ mod Proxy {
},
fact_registry_interface::{IFactRegistryDispatcher, IFactRegistryDispatcherTrait,}
},
StarkProofWithSerde, StarkProof, CairoVersion,
StarkProofWithSerde, StarkProof, MemoryVerification,
fri::fri::{FriLayerWitness, FriVerificationStateConstant, FriVerificationStateVariable},
settings::{JobId, FactHash, VerificationHash},
};
Expand Down
12 changes: 6 additions & 6 deletions src/contracts/verifier.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use integrity::{
StarkProof, CairoVersion, StarkProofWithSerde,
StarkProof, MemoryVerification, StarkProofWithSerde,
fri::fri::{FriLayerWitness, FriVerificationStateConstant, FriVerificationStateVariable},
settings::{VerifierSettings, FactHash, JobId, SecurityBits},
};
Expand Down Expand Up @@ -66,7 +66,7 @@ mod CairoVerifier {
storage::{StoragePointerReadAccess, StoragePointerWriteAccess, StoragePathEntry, Map},
};
use integrity::{
CairoVersion, PublicInputImpl, StarkProofWithSerde, stark::{StarkProof, StarkProofImpl},
MemoryVerification, PublicInputImpl, StarkProofWithSerde, stark::{StarkProof, StarkProofImpl},
fri::fri::{
FriLayerWitness, FriVerificationStateConstant, FriVerificationStateVariable,
hash_constant, hash_variable
Expand Down Expand Up @@ -111,12 +111,12 @@ mod CairoVerifier {
stark_proof_serde: StarkProofWithSerde,
) -> ProofVerified {
let stark_proof: StarkProof = stark_proof_serde.into();
let (program_hash, output_hash) = match settings.cairo_version {
let (program_hash, output_hash) = match settings.memory_verification {
0 => stark_proof.public_input.verify_strict(),
1 => stark_proof.public_input.verify_relaxed(),
2 => stark_proof.public_input.verify_cairo1(),
_ => {
assert(false, 'invalid cairo_version');
assert(false, 'invalid memory_verification');
(0, 0)
}
};
Expand All @@ -143,12 +143,12 @@ mod CairoVerifier {
assert(self.state_constant.entry(job_id).read().is_none(), 'job_id already exists');

let stark_proof: StarkProof = stark_proof_serde.into();
let (program_hash, output_hash) = match settings.cairo_version {
let (program_hash, output_hash) = match settings.memory_verification {
0 => stark_proof.public_input.verify_strict(),
1 => stark_proof.public_input.verify_relaxed(),
2 => stark_proof.public_input.verify_cairo1(),
_ => {
assert(false, 'invalid cairo_version');
assert(false, 'invalid memory_verification');
(0, 0)
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use integrity::{
IFactRegistry, IFactRegistryDispatcher, IFactRegistryDispatcherTrait
},
settings::{
FactHash, VerificationHash, PresetHash, SecurityBits, JobId, CairoVersion, HasherBitLength,
FactHash, VerificationHash, PresetHash, SecurityBits, JobId, MemoryVerification, HasherBitLength,
StoneVersion, VerifierSettings, VerifierPreset, VerifierConfiguration, split_settings
},
};
Expand Down Expand Up @@ -74,12 +74,12 @@ fn main(mut serialized: Span<felt252>, settings: @VerifierSettings) -> (felt252,
.verify(ContractAddressZero::zero(), ContractAddressZero::zero(), settings);
assert(security_bits >= SECURITY_BITS, 'Security bits are too low');

let (program_hash, output_hash) = match (*settings).cairo_version {
let (program_hash, output_hash) = match (*settings).memory_verification {
0 => stark_proof.public_input.verify_strict(),
1 => stark_proof.public_input.verify_relaxed(),
2 => stark_proof.public_input.verify_cairo1(),
_ => {
assert(false, 'invalid cairo_version');
assert(false, 'invalid memory_verification');
(0, 0)
}
};
Expand Down
20 changes: 10 additions & 10 deletions src/settings.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type JobId = felt252;


#[derive(Drop, Copy, PartialEq, Serde, starknet::Store)]
enum CairoVersion {
enum MemoryVerification {
Strict,
Relaxed,
Cairo1,
Expand All @@ -27,7 +27,7 @@ enum StoneVersion {
// settings accepted by verifier (parameters for verification)
#[derive(Drop, Copy, Serde, starknet::Store)]
struct VerifierSettings {
cairo_version: felt252, // should be CairoVersion but causes compiler bug
memory_verification: felt252, // should be MemoryVerification but causes compiler bug
hasher_bit_length: HasherBitLength,
stone_version: StoneVersion,
}
Expand All @@ -45,19 +45,19 @@ struct VerifierConfiguration {
layout: felt252, // string encoded as hex
hasher: felt252, // function and number of bits
stone_version: felt252, // stone5 or stone6
cairo_version: felt252, // cairo0 or cairo1
memory_verification: felt252, // cairo0 or cairo1
}

fn split_settings(verifier_config: VerifierConfiguration) -> (VerifierSettings, VerifierPreset) {
let layout = verifier_config.layout;

let cairo_version = if verifier_config.cairo_version == 'strict' {
0 // CairoVersion::Strict
} else if verifier_config.cairo_version == 'relaxed' {
1 // CairoVersion::Relaxed
let memory_verification = if verifier_config.memory_verification == 'strict' {
0 // MemoryVerification::Strict
} else if verifier_config.memory_verification == 'relaxed' {
1 // MemoryVerification::Relaxed
} else {
assert(verifier_config.cairo_version == 'cairo1', 'Unsupported cairo version');
2 // CairoVersion::Cairo1
assert(verifier_config.memory_verification == 'cairo1', 'Unsupported cairo version');
2 // MemoryVerification::Cairo1
};

let (hasher, hasher_bit_length) = if verifier_config.hasher == 'keccak_160_lsb' {
Expand All @@ -79,7 +79,7 @@ fn split_settings(verifier_config: VerifierConfiguration) -> (VerifierSettings,
};

(
VerifierSettings { cairo_version, hasher_bit_length, stone_version },
VerifierSettings { memory_verification, hasher_bit_length, stone_version },
VerifierPreset { layout, hasher }
)
}
4 changes: 2 additions & 2 deletions src/stark/tests/test_stark_proof_verify.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn test_stark_proof_fibonacci_verify() {
};

let settings = VerifierSettings {
cairo_version: 0, // strict
memory_verification: 0, // strict
hasher_bit_length: HasherBitLength::Lsb160,
stone_version: StoneVersion::Stone5,
};
Expand All @@ -42,7 +42,7 @@ fn test_stark_proof_fibonacci_verify() {
};

let settings = VerifierSettings {
cairo_version: 0, // strict
memory_verification: 0, // strict
hasher_bit_length: HasherBitLength::Lsb160,
stone_version: StoneVersion::Stone5,
};
Expand Down
4 changes: 2 additions & 2 deletions src/stark/tests/test_stark_verify.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn test_stark_verify() {
let stark_domains = stone_proof_fibonacci::stark::domains::get();

let settings = VerifierSettings {
cairo_version: 0, // strict
memory_verification: 0, // strict
hasher_bit_length: HasherBitLength::Lsb160,
stone_version: StoneVersion::Stone5,
};
Expand All @@ -41,7 +41,7 @@ fn test_stark_verify() {
let stark_domains = stone_proof_fibonacci_keccak::stark::domains::get();

let settings = VerifierSettings {
cairo_version: 0, // strict
memory_verification: 0, // strict
hasher_bit_length: HasherBitLength::Lsb160,
stone_version: StoneVersion::Stone5,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn test_table_commitment_decommit() {
let witness = stone_proof_fibonacci::traces::witness::get().original;

let settings = VerifierSettings {
cairo_version: 0, // strict
memory_verification: 0, // strict
hasher_bit_length: HasherBitLength::Lsb160,
stone_version: StoneVersion::Stone5,
};
Expand All @@ -37,7 +37,7 @@ fn test_table_commitment_decommit() {
let witness = stone_proof_fibonacci_keccak::traces::witness::get().original;

let settings = VerifierSettings {
cairo_version: 0, // strict
memory_verification: 0, // strict
hasher_bit_length: HasherBitLength::Lsb160,
stone_version: StoneVersion::Stone5,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fn test_vector_commitment_decommit_1() {
};

let settings = VerifierSettings {
cairo_version: 0, // strict
memory_verification: 0, // strict
hasher_bit_length: HasherBitLength::Lsb160,
stone_version: StoneVersion::Stone5,
};
Expand Down Expand Up @@ -217,7 +217,7 @@ fn test_vector_commitment_decommit() {
};

let settings = VerifierSettings {
cairo_version: 0, // strict
memory_verification: 0, // strict
hasher_bit_length: HasherBitLength::Lsb160,
stone_version: StoneVersion::Stone5,
};
Expand Down
6 changes: 3 additions & 3 deletions verify-on-starknet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Check if the arguments are provided
if [ $# -ne 6 ]; then
echo "Usage: $0 <fact_registry_address> <calldata_file> <layout> <hasher> <stone_version> <cairo_version>"
echo "Usage: $0 <fact_registry_address> <calldata_file> <layout> <hasher> <stone_version> <memory_verification>"
exit 1
fi

Expand All @@ -22,7 +22,7 @@ calldata_file=$2
layout=$(string_to_hex $3)
hasher=$(string_to_hex $4)
stone_version=$(string_to_hex $5)
cairo_version=$(string_to_hex $6)
memory_verification=$(string_to_hex $6)

# Check if the file exists
if [ ! -f "$calldata_file" ]; then
Expand All @@ -39,5 +39,5 @@ sncast \
invoke \
--contract-address "$contract_address" \
--function "verify_proof_full_and_register_fact" \
--calldata $layout $hasher $stone_version $cairo_version $calldata \
--calldata $layout $hasher $stone_version $memory_verification $calldata \
--fee-token eth

0 comments on commit 00cee89

Please sign in to comment.