Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
fri.rs 1.65 KiB
use ark_ff::PrimeField;
use ark_poly::univariate::DensePolynomial;
use ark_poly::DenseUVPolynomial;
use ark_std::ops::Div;
use rs_merkle::Hasher;
use std::time::{Duration, Instant};

use fri::algorithms::Blake3;
use fri_test_utils::Fq;
use komodo::error::KomodoError;

fn run<const N: usize, F: PrimeField, H: Hasher, P>(
    bytes: &[u8],
    k: usize,
    n: usize,
    bf: usize,
    rpo: usize,
    q: usize,
) -> Result<(), KomodoError>
where
    P: DenseUVPolynomial<F>,
    for<'a, 'b> &'a P: Div<&'b P, Output = P>,
    <H as rs_merkle::Hasher>::Hash: AsRef<[u8]>,
{
    eprintln!("evaluation");
    let start_time = Instant::now();
    let evaluations = komodo::fri::evaluate::<F>(&bytes, k, n);
    eprintln!("{:?}", Instant::now().duration_since(start_time));
    eprintln!("encoding");
    let evals = evaluations.clone();
    let start_time = Instant::now();
    let shards = komodo::fri::encode::<F>(&bytes, evals, k, n);
    eprintln!("{:?}", Instant::now().duration_since(start_time));
    eprintln!("proving");
    let start_time = Instant::now();
    let blocks = komodo::fri::prove::<N, F, H, P>(evaluations, shards, bf, rpo, q).unwrap();
    eprintln!("{:?}", Instant::now().duration_since(start_time));

    eprintln!("verifying");
    let start_time = Instant::now();
    for block in blocks {
        komodo::fri::verify::<N, F, H, P>(block, n, q).unwrap();
    }
    eprintln!("{:?}", Instant::now().duration_since(start_time));

    Ok(())
}

fn main() {
    let bytes = include_bytes!("../assets/128_4_3.bin").to_vec();
    eprintln!("loaded {} bytes of data", bytes.len());

    run::<2, Fq, Blake3, DensePolynomial<Fq>>(&bytes, 4, 4 * 2, 2, 1, 32).unwrap();
}