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: Sorted execution trace #5252

Merged
merged 45 commits into from
Mar 19, 2024
Merged

feat: Sorted execution trace #5252

merged 45 commits into from
Mar 19, 2024

Conversation

ledwards2225
Copy link
Contributor

@ledwards2225 ledwards2225 commented Mar 15, 2024

This work results in an execution trace fully sorted by gate type.

Prior to this PR, all of the infrastructure was added to construct and process a sorted execution trace. Each builder has a blocks object which essentially holds a {wires, selectors} pair for each gate type. Up until now, all gates were being added into blocks.main, which is equivalent to what we've always done. This PR simply adds gates into their appropriate specialized block, e.g. arithmetic gates are added into blocks.arithmetic and auxiliary gates are added into blocks.aux. After being processed in the ExecutionTrace class, this results in an execution trace sorted by gate type.

Note: This PR adds dummy gates in several new locations to account for the fact that some gates of a particular type were previously reading into a subsequent gate of different type, which breaks once the gates are sorted by type.
Note: This PR does not include any logic for taking advantage of the sorted structure.

Closes AztecProtocol/barretenberg#867 (gates are sorted)
Closes AztecProtocol/barretenberg#873 (no more gate interleaving assumptions, except ones now identified in more specific issues)
Closes AztecProtocol/barretenberg#910 (gate type summary via blocks.summarize())

@ledwards2225 ledwards2225 marked this pull request as ready for review March 15, 2024 15:35
Copy link
Contributor

github-actions bot commented Mar 15, 2024

Changes to circuit sizes

Generated at commit: 15d071f4795d8c5fbd9d2e681ed4d97c658a9c28, compared to commit: 10ef9702c43d36afd334a78df26fe0301c2ac001

🧾 Summary (100% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
rollup_base 0 ➖ 0.00% -4 ✅ -0.00%
private_kernel_inner 0 ➖ 0.00% -4 ✅ -0.00%
private_kernel_tail 0 ➖ 0.00% -7 ✅ -0.00%
public_kernel_tail 0 ➖ 0.00% -3 ✅ -0.00%
public_kernel_app_logic 0 ➖ 0.00% -3 ✅ -0.00%
private_kernel_init 0 ➖ 0.00% -4 ✅ -0.00%
public_kernel_teardown 0 ➖ 0.00% -3 ✅ -0.00%
public_kernel_setup 0 ➖ 0.00% -3 ✅ -0.00%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
rollup_base 171,450 (0) 0.00% 1,730,656 (-4) -0.00%
private_kernel_inner 95,996 (0) 0.00% 521,442 (-4) -0.00%
private_kernel_tail 373,475 (0) 0.00% 839,580 (-7) -0.00%
public_kernel_tail 124,967 (0) 0.00% 358,964 (-3) -0.00%
public_kernel_app_logic 56,202 (0) 0.00% 316,867 (-3) -0.00%
private_kernel_init 48,706 (0) 0.00% 348,989 (-4) -0.00%
public_kernel_teardown 29,516 (0) 0.00% 184,407 (-3) -0.00%
public_kernel_setup 29,408 (0) 0.00% 184,298 (-3) -0.00%

@AztecBot
Copy link
Collaborator

AztecBot commented Mar 18, 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 10ef9702 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,668 18,820 36,356
l1_rollup_calldata_gas 66,292 239,080 469,112
l1_rollup_execution_gas 647,390 929,438 1,305,292
l2_block_processing_time_in_ms 1,271 (-2%) 4,569 (-4%) 9,368
note_successful_decrypting_time_in_ms 176 (+2%) 523 (-6%) 976 (-2%)
note_trial_decrypting_time_in_ms 81.8 (+9%) 42.2 (-46%) 109 (-13%)
l2_block_building_time_in_ms 18,110 68,932 137,191
l2_block_rollup_simulation_time_in_ms 8,109 (+1%) 28,680 56,796
l2_block_public_tx_process_time_in_ms 9,979 (-1%) 40,197 (+1%) 80,299

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,770 (+1%) 28,576 (+7%)
note_history_successful_decrypting_time_in_ms 1,290 (+5%) 2,582 (+4%)
note_history_trial_decrypting_time_in_ms 100 (+65%) 171 (-7%)
node_database_size_in_bytes 18,620,496 34,992,208
pxe_database_size_in_bytes 29,859 59,414

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 280 44,366 28,244
private-kernel-ordering 214 52,868 14,326
base-parity 1,928 (+8%) 128 311
base-rollup 718 165,787 925
root-parity 1,464 (-10%) 1,244 311
root-rollup 52.2 (+1%) 4,487 725
private-kernel-inner 643 73,771 28,244
public-kernel-app-logic 456 (+3%) 35,260 28,215
public-kernel-tail 176 (+2%) 40,926 28,215
merge-rollup 8.32 2,696 925

Tree insertion stats

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

Metric 1 leaves 16 leaves 64 leaves 128 leaves 512 leaves 1024 leaves 2048 leaves 4096 leaves 32 leaves
batch_insert_into_append_only_tree_16_depth_ms 10.0 16.2 (+1%) N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_count 16.8 31.6 N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_ms 0.585 0.500 (+1%) N/A N/A N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A 51.4 (+12%) 72.4 231 447 874 (-1%) 1,731 N/A
batch_insert_into_append_only_tree_32_depth_hash_count N/A N/A 96.0 159 543 1,055 2,079 4,127 N/A
batch_insert_into_append_only_tree_32_depth_hash_ms N/A N/A 0.528 (+12%) 0.447 0.422 0.419 (+1%) 0.415 (-1%) 0.415 N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 59.1 (+7%) 107 (-1%) 338 (-1%) 665 (+1%) 1,317 (-1%) 2,620 N/A
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 104 207 691 1,363 2,707 5,395 N/A
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A 0.529 (+8%) 0.483 0.460 0.458 (+1%) 0.457 0.454 N/A
batch_insert_into_indexed_tree_40_depth_ms N/A N/A N/A N/A N/A N/A N/A N/A 63.5 (+4%)
batch_insert_into_indexed_tree_40_depth_hash_count N/A N/A N/A N/A N/A N/A N/A N/A 109
batch_insert_into_indexed_tree_40_depth_hash_ms N/A N/A N/A N/A N/A N/A N/A N/A 0.556 (+4%)

Miscellaneous

Transaction sizes based on how many contract classes are registered in the tx.

Metric 0 registered classes
tx_size_in_bytes 22,012

Transaction processing duration by data writes.

Metric 0 new note hashes 1 new note hashes
tx_pxe_processing_time_ms 3,203 (-1%) 1,743
Metric 0 public data writes 1 public data writes
tx_sequencer_processing_time_ms 11.5 1,269 (+3%)

bool result = true;
// TODO(https://github.com/AztecProtocol/barretenberg/issues/870): Currently we check all relations for each block.
// Once sorting is complete, is will be sufficient to check only the relevant relation(s) per block.
size_t block_idx = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously I was only checking the main block (which contained all gates). Now I'm looping over all blocks and checking all relations on each one.

@@ -62,7 +62,7 @@ class GoblinMockCircuits {
{
// Determine number of times to execute the below operations that constitute the mock circuit logic. Note that
// the circuit size does not scale linearly with number of iterations due to e.g. amortization of lookup costs
const size_t NUM_ITERATIONS_LARGE = 13; // results in circuit size 2^19 (521327 gates)
const size_t NUM_ITERATIONS_LARGE = 12; // results in circuit size 2^19 (502238 gates)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to reduce this due to dummy gates increasing sizes of some circuits

}
check_selector_length_consistency();
++this->num_gates;
create_dummy_gate(block, in.x2, in.x3, in.y3, in.y2);
Copy link
Contributor Author

@ledwards2225 ledwards2225 Mar 18, 2024

Choose a reason for hiding this comment

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

Here I'm just using the create_dummy_gate method instead of doing it manually

blocks.main.pad_additional();
}
check_selector_length_consistency();
create_add_gate({ variable_index[0], this->zero_idx, this->zero_idx, 1, 0, 0, -start });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No change, just using create_add_gate instead of the manual thing

0,
-end });
create_dummy_gate(block, variable_index[variable_index.size() - 1], this->zero_idx, this->zero_idx, this->zero_idx);
create_add_gate({ variable_index[variable_index.size() - 1], this->zero_idx, this->zero_idx, 1, 0, 0, -end });
Copy link
Contributor Author

@ledwards2225 ledwards2225 Mar 18, 2024

Choose a reason for hiding this comment

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

No actual change here, just using create_add_gate instead since there was no need for the "big add gate" functionality

@@ -313,7 +313,7 @@ class UltraCircuitBuilder_ : public CircuitBuilderBase<typename Arithmetization_
UltraCircuitBuilder_(const size_t size_hint = 0)
: CircuitBuilderBase<FF>(size_hint)
{
blocks.main.reserve(size_hint);
// TODO(https://github.com/AztecProtocol/barretenberg/issues/870): reserve space in blocks here somehow?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Leaving this as a TODO. I previously looked at how important this reserve was and it turns out the answer is that it's entirely negligible.

@ledwards2225 ledwards2225 self-assigned this Mar 18, 2024
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.

Chunky. Left very few comments. LGTM

@ledwards2225 ledwards2225 enabled auto-merge (squash) March 19, 2024 21:45
@ledwards2225 ledwards2225 merged commit a216759 into master Mar 19, 2024
93 of 95 checks passed
@ledwards2225 ledwards2225 deleted the lde/sorted_trace branch March 19, 2024 22:17
sirasistant pushed a commit that referenced this pull request Mar 20, 2024
🤖 I have created a release *beep* *boop*
---


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

##
[0.30.1](aztec-package-v0.30.0...aztec-package-v0.30.1)
(2024-03-20)


### Miscellaneous

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

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

##
[0.30.1](barretenberg.js-v0.30.0...barretenberg.js-v0.30.1)
(2024-03-20)


### Miscellaneous

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

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

##
[0.30.1](aztec-cli-v0.30.0...aztec-cli-v0.30.1)
(2024-03-20)


### Miscellaneous

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

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

##
[0.30.1](aztec-packages-v0.30.0...aztec-packages-v0.30.1)
(2024-03-20)


### Features

* Add CMOV instruction to brillig and brillig gen
([#5308](#5308))
([208abbb](208abbb))
* **avm:** Indirect memory support for arithmetic/bitwise opcodes
([#5328](#5328))
([d5ffa17](d5ffa17)),
closes
[#5273](#5273)
* **avm:** Indirect memory support for MOV
([#5257](#5257))
([10ef970](10ef970)),
closes
[#5205](#5205)
* Merge SMT Terms in one class
([#5254](#5254))
([f5c9b0f](f5c9b0f))
* Sorted execution trace
([#5252](#5252))
([a216759](a216759))


### Bug Fixes

* Fix recursion tests and reinstate in CI
([#5300](#5300))
([96c6f21](96c6f21))
* Skip uniswap l1 tests
([#5334](#5334))
([7a56941](7a56941))
* Update smt_verification README.md
([#5332](#5332))
([46b15e3](46b15e3))


### Miscellaneous

* Avm team as generated codeowners
([#5325](#5325))
([06d2786](06d2786))
* No Translator composer
([#5202](#5202))
([c8897ca](c8897ca))
* Remove toy vm files
([#5326](#5326))
([d940356](d940356))
* Replace relative paths to noir-protocol-circuits
([ea2ac09](ea2ac09))
</details>

<details><summary>barretenberg: 0.30.1</summary>

##
[0.30.1](barretenberg-v0.30.0...barretenberg-v0.30.1)
(2024-03-20)


### Features

* Add CMOV instruction to brillig and brillig gen
([#5308](#5308))
([208abbb](208abbb))
* **avm:** Indirect memory support for arithmetic/bitwise opcodes
([#5328](#5328))
([d5ffa17](d5ffa17)),
closes
[#5273](#5273)
* **avm:** Indirect memory support for MOV
([#5257](#5257))
([10ef970](10ef970)),
closes
[#5205](#5205)
* Merge SMT Terms in one class
([#5254](#5254))
([f5c9b0f](f5c9b0f))
* Sorted execution trace
([#5252](#5252))
([a216759](a216759))


### Bug Fixes

* Fix recursion tests and reinstate in CI
([#5300](#5300))
([96c6f21](96c6f21))
* Update smt_verification README.md
([#5332](#5332))
([46b15e3](46b15e3))


### Miscellaneous

* No Translator composer
([#5202](#5202))
([c8897ca](c8897ca))
* Remove toy vm files
([#5326](#5326))
([d940356](d940356))
</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 21, 2024
🤖 I have created a release *beep* *boop*
---


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

##
[0.30.1](AztecProtocol/aztec-packages@aztec-package-v0.30.0...aztec-package-v0.30.1)
(2024-03-20)


### Miscellaneous

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

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

##
[0.30.1](AztecProtocol/aztec-packages@barretenberg.js-v0.30.0...barretenberg.js-v0.30.1)
(2024-03-20)


### Miscellaneous

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

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

##
[0.30.1](AztecProtocol/aztec-packages@aztec-cli-v0.30.0...aztec-cli-v0.30.1)
(2024-03-20)


### Miscellaneous

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

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

##
[0.30.1](AztecProtocol/aztec-packages@aztec-packages-v0.30.0...aztec-packages-v0.30.1)
(2024-03-20)


### Features

* Add CMOV instruction to brillig and brillig gen
([#5308](AztecProtocol/aztec-packages#5308))
([208abbb](AztecProtocol/aztec-packages@208abbb))
* **avm:** Indirect memory support for arithmetic/bitwise opcodes
([#5328](AztecProtocol/aztec-packages#5328))
([d5ffa17](AztecProtocol/aztec-packages@d5ffa17)),
closes
[#5273](AztecProtocol/aztec-packages#5273)
* **avm:** Indirect memory support for MOV
([#5257](AztecProtocol/aztec-packages#5257))
([10ef970](AztecProtocol/aztec-packages@10ef970)),
closes
[#5205](AztecProtocol/aztec-packages#5205)
* Merge SMT Terms in one class
([#5254](AztecProtocol/aztec-packages#5254))
([f5c9b0f](AztecProtocol/aztec-packages@f5c9b0f))
* Sorted execution trace
([#5252](AztecProtocol/aztec-packages#5252))
([a216759](AztecProtocol/aztec-packages@a216759))


### Bug Fixes

* Fix recursion tests and reinstate in CI
([#5300](AztecProtocol/aztec-packages#5300))
([96c6f21](AztecProtocol/aztec-packages@96c6f21))
* Skip uniswap l1 tests
([#5334](AztecProtocol/aztec-packages#5334))
([7a56941](AztecProtocol/aztec-packages@7a56941))
* Update smt_verification README.md
([#5332](AztecProtocol/aztec-packages#5332))
([46b15e3](AztecProtocol/aztec-packages@46b15e3))


### Miscellaneous

* Avm team as generated codeowners
([#5325](AztecProtocol/aztec-packages#5325))
([06d2786](AztecProtocol/aztec-packages@06d2786))
* No Translator composer
([#5202](AztecProtocol/aztec-packages#5202))
([c8897ca](AztecProtocol/aztec-packages@c8897ca))
* Remove toy vm files
([#5326](AztecProtocol/aztec-packages#5326))
([d940356](AztecProtocol/aztec-packages@d940356))
* Replace relative paths to noir-protocol-circuits
([ea2ac09](AztecProtocol/aztec-packages@ea2ac09))
</details>

<details><summary>barretenberg: 0.30.1</summary>

##
[0.30.1](AztecProtocol/aztec-packages@barretenberg-v0.30.0...barretenberg-v0.30.1)
(2024-03-20)


### Features

* Add CMOV instruction to brillig and brillig gen
([#5308](AztecProtocol/aztec-packages#5308))
([208abbb](AztecProtocol/aztec-packages@208abbb))
* **avm:** Indirect memory support for arithmetic/bitwise opcodes
([#5328](AztecProtocol/aztec-packages#5328))
([d5ffa17](AztecProtocol/aztec-packages@d5ffa17)),
closes
[#5273](AztecProtocol/aztec-packages#5273)
* **avm:** Indirect memory support for MOV
([#5257](AztecProtocol/aztec-packages#5257))
([10ef970](AztecProtocol/aztec-packages@10ef970)),
closes
[#5205](AztecProtocol/aztec-packages#5205)
* Merge SMT Terms in one class
([#5254](AztecProtocol/aztec-packages#5254))
([f5c9b0f](AztecProtocol/aztec-packages@f5c9b0f))
* Sorted execution trace
([#5252](AztecProtocol/aztec-packages#5252))
([a216759](AztecProtocol/aztec-packages@a216759))


### Bug Fixes

* Fix recursion tests and reinstate in CI
([#5300](AztecProtocol/aztec-packages#5300))
([96c6f21](AztecProtocol/aztec-packages@96c6f21))
* Update smt_verification README.md
([#5332](AztecProtocol/aztec-packages#5332))
([46b15e3](AztecProtocol/aztec-packages@46b15e3))


### Miscellaneous

* No Translator composer
([#5202](AztecProtocol/aztec-packages#5202))
([c8897ca](AztecProtocol/aztec-packages@c8897ca))
* Remove toy vm files
([#5326](AztecProtocol/aztec-packages#5326))
([d940356](AztecProtocol/aztec-packages@d940356))
</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