dusk-network / plonk

Pure Rust implementation of the PLONK ZKProof System done by the Dusk team
https://dusk-network.github.io/plonk
Mozilla Public License 2.0
543 stars 150 forks source link

feat: add `compress` to compiler #752

Closed vlopes11 closed 1 year ago

vlopes11 commented 1 year ago

This commit introduces Compiler::compress and Compiler::decompress, two functions that will create a compressed representation of a circuit that can be used to generate prover and verifier keys.

The compression strategy takes advantage of the fact that circuit representations are sparse; meaning, most of the scalars are zeroes. We also have a higher incidence of 1 and -1, so any value that is equivalent to a i8 is compressed into a single byte, instead of the regular 32 bytes of a bls12-381.

This will result in expressive gains in terms of storage. For instance, a 2^12 circuit can be compressed into roughly 100Kb.

codecov[bot] commented 1 year ago

Codecov Report

Merging #752 (4c24a8e) into master (0487cc4) will decrease coverage by 0.26%. The diff coverage is 85.91%.

:exclamation: Current head 4c24a8e differs from pull request most recent head c4fda09. Consider uploading reports for the commit c4fda09 to get more accurate results

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/dusk-network/plonk/pull/752/graphs/tree.svg?width=650&height=150&src=pr&token=7JKOJ0fLuy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network)](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network) ```diff @@ Coverage Diff @@ ## master #752 +/- ## ========================================== - Coverage 85.33% 85.07% -0.26% ========================================== Files 54 56 +2 Lines 4166 4343 +177 ========================================== + Hits 3555 3695 +140 - Misses 611 648 +37 ``` | [Impacted Files](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network) | Coverage Δ | | |---|---|---| | [src/composer.rs](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network#diff-c3JjL2NvbXBvc2VyLnJz) | `91.05% <ø> (ø)` | | | [src/composer/verifier.rs](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network#diff-c3JjL2NvbXBvc2VyL3ZlcmlmaWVyLnJz) | `89.47% <ø> (+3.26%)` | :arrow_up: | | [src/constraint\_system/witness.rs](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network#diff-c3JjL2NvbnN0cmFpbnRfc3lzdGVtL3dpdG5lc3MucnM=) | `66.66% <ø> (ø)` | | | [src/error.rs](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network#diff-c3JjL2Vycm9yLnJz) | `0.00% <ø> (ø)` | | | [tests/common/mod.rs](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network#diff-dGVzdHMvY29tbW9uL21vZC5ycw==) | `76.47% <ø> (ø)` | | | [src/constraint\_system/constraint.rs](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network#diff-c3JjL2NvbnN0cmFpbnRfc3lzdGVtL2NvbnN0cmFpbnQucnM=) | `60.25% <33.33%> (ø)` | | | [src/composer/compiler/compress/hades.rs](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network#diff-c3JjL2NvbXBvc2VyL2NvbXBpbGVyL2NvbXByZXNzL2hhZGVzLnJz) | `80.95% <80.95%> (ø)` | | | [src/composer/compiler.rs](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network#diff-c3JjL2NvbXBvc2VyL2NvbXBpbGVyLnJz) | `97.95% <85.71%> (-0.62%)` | :arrow_down: | | [src/composer/compiler/compress.rs](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network#diff-c3JjL2NvbXBvc2VyL2NvbXBpbGVyL2NvbXByZXNzLnJz) | `87.89% <87.89%> (ø)` | | | [src/composer/prover.rs](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network#diff-c3JjL2NvbXBvc2VyL3Byb3Zlci5ycw==) | `95.75% <100.00%> (-2.79%)` | :arrow_down: | | ... and [1 more](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network) | | ... and [8 files with indirect coverage changes](https://app.codecov.io/gh/dusk-network/plonk/pull/752/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network) ------ [Continue to review full report in Codecov by Sentry](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network). Last update [0487cc4...c4fda09](https://app.codecov.io/gh/dusk-network/plonk/pull/752?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dusk-network).