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: frontier lib > frontier contract #8172

Merged
merged 1 commit into from
Aug 26, 2024
Merged

Conversation

LHerskind
Copy link
Contributor

@LHerskind LHerskind commented Aug 24, 2024

#8114

Updating the inbox to use a library instead of separate contracts such that:

  • Each tree are in the same contract
  • zeros, height and size are shared between all which cuts down a lot of compute
  • Creating a new tree require NO big setup.

Notable savings:

  • Inbox::consume: 201631 -> 27700 in median gas
  • Inbox::sendL2Message: 249556 -> 79344 in max
  • Rollup::process: 310435 -> 166554 median

Also added a revert case when reading past what have been build.

Copy link
Contributor Author

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

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

@LHerskind LHerskind force-pushed the lh/8114-inbox-optimisations branch from a4d2fd4 to 42313a0 Compare August 24, 2024 11:08
@AztecBot
Copy link
Collaborator

Benchmark results

Metrics with a significant change:

  • protocol_circuit_simulation_time_in_ms (private-kernel-tail-to-public): 770 (+17%)
  • avm_simulation_time_ms (Token:mint_public): 69.6 (+56%)
  • avm_simulation_time_ms (Token:assert_minter_and_mint): 41.2 (-37%)
  • l1_rollup_execution_gas (4): 842,993 (-40%)
  • l1_rollup_execution_gas (8): 1,576,655 (-26%)
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,730 1,559 708 750 (+1%) 773
proof_construction_time_sha256_30_ms 11,469 3,095 1,386 (+1%) 1,438 1,451
proof_construction_time_sha256_100_ms 44,115 11,821 5,434 5,639 (+3%) 5,739 (+2%)
proof_construction_time_poseidon_hash_ms 78.0 34.0 34.0 58.0 (+2%) 87.0
proof_construction_time_poseidon_hash_30_ms 1,529 422 (+1%) 202 227 279 (+2%)
proof_construction_time_poseidon_hash_100_ms 5,648 1,511 680 (+1%) 714 (-4%) 746

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 4,356 7,876 14,884
l1_rollup_calldata_gas 50,208 92,974 178,180
l1_rollup_execution_gas ⚠️ 842,993 (-40%) ⚠️ 1,576,655 (-26%) 3,361,917 (-14%)
l2_block_processing_time_in_ms 255 (+3%) 445 (+1%) 825
l2_block_building_time_in_ms 11,354 22,254 (-1%) 44,321
l2_block_rollup_simulation_time_in_ms 11,354 22,253 (-1%) 44,321
l2_block_public_tx_process_time_in_ms 9,626 20,453 (-1%) 42,477

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 2,994 (+3%) 3,877 (+1%)
node_database_size_in_bytes 12,644,432 16,748,624
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
private-kernel-init 85.4 (+1%) 378 (-5%) 21,755 44,860 N/A
private-kernel-inner 171 (+1%) 693 (-2%) 72,566 45,007 N/A
private-kernel-reset-tiny 308 698 (-3%) 65,590 44,846 N/A
private-kernel-tail 162 136 (-3%) 50,643 52,257 N/A
base-parity 5.56 (-1%) N/A 160 96.0 N/A
root-parity 35.0 (-1%) N/A 73,948 96.0 N/A
base-rollup 3,452 N/A 189,136 664 N/A
block-root-rollup 41.1 (-1%) N/A 58,205 2,448 N/A
public-kernel-setup 82.4 (-3%) N/A 105,085 71,222 N/A
public-kernel-app-logic 95.2 (-1%) N/A 104,911 71,222 N/A
public-kernel-tail 866 (-1%) N/A 390,582 16,414 N/A
private-kernel-reset-small 303 (-1%) N/A 66,341 45,629 N/A
private-kernel-tail-to-public ⚠️ 770 (+17%) 586 (-5%) 455,020 1,825 N/A
public-kernel-teardown 81.8 (-1%) N/A 105,349 71,222 N/A
merge-rollup 20.2 (-2%) N/A 38,174 664 N/A
undefined N/A N/A N/A N/A 80,707 (+5%)

Stats on running time collected for app circuits

Function input_size_in_bytes output_size_in_bytes witness_generation_time_in_ms
ContractClassRegisterer:register 1,344 11,731 341 (-1%)
ContractInstanceDeployer:deploy 1,408 11,731 18.1 (-2%)
MultiCallEntrypoint:entrypoint 1,920 11,731 404 (-1%)
FeeJuice:deploy 1,376 11,731 383 (-2%)
SchnorrAccount:constructor 1,312 11,731 74.6 (-1%)
SchnorrAccount:entrypoint 2,304 11,731 396 (-1%)
Token:privately_mint_private_note 1,280 11,731 103 (+3%)
FPC:fee_entrypoint_public 1,344 11,731 28.1 (+2%)
Token:transfer 1,312 11,731 224 (-1%)
Benchmarking:create_note 1,344 11,731 88.1 (-1%)
SchnorrAccount:verify_private_authwit 1,280 11,731 27.7 (-2%)
Token:unshield 1,376 11,731 529
FPC:fee_entrypoint_private 1,376 11,731 786 (+12%)

AVM Simulation

Time to simulate various public functions in the AVM.

Function time_ms bytecode_size_in_bytes
FeeJuice:_increase_public_balance 55.5 7,739
FeeJuice:set_portal 11.2 (+4%) 2,354
Token:constructor 81.5 (+5%) 26,051
FPC:constructor 54.0 (+1%) 18,001
FeeJuice:mint_public 38.3 (-3%) 5,877
Token:mint_public ⚠️ 69.6 (+56%) 10,917
Token:assert_minter_and_mint ⚠️ 41.2 (-37%) 7,512
AuthRegistry:set_authorized 45.7 (+23%) 4,391
FPC:prepare_fee 224 (-5%) 7,043
Token:transfer_public 30.9 39,426
FPC:pay_refund 59.5 (+17%) 10,234
Benchmarking:increment_balance 1,198 (-1%) 6,563
Token:_increase_public_balance 40.7 (+1%) 8,433
FPC:pay_refund_with_shielded_rebate 63.5 10,783

Public DB Access

Time to access various public DBs.

Function time_ms
get-nullifier-index 0.163 (+3%)

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 2.17 (-2%) 3.84 (-1%) 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.112 (-2%) 0.108 (-1%) N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A 11.1 (-2%) 17.7 (+1%) 31.9 (+3%) 58.7 (-1%) 112 (-2%)
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.106 (-2%) 0.103 (+1%) 0.103 (+3%) 0.101 0.101 (-1%)
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 14.3 25.5 (-2%) 43.4 (-1%) 81.9 (-2%) 161
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.108 (-1%) 0.103 (-2%) 0.105 0.101 (-1%) 0.102 (+1%)
batch_insert_into_indexed_tree_40_depth_ms N/A N/A 16.5 N/A N/A N/A N/A
batch_insert_into_indexed_tree_40_depth_hash_count N/A N/A 132 N/A N/A N/A N/A
batch_insert_into_indexed_tree_40_depth_hash_ms N/A N/A 0.106 (-1%) 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 64,779 668,997

Transaction size based on fee payment method

| Metric | |
| - | |

@LHerskind LHerskind marked this pull request as ready for review August 26, 2024 08:00
@Maddiaa0 Maddiaa0 merged commit 717cf3d into master Aug 26, 2024
97 checks passed
@Maddiaa0 Maddiaa0 deleted the lh/8114-inbox-optimisations branch August 26, 2024 08:37
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