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: refactor shared mutable to include private and unconstrained getters #7465

Closed

Conversation

sklppy88
Copy link
Contributor

Please read contributing guidelines and remove this line.

Copy link
Contributor Author

sklppy88 commented Jul 12, 2024

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

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

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

@AztecBot
Copy link
Collaborator

AztecBot commented Jul 12, 2024

Benchmark results

Metrics with a significant change:

  • protocol_circuit_proving_time_in_ms (root-parity): 30,102 (-40%)
  • protocol_circuit_proving_time_in_ms (public-kernel-setup): 17,517 (-21%)
  • protocol_circuit_proving_time_in_ms (public-kernel-teardown): 17,994 (-21%)
  • protocol_circuit_proving_time_in_ms (root-rollup): 28,104 (-31%)
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,771 (+7%) 1,554 (+5%) 708 (+6%) 748 (+3%) 770 (+6%)
proof_construction_time_sha256_30_ms 11,876 (+9%) 3,184 (+7%) 1,410 (+8%) 1,449 (+6%) 1,473 (+6%)
proof_construction_time_sha256_100_ms 44,146 (+6%) 11,926 (+5%) 5,433 (+7%) 5,397 (-5%) 5,377 (+6%)
proof_construction_time_poseidon_hash_ms 78.0 (+4%) 34.0 34.0 57.0 88.0 (-1%)
proof_construction_time_poseidon_hash_30_ms 1,528 (+6%) 417 (+4%) 201 (+4%) 219 (+2%) 264 (+1%)
proof_construction_time_poseidon_hash_100_ms 5,659 (+6%) 1,525 (+4%) 674 (+5%) 714 (+4%) 750 (+6%)

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 708 708 708
l1_rollup_calldata_gas 6,588 6,594 6,600
l1_rollup_execution_gas 583,050 583,207 583,364
l2_block_processing_time_in_ms 758 (-6%) 1,427 (-5%) 2,689 (-7%)
l2_block_building_time_in_ms 13,157 (-5%) 26,073 (-3%) 50,642 (-5%)
l2_block_rollup_simulation_time_in_ms 13,156 (-5%) 26,072 (-3%) 50,641 (-5%)
l2_block_public_tx_process_time_in_ms 11,026 (-5%) 23,720 (-3%) 48,269 (-5%)

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,103 (-5%) 10,068 (-4%)
node_database_size_in_bytes 12,468,304 16,441,424
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 116 (-4%) 403 (+2%) 21,732 54,085 N/A N/A N/A N/A
private-kernel-inner 229 (-3%) 701 (-1%) 81,199 54,264 N/A N/A N/A N/A
private-kernel-tail 1,127 (-1%) 2,488 (-1%) 61,808 61,554 N/A N/A N/A N/A
base-parity 6.42 (-5%) 811 (-6%) 160 96.0 1,965 (-2%) 12,676 3.00 131,072
root-parity 107 (-4%) 116 (-1%) 64,860 96.0 ⚠️ 30,102 (-40%) 12,676 3.00 4,194,304
base-rollup 4,222 (-3%) 4,765 (-3%) 180,315 632 42,911 (-12%) 13,476 28.0 4,194,304
root-rollup 151 (-6%) 122 (+1%) 51,261 652 ⚠️ 28,104 (-31%) 13,412 26.0 4,194,304
public-kernel-setup 199 (-2%) 2,328 (-4%) 112,536 80,310 ⚠️ 17,517 (-21%) 118,916 3,323 2,097,152
public-kernel-app-logic 150 (-3%) 3,206 (-2%) 112,536 80,310 10,131 (+1%) 118,916 3,323 1,048,576
public-kernel-tail 894 (-3%) 25,360 (-7%) 409,413 10,046 64,903 (-11%) 24,868 384 8,388,608
private-kernel-reset-tiny 298 (-4%) 987 (-1%) 77,007 53,954 N/A N/A N/A N/A
private-kernel-tail-to-public 6,715 (-1%) 2,831 777,415 1,632 N/A N/A N/A N/A
public-kernel-teardown 139 (-4%) 3,207 (-2%) 112,536 80,310 ⚠️ 17,994 (-21%) 118,916 3,323 2,097,152
merge-rollup 57.4 (-6%) N/A 33,566 632 N/A N/A N/A N/A
undefined N/A N/A N/A N/A 164,222 (+2%) 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,312 9,344 396 (-3%) N/A N/A
ContractInstanceDeployer:deploy 1,376 9,344 24.8 (-5%) N/A N/A
MultiCallEntrypoint:entrypoint 1,888 9,344 624 (-5%) N/A N/A
GasToken:deploy 1,344 9,344 570 (-3%) N/A N/A
SchnorrAccount:constructor 1,280 9,344 424 (-8%) N/A N/A
SchnorrAccount:entrypoint 2,272 9,344 757 (-7%) N/A N/A
Token:privately_mint_private_note 1,248 9,344 490 (-7%) N/A N/A
FPC:fee_entrypoint_public 1,312 9,344 100 (-3%) N/A N/A
Token:transfer 1,280 9,344 1,454 (-6%) N/A N/A
AuthRegistry:set_authorized (avm) 19,222 N/A N/A 95,392 2,041 (-4%)
FPC:prepare_fee (avm) 26,664 N/A N/A 95,456 2,763 (-2%)
Token:transfer_public (avm) 42,914 N/A N/A 95,456 3,132 (-2%)
AuthRegistry:consume (avm) 33,100 N/A N/A 95,424 2,691 (-4%)
FPC:pay_refund (avm) 36,829 N/A N/A 95,424 10,707 (-3%)
Benchmarking:create_note 1,312 9,344 422 (-10%) N/A N/A
SchnorrAccount:verify_private_authwit 1,248 9,344 41.5 (-10%) N/A N/A
Token:unshield 1,344 9,344 1,192 (-7%) N/A N/A
FPC:fee_entrypoint_private 1,344 9,344 1,548 (-7%) 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 97.6 (-2%) 13,790
GasToken:set_portal 13.2 (+2%) 3,339
Token:constructor 120 (-7%) 23,692
FPC:constructor 91.7 (+1%) 13,592
GasToken:mint_public 80.2 (-3%) 10,158
Token:mint_public 330 (-5%) 19,034
Token:assert_minter_and_mint 48.5 (-1%) 12,925
AuthRegistry:set_authorized 45.0 (-7%) 7,812
FPC:prepare_fee 107 (-12%) 15,062
Token:transfer_public 45.9 (+6%) 31,218
FPC:pay_refund 130 (+2%) 25,260
Benchmarking:increment_balance 1,343 (-4%) 15,267
Token:_increase_public_balance 14.9 (-19%) 15,006
FPC:pay_refund_with_shielded_rebate 183 (-9%) 26,347

