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

Remove dependency on curv in multisig #1819

Merged
merged 6 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
270 changes: 27 additions & 243 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ lazy_static = "1.4"
parking_lot = "0.12"
regex = "1"
reqwest = {version = "0.11.4", features = ["json"]}
secp256k1 = "0.20"
secp256k1 = {version = "0.20", features = ["serde", "rand-std", "global-context"]}
serde = {version = "1.0", features = ["derive", "rc"]}
serde_json = "1.0"
sha2 = "0.9.5"
Expand All @@ -58,6 +58,8 @@ thiserror = "1.0.26"
tokio = {version = "1.13.1", features = ["full"]}
tokio-stream = "0.1.5"
url = "1.7.2"
num-bigint = "0.4"
num-traits = "0.2"
web3 = {git = 'https://github.com/tomusdrw/rust-web3.git', rev = '8796c88', features = ['signing']}
zeroize = "1.5.4"
libp2p = "0.40"
Expand Down Expand Up @@ -149,9 +151,6 @@ tag = 'chainflip-monthly-2022-05'
git = 'https://github.com/chainflip-io/substrate.git'
tag = 'chainflip-monthly-2022-05'

[dependencies.curv-kzen]
version = "0.9"

[dev-dependencies]
env_logger = "0.9.0"
jsonrpc-pubsub = "18.0.0"
Expand Down
2 changes: 1 addition & 1 deletion engine/src/multisig/client/keygen/keygen_frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn generate_dkg_challenge<P: ECPoint>(

let x: [u8; 32] = result.as_slice().try_into().expect("Invalid hash size");

P::Scalar::from_bytes(&x)
P::Scalar::from_bytes_mod_order(&x)
}

/// Generate ZKP (zero-knowledge proof) of `secret`
Expand Down
2 changes: 1 addition & 1 deletion engine/src/multisig/client/signing/frost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn gen_rho_i<P: ECPoint>(

let x: [u8; 32] = result.as_slice().try_into().expect("Invalid hash size");

P::Scalar::from_bytes(&x)
P::Scalar::from_bytes_mod_order(&x)
}

type SigningResponse<P> = LocalSig3<P>;
Expand Down
7 changes: 5 additions & 2 deletions engine/src/multisig/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pub mod secp255k1;

use generic_array::{typenum::Unsigned, ArrayLength};

pub use curv::{arithmetic::traits::Converter as BigIntConverter, BigInt};
use zeroize::{DefaultIsZeroes, ZeroizeOnDrop};

use std::fmt::Debug;
Expand Down Expand Up @@ -61,6 +60,10 @@ pub trait ECPoint:
}

// Only relevant for ETH contract keys
// TODO: this is a property of a signing scheme
// rather than the underlying curve, so this
// should be moved to `CryptoScheme` before we
j4m1ef0rd marked this conversation as resolved.
Show resolved Hide resolved
// Bitcoin or any other secp256k1 scheme
fn is_compatible(&self) -> bool {
true
}
Expand Down Expand Up @@ -117,7 +120,7 @@ pub trait ECScalar:
{
fn random(rng: &mut Rng) -> Self;

fn from_bytes(x: &[u8; 32]) -> Self;
fn from_bytes_mod_order(x: &[u8; 32]) -> Self;

fn zero() -> Self;

Expand Down
4 changes: 2 additions & 2 deletions engine/src/multisig/crypto/curve25519_ristretto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ mod point_impls {

mod scalar_impls {

use zeroize::{Zeroize, ZeroizeOnDrop};
use zeroize::Zeroize;

use super::*;

Expand All @@ -88,7 +88,7 @@ mod scalar_impls {
Scalar(SK::from_bytes_mod_order_wide(&scalar_bytes))
}

fn from_bytes(x: &[u8; 32]) -> Self {
fn from_bytes_mod_order(x: &[u8; 32]) -> Self {
Scalar(SK::from_bytes_mod_order(*x))
}

Expand Down
2 changes: 1 addition & 1 deletion engine/src/multisig/crypto/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl CryptoScheme for EthSigning {
&pubkey_to_eth_addr(nonce_commitment.get_element()),
);

Scalar::from_bytes(&e)
Scalar::from_bytes_mod_order(&e)
}

fn build_response(
Expand Down
3 changes: 2 additions & 1 deletion engine/src/multisig/crypto/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ macro_rules! derive_scalar_impls {

impl Drop for $scalar {
fn drop(&mut self) {
use zeroize::Zeroize;
self.zeroize();
}
}

impl ZeroizeOnDrop for $scalar {}
impl zeroize::ZeroizeOnDrop for $scalar {}

impl std::ops::Add for $scalar {
type Output = $scalar;
Expand Down
Loading