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

Starknet Keccak #57

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Conversation

marioiordanov
Copy link

@marioiordanov marioiordanov commented May 3, 2023

The PR includes:

Implementation of starknet_keccak hash function


This change is Reviewable

@marioiordanov marioiordanov mentioned this pull request May 3, 2023
Copy link
Collaborator

@yair-starkware yair-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @marioiordanov)


src/hash.rs line 58 at r1 (raw file):

    let mut res_bytes: [u8; 32] = [0; 32];
    masked_number.to_big_endian(&mut res_bytes);
    StarkFelt::new(res_bytes).expect("error when converting to StarkFelt")

Return a Result instead of expecting


src/hash_test.rs line 75 at r1 (raw file):

#[test]
fn starknet_keccak_mask() {
    let mask: U256 = U256::pow(U256::from(2), U256::from(250)) - U256::from(1);

Is it possible to calculate this in the const itself? (not blocking)

Code quote:

let mask: U256 = U256::pow(U256::from(2), U256::from(250)) - U256::from(1);

src/hash_test.rs line 86 at r1 (raw file):

    let expected_keccak_felt =
        stark_felt!("0x362398bec32bc0ebb411203221a35a0301193a96f317ebe5e40be9f60d15320");
    let increase_balance_keccak_felt = crate::hash::starknet_keccak("increase_balance".as_bytes());

Replace the full path by importing the function

Code quote:

crate::

Copy link
Author

@marioiordanov marioiordanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 3 files reviewed, 2 unresolved discussions (waiting on @yair-starkware)


src/hash.rs line 58 at r1 (raw file):

Previously, yair-starkware (Yair) wrote…

Return a Result instead of expecting

Done.


src/hash_test.rs line 75 at r1 (raw file):

Previously, yair-starkware (Yair) wrote…

Is it possible to calculate this in the const itself? (not blocking)

No, because it gives a compilation error: he trait Sub<_> is implemented for U256, but that implementation is not const

Copy link
Collaborator

@yair-starkware yair-starkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 2 files at r2.
Reviewable status: 2 of 3 files reviewed, 1 unresolved discussion (waiting on @marioiordanov)


src/hash.rs line 24 at r2 (raw file):

const CHOOSER_FULL: u8 = 15;
const CHOOSER_HALF: u8 = 14;
/// the MASK equals to U256::pow(U256::from(2), U256::from(250)) - U256::from(1)

The

Code quote:

the

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants