Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::ProofCompressor Class Reference

Compresses Chonk proofs from vector<fr> to compact byte representations. More...

#include <proof_compression.hpp>

Static Public Member Functions

static size_t compressed_element_count (size_t mega_num_public_inputs=0)
 Count the total compressed elements for a Chonk proof. Each element (scalar or commitment, either curve) compresses to exactly 32 bytes.
 
static size_t compressed_mega_num_public_inputs (size_t compressed_bytes)
 Derive mega_num_public_inputs from compressed proof size.
 
static std::vector< uint8_t > compress_chonk_proof (const ChonkProof &proof)
 
static ChonkProof decompress_chonk_proof (const std::vector< uint8_t > &compressed, size_t mega_num_public_inputs)
 

Private Types

using Fr = curve::BN254::ScalarField
 
using Fq = curve::BN254::BaseField
 

Static Private Member Functions

template<typename Field >
static bool y_is_negative (const Field &y)
 True if y is in the "upper half" of its field, used for point compression sign bit.
 
static void write_u256 (std::vector< uint8_t > &out, const uint256_t &val)
 
static uint256_t read_u256 (const std::vector< uint8_t > &data, size_t &pos)
 
static Fq reconstruct_fq (const Fr &lo, const Fr &hi)
 
static std::pair< Fr, Frsplit_fq (const Fq &val)
 
template<typename ScalarFn , typename CommitmentFn >
static void walk_mega_zk_proof (ScalarFn &&process_scalar, CommitmentFn &&process_commitment, size_t num_public_inputs)
 Walk a MegaZK proof (BN254, ZK sumcheck).
 
template<typename ScalarFn , typename CommitmentFn >
static void walk_merge_proof (ScalarFn &&process_scalar, CommitmentFn &&process_commitment)
 Walk a Merge proof (42 Fr, all BN254).
 
template<typename ScalarFn , typename CommitmentFn >
static void walk_eccvm_proof (ScalarFn &&process_scalar, CommitmentFn &&process_commitment)
 Walk an ECCVM proof (all Grumpkin).
 
template<typename ScalarFn , typename CommitmentFn >
static void walk_ipa_proof (ScalarFn &&process_scalar, CommitmentFn &&process_commitment)
 Walk an IPA proof (64 Fr, all Grumpkin).
 
template<typename ScalarFn , typename CommitmentFn >
static void walk_translator_proof (ScalarFn &&process_scalar, CommitmentFn &&process_commitment)
 Walk a Translator proof (all BN254).
 
template<typename BN254ScalarFn , typename BN254CommFn , typename GrumpkinScalarFn , typename GrumpkinCommFn >
static void walk_chonk_proof (BN254ScalarFn &&bn254_scalar, BN254CommFn &&bn254_comm, GrumpkinScalarFn &&grumpkin_scalar, GrumpkinCommFn &&grumpkin_comm, size_t mega_num_public_inputs)
 Walk a full Chonk proof (5 sub-proofs across two curves).
 

Static Private Attributes

static constexpr uint256_t SIGN_BIT_MASK = uint256_t(1) << 255
 
static constexpr uint64_t NUM_LIMB_BITS = 68
 
static constexpr uint64_t FQ_SPLIT_BITS = NUM_LIMB_BITS * 2
 
static constexpr size_t BN254_FRS_PER_SCALAR = 1
 
static constexpr size_t BN254_FRS_PER_COMM = 4
 
static constexpr size_t GRUMPKIN_FRS_PER_SCALAR = 2
 
static constexpr size_t GRUMPKIN_FRS_PER_COMM = 2
 
static constexpr size_t EXPECTED_MEGA_ZK_FRS
 
static constexpr size_t EXPECTED_MERGE_FRS
 
static constexpr size_t EXPECTED_ECCVM_FRS
 
static constexpr size_t EXPECTED_IPA_FRS
 
static constexpr size_t EXPECTED_TRANSLATOR_FRS
 

Detailed Description

Compresses Chonk proofs from vector<fr> to compact byte representations.

Compression techniques:

  1. Point compression: store only x-coordinate + sign bit (instead of x and y)
  2. Fq-as-u256: store each Fq coordinate as 32 bytes (instead of 2 Fr for lo/hi split)
  3. Fr-as-u256: store each Fr scalar as 32 bytes (uniform encoding)

Every element compresses to exactly 32 bytes regardless of type:

  • BN254 commitment (4 Fr → 32 bytes): point compression on Fq coordinates
  • BN254 scalar (1 Fr → 32 bytes): direct u256 encoding
  • Grumpkin commitment (2 Fr → 32 bytes): point compression on Fr coordinates
  • Grumpkin scalar (2 Fr → 32 bytes): reconstruct Fq, write as u256

