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 new file mode 100644 index 00000000..fb304c01 --- /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 = "1" diff --git a/core/musig/src/lib.rs b/core/musig/src/lib.rs new file mode 100644 index 00000000..ac8c84af --- /dev/null +++ b/core/musig/src/lib.rs @@ -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 { + pub secret: PrivateKey, + pub public: PublicKey, +} + +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!(); + } +} + +/// 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() { + + } +} 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" -