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

feat: Circuit checker class #4931

Merged
merged 18 commits into from
Mar 6, 2024
Merged

feat: Circuit checker class #4931

merged 18 commits into from
Mar 6, 2024

Conversation

ledwards2225
Copy link
Contributor

@ledwards2225 ledwards2225 commented Mar 4, 2024

Moves the check_circuit functionality to a single new class called CircuitChecker that utilizes Relations instead of redefining the constraint algebra in the circuit builders.

The initial motivation for this work was to update the check circuit functionality to handle the new block structure. I've decided to do a larger refactor because notions like Flavor and Relations that did not yet exist when check_circuit was originally implemented now allow for substantial simplification. The overall logic remains equivalent. Most of the file changes amount to builder.check_circuit() --> CircuitChecker::check(builder).

Note: the CircuitChecker::check() method receives a const reference to a builder, makes a copy, finalizes that copy and performs checks on the result. It is thus guaranteed that the original circuit is unchanged so checks to this end have been removed from some tests.

Closes AztecProtocol/barretenberg#885 (Update check circuit to handle block structure)
Closes AztecProtocol/barretenberg#806 (Use Relations for check circuit)

@ledwards2225 ledwards2225 self-assigned this Mar 4, 2024
@AztecBot
Copy link
Collaborator

AztecBot commented Mar 4, 2024

Benchmark results

No metrics with a significant change found.

Detailed results

All benchmarks are run on txs on the Benchmarking contract on the repository. Each tx consists of a batch call to create_note and increment_balance, which guarantees that each tx has a private call, a nested private call, a public call, and a nested public call, as well as an emitted private note, an unencrypted log, and public storage read and write.

This benchmark source data is available in JSON format on S3 here.

Values are compared against data from master at commit 06a91169 and shown if the difference exceeds 1%.

L2 block published to L1

Each column represents the number of txs on an L2 block published to L1.

Metric 8 txs 32 txs 64 txs
l1_rollup_calldata_size_in_bytes 5,700 18,884 36,452
l1_rollup_calldata_gas 66,468 239,360 470,024
l1_rollup_execution_gas 194,416 500,666 909,282
l2_block_processing_time_in_ms 1,190 (+1%) 4,571 (+2%) 8,899
note_successful_decrypting_time_in_ms 204 538 (-1%) 1,005 (+1%)
note_trial_decrypting_time_in_ms 13.4 (+50%) 59.4 (-18%) 37.6 (-73%)
l2_block_building_time_in_ms 17,481 70,528 (+2%) 130,659 (-8%)
l2_block_rollup_simulation_time_in_ms 13,367 (-1%) 53,206 99,734 (-8%)
l2_block_public_tx_process_time_in_ms 4,082 (+1%) 17,253 (+6%) 30,758 (-8%)

L2 chain processing

Each column represents the number of blocks on the L2 chain where each block has 16 txs.

Metric 5 blocks 10 blocks
node_history_sync_time_in_ms 14,690 (-5%) 26,961 (-5%)
note_history_successful_decrypting_time_in_ms 1,259 (+1%) 2,390 (-3%)
note_history_trial_decrypting_time_in_ms 95.3 (+10%) 147 (-18%)
node_database_size_in_bytes 18,767,952 35,512,400
pxe_database_size_in_bytes 29,923 59,478

Circuits stats

Stats on running time and I/O sizes collected for every circuit run across all benchmarks.

Circuit circuit_simulation_time_in_ms circuit_input_size_in_bytes circuit_output_size_in_bytes
private-kernel-init 256 44,736 28,001
private-kernel-ordering 195 (-2%) 52,625 14,627
base-rollup 1,344 (-3%) 177,932 997
root-rollup 73.3 (-1%) 4,320 825
private-kernel-inner 324 (-3%) 73,715 28,001
public-kernel-app-logic 199 (-2%) 32,254 25,379
merge-rollup 8.79 (-3%) 2,840 997

Tree insertion stats

The duration to insert a fixed batch of leaves into each tree type.

Metric 1 leaves 2 leaves 8 leaves 16 leaves 32 leaves 64 leaves 128 leaves 512 leaves 1024 leaves 2048 leaves 4096 leaves
batch_insert_into_append_only_tree_16_depth_ms 9.92 (-1%) 11.0 13.7 (+10%) 16.1 (-1%) 21.9 (-1%) 35.3 (-1%) N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_count 16.9 17.5 23.0 31.6 47.0 79.0 N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_ms 0.576 (-1%) 0.607 (-1%) 0.581 (+9%) 0.497 (-1%) 0.459 (-1%) 0.440 (-1%) N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A N/A N/A N/A 46.2 72.6 (-3%) 230 446 (-1%) 865 (-1%) 1,718 (-1%)
batch_insert_into_append_only_tree_32_depth_hash_count N/A N/A N/A N/A N/A 96.0 159 543 1,055 2,079 4,127
batch_insert_into_append_only_tree_32_depth_hash_ms N/A N/A N/A N/A N/A 0.474 0.448 (-3%) 0.419 0.417 (-1%) 0.411 (-1%) 0.412 (-2%)
batch_insert_into_indexed_tree_20_depth_ms N/A N/A N/A N/A N/A 54.4 (-3%) 107 338 (+1%) 663 1,364 (+5%) 2,611
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A N/A N/A N/A 104 207 691 1,363 2,707 5,395
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A N/A N/A N/A 0.483 (-3%) 0.484 0.456 0.456 0.472 (+4%) 0.452
batch_insert_into_indexed_tree_40_depth_ms N/A N/A N/A N/A 61.5 N/A N/A N/A N/A N/A N/A
batch_insert_into_indexed_tree_40_depth_hash_count N/A N/A N/A N/A 109 N/A N/A N/A N/A N/A N/A
batch_insert_into_indexed_tree_40_depth_hash_ms N/A N/A N/A N/A 0.538 N/A N/A N/A N/A N/A N/A

Miscellaneous

Transaction sizes based on how many contracts are deployed in the tx.

Metric 0 deployed contracts
tx_size_in_bytes 19,179

Transaction processing duration by data writes.

Metric 0 new note hashes 1 new note hashes
tx_pxe_processing_time_ms 2,716 (+2%) 1,399
Metric 0 public data writes 1 public data writes
tx_sequencer_processing_time_ms 0.0315 (+5%) 486 (-2%)

@ledwards2225 ledwards2225 marked this pull request as ready for review March 5, 2024 21:30
@@ -1,4 +1,5 @@
#include "ultra_circuit_builder.hpp"
#include "barretenberg/proof_system/circuit_builder/ultra_circuit_builder.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels very weird that the tests for ultra are not in the same directory as the builder. Is it because you didn't want to create a circular dependency?

@@ -1,4 +1,5 @@
#include "standard_circuit_builder.hpp"
#include "barretenberg/proof_system/circuit_builder/standard_circuit_builder.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels weird that the tests for builders are here and not in the same folder as the implementation

};

template <typename Builder>
void CircuitChecker::populate_values(
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no description what this function does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of the descriptions are in the header. Cody has mentioned that this is better for doxygen for some reason

return result;
};

template <typename Relation> bool CircuitChecker::check_relation(auto& values, auto& params)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd add a description and mention that this only works for linearly independent relations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point about the lin dep relations, will add a note to the descrip in the header

Copy link
Contributor

@Rumata888 Rumata888 left a comment

Choose a reason for hiding this comment

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

Everything looks good. The only thing that slightly bothers me is that the tests migrated to the circuit_checker folder. Feels unintuitive.

@ledwards2225 ledwards2225 merged commit 4eba266 into master Mar 6, 2024
95 checks passed
@ledwards2225 ledwards2225 deleted the lde/circuit_checker branch March 6, 2024 16:30
PhilWindle pushed a commit that referenced this pull request Mar 6, 2024
🤖 I have created a release *beep* *boop*
---


<details><summary>aztec-package: 0.26.4</summary>

##
[0.26.4](aztec-package-v0.26.3...aztec-package-v0.26.4)
(2024-03-06)


### Miscellaneous

* **aztec-package:** Synchronize aztec-packages versions
</details>

<details><summary>barretenberg.js: 0.26.4</summary>

##
[0.26.4](barretenberg.js-v0.26.3...barretenberg.js-v0.26.4)
(2024-03-06)


### Miscellaneous

* **barretenberg.js:** Synchronize aztec-packages versions
</details>

<details><summary>aztec-cli: 0.26.4</summary>

##
[0.26.4](aztec-cli-v0.26.3...aztec-cli-v0.26.4)
(2024-03-06)


### Miscellaneous

* **aztec-cli:** Synchronize aztec-packages versions
</details>

<details><summary>aztec-packages: 0.26.4</summary>

##
[0.26.4](aztec-packages-v0.26.3...aztec-packages-v0.26.4)
(2024-03-06)


### Features

* **avm:** ALU &lt;--&gt; MAIN inter table relation on intermediate
registers copy
([#4945](#4945))
([8708131](8708131)),
closes
[#4613](#4613)
* Circuit checker class
([#4931](#4931))
([4eba266](4eba266))
* Compute out hash in circuits
[#4561](#4561)
([#4873](#4873))
([06a9116](06a9116))


### Bug Fixes

* **ci:** Noir mirror base commit
([#4969](#4969))
([546c666](546c666))
* Fix release
([#4994](#4994))
([19a8728](19a8728))


### Miscellaneous

* Use public constructors where possible
([#4937](#4937))
([225aad6](225aad6))
</details>

<details><summary>barretenberg: 0.26.4</summary>

##
[0.26.4](barretenberg-v0.26.3...barretenberg-v0.26.4)
(2024-03-06)


### Features

* **avm:** ALU &lt;--&gt; MAIN inter table relation on intermediate
registers copy
([#4945](#4945))
([8708131](8708131)),
closes
[#4613](#4613)
* Circuit checker class
([#4931](#4931))
([4eba266](4eba266))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
AztecBot added a commit to AztecProtocol/barretenberg that referenced this pull request Mar 7, 2024
🤖 I have created a release *beep* *boop*
---


<details><summary>aztec-package: 0.26.4</summary>

##
[0.26.4](AztecProtocol/aztec-packages@aztec-package-v0.26.3...aztec-package-v0.26.4)
(2024-03-06)


### Miscellaneous

* **aztec-package:** Synchronize aztec-packages versions
</details>

<details><summary>barretenberg.js: 0.26.4</summary>

##
[0.26.4](AztecProtocol/aztec-packages@barretenberg.js-v0.26.3...barretenberg.js-v0.26.4)
(2024-03-06)


### Miscellaneous

* **barretenberg.js:** Synchronize aztec-packages versions
</details>

<details><summary>aztec-cli: 0.26.4</summary>

##
[0.26.4](AztecProtocol/aztec-packages@aztec-cli-v0.26.3...aztec-cli-v0.26.4)
(2024-03-06)


### Miscellaneous

* **aztec-cli:** Synchronize aztec-packages versions
</details>

<details><summary>aztec-packages: 0.26.4</summary>

##
[0.26.4](AztecProtocol/aztec-packages@aztec-packages-v0.26.3...aztec-packages-v0.26.4)
(2024-03-06)


### Features

* **avm:** ALU &lt;--&gt; MAIN inter table relation on intermediate
registers copy
([#4945](AztecProtocol/aztec-packages#4945))
([8708131](AztecProtocol/aztec-packages@8708131)),
closes
[#4613](AztecProtocol/aztec-packages#4613)
* Circuit checker class
([#4931](AztecProtocol/aztec-packages#4931))
([4eba266](AztecProtocol/aztec-packages@4eba266))
* Compute out hash in circuits
[#4561](AztecProtocol/aztec-packages#4561)
([#4873](AztecProtocol/aztec-packages#4873))
([06a9116](AztecProtocol/aztec-packages@06a9116))


### Bug Fixes

* **ci:** Noir mirror base commit
([#4969](AztecProtocol/aztec-packages#4969))
([546c666](AztecProtocol/aztec-packages@546c666))
* Fix release
([#4994](AztecProtocol/aztec-packages#4994))
([19a8728](AztecProtocol/aztec-packages@19a8728))


### Miscellaneous

* Use public constructors where possible
([#4937](AztecProtocol/aztec-packages#4937))
([225aad6](AztecProtocol/aztec-packages@225aad6))
</details>

<details><summary>barretenberg: 0.26.4</summary>

##
[0.26.4](AztecProtocol/aztec-packages@barretenberg-v0.26.3...barretenberg-v0.26.4)
(2024-03-06)


### Features

* **avm:** ALU &lt;--&gt; MAIN inter table relation on intermediate
registers copy
([#4945](AztecProtocol/aztec-packages#4945))
([8708131](AztecProtocol/aztec-packages@8708131)),
closes
[#4613](AztecProtocol/aztec-packages#4613)
* Circuit checker class
([#4931](AztecProtocol/aztec-packages#4931))
([4eba266](AztecProtocol/aztec-packages@4eba266))
</details>

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants