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: Switch pedersen to poseidon (WIP) #5523

Closed
wants to merge 8 commits into from
Closed

Conversation

sirasistant
Copy link
Contributor

Please read contributing guidelines and remove this line.

Copy link
Contributor

github-actions bot commented Apr 1, 2024

Changes to circuit sizes

Generated at commit: b24266c5a5d2c933ee8fd7baac53f225b31588e6, compared to commit: 4118bcd278524b3ba72f8f656285beb1c284f8f2

🧾 Summary (100% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
private_kernel_init +17,598 ❌ +36.21% +67,454 ❌ +19.30%
public_kernel_setup +7,039 ❌ +23.99% +26,778 ❌ +14.62%
public_kernel_teardown +7,039 ❌ +23.92% +26,778 ❌ +14.62%
private_kernel_inner +17,597 ❌ +18.36% +68,290 ❌ +13.12%
public_kernel_app_logic +7,810 ❌ +13.93% +30,095 ❌ +9.56%
private_kernel_tail +17,601 ❌ +4.71% +62,335 ❌ +7.42%
public_kernel_tail +5,273 ❌ +4.22% +20,525 ❌ +5.72%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
private_kernel_init 66,200 (+17,598) +36.21% 416,967 (+67,454) +19.30%
public_kernel_setup 36,383 (+7,039) +23.99% 209,876 (+26,778) +14.62%
public_kernel_teardown 36,468 (+7,039) +23.92% 209,962 (+26,778) +14.62%
private_kernel_inner 113,464 (+17,597) +18.36% 588,662 (+68,290) +13.12%
public_kernel_app_logic 63,885 (+7,810) +13.93% 344,849 (+30,095) +9.56%
private_kernel_tail 391,078 (+17,601) +4.71% 901,918 (+62,335) +7.42%
public_kernel_tail 130,244 (+5,273) +4.22% 379,495 (+20,525) +5.72%

@sirasistant
Copy link
Contributor Author

sirasistant commented Apr 1, 2024

A major slowdown appears to happenning with poseidon in private functions, the execution of the private function for benchmarking appears to have gone from ~400ms to ~7000ms . The bytecode size hasn't increased that much and the flamegraph seems to report that this slowdown comes from a lot of field inversions and ¿circuit deserializing?. This is very weird. Attaching the before and after flamegraph for a benchmarking run with 8 txs

after.zip
before.zip

@sirasistant
Copy link
Contributor Author

I think the slowdown comes from call stack item hashes. I think that it makes the account contracts blow up in size, not the app contracts, which makes sense, since call stack items are very large and probably all the conditional logic to condition the permutations is hurting performance

@AztecBot
Copy link
Collaborator

AztecBot commented Apr 1, 2024

Benchmark results

Metrics with a significant change:

  • circuit_simulation_time_in_ms (private-kernel-ordering): 229 (+36%)
  • note_history_successful_decrypting_time_in_ms (5): 4,953 (+302%)
  • note_history_successful_decrypting_time_in_ms (10): 9,947 (+302%)
  • note_successful_decrypting_time_in_ms (8): 547 (+112%)
  • note_successful_decrypting_time_in_ms (32): 1,962 (+223%)
  • note_successful_decrypting_time_in_ms (64): 3,920 (+281%)
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 a0720ff3 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 676 676 676
l1_rollup_calldata_gas 6,424 6,424 6,424
l1_rollup_execution_gas 585,757 585,757 585,757
l2_block_processing_time_in_ms 1,337 (+2%) 4,891 (+4%) 9,380
note_successful_decrypting_time_in_ms ⚠️ 547 (+112%) ⚠️ 1,962 (+223%) ⚠️ 3,920 (+281%)
note_trial_decrypting_time_in_ms 56.2 (-12%) 34.8 (+36%) 57.6 (-5%)
l2_block_building_time_in_ms 12,207 44,907 (+1%) 88,707 (+1%)
l2_block_rollup_simulation_time_in_ms 7,368 (-1%) 25,863 50,296 (-1%)
l2_block_public_tx_process_time_in_ms 4,821 (+2%) 18,995 (+2%) 38,276 (+4%)

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,207 (+1%) 27,857 (+1%)
note_history_successful_decrypting_time_in_ms ⚠️ 4,953 (+302%) ⚠️ 9,947 (+302%)
note_history_trial_decrypting_time_in_ms 60.7 (-30%) 173 (+15%)
node_database_size_in_bytes 18,636,880 35,004,496
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 199 (+9%) 44,379 28,214
private-kernel-ordering ⚠️ 229 (+36%) 52,880 14,296
base-parity 3,499 (-1%) 128 311
root-parity 1,300 (+1%) 1,244 311
base-rollup 14,959 165,760 861
root-rollup 48.9 (-1%) 4,359 725
private-kernel-inner 231 (+2%) 73,795 28,214
public-kernel-app-logic 101 (+6%) 35,252 28,217
public-kernel-tail 147 (+6%) 40,928 28,217
merge-rollup 8.90 (+8%) 2,568 861
public-kernel-teardown 96.7 (+5%) 35,252 28,217
public-kernel-setup 95.0 (+4%) 35,252 28,217

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.1 16.0 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.586 0.494 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 46.0 (-1%) 72.5 233 (+1%) 445 (-1%) 881 (+1%) 1,740 (+1%) 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.472 (-1%) 0.447 0.425 (+1%) 0.416 (-1%) 0.419 (+1%) 0.417 (+1%) N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 54.2 108 (+1%) 350 (+4%) 661 (-1%) 1,337 (+2%) 2,670 (+3%) N/A
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 105 207 691 1,363 2,707 5,395 N/A
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A 0.478 0.486 (+1%) 0.475 (+4%) 0.454 (-1%) 0.465 (+2%) 0.465 (+2%) 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 61.3
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.535

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 14,968 495,320

Transaction size based on fee payment method

Metric none fee payment method native fee payment method fpc_public fee payment method fpc_private fee payment method
tx_with_fee_size_in_bytes 773 905 1,161 1,377

Transaction processing duration by data writes.

Metric 0 new note hashes 1 new note hashes 2 new note hashes
tx_pxe_processing_time_ms 1,920 (+7%) 1,368 (+14%) 6,063 (+8%)
Metric 0 public data writes 1 public data writes 2 public data writes 3 public data writes 4 public data writes 5 public data writes 8 public data writes
tx_sequencer_processing_time_ms 9.26 (-22%) 600 (+3%) 455 (+5%) 1,192 (+3%) 604 (+3%) 2,062 (+2%) 598 (+7%)

@sirasistant
Copy link
Contributor Author

Yup it's the account contract. It goes from 14k ACIR opcodes to 400k opcodes, they are apparently related to the conditional logic to hash all the call stack items, which is consistent with the flamegraph and the fix.

@ludamad ludamad deleted the arv/poseidon_hash branch August 22, 2024 14:49
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