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

refactor: private reset kernel #7984

Merged
merged 7 commits into from
Aug 15, 2024
Merged

Conversation

LeilaWang
Copy link
Collaborator

Please read contributing guidelines and remove this line.

Copy link
Contributor

github-actions bot commented Aug 14, 2024

Changes to circuit sizes

Generated at commit: 22af0b7aae6a7d325da303235fbc9cbcb3f7b2a0, compared to commit: 3d61bdfbe16464e19523d20f231fbd3ff76f509c

🧾 Summary (100% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
rollup_base -23 ✅ -0.01% -23 ✅ -0.00%
public_kernel_setup -440 ✅ -0.20% -220 ✅ -0.01%
public_kernel_teardown -613 ✅ -0.21% -326 ✅ -0.02%
public_kernel_app_logic -609 ✅ -0.21% -325 ✅ -0.05%
public_kernel_tail -9,718 ✅ -0.97% -9,665 ✅ -0.10%
private_kernel_tail_to_public -440 ✅ -1.17% -76 ✅ -0.13%
private_kernel_inner -1,088 ✅ -2.18% -275 ✅ -0.41%
private_kernel_init -802 ✅ -2.80% -424 ✅ -1.09%
private_kernel_reset -24,458 ✅ -20.89% -45,829 ✅ -8.80%
private_kernel_reset_full_inner -24,459 ✅ -22.21% -45,831 ✅ -9.33%
private_kernel_reset_big -25,226 ✅ -28.80% -36,190 ✅ -12.08%
private_kernel_reset_medium -25,610 ✅ -35.25% -31,369 ✅ -16.63%
private_kernel_reset_small -25,802 ✅ -39.58% -28,959 ✅ -21.75%
private_kernel_reset_tiny -25,898 ✅ -42.14% -27,754 ✅ -26.29%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
rollup_base 348,208 (-23) -0.01% 9,076,523 (-23) -0.00%
public_kernel_setup 215,537 (-440) -0.20% 1,833,754 (-220) -0.01%
public_kernel_teardown 294,503 (-613) -0.21% 1,914,436 (-326) -0.02%
public_kernel_app_logic 293,959 (-609) -0.21% 595,785 (-325) -0.05%
public_kernel_tail 995,440 (-9,718) -0.97% 9,375,587 (-9,665) -0.10%
private_kernel_tail_to_public 37,122 (-440) -1.17% 57,044 (-76) -0.13%
private_kernel_inner 48,931 (-1,088) -2.18% 66,676 (-275) -0.41%
private_kernel_init 27,819 (-802) -2.80% 38,460 (-424) -1.09%
private_kernel_reset 92,596 (-24,458) -20.89% 474,833 (-45,829) -8.80%
private_kernel_reset_full_inner 85,690 (-24,459) -22.21% 445,153 (-45,831) -9.33%
private_kernel_reset_big 62,353 (-25,226) -28.80% 263,436 (-36,190) -12.08%
private_kernel_reset_medium 47,044 (-25,610) -35.25% 157,219 (-31,369) -16.63%
private_kernel_reset_small 39,387 (-25,802) -39.58% 104,212 (-28,959) -21.75%
private_kernel_reset_tiny 35,560 (-25,898) -42.14% 77,798 (-27,754) -26.29%

@AztecBot
Copy link
Collaborator

AztecBot commented Aug 14, 2024

Benchmark results

Metrics with a significant change:

  • proof_construction_time_sha256_100_ms (16): 7,125 (+31%)
  • protocol_circuit_simulation_time_in_ms (private-kernel-tail): 208 (-23%)
  • protocol_circuit_simulation_time_in_ms (private-kernel-tail-to-public): 771 (-48%)
  • avm_simulation_time_ms (Token:mint_public): 42.9 (-42%)
  • avm_simulation_time_ms (Token:assert_minter_and_mint): 69.0 (+73%)
  • avm_simulation_time_ms (Token:transfer_public): 33.4 (+52%)
  • protocol_circuit_witness_generation_time_in_ms (private-kernel-reset-tiny): 871 (-27%)
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 5,763 1,555 697 (-1%) 761 (-2%) 770
proof_construction_time_sha256_30_ms 11,848 3,166 1,406 1,426 1,471 (+1%)
proof_construction_time_sha256_100_ms 44,190 (-2%) 12,640 (+6%) ⚠️ 7,125 (+31%) 5,659 (+5%) 5,581 (+4%)
proof_construction_time_poseidon_hash_ms 78.0 34.0 34.0 59.0 (+2%) 88.0 (+1%)
proof_construction_time_poseidon_hash_30_ms 1,529 418 (-1%) 202 231 (+3%) 269
proof_construction_time_poseidon_hash_100_ms 5,664 1,534 (+1%) 689 (+2%) 746 (+1%) 750 (+1%)

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 4,324 7,844 14,852
l1_rollup_calldata_gas 49,672 92,480 177,656
l1_rollup_execution_gas 1,294,335 2,042,111 3,869,326
l2_block_processing_time_in_ms 249 (-3%) 440 (-2%) 820 (+1%)
l2_block_building_time_in_ms 9,409 (+1%) 18,154 36,525 (+1%)
l2_block_rollup_simulation_time_in_ms 9,409 (+1%) 18,154 36,525 (+1%)
l2_block_public_tx_process_time_in_ms 7,949 (+1%) 16,612 34,934 (+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 2,953 3,808 (-5%)
node_database_size_in_bytes 12,734,544 16,883,792 (+1%)
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
private-kernel-init 97.0 (-4%) 380 (-4%) 21,673 (-1%) 44,858 N/A
private-kernel-inner 165 (-2%) 685 (-2%) 72,308 45,005 N/A
private-kernel-reset-tiny 516 (+2%) ⚠️ 871 (-27%) 65,974 (-5%) 44,844 N/A
private-kernel-tail ⚠️ 208 (-23%) 160 (-18%) 50,728 52,256 N/A
base-parity 5.54 N/A 160 96.0 N/A
root-parity 33.2 (-1%) N/A 69,084 96.0 N/A
base-rollup 2,873 N/A 187,817 664 N/A
root-rollup 38.4 (-1%) N/A 54,525 716 N/A
public-kernel-setup 96.5 (-4%) N/A 103,760 71,222 N/A
public-kernel-app-logic 104 (-2%) N/A 103,599 71,222 N/A
public-kernel-tail 576 (+1%) N/A 409,190 16,414 N/A
private-kernel-reset-small 485 N/A 66,085 (-1%) 45,629 N/A
private-kernel-tail-to-public ⚠️ 771 (-48%) 635 (-10%) 492,960 (-3%) 1,697 N/A
public-kernel-teardown 92.7 (-3%) N/A 104,005 71,222 N/A
merge-rollup 19.2 N/A 35,742 664 N/A
undefined N/A N/A N/A N/A 67,255 (-1%)

Stats on running time collected for app circuits

Function input_size_in_bytes output_size_in_bytes witness_generation_time_in_ms
ContractClassRegisterer:register 1,344 11,731 346
ContractInstanceDeployer:deploy 1,408 11,731 18.3
MultiCallEntrypoint:entrypoint 1,920 11,731 464
FeeJuice:deploy 1,376 11,731 389
SchnorrAccount:constructor 1,312 11,731 171
SchnorrAccount:entrypoint 2,304 11,731 508
Token:privately_mint_private_note 1,280 11,731 221
FPC:fee_entrypoint_public 1,344 11,731 22.5 (-16%)
Token:transfer 1,312 11,731 399 (-2%)
Benchmarking:create_note 1,344 11,731 165
SchnorrAccount:verify_private_authwit 1,280 11,731 27.4
Token:unshield 1,376 11,731 636
FPC:fee_entrypoint_private 1,376 11,731 852

AVM Simulation

Time to simulate various public functions in the AVM.

Function time_ms bytecode_size_in_bytes
FeeJuice:_increase_public_balance 57.4 (+6%) 8,139
FeeJuice:set_portal 9.36 (-10%) 2,362
Token:constructor 82.0 (-3%) 31,107
FPC:constructor 54.1 (-1%) 22,380
FeeJuice:mint_public 38.2 6,150
Token:mint_public ⚠️ 42.9 (-42%) 11,720
Token:assert_minter_and_mint ⚠️ 69.0 (+73%) 8,028
AuthRegistry:set_authorized 44.5 (-5%) 4,537
FPC:prepare_fee 240 (-9%) 8,812
Token:transfer_public ⚠️ 33.4 (+52%) 47,374
FPC:pay_refund 66.8 (+6%) 12,114
Benchmarking:increment_balance 974 (+1%) 7,450
Token:_increase_public_balance 38.3 (-3%) 8,960
FPC:pay_refund_with_shielded_rebate 69.9 (+4%) 12,663

Public DB Access

Time to access various public DBs.

Function time_ms
get-nullifier-index 0.168 (+3%)

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 2.20 3.82 (-3%) 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.114 0.107 (-4%) N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A 11.3 (-2%) 18.2 (-2%) 32.1 (+4%) 59.0 (-2%) 115 (-1%)
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.108 (-2%) 0.104 (-3%) 0.104 (+4%) 0.101 (-1%) 0.103
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 14.4 (+1%) 25.6 (-2%) 43.7 (+1%) 82.0 (-2%) 164
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.109 (+1%) 0.103 (-2%) 0.106 (+1%) 0.101 (-1%) 0.104 (+1%)
batch_insert_into_indexed_tree_40_depth_ms N/A N/A 16.3 (-1%) N/A N/A N/A N/A
batch_insert_into_indexed_tree_40_depth_hash_count N/A N/A 132 N/A N/A N/A N/A
batch_insert_into_indexed_tree_40_depth_hash_ms N/A N/A 0.104 (-2%) 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 64,779 668,997

Transaction size based on fee payment method

| Metric | |
| - | |

@LeilaWang LeilaWang marked this pull request as ready for review August 15, 2024 09:19
Comment on lines +37 to +40
unconstrained pub fn find_index_hint<T, let N: u32, Env>(array: [T; N], find: fn[Env](T) -> bool) -> u32 {
let mut index = N;
for i in 0..N {
if should_propagate[i] {
assert_eq(arr[i], vec_hint.get(verifying_index));
verifying_index += 1;
}
}
assert_eq(verifying_index, vec_hint.len());

vec_hint
}

unconstrained pub fn find_index_hint<T, let N: u32>(array: [T; N], find: T) -> u32 where T: Eq {
let mut index = 0;
for i in 0..array.len() {
if array[i] == find {
if (index == N) & find(array[i]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!! Much cleaner 👍

@LeilaWang LeilaWang merged commit 0d82c79 into master Aug 15, 2024
95 checks passed
@LeilaWang LeilaWang deleted the lw/private_reset_refactoring branch August 15, 2024 16:42
rahul-kothari pushed a commit that referenced this pull request Aug 15, 2024
🤖 I have created a release *beep* *boop*
---


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

##
[0.49.1](aztec-package-v0.49.0...aztec-package-v0.49.1)
(2024-08-15)


### Miscellaneous

* Sync alphanet back to master
([#7970](#7970))
([523724d](523724d))
</details>

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

##
[0.49.1](barretenberg.js-v0.49.0...barretenberg.js-v0.49.1)
(2024-08-15)


### Miscellaneous

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

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

##
[0.49.1](aztec-packages-v0.49.0...aztec-packages-v0.49.1)
(2024-08-15)


### Features

* Add pending reorg chain resistance in contracts
([#7926](#7926))
([f769f84](f769f84))
* **avm:** Base and dynamic gas in TS and CPP (part 2)
([#8016](#8016))
([5801732](5801732))


### Bug Fixes

* Docker.dockerignore file can be huge.
([#8023](#8023))
([cee9d9a](cee9d9a))
* Forking world state in prover-node
([#7995](#7995))
([ebffe96](ebffe96))


### Miscellaneous

* **avm:** Separate binary and bytes finalization
([#8010](#8010))
([3ad6dd9](3ad6dd9))
* Private reset kernel
([#7984](#7984))
([0d82c79](0d82c79))
* Sync alphanet back to master
([#7970](#7970))
([523724d](523724d))
</details>

<details><summary>barretenberg: 0.49.1</summary>

##
[0.49.1](barretenberg-v0.49.0...barretenberg-v0.49.1)
(2024-08-15)


### Features

* **avm:** Base and dynamic gas in TS and CPP (part 2)
([#8016](#8016))
([5801732](5801732))


### Miscellaneous

* **avm:** Separate binary and bytes finalization
([#8010](#8010))
([3ad6dd9](3ad6dd9))
</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 Aug 16, 2024
🤖 I have created a release *beep* *boop*
---


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

##
[0.49.1](AztecProtocol/aztec-packages@aztec-package-v0.49.0...aztec-package-v0.49.1)
(2024-08-15)


### Miscellaneous

* Sync alphanet back to master
([#7970](AztecProtocol/aztec-packages#7970))
([523724d](AztecProtocol/aztec-packages@523724d))
</details>

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

##
[0.49.1](AztecProtocol/aztec-packages@barretenberg.js-v0.49.0...barretenberg.js-v0.49.1)
(2024-08-15)


### Miscellaneous

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

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

##
[0.49.1](AztecProtocol/aztec-packages@aztec-packages-v0.49.0...aztec-packages-v0.49.1)
(2024-08-15)


### Features

* Add pending reorg chain resistance in contracts
([#7926](AztecProtocol/aztec-packages#7926))
([f769f84](AztecProtocol/aztec-packages@f769f84))
* **avm:** Base and dynamic gas in TS and CPP (part 2)
([#8016](AztecProtocol/aztec-packages#8016))
([5801732](AztecProtocol/aztec-packages@5801732))


### Bug Fixes

* Docker.dockerignore file can be huge.
([#8023](AztecProtocol/aztec-packages#8023))
([cee9d9a](AztecProtocol/aztec-packages@cee9d9a))
* Forking world state in prover-node
([#7995](AztecProtocol/aztec-packages#7995))
([ebffe96](AztecProtocol/aztec-packages@ebffe96))


### Miscellaneous

* **avm:** Separate binary and bytes finalization
([#8010](AztecProtocol/aztec-packages#8010))
([3ad6dd9](AztecProtocol/aztec-packages@3ad6dd9))
* Private reset kernel
([#7984](AztecProtocol/aztec-packages#7984))
([0d82c79](AztecProtocol/aztec-packages@0d82c79))
* Sync alphanet back to master
([#7970](AztecProtocol/aztec-packages#7970))
([523724d](AztecProtocol/aztec-packages@523724d))
</details>

<details><summary>barretenberg: 0.49.1</summary>

##
[0.49.1](AztecProtocol/aztec-packages@barretenberg-v0.49.0...barretenberg-v0.49.1)
(2024-08-15)


### Features

* **avm:** Base and dynamic gas in TS and CPP (part 2)
([#8016](AztecProtocol/aztec-packages#8016))
([5801732](AztecProtocol/aztec-packages@5801732))


### Miscellaneous

* **avm:** Separate binary and bytes finalization
([#8010](AztecProtocol/aztec-packages#8010))
([3ad6dd9](AztecProtocol/aztec-packages@3ad6dd9))
</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.

3 participants