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): integrate new range and cmp gadgets #8165

Merged
merged 1 commit into from
Aug 29, 2024

Conversation

IlyasRidhuan
Copy link
Contributor

@IlyasRidhuan IlyasRidhuan commented Aug 23, 2024

time AVM_ENABLE_FULL_PROVING=1 ./bb avm_prove --avm-bytecode /tmp/bb-dY93DM/tmp-ygXEjA/avm_bytecode.bin --avm-calldata /tmp/bb-dY93DM/tmp-ygXEjA/avm_calldata.bin --avm-public-inputs /tmp/bb-dY93DM/tmp-ygXEjA/avm_public_inputs.bin --avm-hints /tmp/bb-dY93DM/tmp-ygXEjA/avm_hints.bin -o /tmp/bb-dY93DM/tmp-ygXEjA/ -v
bb command is: avm_prove
bytecode size: 38126
calldata size: 6
public_inputs size: 691
hints.storage_value_hints size: 2
hints.note_hash_exists_hints size: 0
hints.nullifier_exists_hints size: 1
hints.l1_to_l2_message_exists_hints size: 0
hints.externalcall_hints size: 0
hints.contract_instance_hints size: 0
initializing crs with size: 1048576
using cached crs of size 33554433 at "/mnt/user-data/ilyas/.bb-crs/bn254_g1.dat"
Deserialized 3322 instructions
------- GENERATING TRACE -------
Trace sizes before padding:
        main_trace_size: 65535
        mem_trace_size: 2084
        alu_trace_size: 410
        range_check_size: 65536
        conv_trace_size: 1
        bin_trace_size: 0
        sha256_trace_size: 0
        poseidon2_trace_size: 0
        pedersen_trace_size: 4
        gas_trace_size: 890
        fixed_gas_table_size: 66
        slice_trace_size: 7
        range_check_trace_size: 4266
        cmp_trace_size: 39
Built trace size: 65536
Number of columns: 696
Number of non-zero elements: 236111/45613056 (0%)
Relation degrees:
        alu: [5°: 2, 4°: 6, 3°: 11, 2°: 24, 1°: 5]
        binary: [3°: 1, 2°: 9]
        cmp: [4°: 3, 3°: 1, 2°: 21, 1°: 2]
        conversion: [2°: 1]
        gas: [4°: 2, 3°: 2, 2°: 2]
        keccakf1600: [2°: 1]
        kernel: [3°: 3, 2°: 41]
        main: [4°: 3, 3°: 7, 2°: 101, 1°: 3]
        mem: [5°: 1, 3°: 8, 2°: 41, 1°: 2]
        mem_slice: [3°: 3, 2°: 7, 1°: 1]
        pedersen: [2°: 1]
        poseidon2: [6°: 256, 2°: 17]
        range_check: [3°: 1, 2°: 15, 1°: 9]
        sha256: [2°: 1]
Trace size after padding: 2^16
------- PROVING EXECUTION -------
vk fields size: 66
circuit size: 0x0000000000000000000000000000000000000000000000000000000000010000
num of pub inputs: 0x0000000000000000000000000000000000000000000000000000000000000000
proof written to: "/tmp/bb-dY93DM/tmp-ygXEjA/proof"
vk written to: "/tmp/bb-dY93DM/tmp-ygXEjA/vk"
vk as fields written to: "/tmp/bb-dY93DM/tmp-ygXEjA/vk_fields.json"
------- STATS -------
prove/all_ms: 6953
prove/create_composer_ms: 0
prove/create_prover_ms: 1988
prove/create_verifier_ms: 41
prove/execute_log_derivative_inverse_commitments_round_ms: 344
prove/execute_log_derivative_inverse_round_ms: 205
prove/execute_pcs_rounds_ms: 760
prove/execute_relation_check_rounds_ms: 727
prove/execute_wire_commitments_round_ms: 616
prove/gen_trace_ms: 2150

AVM_ENABLE_FULL_PROVING=1 ./bb avm_prove --avm-bytecode  --avm-calldata        71.13s user 69.17s system 1579% cpu 8.882 total

Copy link
Contributor Author

IlyasRidhuan commented Aug 23, 2024

