Skip to content

Commit

Permalink
cite private mod from nova
Browse files Browse the repository at this point in the history
  • Loading branch information
hero78119 committed Aug 5, 2023
1 parent 9843672 commit 7bea53f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
38 changes: 20 additions & 18 deletions nova/src/nonnative/mod.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,40 @@
//! This module implements various low-level gadgets, which is copy from Nova non-public mod
//! https://github.com/microsoft/Nova/blob/main/src/gadgets/mod.rs#L3
//! This module implements various gadgets necessary for doing non-native arithmetic
//! Code in this module is adapted from [bellman-bignat](https://github.com/alex-ozdemir/bellman-bignat), which is licenced under MIT

use bellperson::SynthesisError;
use ff::PrimeField;

trait OptionExt<T> {
fn grab(&self) -> Result<&T, SynthesisError>;
fn grab_mut(&mut self) -> Result<&mut T, SynthesisError>;
fn grab(&self) -> Result<&T, SynthesisError>;
fn grab_mut(&mut self) -> Result<&mut T, SynthesisError>;
}

impl<T> OptionExt<T> for Option<T> {
fn grab(&self) -> Result<&T, SynthesisError> {
self.as_ref().ok_or(SynthesisError::AssignmentMissing)
}
fn grab_mut(&mut self) -> Result<&mut T, SynthesisError> {
self.as_mut().ok_or(SynthesisError::AssignmentMissing)
}
fn grab(&self) -> Result<&T, SynthesisError> {
self.as_ref().ok_or(SynthesisError::AssignmentMissing)
}
fn grab_mut(&mut self) -> Result<&mut T, SynthesisError> {
self.as_mut().ok_or(SynthesisError::AssignmentMissing)
}
}

trait BitAccess {
fn get_bit(&self, i: usize) -> Option<bool>;
fn get_bit(&self, i: usize) -> Option<bool>;
}

impl<Scalar: PrimeField> BitAccess for Scalar {
fn get_bit(&self, i: usize) -> Option<bool> {
if i as u32 >= Scalar::NUM_BITS {
return None;
}
fn get_bit(&self, i: usize) -> Option<bool> {
if i as u32 >= Scalar::NUM_BITS {
return None;
}

let (byte_pos, bit_pos) = (i / 8, i % 8);
let byte = self.to_repr().as_ref()[byte_pos];
let bit = byte >> bit_pos & 1;
Some(bit == 1)
}
let (byte_pos, bit_pos) = (i / 8, i % 8);
let byte = self.to_repr().as_ref()[byte_pos];
let bit = byte >> bit_pos & 1;
Some(bit == 1)
}
}

pub mod bignat;
Expand Down
4 changes: 2 additions & 2 deletions nova/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! This module implements various low-level gadgets, which is copy from Nova non-public mod
//! https://github.com/microsoft/Nova/blob/main/src/gadgets/mod.rs#L3
//! This module implements various util function, which is copy from Nova non-public mod
//! https://github.com/microsoft/Nova/blob/main/src/gadgets/mod.rs#L5
use std::collections::BTreeMap;

#[allow(dead_code)]
Expand Down

0 comments on commit 7bea53f

Please sign in to comment.