|
3 | 3 | #include "barretenberg/chonk/chonk.hpp" |
4 | 4 | #include "barretenberg/chonk/chonk_verifier.hpp" |
5 | 5 | #include "barretenberg/chonk/mock_circuit_producer.hpp" |
| 6 | +#include "barretenberg/chonk/proof_compression.hpp" |
6 | 7 | #include "barretenberg/chonk/test_bench_shared.hpp" |
7 | 8 | #include "barretenberg/common/assert.hpp" |
| 9 | +#include "barretenberg/common/log.hpp" |
8 | 10 | #include "barretenberg/common/mem.hpp" |
9 | 11 | #include "barretenberg/common/test.hpp" |
10 | 12 | #include "barretenberg/ecc/curves/grumpkin/grumpkin.hpp" |
@@ -563,3 +565,33 @@ TEST_F(ChonkTests, MTailPropagationConsistency) |
563 | 565 | { |
564 | 566 | ChonkTests::test_hiding_kernel_io_propagation(HidingKernelIOField::ECC_OP_TABLES); |
565 | 567 | } |
| 568 | + |
| 569 | +TEST_F(ChonkTests, ProofCompressionRoundtrip) |
| 570 | +{ |
| 571 | + TestSettings settings{ .log2_num_gates = SMALL_LOG_2_NUM_GATES }; |
| 572 | + auto [proof, vk_and_hash] = accumulate_and_prove_ivc(/*num_app_circuits=*/1, settings); |
| 573 | + |
| 574 | + auto original_flat = proof.to_field_elements(); |
| 575 | + info("Original proof size: ", original_flat.size(), " Fr elements (", original_flat.size() * 32, " bytes)"); |
| 576 | + |
| 577 | + auto compressed = ProofCompressor::compress_chonk_proof(proof); |
| 578 | + double ratio = static_cast<double>(original_flat.size() * 32) / static_cast<double>(compressed.size()); |
| 579 | + info("Compressed proof size: ", compressed.size(), " bytes"); |
| 580 | + info("Compression ratio: ", ratio, "x"); |
| 581 | + |
| 582 | + // Compression should achieve at least 1.5x (commitments 4 Fr → 32 bytes, scalars 1:1) |
| 583 | + EXPECT_GE(ratio, 1.5) << "Compression ratio " << ratio << "x is below the expected minimum of 1.5x"; |
| 584 | + |
| 585 | + size_t mega_num_pub_inputs = proof.mega_proof.size() - ChonkProof::HIDING_KERNEL_PROOF_LENGTH_WITHOUT_PUBLIC_INPUTS; |
| 586 | + ChonkProof decompressed = ProofCompressor::decompress_chonk_proof(compressed, mega_num_pub_inputs); |
| 587 | + |
| 588 | + // Verify element-by-element roundtrip |
| 589 | + auto decompressed_flat = decompressed.to_field_elements(); |
| 590 | + ASSERT_EQ(decompressed_flat.size(), original_flat.size()); |
| 591 | + for (size_t i = 0; i < original_flat.size(); i++) { |
| 592 | + ASSERT_EQ(decompressed_flat[i], original_flat[i]) << "Mismatch at element " << i; |
| 593 | + } |
| 594 | + |
| 595 | + // Verify the decompressed proof |
| 596 | + EXPECT_TRUE(verify_chonk(decompressed, vk_and_hash)); |
| 597 | +} |
0 commit comments