Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hints): add NewHint#34 #1091

Merged
merged 8 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,26 @@
%}
```

* Implement hint for cairo_sha256_arbitrary_input_length whitelist [#1091](https://github.com/lambdaclass/cairo-rs/pull/1091)

`BuiltinHintProcessor` now supports the following hint:

```python
%{
from starkware.cairo.common.cairo_sha256.sha256_utils import (
compute_message_schedule, sha2_compress_function)

_sha256_input_chunk_size_felts = int(ids.SHA256_INPUT_CHUNK_SIZE_FELTS)
assert 0 <= _sha256_input_chunk_size_felts < 100
_sha256_state_size_felts = int(ids.SHA256_STATE_SIZE_FELTS)
assert 0 <= _sha256_state_size_felts < 100
w = compute_message_schedule(memory.get_range(
ids.sha256_start, _sha256_input_chunk_size_felts))
new_state = sha2_compress_function(memory.get_range(ids.state, _sha256_state_size_felts), w)
segments.write_arg(ids.output, new_state)
%}
```

* Add missing hint on vrf.json lib [#1053](https://github.com/lambdaclass/cairo-rs/pull/1053):

`BuiltinHintProcessor` now supports the following hint:
Expand Down
43 changes: 43 additions & 0 deletions cairo_programs/packed_sha256_test.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
%builtins range_check bitwise
from starkware.cairo.common.alloc import alloc
from cairo_programs.packed_sha256 import (
BLOCK_SIZE,
compute_message_schedule,
sha2_compress,
get_round_constants,
sha256,
finalize_sha256,
)
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin

func test_packed_sha256{range_check_ptr, bitwise_ptr: BitwiseBuiltin*}() {
alloc_locals;
let input_len = 3;
let input: felt* = alloc();
assert input[0] = 1214606444;
assert input[1] = 1864398703;
assert input[2] = 1919706112;
let n_bytes = 11;

let (local sha256_ptr_start: felt*) = alloc();
let sha256_ptr = sha256_ptr_start;

let (local output: felt*) = sha256{sha256_ptr=sha256_ptr}(input, n_bytes);
assert output[0] = 1693223114;
assert output[1] = 11692261;
assert output[2] = 3122279783;
assert output[3] = 2317046550;
assert output[4] = 3524457715;
assert output[5] = 1722959730;
assert output[6] = 844319370;
assert output[7] = 3970137916;

finalize_sha256(sha256_ptr_start=sha256_ptr_start, sha256_ptr_end=sha256_ptr);

return ();
}

func main{range_check_ptr, bitwise_ptr: BitwiseBuiltin*}() {
test_packed_sha256();
return ();
}
Loading
Loading