[−][src]Struct private_currency::crypto::Commitment
Pedersen commitment to an integer value.
Theory
A Pedersen commitment has the form (in the additive notation)
Comm(x; r) = xG + rH,
where
GandHare two generators in a prime-order groupQ, with unknown discrete logarithm relationships among them (i.e., nobody knowsksuch asG = kH)xis the committed value (it’s a residue class modulo the group order|Q|, but we may essentially treat it as an integer)ris the blinding factor (also a residue class modulo the group order|Q|). Usually, it’s chosen randomly from a cryptographically secure RNG.
Q, G and H are public parameters of the scheme shared among all commitments,
while x and r are private.
(x, r) is called an opening to the commitment; knowing the opening, it’s easy to check
if it corresponds to the given commitment.
Under common security assumptions, a Pedersen commitment is
- perfectly hiding (a party not knowing
xandrcannot find them out fromComm(..)), and - computationally binding (a party cannot produce
(x', r') != (x, r)such that they will open to the same commitment).
Commitment arithmetic
It is possible to add and subtract Pedersen commitments; the result is a commitment to the sum / difference of corresponding values. This fact is what allows using commitments in private currency.
Implementation details
We use a Ristretto group built on top of Curve25519 as Q. Generators G and H are
constructed according to the default scheme in the bulletproofs
implementation.
Examples
let (mut commitment, mut opening) = Commitment::new(42); assert_eq!(opening.value, 42); assert_eq!(commitment, Commitment::from_opening(&opening)); let (other_commitment, other_opening) = Commitment::new(23); commitment -= other_commitment; opening -= other_opening; assert_eq!(opening.value, 19); assert_eq!(commitment, Commitment::from_opening(&opening));
Methods
impl Commitment[src]
impl Commitmentpub fn new(value: u64) -> (Self, Opening)[src]
pub fn new(value: u64) -> (Self, Opening)Creates a commitment with a randomly chosen blinding.
Return value
Returns the created commitment and the corresponding opening for it.
pub fn from_opening(opening: &Opening) -> Self[src]
pub fn from_opening(opening: &Opening) -> SelfCreates a commitment from the given opening.
pub fn with_no_blinding(value: u64) -> Self[src]
pub fn with_no_blinding(value: u64) -> SelfCreates a commitment with no blinding factor.
Warning. The commitments created in this way are not hiding. Use them only if you know what you’re doing.
pub fn from_slice(slice: &[u8]) -> Option<Self>[src]
pub fn from_slice(slice: &[u8]) -> Option<Self>Attempts to deserialize a commitment from byte slice.
pub fn to_bytes(&self) -> Vec<u8>[src]
pub fn to_bytes(&self) -> Vec<u8>Serializes this commitment to bytes.
Implementation details
The commitment is serialized as a single compressed Ristretto point (i.e., 32 bytes).
pub fn verify(&self, opening: &Opening) -> bool[src]
pub fn verify(&self, opening: &Opening) -> boolVerifies if this commitment corresponds to the provided opening.
Trait Implementations
impl Clone for Commitment[src]
impl Clone for Commitmentfn clone(&self) -> Commitment[src]
fn clone(&self) -> Commitmentfn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl Eq for Commitment[src]
impl Eq for Commitmentimpl PartialEq<Commitment> for Commitment[src]
impl PartialEq<Commitment> for Commitmentfn eq(&self, other: &Commitment) -> bool[src]
fn eq(&self, other: &Commitment) -> boolfn ne(&self, other: &Commitment) -> bool[src]
fn ne(&self, other: &Commitment) -> boolimpl Debug for Commitment[src]
impl Debug for Commitmentimpl Sub<Commitment> for Commitment[src]
impl Sub<Commitment> for Commitmenttype Output = Commitment
The resulting type after applying the - operator.
fn sub(self, rhs: Self) -> Commitment[src]
fn sub(self, rhs: Self) -> Commitmentimpl<'a, 'b> Sub<&'b Commitment> for &'a Commitment[src]
impl<'a, 'b> Sub<&'b Commitment> for &'a Commitmenttype Output = Commitment
The resulting type after applying the - operator.
fn sub(self, rhs: &'b Commitment) -> Commitment[src]
fn sub(self, rhs: &'b Commitment) -> Commitmentimpl Add<Commitment> for Commitment[src]
impl Add<Commitment> for Commitmenttype Output = Commitment
The resulting type after applying the + operator.
fn add(self, rhs: Self) -> Commitment[src]
fn add(self, rhs: Self) -> Commitmentimpl<'a, 'b> Add<&'b Commitment> for &'a Commitment[src]
impl<'a, 'b> Add<&'b Commitment> for &'a Commitmenttype Output = Commitment
The resulting type after applying the + operator.
fn add(self, rhs: &'b Commitment) -> Commitment[src]
fn add(self, rhs: &'b Commitment) -> Commitmentimpl SubAssign<Commitment> for Commitment[src]
impl SubAssign<Commitment> for Commitmentfn sub_assign(&mut self, rhs: Self)[src]
fn sub_assign(&mut self, rhs: Self)impl ExonumJson for Commitment[src]
impl ExonumJson for Commitmentfn deserialize_field<B: WriteBufferWrapper>(
value: &Value,
buffer: &mut B,
from: u32,
to: u32
) -> Result<(), Box<dyn Error>>[src]
fn deserialize_field<B: WriteBufferWrapper>(
value: &Value,
buffer: &mut B,
from: u32,
to: u32
) -> Result<(), Box<dyn Error>>fn serialize_field(&self) -> Result<Value, Box<dyn Error + Send + Sync>>[src]
fn serialize_field(&self) -> Result<Value, Box<dyn Error + Send + Sync>>impl<'a> Field<'a> for Commitment[src]
impl<'a> Field<'a> for Commitmentfn field_size() -> u32[src]
fn field_size() -> u32unsafe fn read(buffer: &'a [u8], from: u32, to: u32) -> Self[src]
unsafe fn read(buffer: &'a [u8], from: u32, to: u32) -> Selffn write(&self, buffer: &mut Vec<u8>, from: u32, to: u32)[src]
fn write(&self, buffer: &mut Vec<u8>, from: u32, to: u32)fn check(
buffer: &'a [u8],
from: CheckedOffset,
to: CheckedOffset,
latest_segment: CheckedOffset
) -> CheckResult[src]
fn check(
buffer: &'a [u8],
from: CheckedOffset,
to: CheckedOffset,
latest_segment: CheckedOffset
) -> CheckResultimpl FromHex for Commitment[src]
impl FromHex for Commitmentimpl CryptoHash for Commitment[src]
impl CryptoHash for Commitmentimpl StorageValue for Commitment[src]
impl StorageValue for Commitmentfn into_bytes(self) -> Vec<u8>[src]
fn into_bytes(self) -> Vec<u8>fn from_bytes(value: Cow<[u8]>) -> Self[src]
fn from_bytes(value: Cow<[u8]>) -> SelfAuto Trait Implementations
impl Send for Commitment
impl Send for Commitmentimpl Sync for Commitment
impl Sync for CommitmentBlanket Implementations
impl<T> From for T[src]
impl<T> From for Timpl<T, U> Into for T where
U: From<T>, [src]
impl<T, U> Into for T where
U: From<T>, impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, impl<T, U> TryFrom for T where
T: From<U>, [src]
impl<T, U> TryFrom for T where
T: From<U>, type Error = !
try_from)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>impl<T> Borrow for T where
T: ?Sized, [src]
impl<T> Borrow for T where
T: ?Sized, impl<T> Any for T where
T: 'static + ?Sized, [src]
impl<T> Any for T where
T: 'static + ?Sized, fn get_type_id(&self) -> TypeId[src]
fn get_type_id(&self) -> TypeIdimpl<T, U> TryInto for T where
U: TryFrom<T>, [src]
impl<T, U> TryInto for T where
U: TryFrom<T>, type Error = <U as TryFrom<T>>::Error
try_from)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>impl<T> BorrowMut for T where
T: ?Sized, [src]
impl<T> BorrowMut for T where
T: ?Sized, fn borrow_mut(&mut self) -> &mut T[src]
fn borrow_mut(&mut self) -> &mut Timpl<'a, T> Field for T where
T: SegmentField<'a>, [src]
impl<'a, T> Field for T where
T: SegmentField<'a>, fn field_size() -> u32[src]
fn field_size() -> u32unsafe fn read(buffer: &'a [u8], from: u32, to: u32) -> T[src]
unsafe fn read(buffer: &'a [u8], from: u32, to: u32) -> Tfn write(&self, buffer: &mut Vec<u8>, from: u32, to: u32)[src]
fn write(&self, buffer: &mut Vec<u8>, from: u32, to: u32)fn check(
buffer: &'a [u8],
pointer_from: CheckedOffset,
pointer_to: CheckedOffset,
latest_segment: CheckedOffset
) -> Result<CheckedOffset, Error>[src]
fn check(
buffer: &'a [u8],
pointer_from: CheckedOffset,
pointer_to: CheckedOffset,
latest_segment: CheckedOffset
) -> Result<CheckedOffset, Error>impl<T> CryptoHash for T where
T: Message, [src]
impl<T> CryptoHash for T where
T: Message, impl<T> UniqueHash for T where
T: CryptoHash, [src]
impl<T> UniqueHash for T where
T: CryptoHash, impl<T> Erased for T
impl<T> Erased for Timpl<T> Erased for T
impl<T> Erased for Timpl<Q, K> Equivalent for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized, [src]
impl<Q, K> Equivalent for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized, fn equivalent(&self, key: &K) -> bool[src]
fn equivalent(&self, key: &K) -> boolimpl<T> Same for T
impl<T> Same for Ttype Output = T
Should always be Self