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: reduce note and nullifier constants #7255

Merged
merged 3 commits into from
Jul 2, 2024
Merged

Conversation

LHerskind
Copy link
Contributor

@LHerskind LHerskind commented Jul 1, 2024

Reduces the MAX_NOTE_HASH_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_READ_REQUESTS_PER_CALL, MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL to 16 to align better what is possible, e.g., we should not allow doing more read requests than what you would be able to "read" and check is up to date. Also updating the TX versions.

Note, there might be a slight edge case, namely that if doing MAX_NOTE_HASH_READ_REQUESTS_PER_TX you might not be able to really emit MAX nulliifier because one of them was used for the tx hash.

Copy link
Contributor Author

LHerskind commented Jul 1, 2024

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

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

@LHerskind LHerskind mentioned this pull request Jul 1, 2024
Copy link
Contributor

github-actions bot commented Jul 1, 2024

Changes to circuit sizes

Generated at commit: 2156b183abb8acfe0fbb408d2479e2f590f32bde, compared to commit: 244ef7e5a6871443444df88c28a1c2a7430d6db1

🧾 Summary (100% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
private_kernel_init -5,440 ✅ -17.73% -16,839 ✅ -4.31%
private_kernel_tail_to_public -960 ✅ -0.22% -93,504 ✅ -5.28%
private_kernel_tail -192 ✅ -0.90% -92,017 ✅ -6.89%
private_kernel_reset_big -61,184 ✅ -34.25% -155,730 ✅ -9.15%
private_kernel_inner -9,376 ✅ -17.52% -132,822 ✅ -10.28%
private_kernel_reset_medium -61,184 ✅ -41.61% -155,730 ✅ -12.15%
private_kernel_reset_small -61,184 ✅ -46.62% -155,730 ✅ -14.54%
private_kernel_tail_to_public_simulated 0 ➖ 0.00% -576 ✅ -15.00%
public_kernel_app_logic_simulated 0 ➖ 0.00% -576 ✅ -15.00%
public_kernel_setup_simulated 0 ➖ 0.00% -576 ✅ -15.00%
public_kernel_teardown_simulated 0 ➖ 0.00% -576 ✅ -15.00%
public_kernel_teardown -97,840 ✅ -28.72% -362,975 ✅ -17.91%
public_kernel_app_logic -97,840 ✅ -28.73% -362,976 ✅ -17.91%
public_kernel_setup -97,600 ✅ -34.74% -336,012 ✅ -18.64%
public_kernel_tail -246,491 ✅ -20.24% -1,020,150 ✅ -18.80%
private_kernel_init_simulated 0 ➖ 0.00% -576 ✅ -20.51%
private_kernel_inner_simulated 0 ➖ 0.00% -576 ✅ -20.51%
private_kernel_reset_simulated 0 ➖ 0.00% -576 ✅ -20.51%
private_kernel_reset_simulated_big 0 ➖ 0.00% -576 ✅ -20.51%
private_kernel_reset_simulated_medium 0 ➖ 0.00% -576 ✅ -20.51%
private_kernel_reset_simulated_small 0 ➖ 0.00% -576 ✅ -20.51%
private_kernel_reset -106,707 ✅ -44.13% -847,413 ✅ -33.30%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
private_kernel_init 25,247 (-5,440) -17.73% 373,936 (-16,839) -4.31%
private_kernel_tail_to_public 444,478 (-960) -0.22% 1,677,002 (-93,504) -5.28%
private_kernel_tail 21,244 (-192) -0.90% 1,243,526 (-92,017) -6.89%
private_kernel_reset_big 117,445 (-61,184) -34.25% 1,546,939 (-155,730) -9.15%
private_kernel_inner 44,134 (-9,376) -17.52% 1,159,826 (-132,822) -10.28%
private_kernel_reset_medium 85,853 (-61,184) -41.61% 1,126,071 (-155,730) -12.15%
private_kernel_reset_small 70,056 (-61,184) -46.62% 915,636 (-155,730) -14.54%
private_kernel_tail_to_public_simulated 1 (0) 0.00% 3,263 (-576) -15.00%
public_kernel_app_logic_simulated 1 (0) 0.00% 3,263 (-576) -15.00%
public_kernel_setup_simulated 1 (0) 0.00% 3,263 (-576) -15.00%
public_kernel_teardown_simulated 1 (0) 0.00% 3,263 (-576) -15.00%
public_kernel_teardown 242,879 (-97,840) -28.72% 1,663,445 (-362,975) -17.91%
public_kernel_app_logic 242,681 (-97,840) -28.73% 1,663,205 (-362,976) -17.91%
public_kernel_setup 183,355 (-97,600) -34.74% 1,466,681 (-336,012) -18.64%
public_kernel_tail 971,057 (-246,491) -20.24% 4,407,521 (-1,020,150) -18.80%
private_kernel_init_simulated 1 (0) 0.00% 2,232 (-576) -20.51%
private_kernel_inner_simulated 1 (0) 0.00% 2,232 (-576) -20.51%
private_kernel_reset_simulated 1 (0) 0.00% 2,232 (-576) -20.51%
private_kernel_reset_simulated_big 1 (0) 0.00% 2,232 (-576) -20.51%
private_kernel_reset_simulated_medium 1 (0) 0.00% 2,232 (-576) -20.51%
private_kernel_reset_simulated_small 1 (0) 0.00% 2,232 (-576) -20.51%
private_kernel_reset 135,109 (-106,707) -44.13% 1,696,995 (-847,413) -33.30%

Base automatically changed from lh/remove-4738-comment to master July 1, 2024 16:48
@LHerskind LHerskind force-pushed the lh/max-xxx-reduction branch from 6051624 to a992701 Compare July 1, 2024 17:03
@LHerskind LHerskind force-pushed the lh/max-xxx-reduction branch from a992701 to 0697924 Compare July 2, 2024 11:07
@AztecBot
Copy link
Collaborator

AztecBot commented Jul 2, 2024

Benchmark results

Metrics with a significant change:

  • proof_construction_time_sha256_30_ms (16): 1,432 (-20%)
  • app_circuit_witness_generation_time_in_ms (Token:transfer): 1,778 (-39%)
  • app_circuit_witness_generation_time_in_ms (Token:unshield): 1,533 (-44%)
  • app_circuit_witness_generation_time_in_ms (FPC:fee_entrypoint_private): 2,109 (-42%)
  • protocol_circuit_simulation_time_in_ms (public-kernel-tail): 1,150 (-17%)
  • protocol_circuit_input_size_in_bytes (private-kernel-tail): 61,457 (-18%)
  • protocol_circuit_input_size_in_bytes (public-kernel-tail): 399,014 (-22%)
  • protocol_circuit_output_size_in_bytes (private-kernel-init): 54,134 (-19%)
  • protocol_circuit_output_size_in_bytes (private-kernel-inner): 54,134 (-19%)
  • protocol_circuit_output_size_in_bytes (private-kernel-reset-small): 54,134 (-19%)
  • avm_simulation_time_ms (Token:transfer_public): 29.4 (-50%)
  • avm_simulation_time_ms (Benchmarking:increment_balance): 2,202 (-16%)
  • app_circuit_proving_time_in_ms (Token:transfer): 12,199 (-48%)
  • app_circuit_size_in_gates (Token:transfer): 524,288 (-50%)
  • protocol_circuit_witness_generation_time_in_ms (private-kernel-init): 385 (-27%)
  • protocol_circuit_witness_generation_time_in_ms (private-kernel-inner): 774 (-25%)
  • protocol_circuit_witness_generation_time_in_ms (private-kernel-reset-small): 1,075 (-44%)
  • protocol_circuit_witness_generation_time_in_ms (base-parity): 1,523 (-16%)
  • protocol_circuit_witness_generation_time_in_ms (public-kernel-setup): 2,426 (-36%)
  • protocol_circuit_witness_generation_time_in_ms (public-kernel-app-logic): 3,422 (-29%)
  • protocol_circuit_witness_generation_time_in_ms (public-kernel-teardown): 3,377 (-32%)
  • protocol_circuit_witness_generation_time_in_ms (public-kernel-tail): 27,017 (-34%)
  • protocol_circuit_proving_time_in_ms (private-kernel-reset-small): 30,622 (-37%)
  • protocol_circuit_proof_size_in_bytes (private-kernel-init): 73,920 (-20%)
  • protocol_circuit_proof_size_in_bytes (private-kernel-inner): 73,920 (-20%)
  • protocol_circuit_proof_size_in_bytes (private-kernel-reset-small): 73,920 (-20%)
  • protocol_circuit_size_in_gates (private-kernel-reset-small): 1,048,576 (-50%)
  • protocol_circuit_num_public_inputs (private-kernel-init): 2,243 (-20%)
  • protocol_circuit_num_public_inputs (private-kernel-inner): 2,243 (-20%)
  • protocol_circuit_num_public_inputs (private-kernel-reset-small): 2,243 (-20%)
  • l2_block_building_time_in_ms (8): 41,826 (-16%)
  • l2_block_rollup_simulation_time_in_ms (8): 41,826 (-16%)
  • l2_block_public_tx_process_time_in_ms (8): 38,615 (-16%)
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_30_ms 11,876 (+2%) 3,187 ⚠️ 1,432 (-20%) 1,605 (+11%) 1,519
proof_construction_time_sha256_100_ms 44,102 (+1%) 11,777 (+1%) 5,415 5,356 (-1%) 5,360
proof_construction_time_poseidon_hash_ms 79.0 (+1%) 34.0 34.0 (-15%) 59.0 88.0 (-1%)
proof_construction_time_poseidon_hash_30_ms 1,535 (+1%) 418 200 228 (+1%) 266 (+2%)
proof_construction_time_poseidon_hash_100_ms 5,793 (+1%) 1,575 (+1%) 725 768 (-1%) 791

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 1,412 1,412 1,412
l1_rollup_calldata_gas 9,476 (+1%) 9,464 9,452
l1_rollup_execution_gas 611,215 611,354 611,493
l2_block_processing_time_in_ms 758 (+1%) 1,421 2,684 (-1%)
l2_block_building_time_in_ms 21,039 (-15%) ⚠️ 41,826 (-16%) 82,378 (-15%)
l2_block_rollup_simulation_time_in_ms 21,039 (-15%) ⚠️ 41,826 (-16%) 82,378 (-15%)
l2_block_public_tx_process_time_in_ms 18,021 (-15%) ⚠️ 38,615 (-16%) 79,178 (-15%)

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,073 9,851
node_database_size_in_bytes 12,251,216 16,138,320
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 proving_time_in_ms input_size_in_bytes output_size_in_bytes proof_size_in_bytes num_public_inputs size_in_gates
private-kernel-init 102 (-11%) ⚠️ 385 (-27%) 12,510 (-6%) 19,482 (-6%) ⚠️ 54,134 (-19%) ⚠️ 73,920 (-20%) ⚠️ 2,243 (-20%) 524,288
private-kernel-inner 308 (-14%) ⚠️ 774 (-25%) 49,829 80,694 (-15%) ⚠️ 54,134 (-19%) ⚠️ 73,920 (-20%) ⚠️ 2,243 (-20%) 2,097,152
private-kernel-tail 1,087 (-3%) 2,582 48,149 (-5%) ⚠️ 61,457 (-18%) 62,057 (-13%) 14,912 399 2,097,152
base-parity 6.21 (-1%) ⚠️ 1,523 (-16%) 2,623 (-4%) 128 64.0 2,208 2.00 131,072
root-parity 49.5 (+1%) 76.8 (-3%) 39,856 (-3%) 27,100 64.0 2,720 18.0 2,097,152
base-rollup 6,585 (-15%) 4,787 (-5%) 91,038 (+2%) 170,330 728 3,648 47.0 4,194,304
root-rollup 111 (+1%) 81.2 (-11%) 24,586 (-1%) 25,253 620 3,456 41.0 1,048,576
public-kernel-setup 546 (-14%) ⚠️ 2,426 (-36%) 42,704 (-7%) 102,121 (-13%) 80,278 (-14%) 106,912 (-15%) 3,274 (-15%) 2,097,152
public-kernel-app-logic 502 (-14%) ⚠️ 3,422 (-29%) 44,499 (-7%) 102,121 (-13%) 80,278 (-14%) 106,912 (-15%) 3,274 (-15%) 2,097,152
public-kernel-tail ⚠️ 1,150 (-17%) ⚠️ 27,017 (-34%) 173,705 (-11%) ⚠️ 399,014 (-22%) 10,014 14,912 399 8,388,608
private-kernel-reset-small 467 (-15%) ⚠️ 1,075 (-44%) ⚠️ 30,622 (-37%) 109,233 (-11%) ⚠️ 54,134 (-19%) ⚠️ 73,920 (-20%) ⚠️ 2,243 (-20%) ⚠️ 1,048,576 (-50%)
public-kernel-teardown 497 (-13%) ⚠️ 3,377 (-32%) 42,755 (-11%) 102,121 (-13%) 80,278 (-14%) 106,912 (-15%) 3,274 (-15%) 2,097,152
merge-rollup 29.2 N/A N/A 16,486 728 N/A N/A N/A
private-kernel-tail-to-public N/A 8,389 (-12%) 52,122 (-4%) N/A N/A 106,912 (-15%) 3,274 (-15%) 2,097,152

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 size_in_gates num_public_inputs
ContractClassRegisterer:register 1,344 8,792 (-12%) 405 (-1%) N/A N/A N/A N/A
ContractInstanceDeployer:deploy 1,408 8,792 (-12%) 38.5 (-3%) N/A N/A N/A N/A
MultiCallEntrypoint:entrypoint 1,920 8,792 (-12%) 1,194 (-8%) N/A N/A N/A N/A
GasToken:deploy 1,376 8,792 (-12%) 892 (-8%) N/A N/A N/A N/A
SchnorrAccount:constructor 1,312 8,792 (-12%) 498 (+2%) N/A N/A N/A N/A
SchnorrAccount:entrypoint 2,304 8,792 (-12%) 1,632 (-13%) 14,720 (-12%) 53,012 (-6%) 2,097,152 393 (-14%)
Token:privately_mint_private_note 1,280 8,792 (-12%) 617 (-6%) N/A N/A N/A N/A
FPC:fee_entrypoint_public 1,344 8,792 (-12%) 269 (-12%) 14,720 (-12%) 11,310 (-4%) 524,288 393 (-14%)
Token:transfer 1,312 8,792 (-12%) ⚠️ 1,778 (-39%) 14,720 (-12%) ⚠️ 12,199 (-48%) ⚠️ 524,288 (-50%) 393 (-14%)
AuthRegistry:set_authorized (avm) 19,226 (-8%) N/A N/A 91,264 (-3%) 1,328 (-3%) N/A N/A
FPC:prepare_fee (avm) 26,668 (-6%) N/A N/A 91,328 (-3%) 2,952 (-4%) N/A N/A
Token:transfer_public (avm) 42,884 (-4%) N/A N/A 91,328 (-3%) 4,015 (+1%) N/A N/A
AuthRegistry:consume (avm) 33,104 (-5%) N/A N/A 91,264 (-3%) 2,932 (-1%) N/A N/A
FPC:pay_refund (avm) 36,833 (-4%) N/A N/A 91,296 (-3%) 23,556 (-7%) N/A N/A
Benchmarking:create_note 1,344 8,792 (-12%) 485 (+1%) N/A N/A N/A N/A
SchnorrAccount:verify_private_authwit 1,280 8,792 (-12%) 71.4 (-2%) N/A N/A N/A N/A
Token:unshield 1,376 8,792 (-12%) ⚠️ 1,533 (-44%) N/A N/A N/A N/A
FPC:fee_entrypoint_private 1,376 8,792 (-12%) ⚠️ 2,109 (-42%) N/A N/A 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 69.8 13,790
GasToken:set_portal 17.4 (+2%) 3,305
Token:constructor 86.9 (-13%) 23,658
FPC:constructor 62.6 (+2%) 13,592
GasToken:mint_public 51.4 (-6%) 10,158
Token:mint_public 69.9 (-19%) 19,000
Token:assert_minter_and_mint 174 (-13%) 12,891
AuthRegistry:set_authorized 31.1 (-8%) 7,812
FPC:prepare_fee 108 (-23%) 15,062
Token:transfer_public ⚠️ 29.4 (-50%) 31,184
FPC:pay_refund 132 (-26%) 25,260
Benchmarking:increment_balance ⚠️ 2,202 (-16%) 15,233
Token:_increase_public_balance 55.6 (-1%) 14,972
FPC:pay_refund_with_shielded_rebate 117 (-11%) 26,347

Public DB Access

Time to access various public DBs.

Function time_ms
get-nullifier-index 0.152 (-12%)

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.8 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.603 0.515 N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A 48.1 (-1%) 75.9 (-1%) 131 (-1%) 247 470
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.491 (-1%) 0.466 (-1%) 0.451 0.447 0.439
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 59.6 (-1%) 112 183 356 691
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.503 (-1%) 0.502 0.484 0.482 0.474
batch_insert_into_indexed_tree_40_depth_ms N/A N/A 72.8 (-1%) 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.518 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 74,057 (-14%) 667,850

Transaction size based on fee payment method

| Metric | |
| - | |

@LHerskind LHerskind marked this pull request as ready for review July 2, 2024 15:10
@LHerskind LHerskind requested review from benesjan and sirasistant July 2, 2024 15:11
@LHerskind LHerskind merged commit 4637304 into master Jul 2, 2024
92 checks passed
@LHerskind LHerskind deleted the lh/max-xxx-reduction branch July 2, 2024 15:50
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