Skip to content

Commit

Permalink
no_std: use ark_std
Browse files Browse the repository at this point in the history
  • Loading branch information
redshiftzero committed Dec 12, 2023
1 parent 7b2f1e8 commit 96c3bd7
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use ark_ec::{
use ark_ed_on_bls12_377::EdwardsConfig;
use ark_ff::MontFp;
use ark_serialize::Valid;
use ark_std::vec::Vec;

use crate::{
constants::{GENERATOR_X, GENERATOR_Y},
Expand Down
6 changes: 3 additions & 3 deletions src/element/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct AffineElement {
}

impl Hash for AffineElement {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.inner.hash(state);
}
}
Expand Down Expand Up @@ -46,8 +46,8 @@ impl PartialEq for AffineElement {

impl Eq for AffineElement {}

impl std::fmt::Debug for AffineElement {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl core::fmt::Debug for AffineElement {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
let element: Element = self.into();
f.write_fmt(format_args!(
"decaf377::AffineElement({})",
Expand Down
6 changes: 3 additions & 3 deletions src/element/projective.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ pub struct Element {
}

impl Hash for Element {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
self.inner.hash(state);
}
}

impl std::fmt::Debug for Element {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl core::fmt::Debug for Element {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
// This prints the hex of the encoding of self, rather than the
// coordinates, because that's what's most useful to downstream
// consumers of the library.
Expand Down
4 changes: 2 additions & 2 deletions src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ use crate::{
#[derive(Copy, Clone, Default, Eq, Ord, PartialOrd, PartialEq)]
pub struct Encoding(pub [u8; 32]);

impl std::fmt::Debug for Encoding {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
impl core::fmt::Debug for Encoding {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_fmt(format_args!(
"decaf377::Encoding({})",
hex::encode(&self.0[..])
Expand Down
5 changes: 3 additions & 2 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use ark_std::error::Error;

#[derive(Debug)]
pub enum EncodingError {
InvalidEncoding,
Expand All @@ -15,5 +17,4 @@ impl core::fmt::Display for EncodingError {
}
}

#[cfg(feature = "std")]
impl std::error::Error for EncodingError {}
impl Error for EncodingError {}
2 changes: 2 additions & 0 deletions src/invsqrt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use hashbrown::HashMap;

use ark_ed_on_bls12_377::Fq;
use ark_ff::{BigInteger256, BigInteger64, Field, Zero};
use ark_std::boxed::Box;
use ark_std::vec::Vec;
use once_cell::sync::Lazy;

use crate::constants::{G, M_MINUS_ONE_DIV_TWO, N, ONE, SQRT_W, ZETA_TO_ONE_MINUS_M_DIV_TWO};
Expand Down
1 change: 1 addition & 0 deletions src/r1cs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub mod ops;

pub use ark_ed_on_bls12_377::constraints::FqVar;
use ark_ff::ToConstraintField;
use ark_std::vec::Vec;
pub use element::ElementVar;

use crate::{Element, Fq};
Expand Down
3 changes: 2 additions & 1 deletion src/r1cs/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use ark_ec::AffineRepr;
use ark_ed_on_bls12_377::constraints::FqVar;
use ark_r1cs_std::{alloc::AllocVar, eq::EqGadget, prelude::*, R1CSVar};
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
use ark_std::vec::Vec;

use crate::r1cs::lazy::LazyElementVar;
use crate::{element::EdwardsAffine, r1cs::inner::ElementVar as InnerElementVar};
Expand Down Expand Up @@ -125,7 +126,7 @@ impl CondSelectGadget<Fq> for ElementVar {
// This lets us use `new_constant`, `new_input` (public), or `new_witness` to add
// decaf elements to an R1CS constraint system.
impl AllocVar<Element, Fq> for ElementVar {
fn new_variable<T: std::borrow::Borrow<Element>>(
fn new_variable<T: core::borrow::Borrow<Element>>(
cs: impl Into<ark_relations::r1cs::Namespace<Fq>>,
f: impl FnOnce() -> Result<T, SynthesisError>,
mode: AllocationMode,
Expand Down
3 changes: 2 additions & 1 deletion src/r1cs/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use ark_r1cs_std::{
};
use ark_relations::ns;
use ark_relations::r1cs::{ConstraintSystemRef, SynthesisError};
use ark_std::vec::Vec;

use crate::element::EdwardsAffine;
use crate::Decaf377EdwardsConfig;
Expand Down Expand Up @@ -230,7 +231,7 @@ impl CondSelectGadget<Fq> for ElementVar {
// This lets us use `new_constant`, `new_input` (public), or `new_witness` to add
// decaf elements to an R1CS constraint system.
impl AllocVar<Element, Fq> for ElementVar {
fn new_variable<T: std::borrow::Borrow<Element>>(
fn new_variable<T: core::borrow::Borrow<Element>>(
cs: impl Into<ark_relations::r1cs::Namespace<Fq>>,
f: impl FnOnce() -> Result<T, SynthesisError>,
mode: AllocationMode,
Expand Down

0 comments on commit 96c3bd7

Please sign in to comment.