Public DB Access

Time to access various public DBs.

Function time_ms
get-nullifier-index 0.159 (+4%)

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.3 (-4%) 16.7 (-4%) 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.597 (-5%) 0.512 (-5%) N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A 47.9 (-5%) 75.8 (-6%) 130 (-7%) 247 (-5%) 469 (-7%)
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.490 (-5%) 0.466 (-6%) 0.448 (-7%) 0.447 (-6%) 0.438 (-7%)
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 59.3 (-5%) 113 (-5%) 182 (-7%) 356 (-5%) 690 (-7%)
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.501 (-5%) 0.506 (-5%) 0.477 (-7%) 0.481 (-5%) 0.474 (-7%)
batch_insert_into_indexed_tree_40_depth_ms N/A N/A 72.7 (-5%) 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.517 (-5%) 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 76,837 667,838

Transaction size based on fee payment method

| Metric | |
| - | |

@sklppy88 sklppy88 changed the title init feat: refactor shared mutable to include private and unconstrained getters Jul 13, 2024
@sklppy88 sklppy88 force-pushed the ek/feat/7326/refactor-shared-mutable-to-include-getters branch from 26fc989 to 4efbe51 Compare July 13, 2024 10:06
@sklppy88 sklppy88 marked this pull request as ready for review July 15, 2024 14:41
@sklppy88 sklppy88 force-pushed the ek/feat/7326/add-unconstrained-getters-for-shared-mutable branch from 7471bf1 to 77b0685 Compare July 15, 2024 19:41
@sklppy88 sklppy88 force-pushed the ek/feat/7326/refactor-shared-mutable-to-include-getters branch from 4efbe51 to 42518ef Compare July 15, 2024 19:41
Copy link
Contributor

@nventuro nventuro left a comment

Choose a reason for hiding this comment

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

I'm not sure I'm a fan of the approach of methods for external reads, since it deviates quite a bit from other state variables, and will likely be quite dangerous. Raw acess to external contract state is not something we want to encourage: key rotation is an exception due to the massive performance impact, plus clear semantics around keys. But those kind of usecases are I think better served by helper functions, not core methods.

In my mind the largest issue with methods is the redundancy in the context object: we've modeled storage access in some execution, but then break that model by not using some of the context's values (in this case the address). The notion of 'my storage includes a shared mutable state variable, which I can read and write, but I can also use to read/write external variables as long as they look exactly like it' seems bizarre.

For the concrete SharedMutablePrivateGetter issue, I think I'd much rather have the struct be removed and replaced with a free-standing function, instead of trying to bundle it in the basic SharedMutable. But even then we're likely not going to use SharedMutable for key rotation (the major use case for the private getter), so we might as well not worry about this issue for the time being, and come back to it once our plans have better solidified.

@sklppy88 sklppy88 force-pushed the ek/feat/7326/add-unconstrained-getters-for-shared-mutable branch from 77b0685 to f70bcaf Compare July 15, 2024 20:57
@sklppy88 sklppy88 force-pushed the ek/feat/7326/refactor-shared-mutable-to-include-getters branch from 42518ef to 6898030 Compare July 15, 2024 21:01
@sklppy88 sklppy88 force-pushed the ek/feat/7326/add-unconstrained-getters-for-shared-mutable branch from f70bcaf to 2deb1bb Compare July 15, 2024 21:14
@sklppy88 sklppy88 force-pushed the ek/feat/7326/refactor-shared-mutable-to-include-getters branch from 6898030 to c391ca7 Compare July 15, 2024 21:14
@sklppy88 sklppy88 force-pushed the ek/feat/7326/add-unconstrained-getters-for-shared-mutable branch 2 times, most recently from 556fe66 to e6fedda Compare July 15, 2024 22:17
@sklppy88 sklppy88 marked this pull request as draft July 15, 2024 22:18
@sklppy88 sklppy88 force-pushed the ek/feat/7326/add-unconstrained-getters-for-shared-mutable branch from e6fedda to 9a2fb8b Compare July 15, 2024 22:23
Base automatically changed from ek/feat/7326/add-unconstrained-getters-for-shared-mutable to master July 15, 2024 23:33
@sklppy88 sklppy88 closed this Aug 9, 2024
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