[−][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
G
andH
are two generators in a prime-order groupQ
, with unknown discrete logarithm relationships among them (i.e., nobody knowsk
such asG = kH
)x
is the committed value (it’s a residue class modulo the group order|Q|
, but we may essentially treat it as an integer)r
is 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
x
andr
cannot 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 Commitment
pub 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) -> Self
Creates a commitment from the given opening.
pub fn with_no_blinding(value: u64) -> Self
[src]
pub fn with_no_blinding(value: u64) -> Self
Creates 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) -> bool
Verifies if this commitment corresponds to the provided opening.
Trait Implementations
impl Clone for Commitment
[src]
impl Clone for Commitment
fn clone(&self) -> Commitment
[src]
fn clone(&self) -> Commitment
fn 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 Commitment
impl PartialEq<Commitment> for Commitment
[src]
impl PartialEq<Commitment> for Commitment
fn eq(&self, other: &Commitment) -> bool
[src]
fn eq(&self, other: &Commitment) -> bool
fn ne(&self, other: &Commitment) -> bool
[src]
fn ne(&self, other: &Commitment) -> bool
impl Debug for Commitment
[src]
impl Debug for Commitment
impl Sub<Commitment> for Commitment
[src]
impl Sub<Commitment> for Commitment
type Output = Commitment
The resulting type after applying the -
operator.
fn sub(self, rhs: Self) -> Commitment
[src]
fn sub(self, rhs: Self) -> Commitment
impl<'a, 'b> Sub<&'b Commitment> for &'a Commitment
[src]
impl<'a, 'b> Sub<&'b Commitment> for &'a Commitment
type Output = Commitment
The resulting type after applying the -
operator.
fn sub(self, rhs: &'b Commitment) -> Commitment
[src]
fn sub(self, rhs: &'b Commitment) -> Commitment
impl Add<Commitment> for Commitment
[src]
impl Add<Commitment> for Commitment
type Output = Commitment
The resulting type after applying the +
operator.
fn add(self, rhs: Self) -> Commitment
[src]
fn add(self, rhs: Self) -> Commitment
impl<'a, 'b> Add<&'b Commitment> for &'a Commitment
[src]
impl<'a, 'b> Add<&'b Commitment> for &'a Commitment
type Output = Commitment
The resulting type after applying the +
operator.
fn add(self, rhs: &'b Commitment) -> Commitment
[src]
fn add(self, rhs: &'b Commitment) -> Commitment
impl SubAssign<Commitment> for Commitment
[src]
impl SubAssign<Commitment> for Commitment
fn sub_assign(&mut self, rhs: Self)
[src]
fn sub_assign(&mut self, rhs: Self)
impl ExonumJson for Commitment
[src]
impl ExonumJson for Commitment
fn 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 Commitment
fn field_size() -> u32
[src]
fn field_size() -> u32
unsafe fn read(buffer: &'a [u8], from: u32, to: u32) -> Self
[src]
unsafe fn read(buffer: &'a [u8], from: u32, to: u32) -> Self
fn 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
) -> CheckResult
impl FromHex for Commitment
[src]
impl FromHex for Commitment
impl CryptoHash for Commitment
[src]
impl CryptoHash for Commitment
impl StorageValue for Commitment
[src]
impl StorageValue for Commitment
fn 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]>) -> Self
Auto Trait Implementations
impl Send for Commitment
impl Send for Commitment
impl Sync for Commitment
impl Sync for Commitment
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<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) -> TypeId
impl<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 T
impl<'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() -> u32
unsafe fn read(buffer: &'a [u8], from: u32, to: u32) -> T
[src]
unsafe fn read(buffer: &'a [u8], from: u32, to: u32) -> T
fn 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 T
impl<T> Erased for T
impl<T> Erased for T
impl<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) -> bool
impl<T> Same for T
impl<T> Same for T
type Output = T
Should always be Self