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(blockifier): add support for keccak syscall #1546

Merged
merged 1 commit into from
Nov 14, 2024

Conversation

varex83
Copy link
Contributor

@varex83 varex83 commented Oct 23, 2024

This PR adds support for keccak syscall for the native syscall handler.

@varex83 varex83 added the native integration Related with the integration of Cairo Native into the Blockifier label Oct 23, 2024
@reviewable-StarkWare
Copy link

This change is Reviewable

Copy link

Artifacts upload triggered. View details here

Copy link

codecov bot commented Oct 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.67%. Comparing base (e3165c4) to head (6479b44).
Report is 387 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #1546       +/-   ##
===========================================
+ Coverage   40.10%   67.67%   +27.56%     
===========================================
  Files          26      103       +77     
  Lines        1895    13827    +11932     
  Branches     1895    13827    +11932     
===========================================
+ Hits          760     9357     +8597     
- Misses       1100     4070     +2970     
- Partials       35      400      +365     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rodrigo-pino rodrigo-pino force-pushed the rdr/update-testing-suite branch 2 times, most recently from c728762 to 4cf52c8 Compare October 24, 2024 11:51
@varex83 varex83 changed the title feat: add support for keccak syscall feat(blockifier): add support for keccak syscall Oct 28, 2024
@varex83 varex83 force-pushed the bohdan/add-keccak-syscall branch from cb606a0 to ada76ce Compare October 28, 2024 10:33
Copy link

Artifacts upload triggered. View details here

@varex83 varex83 marked this pull request as ready for review October 28, 2024 10:42
Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

Copy link

Artifacts upload triggered. View details here

@rodrigo-pino rodrigo-pino force-pushed the rdr/update-testing-suite branch 2 times, most recently from a00994e to e2c9fe8 Compare October 28, 2024 15:36
@PearsonWhite PearsonWhite changed the base branch from rdr/update-testing-suite to rdr/add-syscall-counting October 29, 2024 01:29
Copy link

Artifacts upload triggered. View details here

@rodrigo-pino rodrigo-pino force-pushed the rdr/add-syscall-counting branch 2 times, most recently from 147c1d3 to ded98cf Compare October 29, 2024 14:23
@varex83 varex83 force-pushed the bohdan/add-keccak-syscall branch from a63f4d1 to 59867fc Compare October 29, 2024 16:06
Copy link

Artifacts upload triggered. View details here

Copy link
Contributor

@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.

Reviewed 1 of 3 files at r2, 1 of 2 files at r9, 1 of 1 files at r10.
Reviewable status: 3 of 6 files reviewed, 1 unresolved discussion (waiting on @noaov1 and @varex83)


crates/blockifier/src/execution/native/syscall_handler.rs line 233 at r10 (raw file):

        )?;

        const KECCAK_FULL_RATE_IN_WORDS: usize = 17;

Where did this number come from?

Code quote:

const KECCAK_FULL_RATE_IN_WORDS: usize = 17;

Copy link
Contributor Author

@varex83 varex83 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: 3 of 6 files reviewed, 1 unresolved discussion (waiting on @meship-starkware and @noaov1)


crates/blockifier/src/execution/native/syscall_handler.rs line 233 at r10 (raw file):

Previously, meship-starkware (Meshi Peled) wrote…

Where did this number come from?

The implementation of keccak is fully done by rewriting the original VM implementation, so this const is from here, please take a look here: https://github.com/starkware-libs/sequencer/blob/main/crates/blockifier/src/execution/syscalls/mod.rs#L677

@rodrigo-pino rodrigo-pino force-pushed the rdr/add-syscall-counting branch 5 times, most recently from 6e88aa9 to 55834b2 Compare October 31, 2024 14:45
@rodrigo-pino rodrigo-pino force-pushed the rdr/add-syscall-counting branch from 139d79d to 3d4ab3d Compare November 10, 2024 11:48
@varex83 varex83 changed the base branch from rdr/add-syscall-counting to main November 11, 2024 09:45
@varex83 varex83 force-pushed the bohdan/add-keccak-syscall branch from c9d0ba1 to 721eb95 Compare November 11, 2024 10:06
Copy link

