Skip to content

Commit

Permalink
Optimizations (#136)
Browse files Browse the repository at this point in the history
* Use divrem in rotr functions

* Sigma calculation optimization

* Use felts where possible

* Inline rotr functions

* Fmt

* Fix comment break

* Revert to scarb 2.6.3

* Fmt

* Fmt

* public input hash test

* cairo0_example_proof_blake2s

* Fix public input test

* Fmt

* ducking formatting

* I gonna loose my mind

---------

Co-authored-by: Bartosz Nowak <bartekn337@gmail.com>
  • Loading branch information
fmkra and Okm165 authored Aug 29, 2024
1 parent 1c8fb28 commit af5cf79
Show file tree
Hide file tree
Showing 16 changed files with 407 additions and 132 deletions.
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
2 changes: 1 addition & 1 deletion src/air/layouts/recursive/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl RecursivePublicInputImpl 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
2 changes: 1 addition & 1 deletion src/air/layouts/recursive_with_poseidon/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl RecursiveWithPoseidonPublicInputImpl 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
2 changes: 1 addition & 1 deletion src/air/layouts/small/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl SmallPublicInputImpl 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
2 changes: 1 addition & 1 deletion src/air/layouts/starknet/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl StarknetPublicInputImpl 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
2 changes: 1 addition & 1 deletion src/air/layouts/starknet_with_keccak/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl StarknetWithKeccakPublicInputImpl 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
7 changes: 5 additions & 2 deletions src/air/public_input.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,17 @@ fn verify_cairo1_public_input(public_input: @PublicInput) -> (felt252, felt252)
let program = memory.extract_range_unchecked(0, memory.len() - output_len);
let program_hash = poseidon_hash_span(program);

// 2. Output segment
// 2. Output segment
let output = memory.extract_range_unchecked(memory.len() - output_len, output_len);
let output_hash = poseidon_hash_span(output);
(program_hash, output_hash)
}

// === RECURSIVE BEGIN ===
#[cfg(test)]
mod tests {
use super::get_public_input_hash;
use cairo_verifier::tests::stone_proof_fibonacci_keccak::public_input::get;
// test data from cairo0-verifier run on stone-prover generated proof
#[test]
#[available_gas(9999999999)]
fn test_get_public_input_hash() {
Expand All @@ -199,3 +199,6 @@ mod tests {
)
}
}
// === RECURSIVE END ===


2 changes: 1 addition & 1 deletion src/air/public_memory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl PageImpl of PageTrait {

let current = *self.at(offset);

// TODO is this needed? If not we can just use slice directly
// TODO is this needed? If not we can just use slice directly
assert(current.address == (addr + i).into(), 'Invalid address');
arr.append(current.value);
i += 1;
Expand Down
Loading

0 comments on commit af5cf79

Please sign in to comment.