Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Keccak Challenge-API integration #925

Merged
merged 13 commits into from
Nov 30, 2022
Merged

Keccak Challenge-API integration #925

merged 13 commits into from
Nov 30, 2022

Conversation

CPerezz
Copy link
Member

@CPerezz CPerezz commented Nov 23, 2022

This introduces the challenge API inclusion into the all three different Keccak circuit implementations. Resolves: #751
This introduces 2 different challenges. One for the inputs and another for the table-exposed value.

The changes consists on:
1- Swap the meta.advice_column for meta.advice_column_in(SecondPhase).
2- Replace the randomnes, which is hardcoded now in the circuit by the Challenges.
Including it in the configure and witness_generation functions.
3- Test with a custom Challenges which has a fixed value.

From this work, two main issues/tech-debt derive.

  1. I made an effort to migrate Part<F> and PartValue<F> to use the
    Value<F> halo2 API. But since the struct doesn't implement PartialEq
    it's challenging to do it. As I do need to operate with it quite a lot.

Also, there's another caveat which is that it feels really tricky to
extract the byte representation from a Value<F>. It feels like if
you're cheating to the API constrantly (using .map() to gain access to
the underlying F so that you can do extra things with it such as
decompose it into bytes).

For these reasons, right now extract_field was added. An issue will be
filled to track the tech-debt left here and pay it once we maybe we add
the required functionalities to halo2::Value<F>.

  1. The SuperCircuit is using now the slowest and worst performant of the 3 keccak implementations. So I ported the three so that we can run benchmarks for them with the SuperCircuit which will help to decide which one we keep and which ones we remove to reduce code manteinance.
    After a discussion with @Brechtpd on this topic, we both agreed that multi-packed approach should be the one to keep. But I think is worth a benchmark before we take that path removing the two other implementations from the repo.

Tech-debt issues generated from this PR:

@github-actions github-actions bot added the crate-zkevm-circuits Issues related to the zkevm-circuits workspace member label Nov 23, 2022
@CPerezz CPerezz mentioned this pull request Nov 23, 2022
@github-actions
Copy link

👋 Comment on this pull request with /test to trigger the integration tests.

Currently, halo2 prevents the user from adding `Advice<PhaseN>` columns
if no column of the previous phase was defined before.

Since the first thing we need are the `Challenges` and these are placed
with `Phase2` we no longer can compile the code.
Therefore, a dummy column is added so that halo2 does not complain.
This should be solved in the future if the challenge API polishes this.
This introduces the challenge API inclusion into the Keccak Bit
implementation.
This carries 2 different challenges. one for the inputs and another for
the table-exposed value.

The changes consists on:
1- Swap the meta.advice_column for meta.advice_column_in(SecondPhase).
2- Replace the randomnes hardcoded now in the circuit by the Challenges.
Including it in the configure and witness_generation functions.
3- Test with a custom Challenges which has a fixed value.
I made an effort to migrate `Part<F>` and `PartValue<F>` to use the
`Value<F>` halo2 API. But since the struct doesn't implement `PartialEq`
it's challenging to do it. As I do need to operate with it quite a lot.

Also, there's another caveat which is that it feels really tricky to
extract the byte representation from a `Value<F>`. It feels like if
you're cheating to the API constrantly (using `.map()` to gain access to
the underlying F so that you can do extra things with it such as
decompose it into bytes).

For these reasons, right now `extract_field` was added. An issue will be
filled to track the tech-debt left here and pay it once we maybe we add
the required functionalities to `halo2::Value<F>`.
Now that all the three keccak implementations use the challenge API,
it's time to update the SuperCircuit to adapt to these new APIs.
@CPerezz CPerezz marked this pull request as ready for review November 28, 2022 13:36
@CPerezz CPerezz marked this pull request as draft November 28, 2022 13:38
@CPerezz CPerezz marked this pull request as ready for review November 28, 2022 17:00
@CPerezz CPerezz changed the title [WIP] Keccak Challenge-API integration Keccak Challenge-API integration Nov 28, 2022
@github-actions github-actions bot added crate-circuit-benchmarks Issues related to the circuit-benchmarks workspace member T-bench Type: benchmark improvements labels Nov 28, 2022
Copy link
Collaborator

@han0110 han0110 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice work! Only left some minor comments.

Comment on lines +190 to +194
let mut value_f = F::zero();
value.map(|f| {
value_f = f;
f
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could reuse extract_field?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix this in #948

zkevm-circuits/src/util.rs Show resolved Hide resolved
@CPerezz CPerezz merged commit 88e2a52 into main Nov 30, 2022
@CPerezz CPerezz deleted the keccak_challenge_api branch November 30, 2022 11:36
CPerezz added a commit that referenced this pull request Nov 30, 2022
CPerezz added a commit that referenced this pull request Nov 30, 2022
CPerezz added a commit that referenced this pull request Dec 1, 2022
* feat: Integrate KeccakPackedMulti with Challenge-API

* fix: Clippy lints

* fix: Pay #925 tech debt

* remove: Keccak packed implementation

* remove: Keccak-bit implementation

* change: Export KeccakPackedConfig as KeccakConfig

* remove: Benchmarks of discarted keccak impls
jonathanpwang pushed a commit to jonathanpwang/zkevm-circuits that referenced this pull request Dec 29, 2022
* remove: Unnedeed TODO

* Change: Port Keccak table from F to Value

* Fix: Add dummy advice colum to prevent Phase error

Currently, halo2 prevents the user from adding `Advice<PhaseN>` columns
if no column of the previous phase was defined before.

Since the first thing we need are the `Challenges` and these are placed
with `Phase2` we no longer can compile the code.
Therefore, a dummy column is added so that halo2 does not complain.
This should be solved in the future if the challenge API polishes this.

* feat: Port KeccakBit impl to challenge API

This introduces the challenge API inclusion into the Keccak Bit
implementation.
This carries 2 different challenges. one for the inputs and another for
the table-exposed value.

The changes consists on:
1- Swap the meta.advice_column for meta.advice_column_in(SecondPhase).
2- Replace the randomnes hardcoded now in the circuit by the Challenges.
Including it in the configure and witness_generation functions.
3- Test with a custom Challenges which has a fixed value.

* feat: Integrate KeccakPackedMulti with Challenge-API

* feat: Migrate keccak-packed circuit to Challenge-API

* fix: Add `extract_field` to utils

I made an effort to migrate `Part<F>` and `PartValue<F>` to use the
`Value<F>` halo2 API. But since the struct doesn't implement `PartialEq`
it's challenging to do it. As I do need to operate with it quite a lot.

Also, there's another caveat which is that it feels really tricky to
extract the byte representation from a `Value<F>`. It feels like if
you're cheating to the API constrantly (using `.map()` to gain access to
the underlying F so that you can do extra things with it such as
decompose it into bytes).

For these reasons, right now `extract_field` was added. An issue will be
filled to track the tech-debt left here and pay it once we maybe we add
the required functionalities to `halo2::Value<F>`.

* update: Adapt SuperCircuit to new keccak APIs

Now that all the three keccak implementations use the challenge API,
it's time to update the SuperCircuit to adapt to these new APIs.

* fix: Clippy lints

* fix: Update benchmarks and set hardcoded input length

* chore: Conditionally add an empty column before Challenge generation in tests
jonathanpwang pushed a commit to jonathanpwang/zkevm-circuits that referenced this pull request Dec 29, 2022
…ns#948)

* feat: Integrate KeccakPackedMulti with Challenge-API

* fix: Clippy lints

* fix: Pay privacy-scaling-explorations#925 tech debt

* remove: Keccak packed implementation

* remove: Keccak-bit implementation

* change: Export KeccakPackedConfig as KeccakConfig

* remove: Benchmarks of discarted keccak impls
CPerezz added a commit that referenced this pull request Jan 2, 2023
Once Keccak was migrated to the Challenge API in #925, there was a column
containing `data_rlcs` which was getting stored values that were the
result of an RLC.

Therefore, this swaps the `data_rlcs` colum Phase to `SecondPhase`.

Resolves: #1016
CPerezz added a commit that referenced this pull request Jan 2, 2023
Once Keccak was migrated to the Challenge API in #925, there was a column
containing `data_rlcs` which was getting stored values that were the
result of an RLC.

Therefore, this swaps the `data_rlcs` colum Phase to `SecondPhase`.

Resolves: #1016
GopherJ pushed a commit to dompute/zkevm-circuits that referenced this pull request Sep 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
crate-circuit-benchmarks Issues related to the circuit-benchmarks workspace member crate-zkevm-circuits Issues related to the zkevm-circuits workspace member T-bench Type: benchmark improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor Keccak circuit with challenge API
2 participants