-
Notifications
You must be signed in to change notification settings - Fork 321
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: add blake2b compression precompile #321
Conversation
Signed-off-by: 0xKanekiKen <100861945+0xKanekiKen@users.noreply.github.com>
Signed-off-by: 0xKanekiKen <100861945+0xKanekiKen@users.noreply.github.com>
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
@0xkanekiken - I see that your PR is modeled off of the Blake3 precompile. I recently fixed a bug in that precompile which I believe also affects this PR. |
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
@kevjue- thank you. I had the same question when I was taking a look at the constraints of blake3. However, I noticed that the sp1/core/src/syscall/precompiles/blake3/compress/trace.rs Lines 108 to 116 in 4cf6377
I attempted to incorporate the fix you introduced, but I am still encountering the |
@0xkanekiken - Ya, the fix PR removed the need for setting Regarding the You can try adding this function ( Line 112 in 0494105
Line 200 in 0494105
I actually suspect that all your constraints in your blake2b air related to the blake logic are fine. You normally encounter the |
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
96edae5
to
54a416e
Compare
Thank you for all the guidance and support! Indeed, the problem stemmed from how I defined the memory access AIR constraints. I've addressed this issue in 54a416e. Consequently, the tests are passing, and I'm able to generate the proof. It's ready for a review now. |
Thanks for the PR @0xkanekiken ! In general, it looks great! But we'll take a closer look at it soon. |
} | ||
|
||
// The expected output state is the result of compress_inner. | ||
let output_state: [u8; 128] = [ |
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.
would it be possible to import a pure rust implementation of blake2b in this program and then get the output_state
from calling that so that we have a ground truth reference for the code?
impl Blake2bCompressInnerChip { | ||
/// Constrains the given index is correct for the given selector. The `selector` is an | ||
/// `n`-dimensional boolean array whose `i`-th element is true if and only if the index is `i`. | ||
fn constrain_index_selector<AB: SP1AirBuilder>( |
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.
do we not already have a generic thing of doing this? this seems like a really good utility to have in airbuilder in general tbh, so maybe we should move it to a move general crate with all the existing air builder methods
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.
should I address this issue in the current PR, or should it be handled in a separate PR by creating an issue?
02bbcb0
to
dae5554
Compare
Signed-off-by: 0xkanekiken <100861945+0xKanekiKen@users.noreply.github.com>
dae5554
to
393a7f7
Compare
At some point, we should merge a PR like this for the blake2b precompile if there is further demand, but for now it's not high priority and this PR is quite out of date so closing for now. |
The implementation is based on reference #180 and partially addresses issue #231. In the Blake2b hash function, the state and message elements are represented as
u64
values, whereas the sp1 standard supportsu32
words. As a result, eachu64
is implemented using twou32
limbs, with appropriate handling for this format.Furthermore, two operations for
u64
data types have been introduced:u64
.u64
.The XOR operation for
u64
can be derived from the XOR operations of individualu32
limbs.To-Do: