Skip to content
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

[keccak] Reduce Advice column usage in permutation circuit #501

Merged
merged 4 commits into from
May 16, 2022

Conversation

CPerezz
Copy link
Member

@CPerezz CPerezz commented May 9, 2022

Advice columns collapsing

StateBaseConversion - BaseConversion

We were previosly using 25 BaseConversionConfigs inside of a single
StateBaseConversion config.
Indeed, we can reach the same result and have 25 different regions for
each BaseConversionConfig without the need to have 25 different
instanciations.

This is important since each one of them adds 6 Advice columns and 2
Selector columns.

The after and before sum of columns for the permutation circuits shows a
decent reduction of almost a half of the columns in usage.

Before results for test_state_base_conversion:

Num advice columns: 151
Num fixed columns: 53
Num instance columns: 0
Num lookups: 25
Num gates: 50
num polys: 50
max_degree_poly: 3 - 
max_degree_lookup_input: 3 - lookup input 'Lookup i/o_coeff at Base conversion table'
max_degree_lookup: 1 - lookup table 'Lookup i/o_coeff at Base conversion table'

After results for test_state_base_conversion:

Num advice columns: 32
Num fixed columns: 5
Num instance columns: 0
Num lookups: 1
Num gates: 2
num polys: 2
max_degree_poly: 3 - 
max_degree_lookup_input: 3 - lookup input 'Lookup i/o_coeff at Base conversion table'
max_degree_lookup: 1 - lookup table 'Lookup i/o_coeff at Base conversion table'

Rho - LaneRotateConversionConfig

As a consequence of f507d16 and continuing the work on #489 this reduces
the RhoConfig to use a simple LaneRotateConversionConfig which gets
assigned 25 times witnesses generating 25 different Regions instead of
duplicating columns over and over.

This is important since each one of them adds 5 Advice columns, 2
Fixed columns and 2 Selector columns.

Before results for test_rho_gate:

Num advice columns: 156
Num fixed columns: 135
Num instance columns: 0
Num lookups: 52
Num gates: 52
num polys: 77
max_degree_poly: 3 - delta_acc === - coef * power_of_base
max_degree_lookup_input: 2 - lookup input 'b13 -> b9 table'
max_degree_lookup: 1 - lookup table 'b13 -> b9 table'

After results for test_rho_gate:

Num advice columns: 36
Num fixed columns: 15
Num instance columns: 0
Num lookups: 4
Num gates: 4
num polys: 5
max_degree_poly: 3 - delta_acc === - coef * power_of_base
max_degree_lookup_input: 2 - lookup input 'b13 -> b9 table'
max_degree_lookup: 1 - lookup table 'b13 -> b9 table'

@github-actions github-actions bot added the crate-keccak Issues related to the keccak workspace member label May 9, 2022
@CPerezz CPerezz changed the title [WIP] Optimize keccak permutation circuit [keccak] Reduce Advice column usage in permutation circuit May 11, 2022
@CPerezz CPerezz marked this pull request as ready for review May 11, 2022 13:32
@CPerezz CPerezz requested a review from a team as a code owner May 11, 2022 13:32
@CPerezz CPerezz requested review from ed255 and ChihChengLiang and removed request for a team May 11, 2022 13:32
Copy link
Collaborator

@ChihChengLiang ChihChengLiang left a comment

Choose a reason for hiding this comment

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

LGTM, Great improvement! Now we have much fewer columns overheads.
Added some nitpicks.

keccak256/src/permutation/rho.rs Show resolved Hide resolved
keccak256/src/permutation/rho.rs Show resolved Hide resolved
@@ -138,18 +136,9 @@ pub struct LaneRotateConversionConfig<F> {
impl<F: Field> LaneRotateConversionConfig<F> {
pub fn configure(
meta: &mut ConstraintSystem<F>,
lane_idx: usize,
lane: Column<Advice>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can still keep this lane and enable the copy for it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure I do follow. They'll be unused inside. So I thought the best was to enable it in the top level Config that instanciates LaneRotateConversionConfig.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Enabling it in the top-level Config sounds good.

keccak256/src/permutation/rho_checks.rs Show resolved Hide resolved
keccak256/src/permutation/rho_checks.rs Show resolved Hide resolved
keccak256/src/permutation/state_conversion.rs Outdated Show resolved Hide resolved
We were previosly using 25 `BaseConversionConfig`s inside of a single
`StateBaseConversion` config.
Indeed, we can reach the same result and have 25 different regions for
each BaseConversionConfig without the need to have 25 different
instanciations.

This is important since each one of them adds 6 Advice columns and 2
Selector columns.

The after and before sum of columns for the permutation circuits shows a
decent reduction of almost a half of the columns in usage.
Currently, we were generating 25 `LaneRotateConversionConfig`s inside of
`RhoConfig`.
The only way to prevent this behaviour passes by first refactoring
`LaneRotateConversionConfig` so that it doesn't require `lane` and
`lane_idx` in order to call `configure` and generate `rotation`.

Therefore, the generation of `rotation` has been passed to the witness
assignation step. And also, lane is now not required anymore.

This allows to have 25 regions assigned for the config instead of 25
configs with 1 `Region` each.
As a consequence of f507d16 and continuing the work on #489 this reduces
the `RhoConfig` to use a simple `LaneRotateConversionConfig` which gets
assigned 25 times witnesses generating 25 different `Region`s instead of
duplicating columns over and over.

This is important since each one of them adds 5 `Advice` columns, 2
`Fixed` columns and 2 Selector columns.
@CPerezz CPerezz added the benchmarks: Keccak Triggers a Keccak round benchmark label May 16, 2022
@CPerezz
Copy link
Member Author

CPerezz commented May 16, 2022

Final benchmarks before/after for keccak permutation after the column reduction/squash.
Before

test keccak_permutation::tests::bench_keccak_round has been running for over 60 seconds
Start:   EVM Proof generation with 19 rows
End: Setup generation with degree = 19 .........................................220.844s

After:

test keccak_permutation::tests::bench_keccak_round has been running for over 60 seconds
Start:   EVM Proof generation with 19 rows
End:     EVM Proof generation with 19 rows .........................................171.443s
test keccak_permutation::tests::bench_keccak_round ... ok

@CPerezz CPerezz merged commit f7d1e9e into main May 16, 2022
@CPerezz CPerezz deleted the optimize_keccak_circuit branch May 16, 2022 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
benchmarks: Keccak Triggers a Keccak round benchmark crate-keccak Issues related to the keccak workspace member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants