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

refactor(aztec-nr)!: move nullifier testing inside contexts #5336

Closed
wants to merge 2 commits into from

Conversation

fcarreiro
Copy link
Contributor

@fcarreiro fcarreiro commented Mar 20, 2024

  • Moved nullifier (non)inclusion to the contexts
    • nullifier_valid_inclusion(null): bool proves that the inclusion is valid
    • nullifier_valid_non_inclusion(null): bool proves that the non-inclusion is valid
    • nullifier_exists(null): bool proves that you can get either an inclusion or non-inclusion
    • _at versions for PrivateContext
  • Replaced calls to prove_nullifier_xxx with assert(context.nullifier_xxx)

Copy link
Contributor Author

fcarreiro commented Mar 20, 2024

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

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

@fcarreiro fcarreiro force-pushed the fc/public-avm-context-refactor branch from 444e65d to 1f13c6a Compare March 20, 2024 14:44
@fcarreiro fcarreiro force-pushed the fc/refactor-nullifier-testing branch from 1619f07 to 7cea292 Compare March 20, 2024 14:44
@fcarreiro fcarreiro changed the title refactor!(aztec-nr): move nullifier testing inside contexts refactor(aztec-nr)!: move nullifier testing inside contexts Mar 20, 2024
@fcarreiro fcarreiro force-pushed the fc/public-avm-context-refactor branch from 1f13c6a to 75c43c6 Compare March 20, 2024 14:54
@fcarreiro fcarreiro force-pushed the fc/refactor-nullifier-testing branch from 7cea292 to b38ea54 Compare March 20, 2024 14:54
@AztecBot
Copy link
Collaborator

AztecBot commented Mar 20, 2024

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.

Values are compared against data from master at commit 5f0f4fca 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 64 txs
l1_rollup_calldata_size_in_bytes 5,668 18,820 36,356
l1_rollup_calldata_gas 66,388 238,768 469,700
l1_rollup_execution_gas 647,486 929,126 1,305,880
l2_block_processing_time_in_ms 1,280 (-6%) 4,551 (-8%) 9,393 (-2%)
note_successful_decrypting_time_in_ms 178 (+5%) 528 (+2%) 958 (-7%)
note_trial_decrypting_time_in_ms 80.0 (+5%) 44.9 (+31%) 90.5 (+54%)
l2_block_building_time_in_ms 18,275 69,130 (-1%) 137,040
l2_block_rollup_simulation_time_in_ms 8,088 (-1%) 28,689 (-4%) 56,683 (-1%)
l2_block_public_tx_process_time_in_ms 10,167 (+1%) 40,387 (+2%) 80,256 (+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,495 25,698 (-3%)
note_history_successful_decrypting_time_in_ms 1,208 2,457
note_history_trial_decrypting_time_in_ms 68.1 (+8%) 180 (+8%)
node_database_size_in_bytes 18,645,072 35,053,648
pxe_database_size_in_bytes 29,859 59,414

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 276 (-2%) 44,366 28,244
private-kernel-ordering 213 52,868 14,326
base-parity 1,786 (-4%) 128 311
base-rollup 711 (-2%) 165,787 925
root-parity 1,650 (+2%) 1,244 311
root-rollup 52.7 (+2%) 4,487 725
private-kernel-inner 636 (-1%) 73,771 28,244
public-kernel-app-logic 441 (-1%) 35,260 28,215
public-kernel-tail 171 (-1%) 40,926 28,215
merge-rollup 8.22 (-1%) 2,696 925

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.0 16.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.8 31.6 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.583 0.494 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 46.2 (+1%) 71.7 (-1%) 232 438 (-2%) 867 (-1%) 1,730 (-1%) N/A
batch_insert_into_append_only_tree_32_depth_hash_count N/A N/A 96.0 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.475 (+1%) 0.443 (-1%) 0.423 0.409 (-2%) 0.413 0.415 N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 53.2 (-1%) 106 (-1%) 337 649 (-3%) 1,310 (-2%) 2,619 (-1%) N/A
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 104 207 691 1,363 2,707 5,395 N/A
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A 0.474 (-1%) 0.478 (-1%) 0.458 0.447 (-3%) 0.454 (-1%) 0.453 (-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 60.4 (-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
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.528 (-1%)

Miscellaneous

Transaction sizes based on how many contract classes are registered in the tx.

Metric 0 registered classes
tx_size_in_bytes 22,012

Transaction processing duration by data writes.

Metric 0 new note hashes 1 new note hashes
tx_pxe_processing_time_ms 3,213 1,736 (-1%)
Metric 0 public data writes 1 public data writes
tx_sequencer_processing_time_ms 11.2 (-18%) 1,232 (-1%)

@fcarreiro fcarreiro force-pushed the fc/refactor-nullifier-testing branch 2 times, most recently from 3743311 to 455eb5a Compare March 20, 2024 15:33
@fcarreiro fcarreiro marked this pull request as ready for review March 20, 2024 15:33
@fcarreiro fcarreiro requested a review from LHerskind March 20, 2024 15:33
@fcarreiro fcarreiro force-pushed the fc/refactor-nullifier-testing branch from 455eb5a to f08db39 Compare March 20, 2024 16:01
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.

Quick comments.

I'm not fully understanding why the libraries are altered this much. In my mind from earlier the diff would mainly be addition into the context of the exists function, the rest would look similar to what it does not (but not fully same). So if you just want to use it, use the context but if you wanna optimize then use the libraries. That way the contexts could be the same and more other stuff to libraries that can be pulled in if needed

nullifier_exists(nullifier) == 1
}
fn nullifier_valid_inclusion(self, nullifier: Field) -> bool {
self.nullifier_exists(nullifier) == false
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems wrong. Or maybe I'm just cooked.

  • If nullifier_exists returns false then the inclusion should be failing.
  • If nullifier_exists returns true then the inclusion should pass and the non_inclusion should fail.

@@ -151,6 +173,24 @@ impl PrivateContext {
get_header_at(block_number, self)
}

pub fn nullifier_valid_inclusion_at(
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to be as consistent as possible within the two it seems better to not have the _at in here but specifically use the library for that. Similar for anything but the exists?

xor == false
}

fn nullifier_valid_inclusion(self, nullifier: Field) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

As above, I'm ok with just having the exists in the context, and then people can go to libraries for stuff that can more easily be messed up if they want to.

* @param header The header at which we'll prove that the nullifier exists in the nullifier tree
* @return true if the nullifier is included in the nullifier tree, false otherwise
*/
pub fn nullifier_valid_inclusion(nullifier: Field, header: Header) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not really following why we are changing these libraries? Was it not just the context you wanted to have the exists that matches?

// nullifier's next_value is bigger than the nullifier)
unconstrained pub fn get_nullifier_membership_witness(block_number: u32, nullifier: Field) -> NullifierMembershipWitness {
) -> [Field; 1 + NULLIFIER_MEMBERSHIP_WITNESS_LENGTH] {}
// ^ found?
Copy link
Contributor

Choose a reason for hiding this comment

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

If you have an option then the option adds a length of 1 for the is_some

Base automatically changed from fc/public-avm-context-refactor to master March 20, 2024 17:00
@fcarreiro fcarreiro marked this pull request as draft March 22, 2024 15:34
@fcarreiro fcarreiro closed this Mar 27, 2024
@fcarreiro fcarreiro deleted the fc/refactor-nullifier-testing branch April 9, 2024 09:40
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