-
Notifications
You must be signed in to change notification settings - Fork 4
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: Blake2s round precompile #176
base: dev
Are you sure you want to change the base?
Conversation
2481b2d
to
ce4b853
Compare
ce4b853
to
b4c74f8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good at first glance! I'll come back to this.
Cargo.toml
Outdated
@@ -78,7 +78,7 @@ getrandom = "=0.2.14" # 0.2.15 depends on yanked libc 0.2.154 | |||
hashbrown = { version = "0.14.5", features = ["serde"] } | |||
hex = "0.4.3" | |||
home = "0.5.9" | |||
hybrid-array = "0.2.0-rc" | |||
hybrid-array = "0.2.0-rc.9" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the resolution to 0.2.0-rc.9 should be automatic without this change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference: https://github.com/argumentcomputer/zk-light-clients/pull/241>
The hybrid-array
dependency has been recently updated to 0.2.0-rc.10 version which breaks compiling the sphinx programs (also see this broken CI job). My attempt was to hardcode version to 0.2.0-rc.9 (which allows successful compiling of sphinx programs) - but it actually still doesn't help - we need either downgrade version manually:
cargo update hybrid-array@0.2.0-rc.10 --precise 0.2.0-rc.9
or, as @wwared suggested - reinstall the whole toolchain from scratch.
Anyway, you are right, we can leave it as is.
core/src/utils/prove.rs
Outdated
let record_clone = record.clone(); | ||
machine.debug_constraints(pk, record_clone); | ||
} | ||
//#[cfg(debug_assertions)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: remove before merge.
FYI, we have a cargo-profile called dev-ci, which will be as efficient to run as --release
, but has debug assertions!
); | ||
} | ||
|
||
self.constrain_shuffled_indices(builder, &local.shuffled_indices, local.is_real); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like local.shuffled_indices
is only used here, and this is just enforcing that the first 4 elements are 0 while the rest are 1.
I believe you can remove the shuffled_indices
column and its related constraints without any impact. The shuffling is still properly constrained by the constant values of the vX_shuffle_lookup
vectors offsetting the memory reads.
zkvm/precompiles/src/lib.rs
Outdated
pub fn syscall_blake2s_add_2(left: *mut u32, right: *const u32); | ||
pub fn syscall_blake2s_add_3(left: *mut u32, right: *const u32); | ||
pub fn syscall_blake2s_xor_rotate_right_16(left: *mut u32, right: *const u32); | ||
pub fn syscall_blake2s_xor_rotate_right_12(left: *mut u32, right: *const u32); | ||
pub fn syscall_blake2s_xor_rotate_right_8(left: *mut u32, right: *const u32); | ||
pub fn syscall_blake2s_xor_rotate_right_7(left: *mut u32, right: *const u32); | ||
pub fn syscall_blake2s_quarter_round(left: *mut u32, right: *const u32); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe these can be removed since they are no longer being used/defined
core/src/stark/air.rs
Outdated
let blake_2s_round = Blake2sRoundChip::new(); | ||
chips.push(RiscvAir::Blake2sRound(blake_2s_round)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be moved up to after bls12381_g1_decompress
above I believe
61fa060
to
4bcefbd
Compare
4bcefbd
to
430087a
Compare
This PR implements gadget and syscall for Blake2s round function.
The integrated code that allows using this syscall in external sphinx programs is located in zkvm branch of RustCrypto.
The following is a comparison of single Blake2s hashing inside Sphinx program without / with precompile:
TODO: