AztecProtocol / aztec-packages

Apache License 2.0
184 stars 184 forks source link

feat(avm): poseidon2 constraints #7269

Closed IlyasRidhuan closed 2 months ago

IlyasRidhuan commented 3 months ago

Token transfer

% time AVM_ENABLE_FULL_PROVING=1 build/bin/bb avm_prove --avm-bytecode ~/tmp-8Q3xgk/avm_bytecode.bin --avm-calldata ~/tmp-8Q3xgk/avm_calldata.bin --avm-public-inputs ~/tmp-8Q3xgk/avm_public_inputs.bin --avm-hints ~/tmp-8Q3xgk/avm_hints.bin -o ~/tmp-8Q3xgk -v
bytecode size: 31218
calldata size: 6
public_inputs size: 481
hints.storage_value_hints size: 2
hints.note_hash_exists_hints size: 0
hints.nullifier_exists_hints size: 1
hints.l1_to_l2_message_exists_hints size: 0
hints.externalcall_hints size: 0
hints.contract_instance_hints size: 0
using cached crs of size 8388609 at "/mnt/user-data/facundo/.bb-crs/bn254_g1.dat"
Deserialized 2524 instructions
------- GENERATING TRACE -------
Trace sizes before padding:
        main_trace_size: 1638
        mem_trace_size: 3880
        alu_trace_size: 811
        range_check_size: 65536
        conv_trace_size: 1
        lookup_table_size: 0
        sha256_trace_size: 0
        poseidon2_trace_size: 0
        pedersen_trace_size: 4
        gas_trace_size: 1620
        fixed_gas_table_size: 65
        slice_trace_size: 7
Final trace size: 65537
------- PROVING EXECUTION -------
proof written to: "/mnt/user-data/facundo/tmp-8Q3xgk/proof"
vk written to: "/mnt/user-data/facundo/tmp-8Q3xgk/vk"
vk as fields written to: "/mnt/user-data/facundo/tmp-8Q3xgk/vk_fields.json"

AVM_ENABLE_FULL_PROVING=1 build/bin/bb avm_prove --avm-bytecode        -o  -v  340.59s user 84.63s system 731% cpu 58.117 total

Stats before and after

--- before poseidon constraints 1 cpu

prove/all_ms: 51410
prove/check_circuit_ms: 13024
prove/create_composer_ms: 0
> prove/create_prover_ms: 1326
prove/create_verifier_ms: 0
prove/execute_log_derivative_inverse_commitments_round_ms: 8681
> prove/execute_log_derivative_inverse_round_ms: 2744
prove/execute_pcs_rounds_ms: 1446
> prove/execute_relation_check_rounds_ms: 22424
prove/execute_wire_commitments_round_ms: 511
prove/gen_trace_ms: 1113

--- w/poseidon constraints 1 cpu

prove/all_ms: 121407
prove/check_circuit_ms: 35416
prove/create_composer_ms: 0
> prove/create_prover_ms: 3571
prove/create_verifier_ms: 0
prove/execute_log_derivative_inverse_commitments_round_ms: 8544
> prove/execute_log_derivative_inverse_round_ms: 5868
prove/execute_pcs_rounds_ms: 1864
> prove/execute_relation_check_rounds_ms: 63895
prove/execute_wire_commitments_round_ms: 541
prove/gen_trace_ms: 1599
IlyasRidhuan commented 3 months ago

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

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

AztecBot commented 3 months ago

Benchmark results

