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: prepare circuit output for validation #6678

Merged
merged 25 commits into from
May 29, 2024

Conversation

LeilaWang
Copy link
Collaborator

@LeilaWang LeilaWang commented May 24, 2024

Changing private kernel init and inner to:

  • Construct the output (unconstrained).
  • Check the output against tx request or previous kernel.
  • Check the output against private call.
  • Return the output.

The checks are done in a new component: private_kernel_circuit_output_validator.nr.

Copy link
Contributor

github-actions bot commented May 24, 2024

Changes to circuit sizes

Generated at commit: a231907bf45ed08d158303f25d4e65c47b9daee4, compared to commit: 1230e566698b62591a3bf8f35baa60c454f089e9

🧾 Summary (100% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
public_kernel_tail -1,976 ✅ -0.20% -1,166 ✅ -0.03%
public_kernel_teardown -1,344 ✅ -0.50% -1,338 ✅ -0.08%
public_kernel_app_logic -1,344 ✅ -0.50% -1,338 ✅ -0.08%
public_kernel_setup -1,247 ✅ -0.55% -1,241 ✅ -0.08%
private_kernel_tail_to_public -8,432 ✅ -1.48% -7,417 ✅ -0.34%
private_kernel_tail -8,432 ✅ -4.22% -7,418 ✅ -0.51%
private_kernel_inner -212,933 ✅ -80.07% -500,509 ✅ -28.07%
private_kernel_init -200,795 ✅ -86.86% -474,088 ✅ -54.78%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
public_kernel_tail 979,797 (-1,976) -0.20% 4,469,533 (-1,166) -0.03%
public_kernel_teardown 265,802 (-1,344) -0.50% 1,696,674 (-1,338) -0.08%
public_kernel_app_logic 265,445 (-1,344) -0.50% 1,696,276 (-1,338) -0.08%
public_kernel_setup 224,918 (-1,247) -0.55% 1,549,542 (-1,241) -0.08%
private_kernel_tail_to_public 561,446 (-8,432) -1.48% 2,170,465 (-7,417) -0.34%
private_kernel_tail 191,390 (-8,432) -4.22% 1,457,790 (-7,418) -0.51%
private_kernel_inner 53,009 (-212,933) -80.07% 1,282,703 (-500,509) -28.07%
private_kernel_init 30,382 (-200,795) -86.86% 391,405 (-474,088) -54.78%

@ludamad
Copy link
Collaborator

ludamad commented May 24, 2024

just merged master as I noticed it had a fix for your CI failure :)

@AztecBot
Copy link
Collaborator

AztecBot commented May 24, 2024

Benchmark results

Metrics with a significant change:

  • protocol_circuit_simulation_time_in_ms (private-kernel-inner): 406 (-34%)
  • app_circuit_proving_time_in_ms (Token:transfer): 54,678 (+19%)
  • protocol_circuit_witness_generation_time_in_ms (private-kernel-init): 500 (-87%)
  • protocol_circuit_witness_generation_time_in_ms (private-kernel-inner): 995 (-78%)
  • protocol_circuit_proving_time_in_ms (private-kernel-init): 13,213 (-40%)
  • protocol_circuit_size_in_gates (private-kernel-init): 524,288 (-50%)
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 | |
| - | |

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 1,412 1,412 1,412
l1_rollup_calldata_gas 9,452 9,452 9,464
l1_rollup_execution_gas 616,093 616,093 616,105
l2_block_processing_time_in_ms 1,289 4,777 9,491
l2_block_building_time_in_ms 46,620 (+3%) 185,529 (+4%) 372,445 (+4%)
l2_block_rollup_simulation_time_in_ms 46,449 (+3%) 184,881 (+4%) 371,173 (+4%)
l2_block_public_tx_process_time_in_ms 25,225 (+4%) 105,946 (+4%) 218,199 (+5%)

L2 chain processing

Each column represents the number of blocks on the L2 chain where each block has 16 txs.

Metric 3 blocks 5 blocks
node_history_sync_time_in_ms 9,585 14,486
node_database_size_in_bytes 14,504,016 21,303,376
pxe_database_size_in_bytes 18,071 29,868

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 proving_time_in_ms input_size_in_bytes output_size_in_bytes proof_size_in_bytes num_public_inputs size_in_gates
private-kernel-init 133 (-16%) ⚠️ 500 (-87%) ⚠️ 13,213 (-40%) 20,630 64,614 89,536 2,731 ⚠️ 524,288 (-50%)
private-kernel-inner ⚠️ 406 (-34%) ⚠️ 995 (-78%) 43,078 (+2%) 92,318 64,614 89,536 2,731 2,097,152
private-kernel-tail 588 (+5%) 2,820 (-6%) 36,152 96,541 77,732 11,648 297 2,097,152
base-parity 6.70 (+2%) 1,182 2,906 128 64.0 2,208 2.00 131,072
root-parity 49.8 66.8 (+27%) 44,408 (+1%) 27,084 64.0 2,720 18.0 2,097,152
base-rollup 744 (-5%) 2,339 (+2%) 74,594 119,734 756 3,648 47.0 4,194,304
root-rollup 112 63.3 (+1%) 19,766 (+2%) 25,297 620 3,456 41.0 1,048,576
public-kernel-app-logic 542 (+3%) 3,138 (-1%) 48,226 105,253 86,550 116,768 3,582 2,097,152
public-kernel-tail 1,136 (+2%) 24,130 155,775 (+1%) 401,002 7,646 11,648 297 8,388,608
private-kernel-reset-small 595 (+2%) 2,144 (+2%) 46,316 (+2%) 120,733 64,614 89,536 2,731 2,097,152
merge-rollup 28.6 N/A N/A 16,534 756 N/A N/A N/A
public-kernel-setup 656 (+4%) N/A N/A 105,253 86,550 N/A N/A N/A
public-kernel-teardown 552 (+3%) N/A N/A 105,253 86,550 N/A N/A N/A
private-kernel-tail-to-public N/A 8,683 (+1%) 92,185 (+1%) N/A N/A 116,768 3,582 4,194,304

Stats on running time collected for app circuits

Function input_size_in_bytes output_size_in_bytes witness_generation_time_in_ms proof_size_in_bytes proving_time_in_ms size_in_gates num_public_inputs
ContractClassRegisterer:register 1,344 9,944 469 (+1%) N/A N/A N/A N/A
ContractInstanceDeployer:deploy 1,408 9,944 42.2 N/A N/A N/A N/A
MultiCallEntrypoint:entrypoint 1,920 9,944 1,450 N/A N/A N/A N/A
SchnorrAccount:constructor 1,312 9,944 996 (+1%) N/A N/A N/A N/A
SchnorrAccount:entrypoint 2,304 9,944 2,105 16,768 49,190 (-3%) 2,097,152 457
Token:privately_mint_private_note 1,280 9,944 1,161 (+1%) N/A N/A N/A N/A
Token:transfer 1,376 9,944 4,083 16,768 ⚠️ 54,678 (+19%) 2,097,152 457
Benchmarking:create_note 1,312 9,944 953 (+1%) N/A N/A N/A N/A
FPC:fee_entrypoint_public 1,344 9,944 223 (-1%) N/A N/A N/A N/A
SchnorrAccount:spend_private_authwit 1,280 9,944 77.6 N/A N/A N/A N/A
Token:unshield 1,376 9,944 3,255 N/A N/A N/A N/A
FPC:fee_entrypoint_private 1,376 9,944 4,030 N/A N/A N/A N/A

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.4 17.0 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.606 0.523 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 48.6 76.0 247 476 (-1%) 927 1,834 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.497 0.469 0.448 0.444 (-1%) 0.440 0.439 N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 58.2 113 357 (+1%) 700 1,379 2,757 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.504 0.506 0.484 (+1%) 0.481 0.478 0.479 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 62.5
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 107
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.554

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 84,050 665,267

Transaction size based on fee payment method

| Metric | |
| - | |

@@ -38,10 +42,8 @@ impl PrivateKernelCircuitPublicInputsComposer {
tx_request.tx_context,
);

public_inputs.min_revertible_side_effect_counter = private_call_public_inputs.min_revertible_side_effect_counter;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Assigning the min counter in propagate_from_private_call instead, which is run by both init and inner.

}

#[test]
fn propagate_max_block_number_request() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tests for propagating data are done in the tests for PrivateKernelCircuitPublicInputsComposer.

assert(
note_logs[i].note_hash_counter
== self.public_inputs.end.new_note_hashes.get_unchecked(note_index).counter(), "Could not find note hash linked to note log."
assert(note_index < new_note_hashes.len(), "Could not find note hash linked to note log");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Need to check against the number of non-empty items. Otherwise, we would be allowing a log to link to counter 0.

@LeilaWang LeilaWang marked this pull request as ready for review May 28, 2024 08:55
@LeilaWang LeilaWang requested a review from sirasistant May 28, 2024 08:55
Copy link
Collaborator

@sirasistant sirasistant left a comment

Choose a reason for hiding this comment

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

Looks great! And the reduction in constraints is enormous! Only some very small nits 🥳

for i in 0..dest.len() { // Loop through dest instead of source because we also need to check that dest is appended with empty items.
should_check |= i == num_prepended_items; // Prepended items have been checked in validate_array_prepended() and can be skipped here.
if should_check {
is_non_empty_item &= i != items_propagated;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can probably extract this one out of the if should_check and maybe same some constraints 🤓

for i in 0..dest.len() {
should_check |= i == num_prepended_items;
if should_check {
is_non_empty_item &= i != items_propagated;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same on this one!

@LeilaWang LeilaWang enabled auto-merge (squash) May 28, 2024 23:16
@LeilaWang LeilaWang disabled auto-merge May 29, 2024 09:42
@LeilaWang LeilaWang enabled auto-merge (squash) May 29, 2024 10:02
@LeilaWang LeilaWang merged commit 03511f5 into master May 29, 2024
84 of 85 checks passed
@LeilaWang LeilaWang deleted the lw/circuit_output_validation branch May 29, 2024 11:03
TomAFrench added a commit that referenced this pull request May 29, 2024
* master:
  feat: prepare circuit output for validation (#6678)
  chore: stop building/publishing `acvm_backend.wasm` (#6584)
  chore: add bench programs (#6566)
  chore: make public data update requests, note hashes, and unencrypted logs readonly in TS (#6658)
  git subrepo push --branch=master noir-projects/aztec-nr
  git_subrepo.sh: Fix parent in .gitrepo file. [skip ci]
  chore: replace relative paths to noir-protocol-circuits
  git subrepo push --branch=master barretenberg
  feat: update honk recursion constraint (#6545)
  feat: Add code-workspace and update build dirs (#6723)
  feat: Sync from noir (#6717)
  feat: folding acir programs (#6685)
  feat: sumcheck part of ECCVM recursive verifier instantiated as an UltraCircuit (#6413)
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.

4 participants