Definition at line 32 of file proof_compression.hpp.

Member Typedef Documentation

◆ Fq

Definition at line 34 of file proof_compression.hpp.

◆ Fr

Definition at line 33 of file proof_compression.hpp.

Member Function Documentation

◆ compress_chonk_proof()

static std::vector< uint8_t > bb::ProofCompressor::compress_chonk_proof ( const ChonkProof proof)
inlinestatic

Definition at line 430 of file proof_compression.hpp.

◆ compressed_element_count()

static size_t bb::ProofCompressor::compressed_element_count ( size_t  mega_num_public_inputs = 0)
inlinestatic

Count the total compressed elements for a Chonk proof. Each element (scalar or commitment, either curve) compresses to exactly 32 bytes.

Definition at line 405 of file proof_compression.hpp.

◆ compressed_mega_num_public_inputs()

static size_t bb::ProofCompressor::compressed_mega_num_public_inputs ( size_t  compressed_bytes)
inlinestatic

Derive mega_num_public_inputs from compressed proof size.

Parameters
compressed_bytesTotal size of the compressed proof in bytes.

Definition at line 417 of file proof_compression.hpp.

◆ decompress_chonk_proof()

static ChonkProof bb::ProofCompressor::decompress_chonk_proof ( const std::vector< uint8_t > &  compressed,
size_t  mega_num_public_inputs 
)
inlinestatic

Definition at line 493 of file proof_compression.hpp.

◆ read_u256()

static uint256_t bb::ProofCompressor::read_u256 ( const std::vector< uint8_t > &  data,
size_t &  pos 
)
inlinestaticprivate

Definition at line 59 of file proof_compression.hpp.

◆ reconstruct_fq()

static Fq bb::ProofCompressor::reconstruct_fq ( const Fr lo,
const Fr hi 
)
inlinestaticprivate

Definition at line 68 of file proof_compression.hpp.

◆ split_fq()

static std::pair< Fr, Fr > bb::ProofCompressor::split_fq ( const Fq val)
inlinestaticprivate

Definition at line 73 of file proof_compression.hpp.

◆ walk_chonk_proof()

template<typename BN254ScalarFn , typename BN254CommFn , typename GrumpkinScalarFn , typename GrumpkinCommFn >
static void bb::ProofCompressor::walk_chonk_proof ( BN254ScalarFn &&  bn254_scalar,
BN254CommFn &&  bn254_comm,
GrumpkinScalarFn &&  grumpkin_scalar,
GrumpkinCommFn &&  grumpkin_comm,
size_t  mega_num_public_inputs 
)
inlinestaticprivate

Walk a full Chonk proof (5 sub-proofs across two curves).

Definition at line 304 of file proof_compression.hpp.

◆ walk_eccvm_proof()

template<typename ScalarFn , typename CommitmentFn >
static void bb::ProofCompressor::walk_eccvm_proof ( ScalarFn &&  process_scalar,
CommitmentFn &&  process_commitment 
)
inlinestaticprivate

Walk an ECCVM proof (all Grumpkin).

Layout from ECCVMFlavor::PROOF_LENGTH formula and ECCVM prover code. Grumpkin RoundUnivariateHandler commits to each round univariate and sends 2 evaluations (at 0 and 1), interleaved per round.

Definition at line 168 of file proof_compression.hpp.

◆ walk_ipa_proof()

template<typename ScalarFn , typename CommitmentFn >
static void bb::ProofCompressor::walk_ipa_proof ( ScalarFn &&  process_scalar,
CommitmentFn &&  process_commitment 
)
inlinestaticprivate

Walk an IPA proof (64 Fr, all Grumpkin).

IPA_PROOF_LENGTH = 4 * CONST_ECCVM_LOG_N + 4

Definition at line 236 of file proof_compression.hpp.

◆ walk_mega_zk_proof()

template<typename ScalarFn , typename CommitmentFn >
static void bb::ProofCompressor::walk_mega_zk_proof ( ScalarFn &&  process_scalar,
CommitmentFn &&  process_commitment,
size_t  num_public_inputs 
)
inlinestaticprivate

Walk a MegaZK proof (BN254, ZK sumcheck).

Layout from MegaZKStructuredProofBase and sumcheck prover code.

Definition at line 89 of file proof_compression.hpp.

◆ walk_merge_proof()

template<typename ScalarFn , typename CommitmentFn >
static void bb::ProofCompressor::walk_merge_proof ( ScalarFn &&  process_scalar,
CommitmentFn &&  process_commitment 
)
inlinestaticprivate

Walk a Merge proof (42 Fr, all BN254).

