Update get range proof signature function to return an error

This commit is contained in:
aniampio
2022-04-19 16:55:57 +03:00
parent 8e9c0d2b0d
commit f96a4ffed3
4 changed files with 18 additions and 5 deletions
+3
View File
@@ -25,6 +25,9 @@ pub enum CompactEcashError {
#[error("Spend Verification related error: {0}")]
Spend(String),
#[error("ZKP Proof related error: {0}")]
RangeProofOutOfBound(String),
#[error("Tried to deserialize {object} with bytes of invalid length. Expected {actual} < {} or {modulus_target} % {modulus} == 0")]
DeserializationInvalidLength {
actual: usize,
@@ -319,7 +319,7 @@ impl SpendProof {
mod tests {
use bls12_381::{G1Projective, G2Projective, Scalar};
use group::Curve;
use rand::thread_rng;
use rand::{Rng, thread_rng};
use crate::proofs::proof_spend::{SpendInstance, SpendProof, SpendWitness};
use crate::scheme::{pseudorandom_fgt, pseudorandom_fgv};
@@ -350,6 +350,7 @@ mod tests {
let v = grparams.random_scalar();
let t = grparams.random_scalar();
let attributes = vec![sk, v, t];
// the below value must be from range 0 to params.L()
let l = 5;
let gamma1 = *grparams.gamma1();
let g1 = *grparams.gen1();
@@ -387,7 +388,7 @@ mod tests {
let o_lambda = ((o_a + o_d) * lambda).neg();
// parse the signature associated with value l
let sign_l = params.get_sign_by_idx(l);
let sign_l = params.get_sign_by_idx(l).unwrap();
// randomise the signature associated with value l
let (sign_l_prime, r_l) = sign_l.randomise(grparams);
// compute kappa_l
+1 -1
View File
@@ -121,7 +121,7 @@ impl Wallet {
let o_lambda = ((o_a + o_d) * lambda).neg();
// parse the signature associated with value l
let sign_l = params.get_sign_by_idx(self.l());
let sign_l = params.get_sign_by_idx(self.l())?;
// randomise the signature associated with value l
let (sign_l_prime, sign_l_blinding_factor) = sign_l.randomise(grparams);
// compute kappa_l
+11 -2
View File
@@ -5,7 +5,7 @@ use ff::Field;
use group::{Curve, GroupEncoding};
use rand::thread_rng;
use crate::error::Result;
use crate::error::{CompactEcashError, Result};
use crate::utils::{hash_g1, Signature};
const ATTRIBUTES_LEN: usize = 3;
@@ -112,7 +112,16 @@ impl Parameters {
pub fn pkRP(&self) -> &PublicKeyRP { &self.pkRP }
pub fn L(&self) -> u64 { self.L }
pub fn signs(&self) -> &HashMap<u64, Signature> { &self.signs }
pub fn get_sign_by_idx(&self, idx: u64) -> &Signature { self.signs.get(&idx).unwrap() }
pub fn get_sign_by_idx(&self, idx: u64) -> Result<&Signature> {
match self.signs.get(&idx) {
Some(val) => return Ok(val),
None => return
Err(CompactEcashError::RangeProofOutOfBound
("Cannot find the range proof signature for the given value. \
Check if the requested value is within the bound 0..L".to_string()
))
}
}
}
pub fn setup() -> Parameters {