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: add totalFees to global variables #6439

Closed

Conversation

just-mitch
Copy link
Collaborator

@just-mitch just-mitch commented May 15, 2024

Add totalFees to global variables. Update the spec.

Note: we could have had the L1 rollup contract iterate over all the tx_effects and pay out that way. Doing it ourselves in the circuit feels cheaper though, and maybe safer for a world where:

  1. tx_effects are spread over multiple l1 blocks
  2. tx_effects are published as blobs so we wouldn't have direct access to math over them on l1.

Copy link
Collaborator Author

just-mitch commented May 15, 2024

Base automatically changed from 05-15-feat_pay_out_arbitrary_fee_to_coinbase_on_l1 to master May 15, 2024 20:33
Copy link
Contributor

github-actions bot commented May 15, 2024

Changes to circuit sizes

Generated at commit: 381633bf656b1cc1d4051d2bfd690b08df0e8929, compared to commit: 6417cd905ab032c6724b6c07082e81f67d5f750f

🧾 Summary (100% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
public_kernel_setup +132,805 ❌ +152.18% +330,486 ❌ +99.80%
public_kernel_teardown +132,808 ❌ +151.81% +330,489 ❌ +99.71%
public_kernel_app_logic +133,116 ❌ +116.20% +364,861 ❌ +85.71%
public_kernel_tail +378,897 ❌ +58.27% +1,650,757 ❌ +80.18%
private_kernel_reset +84,517 ❌ +51.11% +745,133 ❌ +42.79%
private_kernel_inner_simulated 0 ➖ 0.00% +722 ❌ +38.34%
private_kernel_reset_simulated 0 ➖ 0.00% +722 ❌ +38.34%
private_kernel_init_simulated 0 ➖ 0.00% +722 ❌ +38.34%
private_kernel_tail_to_public_simulated 0 ➖ 0.00% +722 ❌ +26.02%
public_kernel_setup_simulated 0 ➖ 0.00% +722 ❌ +26.02%
public_kernel_teardown_simulated 0 ➖ 0.00% +722 ❌ +26.02%
public_kernel_app_logic_simulated 0 ➖ 0.00% +722 ❌ +26.02%
private_kernel_init +62,048 ❌ +37.98% +147,556 ❌ +21.71%
private_kernel_inner +67,934 ❌ +35.46% +290,732 ❌ +20.76%
private_kernel_tail +3,656 ❌ +1.91% +118,453 ❌ +9.94%
private_kernel_tail_to_public +4,376 ❌ +0.72% +119,891 ❌ +5.99%
rollup_base_simulated 0 ➖ 0.00% +1 ❌ +2.17%
public_kernel_tail_simulated 0 ➖ 0.00% +2 ❌ +0.75%
private_kernel_tail_simulated 0 ➖ 0.00% +2 ❌ +0.75%
rollup_root +2 ❌ +0.14% +314 ❌ +0.11%
rollup_base +10 ❌ +0.01% +318 ❌ +0.02%
rollup_merge +2 ❌ +0.66% 0 ➖ 0.00%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
public_kernel_setup 220,072 (+132,805) +152.18% 661,643 (+330,486) +99.80%
public_kernel_teardown 220,289 (+132,808) +151.81% 661,947 (+330,489) +99.71%
public_kernel_app_logic 247,671 (+133,116) +116.20% 790,569 (+364,861) +85.71%
public_kernel_tail 1,029,194 (+378,897) +58.27% 3,709,605 (+1,650,757) +80.18%
private_kernel_reset 249,887 (+84,517) +51.11% 2,486,571 (+745,133) +42.79%
private_kernel_inner_simulated 1 (0) 0.00% 2,605 (+722) +38.34%
private_kernel_reset_simulated 1 (0) 0.00% 2,605 (+722) +38.34%
private_kernel_init_simulated 1 (0) 0.00% 2,605 (+722) +38.34%
private_kernel_tail_to_public_simulated 1 (0) 0.00% 3,497 (+722) +26.02%
public_kernel_setup_simulated 1 (0) 0.00% 3,497 (+722) +26.02%
public_kernel_teardown_simulated 1 (0) 0.00% 3,497 (+722) +26.02%
public_kernel_app_logic_simulated 1 (0) 0.00% 3,497 (+722) +26.02%
private_kernel_init 225,432 (+62,048) +37.98% 827,333 (+147,556) +21.71%
private_kernel_inner 259,539 (+67,934) +35.46% 1,691,250 (+290,732) +20.76%
private_kernel_tail 195,188 (+3,656) +1.91% 1,310,347 (+118,453) +9.94%
private_kernel_tail_to_public 612,365 (+4,376) +0.72% 2,120,690 (+119,891) +5.99%
rollup_base_simulated 1 (0) 0.00% 47 (+1) +2.17%
public_kernel_tail_simulated 1 (0) 0.00% 268 (+2) +0.75%
private_kernel_tail_simulated 1 (0) 0.00% 268 (+2) +0.75%
rollup_root 1,407 (+2) +0.14% 296,070 (+314) +0.11%
rollup_base 181,037 (+10) +0.01% 1,772,806 (+318) +0.02%
rollup_merge 304 (+2) +0.66% 45,980 (0) 0.00%

@just-mitch just-mitch force-pushed the 05-15-feat_add_totalfees_to_global_variables branch from 6518c54 to 7c310f1 Compare May 16, 2024 00:06
@AztecBot
Copy link
Collaborator

AztecBot commented May 16, 2024

Benchmark results

Metrics with a significant change:

  • protocol_circuit_simulation_time_in_ms (private-kernel-inner): 534 (+27%)
  • protocol_circuit_simulation_time_in_ms (private-kernel-reset): 994 (+47%)
  • protocol_circuit_simulation_time_in_ms (private-kernel-tail): 539 (+21%)
  • protocol_circuit_simulation_time_in_ms (public-kernel-tail): 878 (+64%)
  • protocol_circuit_input_size_in_bytes (private-kernel-inner): 88,916 (+23%)
  • protocol_circuit_input_size_in_bytes (private-kernel-reset): 325,966 (+48%)
  • protocol_circuit_input_size_in_bytes (private-kernel-tail): 87,352 (+23%)
  • protocol_circuit_input_size_in_bytes (public-kernel-app-logic): 96,550 (+23%)
  • protocol_circuit_input_size_in_bytes (public-kernel-tail): 380,787 (+106%)
  • protocol_circuit_output_size_in_bytes (private-kernel-init): 61,635 (+34%)
  • protocol_circuit_output_size_in_bytes (private-kernel-inner): 61,452 (+33%)
  • protocol_circuit_output_size_in_bytes (private-kernel-reset): 61,635 (+34%)
  • protocol_circuit_output_size_in_bytes (private-kernel-tail): 79,515 (+24%)
  • protocol_circuit_output_size_in_bytes (public-kernel-app-logic): 84,677 (+23%)
  • tx_pxe_processing_time_ms (1): 3,696 (+20%)
  • tx_pxe_processing_time_ms (2): 113,499 (+26%)
  • tx_size_in_bytes (0): 83,572 (+22%)
  • tx_sequencer_processing_time_ms (1): 2,277 (+46%)
  • tx_sequencer_processing_time_ms (2): 1,664 (+25%)
  • tx_sequencer_processing_time_ms (4): 2,534 (+19%)
  • tx_sequencer_processing_time_ms (8): 1,628 (+23%)
  • app_circuit_proving_time_in_ms (FPC:fee_entrypoint_public): 16,308 (+24%)
  • app_circuit_num_public_inputs (SchnorrAccount:entrypoint): 419 (+17%)
  • app_circuit_num_public_inputs (Test:emit_nullifier): 419 (+17%)
  • app_circuit_num_public_inputs (FPC:fee_entrypoint_public): 419 (+17%)
  • app_circuit_num_public_inputs (Token:transfer): 419 (+17%)
  • app_circuit_num_public_inputs (FPC:fee_entrypoint_private): 419 (+17%)
  • app_circuit_num_public_inputs (Token:unshield): 419 (+17%)
  • app_circuit_num_public_inputs (SchnorrAccount:spend_private_authwit): 419 (+17%)
  • protocol_circuit_witness_generation_time_in_ms (private-kernel-init): 3,620 (+38%)
  • protocol_circuit_witness_generation_time_in_ms (private-kernel-inner): 4,363 (+24%)
  • protocol_circuit_witness_generation_time_in_ms (private-kernel-reset): 6,529 (+48%)
  • protocol_circuit_witness_generation_time_in_ms (base-parity): 323 (-48%)
  • protocol_circuit_witness_generation_time_in_ms (public-kernel-app-logic): 309 (-33%)
  • protocol_circuit_witness_generation_time_in_ms (root-parity): 175 (+35%)
  • protocol_circuit_witness_generation_time_in_ms (base-rollup): 7,172 (+57%)
  • protocol_circuit_witness_generation_time_in_ms (public-kernel-teardown): 358 (-18%)
  • protocol_circuit_witness_generation_time_in_ms (public-kernel-tail): 864 (+79%)
  • protocol_circuit_proving_time_in_ms (private-kernel-init): 24,124 (+20%)
  • protocol_circuit_proving_time_in_ms (private-kernel-reset): 88,019 (+95%)
  • protocol_circuit_proving_time_in_ms (private-kernel-tail-to-public): 68,331 (+61%)
  • protocol_circuit_proving_time_in_ms (base-parity): 8,394 (+167%)
  • protocol_circuit_proving_time_in_ms (public-kernel-setup): 681 (-20%)
  • protocol_circuit_proving_time_in_ms (public-kernel-app-logic): 517 (-35%)
  • protocol_circuit_proving_time_in_ms (root-parity): 96,934 (+149%)
  • protocol_circuit_proving_time_in_ms (public-kernel-teardown): 734 (-27%)
  • protocol_circuit_proving_time_in_ms (public-kernel-tail): 996 (+26%)
  • protocol_circuit_proving_time_in_ms (base-rollup): 90,515 (+109%)
  • protocol_circuit_proving_time_in_ms (root-rollup): 11,776 (+44%)
  • protocol_circuit_proof_size_in_bytes (private-kernel-init): 85,504 (+37%)
  • protocol_circuit_proof_size_in_bytes (private-kernel-inner): 85,504 (+37%)
  • protocol_circuit_proof_size_in_bytes (private-kernel-reset): 85,504 (+37%)
  • protocol_circuit_proof_size_in_bytes (private-kernel-tail-to-public): 114,048 (+25%)
  • protocol_circuit_size_in_gates (private-kernel-reset): 4,194,304 (+100%)
  • protocol_circuit_size_in_gates (private-kernel-tail-to-public): 4,194,304 (+100%)
  • protocol_circuit_num_public_inputs (private-kernel-init): 2,605 (+38%)
  • protocol_circuit_num_public_inputs (private-kernel-inner): 2,605 (+38%)
  • protocol_circuit_num_public_inputs (private-kernel-reset): 2,605 (+38%)
  • protocol_circuit_num_public_inputs (private-kernel-tail-to-public): 3,497 (+26%)
  • protocol_circuit_num_public_inputs (public-kernel-setup): 3,481 (+26%)
  • protocol_circuit_num_public_inputs (public-kernel-app-logic): 3,481 (+26%)
  • protocol_circuit_num_public_inputs (public-kernel-teardown): 3,481 (+26%)
  • l2_block_building_time_in_ms (8): 35,477 (+34%)
  • l2_block_building_time_in_ms (32): 139,194 (+33%)
  • l2_block_building_time_in_ms (64): 277,718 (+34%)
  • l2_block_rollup_simulation_time_in_ms (8): 35,257 (+34%)
  • l2_block_rollup_simulation_time_in_ms (32): 138,414 (+34%)
  • l2_block_rollup_simulation_time_in_ms (64): 276,185 (+34%)
  • l2_block_public_tx_process_time_in_ms (8): 16,650 (+41%)
  • l2_block_public_tx_process_time_in_ms (32): 70,937 (+41%)
  • l2_block_public_tx_process_time_in_ms (64): 143,399 (+42%)
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.

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 772 (+4%) 772 (+4%) 772 (+4%)
l1_rollup_calldata_gas 6,820 (+2%) 6,796 (+2%) 6,772 (+2%)
l1_rollup_execution_gas 587,349 587,325 587,301
l2_block_processing_time_in_ms 1,603 6,046 12,091 (+1%)
l2_block_building_time_in_ms ⚠️ 35,477 (+34%) ⚠️ 139,194 (+33%) ⚠️ 277,718 (+34%)
l2_block_rollup_simulation_time_in_ms ⚠️ 35,257 (+34%) ⚠️ 138,414 (+34%) ⚠️ 276,185 (+34%)
l2_block_public_tx_process_time_in_ms ⚠️ 16,650 (+41%) ⚠️ 70,937 (+41%) ⚠️ 143,399 (+42%)

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 17,941 33,645
node_database_size_in_bytes 21,385,296 38,031,440
pxe_database_size_in_bytes 29,868 59,425

Circuits stats

Stats on running time and I/O sizes collected for every kernel circuit run across all benchmarks.

Circuit protocol_circuit_simulation_time_in_ms protocol_circuit_witness_generation_time_in_ms protocol_circuit_proving_time_in_ms protocol_circuit_input_size_in_bytes protocol_circuit_output_size_in_bytes protocol_circuit_proof_size_in_bytes protocol_circuit_num_public_inputs protocol_circuit_size_in_gates
private-kernel-init 163 (+16%) ⚠️ 3,620 (+38%) ⚠️ 24,124 (+20%) 20,414 (+5%) ⚠️ 61,635 (+34%) ⚠️ 85,504 (+37%) ⚠️ 2,605 (+38%) 1,048,576
private-kernel-inner ⚠️ 534 (+27%) ⚠️ 4,363 (+24%) 45,280 (+15%) ⚠️ 88,916 (+23%) ⚠️ 61,452 (+33%) ⚠️ 85,504 (+37%) ⚠️ 2,605 (+38%) 2,097,152
private-kernel-reset ⚠️ 994 (+47%) ⚠️ 6,529 (+48%) ⚠️ 88,019 (+95%) ⚠️ 325,966 (+48%) ⚠️ 61,635 (+34%) ⚠️ 85,504 (+37%) ⚠️ 2,605 (+38%) ⚠️ 4,194,304 (+100%)
private-kernel-tail ⚠️ 539 (+21%) 4,960 (+7%) 39,146 (+6%) ⚠️ 87,352 (+23%) ⚠️ 79,515 (+24%) 10,720 (+1%) 268 (+1%) 2,097,152
base-parity 8.90 (+9%) ⚠️ 323 (-48%) ⚠️ 8,394 (+167%) 128 64.0 2,208 2.00 131,072
root-parity 51.5 ⚠️ 175 (+35%) ⚠️ 96,934 (+149%) 27,064 64.0 2,720 18.0 2,097,152
base-rollup 916 (+11%) ⚠️ 7,172 (+57%) ⚠️ 90,515 (+109%) 111,220 957 (+3%) 3,136 (+1%) 31.0 (+3%) 2,097,152
root-rollup 72.9 186 (+9%) ⚠️ 11,776 (+44%) 11,518 (+1%) 821 (+4%) 3,456 (+1%) 41.0 (+3%) 524,288
public-kernel-app-logic 194 (+25%) ⚠️ 309 (-33%) ⚠️ 517 (-35%) ⚠️ 96,550 (+23%) ⚠️ 84,677 (+23%) 89,267 (-1%) ⚠️ 3,481 (+26%) 4,096
public-kernel-tail ⚠️ 878 (+64%) ⚠️ 864 (+79%) ⚠️ 996 (+26%) ⚠️ 380,787 (+106%) 7,785 (+1%) 10,192 252 (+1%) 512
public-kernel-setup 142 (+10%) 342 (-11%) ⚠️ 681 (-20%) 112,451 (+2%) 75,826 (+10%) 88,644 (-2%) ⚠️ 3,481 (+26%) 4,096
public-kernel-teardown 150 (+9%) ⚠️ 358 (-18%) ⚠️ 734 (-27%) 121,283 (+6%) 77,826 (+13%) 93,312 (+3%) ⚠️ 3,481 (+26%) 4,096
private-kernel-ordering 345 N/A N/A 61,432 39,554 N/A N/A N/A
merge-rollup 6.92 (+2%) 114 (-8%) 2,253 (+1%) 2,760 (+2%) 957 (+3%) 3,136 (+1%) 31.0 (+3%) 65,536
private-kernel-tail-to-public N/A 10,790 (+13%) ⚠️ 68,331 (+61%) N/A N/A ⚠️ 114,048 (+25%) ⚠️ 3,497 (+26%) ⚠️ 4,194,304 (+100%)

Stats on running time collected for app circuits

Function app_circuit_proof_size_in_bytes app_circuit_proving_time_in_ms app_circuit_size_in_gates app_circuit_num_public_inputs
SchnorrAccount:entrypoint 15,552 (+14%) 48,385 (+3%) 2,097,152 ⚠️ 419 (+17%)
Test:emit_nullifier 15,552 (+14%) 2,584 (+11%) 65,536 ⚠️ 419 (+17%)
FPC:fee_entrypoint_public 15,552 (+14%) ⚠️ 16,308 (+24%) 524,288 ⚠️ 419 (+17%)
Token:transfer 15,552 (+14%) 40,072 (-2%) 2,097,152 ⚠️ 419 (+17%)
FPC:fee_entrypoint_private 15,552 (+14%) 8,987 (-9%) 524,288 ⚠️ 419 (+17%)
Token:unshield 15,552 (+14%) 37,051 (+9%) 2,097,152 ⚠️ 419 (+17%)
SchnorrAccount:spend_private_authwit 15,552 (+14%) 2,677 (+4%) 131,072 ⚠️ 419 (+17%)

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 13.2 21.4 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.7 31.8 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.770 0.660 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 61.5 97.1 315 (-1%) 611 1,193 (-1%) 2,368 N/A
batch_insert_into_append_only_tree_32_depth_hash_count N/A N/A 95.9 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.631 0.601 0.572 (-1%) 0.571 (+1%) 0.566 (-1%) 0.566 (-1%) N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 74.2 143 455 895 1,775 3,549 (+1%) N/A
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 106 208 692 1,363 2,707 5,395 N/A
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A 0.645 0.644 0.617 (-1%) 0.616 0.615 0.618 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 81.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 (+1%)
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.710

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 ⚠️ 83,572 (+22%) 765,776 (+15%)

Transaction size based on fee payment method

| Metric | |
| - | |

Transaction processing duration by data writes.

Metric 0 new note hashes 1 new note hashes 2 new note hashes
tx_pxe_processing_time_ms 26,490 (-5%) ⚠️ 3,696 (+20%) ⚠️ 113,499 (+26%)
Metric 0 public data writes 1 public data writes 2 public data writes 4 public data writes 8 public data writes
tx_sequencer_processing_time_ms 1,016 (-4%) ⚠️ 2,277 (+46%) ⚠️ 1,664 (+25%) ⚠️ 2,534 (+19%) ⚠️ 1,628 (+23%)

@@ -230,7 +230,10 @@ export const deployL1Contracts = async (
abi: contractsToDeploy.gasToken.contractAbi,
client: walletClient,
});
await gasToken.write.mint([rollupAddress.toString(), 100000000000000000000n], {} as any);
const receipt = await gasToken.write.mint([rollupAddress.toString(), 100000000000000000000n], {} as any);
await publicClient.waitForTransactionReceipt({
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thank you @spalladino !

@just-mitch just-mitch force-pushed the 05-15-feat_add_totalfees_to_global_variables branch from 7c310f1 to ac434c9 Compare May 16, 2024 10:29
@AztecBot
Copy link
Collaborator

AztecBot commented May 16, 2024

Docs Preview

Hey there! 👋 You can check your preview at https://66466af984ebc7077ad9f228--aztec-docs-dev.netlify.app

@just-mitch just-mitch force-pushed the 05-15-feat_add_totalfees_to_global_variables branch 4 times, most recently from b1059a3 to 1bb0586 Compare May 16, 2024 18:03
@just-mitch just-mitch marked this pull request as ready for review May 16, 2024 19:13
@just-mitch just-mitch requested a review from spalladino May 16, 2024 19:18
@just-mitch just-mitch force-pushed the 05-15-feat_add_totalfees_to_global_variables branch from 1bb0586 to b5a573e Compare May 16, 2024 19:23
@just-mitch just-mitch requested a review from LeilaWang May 16, 2024 20:24
Copy link
Collaborator

@spalladino spalladino left a comment

Choose a reason for hiding this comment

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

Code looks good. However, GlobalVariables are also referenced from the CombinedConstantData that are used across the kernel circuits, and are constant across the entire block. total_fees does not seem to fit the bill in there, since it's accumulated across the block, so maybe it should be directly in the Header and not within its global_variables?

@just-mitch
Copy link
Collaborator Author

just-mitch commented May 16, 2024

so maybe it should be directly in the Header and not within its global_variables?

@spalladino I was kind of thinking the same thing. @LeilaWang , @LHerskind . Thoughts?

@LeilaWang
Copy link
Collaborator

Agree with Palla!

@just-mitch
Copy link
Collaborator Author

Close in favor of #6522

@just-mitch just-mitch closed this May 17, 2024
@ludamad ludamad deleted the 05-15-feat_add_totalfees_to_global_variables branch August 22, 2024 15:02
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.

5 participants