Artifacts upload triggered. View details here

Copy link
Contributor

@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.

Reviewed 5 of 5 files at r12, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @varex83)

Copy link
Contributor

@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.

:lgtm:

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @varex83)

@varex83 varex83 force-pushed the bohdan/add-keccak-syscall branch from 721eb95 to e0191eb Compare November 11, 2024 22:32
Copy link

Artifacts upload triggered. View details here

@varex83 varex83 force-pushed the bohdan/add-keccak-syscall branch from e0191eb to d8cb878 Compare November 11, 2024 22:34
Copy link

Artifacts upload triggered. View details here

Copy link
Contributor

@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.

Reviewed 2 of 2 files at r13, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @varex83)

Copy link
Contributor

@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.

You have some conflicts please rebase

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @varex83)

@varex83 varex83 force-pushed the bohdan/add-keccak-syscall branch from d8cb878 to 6479b44 Compare November 13, 2024 08:43
Copy link

Artifacts upload triggered. View details here

Copy link
Contributor

@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.

Reviewed 2 of 2 files at r14, all commit messages.
Dismissed @graphite-app[bot] from a discussion.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @varex83 and @Yoni-Starkware)

Copy link
Contributor

@rodrigo-pino rodrigo-pino 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 @noaov1, @varex83, and @Yoni-Starkware)


crates/blockifier/src/execution/native/syscall_handler.rs line 226 at r11 (raw file):

Previously, noaov1 (Noa Oved) wrote…

In the CASM syscall implementation, we receive input as a vector of felts. If any of the felts don't fit into a u64, we return an (unprovable) error. I'm curious about how Cairo native would handle this situation (is it even possible?).

 We have no control over it, we would have to ask the Native team for certainty but my guess is that it would throw an overflow error (if it was possible for it to happen at first). Since one of the pros of Sierra is that there is type information present, and if execution was correct until this point (no overflow errors whatsoever) my guess is that those values won't be incorrect.

Copy link
Contributor

@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: all files reviewed, 1 unresolved discussion (waiting on @varex83 and @Yoni-Starkware)

Copy link
Contributor

@avi-starkware avi-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 r13, 2 of 2 files at r14, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ilyalesokhin-starkware and @Yoni-Starkware)

Comment on lines +285 to +291
let mut state = [0u64; 25];
for chunk in input.chunks(KECCAK_FULL_RATE_IN_WORDS) {
for (i, val) in chunk.iter().enumerate() {
state[i] ^= val;
}
keccak::f1600(&mut state)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@ilyalesokhin-starkware
Is this comment correct?

Copy link
Contributor

@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: all files reviewed, 1 unresolved discussion (waiting on @ilyalesokhin-starkware 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.

:lgtm:

Reviewed 1 of 2 files at r13, 2 of 2 files at r14, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @ilyalesokhin-starkware)

Comment on lines +285 to +291
let mut state = [0u64; 25];
for chunk in input.chunks(KECCAK_FULL_RATE_IN_WORDS) {
for (i, val) in chunk.iter().enumerate() {
state[i] ^= val;
}
keccak::f1600(&mut state)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The syscall computes a keccak round; the caller is responsible for the padding.

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: :shipit: complete! all files reviewed, all discussions resolved (waiting on @varex83)

Comment on lines +285 to +291
let mut state = [0u64; 25];
for chunk in input.chunks(KECCAK_FULL_RATE_IN_WORDS) {
for (i, val) in chunk.iter().enumerate() {
state[i] ^= val;
}
keccak::f1600(&mut state)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@starkware-libs starkware-libs deleted a comment from graphite-app bot Nov 14, 2024
@Yoni-Starkware Yoni-Starkware merged commit 5f70eab into main Nov 14, 2024
11 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 16, 2024
@meship-starkware meship-starkware deleted the bohdan/add-keccak-syscall branch November 19, 2024 08:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
native integration Related with the integration of Cairo Native into the Blockifier
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants