Skip to content

Commit 4d97173

Browse files
MegaRedHandOppenfmolettapefontana
authored
feat(hints): add NewHint#34 (#1091)
* Add NewHint#34 Co-authored-by: Mario Rugiero <[email protected]> * Update changelog * Change `let` + `assert` for `assert` Co-authored-by: fmoletta <[email protected]> * Change AssertionFailed messages * Change let + assert for simple assert --------- Co-authored-by: Mario Rugiero <[email protected]> Co-authored-by: fmoletta <[email protected]> Co-authored-by: Pedro Fontana <[email protected]>
1 parent a733298 commit 4d97173

File tree

11 files changed

+1228
-50
lines changed

11 files changed

+1228
-50
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,26 @@
142142
%}
143143
```
144144

145+
* Implement hint for cairo_sha256_arbitrary_input_length whitelist [#1091](https://github.com/lambdaclass/cairo-rs/pull/1091)
146+
147+
`BuiltinHintProcessor` now supports the following hint:
148+
149+
```python
150+
%{
151+
from starkware.cairo.common.cairo_sha256.sha256_utils import (
152+
compute_message_schedule, sha2_compress_function)
153+
154+
_sha256_input_chunk_size_felts = int(ids.SHA256_INPUT_CHUNK_SIZE_FELTS)
155+
assert 0 <= _sha256_input_chunk_size_felts < 100
156+
_sha256_state_size_felts = int(ids.SHA256_STATE_SIZE_FELTS)
157+
assert 0 <= _sha256_state_size_felts < 100
158+
w = compute_message_schedule(memory.get_range(
159+
ids.sha256_start, _sha256_input_chunk_size_felts))
160+
new_state = sha2_compress_function(memory.get_range(ids.state, _sha256_state_size_felts), w)
161+
segments.write_arg(ids.output, new_state)
162+
%}
163+
```
164+
145165
* Add missing hint on vrf.json lib [#1053](https://github.com/lambdaclass/cairo-rs/pull/1053):
146166

147167
`BuiltinHintProcessor` now supports the following hint:
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
%builtins range_check bitwise
2+
from starkware.cairo.common.alloc import alloc
3+
from cairo_programs.packed_sha256 import (
4+
BLOCK_SIZE,
5+
compute_message_schedule,
6+
sha2_compress,
7+
get_round_constants,
8+
sha256,
9+
finalize_sha256,
10+
)
11+
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin
12+
13+
func test_packed_sha256{range_check_ptr, bitwise_ptr: BitwiseBuiltin*}() {
14+
alloc_locals;
15+
let input_len = 3;
16+
let input: felt* = alloc();
17+
assert input[0] = 1214606444;
18+
assert input[1] = 1864398703;
19+
assert input[2] = 1919706112;
20+
let n_bytes = 11;
21+
22+
let (local sha256_ptr_start: felt*) = alloc();
23+
let sha256_ptr = sha256_ptr_start;
24+
25+
let (local output: felt*) = sha256{sha256_ptr=sha256_ptr}(input, n_bytes);
26+
assert output[0] = 1693223114;
27+
assert output[1] = 11692261;
28+
assert output[2] = 3122279783;
29+
assert output[3] = 2317046550;
30+
assert output[4] = 3524457715;
31+
assert output[5] = 1722959730;
32+
assert output[6] = 844319370;
33+
assert output[7] = 3970137916;
34+
35+
finalize_sha256(sha256_ptr_start=sha256_ptr_start, sha256_ptr_end=sha256_ptr);
36+
37+
return ();
38+
}
39+
40+
func main{range_check_ptr, bitwise_ptr: BitwiseBuiltin*}() {
41+
test_packed_sha256();
42+
return ();
43+
}

0 commit comments

Comments
 (0)