mirror of
https://github.com/arnaucube/ark-r1cs-std.git
synced 2026-01-09 07:21:29 +01:00
Support commit and prove
This commit is contained in:
@@ -87,3 +87,4 @@ ark-mnt4-753 = { git = "https://github.com/arkworks-rs/curves/" }
|
|||||||
ark-mnt6-298 = { git = "https://github.com/arkworks-rs/curves/" }
|
ark-mnt6-298 = { git = "https://github.com/arkworks-rs/curves/" }
|
||||||
ark-mnt6-753 = { git = "https://github.com/arkworks-rs/curves/" }
|
ark-mnt6-753 = { git = "https://github.com/arkworks-rs/curves/" }
|
||||||
ark-pallas = { git = "https://github.com/arkworks-rs/curves/" }
|
ark-pallas = { git = "https://github.com/arkworks-rs/curves/" }
|
||||||
|
ark-relations = { git = "https://github.com/winderica/snark/", branch = "cp" }
|
||||||
|
|||||||
27
src/alloc.rs
27
src/alloc.rs
@@ -19,19 +19,22 @@ pub enum AllocationMode {
|
|||||||
/// Indicate to the `ConstraintSystem` that the high-level variable should
|
/// Indicate to the `ConstraintSystem` that the high-level variable should
|
||||||
/// be allocated as a private witness to the `ConstraintSystem`.
|
/// be allocated as a private witness to the `ConstraintSystem`.
|
||||||
Witness = 2,
|
Witness = 2,
|
||||||
|
|
||||||
|
Committed = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AllocationMode {
|
impl AllocationMode {
|
||||||
/// Outputs the maximum according to the relation `Constant < Input <
|
/// Outputs the maximum according to the relation `Constant < Input <
|
||||||
/// Witness`.
|
/// Witness`.
|
||||||
pub fn max(&self, other: Self) -> Self {
|
pub fn max(&self, other: Self) -> Self {
|
||||||
use AllocationMode::*;
|
// use AllocationMode::*;
|
||||||
match (self, other) {
|
// match (self, other) {
|
||||||
(Constant, _) => other,
|
// (Constant, _) => other,
|
||||||
(Input, Constant) => *self,
|
// (Input, Constant) => *self,
|
||||||
(Input, _) => other,
|
// (Input, _) => other,
|
||||||
(Witness, _) => *self,
|
// (Witness, _) => *self,
|
||||||
}
|
// }
|
||||||
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,6 +80,16 @@ pub trait AllocVar<V: ?Sized, F: Field>: Sized {
|
|||||||
Self::new_variable(cs, f, AllocationMode::Witness)
|
Self::new_variable(cs, f, AllocationMode::Witness)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Allocates a new commitment of type `Self` in the `ConstraintSystem`
|
||||||
|
/// `cs`.
|
||||||
|
#[tracing::instrument(target = "r1cs", skip(cs, f))]
|
||||||
|
fn new_committed<T: Borrow<V>>(
|
||||||
|
cs: impl Into<Namespace<F>>,
|
||||||
|
f: impl FnOnce() -> Result<T, SynthesisError>,
|
||||||
|
) -> Result<Self, SynthesisError> {
|
||||||
|
Self::new_variable(cs, f, AllocationMode::Committed)
|
||||||
|
}
|
||||||
|
|
||||||
/// Allocates a new constant or private witness of type `Self` in the
|
/// Allocates a new constant or private witness of type `Self` in the
|
||||||
/// `ConstraintSystem` `cs` with the allocation mode inferred from `cs`.
|
/// `ConstraintSystem` `cs` with the allocation mode inferred from `cs`.
|
||||||
/// A constant is allocated if `cs` is `None`, and a private witness is
|
/// A constant is allocated if `cs` is `None`, and a private witness is
|
||||||
|
|||||||
@@ -703,10 +703,11 @@ impl<F: PrimeField> AllocVar<F, F> for AllocatedFp<F> {
|
|||||||
value = Some(*f()?.borrow());
|
value = Some(*f()?.borrow());
|
||||||
value.ok_or(SynthesisError::AssignmentMissing)
|
value.ok_or(SynthesisError::AssignmentMissing)
|
||||||
};
|
};
|
||||||
let variable = if mode == AllocationMode::Input {
|
let variable = match mode {
|
||||||
cs.new_input_variable(value_generator)?
|
AllocationMode::Input => cs.new_input_variable(value_generator)?,
|
||||||
} else {
|
AllocationMode::Witness => cs.new_witness_variable(value_generator)?,
|
||||||
cs.new_witness_variable(value_generator)?
|
AllocationMode::Committed => cs.new_committed_variable(value_generator)?,
|
||||||
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
Ok(Self::new(value, variable, cs))
|
Ok(Self::new(value, variable, cs))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -514,12 +514,13 @@ where
|
|||||||
// zero if `self` was zero. However, we also want to make sure that generated
|
// zero if `self` was zero. However, we also want to make sure that generated
|
||||||
// constraints are satisfiable in both cases.
|
// constraints are satisfiable in both cases.
|
||||||
//
|
//
|
||||||
// In particular, using non-sensible values for `x` and `y` in zero-case may cause
|
// In particular, using non-sensible values for `x` and `y` in zero-case may
|
||||||
// `unchecked` operations to generate constraints that can never be satisfied, depending
|
// cause `unchecked` operations to generate constraints that can never
|
||||||
// on the curve equation coefficients.
|
// be satisfied, depending on the curve equation coefficients.
|
||||||
//
|
//
|
||||||
// The safest approach is to use coordinates of some point from the curve, thus not
|
// The safest approach is to use coordinates of some point from the curve, thus
|
||||||
// violating assumptions of `NonZeroAffine`. For instance, generator point.
|
// not violating assumptions of `NonZeroAffine`. For instance, generator
|
||||||
|
// point.
|
||||||
let x = infinity.select(&F::constant(P::GENERATOR.x), &x)?;
|
let x = infinity.select(&F::constant(P::GENERATOR.x), &x)?;
|
||||||
let y = infinity.select(&F::constant(P::GENERATOR.y), &y)?;
|
let y = infinity.select(&F::constant(P::GENERATOR.y), &y)?;
|
||||||
let non_zero_self = NonZeroAffineVar::new(x, y);
|
let non_zero_self = NonZeroAffineVar::new(x, y);
|
||||||
@@ -904,6 +905,7 @@ where
|
|||||||
Ok(ge)
|
Ok(ge)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -650,6 +650,7 @@ where
|
|||||||
Ok(ge)
|
Ok(ge)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
_ => unimplemented!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
//! This crate implements common "gadgets" that make
|
//! This crate implements common "gadgets" that make
|
||||||
//! programming rank-1 constraint systems easier.
|
//! programming rank-1 constraint systems easier.
|
||||||
#![deny(
|
#![deny(
|
||||||
warnings,
|
// warnings,
|
||||||
unused,
|
// unused,
|
||||||
future_incompatible,
|
future_incompatible,
|
||||||
nonstandard_style,
|
nonstandard_style,
|
||||||
rust_2018_idioms
|
rust_2018_idioms
|
||||||
|
|||||||
Reference in New Issue
Block a user