Skip to content

Conversation

meship-starkware
Copy link
Collaborator

No description provided.

@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link
Collaborator Author

meship-starkware commented Sep 30, 2025

@meship-starkware meship-starkware marked this pull request as ready for review September 30, 2025 11:18
Copy link
Collaborator Author

@meship-starkware meship-starkware 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: 0 of 1 files reviewed, 2 unresolved discussions (waiting on @liorgold2 and @Yoni-Starkware)


crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/naive_blake.cairo line 25 at r1 (raw file):

    const MESSAGE_SHIFT = 2 ** 32;
    const FLAGS_SHIFT = 2 ** 48;
    const OPCODE_EXT_SHIFT = 2 ** 63;

Not sure if these are needed, we can just write the numbers in the final constant, just added them to be consistent with the type rs implementation

Code quote:

    const COUNTER_SHIFT = 1;
    const STATE_SHIFT = 2 ** 16;
    const MESSAGE_SHIFT = 2 ** 32;
    const FLAGS_SHIFT = 2 ** 48;
    const OPCODE_EXT_SHIFT = 2 ** 63;

crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/naive_blake.cairo line 29 at r1 (raw file):

    const POS_STATE_OFFSET = 2 ** 15 + STATE_OFFSET;
    const POS_MESSAGE_OFFSET = 2 ** 15 + MESSAGE_OFFSET;
    const POS_COUNTER_OFFSET = 2 ** 15 + COUNTER_OFFSET;

Added this content because the format fix did not handle the parentheses well in the BLAKE2S_FINALIZE_INSTRUCTION constant

Code quote:

    const POS_STATE_OFFSET = 2 ** 15 + STATE_OFFSET;
    const POS_MESSAGE_OFFSET = 2 ** 15 + MESSAGE_OFFSET;
    const POS_COUNTER_OFFSET = 2 ** 15 + COUNTER_OFFSET;

Copy link
Contributor

@liorgold2 liorgold2 left a comment

Choose a reason for hiding this comment

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

@liorgold2 reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: all files reviewed, 3 unresolved discussions (waiting on @meship-starkware and @Yoni-Starkware)


crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/naive_blake.cairo line 25 at r1 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

Not sure if these are needed, we can just write the numbers in the final constant, just added them to be consistent with the type rs implementation

Good idea, let's remove these constants.


crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/naive_blake.cairo line 29 at r1 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

Added this content because the format fix did not handle the parentheses well in the BLAKE2S_FINALIZE_INSTRUCTION constant

Ok.


crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/naive_blake.cairo line 14 at r1 (raw file):

    // - State and data are referenced from fp
    // - Counter is referenced from ap
    // - Increment ap by 1 after instruction

Suggestion:

    // Flags: 000100000001010.
    // - State and data are referenced from fp.
    // - Counter is referenced from ap.
    // - Increment ap by 1 after the instruction.

Copy link
Contributor

@liorgold2 liorgold2 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: all files reviewed, 3 unresolved discussions (waiting on @meship-starkware and @Yoni-Starkware)


crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/naive_blake.cairo line 14 at r1 (raw file):

    // - State and data are referenced from fp
    // - Counter is referenced from ap
    // - Increment ap by 1 after instruction

Actually, you can comment on the flags:

    const OP0_REG = 1;  // State is fp-based.
    const OP1_FP = 3;  // Data is fp-based.
    const AP_ADD1 = 11;  // Increment ap by 1 after the instruction.

@meship-starkware meship-starkware force-pushed the meship/fix_blake_opcode_class_in_naive_blake branch from 909d42a to 968f1aa Compare September 30, 2025 13:55
Copy link
Collaborator Author

@meship-starkware meship-starkware 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: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @liorgold2 and @Yoni-Starkware)


crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/naive_blake.cairo line 14 at r1 (raw file):

Previously, liorgold2 wrote…

Actually, you can comment on the flags:

    const OP0_REG = 1;  // State is fp-based.
    const OP1_FP = 3;  // Data is fp-based.
    const AP_ADD1 = 11;  // Increment ap by 1 after the instruction.

Done.

Copy link
Contributor

@liorgold2 liorgold2 left a comment

Choose a reason for hiding this comment

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

@liorgold2 reviewed 2 of 2 files at r2, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @meship-starkware and @Yoni-Starkware)


crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/naive_blake.cairo line 14 at r1 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

Done.

See second reply - move comments to the constants.

Copy link
Collaborator

@Yoni-Starkware Yoni-Starkware 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: all files reviewed, 2 unresolved discussions (waiting on @meship-starkware)


crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/naive_blake.cairo line 6 at r2 (raw file):

// Computes blake2s of `input` of size 16 felts, representing 32 bits each.
// The initial state is the standard BLAKE2s IV XORed with the parameter block P[0] = 0x01010020.
func blake_with_opcode_for_single_16_length_word(data: felt*, out: felt*, initial_state: felt*) {

@meship-starkware I wonder if adding noise to this function (+-1 to one of the consts and removing the static asserts) makes some tests fail. In particular, some consistency test with Rust.

@meship-starkware meship-starkware force-pushed the meship/fix_blake_opcode_class_in_naive_blake branch from 968f1aa to d70591c Compare October 5, 2025 06:19
Copy link
Collaborator Author

@meship-starkware meship-starkware 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 2 files reviewed, 2 unresolved discussions (waiting on @liorgold2)


crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/naive_blake.cairo line 14 at r1 (raw file):

Previously, liorgold2 wrote…

See second reply - move comments to the constants.

Done.

Copy link
Collaborator Author

@meship-starkware meship-starkware 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 2 files reviewed, 2 unresolved discussions (waiting on @liorgold2 and @Yoni-Starkware)


crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/naive_blake.cairo line 6 at r2 (raw file):

Previously, Yoni-Starkware (Yoni) wrote…

@meship-starkware I wonder if adding noise to this function (+-1 to one of the consts and removing the static asserts) makes some tests fail. In particular, some consistency test with Rust.

Changing one of the constants would fail the test that checks the encryption, as the Blake opcode will return something else. Removing the static asserts won't fail anything, but can we make a test that will fail if someone removes the static assert? If someone removes the static assert, it will change the order of the function arguments; the Blake opcode would fail as well, it would just be a bit harder to understand the failure reason

Copy link
Collaborator Author

@meship-starkware meship-starkware left a comment

Choose a reason for hiding this comment

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

@ArniStarkware This Solve the merge conflict with main

Reviewable status: 1 of 2 files reviewed, 2 unresolved discussions (waiting on @liorgold2 and @Yoni-Starkware)

Copy link
Collaborator

@Yoni-Starkware Yoni-Starkware 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 2 files reviewed, 2 unresolved discussions (waiting on @liorgold2 and @meship-starkware)


crates/apollo_starknet_os_program/src/cairo/starkware/starknet/core/os/naive_blake.cairo line 6 at r2 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

Changing one of the constants would fail the test that checks the encryption, as the Blake opcode will return something else. Removing the static asserts won't fail anything, but can we make a test that will fail if someone removes the static assert? If someone removes the static assert, it will change the order of the function arguments; the Blake opcode would fail as well, it would just be a bit harder to understand the failure reason

Static asserts are sanity check. I told you to remove them because I didn't want them to catch your noise.
What about AP_ADD1?

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.

4 participants