Skip to content

Commit

Permalink
algebra: Add sub-modular structure to algebra
Browse files Browse the repository at this point in the history
  • Loading branch information
joeykraut committed Oct 11, 2023
1 parent 7e11493 commit 1195f5d
Show file tree
Hide file tree
Showing 31 changed files with 107 additions and 89 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ path = "src/lib.rs"
benchmarks = []
stats = ["benchmarks"]
test_helpers = ["ark-bn254"]
poly = []

[[test]]
name = "integration"
Expand Down
4 changes: 1 addition & 3 deletions benches/circuit_msm_throughput.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
use std::time::{Duration, Instant};

use ark_mpc::{
algebra::authenticated_curve::AuthenticatedPointResult, test_helpers::execute_mock_mpc,
};
use ark_mpc::{algebra::AuthenticatedPointResult, test_helpers::execute_mock_mpc};
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};
use itertools::Itertools;
use tokio::runtime::Builder as RuntimeBuilder;
Expand Down
4 changes: 2 additions & 2 deletions benches/gate_throughput.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::{path::Path, sync::Mutex};

use ark_mpc::{
algebra::scalar::Scalar, beaver::PartyIDBeaverSource, network::NoRecvNetwork,
test_helpers::TestCurve, MpcFabric, PARTY0,
algebra::Scalar, beaver::PartyIDBeaverSource, network::NoRecvNetwork, test_helpers::TestCurve,
MpcFabric, PARTY0,
};
use cpuprofiler::{Profiler as CpuProfiler, PROFILER};
use criterion::{
Expand Down
4 changes: 2 additions & 2 deletions benches/gate_throughput_traced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
use std::time::Instant;

use ark_mpc::{
algebra::scalar::Scalar, beaver::PartyIDBeaverSource, network::NoRecvNetwork,
test_helpers::TestCurve, MpcFabric, PARTY0,
algebra::Scalar, beaver::PartyIDBeaverSource, network::NoRecvNetwork, test_helpers::TestCurve,
MpcFabric, PARTY0,
};
use clap::Parser;
use cpuprofiler::PROFILER;
Expand Down
2 changes: 1 addition & 1 deletion benches/growable_buffer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use ark_mpc::{algebra::scalar::Scalar, buffer::GrowableBuffer, test_helpers::TestCurve};
use ark_mpc::{algebra::Scalar, buffer::GrowableBuffer, test_helpers::TestCurve};
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion, Throughput};

// --------------
Expand Down
2 changes: 1 addition & 1 deletion benches/native_msm.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Defines a benchmark for native multiscalar-multiplication on `Scalar` and `CurvePoint` types
use ark_mpc::{
algebra::{curve::CurvePoint, scalar::Scalar},
algebra::{CurvePoint, Scalar},
random_point,
test_helpers::TestCurve,
};
Expand Down
7 changes: 2 additions & 5 deletions integration/authenticated_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
use ark_mpc::{
algebra::{
authenticated_curve::{
test_helpers::{modify_mac, modify_public_modifier, modify_share},
AuthenticatedPointResult,
},
scalar::Scalar,
curve_test_helpers::{modify_mac, modify_public_modifier, modify_share},
AuthenticatedPointResult, Scalar,
},
random_point, PARTY0, PARTY1,
};
Expand Down
5 changes: 1 addition & 4 deletions integration/authenticated_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
//! a malicious-secure primitive
use ark_mpc::{
algebra::{
authenticated_scalar::{test_helpers::*, AuthenticatedScalarResult},
scalar::Scalar,
},
algebra::{scalar_test_helpers::*, AuthenticatedScalarResult, Scalar},
ResultValue, PARTY0, PARTY1,
};
use itertools::Itertools;
Expand Down
5 changes: 1 addition & 4 deletions integration/circuits.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//! Tests for more complicated operations (i.e. circuits)
use ark_mpc::{
algebra::{
authenticated_curve::AuthenticatedPointResult,
authenticated_scalar::AuthenticatedScalarResult, scalar::Scalar,
},
algebra::{AuthenticatedPointResult, AuthenticatedScalarResult, Scalar},
random_point, PARTY0, PARTY1,
};
use itertools::Itertools;
Expand Down
2 changes: 1 addition & 1 deletion integration/fabric.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Defines tests for the fabric directly
use ark_mpc::{algebra::scalar::Scalar, PARTY0, PARTY1};
use ark_mpc::{algebra::Scalar, PARTY0, PARTY1};

use crate::{
helpers::{assert_scalars_eq, await_result, share_scalar},
Expand Down
5 changes: 2 additions & 3 deletions integration/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use std::fmt::Debug;

use ark_mpc::{
algebra::{
authenticated_curve::AuthenticatedPointResult,
authenticated_scalar::AuthenticatedScalarResult, mpc_curve::MpcPointResult,
mpc_scalar::MpcScalarResult, scalar::Scalar,
AuthenticatedPointResult, AuthenticatedScalarResult, MpcPointResult, MpcScalarResult,
Scalar,
},
beaver::SharedValueSource,
network::{NetworkPayload, PartyId},
Expand Down
2 changes: 1 addition & 1 deletion integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{borrow::Borrow, io::Write, net::SocketAddr, process::exit, thread, tim

use ark_bn254::G1Projective as Bn254Projective;
use ark_mpc::{
algebra::{curve::CurvePoint, scalar::Scalar},
algebra::{CurvePoint, Scalar},
network::{NetworkOutbound, NetworkPayload, QuicTwoPartyNet},
MpcFabric, PARTY0,
};
Expand Down
6 changes: 1 addition & 5 deletions integration/mpc_curve.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
//! Defines tests for the `MpcPointResult` type and arithmetic on this type
use ark_mpc::{
algebra::{
curve::CurvePointResult,
mpc_curve::MpcPointResult,
scalar::{Scalar, ScalarResult},
},
algebra::{CurvePointResult, MpcPointResult, Scalar, ScalarResult},
random_point, PARTY0, PARTY1,
};
use itertools::Itertools;
Expand Down
5 changes: 1 addition & 4 deletions integration/mpc_scalar.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
//! Defines unit tests for `MpcScalarResult` types
use ark_mpc::{
algebra::{
mpc_scalar::MpcScalarResult,
scalar::{Scalar, ScalarResult},
},
algebra::{MpcScalarResult, Scalar, ScalarResult},
PARTY0, PARTY1,
};
use itertools::Itertools;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,17 @@ use futures::{Future, FutureExt};
use itertools::{izip, Itertools};

use crate::{
algebra::macros::*,
algebra::scalar::*,
commitment::{HashCommitment, HashCommitmentResult},
error::MpcError,
fabric::{MpcFabric, ResultValue},
ResultId, PARTY0,
};

use super::{
authenticated_scalar::AuthenticatedScalarResult,
curve::{BatchCurvePointResult, CurvePoint, CurvePointResult},
macros::{impl_borrow_variants, impl_commutative},
mpc_curve::MpcPointResult,
scalar::{Scalar, ScalarResult},
};

/// The number of underlying results in an `AuthenticatedPointResult`
Expand Down
13 changes: 3 additions & 10 deletions src/algebra/curve.rs → src/algebra/curve/curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,13 @@ use serde::{de::Error as DeError, Deserialize, Serialize};

use crate::{
algebra::{
authenticated_curve::AUTHENTICATED_POINT_RESULT_LEN,
authenticated_scalar::AUTHENTICATED_SCALAR_RESULT_LEN,
macros::*, n_bytes_field, scalar::*, AUTHENTICATED_POINT_RESULT_LEN,
AUTHENTICATED_SCALAR_RESULT_LEN,
},
fabric::{ResultHandle, ResultValue},
};

use super::{
authenticated_curve::AuthenticatedPointResult,
authenticated_scalar::AuthenticatedScalarResult,
macros::{impl_borrow_variants, impl_commutative},
mpc_curve::MpcPointResult,
mpc_scalar::MpcScalarResult,
scalar::{n_bytes_field, Scalar, ScalarResult},
};
use super::{authenticated_curve::AuthenticatedPointResult, mpc_curve::MpcPointResult};

/// The number of points and scalars to pull from an iterated MSM when
/// performing a multiscalar multiplication
Expand Down
13 changes: 13 additions & 0 deletions src/algebra/curve/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Defines curve types for shared authenticated, shared unauthenticated, and plaintext curve points
#![allow(clippy::module_inception)]

mod authenticated_curve;
mod curve;
mod mpc_curve;

pub use authenticated_curve::*;
pub use curve::*;
pub use mpc_curve::*;

#[cfg(feature = "test_helpers")]
pub use authenticated_curve::test_helpers as curve_test_helpers;
12 changes: 5 additions & 7 deletions src/algebra/mpc_curve.rs → src/algebra/curve/mpc_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ use std::ops::{Add, Mul, Neg, Sub};
use ark_ec::CurveGroup;
use itertools::Itertools;

use crate::{fabric::ResultValue, network::NetworkPayload, MpcFabric, ResultId, PARTY0};

use super::{
curve::{BatchCurvePointResult, CurvePoint, CurvePointResult},
macros::{impl_borrow_variants, impl_commutative},
mpc_scalar::MpcScalarResult,
scalar::{Scalar, ScalarResult},
use crate::{
algebra::macros::*, algebra::scalar::*, fabric::ResultValue, network::NetworkPayload,
MpcFabric, ResultId, PARTY0,
};

use super::curve::{BatchCurvePointResult, CurvePoint, CurvePointResult};

/// Defines a secret shared type of a curve point
#[derive(Clone, Debug)]
pub struct MpcPointResult<C: CurveGroup> {
Expand Down
15 changes: 8 additions & 7 deletions src/algebra/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Defines algebraic MPC types and operations on them
pub mod authenticated_curve;
pub mod authenticated_scalar;
pub mod curve;
pub mod macros;
pub mod mpc_curve;
pub mod mpc_scalar;
pub mod scalar;
mod curve;
mod macros;
mod poly;
mod scalar;

pub use curve::*;
pub use poly::*;
pub use scalar::*;
24 changes: 24 additions & 0 deletions src/algebra/poly/authenticated_poly.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//! An authenticated polynomial over a `CurveGroup`'s scalar field
//!
//! Modeled after the `ark_poly::DensePolynomial` type, but allocated in an MPC fabric
use ark_ec::CurveGroup;

use crate::algebra::AuthenticatedScalarResult;

/// An authenticated polynomial; i.e. a polynomial in which the coefficients are secret
/// shared between parties
///
/// This is modeled after the `ark_poly::DensePolynomial` [source](https://github.com/arkworks-rs/algebra/blob/master/poly/src/polynomial/univariate/dense.rs#L22)
#[derive(Debug, Clone)]
pub struct AuthenticatedDensePoly<C: CurveGroup> {
/// A vector of coefficients, the coefficient for `x^i` is stored at index `i`
pub coeffs: Vec<AuthenticatedScalarResult<C>>,
}

impl<C: CurveGroup> AuthenticatedDensePoly<C> {
/// Constructor
pub fn from_coeffs(coeffs: Vec<AuthenticatedScalarResult<C>>) -> Self {
Self { coeffs }
}
}
7 changes: 7 additions & 0 deletions src/algebra/poly/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//! Polynomial types over secret shared fields
//!
//! Modeled after the `ark_poly` implementation
mod authenticated_poly;

pub use authenticated_poly::*;
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ use futures::{Future, FutureExt};
use itertools::{izip, Itertools};

use crate::{
algebra::{macros::*, AuthenticatedPointResult, CurvePoint, CurvePointResult},
commitment::{PedersenCommitment, PedersenCommitmentResult},
error::MpcError,
fabric::{MpcFabric, ResultId, ResultValue},
PARTY0,
};

use super::{
authenticated_curve::AuthenticatedPointResult,
curve::{CurvePoint, CurvePointResult},
macros::{impl_borrow_variants, impl_commutative},
mpc_scalar::MpcScalarResult,
scalar::{BatchScalarResult, Scalar, ScalarResult},
};
Expand Down
13 changes: 13 additions & 0 deletions src/algebra/scalar/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Scalar type arithmetic with shared authenticated, shared non-authenticated, and plaintext types
#![allow(clippy::module_inception)]

mod authenticated_scalar;
mod mpc_scalar;
mod scalar;

pub use authenticated_scalar::*;
pub use mpc_scalar::*;
pub use scalar::*;

#[cfg(feature = "test_helpers")]
pub use authenticated_scalar::test_helpers as scalar_test_helpers;
11 changes: 4 additions & 7 deletions src/algebra/mpc_scalar.rs → src/algebra/scalar/mpc_scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@ use ark_ec::CurveGroup;
use itertools::Itertools;

use crate::{
algebra::scalar::BatchScalarResult,
algebra::macros::*,
algebra::BatchScalarResult,
algebra::{CurvePoint, CurvePointResult, MpcPointResult},
fabric::{MpcFabric, ResultValue},
network::NetworkPayload,
PARTY0,
};

use super::{
curve::{CurvePoint, CurvePointResult},
macros::{impl_borrow_variants, impl_commutative},
mpc_curve::MpcPointResult,
scalar::{Scalar, ScalarResult},
};
use super::scalar::{Scalar, ScalarResult};

/// Defines a secret shared type over the `Scalar` field
#[derive(Clone, Debug)]
Expand Down
3 changes: 1 addition & 2 deletions src/algebra/scalar.rs → src/algebra/scalar/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ use num_bigint::BigUint;
use rand::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};

use crate::algebra::macros::*;
use crate::fabric::{ResultHandle, ResultValue};

use super::macros::{impl_borrow_variants, impl_commutative};

// -----------
// | Helpers |
// -----------
Expand Down
2 changes: 1 addition & 1 deletion src/beaver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use ark_ec::CurveGroup;
use itertools::Itertools;

use crate::algebra::scalar::Scalar;
use crate::algebra::Scalar;

/// SharedValueSource implements both the functionality for:
/// 1. Single additively shared values [x] where party 1 holds
Expand Down
5 changes: 1 addition & 4 deletions src/commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ use rand::thread_rng;
use sha3::{Digest, Sha3_256};

use crate::{
algebra::{
curve::{CurvePoint, CurvePointResult},
scalar::{Scalar, ScalarResult},
},
algebra::{CurvePoint, CurvePointResult, Scalar, ScalarResult},
fabric::ResultValue,
};

Expand Down
9 changes: 3 additions & 6 deletions src/fabric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ use itertools::Itertools;

use crate::{
algebra::{
authenticated_curve::AuthenticatedPointResult,
authenticated_scalar::AuthenticatedScalarResult,
curve::{BatchCurvePointResult, CurvePoint, CurvePointResult},
mpc_curve::MpcPointResult,
mpc_scalar::MpcScalarResult,
scalar::{BatchScalarResult, Scalar, ScalarResult},
AuthenticatedPointResult, AuthenticatedScalarResult, BatchCurvePointResult,
BatchScalarResult, CurvePoint, CurvePointResult, MpcPointResult, MpcScalarResult, Scalar,
ScalarResult,
},
beaver::SharedValueSource,
network::{MpcNetwork, NetworkOutbound, NetworkPayload, PartyId},
Expand Down
2 changes: 1 addition & 1 deletion src/fabric/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use ark_ec::CurveGroup;
use futures::Future;

use crate::{
algebra::{curve::CurvePoint, scalar::Scalar},
algebra::{CurvePoint, Scalar},
network::NetworkPayload,
Shared,
};
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use std::sync::{Arc, RwLock};

use algebra::{curve::CurvePoint, scalar::Scalar};
use algebra::{CurvePoint, Scalar};
use ark_ec::CurveGroup;

use rand::thread_rng;
Expand Down
Loading

0 comments on commit 1195f5d

Please sign in to comment.