This repository was archived by the owner on May 3, 2024. It is now read-only.
forked from privacy-ethereum/zkevm-circuits
-
Notifications
You must be signed in to change notification settings - Fork 122
blake2f precompile #51
Copy link
Copy link
Open
Labels
Description
Checklist:
- Can do multiple blake2f hash calculations in a single circuit
- For each of those blake2f hash calculations, can do any number of rounds
- Easy to change the layout (number of columns) so different work loads can be handled
- Possible to do 5M rounds in a circuit with height <= 2**25
- Doc explaining how the circuit works on a high level
- Challenge API integration
- There's a blake2f table struct similar to this one for keccak: https://github.com/privacy-scaling-explorations/zkevm-circuits/blob/bfbedfd1f579fdcee75679773e526b18eefcf10a/zkevm-circuits/src/table.rs#L865. This it the API that will be used by external circuits to lookup blake2f hashes in e.g. for keccak other circuits simple lookup the hash of some input data like this: (1, input_rlc, num_bytes, hash). The format for blake2 will probably be a bit different because of how the blake2f precompile works, perhaps something like this
is_enabled
column: Set to 1 only for rows that contain valid hash for the data in the column below, otherwise needs to be set to 0 (so no garbage data can be lookup up). In other wordsis_enabled
is set to1
once per blake2f once all data has been verified and the hash is calculated.num_rounds
column: the number of rounds that produced the blake2f hashstate_rlc
column: the rlc of the state vector datamessage_rlc
column: the rlc of all the input bytes used in the hashoffset_counter_0',
offset_counter_1' columns: the offset countersf
column: final block indicatorlo_hash
column : the lowest 128 bits of the blake2 hashhi_hash
column : the highest 128 bits of the blake2 hash
Description:
- https://eips.ethereum.org/EIPS/eip-152
- https://www.rfc-editor.org/rfc/rfc7693#section-3.2
- https://en.wikipedia.org/wiki/BLAKE_(hash_function)
- https://www.evm.codes/precompiled
Implementation probably similar to sha256, so a good idea to first look at that implementation and use it as a base: privacy-ethereum#756
Presentation: https://docs.google.com/presentation/d/1eHVzLPRIEziCJ_oDuJG0yZ-5klNj_daqioC0UaGDaiw/edit#slide=id.p