Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: divide proof operations to subroutines #164

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
10 changes: 7 additions & 3 deletions .github/workflows/ci-detox-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,19 @@ jobs:
runs-on: ${{ matrix.runners }}
strategy:
matrix:
runners: [[self-hosted, macos, X64, general, runner03]]
runners: [[self-hosted, macos, general, ARM64]]
concurrency:
group: ci-detox-android-${{ matrix.runners }}-${{ github.head_ref }}
group: ci-detox-android-${{ matrix.runners }}-${{ github.head_ref || github.run_id}}
cancel-in-progress: true
timeout-minutes: 30
timeout-minutes: 60

env:
NODE_OPTIONS: "--max-old-space-size=5120"

defaults:
run:
working-directory: wrappers/react-native
shell: zsh -il {0} # load ~/.zshrc

steps:
- name: Checkout
Expand Down
20 changes: 11 additions & 9 deletions .github/workflows/ci-detox-ios.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,23 @@ jobs:
ios:
name: Detox iOS E2E Testing
needs: [libraries]
runs-on: ${{ matrix.runners }}
strategy:
matrix:
runners: [[self-hosted, macos, X64, general]]
concurrency:
group: ci-detox-ios-${{ matrix.runners }}-${{ github.head_ref }}
cancel-in-progress: true
timeout-minutes: 30
runs-on: macos-latest
# strategy:
# matrix:
# runners: [[self-hosted, macos, general, detox-ios]]
# concurrency:
# group: ci-detox-ios-${{ matrix.runners }}-${{ github.head_ref || github.run_id }}
# cancel-in-progress: true
timeout-minutes: 120

defaults:
run:
working-directory: wrappers/react-native
shell: zsh -il {0} # load ~/.zshrc

env:
DEVELOPER_DIR: /Applications/Xcode_13.2.1.app
DEVELOPER_DIR: /Applications/Xcode_14.2.app
NODE_OPTIONS: "--max-old-space-size=5120"
# Do not launch packager during CI build
RCT_NO_LAUNCH_PACKAGER: 'true'

Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ sha2 = "0.9"
sha3 = "0.9"

[dev-dependencies]
criterion = { version = "0.4.0", features = ["html_reports"] }
criterion = { version = "0.5.1", features = ["html_reports"] }
hex = "0.4"
rand_xorshift = "0.3"
bbs-fixtures-generator = {version = "0.1.0", path = "tools/bbs-fixtures-generator"}
Expand Down
4 changes: 2 additions & 2 deletions src/common/key_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ macro_rules! bbs_bls_key_pair_impl {

/// Convert a vector of bytes of big-endian representation of the
/// secret key.
pub fn from_vec(bytes: &Vec<u8>) -> Result<Self, Error> {
pub fn from_vec(bytes: &[u8]) -> Result<Self, Error> {
match vec_to_byte_array::<{ Self::SIZE_BYTES }>(bytes) {
Ok(result) => Self::from_bytes(&result),
Err(e) => Err(e),
Expand Down Expand Up @@ -195,7 +195,7 @@ macro_rules! bbs_bls_key_pair_impl {

/// Convert a vector of bytes of big-endian representation of the
/// public key.
pub fn from_vec(bytes: &Vec<u8>) -> Result<Self, Error> {
pub fn from_vec(bytes: &[u8]) -> Result<Self, Error> {
match vec_to_byte_array::<{ Self::SIZE_BYTES }>(bytes) {
Ok(result) => Self::from_octets(&result),
Err(e) => Err(e),
Expand Down
6 changes: 2 additions & 4 deletions src/common/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ macro_rules! print_byte_array {

pub(crate) use print_byte_array;

pub fn vec_to_byte_array<const N: usize>(
vec: &Vec<u8>,
) -> Result<[u8; N], Error> {
pub fn vec_to_byte_array<const N: usize>(vec: &[u8]) -> Result<[u8; N], Error> {
let data_len = vec.len();
match <[u8; N]>::try_from(vec.clone()) {
match <[u8; N]>::try_from(vec) {
Ok(result) => Ok(result),
Err(_) => Err(Error::Conversion {
cause: format!(
Expand Down
2 changes: 1 addition & 1 deletion src/curves/bls12_381.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub use blstrs::{Bls12 as pairing_engine, *};
pub use blstrs::*;

/// Number of bytes to store a scalar.
pub(crate) const OCTET_SCALAR_LENGTH: usize = 32;
Expand Down
20 changes: 20 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::usize;

/// Error enumerates all possible errors occuring in this library.
/// An error returned by the crypto component.
#[derive(Clone, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -68,6 +70,14 @@ pub enum Error {
messages: usize,
},

/// Not enough random scalars during Proof initialization.
UndisclosedIndexesRandomScalarsLengthMismatch {
/// Number of random scalars.
random_scalars: usize,
/// Number of messages.
undisclosed_indexes: usize,
},

/// The given point(from `G1` or `G2`) is an `Identity` element of
/// respective subgroup.
PointIsIdentity,
Expand Down Expand Up @@ -135,6 +145,16 @@ impl core::fmt::Debug for Error {
#messages: {messages}."
)
}
Error::UndisclosedIndexesRandomScalarsLengthMismatch {
random_scalars,
undisclosed_indexes,
} => {
write!(
f,
"length mismatch #random_scalars: {random_scalars}, \
#undisclosed_indexes: {undisclosed_indexes}."
)
}
Error::PointIsIdentity => {
write!(f, "unexpected `Identity` element.")
}
Expand Down
1 change: 0 additions & 1 deletion src/schemes/bbs/api/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ where
request.presentation_header.as_ref(),
&generators,
&messages,
Some(total_message_count),
)
}

Expand Down
2 changes: 1 addition & 1 deletion src/schemes/bbs/core/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(crate) trait Generators: Debug + Clone {
/// Note - `MessageGenerators` is zero indexed, so passed `index` value
/// should be in [0, `length`) range. In case of an invalid `index`, `None`
/// value is returned.
fn get_message_generator(&mut self, index: usize) -> Option<G1Projective>;
fn get_message_generator(&self, index: usize) -> Option<G1Projective>;

/// Get a `Iterator` for message generators.
fn message_generators_iter(&self) -> MessageGeneratorsIter<Self> {
Expand Down
2 changes: 1 addition & 1 deletion src/schemes/bbs/core/generator/memory_cached_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<C: BbsCiphersuiteParameters + Debug + Clone> Generators
/// Note `MessageGenerators` is zero indexed, so passed `index` value should
/// be in [0, `length`) range. In case of invalid `index`, `None` value
/// is returned.
fn get_message_generator(&mut self, index: usize) -> Option<G1Projective> {
fn get_message_generator(&self, index: usize) -> Option<G1Projective> {
if index >= self.H_list.len() {
return None;
}
Expand Down
Loading
Loading