Metrics with a significant change:

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](https://aztec-ci-artifacts.s3.us-east-2.amazonaws.com/benchmarks-v1/pulls/7269.json). ### 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,706 | 1,537 | 703 | 736 | 768 | proof_construction_time_sha256_30_ms | 11,666 | 3,128 | 1,400 | 1,436 | 1,455 (-1%) | proof_construction_time_sha256_100_ms | 43,710 | 12,219 (-1%) | 5,652 | 5,601 (+1%) | 5,475 | proof_construction_time_poseidon_hash_ms | 78.0 | 34.0 | 34.0 | 57.0 (-3%) | 87.0 (-1%) | proof_construction_time_poseidon_hash_30_ms | 1,515 | 417 | 200 | 225 (-3%) | 269 (+2%) | proof_construction_time_poseidon_hash_100_ms | 5,580 (-1%) | 1,516 | 673 (-1%) | 744 (+2%) | 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 | 740 | 740 | 740 | l1_rollup_calldata_gas | 6,704 | 6,722 | 6,728 | l1_rollup_execution_gas | 611,971 | 612,140 | 612,297 | l2_block_processing_time_in_ms | 773 (+4%) | 1,415 | 2,719 (+3%) | l2_block_building_time_in_ms | 10,174 (+1%) | 19,976 (+1%) | 39,453 (+1%) | l2_block_rollup_simulation_time_in_ms | 10,174 (+1%) | 19,975 (+1%) | 39,453 (+1%) | l2_block_public_tx_process_time_in_ms | 8,456 (+1%) | 18,051 (+1%) | 37,430 (+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,075 (+1%) | 9,894 | node_database_size_in_bytes | 12,726,352 | 16,879,696 | 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 | 106 (-1%) | 394 (-5%) | 21,755 | 44,858 | N/A | N/A | N/A | N/A | private-kernel-inner | 174 | 681 (-6%) | 72,541 | 45,005 | N/A | N/A | N/A | N/A | private-kernel-tail | 729 | 905 (-5%) | 53,065 | 46,792 | N/A | N/A | N/A | N/A | base-parity | 6.41 (-1%) | 627 | 160 | 96.0 | :warning: 1,961 (**+40%**) | 13,188 | 19.0 | 131,072 | root-parity | 112 (-1%) | 128 (-1%) | 69,084 | 96.0 | 30,549 (-5%) | 13,188 | 19.0 | 4,194,304 | base-rollup | 3,240 | 4,920 (-3%) | 182,288 | 664 | 43,427 (-4%) | 14,020 | 45.0 | 4,194,304 | root-rollup | 156 | 117 (-6%) | 54,525 | 716 | 28,230 (+2%) | 13,988 | 44.0 | 4,194,304 | public-kernel-setup | 87.7 (+2%) | 2,659 (-3%) | 98,521 | 65,718 | 18,338 (-3%) | 123,076 | 3,453 | 2,097,152 | public-kernel-app-logic | 101 | 3,940 (-3%) | 98,521 | 65,718 | 10,888 (-5%) | 123,076 | 3,453 | 1,048,576 | public-kernel-tail | 622 | 26,334 (+4%) | 396,198 | 10,878 | 65,626 (-3%) | 26,436 | 433 | 8,388,608 | private-kernel-reset-tiny | 234 (+2%) | 872 (-6%) | 68,568 | 44,750 | N/A | N/A | N/A | N/A | private-kernel-tail-to-public | 5,374 | 1,592 (-5%) | 919,213 | 1,697 | N/A | N/A | N/A | N/A | public-kernel-teardown | 82.7 | 3,923 (-2%) | 98,521 | 65,718 | 19,718 | 123,076 | 3,453 | 2,097,152 | merge-rollup | 60.5 (+1%) | N/A | 35,742 | 664 | N/A | N/A | N/A | N/A | undefined | N/A | N/A | N/A | N/A | 156,076 (-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,344 | 11,731 | 343 (-1%) | N/A | N/A | ContractInstanceDeployer:deploy | 1,408 | 11,731 | 27.2 (-1%) | N/A | N/A | MultiCallEntrypoint:entrypoint | 1,920 | 11,731 | 605 | N/A | N/A | GasToken:deploy | 1,376 | 11,731 | 437 | N/A | N/A | SchnorrAccount:constructor | 1,312 | 11,731 | 429 | N/A | N/A | SchnorrAccount:entrypoint | 2,304 | 11,731 | 836 (+2%) | N/A | N/A | Token:privately_mint_private_note | 1,280 | 11,731 | 507 (+1%) | N/A | N/A | FPC:fee_entrypoint_public | 1,344 | 11,731 | 87.8 (-1%) | N/A | N/A | Token:transfer | 1,312 | 11,731 | 1,259 (-1%) | N/A | N/A | AuthRegistry:set_authorized (avm) | 18,491 | N/A | N/A | :warning: 148,864 (**+46%**) | :warning: 2,569 (**+30%**) | FPC:prepare_fee (avm) | 22,958 | N/A | N/A | :warning: 148,928 (**+46%**) | :warning: 3,219 (**+47%**) | Token:transfer_public (avm) | 46,881 | N/A | N/A | :warning: 148,928 (**+46%**) | :warning: 18,136 (**+175%**) | AuthRegistry:consume (avm) | 26,734 | N/A | N/A | :warning: 148,896 (**+46%**) | :warning: 4,723 (**+85%**) | FPC:pay_refund (avm) | 26,227 | N/A | N/A | :warning: 148,896 (**+46%**) | :warning: 7,515 (**+115%**) | Benchmarking:create_note | 1,344 | 11,731 | 447 (+6%) | N/A | N/A | SchnorrAccount:verify_private_authwit | 1,280 | 11,731 | 45.3 (-1%) | N/A | N/A | Token:unshield | 1,376 | 11,731 | 1,079 (-1%) | N/A | N/A | FPC:fee_entrypoint_private | 1,376 | 11,731 | 1,385 (-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 | 94.8 (-2%) | 8,139 | GasToken:set_portal | 14.9 (-4%) | 2,362 | Token:constructor | 122 (-4%) | 16,400 | FPC:constructor | 92.9 (-1%) | 9,304 | GasToken:mint_public | 80.6 (-1%) | 6,150 | Token:mint_public | :warning: 62.4 (**-33%**) | 11,720 | Token:assert_minter_and_mint | 49.7 (-12%) | 8,028 | AuthRegistry:set_authorized | 10.6 (+16%) | 4,537 | FPC:prepare_fee | 267 | 8,812 | Token:transfer_public | :warning: 44.0 (**+31%**) | 32,641 | FPC:pay_refund | 86.2 (+15%) | 12,114 | Benchmarking:increment_balance | 998 (+1%) | 7,450 | Token:_increase_public_balance | 12.0 (-5%) | 8,960 | FPC:pay_refund_with_shielded_rebate | 144 (-2%) | 12,663 | ### Public DB Access Time to access various public DBs. | Function | time_ms | | - | - | get-nullifier-index | 0.156 (+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 | 10.2 | 16.5 | 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.589 | 0.505 | N/A | N/A | N/A | N/A | N/A | batch_insert_into_append_only_tree_32_depth_ms | N/A | N/A | 47.5 (+1%) | 75.2 (+1%) | 130 (+1%) | 244 (+1%) | 480 (+5%) | 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.485 (+1%) | 0.461 (+1%) | 0.446 | 0.442 (+1%) | 0.448 (+4%) | batch_insert_into_indexed_tree_20_depth_ms | N/A | N/A | 59.0 (+1%) | 111 | 181 (+1%) | 351 (+1%) | 706 (+4%) | 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.497 (+1%) | 0.496 | 0.479 (+1%) | 0.475 | 0.485 (+4%) | batch_insert_into_indexed_tree_40_depth_ms | N/A | N/A | 72.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.512 | 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 | 59,093 | 663,472 | Transaction size based on fee payment method | Metric | | | - | |