-
Notifications
You must be signed in to change notification settings - Fork 112
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
BLAKE2b gadget #1767
Open
boray
wants to merge
43
commits into
v2
Choose a base branch
from
feature/blake2b
base: v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+762
−117
Open
BLAKE2b gadget #1767
Changes from 39 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
d357853
add blake2b
boray cb93722
add or gadget and improvements
boray 31abb6e
Merge branch 'feature/blake2b' of github.com:o1-labs/o1js into featur…
boray 2846396
add comments and tests
boray 9dd79aa
fix bitwise test
boray 24c743a
add comments to gadgets
boray 044cbe1
dump vks
boray 81bc5a9
add doccoments and test
boray 58a07a0
add yoni's fix #1763
boray 72877d7
Merge remote-tracking branch 'origin/main' into feature/blake2b
boray 10836c9
add UInt32.or()
boray 00cdb75
Update src/lib/provable/gadgets/bitwise.ts
boray 5db6974
update vk-regression.json
boray 63b939c
fixes and styling
boray e6317f1
remove question marks
boray 95a71d3
Merge remote-tracking branch 'origin/feature/divmod32-quotientbits-bo…
boray 90daf62
optimize g function additions
boray 1938405
hardcode IV as UInt64
boray 5e2b28a
dump vks
boray a86a106
simplify or
boray c38118e
fix formatting
boray 5bba739
fix divMod64 range check
boray e9c5a29
Merge remote-tracking branch 'origin/v2' into feature/blake2b
boray 555070b
fix elliptic curve to match v2
boray d071e7b
fix formatting
boray 9b32c4d
style(gadgets.ts): wrap comments for readability
boray 70169e3
fix(bitwise.unit-test.ts): correct typo
boray acd32bb
perf: optimize divmod rangechecks
boray ec5b6a7
fix: remove incorrect optimization
boray b741027
fix(arithmetic.ts): fix range assertion
boray a34d8c2
docs: clarify output description
boray 6ba2968
fix(blake2b.ts): add range check for digestLength
boray d841a51
fix(blake2b.ts): range check input byte length
boray d999c09
test: add test vector
boray e5bd574
feat: add last block flag and state type
boray 1c5f3bd
fix: counter logic
boray 7f650b1
chore: update reference
boray e545799
docs: add comments
boray 368ae88
docs: add more comments
boray cb80ccf
perf: reduce row number
boray 20a0eac
fix: uint64 construction
boray cceeef5
test: remove in-circuit equivalence tests
boray 4304c0f
test: add in-circuit tests for blake2b
boray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Bytes, Gadgets, ZkProgram } from 'o1js'; | ||
|
||
export { BLAKE2BProgram, Bytes12 }; | ||
|
||
class Bytes12 extends Bytes(12) {} | ||
|
||
let BLAKE2BProgram = ZkProgram({ | ||
name: 'blake2b', | ||
publicOutput: Bytes(32), | ||
methods: { | ||
blake2b: { | ||
privateInputs: [Bytes12], | ||
async method(xs: Bytes12) { | ||
return Gadgets.BLAKE2B.hash(xs, 32); | ||
}, | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Bytes12, BLAKE2BProgram } from './blake2b.js'; | ||
|
||
console.time('compile'); | ||
await BLAKE2BProgram.compile(); | ||
console.timeEnd('compile'); | ||
|
||
let preimage = Bytes12.fromString('hello world!'); | ||
|
||
console.log('blake2b rows:', (await BLAKE2BProgram.analyzeMethods()).blake2b.rows); | ||
|
||
console.time('prove'); | ||
let proof = await BLAKE2BProgram.blake2b(preimage); | ||
console.timeEnd('prove'); | ||
let isValid = await BLAKE2BProgram.verify(proof); | ||
|
||
console.log('digest:', proof.publicOutput.toHex()); | ||
|
||
if ( | ||
proof.publicOutput.toHex() !== | ||
'4fccfb4d98d069558aa93e9565f997d81c33b080364efd586e77a433ddffc5e2' | ||
) | ||
throw new Error('Invalid blake2b digest!'); | ||
if (!isValid) throw new Error('Invalid proof'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is 255 not included because of Pasta curves?
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 am not sure why we don't include 255. I followed the range checking practice used in
divMod32
. Maybe @mitschabaude knows the reason?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.
Because the field size is less than 2^255, there are 255 bit integers that have two different representations in the field (in fact that's true for almost all 255 bit integers since the field size is just slightly over 2^254)
That non-uniqueness would make the divmod gadget unsound: the prover could pick between two different quotient/remainder splits, one of which is wrong.