Skip to content

Commit

Permalink
🚧 Implement reveal for ark-marlin
Browse files Browse the repository at this point in the history
  • Loading branch information
sheagrief committed Oct 3, 2023
1 parent 3ee863d commit 3fd34df
Show file tree
Hide file tree
Showing 4 changed files with 333 additions and 2 deletions.
5 changes: 4 additions & 1 deletion arkworks/marlin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ edition = "2018"
[dependencies]
ark-serialize = { path = "../algebra/serialize", version = "^0.3.0", default-features = false, features = [ "derive" ] }
ark-ff = { path = "../algebra/ff", version = "^0.3.0", default-features = false }
ark-ec = { path = "../algebra/ec", version = "^0.3.0", default-features = false }
ark-std = { path = "../std", version = "^0.3.0", default-features = false }
ark-poly = { path = "../algebra/poly", version = "^0.3.0", default-features = false }
ark-relations = { path = "../snark/relations", version = "^0.3.0", default-features = false }
Expand All @@ -31,10 +32,12 @@ rand_chacha = { version = "0.3.0", default-features = false }
rayon = { version = "1", optional = true }
digest = { version = "0.9" }
derivative = { version = "2", features = ["use_core"] }
mpc-algebra = { path = "../../mpc-algebra" }
blake2 = "0.9"

[dev-dependencies]
blake2 = { version = "0.9", default-features = false }
ark-bls12-381 = { version = "^0.3.0", default-features = false, features = [ "curve" ] }
ark-bls12-381 = { path = "../curves/bls12_381", version = "^0.3.0", default-features = false, features = [ "curve" ] }
ark-mnt4-298 = { version = "^0.3.0", default-features = false, features = ["r1cs", "curve"] }
ark-mnt6-298 = { version = "^0.3.0", default-features = false, features = ["r1cs"] }
ark-mnt4-753 = { version = "^0.3.0", default-features = false, features = ["r1cs", "curve"] }
Expand Down
2 changes: 1 addition & 1 deletion arkworks/marlin/src/ahp/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct IndexInfo<F> {
pub num_instance_variables: usize,

#[doc(hidden)]
f: PhantomData<F>,
pub f: PhantomData<F>,
}

