Skip to content

Commit

Permalink
feat: relax commit bounds (#10)
Browse files Browse the repository at this point in the history
* Relax commit bounds

Relaxed commit bounds by allowing generators with more extension degrees (that
remain unused) as is strictly necessary for the resulting multi-exponentiation
multiplication.

* test CI benches failure

CI benches fails with `Error: Process completed with exit code 1.`

In `benchmark.yml`
```
          fail-on-alert: true
```
and in the tests
```
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high severe
```
which could be the reason it reports a failure.
  • Loading branch information
hansieodendaal committed May 31, 2022
1 parent 15a799f commit 4ec07aa
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Expand Up @@ -30,5 +30,5 @@ jobs:
# Show alert with commit comment on detecting possible performance regression
alert-threshold: '120%'
comment-on-alert: true
fail-on-alert: true
fail-on-alert: false
alert-comment-cc-users: '@mikethetike'
9 changes: 4 additions & 5 deletions src/generators/pedersen_gens.rs
Expand Up @@ -94,18 +94,17 @@ where P: Compressable + MultiscalarMul<Point = P> + Clone
{
/// Creates a Pedersen commitment using the value scalar and a blinding factor vector
pub fn commit(&self, value: Scalar, blindings: &[Scalar]) -> Result<P, ProofError> {
let extension_degree = self.extension_degree as usize;
if blindings.is_empty() || blindings.len() != extension_degree {
if blindings.is_empty() || blindings.len() > self.extension_degree as usize {
Err(ProofError::InvalidLength("blinding vector".to_string()))
} else {
let mut scalars = Vec::with_capacity(1 + extension_degree);
let mut scalars = Vec::with_capacity(1 + blindings.len());
scalars.push(value);
for item in blindings {
scalars.push(*item);
}
let mut points = Vec::with_capacity(1 + extension_degree);
let mut points = Vec::with_capacity(1 + blindings.len());
points.push(self.h_base.clone());
for item in self.g_base_vec.iter().take(extension_degree) {
for item in self.g_base_vec.iter().take(blindings.len()) {
points.push(item.clone());
}
Ok(P::multiscalar_mul(&scalars, &points))
Expand Down
31 changes: 14 additions & 17 deletions src/ristretto.rs
Expand Up @@ -181,6 +181,15 @@ mod tests {
use super::*;
use crate::protocols::scalar_protocol::ScalarProtocol;

static EXTENSION_DEGREE: [ExtensionDegree; 6] = [
ExtensionDegree::Zero,
ExtensionDegree::One,
ExtensionDegree::Two,
ExtensionDegree::Three,
ExtensionDegree::Four,
ExtensionDegree::Five,
];

#[test]
fn test_constants() {
// Extended Pedersen generators with extension degree of zero to five
Expand All @@ -192,14 +201,7 @@ mod tests {
*RISTRETTO_BASEPOINT_POINT_BLINDING_5,
*RISTRETTO_BASEPOINT_POINT_BLINDING_6,
];
for extension_degree in [
ExtensionDegree::Zero,
ExtensionDegree::One,
ExtensionDegree::Two,
ExtensionDegree::Three,
ExtensionDegree::Four,
ExtensionDegree::Five,
] {
for extension_degree in EXTENSION_DEGREE {
let pc_gens = create_pedersen_gens_with_extension_degree(extension_degree);
for (i, item) in lazy_statics.iter().enumerate().take(pc_gens.extension_degree as usize) {
assert_eq!(pc_gens.g_base_vec[i].compress(), pc_gens.g_base_compressed_vec[i]);
Expand All @@ -223,17 +225,12 @@ mod tests {
Scalar::random_not_zero(&mut rng),
];

for extension_degree in [
ExtensionDegree::Zero,
ExtensionDegree::One,
ExtensionDegree::Two,
ExtensionDegree::Three,
ExtensionDegree::Four,
ExtensionDegree::Five,
] {
for extension_degree in EXTENSION_DEGREE {
let pc_gens = create_pedersen_gens_with_extension_degree(extension_degree);
for i in 0..ExtensionDegree::Five as usize {
if i == extension_degree as usize {
// All commitments where enough extended generators are available to enable multi-exponentiation
// multiplication of the blinding factor vector will be ok
if i > 0 && i <= extension_degree as usize {
assert!(pc_gens.commit(value, blindings[..i].to_owned().as_slice()).is_ok());
} else {
assert!(pc_gens.commit(value, blindings[..i].to_owned().as_slice()).is_err());
Expand Down

0 comments on commit 4ec07aa

Please sign in to comment.