|
| 1 | +use ark_crypto_primitives::{ |
| 2 | + crh::{sha256::Sha256, CRHScheme, TwoToOneCRHScheme}, |
| 3 | + merkle_tree::{ByteDigestConverter, Config}, |
| 4 | +}; |
| 5 | +use ark_pcs_bench_templates::*; |
| 6 | +use ark_poly::{DenseMultilinearExtension, MultilinearExtension}; |
| 7 | + |
| 8 | +use ark_bn254::Fr; |
| 9 | +use ark_ff::PrimeField; |
| 10 | + |
| 11 | +use ark_poly_commit::linear_codes::{LinearCodePCS, MultilinearBrakedown}; |
| 12 | +use blake2::Blake2s256; |
| 13 | +use rand_chacha::ChaCha20Rng; |
| 14 | + |
| 15 | +// Brakedown PCS over BN254 |
| 16 | +struct MerkleTreeParams; |
| 17 | +type LeafH = LeafIdentityHasher; |
| 18 | +type CompressH = Sha256; |
| 19 | +impl Config for MerkleTreeParams { |
| 20 | + type Leaf = Vec<u8>; |
| 21 | + |
| 22 | + type LeafDigest = <LeafH as CRHScheme>::Output; |
| 23 | + type LeafInnerDigestConverter = ByteDigestConverter<Self::LeafDigest>; |
| 24 | + type InnerDigest = <CompressH as TwoToOneCRHScheme>::Output; |
| 25 | + |
| 26 | + type LeafHash = LeafH; |
| 27 | + type TwoToOneHash = CompressH; |
| 28 | +} |
| 29 | + |
| 30 | +pub type MLE<F> = DenseMultilinearExtension<F>; |
| 31 | +type MTConfig = MerkleTreeParams; |
| 32 | +type ColHasher<F> = FieldToBytesColHasher<F, Blake2s256>; |
| 33 | +type Brakedown<F> = LinearCodePCS< |
| 34 | + MultilinearBrakedown<F, MTConfig, MLE<F>, ColHasher<F>>, |
| 35 | + F, |
| 36 | + MLE<F>, |
| 37 | + MTConfig, |
| 38 | + ColHasher<F>, |
| 39 | +>; |
| 40 | + |
| 41 | +fn rand_poly_brakedown_ml<F: PrimeField>( |
| 42 | + num_vars: usize, |
| 43 | + rng: &mut ChaCha20Rng, |
| 44 | +) -> DenseMultilinearExtension<F> { |
| 45 | + DenseMultilinearExtension::rand(num_vars, rng) |
| 46 | +} |
| 47 | + |
| 48 | +fn rand_point_brakedown_ml<F: PrimeField>(num_vars: usize, rng: &mut ChaCha20Rng) -> Vec<F> { |
| 49 | + (0..num_vars).map(|_| F::rand(rng)).collect() |
| 50 | +} |
| 51 | + |
| 52 | +const MIN_NUM_VARS: usize = 12; |
| 53 | +const MAX_NUM_VARS: usize = 22; |
| 54 | + |
| 55 | +bench!( |
| 56 | + Brakedown<Fr>, |
| 57 | + rand_poly_brakedown_ml, |
| 58 | + rand_point_brakedown_ml |
| 59 | +); |
0 commit comments