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: fold acir programs #6563

Merged
merged 22 commits into from
May 24, 2024
Merged

feat: fold acir programs #6563

merged 22 commits into from
May 24, 2024

Conversation

ledwards2225
Copy link
Contributor

@ledwards2225 ledwards2225 commented May 21, 2024

Introduces tests of ClientIvc accumulation for a stack of acir-represented circuits generated by noir. Tests appear in three locations: the bb acir tests, the bb.js acir tests, and the new AcirIntegration test suite (which facilitates a better debugging workflow).

@ledwards2225 ledwards2225 self-assigned this May 21, 2024
@AztecBot
Copy link
Collaborator

AztecBot commented May 23, 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.

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 5,733 (+1%) 1,551 714 774 (+1%) 774 (+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 1,412 1,412 1,412
l1_rollup_calldata_gas 9,452 9,464 9,452
l1_rollup_execution_gas 616,093 616,105 616,093
l2_block_processing_time_in_ms 1,370 (-2%) 5,058 (-3%) 10,083 (-2%)
l2_block_building_time_in_ms 47,066 (-1%) 186,371 (-1%) 372,512 (-1%)
l2_block_rollup_simulation_time_in_ms 46,897 (-1%) 185,738 (-1%) 371,259 (-1%)
l2_block_public_tx_process_time_in_ms 25,076 (-3%) 104,673 (-3%) 214,209 (-1%)

L2 chain processing

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

Metric 3 blocks 5 blocks
node_history_sync_time_in_ms 10,070 (+1%) 15,377 (+1%)
node_database_size_in_bytes 14,499,920 21,364,816
pxe_database_size_in_bytes 18,071 29,868

Circuits stats

Stats on running time and I/O sizes collected for every kernel circuit run across all benchmarks.

Circuit protocol_circuit_simulation_time_in_ms protocol_circuit_witness_generation_time_in_ms protocol_circuit_proving_time_in_ms protocol_circuit_input_size_in_bytes protocol_circuit_output_size_in_bytes protocol_circuit_proof_size_in_bytes protocol_circuit_num_public_inputs protocol_circuit_size_in_gates
private-kernel-init 160 (-1%) 3,627 (-2%) 22,053 19,990 61,798 86,720 2,643 1,048,576
private-kernel-inner 604 (-1%) 4,181 (-2%) 47,730 (-1%) 88,862 61,798 86,720 2,643 2,097,152
private-kernel-tail 530 (-1%) 2,917 (+2%) 35,578 (+1%) 86,653 76,438 10,624 265 2,097,152
base-parity 6.53 (-3%) 1,229 (+1%) 2,898 128 64.0 2,208 2.00 131,072
root-parity 50.7 49.9 (-8%) 43,953 27,084 64.0 2,720 18.0 2,097,152
base-rollup 767 (+2%) 2,316 (+1%) 74,302 119,578 756 3,648 47.0 4,194,304
root-rollup 114 (-1%) 66.1 (+3%) 19,169 (-2%) 25,297 620 3,456 41.0 1,048,576
public-kernel-app-logic 525 (-1%) 2,857 48,481 (+3%) 103,405 84,766 116,832 3,584 2,097,152
public-kernel-tail 1,196 25,448 (+1%) 154,176 (-1%) 393,850 7,490 10,624 265 8,388,608
private-kernel-reset-small 583 2,228 (-5%) 26,832 (+8%) 118,173 61,798 86,720 2,643 1,048,576
merge-rollup 29.0 (-1%) N/A N/A 16,534 756 N/A N/A N/A
public-kernel-setup 625 (-1%) N/A N/A 103,405 84,766 N/A N/A N/A
public-kernel-teardown 528 (-1%) N/A N/A 103,405 84,766 N/A N/A N/A
private-kernel-tail-to-public N/A 9,561 (-3%) 83,278 (+2%) N/A N/A 116,832 3,584 4,194,304

Stats on running time collected for app circuits

Function app_circuit_proof_size_in_bytes app_circuit_proving_time_in_ms app_circuit_size_in_gates app_circuit_num_public_inputs
SchnorrAccount:entrypoint 16,128 46,268 (+1%) 2,097,152 437
Token:transfer 16,128 46,074 (+7%) 2,097,152 437

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 11.3 (-1%) 18.6 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.7 31.8 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.661 (-1%) 0.571 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 52.6 (-1%) 81.1 (-1%) 261 (-3%) 508 (+1%) 988 (-2%) 1,963 (-2%) N/A
batch_insert_into_append_only_tree_32_depth_hash_count N/A N/A 95.9 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.538 (-1%) 0.500 (-1%) 0.475 (-3%) 0.474 0.469 (-2%) 0.469 (-2%) N/A
batch_insert_into_indexed_tree_20_depth_ms N/A N/A 62.8 (-1%) 120 (-1%) 379 (-2%) 749 (+1%) 1,471 (-2%) 2,937 (-2%) N/A
batch_insert_into_indexed_tree_20_depth_hash_count N/A N/A 106 208 692 1,363 2,707 5,395 N/A
batch_insert_into_indexed_tree_20_depth_hash_ms N/A N/A 0.544 (-1%) 0.538 (-1%) 0.515 (-2%) 0.513 (+1%) 0.510 (-2%) 0.511 (-2%) 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 67.0 (-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 107
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.594 (-1%)

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 82,705 664,768

Transaction size based on fee payment method

| Metric | |
| - | |

Transaction processing duration by data writes.

Metric 0 new note hashes 1 new note hashes 2 new note hashes
tx_pxe_processing_time_ms 11,627 (+4%) 4,227 (-1%) 70,092 (+1%)
Metric 1 public data writes 2 public data writes 3 public data writes 4 public data writes 8 public data writes
tx_sequencer_processing_time_ms 3,219 (-1%) 2,127 (-1%) 6,023 (-1%) 2,293 2,583 (-1%)

@@ -54,12 +54,6 @@ class ClientIVCTests : public ::testing::Test {
Builder circuit{ ivc.goblin.op_queue };
MockCircuits::construct_arithmetic_circuit(circuit, log2_num_gates);

// TODO(https://github.com/AztecProtocol/barretenberg/issues/911): We require goblin ops to be added to the
Copy link
Contributor Author

Choose a reason for hiding this comment

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

moved this inside ClientIvc to avoid needing to handle it in multiple locations. Made new more descriptive issue.

testing::Values("fold_basic", "fold_basic_nested_call"));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Restricted this to just two tests since some of them have >100 circuits which would take forever with clientIvc, especially because we need to use the structured trace to handle the different sized circuits. All of the fold tests are already tested in the acir_tests suite anyway

@@ -200,6 +200,10 @@ template <class ProverInstances>
FoldingResult<typename ProverInstances::Flavor> ProtoGalaxyProver_<ProverInstances>::fold_instances()
{
BB_OP_COUNT_TIME_NAME("ProtogalaxyProver::fold_instances");
// Ensure instances are all of the same size
Copy link
Contributor Author

@ledwards2225 ledwards2225 May 23, 2024

Choose a reason for hiding this comment

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

This has bitten me a few times. Usually this is a case where verification just fails without any other asserts being triggered.

protected:
static void SetUpTestSuite() { srs::init_crs_factory("../srs_db/ignition"); }
};

class AcirIntegrationSingleTest : public AcirIntegrationTest, public testing::WithParamInterface<std::string> {};
Copy link
Contributor Author

@ledwards2225 ledwards2225 May 23, 2024

Choose a reason for hiding this comment

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

weird diff here. This class already existed I just moved the bn254 init to the base class since one of the added tests uses the base class directly

@ledwards2225 ledwards2225 marked this pull request as ready for review May 23, 2024 17:23
Copy link
Contributor

Changes to circuit sizes

Generated at commit: da6bade698abdce833f11227d9513faf33bd1628, compared to commit: 0f45b77232e8f6ff7d7891755241587417494194

🧾 Summary (100% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
public_kernel_tail +58,118 ❌ +5.99% +131,573 ❌ +2.99%
private_kernel_tail_to_public_simulated 0 ➖ 0.00% +64 ❌ +1.82%
public_kernel_app_logic_simulated 0 ➖ 0.00% +64 ❌ +1.82%
public_kernel_setup_simulated 0 ➖ 0.00% +64 ❌ +1.82%
public_kernel_teardown_simulated 0 ➖ 0.00% +64 ❌ +1.82%
rollup_base -313 ✅ -0.16% -4,124 ✅ -0.20%
private_kernel_tail_simulated 0 ➖ 0.00% -1 ✅ -0.39%
public_kernel_tail_simulated 0 ➖ 0.00% -1 ✅ -0.39%
private_kernel_tail_to_public +49,552 ❌ +8.66% -12,389 ✅ -0.57%
private_kernel_reset -1,171 ✅ -0.45% -15,755 ✅ -0.62%
private_kernel_reset_big -1,011 ✅ -0.53% -15,491 ✅ -0.91%
public_kernel_teardown +364 ❌ +0.15% -16,642 ✅ -1.01%
public_kernel_app_logic +364 ❌ +0.15% -16,642 ✅ -1.02%
public_kernel_setup +232 ❌ +0.10% -16,821 ✅ -1.11%
private_kernel_reset_medium -931 ✅ -0.60% -15,359 ✅ -1.21%
private_kernel_reset_small -891 ✅ -0.64% -15,293 ✅ -1.44%
private_kernel_init -5,058 ✅ -2.17% -15,009 ✅ -1.76%
private_kernel_inner -5,414 ✅ -2.02% -35,140 ✅ -2.00%
private_kernel_init_simulated 0 ➖ 0.00% -88 ✅ -3.24%
private_kernel_inner_simulated 0 ➖ 0.00% -88 ✅ -3.24%
private_kernel_reset_simulated 0 ➖ 0.00% -88 ✅ -3.24%
private_kernel_reset_simulated_big 0 ➖ 0.00% -88 ✅ -3.24%
private_kernel_reset_simulated_medium 0 ➖ 0.00% -88 ✅ -3.24%
private_kernel_reset_simulated_small 0 ➖ 0.00% -88 ✅ -3.24%
private_kernel_tail -6,186 ✅ -3.07% -130,936 ✅ -9.03%

Full diff report 👇
Program ACIR opcodes (+/-) % Circuit size (+/-) %
public_kernel_tail 1,027,756 (+58,118) +5.99% 4,532,550 (+131,573) +2.99%
private_kernel_tail_to_public_simulated 1 (0) 0.00% 3,573 (+64) +1.82%
public_kernel_app_logic_simulated 1 (0) 0.00% 3,573 (+64) +1.82%
public_kernel_setup_simulated 1 (0) 0.00% 3,573 (+64) +1.82%
public_kernel_teardown_simulated 1 (0) 0.00% 3,573 (+64) +1.82%
rollup_base 191,492 (-313) -0.16% 2,110,543 (-4,124) -0.20%
private_kernel_tail_simulated 1 (0) 0.00% 254 (-1) -0.39%
public_kernel_tail_simulated 1 (0) 0.00% 254 (-1) -0.39%
private_kernel_tail_to_public 621,552 (+49,552) +8.66% 2,150,433 (-12,389) -0.57%
private_kernel_reset 257,443 (-1,171) -0.45% 2,530,938 (-15,755) -0.62%
private_kernel_reset_big 188,976 (-1,011) -0.53% 1,681,543 (-15,491) -0.91%
public_kernel_teardown 250,759 (+364) +0.15% 1,623,261 (-16,642) -1.01%
public_kernel_app_logic 250,399 (+364) +0.15% 1,622,860 (-16,642) -1.02%
public_kernel_setup 221,992 (+232) +0.10% 1,492,682 (-16,821) -1.11%
private_kernel_reset_medium 154,744 (-931) -0.60% 1,256,847 (-15,359) -1.21%
private_kernel_reset_small 137,627 (-891) -0.64% 1,044,498 (-15,293) -1.44%
private_kernel_init 228,119 (-5,058) -2.17% 838,870 (-15,009) -1.76%
private_kernel_inner 262,668 (-5,414) -2.02% 1,718,162 (-35,140) -2.00%
private_kernel_init_simulated 1 (0) 0.00% 2,632 (-88) -3.24%
private_kernel_inner_simulated 1 (0) 0.00% 2,632 (-88) -3.24%
private_kernel_reset_simulated 1 (0) 0.00% 2,632 (-88) -3.24%
private_kernel_reset_simulated_big 1 (0) 0.00% 2,632 (-88) -3.24%
private_kernel_reset_simulated_medium 1 (0) 0.00% 2,632 (-88) -3.24%
private_kernel_reset_simulated_small 1 (0) 0.00% 2,632 (-88) -3.24%
private_kernel_tail 195,031 (-6,186) -3.07% 1,319,627 (-130,936) -9.03%

Copy link
Contributor

@lucasxia01 lucasxia01 left a comment

Choose a reason for hiding this comment

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

LGTM

*
*/
TEST_F(AcirIntegrationTest, UpdateAcirCircuit)
Copy link
Contributor

Choose a reason for hiding this comment

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

is this to avoid issues like the premature finalization?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah or anything else that would break this functionality. If this test was present when Maxim made those changes, it would've alerted us to an issue

@ledwards2225 ledwards2225 merged commit f7d6541 into master May 24, 2024
85 checks passed
@ledwards2225 ledwards2225 deleted the lde/acir_folding branch May 24, 2024 18:02
ludamad added a commit that referenced this pull request May 24, 2024
ludamad added a commit that referenced this pull request May 24, 2024
@lucasxia01 lucasxia01 restored the lde/acir_folding branch May 24, 2024 19:40
AztecBot pushed a commit to AztecProtocol/barretenberg that referenced this pull request May 25, 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.

3 participants