Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ repository = "https://github.com/EspressoSystems/hotshot-primitives"

[dependencies]
anyhow = "1.0"
ark-bls12-381 = "0.4.0"
ark-bls12-377 = "0.4.0"
ark-bls12-381 = "0.4.0"
ark-bn254 = "0.4.0"
ark-ec = "0.4.0"
ark-ff = "0.4.0"
Expand All @@ -26,18 +26,18 @@ digest = { version = "0.10" }
displaydoc = { version = "0.2.3", default-features = false }
ethereum-types = { version = "0.14.1", features = ["impl-serde"] }
generic-array = "0.14.7"
jf-relation = { git = "https://github.com/espressosystems/jellyfish"}
jf-primitives = { git = "https://github.com/espressosystems/jellyfish"}
jf-utils = { git = "https://github.com/espressosystems/jellyfish"}
jf-primitives = { git = "https://github.com/espressosystems/jellyfish" }
jf-relation = { git = "https://github.com/espressosystems/jellyfish" }
jf-utils = { git = "https://github.com/espressosystems/jellyfish" }
serde = { version = "1.0", default-features = false, features = ["derive", "rc"] }
sha3 = "0.10.7"
tagged-base64 = { git = "https://github.com/espressosystems/tagged-base64", tag = "0.3.0" }
thiserror = "1.0"
typenum = { version = "1.16.0" }

[dev-dependencies]
jf-primitives = { git = "https://github.com/espressosystems/jellyfish", features = ["test-srs"]}
criterion = { version = "0.5.1", features = ["html_reports"] }
jf-primitives = { git = "https://github.com/espressosystems/jellyfish", features = ["test-srs"] }
sha2 = { version = "0.10" }

[[bench]]
Expand Down
22 changes: 12 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
inputs.pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
inputs.pre-commit-hooks.inputs.nixpkgs.follows = "nixpkgs";

outputs = { self, nixpkgs, flake-utils, flake-compat, rust-overlay, pre-commit-hooks, ... }:
outputs = { self, nixpkgs, flake-utils, flake-compat, rust-overlay
, pre-commit-hooks, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
nightlyToolchain = pkgs.rust-bin.selectLatestNightlyWith
(toolchain: toolchain.minimal.override { extensions = [ "rustfmt" ]; });
nightlyToolchain = pkgs.rust-bin.selectLatestNightlyWith (toolchain:
toolchain.minimal.override { extensions = [ "rustfmt" ]; });

stableToolchain = pkgs.rust-bin.stable.latest.minimal.override {
extensions = [ "clippy" "llvm-tools-preview" "rust-src" ];
};
in with pkgs;
{
in with pkgs; {
check = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
Expand Down Expand Up @@ -74,18 +74,20 @@
nightlyToolchain
cargo-sort

] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ];
] ++ lib.optionals stdenv.isDarwin
[ darwin.apple_sdk.frameworks.Security ];

shellHook = ''
export RUST_BACKTRACE=full
export PATH="$PATH:$(pwd)/target/debug:$(pwd)/target/release"
# Prevent cargo aliases from using programs in `~/.cargo` to avoid conflicts with local rustup installations.
export CARGO_HOME=$HOME/.cargo-nix

# Ensure `cargo fmt` uses `rustfmt` from nightly.
export RUSTFMT="${nightlyToolchain}/bin/rustfmt"
''
# install pre-commit hooks
+ self.check.${system}.pre-commit-check.shellHook;
# install pre-commit hooks
+ self.check.${system}.pre-commit-check.shellHook;
};
}
);
});
}
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// #![warn(missing_docs)] // TODO need rustdoc for stake_table

pub mod circuit;
pub mod quorum_certificate;
pub mod qc;
pub mod stake_table;
pub mod vdf;
pub mod vid;
75 changes: 75 additions & 0 deletions src/qc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//! Quorum Certificate traits and implementations.

use ark_std::{
rand::{CryptoRng, RngCore},
vec::Vec,
};
use bitvec::prelude::*;
use generic_array::{ArrayLength, GenericArray};
use jf_primitives::errors::PrimitivesError;
use jf_primitives::signatures::AggregateableSignatureSchemes;
use serde::{Deserialize, Serialize};

pub mod bit_vector;

/// Trait for validating a QC built from different signatures on the same message
pub trait QuorumCertificate<A: AggregateableSignatureSchemes + Serialize + for<'a> Deserialize<'a>>
{
/// Public parameters for generating the QC
/// E.g: snark proving/verifying keys, list of (or pointer to) public keys stored in the smart contract.
type QCProverParams: Serialize + for<'a> Deserialize<'a>;

/// Public parameters for validating the QC
/// E.g: verifying keys, stake table commitment
type QCVerifierParams: Serialize + for<'a> Deserialize<'a>;

/// Allows to fix the size of the message at compilation time.
type MessageLength: ArrayLength<A::MessageUnit>;

/// Type of the actual quorum certificate object
type QC;

/// Produces a partial signature on a message with a single user signing key
/// NOTE: the original message (vote) should be prefixed with the hash of the stake table.
/// * `agg_sig_pp` - public parameters for aggregate signature
/// * `message` - message to be signed
/// * `sk` - user signing key
/// * `returns` - a "simple" signature
fn sign<R: CryptoRng + RngCore>(
agg_sig_pp: &A::PublicParameter,
message: &GenericArray<A::MessageUnit, Self::MessageLength>,
sk: &A::SigningKey,
prng: &mut R,
) -> Result<A::Signature, PrimitivesError>;

/// Computes an aggregated signature from a set of partial signatures and the verification keys involved
/// * `qc_pp` - public parameters for generating the QC
/// * `signers` - a bool vector indicating the list of verification keys corresponding to the set of partial signatures
/// * `sigs` - partial signatures on the same message
/// * `returns` - an error if some of the partial signatures provided are invalid
/// or the number of partial signatures / verifications keys are different.
/// Otherwise return an obtained quorum certificate.
fn assemble(
qc_pp: &Self::QCProverParams,
signers: &BitSlice,
sigs: &[A::Signature],
) -> Result<Self::QC, PrimitivesError>;

/// Checks an aggregated signature over some message provided as input
/// * `qc_vp` - public parameters for validating the QC
/// * `message` - message to check the aggregated signature against
/// * `qc` - quroum certificate
/// * `returns` - nothing if the signature is valid, an error otherwise.
fn check(
qc_vp: &Self::QCVerifierParams,
message: &GenericArray<A::MessageUnit, Self::MessageLength>,
qc: &Self::QC,
) -> Result<(), PrimitivesError>;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I remember why this is here now. It's not the Checked<T>. And it is needed.

I'm even the person who requested it, I just forgot.

And I think the entire discussion motivating this was on github.

... 90 minutes of searching later...

https://github.com/EspressoSystems/hotshot-primitives/pull/27/files/907f07d85af77fee0ba1b328a77944cdce4e64d5#r1195601782

Short version: we absolutely, non-negotiably, need the CheckedType if we want to be able to use this from HotShot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for digging this comment for us! could you clarify what would the number CheckedType = U256 signify?
the number of votes inside the qc?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of HotShot, the total number of voted shares, I think...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added it back, see if you like c9429f0 @nyospe


/// Trace the list of signers given a qc.
fn trace(
qc_vp: &Self::QCVerifierParams,
message: &GenericArray<A::MessageUnit, Self::MessageLength>,
qc: &Self::QC,
) -> Result<Vec<A::VerificationKey>, PrimitivesError>;
}
Loading