From 7bea53ff5be7332a3fa23b34da7d9d94b0d980ac Mon Sep 17 00:00:00 2001 From: "sm.wu" Date: Sat, 5 Aug 2023 11:00:47 +0800 Subject: [PATCH] cite private mod from nova --- nova/src/nonnative/mod.rs | 38 ++++++++++++++++++++------------------ nova/src/utils.rs | 4 ++-- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/nova/src/nonnative/mod.rs b/nova/src/nonnative/mod.rs index ff67366111..e694bc7d35 100644 --- a/nova/src/nonnative/mod.rs +++ b/nova/src/nonnative/mod.rs @@ -1,3 +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 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 @@ -5,34 +7,34 @@ use bellperson::SynthesisError; use ff::PrimeField; trait OptionExt { - 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 OptionExt for Option { - 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; + fn get_bit(&self, i: usize) -> Option; } impl BitAccess for Scalar { - fn get_bit(&self, i: usize) -> Option { - if i as u32 >= Scalar::NUM_BITS { - return None; - } + fn get_bit(&self, i: usize) -> Option { + 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; diff --git a/nova/src/utils.rs b/nova/src/utils.rs index 7ad0344802..c9ea14f6fd 100644 --- a/nova/src/utils.rs +++ b/nova/src/utils.rs @@ -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)]