-
Notifications
You must be signed in to change notification settings - Fork 857
[word lo/hi] pi circuit replace rand/rlc by keccak hash #1345
[word lo/hi] pi circuit replace rand/rlc by keccak hash #1345
Conversation
0f15455
to
4d9acf0
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.
First pass review. I think that there are many subtleties in this design, I would appreciate having a python implementation of the design to analyze it better before continuing the Rust implementation.
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.
First round reviwe, I also agree with Edu that we should use little endian for all values, which might make life easier (considering we'd need to write solidity to handle the decomposition).
b9efdb6
to
71d0e02
Compare
Updated: combined together with word-lo-hi to address #1383 so we can review together. Unitttest under pi circuit is all pass |
1f41365
to
4c53744
Compare
lookup constraints pi circuit block table assignment pi circuit tx table assignment new way to get public input circuit assignment ready pi circuit pass compile fix cell un-assignment error format code and bug fix fixed copy constraints error fix existing error during unittest code cosmetics fix error due to challenge usage fix lints and code cosmetics pi circuit more test with real block data super circuit keccak dev_load rewrite gate to clearly the branch rewrite circuit in bottom up style and fix all constriants refactor timing for pi circuit keccak table load nonce/gas_limit to u64 code cosmetics increase keccak row to cover new pi input circuit skip signdata generation on non pi circuit test set max keccak row 35000 to cover new pi input circuit fix pi bytes endian in witness block fix fmt migrate to word lo/hi
Updated: rebase onto the latest word-lo-hi and resolved conflict |
pub chain_id: Word, | ||
/// History hashes contains the most recent 256 block hashes in history, | ||
/// where the latest one is at history_hashes[history_hashes.len() - 1]. | ||
pub history_hashes: Vec<Word>, |
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.
Since this will be constant, is not better to express it as [Word;256]
?
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.
There are other places use Vec on history_hashes therefore I think we can keep it the same. Change all of them is a bit out-of-scope and can be separate task 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.
I forget to attach the link to show many other place still use history_hashes as Vec
:)
https://github.com/search?q=repo%3Aprivacy-scaling-explorations%2Fzkevm-circuits%20history_hashes%3A%20Vec%3CWord%3E%2C&type=code
let result = iter::empty() | ||
.chain(0u8.to_be_bytes()) // zero byte | ||
.chain(block_values.coinbase.to_fixed_bytes()) // coinbase | ||
.chain(block_values.gas_limit.to_be_bytes()) // gas_limit |
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.
Spec says big endian?
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 be little endian
in specs)
Its a good catch! in specs byte is attaching in little endian, but there is an reverse during assignment to make coding easier. But in Rust, efficient is more important, so the endian in bytes is keep in big endian in first place.
I submit a pr to align specs pi circuit endian privacy-scaling-explorations/zkevm-specs#438
|
||
// Assign extra fields | ||
let extra_vals = self.get_extra_values(); | ||
let result = result |
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 see in the specs that block hash is also added
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.
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 was quite a big change, thanks a lot for the work!!
Everything is in line with the spec so once @adria0 comments are addressed LGTM 👍
.map(|x| x.to_vec()) | ||
.collect(); | ||
|
||
*current_offset = value_bytes_chunk.iter().try_fold( |
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'm wondering if possible to rewrite it using for
loops, I think that will help the code reader a lot
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.
My option is use functional programming style is more self-explanation than forloop imperative style. With forloop, more intermediate variable need to be allocated. And reader need to be more attention for what each variable meaning. I think try_fold
and folding/refreshing on rpi_value_lc make thing clear. So I tend to be keep current style.
(I tried few variants, still think try_fold
is better)
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.
In general, I'm more in the imperative side, mainly because I never wrote a big project in functional, so I do not have the "functional architecture mindset".
Overall, LGTM 👍 |
All review comment are addressed! thanks for all review and will merge it now |
Description
replace rand/rlc by pure keccak hashing
Issue Link
Type of change
Contents
hi
, and digest[16:32] aslo
, whiledigest = Keccak(<public data>)
nitpick
Rationale
[design decisions and extended information]
How Has This Been Tested?
[explanation]