-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* unsafe keccak + unsafe keccak finalize * solve many issues * fmt * fmt --------- Co-authored-by: Shourya Goel <[email protected]>
- Loading branch information
1 parent
6cab0ef
commit 312d061
Showing
8 changed files
with
151 additions
and
95 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
integration_tests/cairo_zero_hint_tests/unsafe_keccak.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,21 @@ | ||
%builtins output | ||
|
||
from starkware.cairo.common.alloc import alloc | ||
from starkware.cairo.common.keccak import unsafe_keccak | ||
|
||
func main{output_ptr: felt*}() { | ||
alloc_locals; | ||
|
||
let (data: felt*) = alloc(); | ||
|
||
assert data[0] = 500; | ||
assert data[1] = 2; | ||
assert data[2] = 3; | ||
assert data[3] = 6; | ||
assert data[4] = 1; | ||
assert data[5] = 4444; | ||
|
||
let (low: felt, high: felt) = unsafe_keccak(data, 6); | ||
|
||
return (); | ||
} |
21 changes: 21 additions & 0 deletions
21
integration_tests/cairo_zero_hint_tests/unsafe_keccak_finalize.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,21 @@ | ||
%builtins output | ||
|
||
from starkware.cairo.common.alloc import alloc | ||
from starkware.cairo.common.keccak import unsafe_keccak_finalize, KeccakState | ||
from starkware.cairo.common.uint256 import Uint256 | ||
|
||
func main{output_ptr: felt*}() { | ||
alloc_locals; | ||
|
||
let (data: felt*) = alloc(); | ||
|
||
assert data[0] = 0; | ||
assert data[1] = 1; | ||
assert data[2] = 2; | ||
|
||
let keccak_state = KeccakState(start_ptr=data, end_ptr=data + 2); | ||
|
||
let res: Uint256 = unsafe_keccak_finalize(keccak_state); | ||
|
||
return (); | ||
} |
84 changes: 0 additions & 84 deletions
84
integration_tests/cairo_zero_hint_tests_in_progress/block_permutation.small.cairo
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
..._tests/cairo_zero_hint_tests_in_progress/cairo_keccak_finalize.starknet_with_keccak.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,29 @@ | ||
%builtins range_check bitwise | ||
|
||
from starkware.cairo.common.cairo_keccak.keccak import cairo_keccak, finalize_keccak | ||
from starkware.cairo.common.uint256 import Uint256 | ||
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin | ||
from starkware.cairo.common.alloc import alloc | ||
|
||
func main{range_check_ptr: felt, bitwise_ptr: BitwiseBuiltin*}() { | ||
alloc_locals; | ||
|
||
let (keccak_ptr: felt*) = alloc(); | ||
let keccak_ptr_start = keccak_ptr; | ||
|
||
let (inputs: felt*) = alloc(); | ||
|
||
assert inputs[0] = 8031924123371070792; | ||
assert inputs[1] = 560229490; | ||
|
||
let n_bytes = 16; | ||
|
||
let (res: Uint256) = cairo_keccak{keccak_ptr=keccak_ptr}(inputs=inputs, n_bytes=n_bytes); | ||
|
||
assert res.low = 293431514620200399776069983710520819074; | ||
assert res.high = 317109767021952548743448767588473366791; | ||
|
||
finalize_keccak(keccak_ptr_start=keccak_ptr_start, keccak_ptr_end=keccak_ptr); | ||
|
||
return (); | ||
} |
39 changes: 39 additions & 0 deletions
39
integration_tests/cairo_zero_hint_tests_in_progress/keccak.starknet_with_keccak.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,39 @@ | ||
%builtins output range_check bitwise | ||
|
||
from starkware.cairo.common.cairo_keccak.keccak import _keccak | ||
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin | ||
from starkware.cairo.common.alloc import alloc | ||
from starkware.cairo.common.serialize import serialize_word | ||
|
||
func fill_array(array: felt*, base: felt, array_length: felt, iterator: felt) { | ||
if (iterator == array_length) { | ||
return (); | ||
} | ||
|
||
assert array[iterator] = base; | ||
|
||
return fill_array(array, base, array_length, iterator + 1); | ||
} | ||
|
||
func main{output_ptr: felt*, range_check_ptr, bitwise_ptr: BitwiseBuiltin*}() { | ||
alloc_locals; | ||
|
||
let (output: felt*) = alloc(); | ||
let keccak_output = output; | ||
|
||
let (inputs: felt*) = alloc(); | ||
let inputs_start = inputs; | ||
fill_array(inputs, 9, 3, 0); | ||
|
||
let (state: felt*) = alloc(); | ||
let state_start = state; | ||
fill_array(state, 5, 25, 0); | ||
|
||
let n_bytes = 24; | ||
|
||
let (res: felt*) = _keccak{keccak_ptr=keccak_output}( | ||
inputs=inputs_start, n_bytes=n_bytes, state=state_start | ||
); | ||
|
||
return (); | ||
} |
20 changes: 20 additions & 0 deletions
20
...ion_tests/cairo_zero_hint_tests_in_progress/keccak_add_uint256.starknet_with_keccak.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,20 @@ | ||
%builtins output range_check bitwise | ||
|
||
from starkware.cairo.common.keccak_utils.keccak_utils import keccak_add_uint256 | ||
from starkware.cairo.common.uint256 import Uint256 | ||
from starkware.cairo.common.cairo_builtins import BitwiseBuiltin | ||
from starkware.cairo.common.alloc import alloc | ||
from starkware.cairo.common.serialize import serialize_word | ||
|
||
func main{output_ptr: felt*, range_check_ptr, bitwise_ptr: BitwiseBuiltin*}() { | ||
alloc_locals; | ||
|
||
let (inputs) = alloc(); | ||
let inputs_start = inputs; | ||
|
||
let num = Uint256(34623634663146736, 598249824422424658356); | ||
|
||
keccak_add_uint256{inputs=inputs_start}(num=num, bigend=0); | ||
|
||
return (); | ||
} |
17 changes: 17 additions & 0 deletions
17
...ration_tests/cairo_zero_hint_tests_in_progress/keccak_uint256s.starknet_with_keccak.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,17 @@ | ||
%builtins range_check bitwise keccak | ||
from starkware.cairo.common.cairo_builtins import KeccakBuiltin, BitwiseBuiltin | ||
from starkware.cairo.common.builtin_keccak.keccak import keccak_uint256s | ||
from starkware.cairo.common.alloc import alloc | ||
from starkware.cairo.common.uint256 import Uint256 | ||
|
||
func main{range_check_ptr, bitwise_ptr: BitwiseBuiltin*, keccak_ptr: KeccakBuiltin*}() { | ||
let elements: Uint256* = alloc(); | ||
assert elements[0] = Uint256(713458135386519, 18359173571); | ||
assert elements[1] = Uint256(1536741637546373185, 84357893467438914); | ||
assert elements[2] = Uint256(2842949328439284983294, 39248298942938492384); | ||
assert elements[3] = Uint256(27518568234293478923754395731931, 981587843715983274); | ||
assert elements[4] = Uint256(326848123647324823482, 93453458349589345); | ||
let (res) = keccak_uint256s(5, elements); | ||
|
||
return (); | ||
} |
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