Layout from MergeProver::construct_proof.

Definition at line 142 of file proof_compression.hpp.

◆ walk_translator_proof()

template<typename ScalarFn , typename CommitmentFn >
static void bb::ProofCompressor::walk_translator_proof ( ScalarFn &&  process_scalar,
CommitmentFn &&  process_commitment 
)
inlinestaticprivate

Walk a Translator proof (all BN254).

Layout from TranslatorFlavor::PROOF_LENGTH formula.

Definition at line 254 of file proof_compression.hpp.

◆ write_u256()

static void bb::ProofCompressor::write_u256 ( std::vector< uint8_t > &  out,
const uint256_t val 
)
inlinestaticprivate

Definition at line 52 of file proof_compression.hpp.

◆ y_is_negative()

template<typename Field >
static bool bb::ProofCompressor::y_is_negative ( const Field &  y)
inlinestaticprivate

True if y is in the "upper half" of its field, used for point compression sign bit.

Definition at line 43 of file proof_compression.hpp.

Member Data Documentation

◆ BN254_FRS_PER_COMM

constexpr size_t bb::ProofCompressor::BN254_FRS_PER_COMM = 4
staticconstexprprivate

Definition at line 325 of file proof_compression.hpp.

◆ BN254_FRS_PER_SCALAR

constexpr size_t bb::ProofCompressor::BN254_FRS_PER_SCALAR = 1
staticconstexprprivate

Definition at line 324 of file proof_compression.hpp.

◆ EXPECTED_ECCVM_FRS

constexpr size_t bb::ProofCompressor::EXPECTED_ECCVM_FRS
staticconstexprprivate
Initial value:
=
CONST_ECCVM_LOG_N * GRUMPKIN_FRS_PER_COMM +
2 * CONST_ECCVM_LOG_N * GRUMPKIN_FRS_PER_SCALAR +
(CONST_ECCVM_LOG_N - 1) * GRUMPKIN_FRS_PER_COMM +
CONST_ECCVM_LOG_N * GRUMPKIN_FRS_PER_SCALAR +
NUM_SMALL_IPA_EVALUATIONS * GRUMPKIN_FRS_PER_SCALAR +
NUM_TRANSLATION_EVALUATIONS * GRUMPKIN_FRS_PER_SCALAR +
NUM_SMALL_IPA_EVALUATIONS * GRUMPKIN_FRS_PER_SCALAR +
static constexpr size_t NUM_MASKING_POLYNOMIALS
static constexpr size_t NUM_ALL_ENTITIES
static constexpr size_t NUM_WITNESS_ENTITIES
static constexpr size_t GRUMPKIN_FRS_PER_SCALAR
static constexpr size_t GRUMPKIN_FRS_PER_COMM

Definition at line 354 of file proof_compression.hpp.

◆ EXPECTED_IPA_FRS

constexpr size_t bb::ProofCompressor::EXPECTED_IPA_FRS
staticconstexprprivate
Initial value:

Definition at line 376 of file proof_compression.hpp.

◆ EXPECTED_MEGA_ZK_FRS

constexpr size_t bb::ProofCompressor::EXPECTED_MEGA_ZK_FRS
staticconstexprprivate

◆ EXPECTED_MERGE_FRS

constexpr size_t bb::ProofCompressor::EXPECTED_MERGE_FRS
staticconstexprprivate
Initial value:

Definition at line 346 of file proof_compression.hpp.

◆ EXPECTED_TRANSLATOR_FRS

◆ FQ_SPLIT_BITS

constexpr uint64_t bb::ProofCompressor::FQ_SPLIT_BITS = NUM_LIMB_BITS * 2
staticconstexprprivate

Definition at line 40 of file proof_compression.hpp.

◆ GRUMPKIN_FRS_PER_COMM

constexpr size_t bb::ProofCompressor::GRUMPKIN_FRS_PER_COMM = 2
staticconstexprprivate

Definition at line 327 of file proof_compression.hpp.

◆ GRUMPKIN_FRS_PER_SCALAR

constexpr size_t bb::ProofCompressor::GRUMPKIN_FRS_PER_SCALAR = 2
staticconstexprprivate

Definition at line 326 of file proof_compression.hpp.

◆ NUM_LIMB_BITS

constexpr uint64_t bb::ProofCompressor::NUM_LIMB_BITS = 68
staticconstexprprivate

Definition at line 39 of file proof_compression.hpp.

◆ SIGN_BIT_MASK

constexpr uint256_t bb::ProofCompressor::SIGN_BIT_MASK = uint256_t(1) << 255
staticconstexprprivate

Definition at line 36 of file proof_compression.hpp.


The documentation for this class was generated from the following file: