Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
rw0x0 committed Sep 26, 2024
1 parent 5f1b2ec commit 57235b5
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 15 deletions.
1 change: 1 addition & 0 deletions co-noir/co-ultrahonk/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub(crate) mod parse;
pub mod prelude;
pub(crate) mod prover;
pub(crate) mod types;

use ark_ec::pairing::Pairing;
Expand Down
1 change: 1 addition & 0 deletions co-noir/co-ultrahonk/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub use crate::parse::{
builder_variable::SharedBuilderVariable, CoUltraCircuitBuilder, PlainCoBuilder, Rep3CoBuilder,
};
pub use crate::prover::CoUltraHonk;
pub use crate::types::ProvingKey;
// Re-exporting the following traits from `ultrahonk`:
pub use ultrahonk::prelude::HonkProof;
Expand Down
38 changes: 38 additions & 0 deletions co-noir/co-ultrahonk/src/prover.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use crate::types::ProvingKey;
use mpc_core::traits::PrimeFieldMpcProtocol;
use std::marker::PhantomData;
use ultrahonk::prelude::{
HonkCurve, HonkProof, HonkProofResult, TranscriptFieldType, TranscriptType,
POSEIDON2_BN254_T4_PARAMS,
};

pub struct CoUltraHonk<T, P: HonkCurve<TranscriptFieldType>>
where
T: PrimeFieldMpcProtocol<P::ScalarField>,
{
pub(crate) driver: T,
phantom_data: PhantomData<P>,
}

impl<T, P: HonkCurve<TranscriptFieldType>> CoUltraHonk<T, P>
where
T: PrimeFieldMpcProtocol<P::ScalarField>,
{
pub fn new(driver: T) -> Self {
Self {
driver,
phantom_data: PhantomData,
}
}

pub fn prove(
&mut self,
proving_key: ProvingKey<T, P>,
) -> HonkProofResult<HonkProof<TranscriptFieldType>> {
tracing::trace!("UltraHonk prove");

let mut transcript = TranscriptType::new(&POSEIDON2_BN254_T4_PARAMS);

todo!("prove");
}
}
16 changes: 8 additions & 8 deletions co-noir/co-ultrahonk/tests/poseidon.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ark_bn254::Bn254;
use co_ultrahonk::prelude::{PlainCoBuilder, ProvingKey, SharedBuilderVariable};
use co_ultrahonk::prelude::{CoUltraHonk, PlainCoBuilder, ProvingKey, SharedBuilderVariable};
use mpc_core::protocols::plain::PlainDriver;
use ultrahonk::Utils;
use ultrahonk::{prelude::HonkProof, Utils};

#[test]
fn poseidon_plaindriver_test() {
Expand All @@ -24,13 +24,13 @@ fn poseidon_plaindriver_test() {
let prover_crs = ProvingKey::get_prover_crs(&builder, CRS_PATH_G1).unwrap();
let proving_key = ProvingKey::create(&driver, builder, prover_crs);

// let proof = UltraHonk::prove(proving_key).unwrap();
// let proof_u8 = proof.to_buffer();
let mut prover = CoUltraHonk::new(driver);
let proof = prover.prove(proving_key).unwrap();
let proof_u8 = proof.to_buffer();

let read_proof_u8 = std::fs::read(PROOF_FILE).unwrap();
// assert_eq!(proof_u8, read_proof_u8);
assert_eq!(proof_u8, read_proof_u8);

// let read_proof = HonkProof::from_buffer(&read_proof_u8).unwrap();
// assert_eq!(proof, read_proof);
todo!("WIP")
let read_proof = HonkProof::from_buffer(&read_proof_u8).unwrap();
assert_eq!(proof, read_proof);
}
2 changes: 1 addition & 1 deletion co-noir/ultrahonk/src/poseidon2/poseidon2_bn254.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,5 @@ lazy_static! {
Utils::field_from_hex_string("0x02fcca2934e046bc623adead873579865d03781ae090ad4a8579d2e7a6800355").unwrap(),
Utils::field_from_hex_string("0x0ef915f0ac120b876abccceb344a1d36bad3f3c5ab91a8ddcbec2e060d8befac").unwrap(),
];
pub(crate) static ref POSEIDON2_BN254_T4_PARAMS: Arc<Poseidon2Params<Scalar, T, D>> = Arc::new(Poseidon2Params::new(ROUNDS_F, ROUNDS_P, *MAT_DIAG_M_1, EXTERNAL_RC.to_vec(), INTERNAL_RC.to_vec()));
pub static ref POSEIDON2_BN254_T4_PARAMS: Arc<Poseidon2Params<Scalar, T, D>> = Arc::new(Poseidon2Params::new(ROUNDS_F, ROUNDS_P, *MAT_DIAG_M_1, EXTERNAL_RC.to_vec(), INTERNAL_RC.to_vec()));
}
2 changes: 1 addition & 1 deletion co-noir/ultrahonk/src/poseidon2/poseidon2_params.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use ark_ff::PrimeField;

#[derive(Clone, Debug)]
pub(crate) struct Poseidon2Params<F: PrimeField, const T: usize, const D: u64> {
pub struct Poseidon2Params<F: PrimeField, const T: usize, const D: u64> {
pub(crate) rounds_f_beginning: usize,
pub(crate) rounds_f_end: usize,
pub(crate) rounds_p: usize,
Expand Down
5 changes: 5 additions & 0 deletions co-noir/ultrahonk/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
pub use crate::decider::polynomial::Polynomial;
pub use crate::honk_curve::HonkCurve;
pub use crate::parse::crs::CrsParser;
pub use crate::parse::{
acir_format::AcirFormat,
builder::{GenericUltraCircuitBuilder, UltraCircuitBuilder, UltraCircuitVariable},
types::{CycleNode, CyclicPermutation, NUM_SELECTORS, NUM_WIRES},
};
pub use crate::poseidon2::poseidon2_bn254::POSEIDON2_BN254_T4_PARAMS;
pub use crate::prover::HonkProofResult;
pub use crate::prover::UltraHonk;
pub use crate::transcript::TranscriptFieldType;
pub use crate::transcript::TranscriptType;
pub use crate::types::PrecomputedEntities;
pub use crate::types::ProverCrs;
pub use crate::types::{HonkProof, ProvingKey};
2 changes: 1 addition & 1 deletion co-noir/ultrahonk/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
use ark_ec::pairing::Pairing;
use std::{io, marker::PhantomData};

pub(crate) type HonkProofResult<T> = std::result::Result<T, HonkProofError>;
pub type HonkProofResult<T> = std::result::Result<T, HonkProofError>;

/// The errors that may arise during the computation of a co-PLONK proof.
#[derive(Debug, thiserror::Error)]
Expand Down
8 changes: 4 additions & 4 deletions co-noir/ultrahonk/src/transcript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use ark_ec::AffineRepr;
use ark_ff::{PrimeField, Zero};
use std::{collections::BTreeMap, ops::Index, sync::Arc};

pub(crate) type TranscriptFieldType = ark_bn254::Fr;
pub(crate) type TranscriptType = Poseidon2Transcript<TranscriptFieldType>;
pub type TranscriptFieldType = ark_bn254::Fr;
pub type TranscriptType = Poseidon2Transcript<TranscriptFieldType>;

pub(super) struct Poseidon2Transcript<F>
pub struct Poseidon2Transcript<F>
where
F: PrimeField,
{
Expand All @@ -31,7 +31,7 @@ impl<F> Poseidon2Transcript<F>
where
F: PrimeField,
{
pub(crate) fn new(params: &Arc<Poseidon2Params<F, 4, 5>>) -> Self {
pub fn new(params: &Arc<Poseidon2Params<F, 4, 5>>) -> Self {
Self {
proof_data: Default::default(),
manifest: Default::default(),
Expand Down

0 comments on commit 57235b5

Please sign in to comment.