From dff77f54c522cdd6e1801052d916d35b15a65baf Mon Sep 17 00:00:00 2001 From: Osuke Sudo Date: Wed, 3 Apr 2019 10:15:52 +0900 Subject: [PATCH 1/2] init multisig --- core/musig/Cargo.toml | 11 +++++++++++ core/musig/src/lib.rs | 39 ++++++++++++++++++++++++++++++++++++++ demo/wasm-utils/Cargo.toml | 1 - 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 core/musig/Cargo.toml create mode 100644 core/musig/src/lib.rs diff --git a/core/musig/Cargo.toml b/core/musig/Cargo.toml new file mode 100644 index 00000000..1a403ded --- /dev/null +++ b/core/musig/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "musig" +version = "0.1.0" +authors = ["Osuke Sudo "] +edition = "2018" + +[dependencies] +jubjub = { path = "../jubjub" } +rand = { version = "0.6.0" } +failure = { version = "^0.1.1", default-features = false } +merlin = "0.1.0" diff --git a/core/musig/src/lib.rs b/core/musig/src/lib.rs new file mode 100644 index 00000000..406adb27 --- /dev/null +++ b/core/musig/src/lib.rs @@ -0,0 +1,39 @@ + + +const COMMITMENT_SIZE: usize = 32; + +pub struct Commitment(pub [u8; COMMITMENT_SIZE]); + +impl Commitment { + fn for_r() -> Commitment { + unimplemented!(); + } +} + +enum CoR { + Commit(Commitment), + Reveal{ R: } +} + +impl CoR { + fn set_revealsed(&mut self) { + + } + + +} + +pub struct MuSig { + t: T, + stage: S +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_multi_sig() { + + } +} \ No newline at end of file diff --git a/demo/wasm-utils/Cargo.toml b/demo/wasm-utils/Cargo.toml index 0b9f7325..857f598a 100644 --- a/demo/wasm-utils/Cargo.toml +++ b/demo/wasm-utils/Cargo.toml @@ -55,4 +55,3 @@ rev = "7a5b5fc99ae483a0043db7547fb79a6fa44b88a9" [profile.release] # Tell `rustc` to optimize for small code size. opt-level = "s" - From ec4701c3ef85ea663daee636676220b62bd623c4 Mon Sep 17 00:00:00 2001 From: Osuke Sudo Date: Wed, 3 Apr 2019 19:50:33 +0900 Subject: [PATCH 2/2] Init musig for jubjub --- Cargo.lock | 10 ++++ Cargo.toml | 7 +-- core/musig/Cargo.toml | 2 +- core/musig/src/lib.rs | 113 ++++++++++++++++++++++++++++++++++++++---- 4 files changed, 119 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 89b60a4b..b6c7330f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1815,6 +1815,16 @@ dependencies = [ "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "musig" +version = "0.1.0" +dependencies = [ + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "jubjub 0.1.0", + "merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "names" version = "0.11.0" diff --git a/Cargo.toml b/Cargo.toml index fc915f99..e2e8493d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", ] \ No newline at end of file diff --git a/core/musig/Cargo.toml b/core/musig/Cargo.toml index 1a403ded..fb304c01 100644 --- a/core/musig/Cargo.toml +++ b/core/musig/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" jubjub = { path = "../jubjub" } rand = { version = "0.6.0" } failure = { version = "^0.1.1", default-features = false } -merlin = "0.1.0" +merlin = "1" diff --git a/core/musig/src/lib.rs b/core/musig/src/lib.rs index 406adb27..ac8c84af 100644 --- a/core/musig/src/lib.rs +++ b/core/musig/src/lib.rs @@ -1,4 +1,25 @@ +// 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; @@ -10,30 +31,104 @@ impl Commitment { } } -enum CoR { - Commit(Commitment), - Reveal{ R: } +pub struct KeyPair { + pub secret: PrivateKey, + pub public: PublicKey, } -impl CoR { - fn set_revealsed(&mut self) { +enum CoR { + Commit(Commitment), // H(R_i) + Reveal{ R: Point}, // R_i + Cosigned { s: E::Fs }, // s_i extracted from Cosignature type + Collect { R: Point, s: E::Fs }, +} +impl CoR { + fn set_revealsed(&mut self) { + unimplemented!(); } - + fn set_cosigned(&mut self, s: E::Fs) -> Result<(), &'static str> { + unimplemented!(); + } } -pub struct MuSig { +/// Schnorr multi-signature (MuSig) container generic over its session types +pub struct MuSig { t: T, + Rs: BTreeMap, CoR>, stage: S } +impl MuSig { + +} + +/// Commitment stage for cosigner's `R` values +pub struct CommitStage<'k, E: JubjubEngine> { + keypair: &'k KeyPair, + r_me: E::Fs, + R_me: Point, +} + +impl<'k, T: TranscriptProtocol, E: JubjubEngine> MuSig, 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, theirs: Commitment) -> Result<(), &'static str> { + unimplemented!(); + } + + /// Commit to reveal phase transition. + pub fn reveal_stage(self) -> MuSig, E> { + unimplemented!(); + } +} + +/// Reveal stage for cosigner's `R` values +pub struct RevealStage<'k, E: JubjubEngine> { + keypair: &'k KeyPair, + r_me: E::Fs, + R_me: Point, +} + +/// Revealed `R_i` values shared between cosigners during signing +pub struct Reveal(pub [u8; 32]); + +impl<'k, T: TranscriptProtocol, E: JubjubEngine> MuSig, 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 { + /// Collective `R` value + R: Point, + /// Our `s` contribution + s_me: E::Fs, +} + +/// Cosignatures shared between cosigners +pub struct Cosignature(pub [u8; 32]); + +impl MuSig, E> { + /// Reveals our signature contribution + pub fn our_cosignature(&self) -> Cosignature { + unimplemented!(); + } +} + #[cfg(test)] mod tests { use super::*; #[test] fn test_multi_sig() { - + } -} \ No newline at end of file +}