Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the messages spec #114

Merged
merged 71 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
8344932
start messages and validation
oxarbitrage May 13, 2021
b20bc86
add missing docs to constants
oxarbitrage May 13, 2021
f9bc28c
change validation to matches, fix constant doc
oxarbitrage May 14, 2021
be6c9f5
fix the build
oxarbitrage May 14, 2021
e949f2b
validate share_commitment
oxarbitrage May 14, 2021
baa4552
add new constants and validations
oxarbitrage May 14, 2021
2891486
fix validation
oxarbitrage May 14, 2021
c650406
derive serde Serialize and Deserialize in all messages structs
oxarbitrage May 14, 2021
e19e34e
update created structs
oxarbitrage May 17, 2021
474997b
fix build
oxarbitrage May 17, 2021
873dc95
define and use a new MAX_SIGNERS constant
oxarbitrage May 17, 2021
590e812
change group_public type
oxarbitrage May 17, 2021
dbad358
Merge branch 'messages_impl1' into messages_impl2
oxarbitrage May 17, 2021
5de661c
add some test cases
oxarbitrage May 18, 2021
c259682
add validation and serialization tests for SigningCommitments
oxarbitrage May 18, 2021
2e33163
add validation and serialization test to SigningPackage
oxarbitrage May 18, 2021
6b26a1e
change some fields order matching the spec
oxarbitrage May 19, 2021
7f86b2b
Merge branch 'messages_impl1' into messages_impl3
oxarbitrage May 19, 2021
f54616b
fix field order in tests according to last updates to the spec
oxarbitrage May 19, 2021
1eb5d7e
implement serialize and deserialize for ParticipantId
oxarbitrage May 19, 2021
beb3e97
move serde-json to dev-dependencies section
oxarbitrage May 20, 2021
951633b
change to pub(crate)
oxarbitrage May 20, 2021
a8d2357
fix serialize of VerificationKey
oxarbitrage May 20, 2021
6dfb4bc
add assert to serialize
oxarbitrage May 20, 2021
6cae46b
add note, fix typo
oxarbitrage May 20, 2021
30b72b7
improve some code in tests
oxarbitrage May 20, 2021
54e5f29
test serialization of individual fields
oxarbitrage May 20, 2021
4f73414
start messages and validation
oxarbitrage May 13, 2021
e81e223
add missing docs to constants
oxarbitrage May 13, 2021
766e33f
change validation to matches, fix constant doc
oxarbitrage May 14, 2021
3ab77eb
fix the build
oxarbitrage May 14, 2021
c75bddd
validate share_commitment
oxarbitrage May 14, 2021
a82e4d2
add new constants and validations
oxarbitrage May 14, 2021
952b02b
fix validation
oxarbitrage May 14, 2021
65ef751
define and use a new MAX_SIGNERS constant
oxarbitrage May 17, 2021
2078664
change group_public type
oxarbitrage May 17, 2021
2d1ff77
change some fields order matching the spec
oxarbitrage May 19, 2021
916a180
change message fields to new spec
oxarbitrage May 28, 2021
34afee9
Merge remote-tracking branch 'mioarriba/messages_impl1' into messages…
oxarbitrage May 28, 2021
4eb856d
Merge remote-tracking branch 'mioarriba/messages_impl2' into messages…
oxarbitrage May 28, 2021
4fce7ff
remove some non needed conversions
oxarbitrage May 28, 2021
3f19aa7
use a BTreeMap to guarantee the order
oxarbitrage May 29, 2021
90b0200
remove some calls to `clone()` by implementing `Copy`
oxarbitrage May 30, 2021
2363dda
change message type in frost and add validate_signatureshare test
oxarbitrage May 31, 2021
7797a63
change `share_commitment` to BTreeMap
oxarbitrage May 31, 2021
a2d7e93
add `serialize_signatureshare` test
oxarbitrage May 31, 2021
3d03f20
add aggregatesignature tests
oxarbitrage Jun 1, 2021
1b58a12
add some test header messages utility functions
oxarbitrage Jun 1, 2021
c69802f
add a setup utility
oxarbitrage Jun 1, 2021
126287d
move the general serialization checks into an utility function
oxarbitrage Jun 1, 2021
7bfca23
fi some typos
oxarbitrage Jun 1, 2021
3e5b7e7
add and use a `generate_share_commitment` utility
oxarbitrage Jun 2, 2021
d2090b8
add create_signing_commitments utility function
oxarbitrage Jun 2, 2021
b461a86
improve the serialization tests
oxarbitrage Jun 2, 2021
98f1f3e
make room for prop tests
oxarbitrage Jun 2, 2021
602b4f7
add arbitrary tests for serialization
oxarbitrage Jun 2, 2021
97ffcc3
remove allow dead code from messages
oxarbitrage Jun 2, 2021
3817e63
fix some imports
oxarbitrage Jun 2, 2021
7e4ba0a
make signature module public only to the crate
oxarbitrage Jun 3, 2021
ac9d5e6
simplify a bit the frost tests
oxarbitrage Jun 3, 2021
5df8a42
improve the generated docs
oxarbitrage Jun 3, 2021
34246d3
add a `prop_filter` to Header arbitrary
oxarbitrage Jun 3, 2021
4c60947
(ab)use proptest_derive
oxarbitrage Jun 3, 2021
95fb882
improve validation for Message
oxarbitrage Jun 3, 2021
27a8cc2
improve some utility functions
oxarbitrage Jun 3, 2021
2a87605
change frost to serialization id conversion
oxarbitrage Jun 3, 2021
a066bb7
add a quick btreemap test
oxarbitrage Jun 3, 2021
760115e
change the `MsgType` to `u32`
oxarbitrage Jun 3, 2021
59638f3
add no leftover bytes checks
oxarbitrage Jun 3, 2021
8369111
add a full_setup utility
oxarbitrage Jun 3, 2021
503af0e
add map len checks
oxarbitrage Jun 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ funty = "=1.1.0"
[dev-dependencies]
bincode = "1"
criterion = "0.3"
proptest-derive = "0.3"
lazy_static = "1.4"
proptest = "1.0"
rand = "0.8"
rand_chacha = "0.3"
serde_json = "1.0"

