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!: constrain note_getter filter #6703

Merged
merged 3 commits into from
May 29, 2024
Merged

feat!: constrain note_getter filter #6703

merged 3 commits into from
May 29, 2024

Conversation

nventuro
Copy link
Contributor

The application of the filter was not constrained when reading notes, this PR changes that. While filtering can be thought of as assisting PXE during note retrieval to avoid unnecessary extra read requests, I think most users will also assume that the function will also lay down constrains.

The biggest motivation for this change is that this is how select() work: instructions are sent to the PXE to only return certain notes, and we then verify that the oracle behaved as expected. filter() is simply an extension of this for conditions that cannot be expressed in a simple select: it is extremely unexpected that filtering would not be constrained when selects are.

Consider the following example:

// These guarantee that the retrieved notes have a value larger than 500
let opts = NoteGetterOptions::new().options.select(ValueNote::properties().value, 500, Comparator.GT);

// These make a cooperative PXE retrieve notes with a value between 500 and 700, both provide no guarantees whatsoever
let opts = NoteGetterOptions::with_filter(|opt_notes| {
  let mut filtered_notes = [0; opt_notes.len()];
  for i in 0..opt_notes.len() {
    let note_value = opt_notes[i].unwrap_or(0);
    if (note_value > 500) & (note_value < 700) {
      filtered_notes[i] = Option::some(note_value);
    }
  }

  filtered_notes
});

An example is filter_notes_min_sum, which keeps notes until as long as the sum is below some minimum. Callers still have to process the sum again on their end however and compare it to the minimum, since the filter used to provide no guarantees. In some cases this was hidden behind multiple layers of indirection, and as a result ValueNote::decrement_by_at_most does not really uphold that the balance is decremented by less than max_balance - a very subtle bug.

nventuro added 2 commits May 27, 2024 16:18
@nventuro nventuro requested review from benesjan and LHerskind May 27, 2024 18:38
@AztecBot
Copy link
Collaborator

AztecBot commented May 27, 2024

Docs Preview

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

@AztecBot
Copy link
Collaborator

Benchmark results

No metrics with a significant change found.

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,440 9,464 9,464
l1_rollup_execution_gas 616,081 616,105 616,105
l2_block_processing_time_in_ms 1,287 (-2%) 4,804 (-2%) 9,518 (-2%)
l2_block_building_time_in_ms 45,110 (+1%) 178,727 (+1%) 357,020
l2_block_rollup_simulation_time_in_ms 44,944 (+1%) 178,097 (+1%) 355,780
l2_block_public_tx_process_time_in_ms 24,307 (+2%) 101,326 (+1%) 207,059 (+1%)

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,491 14,433 (-1%)
node_database_size_in_bytes 14,495,824 21,364,816
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 161 (+1%) 3,680 (-1%) 22,941 (+2%) 20,630 64,614 89,536 2,731 1,048,576
private-kernel-inner 629 (+1%) 4,360 (+2%) 42,533 (-7%) 92,318 64,614 89,536 2,731 2,097,152
private-kernel-tail 575 (+2%) 3,017 (+4%) 36,546 (+1%) 96,541 77,498 10,656 266 2,097,152
base-parity 6.57 (+1%) 1,232 2,886 (-1%) 128 64.0 2,208 2.00 131,072
root-parity 50.3 (+1%) 59.5 (-3%) 43,804 27,084 64.0 2,720 18.0 2,097,152
base-rollup 771 (+8%) 2,212 74,078 119,610 756 3,648 47.0 4,194,304
root-rollup 112 66.9 (+7%) 19,455 25,297 620 3,456 41.0 1,048,576
public-kernel-app-logic 527 (+1%) 2,960 47,901 (+1%) 104,941 86,302 114,784 3,520 2,097,152
public-kernel-tail 1,095 (+1%) 20,268 (-11%) 154,407 395,386 7,522 10,656 266 8,388,608
private-kernel-reset-small 597 (+1%) 2,084 (-6%) 45,202 120,733 64,614 89,536 2,731 2,097,152
merge-rollup 28.8 (-2%) N/A N/A 16,534 756 N/A N/A N/A
public-kernel-setup 653 (+4%) N/A N/A 104,941 86,302 N/A N/A N/A
public-kernel-teardown 552 (+5%) N/A N/A 104,941 86,302 N/A N/A N/A
private-kernel-tail-to-public N/A 8,556 (-1%) 91,561 (-1%) N/A N/A 114,784 3,520 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 466 (+1%) N/A N/A N/A N/A
ContractInstanceDeployer:deploy 1,408 9,944 42.0 N/A N/A N/A N/A
MultiCallEntrypoint:entrypoint 1,920 9,944 1,439 N/A N/A N/A N/A
SchnorrAccount:constructor 1,312 9,944 995 N/A N/A N/A N/A
SchnorrAccount:entrypoint 2,304 9,944 2,098 (+1%) 16,768 50,963 2,097,152 457
Token:privately_mint_private_note 1,280 9,944 1,145 N/A N/A N/A N/A
Token:transfer 1,376 9,944 4,101 (+2%) 16,768 45,893 (-14%) 2,097,152 457
Benchmarking:create_note 1,312 9,944 958 (+1%) N/A N/A N/A N/A
FPC:fee_entrypoint_public 1,344 9,944 221 (-1%) N/A N/A N/A N/A
SchnorrAccount:spend_private_authwit 1,280 9,944 78.3 N/A N/A N/A N/A
Token:unshield 1,376 9,944 3,302 (+2%) N/A N/A N/A N/A
FPC:fee_entrypoint_private 1,376 9,944 4,071 (+2%) 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.5 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.607 0.522 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.8 76.1 (-1%) 245 (-1%) 477 932 (-1%) 1,843 (-1%) 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.498 0.469 (-1%) 0.445 (-1%) 0.445 0.441 (-1%) 0.439 (-1%) N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 59.4 (+1%) 113 (-1%) 356 (-1%) 700 1,389 (-1%) 2,767 (-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.513 (+1%) 0.506 (-1%) 0.482 (-1%) 0.480 0.480 (-1%) 0.480 (-1%) 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.6
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.555

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,794 665,117

Transaction size based on fee payment method

| Metric | |
| - | |

Copy link
Contributor

@LHerskind LHerskind left a comment

Choose a reason for hiding this comment

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

Think Jans comment on NoteHeader Eq is good and would make it less error prone 👍

@nventuro nventuro enabled auto-merge (squash) May 29, 2024 17:47
@nventuro nventuro merged commit 545da36 into master May 29, 2024
90 checks passed
@nventuro nventuro deleted the nv/fix-filter branch May 29, 2024 20:13
@@ -6,6 +6,12 @@ keywords: [sandbox, cli, aztec, notes, migration, updating, upgrading]

Aztec is in full-speed development. Literally every version breaks compatibility with the previous ones. This page attempts to target errors and difficulties you might encounter when upgrading, and how to resolve them.

## TBD
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be in 0.42 which is the next release

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

6 participants