@IlyasRidhuan IlyasRidhuan changed the title feat(avm): cmp gadget feat(avm): integrate new range and cmp gadgets Aug 23, 2024
@IlyasRidhuan IlyasRidhuan force-pushed the ir/08-14-feat_avm_extract_rng_to_gadget branch from 93b1914 to 8ada417 Compare August 23, 2024 16:37
@AztecBot
Copy link
Collaborator

AztecBot commented Aug 23, 2024

Benchmark results

Metrics with a significant change:

  • protocol_circuit_simulation_time_in_ms (private-kernel-tail-to-public): 1,356 (+62%)
  • avm_simulation_time_ms (Token:mint_public): 47.7 (-85%)
  • avm_simulation_time_ms (Token:assert_minter_and_mint): 318 (+627%)
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 1 threads 4 threads 16 threads 32 threads 64 threads
proof_construction_time_sha256_ms 5,753 1,555 (-2%) 712 764 (+2%) 775 (-1%)
proof_construction_time_sha256_30_ms 11,447 (-1%) 3,084 (-2%) 1,385 (-1%) 1,441 (-1%) 1,464 (-1%)
proof_construction_time_sha256_100_ms 44,021 (-1%) 11,765 (-3%) 5,436 (-5%) 5,621 (-4%) 5,718 (-5%)
proof_construction_time_poseidon_hash_ms 78.0 34.0 34.0 57.0 (-3%) 87.0
proof_construction_time_poseidon_hash_30_ms 1,527 419 (-1%) 202 (-1%) 223 (-3%) 265 (-1%)
proof_construction_time_poseidon_hash_100_ms 5,636 1,504 672 (-1%) 720 (-1%) 752

L2 block published to L1

Each column represents the number of txs on an L2 block published to L1.

Metric 4 txs 8 txs 16 txs
l1_rollup_calldata_size_in_bytes 4,356 7,876 14,884
l1_rollup_calldata_gas 50,148 92,876 177,844
l1_rollup_execution_gas 845,526 1,579,150 3,364,174
l2_block_processing_time_in_ms 254 447 (-4%) 852 (+4%)
l2_block_building_time_in_ms 11,545 22,378 (-1%) 45,045
l2_block_rollup_simulation_time_in_ms 11,544 22,378 (-1%) 45,045
l2_block_public_tx_process_time_in_ms 9,831 20,678 43,301

L2 chain processing

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

Metric 3 blocks 5 blocks
node_history_sync_time_in_ms 2,978 (-3%) 3,904 (-4%)
node_database_size_in_bytes 12,607,568 16,728,144
pxe_database_size_in_bytes 16,254 26,813

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 input_size_in_bytes output_size_in_bytes proving_time_in_ms
private-kernel-init 95.9 (+4%) 396 (-1%) 21,735 44,860 N/A
private-kernel-inner 172 (-14%) 699 (-1%) 72,544 45,007 N/A
private-kernel-reset-tiny 309 (-1%) 712 (-3%) 65,593 44,846 N/A
private-kernel-tail 167 135 (-1%) 50,644 52,257 N/A
base-parity 5.65 N/A 160 96.0 N/A
root-parity 35.7 N/A 73,948 96.0 N/A
base-rollup 2,969 (-2%) N/A 189,136 664 N/A
block-root-rollup 41.6 N/A 58,205 2,448 N/A
public-kernel-setup 84.8 (-1%) N/A 105,085 71,222 N/A
public-kernel-app-logic 98.1 (-1%) N/A 104,911 71,222 N/A
public-kernel-tail 861 N/A 390,582 16,414 N/A
private-kernel-reset-small 310 (-1%) N/A 66,341 45,629 N/A
private-kernel-tail-to-public ⚠️ 1,356 (+62%) 613 (-6%) 455,400 1,825 N/A
public-kernel-teardown 84.6 (-1%) N/A 105,349 71,222 N/A
merge-rollup 20.2 N/A 38,174 664 N/A
undefined N/A N/A N/A N/A 80,442 (+2%)

Stats on running time collected for app circuits