[features]
nightly = []
Expand Down
42 changes: 25 additions & 17 deletions src/frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use crate::private::Sealed;
use crate::{HStar, Signature, SpendAuth, VerificationKey};

/// A secret scalar value representing a single signer's secret key.
#[derive(Clone, Copy, Default)]
pub struct Secret(Scalar);
#[derive(Clone, Copy, Default, PartialEq)]
pub struct Secret(pub(crate) Scalar);

// Zeroizes `Secret` to be the `Default` value on drop (when it goes out of
// scope). Luckily the derived `Default` includes the `Default` impl of
Expand Down Expand Up @@ -63,17 +63,19 @@ impl From<jubjub::ExtendedPoint> for Public {
#[derive(Clone)]
pub struct Share {
receiver_index: u64,
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved
value: Secret,
commitment: ShareCommitment,
/// Secret Key.
pub(crate) value: Secret,
/// The commitments to be distributed among signers.
pub(crate) commitment: ShareCommitment,
}

/// A Jubjub point that is a commitment to one coefficient of our secret
/// polynomial.
///
/// This is a (public) commitment to one coefficient of a secret polynomial used
/// for performing verifiable secret sharing for a Shamir secret share.
#[derive(Clone)]
struct Commitment(jubjub::AffinePoint);
#[derive(Clone, PartialEq)]
pub(crate) struct Commitment(pub(crate) jubjub::AffinePoint);

/// Contains the commitments to the coefficients for our secret polynomial _f_,
/// used to generate participants' key shares.
Expand All @@ -88,11 +90,12 @@ struct Commitment(jubjub::AffinePoint);
/// some agreed-upon public location for publication, where each participant can
/// ensure that they received the correct (and same) value.
#[derive(Clone)]
pub struct ShareCommitment(Vec<Commitment>);
pub struct ShareCommitment(pub(crate) Vec<Commitment>);

/// The product of all signers' individual commitments, published as part of the
/// final signature.
pub struct GroupCommitment(jubjub::AffinePoint);
#[derive(PartialEq)]
pub struct GroupCommitment(pub(crate) jubjub::AffinePoint);

/// Secret and public key material generated by a dealer performing
/// [`keygen_with_dealer`].
Expand Down Expand Up @@ -363,9 +366,12 @@ impl SigningNonces {
/// SigningCommitment can be used for exactly *one* signature.
#[derive(Copy, Clone)]
pub struct SigningCommitments {
index: u64,
hiding: jubjub::ExtendedPoint,
binding: jubjub::ExtendedPoint,
/// The participant index
pub(crate) index: u64,
/// The hiding point.
pub(crate) hiding: jubjub::ExtendedPoint,
/// The binding point.
pub(crate) binding: jubjub::ExtendedPoint,
}

impl From<(u64, &SigningNonces)> for SigningCommitments {
Expand All @@ -388,12 +394,12 @@ pub struct SigningPackage {
/// Message which each participant will sign.
///
/// Each signer should perform protocol-specific verification on the message.
pub message: &'static [u8],
pub message: Vec<u8>,
oxarbitrage marked this conversation as resolved.
Show resolved Hide resolved
}

/// A representation of a single signature used in FROST structures and messages.
#[derive(Clone, Copy, Default)]
pub struct SignatureResponse(Scalar);
#[derive(Clone, Copy, Default, PartialEq)]
pub struct SignatureResponse(pub(crate) Scalar);

/// A participant's signature share, which the coordinator will use to aggregate
/// with all other signer's shares into the joint signature.
Expand Down Expand Up @@ -438,7 +444,7 @@ impl SignatureShare {
/// 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
/// The number of nonces is limited to 255. This limit can be increased if it
/// turns out to be too conservative.
// TODO: Make sure the above is a correct statement, fix if needed in:
// https://github.com/ZcashFoundation/redjubjub/issues/111
Expand Down Expand Up @@ -471,7 +477,9 @@ fn gen_rho_i(index: u64, signing_package: &SigningPackage) -> Scalar {
// binding factor, we should hash our input message first. Our 'standard'
// hash is HStar, which uses a domain separator already, and is the same one
// that generates the binding factor.
let message_hash = HStar::default().update(signing_package.message).finalize();
let message_hash = HStar::default()
.update(signing_package.message.as_slice())
.finalize();

let mut hasher = HStar::default();
hasher
Expand Down Expand Up @@ -526,7 +534,7 @@ fn gen_challenge(
HStar::default()
.update(group_commitment_bytes)
.update(group_public.bytes.bytes)
.update(signing_package.message)
.update(signing_package.message.as_slice())
.finalize()
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ mod constants;
mod error;
pub mod frost;
mod hash;
mod messages;
mod scalar_mul;
mod signature;
pub(crate) mod signature;
mod signing_key;
mod verification_key;

Expand Down
Loading