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 executor - layout and groundwork #3928

Merged
merged 20 commits into from
Jan 16, 2024
Merged

Conversation

Maddiaa0
Copy link
Member

@Maddiaa0 Maddiaa0 commented Jan 10, 2024

Base work for avm - heavily a wip -> making a pr now for eyeballs

Key ideas:
Executor:

  • There is an Avm Executor that has a reference to the current node state
  • Any avm calls are triggered by interacting with the executor
    • fetching bytecode
    • triggering the interpreter

Interpreter:

  • The interpreter contains:
    • The bytecode to execute, and a statemanager

AvmStateManager:

  • The interpreter uses this as its source of truth when requesting data. It is a thin layer between the dbs that handles caching and rolling back state of failed calls.

Journal
Rather than reading and writing to the db, we introduce a journal.
All intermediate storage operations are read from here.
Journal structure:

  • When a call ends; it is merged with the caller's journal
  • When a transaction succeeds the journal is merged with the blocks journal
  • When a block succeeds a journal is commited to db.

Opcode structure
Each opcode takes in a view of the state manager and the current call context.

  • storage operations impact the current journal through the state manager
  • jump instructions can impact the current opcode via changing the pc in the context

This diagram loosely shows the structure
image

fixes: #3317

@AztecBot
Copy link
Collaborator

AztecBot commented Jan 10, 2024

Benchmark results

Metrics with a significant change:

  • batch_insert_into_indexed_tree_ms (512): 529 (+47%)
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 9f61ed1f 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 128 txs
l1_rollup_calldata_size_in_bytes 45,444 179,588 716,132
l1_rollup_calldata_gas 221,040 865,868 3,445,916
l1_rollup_execution_gas 934,184 3,968,342 24,789,452
l2_block_processing_time_in_ms 1,515 (+14%) 5,158 (+2%) 21,527 (+2%)
note_successful_decrypting_time_in_ms 312 (+1%) 945 (+3%) 3,414 (+2%)
note_trial_decrypting_time_in_ms 21.3 70.6 (+55%) 146 (+12%)
l2_block_building_time_in_ms 14,877 59,295 238,639 (+1%)
l2_block_rollup_simulation_time_in_ms 10,499 41,962 (+1%) 169,479 (+1%)
l2_block_public_tx_process_time_in_ms 4,343 17,256 68,886 (+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,942 (-1%) 28,718
note_history_successful_decrypting_time_in_ms 2,207 4,487 (+4%)
note_history_trial_decrypting_time_in_ms 116 (-10%) 186 (+16%)
node_database_size_in_bytes 3,627,127 3,723,872
pxe_database_size_in_bytes 29,923 59,478

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 213 44,681 25,561
private-kernel-ordering 165 43,753 14,809
base-rollup 1,064 128,338 881
root-rollup 82.1 (+2%) 4,088 709
private-kernel-inner 291 71,208 25,561
public-kernel-private-input 205 31,863 25,561
public-kernel-non-first-iteration 203 31,905 25,561
merge-rollup 8.28 (+1%) 2,608 881

Tree insertion stats

The duration to insert a fixed batch of leaves into each tree type.

Metric 1 leaves 2 leaves 8 leaves 16 leaves 32 leaves 64 leaves 128 leaves 512 leaves 1024 leaves 2048 leaves 8192 leaves
batch_insert_into_append_only_tree_ms 11.2 (+1%) 16.9 (+7%) 13.6 18.0 (+1%) 24.2 (+3%) 50.1 (+1%) 84.2 (+9%) 243 469 916 (+1%) 3,704 (+4%)
batch_insert_into_indexed_tree_ms N/A N/A N/A 64.5 N/A 60.0 (+1%) 110 (-4%) ⚠️ 529 (+47%) 732 (-1%) 1,412 (+1%) 5,596 (+1%)

Miscellaneous

Transaction sizes based on how many contracts are deployed in the tx.

Metric 0 deployed contracts 1 deployed contracts
tx_size_in_bytes 15,455 32,224

Transaction processing duration by data writes.

Metric 0 new commitments 1 new commitments
tx_pxe_processing_time_ms 374 1,083
Metric 1 public data writes
tx_sequencer_processing_time_ms 535

Copy link
Member Author

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

@Maddiaa0 Maddiaa0 changed the title wip: avm executor feat: avm executor - layout and groundwork Jan 11, 2024
@Maddiaa0 Maddiaa0 marked this pull request as ready for review January 11, 2024 18:08
@Maddiaa0 Maddiaa0 requested a review from dbanks12 January 11, 2024 18:08
Copy link
Collaborator

@dbanks12 dbanks12 left a comment

Choose a reason for hiding this comment

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

Very nice work! Left some comments (mostly minor).

@Maddiaa0 Maddiaa0 requested a review from dbanks12 January 12, 2024 21:26
Copy link
Collaborator

@dbanks12 dbanks12 left a comment

Choose a reason for hiding this comment

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

LGTM, but we should still resolve the remaining comments :)

@dbanks12 dbanks12 merged commit 432f6d1 into master Jan 16, 2024
85 checks passed
@dbanks12 dbanks12 deleted the md/public-vm-executor branch January 16, 2024 20:26
michaelelliot pushed a commit to Swoir/noir_rs that referenced this pull request Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

public-vm(ts): minimal VM simulation (ADD, CALLDATACOPY, RETURN, field memory only)
3 participants