impl<F: PrimeField> ark_ff::ToBytes for IndexInfo<F> {
Expand Down
2 changes: 2 additions & 0 deletions arkworks/marlin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub mod ahp;
pub use ahp::AHPForR1CS;
use ahp::EvaluationsProvider;

pub mod reveal;

#[cfg(test)]
mod test;

Expand Down
326 changes: 326 additions & 0 deletions arkworks/marlin/src/reveal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,326 @@
#![allow(missing_docs)]
#![allow(dead_code)]
#![allow(unused_imports)]

use ark_ec::PairingEngine;
use ark_ff::Field;
use ark_poly::univariate::DensePolynomial;
use ark_poly_commit::marlin_pc::MarlinKZG10;
// use ark_poly_commit::reveal as pc_reveal;
use blake2::Blake2s;
use mpc_algebra::*;
use Marlin;

use super::*;
use crate::ahp::prover::*;
use ark_poly::EvaluationDomain;
use ark_std::{end_timer, start_timer};

impl<F: PrimeField, S: FieldShare<F>> Reveal for ProverMsg<MpcField<F, S>> {
type Base = ProverMsg<F>;

fn reveal(self) -> Self::Base {
match self {
ProverMsg::EmptyMessage => ProverMsg::EmptyMessage,
ProverMsg::FieldElements(d) => ProverMsg::FieldElements(d.reveal()),
}
}

fn from_add_shared(b: Self::Base) -> Self {
match b {
ProverMsg::EmptyMessage => ProverMsg::EmptyMessage,
ProverMsg::FieldElements(d) => ProverMsg::FieldElements(Reveal::from_add_shared(d)),
}
}

fn from_public(b: Self::Base) -> Self {
match b {
ProverMsg::EmptyMessage => ProverMsg::EmptyMessage,
ProverMsg::FieldElements(d) => ProverMsg::FieldElements(Reveal::from_public(d)),
}
}
}

impl<F: Field> MpcWire for ProverMsg<F> {
fn publicize(&mut self) {
match self {
ProverMsg::EmptyMessage => {}
ProverMsg::FieldElements(d) => todo!(),
}
}

fn is_shared(&self) -> bool {
match self {
ProverMsg::EmptyMessage => false,
ProverMsg::FieldElements(d) => todo!(),
}
}
}

impl<E: PairingEngine, S: PairingShare<E>> Reveal
for Proof<
<MpcPairingEngine<E, S> as PairingEngine>::Fr,
MarlinKZG10<
MpcPairingEngine<E, S>,
DensePolynomial<<MpcPairingEngine<E, S> as PairingEngine>::Fr>,
>,
>
{
type Base =
Proof<<E as PairingEngine>::Fr, MarlinKZG10<E, DensePolynomial<<E as PairingEngine>::Fr>>>;

fn reveal(self) -> Self::Base {
todo!()
}

fn from_add_shared(b: Self::Base) -> Self {
todo!()
}

fn from_public(b: Self::Base) -> Self {
todo!()
}
// struct_reveal_simp_impl!(Proof; commitments, evaluations, prover_messages, pc_proof);
}

impl<F: PrimeField, S: FieldShare<F>> Reveal for ahp::indexer::IndexInfo<MpcField<F, S>> {
type Base = ahp::indexer::IndexInfo<F>;
struct_reveal_simp_impl!(ahp::indexer::IndexInfo;
num_variables,
num_constraints,
num_non_zero,
num_instance_variables,
f
);
}

// fn lift_pp(
// pp: ark_poly_commit::kzg10::UniversalParams<E>,
// ) -> ark_poly_commit::kzg10::UniversalParams<ME> {
// ark_poly_commit::kzg10::UniversalParams {
// powers_of_g: pp
// .powers_of_g
// .into_iter()
// .map(HbcG1Affine::from_public)
// .collect(),
// powers_of_gamma_g: pp
// .powers_of_gamma_g
// .into_iter()
// .map(|(i, w)| (i, HbcG1Affine::from_public(w)))
// .collect(),
// h: HbcG2Affine::from_public(pp.h),
// beta_h: HbcG2Affine::from_public(pp.beta_h),
// neg_powers_of_h: pp
// .neg_powers_of_h
// .into_iter()
// .map(|(i, w)| (i, HbcG2Affine::from_public(w)))
// .collect(),
// prepared_h: HbcG2Prep::from_public(pp.prepared_h),
// prepared_beta_h: HbcG2Prep::from_public(pp.prepared_beta_h),
// }
// }
//
// fn lift_index_vk(
// vk: IndexVerifierKey<Fr, LocalMarlinKZG10>,
// ) -> IndexVerifierKey<MFr, MpcMarlinKZG10> {
// IndexVerifierKey {
// index_comms: vk
// .index_comms
// .into_iter()
// .map(pc_reveal::obs_commitment)
// .collect(),
// verifier_key: lift_vk(vk.verifier_key),
// index_info: lift_index_info(vk.index_info),
// }
// }
impl<E: PairingEngine, S: PairingShare<E>> Reveal
for IndexVerifierKey<
<MpcPairingEngine<E, S> as PairingEngine>::Fr,
MarlinKZG10<
MpcPairingEngine<E, S>,
DensePolynomial<<MpcPairingEngine<E, S> as PairingEngine>::Fr>,
>,
>
{
type Base = IndexVerifierKey<
<E as PairingEngine>::Fr,
MarlinKZG10<E, DensePolynomial<<E as PairingEngine>::Fr>>,
>;

fn reveal(self) -> Self::Base {
todo!()
}

fn from_add_shared(b: Self::Base) -> Self {
todo!()
}

fn from_public(b: Self::Base) -> Self {
todo!()
}
// struct_reveal_simp_impl!(IndexVerifierKey; index_comms, verifier_key, index_info);
}
//impl<F: PrimeField, S: FieldShare<F>> Reveal for ahp::indexer::Matrix<MpcField<F, S>> {
// type Base = ahp::indexer::Matrix<F>;
// struct_reveal_simp_impl!(ahp::indexer::Matrix;
// num_variables,
// num_constraints,
// num_non_zero,
// num_instance_variables,
// f
// );
//}
//
// fn lift_index_matrix(mat: ahp::indexer::Matrix<Fr>) -> ahp::indexer::Matrix<MFr> {
// mat.into_iter()
// .map(|v| {
// v.into_iter()
// .map(|(f, i)| (HbcField::from_public(f), i))
// .collect()
// })
// .collect()
// }
impl<E: PrimeField, S: FieldShare<E>> Reveal for ahp::indexer::Index<MpcField<E, S>> {
type Base = ahp::indexer::Index<E>;
struct_reveal_simp_impl!(ahp::indexer::Index; index_info, a, b, c, a_star_arith, b_star_arith, c_star_arith);
}
// fn lift_index(ii: ahp::indexer::Index<Fr>) -> ahp::indexer::Index<MFr> {
// ahp::indexer::Index {
// index_info: lift_index_info(ii.index_info),
// a: lift_index_matrix(ii.a),
// b: lift_index_matrix(ii.b),
// c: lift_index_matrix(ii.c),
// a_star_arith: lift_matrix_arith(ii.a_star_arith),
// b_star_arith: lift_matrix_arith(ii.b_star_arith),
// c_star_arith: lift_matrix_arith(ii.c_star_arith),
// }
// }
//
// fn lift_labelled_poly(
// p: ark_poly_commit::data_structures::LabeledPolynomial<Fr, DensePolynomial<Fr>>,
// ) -> ark_poly_commit::data_structures::LabeledPolynomial<MFr, DensePolynomial<MFr>> {
// use ark_poly::UVPolynomial;
// ark_poly_commit::data_structures::LabeledPolynomial::new(
// p.label().clone(),
// DensePolynomial::from_coefficients_vec(
// p.polynomial()
// .coeffs()
// .into_iter()
// .map(|c| HbcField::from_public(c.clone()))
// .collect(),
// ),
// p.degree_bound(),
// p.hiding_bound(),
// )
// }
//
// fn lift_evals(
// es: ark_poly::evaluations::univariate::Evaluations<Fr>,
// ) -> ark_poly::evaluations::univariate::Evaluations<MFr> {
// ark_poly::evaluations::univariate::Evaluations {
// evals: es.evals.into_iter().map(HbcField::from_public).collect(),
// domain: ark_poly::GeneralEvaluationDomain::new(es.domain.size()).unwrap(),
// }
// }
//
// fn lift_matrix_evals(
// mat: ahp::constraint_systems::MatrixEvals<Fr>,
// ) -> ahp::constraint_systems::MatrixEvals<MFr> {
// ahp::constraint_systems::MatrixEvals {
// row: lift_evals(mat.row),
// col: lift_evals(mat.col),
// val: lift_evals(mat.val),
// }
// }
impl<E: PrimeField, S: FieldShare<E>> Reveal
for ahp::constraint_systems::MatrixEvals<MpcField<E, S>>
{
type Base = ahp::constraint_systems::MatrixEvals<E>;

fn reveal(self) -> Self::Base {
todo!()
}

fn from_add_shared(b: Self::Base) -> Self {
todo!()
}

fn from_public(b: Self::Base) -> Self {
todo!()
}
// struct_reveal_simp_impl!(ahp::constraint_systems::MatrixEvals; row, col, val);
}
impl<E: PrimeField, S: FieldShare<E>> Reveal
for ahp::constraint_systems::MatrixArithmetization<MpcField<E, S>>
{
type Base = ahp::constraint_systems::MatrixArithmetization<E>;

fn reveal(self) -> Self::Base {
todo!()
}

fn from_add_shared(b: Self::Base) -> Self {
todo!()
}

fn from_public(b: Self::Base) -> Self {
todo!()
}
// struct_reveal_simp_impl!(ahp::constraint_systems::MatrixArithmetization; row, col, val, row_col, evals_on_K, evals_on_B, row_col_evals_on_B);
}
//
// fn lift_matrix_arith(
// mat: ahp::constraint_systems::MatrixArithmetization<Fr>,
// ) -> ahp::constraint_systems::MatrixArithmetization<MFr> {
// ahp::constraint_systems::MatrixArithmetization {
// row: lift_labelled_poly(mat.row),
// col: lift_labelled_poly(mat.col),
// val: lift_labelled_poly(mat.val),
// row_col: lift_labelled_poly(mat.row_col),
// evals_on_K: lift_matrix_evals(mat.evals_on_K),
// evals_on_B: lift_matrix_evals(mat.evals_on_B),
// row_col_evals_on_B: lift_evals(mat.row_col_evals_on_B),
// }
// }
//
// pub fn lift_index_pk(
// pk: IndexProverKey<Fr, LocalMarlinKZG10>,
// ) -> IndexProverKey<MFr, MpcMarlinKZG10> {
// IndexProverKey {
// index_vk: lift_index_vk(pk.index_vk),
// index_comm_rands: pk
// .index_comm_rands
// .into_iter()
// .map(pc_reveal::obs_randomness)
// .collect(),
// index: lift_index(pk.index),
// committer_key: pc_reveal::obs_ck(pk.committer_key),
// }
// }
impl<E: PairingEngine, S: PairingShare<E>> Reveal
for IndexProverKey<
<MpcPairingEngine<E, S> as PairingEngine>::Fr,
MarlinKZG10<
MpcPairingEngine<E, S>,
DensePolynomial<<MpcPairingEngine<E, S> as PairingEngine>::Fr>,
>,
>
{
type Base = IndexProverKey<
<E as PairingEngine>::Fr,
MarlinKZG10<E, DensePolynomial<<E as PairingEngine>::Fr>>,
>;

fn reveal(self) -> Self::Base {
todo!()
}

fn from_add_shared(b: Self::Base) -> Self {
todo!()
}

fn from_public(b: Self::Base) -> Self {
todo!()
}
// struct_reveal_simp_impl!(IndexProverKey; index_vk, index_comm_rands, index, committer_key);
}

0 comments on commit 3fd34df

Please sign in to comment.