Skip to content

Commit

Permalink
Merge pull request #142 from HerodotusDev/Cairo_v0.13.2a0_fixes
Browse files Browse the repository at this point in the history
Cairo v0.13.2a0 fixes
  • Loading branch information
Okm165 authored Sep 6, 2024
2 parents d464f10 + df4da74 commit 29df665
Show file tree
Hide file tree
Showing 21 changed files with 556 additions and 297 deletions.
45 changes: 0 additions & 45 deletions .github/workflows/proof_verification_tests.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/air/layouts/dex/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl DexPublicInputImpl of PublicInputTrait {
ref memory_index
);

// 3. Output segment
// 3. Output segment
let output_len = output_stop - output_start;
let output = memory
.extract_range(
Expand Down
32 changes: 23 additions & 9 deletions src/air/layouts/recursive/public_input.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::array::ArrayTrait;
use core::traits::Into;
use cairo_verifier::{
common::{
math::{pow, Felt252PartialOrd, Felt252Div},
Expand All @@ -10,7 +12,10 @@ use cairo_verifier::{
segments, get_builtins, CPU_COMPONENT_HEIGHT, CPU_COMPONENT_STEP, LAYOUT_CODE,
PEDERSEN_BUILTIN_ROW_RATIO, RANGE_CHECK_BUILTIN_ROW_RATIO, BITWISE_ROW_RATIO
},
public_input::{PublicInput, PublicInputTrait, verify_cairo1_public_input}
public_input::{
PublicInput, PublicInputTrait, verify_cairo1_public_input,
get_builtins as get_program_builtins
}
},
domains::StarkDomains
};
Expand All @@ -36,7 +41,8 @@ impl RecursivePublicInputImpl of PublicInputTrait {
// TODO support more pages?
assert(self.continuous_page_headers.len() == 0, 'Invalid continuous_page_headers');

let builtins = get_builtins();
let layout_builtins = get_builtins();
let program_builtins = get_program_builtins();
let memory = self.main_page;

// 1. Program segment
Expand All @@ -55,7 +61,7 @@ impl RecursivePublicInputImpl of PublicInputTrait {
assert(
*program[0] == 0x40780017fff7fff, 'Invalid program'
); // Instruction: ap += N_BUILTINS.
assert(*program[1] == builtins.len().into(), 'Invalid program');
assert(*program[1] == program_builtins.len().into(), 'Invalid program');
assert(*program[2] == 0x1104800180018000, 'Invalid program'); // Instruction: call rel ?.
assert(*program[4] == 0x10780017fff7fff, 'Invalid program'); // Instruction: jmp rel 0.
assert(*program[5] == 0x0, 'Invalid program');
Expand All @@ -76,10 +82,10 @@ impl RecursivePublicInputImpl of PublicInputTrait {
// 2.2 Main arguments and return values
let mut begin_addresses = ArrayTrait::new();
let mut stop_addresses = ArrayTrait::new();
let layout_builtins_len = layout_builtins.len();
let mut i = 0;
let builtins_len = builtins.len();
loop {
if i == builtins_len {
if i == layout_builtins_len {
break;
}

Expand All @@ -88,16 +94,24 @@ impl RecursivePublicInputImpl of PublicInputTrait {

i += 1;
};
memory.verify_stack(initial_ap, begin_addresses.span(), builtins_len, ref memory_index);
memory
.verify_stack(
final_ap - builtins_len.into(),
initial_ap,
begin_addresses.span(),
program_builtins.span(),
layout_builtins.span(),
ref memory_index
);
memory
.verify_stack(
final_ap - program_builtins.len().into(),
stop_addresses.span(),
builtins_len,
program_builtins.span(),
layout_builtins.span(),
ref memory_index
);

// 3. Output segment
// 3. Output segment
let output_len = output_stop - output_start;
let output = memory
.extract_range(
Expand Down
30 changes: 21 additions & 9 deletions src/air/layouts/recursive_with_poseidon/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use cairo_verifier::{
PEDERSEN_BUILTIN_ROW_RATIO, RANGE_CHECK_BUILTIN_ROW_RATIO, BITWISE_ROW_RATIO,
POSEIDON_ROW_RATIO
},
public_input::{PublicInput, PublicInputTrait, verify_cairo1_public_input}
public_input::{
PublicInput, PublicInputTrait, verify_cairo1_public_input,
get_builtins as get_program_builtins
}
},
domains::StarkDomains
};
Expand All @@ -37,7 +40,8 @@ impl RecursiveWithPoseidonPublicInputImpl of PublicInputTrait {
// TODO support more pages?
assert(self.continuous_page_headers.len() == 0, 'Invalid continuous_page_headers');

let builtins = get_builtins();
let layout_builtins = get_builtins();
let program_builtins = get_program_builtins();
let memory = self.main_page;

// 1. Program segment
Expand All @@ -56,7 +60,7 @@ impl RecursiveWithPoseidonPublicInputImpl of PublicInputTrait {
assert(
*program[0] == 0x40780017fff7fff, 'Invalid program'
); // Instruction: ap += N_BUILTINS.
assert(*program[1] == builtins.len().into(), 'Invalid program');
assert(*program[1] == program_builtins.len().into(), 'Invalid program');
assert(*program[2] == 0x1104800180018000, 'Invalid program'); // Instruction: call rel ?.
assert(*program[4] == 0x10780017fff7fff, 'Invalid program'); // Instruction: jmp rel 0.
assert(*program[5] == 0x0, 'Invalid program');
Expand All @@ -77,10 +81,10 @@ impl RecursiveWithPoseidonPublicInputImpl of PublicInputTrait {
// 2.2 Main arguments and return values
let mut begin_addresses = ArrayTrait::new();
let mut stop_addresses = ArrayTrait::new();
let layout_builtins_len = layout_builtins.len();
let mut i = 0;
let builtins_len = builtins.len();
loop {
if i == builtins_len {
if i == layout_builtins_len {
break;
}

Expand All @@ -89,16 +93,24 @@ impl RecursiveWithPoseidonPublicInputImpl of PublicInputTrait {

i += 1;
};
memory.verify_stack(initial_ap, begin_addresses.span(), builtins_len, ref memory_index);
memory
.verify_stack(
final_ap - builtins_len.into(),
initial_ap,
begin_addresses.span(),
program_builtins.span(),
layout_builtins.span(),
ref memory_index
);
memory
.verify_stack(
final_ap - program_builtins.len().into(),
stop_addresses.span(),
builtins_len,
program_builtins.span(),
layout_builtins.span(),
ref memory_index
);

// 3. Output segment
// 3. Output segment
let output_len = output_stop - output_start;
let output = memory
.extract_range(
Expand Down
30 changes: 21 additions & 9 deletions src/air/layouts/small/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use cairo_verifier::{
segments, get_builtins, CPU_COMPONENT_HEIGHT, CPU_COMPONENT_STEP, LAYOUT_CODE,
PEDERSEN_BUILTIN_ROW_RATIO, RANGE_CHECK_BUILTIN_ROW_RATIO, ECDSA_BUILTIN_ROW_RATIO
},
public_input::{PublicInput, PublicInputTrait, verify_cairo1_public_input}
public_input::{
PublicInput, PublicInputTrait, verify_cairo1_public_input,
get_builtins as get_program_builtins
}
},
domains::StarkDomains
};
Expand All @@ -36,7 +39,8 @@ impl SmallPublicInputImpl of PublicInputTrait {
// TODO support more pages?
assert(self.continuous_page_headers.len() == 0, 'Invalid continuous_page_headers');

let builtins = get_builtins();
let layout_builtins = get_builtins();
let program_builtins = get_program_builtins();
let memory = self.main_page;

// 1. Program segment
Expand All @@ -55,7 +59,7 @@ impl SmallPublicInputImpl of PublicInputTrait {
assert(
*program[0] == 0x40780017fff7fff, 'Invalid program'
); // Instruction: ap += N_BUILTINS.
assert(*program[1] == builtins.len().into(), 'Invalid program');
assert(*program[1] == program_builtins.len().into(), 'Invalid program');
assert(*program[2] == 0x1104800180018000, 'Invalid program'); // Instruction: call rel ?.
assert(*program[4] == 0x10780017fff7fff, 'Invalid program'); // Instruction: jmp rel 0.
assert(*program[5] == 0x0, 'Invalid program');
Expand All @@ -76,10 +80,10 @@ impl SmallPublicInputImpl of PublicInputTrait {
// 2.2 Main arguments and return values
let mut begin_addresses = ArrayTrait::new();
let mut stop_addresses = ArrayTrait::new();
let layout_builtins_len = layout_builtins.len();
let mut i = 0;
let builtins_len = builtins.len();
loop {
if i == builtins_len {
if i == layout_builtins_len {
break;
}

Expand All @@ -88,16 +92,24 @@ impl SmallPublicInputImpl of PublicInputTrait {

i += 1;
};
memory.verify_stack(initial_ap, begin_addresses.span(), builtins_len, ref memory_index);
memory
.verify_stack(
final_ap - builtins_len.into(),
initial_ap,
begin_addresses.span(),
program_builtins.span(),
layout_builtins.span(),
ref memory_index
);
memory
.verify_stack(
final_ap - program_builtins.len().into(),
stop_addresses.span(),
builtins_len,
program_builtins.span(),
layout_builtins.span(),
ref memory_index
);

// 3. Output segment
// 3. Output segment
let output_len = output_stop - output_start;
let output = memory
.extract_range(
Expand Down
30 changes: 21 additions & 9 deletions src/air/layouts/starknet/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use cairo_verifier::{
PEDERSEN_BUILTIN_ROW_RATIO, RANGE_CHECK_BUILTIN_ROW_RATIO, BITWISE_ROW_RATIO,
ECDSA_BUILTIN_ROW_RATIO, EC_OP_BUILTIN_ROW_RATIO, POSEIDON_ROW_RATIO
},
public_input::{PublicInput, PublicInputTrait, verify_cairo1_public_input}
public_input::{
PublicInput, PublicInputTrait, verify_cairo1_public_input,
get_builtins as get_program_builtins
}
},
domains::StarkDomains
};
Expand All @@ -37,7 +40,8 @@ impl StarknetPublicInputImpl of PublicInputTrait {
// TODO support more pages?
assert(self.continuous_page_headers.len() == 0, 'Invalid continuous_page_headers');

let builtins = get_builtins();
let layout_builtins = get_builtins();
let program_builtins = get_program_builtins();
let memory = self.main_page;

// 1. Program segment
Expand All @@ -56,7 +60,7 @@ impl StarknetPublicInputImpl of PublicInputTrait {
assert(
*program[0] == 0x40780017fff7fff, 'Invalid program'
); // Instruction: ap += N_BUILTINS.
assert(*program[1] == builtins.len().into(), 'Invalid program');
assert(*program[1] == program_builtins.len().into(), 'Invalid program');
assert(*program[2] == 0x1104800180018000, 'Invalid program'); // Instruction: call rel ?.
assert(*program[4] == 0x10780017fff7fff, 'Invalid program'); // Instruction: jmp rel 0.
assert(*program[5] == 0x0, 'Invalid program');
Expand All @@ -77,10 +81,10 @@ impl StarknetPublicInputImpl of PublicInputTrait {
// 2.2 Main arguments and return values
let mut begin_addresses = ArrayTrait::new();
let mut stop_addresses = ArrayTrait::new();
let layout_builtins_len = layout_builtins.len();
let mut i = 0;
let builtins_len = builtins.len();
loop {
if i == builtins_len {
if i == layout_builtins_len {
break;
}

Expand All @@ -89,16 +93,24 @@ impl StarknetPublicInputImpl of PublicInputTrait {

i += 1;
};
memory.verify_stack(initial_ap, begin_addresses.span(), builtins_len, ref memory_index);
memory
.verify_stack(
final_ap - builtins_len.into(),
initial_ap,
begin_addresses.span(),
program_builtins.span(),
layout_builtins.span(),
ref memory_index
);
memory
.verify_stack(
final_ap - program_builtins.len().into(),
stop_addresses.span(),
builtins_len,
program_builtins.span(),
layout_builtins.span(),
ref memory_index
);

// 3. Output segment
// 3. Output segment
let output_len = output_stop - output_start;
let output = memory
.extract_range(
Expand Down
Loading

0 comments on commit 29df665

Please sign in to comment.