AztecProtocol / aztec-packages

Apache License 2.0
155 stars 156 forks source link

refactor: gets rid of unencrypted emit in private_context #7236

Closed LHerskind closed 3 hours ago

LHerskind commented 2 days ago

This pr took a stab at something we had discussed related to #7161:

Since having unencrypted emits easily available in the private context is a huge footgun privacy-wise, we decided that it would be better to get rid of it there. However, as we still needed it for the deployer (as we need something to deploy the "first" public code), we left the public inputs and just insert directly into those instead of using a neat function.

The setup is still slightly different from what we are doing in private, because it is dealing with event_type_id slightly odd, and doing a lot of inefficient things. So it needs to be revisited at some point for optimisations. When the event macros are refined to also handle structs with non-field elements we should be able to use a to_be_bytes value from in there to more cleanly emit the event, and also update the "listener" such that we could get rid of the current DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE and instead be looking at just the event_type_id and the contract address to match it.

LHerskind commented 2 days ago

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

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

AztecBot commented 2 days 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/7236.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_30_ms | 11,474 (+1%) | 3,085 (+1%) | 1,427 (-13%) | 1,415 (-8%) | 1,547 (-3%) | proof_construction_time_sha256_100_ms | 44,154 (+1%) | 11,848 | 5,457 | 5,443 | 5,366 | proof_construction_time_poseidon_hash_ms | 78.0 (-1%) | 34.0 | 34.0 | 58.0 | 88.0 (+1%) | proof_construction_time_poseidon_hash_30_ms | 1,525 | 417 (-4%) | 199 | 225 | 267 (-1%) | proof_construction_time_poseidon_hash_100_ms | 5,782 | 1,574 | 721 | 768 (-4%) | 800 | ### 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,464 | 9,470 | 9,428 (-1%) | l1_rollup_execution_gas | 610,285 | 610,291 | 610,249 | l2_block_processing_time_in_ms | 748 (-1%) | 1,499 (+6%) | :warning: 3,451 (**+28%**) | l2_block_building_time_in_ms | 28,042 (+14%) | 50,722 (+2%) | :warning: 111,798 (**+16%**) | l2_block_rollup_simulation_time_in_ms | 28,042 (+14%) | 50,722 (+2%) | :warning: 111,798 (**+16%**) | l2_block_public_tx_process_time_in_ms | :warning: 24,489 (**+16%**) | 46,975 (+3%) | :warning: 108,043 (**+17%**) | ### 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,202 (+2%) | 10,147 (+3%) | node_database_size_in_bytes | 12,193,872 | 16,072,784 | 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 | 126 (+8%) | 534 (+11%) | 13,011 (-2%) | 20,634 | 67,190 | 92,352 | 2,819 | 524,288 | private-kernel-inner | 389 (+8%) | 1,066 (+14%) | 48,592 (-9%) | 94,902 | 67,190 | 92,352 | 2,819 | 2,097,152 | private-kernel-tail | 322 (+7%) | 1,762 (-4%) | 50,238 (-2%) | 99,121 | 71,733 | 14,912 | 399 | 2,097,152 | base-parity | 6.34 (-1%) | 1,827 (-1%) | 2,738 | 128 | 64.0 | 2,208 | 2.00 | 131,072 | root-parity | 54.3 (+10%) | 79.8 (+7%) | 40,941 (+3%) | 27,100 | 64.0 | 2,720 | 18.0 | 2,097,152 | base-rollup | 8,164 (+6%) | 4,952 (-1%) | 87,279 | 170,330 | 756 | 3,648 | 47.0 | 4,194,304 | root-rollup | 112 (+1%) | 91.8 (+4%) | 24,577 (+6%) | 25,309 | 620 | 3,456 | 41.0 | 1,048,576 | public-kernel-setup | 642 (-1%) | 3,747 (+1%) | 45,671 (+1%) | 116,905 | 93,334 | 125,344 | 3,850 | 2,097,152 | public-kernel-app-logic | 618 (+5%) | 4,723 (-2%) | 47,610 (+1%) | 116,905 | 93,334 | 125,344 | 3,850 | 2,097,152 | public-kernel-tail | 1,453 (+4%) | 34,887 (-9%) | 198,662 (-2%) | 511,910 | 10,014 | 14,912 | 399 | 8,388,608 | private-kernel-reset-small | 590 (+7%) | 1,953 (-2%) | 46,144 (-4%) | 123,313 | 67,190 | 92,352 | 2,819 | 2,097,152 | public-kernel-teardown | 581 (-1%) | 4,809 | 46,003 | 116,905 | 93,334 | 125,344 | 3,850 | 2,097,152 | merge-rollup | 30.3 (+5%) | N/A | N/A | 16,542 | 756 | N/A | N/A | N/A | private-kernel-tail-to-public | N/A | 7,096 (+2%) | 96,526 (-1%) | N/A | N/A | 125,344 | 3,850 | 4,194,304 | 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 | 9,944 | 421 (+3%) | N/A | N/A | N/A | N/A | ContractInstanceDeployer:deploy | 1,408 | 9,944 | 42.8 (+7%) | N/A | N/A | N/A | N/A | MultiCallEntrypoint:entrypoint | 1,920 | 9,944 | 1,942 (+10%) | N/A | N/A | N/A | N/A | GasToken:deploy | 1,376 | 9,944 | 965 (-1%) | N/A | N/A | N/A | N/A | SchnorrAccount:constructor | 1,312 | 9,944 | 1,509 (+7%) | N/A | N/A | N/A | N/A | SchnorrAccount:entrypoint | 2,304 | 9,944 | 2,932 (+4%) | 16,768 | 56,532 (-3%) | 2,097,152 | 457 | Token:privately_mint_private_note | 1,280 | 9,944 | 1,633 (-1%) | N/A | N/A | N/A | N/A | FPC:fee_entrypoint_public | 1,344 | 9,944 | 359 (+1%) | 16,768 | 11,206 (-1%) | 524,288 | 457 | Token:transfer | 1,312 | 9,944 | 4,517 (-1%) | 16,768 | 46,721 (-2%) | 2,097,152 | 457 | AuthRegistry:set_authorized (avm) | 20,996 | N/A | N/A | 94,208 (+8%) | 1,364 (+1%) | N/A | N/A | FPC:prepare_fee (avm) | 28,484 | N/A | N/A | 94,272 (+7%) | 5,674 (-3%) | N/A | N/A | Token:transfer_public (avm) | 44,705 | N/A | N/A | 94,272 (+7%) | 3,916 | N/A | N/A | AuthRegistry:consume (avm) | 34,874 | N/A | N/A | 94,208 (+7%) | 2,926 (-1%) | N/A | N/A | FPC:pay_refund (avm) | 38,649 | N/A | N/A | 94,240 (+6%) | 23,270 (+1%) | N/A | N/A | Benchmarking:create_note | 1,344 | 9,944 | 1,440 (+3%) | N/A | N/A | N/A | N/A | SchnorrAccount:verify_private_authwit | 1,280 | 9,944 | 72.8 (-4%) | N/A | N/A | N/A | N/A | Token:unshield | 1,376 | 9,944 | 3,688 (-6%) | N/A | N/A | N/A | N/A | FPC:fee_entrypoint_private | 1,376 | 9,944 | 4,597 (-6%) | 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.1 | 13,800 | GasToken:set_portal | 17.3 (-5%) | 3,315 | Token:constructor | 94.1 (-2%) | 23,719 | FPC:constructor | 63.5 | 13,653 | GasToken:mint_public | 51.9 (-4%) | 10,168 | Token:mint_public | :warning: 600 (**+770%**) | 19,010 | Token:assert_minter_and_mint | :warning: 72.1 (**-67%**) | 12,901 | AuthRegistry:set_authorized | 32.8 (+3%) | 7,822 | FPC:prepare_fee | :warning: 194 (**+31%**) | 15,118 | Token:transfer_public | 52.8 (+14%) | 31,245 | FPC:pay_refund | 174 (-8%) | 25,316 | Benchmarking:increment_balance | 2,715 (+4%) | 15,289 | Token:_increase_public_balance | 56.4 (-3%) | 14,982 | FPC:pay_refund_with_shielded_rebate | 198 (+6%) | 26,403 | ### Public DB Access Time to access various public DBs. | Function | time_ms | | - | - | get-nullifier-index | 0.157 | ### 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.8 (+3%) | 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.623 (+3%) | 0.516 | N/A | N/A | N/A | N/A | N/A | batch_insert_into_append_only_tree_32_depth_ms | N/A | N/A | 50.7 (+4%) | 76.5 (+1%) | 132 | 252 (+2%) | 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.518 (+4%) | 0.469 (+1%) | 0.452 | 0.456 (+2%) | 0.439 | batch_insert_into_indexed_tree_20_depth_ms | N/A | N/A | 62.1 (+3%) | 113 (+1%) | 182 (-1%) | 378 (+7%) | :warning: 1,049 (**+52%**) | 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.529 (+4%) | 0.507 (+1%) | 0.479 (-1%) | 0.513 (+7%) | :warning: 0.737 (**+55%**) | batch_insert_into_indexed_tree_40_depth_ms | N/A | N/A | 77.7 (+6%) | 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.554 (+6%) | 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 | 85,707 | 670,983 | Transaction size based on fee payment method | Metric | | | - | |