Function input_size_in_bytes output_size_in_bytes witness_generation_time_in_ms
ContractClassRegisterer:register 1,344 11,731 345
ContractInstanceDeployer:deploy 1,408 11,731 18.3
MultiCallEntrypoint:entrypoint 1,920 11,731 407
FeeJuice:deploy 1,376 11,731 388 (-1%)
SchnorrAccount:constructor 1,312 11,731 74.3
SchnorrAccount:entrypoint 2,336 11,731 395 (-1%)
Token:privately_mint_private_note 1,280 11,731 103 (-2%)
FPC:fee_entrypoint_public 1,344 11,731 25.9 (-11%)
Token:transfer 1,312 11,731 230
Benchmarking:create_note 1,344 11,731 84.5 (-3%)
SchnorrAccount:verify_private_authwit 1,280 11,731 27.6 (-1%)
Token:unshield 1,376 11,731 523 (-1%)
FPC:fee_entrypoint_private 1,376 11,731 693 (-2%)

AVM Simulation

Time to simulate various public functions in the AVM.

Function time_ms bytecode_size_in_bytes
FeeJuice:_increase_public_balance 65.0 (+13%) 8,174
FeeJuice:set_portal 14.1 (+18%) 4,055
Token:constructor 82.6 (-4%) 29,082
FPC:constructor 55.0 (-1%) 18,940
FeeJuice:mint_public 41.4 (-4%) 6,522
Token:mint_public ⚠️ 47.7 (-85%) 12,704
Token:assert_minter_and_mint ⚠️ 318 (+627%) 8,467
AuthRegistry:set_authorized 48.9 (-1%) 4,194
FPC:prepare_fee 244 (-6%) 6,747
Token:transfer_public 31.2 (-15%) 39,863
FPC:pay_refund 69.5 (+5%) 9,398
Benchmarking:increment_balance 1,226 7,263
Token:_increase_public_balance 42.8 (+2%) 8,686
FPC:pay_refund_with_shielded_rebate 63.9 (+2%) 9,881

Public DB Access

Time to access various public DBs.

Function time_ms
get-nullifier-index 0.160 (-2%)

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 256 leaves 512 leaves 1024 leaves
batch_insert_into_append_only_tree_16_depth_ms 2.22 (-1%) 3.98 N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_count 16.8 31.7 N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_16_depth_hash_ms 0.116 (-1%) 0.113 N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A 11.4 (+1%) 18.1 (+2%) 32.5 (+7%) 58.7 (-5%) 118 (+5%)
batch_insert_into_append_only_tree_32_depth_hash_count N/A N/A 95.9 159 287 543 1,055
batch_insert_into_append_only_tree_32_depth_hash_ms N/A N/A 0.110 (+1%) 0.105 (+2%) 0.105 (+7%) 0.101 (-5%) 0.106 (+5%)
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 15.1 (+2%) 26.3 (+2%) 45.7 (+7%) 82.2 (-3%) 170 (+6%)
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 109 207 355 691 1,363
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A 0.115 (+2%) 0.106 (+2%) 0.111 (+7%) 0.102 (-3%) 0.108 (+7%)
batch_insert_into_indexed_tree_40_depth_ms N/A N/A 16.9 (-1%) N/A N/A N/A N/A
batch_insert_into_indexed_tree_40_depth_hash_count N/A N/A 132 N/A N/A N/A N/A
batch_insert_into_indexed_tree_40_depth_hash_ms N/A N/A 0.108 N/A N/A N/A N/A

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 64,779 668,997

Transaction size based on fee payment method

| Metric | |
| - | |

@IlyasRidhuan IlyasRidhuan marked this pull request as ready for review August 25, 2024 09:59
@IlyasRidhuan IlyasRidhuan force-pushed the ir/08-14-feat_avm_extract_rng_to_gadget branch from 8ada417 to 543aa2d Compare August 25, 2024 19:01
@IlyasRidhuan IlyasRidhuan force-pushed the ir/08-16-feat_avm_cmp_gadget branch 2 times, most recently from 120f236 to 2ee0bc6 Compare August 25, 2024 20:41
Copy link
Contributor

@jeanmon jeanmon left a comment

Choose a reason for hiding this comment

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

Overall this is very good refactoring! Please try to address my feedback or add an explicit TODO (with potentially a ticket). My main concern is related to potential missing range checks (see comments.)

barretenberg/cpp/pil/avm/alu.pil Outdated Show resolved Hide resolved
barretenberg/cpp/pil/avm/alu.pil Outdated Show resolved Hide resolved
barretenberg/cpp/pil/avm/alu.pil Outdated Show resolved Hide resolved
barretenberg/cpp/pil/avm/alu.pil Show resolved Hide resolved
barretenberg/cpp/pil/avm/gadgets/cmp.pil Outdated Show resolved Hide resolved
barretenberg/cpp/pil/avm/gadgets/cmp.pil Outdated Show resolved Hide resolved
barretenberg/cpp/pil/avm/gas.pil Outdated Show resolved Hide resolved
barretenberg/cpp/pil/avm/mem.pil Outdated Show resolved Hide resolved
barretenberg/cpp/src/barretenberg/vm/avm/trace/trace.cpp Outdated Show resolved Hide resolved
@IlyasRidhuan IlyasRidhuan force-pushed the ir/08-14-feat_avm_extract_rng_to_gadget branch from 543aa2d to a5d24a0 Compare August 28, 2024 12:14
@IlyasRidhuan IlyasRidhuan force-pushed the ir/08-14-feat_avm_extract_rng_to_gadget branch from a5d24a0 to b22d58e Compare August 28, 2024 13:11
@IlyasRidhuan IlyasRidhuan force-pushed the ir/08-14-feat_avm_extract_rng_to_gadget branch from b22d58e to 9915be7 Compare August 28, 2024 16:01
@IlyasRidhuan IlyasRidhuan force-pushed the ir/08-14-feat_avm_extract_rng_to_gadget branch from 9915be7 to cf5d27f Compare August 29, 2024 10:57
@IlyasRidhuan IlyasRidhuan force-pushed the ir/08-16-feat_avm_cmp_gadget branch 2 times, most recently from f2b90b1 to 49bed9b Compare August 29, 2024 15:50
Copy link
Contributor Author

IlyasRidhuan commented Aug 29, 2024

Merge activity

  • Aug 29, 1:34 PM EDT: @IlyasRidhuan started a stack merge that includes this pull request via Graphite.
  • Aug 29, 2:53 PM EDT: Graphite rebased this pull request as part of a merge.
  • Aug 29, 3:08 PM EDT: Graphite couldn't merge this PR because it was not satisfying all requirements (Failed CI: 'merge-check', 'build', 'bb-native-tests', 'noir-examples', 'noir-packages-test', 'docs-preview', 'protocol-circuits-gates-report', 'bb-acir-tests-bb', 'bb-acir-tests-sol', 'bb-acir-tests-sol-honk', 'bb-acir-tests-bb-js').

@IlyasRidhuan IlyasRidhuan changed the base branch from ir/08-14-feat_avm_extract_rng_to_gadget to graphite-base/8165 August 29, 2024 17:35
@IlyasRidhuan IlyasRidhuan changed the base branch from graphite-base/8165 to master August 29, 2024 18:50
@IlyasRidhuan IlyasRidhuan enabled auto-merge (squash) August 29, 2024 21:05
@IlyasRidhuan IlyasRidhuan merged commit 2e1be18 into master Aug 29, 2024
101 checks passed
@IlyasRidhuan IlyasRidhuan deleted the ir/08-16-feat_avm_cmp_gadget branch August 29, 2024 21:55
TomAFrench added a commit that referenced this pull request Aug 30, 2024
* master: (28 commits)
  chore: bump noir-bignum to 0.3.2 (#8276)
  feat: Populate epoch 0 from initial validator set (#8286)
  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
  chore(master): Release 0.51.1 (#8218)
  feat(avm): integrate new range and cmp gadgets (#8165)
  chore: rename process to propose for clarity (#8265)
  chore: Bump provernet agents to 8 and speed up bot (#8280)
  feat(avm): avm recursive verifier cpp (#8162)
  feat: moving fee payout + make proof submission sequential (#8262)
  feat: Block cheat codes in anvil (#8277)
  feat: wallet tx management (#8246)
  refactor(avm): replace range and cmp with gadgets (#8164)
  fix(docs): Update entrypoint details on accounts page (#8184)
  feat: l1-publisher cleanup (#8148)
  feat(avm): range check gadget (#7967)
  fix(ci): spot-runner-action was not built (#8274)
  fix: ts codegen (#8267)
  ...
codygunton pushed a commit that referenced this pull request Aug 30, 2024
```
time AVM_ENABLE_FULL_PROVING=1 ./bb avm_prove --avm-bytecode /tmp/bb-dY93DM/tmp-ygXEjA/avm_bytecode.bin --avm-calldata /tmp/bb-dY93DM/tmp-ygXEjA/avm_calldata.bin --avm-public-inputs /tmp/bb-dY93DM/tmp-ygXEjA/avm_public_inputs.bin --avm-hints /tmp/bb-dY93DM/tmp-ygXEjA/avm_hints.bin -o /tmp/bb-dY93DM/tmp-ygXEjA/ -v
bb command is: avm_prove
bytecode size: 38126
calldata size: 6
public_inputs size: 691
hints.storage_value_hints size: 2
hints.note_hash_exists_hints size: 0
hints.nullifier_exists_hints size: 1
hints.l1_to_l2_message_exists_hints size: 0
hints.externalcall_hints size: 0
hints.contract_instance_hints size: 0
initializing crs with size: 1048576
using cached crs of size 33554433 at "/mnt/user-data/ilyas/.bb-crs/bn254_g1.dat"
Deserialized 3322 instructions
------- GENERATING TRACE -------
Trace sizes before padding:
        main_trace_size: 65535
        mem_trace_size: 2084
        alu_trace_size: 410
        range_check_size: 65536
        conv_trace_size: 1
        bin_trace_size: 0
        sha256_trace_size: 0
        poseidon2_trace_size: 0
        pedersen_trace_size: 4
        gas_trace_size: 890
        fixed_gas_table_size: 66
        slice_trace_size: 7
        range_check_trace_size: 4266
        cmp_trace_size: 39
Built trace size: 65536
Number of columns: 696
Number of non-zero elements: 236111/45613056 (0%)
Relation degrees:
        alu: [5°: 2, 4°: 6, 3°: 11, 2°: 24, 1°: 5]
        binary: [3°: 1, 2°: 9]
        cmp: [4°: 3, 3°: 1, 2°: 21, 1°: 2]
        conversion: [2°: 1]
        gas: [4°: 2, 3°: 2, 2°: 2]
        keccakf1600: [2°: 1]
        kernel: [3°: 3, 2°: 41]
        main: [4°: 3, 3°: 7, 2°: 101, 1°: 3]
        mem: [5°: 1, 3°: 8, 2°: 41, 1°: 2]
        mem_slice: [3°: 3, 2°: 7, 1°: 1]
        pedersen: [2°: 1]
        poseidon2: [6°: 256, 2°: 17]
        range_check: [3°: 1, 2°: 15, 1°: 9]
        sha256: [2°: 1]
Trace size after padding: 2^16
------- PROVING EXECUTION -------
vk fields size: 66
circuit size: 0x0000000000000000000000000000000000000000000000000000000000010000
num of pub inputs: 0x0000000000000000000000000000000000000000000000000000000000000000
proof written to: "/tmp/bb-dY93DM/tmp-ygXEjA/proof"
vk written to: "/tmp/bb-dY93DM/tmp-ygXEjA/vk"
vk as fields written to: "/tmp/bb-dY93DM/tmp-ygXEjA/vk_fields.json"
------- STATS -------
prove/all_ms: 6953
prove/create_composer_ms: 0
prove/create_prover_ms: 1988
prove/create_verifier_ms: 41
prove/execute_log_derivative_inverse_commitments_round_ms: 344
prove/execute_log_derivative_inverse_round_ms: 205
prove/execute_pcs_rounds_ms: 760
prove/execute_relation_check_rounds_ms: 727
prove/execute_wire_commitments_round_ms: 616
prove/gen_trace_ms: 2150

AVM_ENABLE_FULL_PROVING=1 ./bb avm_prove --avm-bytecode  --avm-calldata        71.13s user 69.17s system 1579% cpu 8.882 total
```
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