Skip to content

[WIP]Implement musig for jubjub #95

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,18 @@ path = 'demo/cli/src/main.rs'
members = [
"core/bellman-verifier",
"core/crypto",
"demo/cli",
"demo/cli",
"core/jubjub",
"core/pairing",
"core/primitives",
"core/proofs",
"runtime",
"core/keys",
"core/musig",
"modules/indices",
"modules/executive",
]
exclude = [
"runtime/wasm",
"demo/wasm-utils",
"runtime/wasm",
"demo/wasm-utils",
]
11 changes: 11 additions & 0 deletions core/musig/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "musig"
version = "0.1.0"
authors = ["Osuke Sudo <[email protected]>"]
edition = "2018"

[dependencies]
jubjub = { path = "../jubjub" }
rand = { version = "0.6.0" }
failure = { version = "^0.1.1", default-features = false }
merlin = "1"
134 changes: 134 additions & 0 deletions core/musig/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// This file is based on https://github.com/w3f/schnorrkel/blob/master/src/musig.rs

use jubjub::{
curve::{
FixedGenerators,
JubjubEngine,
JubjubParams,
Unknown,
PrimeOrder,
edwards::Point
},
redjubjub::{
PrivateKey,
PublicKey,
Signature,
}
};
use std::collections::BTreeMap;
use merlin::Transcript;

pub trait TranscriptProtocol {}
impl TranscriptProtocol for Transcript {}

const COMMITMENT_SIZE: usize = 32;

pub struct Commitment(pub [u8; COMMITMENT_SIZE]);

impl Commitment {
fn for_r() -> Commitment {
unimplemented!();
}
}

pub struct KeyPair<E: JubjubEngine> {
pub secret: PrivateKey<E>,
pub public: PublicKey<E>,
}

enum CoR<E: JubjubEngine> {
Commit(Commitment), // H(R_i)
Reveal{ R: Point<E, PrimeOrder>}, // R_i
Cosigned { s: E::Fs }, // s_i extracted from Cosignature type
Collect { R: Point<E, PrimeOrder>, s: E::Fs },
}

impl<E: JubjubEngine> CoR<E> {
fn set_revealsed(&mut self) {
unimplemented!();
}

fn set_cosigned(&mut self, s: E::Fs) -> Result<(), &'static str> {
unimplemented!();
}
}

/// Schnorr multi-signature (MuSig) container generic over its session types
pub struct MuSig<T: TranscriptProtocol, S, E: JubjubEngine> {
t: T,
Rs: BTreeMap<PublicKey<E>, CoR<E>>,
stage: S
}

impl<T: TranscriptProtocol, S, E: JubjubEngine> MuSig<T, S, E> {

}

/// Commitment stage for cosigner's `R` values
pub struct CommitStage<'k, E: JubjubEngine> {
keypair: &'k KeyPair<E>,
r_me: E::Fs,
R_me: Point<E, PrimeOrder>,
}

impl<'k, T: TranscriptProtocol, E: JubjubEngine> MuSig<T, CommitStage<'k, E>, E> {
/// Our commitment to our `R` to send to all other cosigners
pub fn our_commitment(&self) -> Commitment {
unimplemented!();
}

/// Add a new cosigner's public key and associated `R` bypassing our commiement phase.
pub fn add_thier_commitment(&mut self, them: PublicKey<E>, theirs: Commitment) -> Result<(), &'static str> {
unimplemented!();
}

/// Commit to reveal phase transition.
pub fn reveal_stage(self) -> MuSig<T, RevealStage<'k, E>, E> {
unimplemented!();
}
}

/// Reveal stage for cosigner's `R` values
pub struct RevealStage<'k, E: JubjubEngine> {
keypair: &'k KeyPair<E>,
r_me: E::Fs,
R_me: Point<E, PrimeOrder>,
}

/// Revealed `R_i` values shared between cosigners during signing
pub struct Reveal(pub [u8; 32]);

impl<'k, T: TranscriptProtocol, E: JubjubEngine> MuSig<T, RevealStage<'k, E>, E> {
/// Reveal our `R` contribution to send to all other cosigners
pub fn our_reveal(&self) -> Reveal {
unimplemented!();
}
}

/// Final cosining stage collection
pub struct CosignStage<E: JubjubEngine> {
/// Collective `R` value
R: Point<E, PrimeOrder>,
/// Our `s` contribution
s_me: E::Fs,
}

/// Cosignatures shared between cosigners
pub struct Cosignature(pub [u8; 32]);

impl<T: TranscriptProtocol, E: JubjubEngine> MuSig<T, CosignStage<E>, E> {
/// Reveals our signature contribution
pub fn our_cosignature(&self) -> Cosignature {
unimplemented!();
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_multi_sig() {

}
}
1 change: 0 additions & 1 deletion demo/wasm-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,3 @@ rev = "7a5b5fc99ae483a0043db7547fb79a6fa44b88a9"
[profile.release]
# Tell `rustc` to optimize for small code size.
opt-level = "s"