-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement inline casm for segment arena
- Loading branch information
1 parent
74c2110
commit 6883060
Showing
5 changed files
with
125 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# Set to run some specific file tests (ex. fib.cairo,alloc.cairo) | ||
INTEGRATION_TESTS_FILTERS=proofmode__small.cairo | ||
INTEGRATION_TESTS_FILTERS= |
45 changes: 45 additions & 0 deletions
45
integration_tests/cairo_1_programs/with_input/proofmode_segment_arena__small.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use array::ArrayTrait; | ||
use array::SpanTrait; | ||
use dict::Felt252DictTrait; | ||
use pedersen::PedersenTrait; | ||
|
||
fn main(mut vals: Array<felt252>) -> Array<felt252> { | ||
// Create a dictionary using segment arena | ||
let mut dict = felt252_dict_new::<felt252>(); | ||
|
||
// Store each value in the dictionary with its index | ||
let mut index: felt252 = 0; | ||
loop { | ||
match vals.pop_front() { | ||
Option::Some(v) => { | ||
dict.insert(index, v); | ||
index += 1; | ||
}, | ||
Option::None(_) => { | ||
break; | ||
} | ||
}; | ||
}; | ||
|
||
// Create result array | ||
let mut res: Array<felt252> = ArrayTrait::new(); | ||
|
||
// Read values back from dictionary and hash them | ||
let mut i: felt252 = 0; | ||
loop { | ||
let i_u128: u128 = i.try_into().unwrap(); | ||
let index_u128: u128 = index.try_into().unwrap(); | ||
|
||
if i_u128 >= index_u128 { | ||
break; | ||
} | ||
|
||
let value = dict.get(i); | ||
let hash = pedersen::pedersen(value, i); | ||
res.append(hash); | ||
|
||
i += 1; | ||
}; | ||
|
||
res | ||
} |
47 changes: 47 additions & 0 deletions
47
integration_tests/cairo_1_programs/with_input/proofmode_with_builtins__small.cairo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use array::ArrayTrait; | ||
use array::SpanTrait; | ||
use pedersen::PedersenTrait; | ||
use core::num::traits::Bounded; | ||
|
||
fn check_and_sum(mut vals: Array<felt252>) -> felt252 { | ||
let mut sum: felt252 = 0; | ||
let upper_bound: u128 = 1000000; // Example bound | ||
|
||
loop { | ||
match vals.pop_front() { | ||
Option::Some(v) => { | ||
// Convert felt252 to u128 for range check | ||
let v_u128: u128 = v.try_into().unwrap(); | ||
// This will ensure v is non-negative and within u128 bounds | ||
assert(v_u128 <= upper_bound, 'Value exceeds bound'); | ||
|
||
sum += v; | ||
}, | ||
Option::None(_) => { | ||
break sum; | ||
} | ||
}; | ||
} | ||
} | ||
|
||
fn main(mut vals: Array<felt252>) -> Array<felt252> { | ||
// Calculate sum with range checks | ||
let sum = check_and_sum(vals); | ||
|
||
// Hash the sum using Pedersen | ||
let hash = pedersen::pedersen(sum, 0); | ||
|
||
// Create result array | ||
let mut res: Array<felt252> = ArrayTrait::new(); | ||
|
||
// Add original sum | ||
res.append(sum); | ||
// Add hash of sum | ||
res.append(hash); | ||
|
||
// Add a u128 conversion to demonstrate more range checks | ||
let sum_u128: u128 = sum.try_into().unwrap(); | ||
res.append(sum_u128.into()); | ||
|
||
res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters