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

chore: apply where statement to impls instead of fns #7433

Merged
merged 4 commits into from
Jul 11, 2024
Merged

Conversation

nventuro
Copy link
Contributor

Now that we can have a where that affects an entire impl, I thought I'd give this a try in the state variables. Often I've felt tricked by these implementations, since when trying to work with them the requirements for a given generic T seem fairly low, but then they add up as I start calling more and more functions, which each add their own trait bounds. The interface ends up feeling dishonest and not really showing all you need to do (all the traits that must be implemented) in order to be able to use the thing.

With this change, the entire impl now requests up front all trait bounds, though it does mean we're a bit more restrictive than strictly needed. I don't think this is an issue - yes, you don't need to be able to serialize in order to read a public mutable, but you can only read if you write before, and that requires serialization. So all in all it seems like we always end up indirectly requiring all traits.

Copy link
Contributor

@sklppy88 sklppy88 left a comment

Choose a reason for hiding this comment

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

Looks nice !

@AztecBot
Copy link
Collaborator

AztecBot commented Jul 10, 2024

Benchmark results

Metrics with a significant change:

  • proof_construction_time_sha256_ms (1): 7,257 (+26%)
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.

Proof generation

Each column represents the number of threads used in proof generation.

Metric 1 threads 4 threads 16 threads 32 threads 64 threads
proof_construction_time_sha256_ms ⚠️ 7,257 (+26%) 1,541 (-2%) 703 (-1%) 745 (-2%) 767
proof_construction_time_sha256_30_ms 11,723 (-1%) 3,196 (+1%) 1,409 1,440 1,457 (-1%)
proof_construction_time_sha256_100_ms 43,864 11,829 5,447 (-6%) 5,436 (+1%) 5,364
proof_construction_time_poseidon_hash_ms 78.0 34.0 34.0 58.0 89.0 (+1%)
proof_construction_time_poseidon_hash_30_ms 1,520 417 200 226 265 (-4%)
proof_construction_time_poseidon_hash_100_ms 5,611 (-1%) 1,512 (-1%) 674 (-1%) 785 (+7%) 745

L2 block published to L1

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

Metric 4 txs 8 txs 16 txs
l1_rollup_calldata_size_in_bytes 708 708 708
l1_rollup_calldata_gas 6,564 (-1%) 6,596 6,588
l1_rollup_execution_gas 583,026 583,209 583,352
l2_block_processing_time_in_ms 762 (+1%) 1,416 2,724 (+1%)
l2_block_building_time_in_ms 13,389 (+2%) 26,168 51,077 (+1%)
l2_block_rollup_simulation_time_in_ms 13,389 (+2%) 26,168 51,076 (+1%)
l2_block_public_tx_process_time_in_ms 11,220 (+2%) 23,797 48,596 (+1%)

L2 chain processing

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

Metric 3 blocks 5 blocks
node_history_sync_time_in_ms 7,067 9,845
node_database_size_in_bytes 12,476,496 16,445,520
pxe_database_size_in_bytes 16,254 26,813

Circuits stats

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

Circuit simulation_time_in_ms witness_generation_time_in_ms input_size_in_bytes output_size_in_bytes proving_time_in_ms proof_size_in_bytes num_public_inputs size_in_gates
private-kernel-init 115 (-1%) 403 (+2%) 21,732 54,085 N/A N/A N/A N/A
private-kernel-inner 229 711 81,199 54,264 N/A N/A N/A N/A
private-kernel-tail 1,127 2,424 (-3%) 61,808 61,554 N/A N/A N/A N/A
base-parity 6.46 (-1%) 793 (-2%) 160 96.0 1,450 (+3%) 12,676 3.00 131,072
root-parity 107 (-1%) 114 (-3%) 64,860 96.0 48,834 (-1%) 12,676 3.00 4,194,304
base-rollup 4,242 4,810 (-1%) 180,315 632 48,971 13,476 28.0 4,194,304
root-rollup 152 (-1%) 120 (-5%) 51,261 652 42,790 13,412 26.0 4,194,304
public-kernel-setup 191 (-2%) 2,432 (+2%) 112,536 80,310 22,506 (-2%) 118,916 3,323 2,097,152
public-kernel-app-logic 150 (-1%) 3,204 (-2%) 112,536 80,310 10,237 (+1%) 118,916 3,323 1,048,576
public-kernel-tail 894 24,846 (-4%) 409,413 10,046 72,556 24,868 384 8,388,608
private-kernel-reset-tiny 1,285 (-1%) 996 77,007 53,954 N/A N/A N/A N/A
private-kernel-tail-to-public 6,720 (-2%) 2,901 (+1%) 777,415 1,632 N/A N/A N/A N/A
public-kernel-teardown 138 (-1%) 3,325 112,536 80,310 23,757 (-2%) 118,916 3,323 2,097,152
merge-rollup 58.4 (+1%) N/A 33,566 632 N/A N/A N/A N/A
undefined N/A N/A N/A N/A 172,001 (+1%) N/A N/A N/A

Stats on running time collected for app circuits

Function input_size_in_bytes output_size_in_bytes witness_generation_time_in_ms proof_size_in_bytes proving_time_in_ms
ContractClassRegisterer:register 1,312 9,344 402 (+2%) N/A N/A
ContractInstanceDeployer:deploy 1,376 9,344 24.9 N/A N/A
MultiCallEntrypoint:entrypoint 1,888 9,344 630 (+1%) N/A N/A
GasToken:deploy 1,344 9,344 563 N/A N/A
SchnorrAccount:constructor 1,280 9,344 426 N/A N/A
SchnorrAccount:entrypoint 2,272 9,344 765 N/A N/A
Token:privately_mint_private_note 1,248 9,344 503 N/A N/A
FPC:fee_entrypoint_public 1,312 9,344 101 (+1%) N/A N/A
Token:transfer 1,280 9,344 1,466 (+1%) N/A N/A
AuthRegistry:set_authorized (avm) 19,222 N/A N/A 95,392 2,081
FPC:prepare_fee (avm) 26,664 N/A N/A 95,456 2,782 (-1%)
Token:transfer_public (avm) 42,914 N/A N/A 95,456 3,176 (+1%)
AuthRegistry:consume (avm) 33,100 N/A N/A 95,424 2,782 (+2%)
FPC:pay_refund (avm) 36,829 N/A N/A 95,424 10,914 (+3%)
Benchmarking:create_note 1,312 9,344 422 N/A N/A
SchnorrAccount:verify_private_authwit 1,248 9,344 41.2 N/A N/A
Token:unshield 1,344 9,344 1,175 (-1%) N/A N/A
FPC:fee_entrypoint_private 1,344 9,344 1,529 (-1%) N/A N/A

AVM Simulation

Time to simulate various public functions in the AVM.

Function time_ms bytecode_size_in_bytes
GasToken:_increase_public_balance 99.5 (-1%) 13,790
GasToken:set_portal 13.9 (+17%) 3,339
Token:constructor 123 (+1%) 23,692
FPC:constructor 92.9 (+1%) 13,592
GasToken:mint_public 80.3 (-3%) 10,158
Token:mint_public 55.2 (-1%) 19,034
Token:assert_minter_and_mint 104 (+18%) 12,925
AuthRegistry:set_authorized 44.4 (-2%) 7,812
FPC:prepare_fee 100 (+1%) 15,062
Token:transfer_public 36.2 (-13%) 31,218
FPC:pay_refund 128 (-3%) 25,260
Benchmarking:increment_balance 1,349 15,267
Token:_increase_public_balance 14.8 15,006
FPC:pay_refund_with_shielded_rebate 177 26,347

Public DB Access

Time to access various public DBs.

Function time_ms
get-nullifier-index 0.160 (+2%)

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 256 leaves 512 leaves 1024 leaves
batch_insert_into_append_only_tree_16_depth_ms 10.4 16.7 N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_count 16.8 31.7 N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_ms 0.599 0.513 N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A 48.0 75.8 (-1%) 131 244 472
batch_insert_into_append_only_tree_32_depth_hash_count N/A N/A 95.9 159 287 543 1,055
batch_insert_into_append_only_tree_32_depth_hash_ms N/A N/A 0.490 0.466 (-1%) 0.450 0.443 0.441
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 59.4 112 184 (+1%) 352 696 (+1%)
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 109 207 355 691 1,363
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A 0.501 0.501 0.480 0.476 0.478
batch_insert_into_indexed_tree_40_depth_ms N/A N/A 72.7 N/A N/A N/A N/A
batch_insert_into_indexed_tree_40_depth_hash_count N/A N/A 133 N/A N/A N/A N/A
batch_insert_into_indexed_tree_40_depth_hash_ms N/A N/A 0.517 N/A N/A N/A N/A

Miscellaneous

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

Metric 0 registered classes 1 registered classes
tx_size_in_bytes 76,837 667,838

Transaction size based on fee payment method

| Metric | |
| - | |

Copy link
Contributor

@benesjan benesjan left a comment

Choose a reason for hiding this comment

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

nice

@benesjan benesjan enabled auto-merge (squash) July 11, 2024 09:47
Copy link
Contributor

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @nventuro and the rest of your teammates on Graphite Graphite

@benesjan
Copy link
Contributor

benesjan commented Jul 11, 2024

@nventuro enabling auto-merge here as well because my storage slot as point PR will touch a lot of things

With that note getter using ROM instead of RAM PR had to now implement Eq for CardNote as well and add Eq to a few functions (see the latest fix commit). Disabled automerge as it might be a bit controversial.

@benesjan benesjan disabled auto-merge July 11, 2024 10:40
@nventuro
Copy link
Contributor Author

Thanks for adding the missing Eq impl!

@nventuro nventuro enabled auto-merge (squash) July 11, 2024 14:18
@nventuro nventuro merged commit bb201f2 into master Jul 11, 2024
91 checks passed
@nventuro nventuro deleted the nv/where-impl branch July 11, 2024 15:27
rahul-kothari pushed a commit that referenced this pull request Jul 11, 2024
🤖 I have created a release *beep* *boop*
---


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

##
[0.46.4](aztec-package-v0.46.3...aztec-package-v0.46.4)
(2024-07-11)


### Miscellaneous

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

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

##
[0.46.4](barretenberg.js-v0.46.3...barretenberg.js-v0.46.4)
(2024-07-11)


### Miscellaneous

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

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

##
[0.46.4](aztec-packages-v0.46.3...aztec-packages-v0.46.4)
(2024-07-11)


### Features

* Configure world-state to follow the proven chain only
([#7430](#7430))
([2e41ac7](2e41ac7))


### Bug Fixes

* Missing secrets in docs publish
([#7445](#7445))
([840a4b9](840a4b9))


### Miscellaneous

* Apply where statement to impls instead of fns
([#7433](#7433))
([bb201f2](bb201f2))
* **avm:** Codegen cleanup
([#7439](#7439))
([e31887e](e31887e))
* **proving:** Post honk branch fixes
([#7435](#7435))
([86eafa0](86eafa0))
</details>

<details><summary>barretenberg: 0.46.4</summary>

##
[0.46.4](barretenberg-v0.46.3...barretenberg-v0.46.4)
(2024-07-11)


### Miscellaneous

* **avm:** Codegen cleanup
([#7439](#7439))
([e31887e](e31887e))
* **proving:** Post honk branch fixes
([#7435](#7435))
([86eafa0](86eafa0))
</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 Jul 12, 2024
🤖 I have created a release *beep* *boop*
---


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

##
[0.46.4](AztecProtocol/aztec-packages@aztec-package-v0.46.3...aztec-package-v0.46.4)
(2024-07-11)


### Miscellaneous

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

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

##
[0.46.4](AztecProtocol/aztec-packages@barretenberg.js-v0.46.3...barretenberg.js-v0.46.4)
(2024-07-11)


### Miscellaneous

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

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

##
[0.46.4](AztecProtocol/aztec-packages@aztec-packages-v0.46.3...aztec-packages-v0.46.4)
(2024-07-11)


### Features

* Configure world-state to follow the proven chain only
([#7430](AztecProtocol/aztec-packages#7430))
([2e41ac7](AztecProtocol/aztec-packages@2e41ac7))


### Bug Fixes

* Missing secrets in docs publish
([#7445](AztecProtocol/aztec-packages#7445))
([840a4b9](AztecProtocol/aztec-packages@840a4b9))


### Miscellaneous

* Apply where statement to impls instead of fns
([#7433](AztecProtocol/aztec-packages#7433))
([bb201f2](AztecProtocol/aztec-packages@bb201f2))
* **avm:** Codegen cleanup
([#7439](AztecProtocol/aztec-packages#7439))
([e31887e](AztecProtocol/aztec-packages@e31887e))
* **proving:** Post honk branch fixes
([#7435](AztecProtocol/aztec-packages#7435))
([86eafa0](AztecProtocol/aztec-packages@86eafa0))
</details>

<details><summary>barretenberg: 0.46.4</summary>

##
[0.46.4](AztecProtocol/aztec-packages@barretenberg-v0.46.3...barretenberg-v0.46.4)
(2024-07-11)


### Miscellaneous

* **avm:** Codegen cleanup
([#7439](AztecProtocol/aztec-packages#7439))
([e31887e](AztecProtocol/aztec-packages@e31887e))
* **proving:** Post honk branch fixes
([#7435](AztecProtocol/aztec-packages#7435))
([86eafa0](AztecProtocol/aztec-packages@86eafa0))
</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
Development

Successfully merging this pull request may close these issues.

4 participants