Skip to content

Commit

Permalink
Change the type of the identifiers from u8 to u64
Browse files Browse the repository at this point in the history
  • Loading branch information
upbqdn authored and oxarbitrage committed May 26, 2021
1 parent 0c7a105 commit 21b2f08
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
41 changes: 22 additions & 19 deletions src/frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl From<jubjub::ExtendedPoint> for Public {
/// reconstruct the secret; in this case we use Shamir's secret sharing.
#[derive(Clone)]
pub struct Share {
receiver_index: u8,
receiver_index: u64,
value: Secret,
commitment: ShareCommitment,
}
Expand Down Expand Up @@ -102,9 +102,8 @@ pub struct GroupCommitment(jubjub::AffinePoint);
pub struct SharePackage {
/// The public signing key that represents the entire group.
pub(crate) group_public: VerificationKey<SpendAuth>,
/// Denotes the participant index each share is owned by. We implicitly
/// restrict the number of participants to 255.
pub index: u8,
/// Denotes the participant index each share is owned by.
pub index: u64,
/// This participant's public key.
pub(crate) public: Public,
/// This participant's share.
Expand Down Expand Up @@ -142,7 +141,7 @@ impl TryFrom<SharePackage> for KeyPackage {
/// [`KeyPackage`]s, which they store to later use during signing.
#[allow(dead_code)]
pub struct KeyPackage {
index: u8,
index: u64,
secret_share: Secret,
public: Public,
group_public: VerificationKey<SpendAuth>,
Expand All @@ -157,7 +156,7 @@ pub struct PublicKeyPackage {
/// correct view of participant's public keys to perform verification before
/// publishing a signature. signer_pubkeys represents all signers for a
/// signing operation.
pub(crate) signer_pubkeys: HashMap<u8, Public>,
pub(crate) signer_pubkeys: HashMap<u64, Public>,
/// group_public represents the joint public key for the entire group.
pub group_public: VerificationKey<SpendAuth>,
}
Expand All @@ -168,7 +167,8 @@ pub struct PublicKeyPackage {
/// Under the hood, this performs verifiable secret sharing, which itself uses
/// Shamir secret sharing, from which each share becomes a participant's secret
/// key. The output from this function is a set of shares along with one single
/// commitment that participants use to verify the integrity of the share.
/// commitment that participants use to verify the integrity of the share. The
/// number of signers is limited to 255.
pub fn keygen_with_dealer<R: RngCore + CryptoRng>(
num_signers: u8,
threshold: u8,
Expand All @@ -181,7 +181,7 @@ pub fn keygen_with_dealer<R: RngCore + CryptoRng>(
let group_public = VerificationKey::from(&secret.0);
let shares = generate_shares(&secret, num_signers, threshold, rng)?;
let mut sharepackages: Vec<SharePackage> = Vec::with_capacity(num_signers as usize);
let mut signer_pubkeys: HashMap<u8, Public> = HashMap::with_capacity(num_signers as usize);
let mut signer_pubkeys: HashMap<u64, Public> = HashMap::with_capacity(num_signers as usize);

for share in shares {
let signer_public = Public(SpendAuth::basepoint() * share.value.0);
Expand Down Expand Up @@ -301,7 +301,7 @@ fn generate_shares<R: RngCore + CryptoRng>(
value += secret.0;

shares.push(Share {
receiver_index: index,
receiver_index: index as u64,
value: Secret(value),
commitment: commitment.clone(),
});
Expand Down Expand Up @@ -363,14 +363,14 @@ impl SigningNonces {
/// SigningCommitment can be used for exactly *one* signature.
#[derive(Copy, Clone)]
pub struct SigningCommitments {
index: u8,
index: u64,
hiding: jubjub::ExtendedPoint,
binding: jubjub::ExtendedPoint,
}

impl From<(u8, &SigningNonces)> for SigningCommitments {
impl From<(u64, &SigningNonces)> for SigningCommitments {
/// For SpendAuth signatures only, not Binding signatures, in RedJubjub/Zcash.
fn from((index, nonces): (u8, &SigningNonces)) -> Self {
fn from((index, nonces): (u64, &SigningNonces)) -> Self {
Self {
index,
hiding: SpendAuth::basepoint() * nonces.hiding,
Expand Down Expand Up @@ -400,7 +400,7 @@ pub struct SignatureResponse(Scalar);
#[derive(Clone, Copy, Default)]
pub struct SignatureShare {
/// Represents the participant index.
pub(crate) index: u8,
pub(crate) index: u64,
/// This participant's signature over the message.
pub(crate) signature: SignatureResponse,
}
Expand Down Expand Up @@ -437,9 +437,12 @@ impl SignatureShare {
/// perform the first round. Batching entails generating more than one
/// nonce/commitment pair at a time. Nonces should be stored in secret storage
/// for later use, whereas the commitments are published.

/// The number of nonces is limited to 255. This limit can be increased if it
/// turns out to be too conservative.
pub fn preprocess<R>(
num_nonces: u8,
participant_index: u8,
participant_index: u64,
rng: &mut R,
) -> (Vec<SigningNonces>, Vec<SigningCommitments>)
where
Expand All @@ -459,7 +462,7 @@ where

/// Generates the binding factor that ensures each signature share is strongly
/// bound to a signing set, specific set of commitments, and a specific message.
fn gen_rho_i(index: u8, signing_package: &SigningPackage) -> Scalar {
fn gen_rho_i(index: u64, signing_package: &SigningPackage) -> Scalar {
// Hash signature message with HStar before deriving the binding factor.
//
// To avoid a collision with other inputs to the hash that generates the
Expand Down Expand Up @@ -489,7 +492,7 @@ fn gen_rho_i(index: u8, signing_package: &SigningPackage) -> Scalar {
/// Schnorr signature.
fn gen_group_commitment(
signing_package: &SigningPackage,
bindings: &HashMap<u8, Scalar>,
bindings: &HashMap<u64, Scalar>,
) -> Result<GroupCommitment, &'static str> {
let identity = jubjub::ExtendedPoint::identity();
let mut accumulator = identity;
Expand Down Expand Up @@ -527,7 +530,7 @@ fn gen_challenge(

/// Generates the lagrange coefficient for the i'th participant.
fn gen_lagrange_coeff(
signer_index: u8,
signer_index: u64,
signing_package: &SigningPackage,
) -> Result<Scalar, &'static str> {
let mut num = Scalar::one();
Expand Down Expand Up @@ -563,7 +566,7 @@ pub fn sign(
participant_nonces: SigningNonces,
share_package: &SharePackage,
) -> Result<SignatureShare, &'static str> {
let mut bindings: HashMap<u8, Scalar> =
let mut bindings: HashMap<u64, Scalar> =
HashMap::with_capacity(signing_package.signing_commitments.len());

for comm in signing_package.signing_commitments.iter() {
Expand Down Expand Up @@ -616,7 +619,7 @@ pub fn aggregate(
signing_shares: &[SignatureShare],
pubkeys: &PublicKeyPackage,
) -> Result<Signature<SpendAuth>, &'static str> {
let mut bindings: HashMap<u8, Scalar> =
let mut bindings: HashMap<u64, Scalar> =
HashMap::with_capacity(signing_package.signing_commitments.len());

for comm in signing_package.signing_commitments.iter() {
Expand Down
6 changes: 3 additions & 3 deletions tests/frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ fn check_sign_with_dealer() {
let threshold = 3;
let (shares, pubkeys) = frost::keygen_with_dealer(numsigners, threshold, &mut rng).unwrap();

let mut nonces: HashMap<u8, Vec<frost::SigningNonces>> =
let mut nonces: HashMap<u64, Vec<frost::SigningNonces>> =
HashMap::with_capacity(threshold as usize);
let mut commitments: Vec<frost::SigningCommitments> = Vec::with_capacity(threshold as usize);

// Round 1, generating nonces and signing commitments for each participant.
for participant_index in 1..(threshold + 1) {
// Generate one (1) nonce and one SigningCommitments instance for each
// participant, up to _threshold_.
let (nonce, commitment) = frost::preprocess(1, participant_index, &mut rng);
nonces.insert(participant_index, nonce);
let (nonce, commitment) = frost::preprocess(1, participant_index as u64, &mut rng);
nonces.insert(participant_index as u64, nonce);
commitments.push(commitment[0]);
}

Expand Down

0 comments on commit 21b2f08

Please sign in to comment.