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: individual storage access #5153

Closed
wants to merge 3 commits into from
Closed

Conversation

fcarreiro
Copy link
Contributor

@fcarreiro fcarreiro commented Mar 12, 2024

WARNING: PR waiting for resolution of blowup. See below.
@sirasistant analyzed and filed noir-lang/noir#4535


This PR updates the oracle storageRead/Write interface to take and return just 1 value, instead of an array of values. However, the function storage_write<N> actually used in Noir still takes/returns an array, and does a loop calling the oracle.

  • The oracle storageWrite was returning a value which was not used. This is due to an ACVM limitation, see below.

The reason for the change is, quoting Sean: "that it's easier for the AVM to prove single-access to memory". IIUC, we want the traces to contain single access, and our AVM opcodes handle that.

This change is NOT trivial, since it implied changing the ACVM and oracle interface. In particular

  • The ACVM oracle interface assumed that every oracle function returned a value (or array of values).
  • I made some changes so that void oracles are possible.

NOTE FOR THE REVIEWER: Sean gave an informal approval on the AVM side, please review everything else. If you are not familiar with the code please let me know of a possible reviewer.


This causes a blowup in instructions for storage access (even to a single field).

Before

open avm_setAdmin() 
        function signature: avm_setAdmin()
        selector: 0xb2a1e760
        bytecode: 555 bytes (sha256 174bb4bfe990d33a453a93706abd25cbe921cbb67bdb3acaa04e4308cdc425ef)

After (name changed)

open avm_setStorageSingle(a: Field) 
        function signature: avm_setStorageSingle(Field)
        selector: 0x928e2ba7
        bytecode: 31619 bytes (sha256 40219438c1fd8f261482505c305bd0530dbc19f02c35ad8067b8a5263db2b55a)

SSA optimization before: file.

  • This has the initial SSA and the final one after that.

SSA optimization after: file.

  • This has the final (not really optimized) result.

Copy link
Contributor Author

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

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

@AztecBot
Copy link
Collaborator

Benchmark results

Metrics with a significant change:

  • tx_sequencer_processing_time_ms (0): 14.4 (+100%)
  • note_successful_decrypting_time_in_ms (8): 148 (-34%)
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 932c1d50 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 5,668 18,820 36,356
l1_rollup_calldata_gas 65,980 238,744 468,644
l1_rollup_execution_gas 666,612 953,605 1,335,952
l2_block_processing_time_in_ms 1,271 (-3%) 4,706 9,447 (+5%)
note_successful_decrypting_time_in_ms ⚠️ 148 (-34%) 516 (-9%) 1,012 (+2%)
note_trial_decrypting_time_in_ms 52.5 (+62%) 31.7 (-60%) 36.5 (-71%)
l2_block_building_time_in_ms 11,945 47,290 (+1%) 94,393
l2_block_rollup_simulation_time_in_ms 6,965 27,696 (+1%) 55,281 (-1%)
l2_block_public_tx_process_time_in_ms 4,956 19,537 39,012

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 13,974 (+2%) 27,023 (-2%)
note_history_successful_decrypting_time_in_ms 1,261 (+5%) 2,496 (+5%)
note_history_trial_decrypting_time_in_ms 91.5 (+42%) 198 (+60%)
node_database_size_in_bytes 19,075,152 (+2%) 35,614,800 (+1%)
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 264 (-3%) 44,338 27,700
private-kernel-ordering 200 (-3%) 52,324 14,326
base-rollup 619 (-1%) 177,083 925
root-rollup 67.0 (-4%) 4,176 789
private-kernel-inner 352 (-2%) 73,197 27,700
public-kernel-app-logic 175 (-2%) 34,582 27,671
public-kernel-tail 90.1 (-2%) 34,206 27,671
merge-rollup 8.18 (-1%) 2,696 925

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 9.76 (-3%) 15.6 (-3%) 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.570 (-3%) 0.483 (-3%) 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 45.9 70.6 (-2%) 229 (-1%) 431 (-2%) 860 (-1%) 1,709 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.471 0.436 (-2%) 0.418 (-1%) 0.404 (-3%) 0.410 0.411 N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 52.8 (-2%) 104 (-2%) 334 641 (-2%) 1,302 (-1%) 2,594 (-1%) N/A
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 104 207 691 1,363 2,707 5,395 N/A
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A 0.471 (-2%) 0.472 (-2%) 0.455 0.441 (-3%) 0.452 (-2%) 0.452 (-1%) 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 60.2 (-1%)
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.526 (-2%)

Miscellaneous

Transaction sizes based on how many contract classes are registered in the tx.

Metric 0 registered classes
tx_size_in_bytes 22,014 (+15%)

Transaction processing duration by data writes.

Metric 0 new note hashes 1 new note hashes
tx_pxe_processing_time_ms 3,001 (+7%) 1,397 (-3%)
Metric 0 public data writes 1 public data writes
tx_sequencer_processing_time_ms ⚠️ 14.4 (+100%) 601 (-1%)

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.

2 participants