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(avm-simulator): individual storage access #5095

Closed

Conversation

fcarreiro
Copy link
Contributor

@fcarreiro fcarreiro commented Mar 8, 2024

WARNING: PR waiting for resolution of blowup. See below.


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.

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)

Copy link
Contributor Author

fcarreiro commented Mar 8, 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 @fcarreiro and the rest of your teammates on Graphite Graphite

@AztecBot
Copy link
Collaborator

AztecBot commented Mar 8, 2024

Benchmark results

Metrics with a significant change:

  • tx_sequencer_processing_time_ms (0): 14.7 (+92%)
  • note_history_successful_decrypting_time_in_ms (5): 2,195 (+72%)
  • note_trial_decrypting_time_in_ms (8): 76.8 (+185%)
  • note_trial_decrypting_time_in_ms (64): 125 (+256%)
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 7f216eb0 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,908 238,780 469,436
l1_rollup_execution_gas 666,388 953,489 1,336,592
l2_block_processing_time_in_ms 1,392 (+5%) 5,018 (+5%) 9,500 (+1%)
note_successful_decrypting_time_in_ms 213 (-5%) 531 (+11%) 991 (-1%)
note_trial_decrypting_time_in_ms ⚠️ 76.8 (+185%) 48.7 (-50%) ⚠️ 125 (+256%)
l2_block_building_time_in_ms 12,402 (+1%) 49,916 (+3%) 97,921 (+1%)
l2_block_rollup_simulation_time_in_ms 7,382 (+1%) 30,164 (+4%) 58,425 (+1%)
l2_block_public_tx_process_time_in_ms 4,982 (+1%) 19,678 (+1%) 39,288 (+1%)

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,510 (+2%) 28,888 (+4%)
note_history_successful_decrypting_time_in_ms ⚠️ 2,195 (+72%) 2,788 (+13%)
note_history_trial_decrypting_time_in_ms 166 (+46%) 156 (-18%)
node_database_size_in_bytes 19,091,536 (+2%) 35,684,432 (+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 280 (+3%) 44,338 27,700
private-kernel-ordering 212 (+2%) 52,324 14,326
base-rollup 686 (+4%) 177,083 925
root-rollup 76.7 (+12%) 4,176 789
private-kernel-inner 376 (+5%) 73,197 27,700
public-kernel-app-logic 184 (+3%) 34,582 27,671
public-kernel-tail 93.7 (+2%) 34,206 27,671
merge-rollup 9.80 (+18%) 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 10.8 (+8%) 16.9 (+5%) 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.630 (+8%) 0.524 (+5%) 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 50.3 (+10%) 72.5 (-2%) 230 443 (-1%) 864 1,723 (-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.517 (+10%) 0.448 (-2%) 0.420 0.416 (-1%) 0.411 0.413 (-1%) N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 58.6 (+9%) 106 334 656 1,312 2,616 (+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.523 (+10%) 0.478 0.455 0.452 0.454 0.453 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 65.3 (+7%)
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.571 (+7%)

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,019 (+7%) 1,480 (+3%)
Metric 0 public data writes 1 public data writes
tx_sequencer_processing_time_ms ⚠️ 14.7 (+92%) 629 (+3%)

@fcarreiro fcarreiro force-pushed the fc/external-static-calls branch 2 times, most recently from a8ed02a to 00aa89a Compare March 11, 2024 11:19
Base automatically changed from fc/external-static-calls to master March 11, 2024 11:23
@fcarreiro fcarreiro force-pushed the fc/avm-individual-storage branch 3 times, most recently from 1581cb6 to 6bd2e17 Compare March 11, 2024 15:45
@fcarreiro fcarreiro changed the title WIP: individual storage access feat(avm-simulator): individual storage access Mar 11, 2024
@fcarreiro fcarreiro force-pushed the fc/avm-individual-storage branch 2 times, most recently from f91d4b6 to 9c5ab33 Compare March 11, 2024 17:18
@fcarreiro fcarreiro changed the base branch from master to fc/even-more-bytecode-please March 11, 2024 23:46
@fcarreiro fcarreiro closed this Mar 12, 2024
@fcarreiro fcarreiro deleted the fc/avm-individual-storage branch April 9, 2024 09:40
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.

None yet

3 participants