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(avm-mini): add sub, mul, div and error handling for finite fields #3612

Merged
merged 14 commits into from
Dec 8, 2023

Conversation

jeanmon
Copy link
Contributor

@jeanmon jeanmon commented Dec 7, 2023

Resolves #3546
Resolves #3548

Description

This PR introduces the following opcodes for the finite field type:

  • SUB: subtraction
  • MUL: multiplication
  • DIV: division

For division, error is raised whenever the numerator is zero. A boolean column op_err was introduced for this purpose.

@jeanmon jeanmon changed the title avm-mini: add sub, mul, div and error handling for finite fields feat(avm-mini): add sub, mul, div and error handling for finite fields Dec 7, 2023
@AztecBot
Copy link
Collaborator

AztecBot commented Dec 7, 2023

Benchmark results

Metrics with a significant change:

  • note_trial_decrypting_time_in_ms (8): 20.1 (-46%)
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 379b5adc 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 128 txs
l1_rollup_calldata_size_in_bytes 45,444 179,588 716,132
l1_rollup_calldata_gas 222,972 867,656 3,449,576
l1_rollup_execution_gas 842,059 3,594,764 22,204,945
l2_block_processing_time_in_ms 2,205 (-5%) 8,463 35,210 (-1%)
note_successful_decrypting_time_in_ms 311 (-5%) 919 3,378 (-3%)
note_trial_decrypting_time_in_ms ⚠️ 20.1 (-46%) 47.4 (-3%) 200 (-1%)
l2_block_building_time_in_ms 20,125 80,117 322,830
l2_block_rollup_simulation_time_in_ms 16,600 66,239 267,101
l2_block_public_tx_process_time_in_ms 3,495 13,808 55,480

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 24,701 (-1%) 47,140 (-1%)
note_history_successful_decrypting_time_in_ms 2,148 (-1%) 4,171 (-1%)
note_history_trial_decrypting_time_in_ms 163 232
node_database_size_in_bytes 3,626,330 3,922,697
pxe_database_size_in_bytes 29,748 59,307

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 199 43,109 20,441
private-kernel-ordering 114 (-1%) 25,833 9,689
base-rollup 2,953 667,692 873
root-rollup 84.2 (-1%) 4,072 881
private-kernel-inner 259 64,516 20,441
public-kernel-private-input 171 25,203 20,441
public-kernel-non-first-iteration 168 (-1%) 25,245 20,441
merge-rollup 10.9 2,592 873

Miscellaneous

Transaction sizes based on how many contracts are deployed in the tx.

Metric 0 deployed contracts 1 deployed contracts
tx_size_in_bytes 10,323 25,938

Copy link
Member

@Maddiaa0 Maddiaa0 left a comment

Choose a reason for hiding this comment

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

nice

@Rumata888
Copy link
Contributor

Could you please provide a description of the PR? As in "this adds opcodes for the AVM Mini ... ". Makes it easier to follow what PRs are about

trace_builder.add(4, 5, 5);
trace_builder.add(5, 5, 5);
trace_builder.add(5, 6, 7);
// Memory layout: [0,0,45,23,12,0,0,0,....]
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add comments that would explain what you are testing? Documenting intentions is helpful further down the line, when somebody will need to support this code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. A subsequent PR will be about multiple unit tests and will be commented.

Copy link
Contributor

@Rumata888 Rumata888 left a comment

Choose a reason for hiding this comment

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

Everything looks good, please just add some comments in places I've highlighted

@jeanmon jeanmon merged commit b190ae9 into avm-main Dec 8, 2023
84 checks passed
@jeanmon jeanmon deleted the jm/3546-ff-sub-div branch December 8, 2023 16:57
michaelelliot pushed a commit to Swoir/noir_rs that referenced this pull request Feb 28, 2024
AztecProtocol#3612)

Resolves AztecProtocol#3546 
Resolves AztecProtocol#3548

### Description

This PR introduces the following opcodes for the finite field type:

- SUB: subtraction
- MUL: multiplication
- DIV: division

For division, error is raised whenever the numerator is zero. A boolean
column op_err was introduced for this purpose.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants