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

fix(avm): relax constraints for leaf_index kernel opcodes #8288

Merged
merged 4 commits into from
Sep 3, 2024

Conversation

IlyasRidhuan
Copy link
Contributor

Re-constraining this is being tracked in #8287

@IlyasRidhuan IlyasRidhuan requested review from fcarreiro and removed request for fcarreiro, Maddiaa0 and jeanmon August 30, 2024 09:36
@AztecBot
Copy link
Collaborator

AztecBot commented Aug 30, 2024

Benchmark results

Metrics with a significant change:

  • protocol_circuit_input_size_in_bytes (public-kernel-tail): 497,078 (+27%)
  • avm_simulation_time_ms (Token:transfer_public): 21.1 (-36%)
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,750 1,560 714 761 (+1%) 777 (+1%)
proof_construction_time_sha256_30_ms 11,454 3,084 1,377 (-1%) 1,418 (-2%) 1,457
proof_construction_time_sha256_100_ms 44,359 (+1%) 11,913 (+1%) 5,512 (+1%) 5,702 (+5%) 5,714 (-1%)
proof_construction_time_poseidon_hash_ms 78.0 34.0 34.0 59.0 (+4%) 88.0 (+1%)
proof_construction_time_poseidon_hash_30_ms 1,526 421 202 222 (-1%) 270
proof_construction_time_poseidon_hash_100_ms 5,639 1,539 (+2%) 674 749 (+1%) 746

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,244 92,972 178,216
l1_rollup_execution_gas 1,396,495 2,130,119 3,915,419
l2_block_processing_time_in_ms 255 443 (-1%) 826
l2_block_building_time_in_ms 12,133 (+7%) 23,834 (+7%) 47,308 (+6%)
l2_block_rollup_simulation_time_in_ms 12,132 (+7%) 23,834 (+7%) 47,308 (+6%)
l2_block_public_tx_process_time_in_ms 10,330 (+7%) 21,951 (+8%) 45,382 (+6%)

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,960 (+1%) 3,807 (-2%)
node_database_size_in_bytes 12,595,280 16,724,048
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 88.9 406 (+3%) 21,755 44,860 N/A
private-kernel-inner 167 (+1%) 709 (+1%) 72,566 45,007 N/A
private-kernel-reset-tiny 305 713 (-2%) 65,590 44,846 N/A
private-kernel-tail 165 (+1%) 136 (+1%) 50,643 58,274 (+12%) N/A
base-parity 5.62 (+1%) N/A 160 96.0 N/A
root-parity 35.3 N/A 73,948 96.0 N/A
base-rollup 3,674 (+6%) N/A 189,136 664 N/A
block-root-rollup 41.6 N/A 58,205 2,448 N/A
public-kernel-setup 90.6 (+8%) N/A 114,173 (+9%) 79,414 (+12%) N/A
public-kernel-app-logic 100 (+5%) N/A 113,999 (+9%) 79,414 (+12%) N/A
public-kernel-tail 934 (+7%) N/A ⚠️ 497,078 (+27%) 16,414 N/A
private-kernel-reset-small 323 (+5%) N/A 66,341 45,629 N/A
private-kernel-tail-to-public 1,375 625 (+2%) 458,474 (+1%) 1,825 N/A
public-kernel-teardown 88.1 (+6%) N/A 114,437 (+9%) 79,414 (+12%) N/A
merge-rollup 20.1 (-4%) N/A 38,174 664 N/A
undefined N/A N/A N/A N/A 79,197

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 341 (-1%)
ContractInstanceDeployer:deploy 1,408 11,731 18.5 (+1%)
MultiCallEntrypoint:entrypoint 1,920 11,731 407
FeeJuice:deploy 1,376 11,731 390 (+1%)
SchnorrAccount:constructor 1,312 11,731 75.4
SchnorrAccount:entrypoint 2,304 11,731 397
Token:privately_mint_private_note 1,280 11,731 107 (+3%)
FPC:fee_entrypoint_public 1,344 11,731 26.8 (-9%)
Token:transfer 1,312 11,731 229 (-3%)
Benchmarking:create_note 1,344 11,731 88.1
SchnorrAccount:verify_private_authwit 1,280 11,731 27.8 (+1%)
Token:unshield 1,376 11,731 530 (+1%)
FPC:fee_entrypoint_private 1,376 11,731 747 (+5%)

AVM Simulation

Time to simulate various public functions in the AVM.

Function time_ms bytecode_size_in_bytes
FeeJuice:_increase_public_balance 55.7 (+2%) 7,739
FeeJuice:set_portal 11.6 (-4%) 2,354
Token:constructor 83.3 (+2%) 26,051
FPC:constructor 53.1 (+1%) 18,001
FeeJuice:mint_public 39.9 5,877
Token:mint_public 71.9 (+3%) 10,917
Token:assert_minter_and_mint 42.6 (+3%) 7,512
AuthRegistry:set_authorized 39.0 (+2%) 4,391
FPC:prepare_fee 237 (+2%) 7,043
Token:transfer_public ⚠️ 21.1 (-36%) 39,426
FPC:pay_refund 59.9 (+13%) 10,234
Benchmarking:increment_balance 1,280 (+7%) 6,563
Token:_increase_public_balance 39.7 (-3%) 8,433
FPC:pay_refund_with_shielded_rebate 64.5 (+2%) 10,783

Public DB Access

Time to access various public DBs.

Function time_ms
get-nullifier-index 0.163 (+4%)

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.18 3.92 (+2%) 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.114 0.111 (+2%) N/A N/A N/A N/A N/A
batch_insert_into_append_only_tree_32_depth_ms N/A N/A 11.3 17.4 30.5 58.6 115 (+2%)
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.109 0.101 0.0996 0.101 (-1%) 0.103 (+3%)
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 14.8 (+3%) 25.5 (-1%) 43.3 81.7 (-1%) 162 (+1%)
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.112 (+3%) 0.103 0.105 0.101 0.102 (+1%)
batch_insert_into_indexed_tree_40_depth_ms N/A N/A 16.5 (-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.105 (-1%) 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 72,050 (+11%) 670,963

Transaction size based on fee payment method

| Metric | |
| - | |

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.

LGTM!

#[KERNEL_OUTPUT_LOOKUP]
sel_q_kernel_output_lookup {kernel_out_offset, ia, side_effect_counter, ib} in sel_kernel_out {clk, kernel_value_out, kernel_side_effect_out, kernel_metadata_out};
sel_q_kernel_output_lookup {kernel_out_offset, /*ia,*/ /*side_effect_counter,*/ ib } in sel_kernel_out {clk, /*kernel_value_out,*/ /*kernel_side_effect_out,*/ kernel_metadata_out};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to turn off the kernel_value_out and side_effect parts of the lookup

}

// Leaf index -> exists
std::unordered_map<uint32_t, FF> get_leaf_index_hints() const
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Splitting out leaf index hints since they now use the leaf index instead of side effect counters which would likely collide in a single map

@@ -173,7 +173,16 @@ void AvmKernelTraceBuilder::op_note_hash_exists(uint32_t clk,
{

uint32_t offset = START_NOTE_HASH_EXISTS_WRITE_OFFSET + note_hash_exists_offset;
perform_kernel_output_lookup(offset, side_effect_counter, note_hash, FF(result));
// TODO(#8287)Lookups are heavily underconstrained atm
if (result == 1) {
Copy link
Contributor Author

@IlyasRidhuan IlyasRidhuan Sep 2, 2024

Choose a reason for hiding this comment

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

This whole section is a bit messy atm while the lookups are still "half-on". Will be resolved when we clean up the hints/public inputs stuff and if we give the trace.cpp access to the public inputs as well

@@ -467,9 +468,10 @@ describe('AVM simulator: transpiled Noir contracts', () => {
expect(results.output).toEqual([expectFound ? Fr.ONE : Fr.ZERO]);

expect(trace.traceL1ToL2MessageCheck).toHaveBeenCalledTimes(1);
const foundOrUndefined = mockAtLeafIndex === undefined || results.output[0].equals(Fr.ONE);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is similar to what we do now for the accrued_substate.test.ts, because of the new way we handle non-exists criteria for leaf indices

const exists = gotLeafIndex === leafIndex.toBigInt();
this.log.debug(`noteHashes(${storageAddress})@${noteHash} ?? leafIndex: ${leafIndex}, exists: ${exists}.`);
this.trace.traceNoteHashCheck(storageAddress, noteHash, leafIndex, exists);
const gotLeafValue = await this.hostStorage.commitmentsDb.getCommitmentValue(leafIndex.toBigInt());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now get the value given the index rather than the other way around, if the values do not match, we return the value that we found (this way the kernel can verify the merkle path).

We constrain equality in the VM (eventually)

@IlyasRidhuan IlyasRidhuan merged commit 62bd9dc into lw/public_validation_requests Sep 3, 2024
93 of 101 checks passed
@IlyasRidhuan IlyasRidhuan deleted the ir/avm_update_kernel branch September 3, 2024 14:54
IlyasRidhuan added a commit that referenced this pull request Sep 3, 2024
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.

4 participants