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 support for uint256 to DSL bigint #5327

Closed
wants to merge 22 commits into from
Closed

Conversation

guipublic
Copy link
Contributor

@guipublic guipublic commented Mar 20, 2024

uint256 in dsl big int are implemented by extending the bigfield class into bigfieldyn class, which is the same code, except that:

  • it does not use a template for the bigfield modulus
  • it allows for any modulus up to 2^{256} (included)

For now this class only works with 2^{256} modulus, but can be very easily extended to support any 256 bits (or less) prime.
Support for non-prime can be added with moderate effort. Only the witness generation part will need to be adapted because Montgomery multiplication does not work with power-of-2 limbs and even modulus.
In this PR, we simply use uint256_t for the witness generation.

I also added U256 in Noir stdlib

@AztecBot
Copy link
Collaborator

AztecBot commented Mar 20, 2024

Benchmark results

Metrics with a significant change:

  • circuit_simulation_time_in_ms (base-parity): 3,225 (-21%)
  • circuit_simulation_time_in_ms (root-parity): 1,337 (+16%)
  • circuit_simulation_time_in_ms (base-rollup): 7,738 (-46%)
  • circuit_simulation_time_in_ms (private-kernel-inner): 394 (+75%)
  • circuit_simulation_time_in_ms (public-kernel-app-logic): 257 (+112%)
  • circuit_input_size_in_bytes (base-rollup): 140,076 (+20%)
  • circuit_output_size_in_bytes (private-kernel-ordering): 27,130 (-31%)
  • circuit_output_size_in_bytes (public-kernel-tail): 20,464 (+54%)
  • tx_pxe_processing_time_ms (0): 2,128 (+25%)
  • tx_pxe_processing_time_ms (1): 1,346 (+22%)
  • tx_size_in_bytes (0): 31,367 (-23%)
  • tx_sequencer_processing_time_ms (1): 859 (+49%)
  • note_history_trial_decrypting_time_in_ms (10): 181 (+77%)
  • l2_block_building_time_in_ms (8): 14,448 (+22%)
  • l2_block_building_time_in_ms (32): 53,440 (+25%)
  • l2_block_building_time_in_ms (64): 105,509 (+25%)
  • l2_block_public_tx_process_time_in_ms (8): 6,923 (+47%)
  • l2_block_public_tx_process_time_in_ms (32): 27,327 (+48%)
  • l2_block_public_tx_process_time_in_ms (64): 54,623 (+48%)
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 e0e72008 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 676 676 676
l1_rollup_calldata_gas 6,418 6,400 6,412
l1_rollup_execution_gas 585,751 585,733 585,745
l2_block_processing_time_in_ms 1,294 (+1%) 4,648 (-5%) 8,996 (-3%)
note_successful_decrypting_time_in_ms 208 (-13%) 565 (+5%) 983 (+2%)
note_trial_decrypting_time_in_ms 62.3 (+64%) 80.2 (+62%) 58.9 (-28%)
l2_block_building_time_in_ms ⚠️ 14,448 (+22%) ⚠️ 53,440 (+25%) ⚠️ 105,509 (+25%)
l2_block_rollup_simulation_time_in_ms 7,497 (+6%) 26,024 (+8%) 50,716 (+8%)
l2_block_public_tx_process_time_in_ms ⚠️ 6,923 (+47%) ⚠️ 27,327 (+48%) ⚠️ 54,623 (+48%)

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,423 (+4%) 28,068 (+5%)
note_history_successful_decrypting_time_in_ms 1,350 (+4%) 2,481 (+3%)
note_history_trial_decrypting_time_in_ms 89.5 (-3%) ⚠️ 181 (+77%)
node_database_size_in_bytes 18,645,072 34,998,352
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 210 (+14%) 44,340 27,145 (+4%)
private-kernel-ordering 185 (+11%) 51,791 (+2%) ⚠️ 27,130 (-31%)
base-parity ⚠️ 3,225 (-21%) 128 311
root-parity ⚠️ 1,337 (+16%) 1,244 311
base-rollup ⚠️ 7,738 (-46%) ⚠️ 140,076 (+20%) 861
root-rollup 49.5 (-3%) 4,359 725
private-kernel-inner ⚠️ 394 (+75%) 72,661 (+1%) 27,138 (+4%)
public-kernel-app-logic ⚠️ 257 (+112%) 41,499 (-13%) 34,476 (-15%)
public-kernel-tail 168 (+2%) 47,323 (-11%) ⚠️ 20,464 (+54%)
merge-rollup 8.48 (-13%) 2,568 861
public-kernel-teardown 117 (+1%) 47,695 40,661
public-kernel-setup 116 (+1%) 47,695 40,661

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.2 (+2%) 16.1 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.593 (+2%) 0.499 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 45.5 (-1%) 78.1 (+8%) 228 443 (-1%) 859 1,694 (-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.467 (-1%) 0.482 (+8%) 0.415 0.414 (-1%) 0.408 0.405 (-1%) N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 53.5 (-1%) 114 (+7%) 332 (-3%) 656 (-1%) 1,292 2,580 N/A
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 104 (-1%) 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.513 (+6%) 0.451 (-3%) 0.452 (-1%) 0.448 0.448 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 61.0
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.533

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 ⚠️ 31,367 (-23%) 501,142

Transaction size based on fee payment method

Metric native fee payment method fpc_public fee payment method fpc_private fee payment method
tx_with_fee_size_in_bytes 905 1,161 1,377

Transaction processing duration by data writes.

Metric 0 new note hashes 1 new note hashes 2 new note hashes
tx_pxe_processing_time_ms ⚠️ 2,128 (+25%) ⚠️ 1,346 (+22%) 5,382
Metric 0 public data writes 1 public data writes 2 public data writes 3 public data writes 4 public data writes 5 public data writes 8 public data writes
tx_sequencer_processing_time_ms 11.0 ⚠️ 859 (+49%) 435 1,069 491 (-6%) 1,747 581 (-1%)




fn test_u256(mut x: [u8; 5], y: [u8; 5]) {
Copy link
Member

Choose a reason for hiding this comment

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

We can put these test functions inside of the stdlib.

This is also not being run currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The function is now called by the test.
I have not added it to stdlib test because I do not see any other test in the stdlib

Copy link
Member

Choose a reason for hiding this comment

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

@TomAFrench
Copy link
Member

Closing this as we've been told that crypto team isn't comfortable with the changes.

@ludamad ludamad deleted the gd/biguint256 branch August 22, 2024 15:20
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