aboutsummaryrefslogtreecommitdiff
path: root/src/multisig
diff options
context:
space:
mode:
authornaughtyfox <mail.for.milo@gmail.com>2018-07-12 12:55:52 +0300
committernaughtyfox <mail.for.milo@gmail.com>2018-10-01 19:16:56 +0300
commit9f3963e8235826704b7bc6ef9e3b90613a72e16c (patch)
tree303e65a2dcbaf40520e68d11cdcb7efcb41cff57 /src/multisig
parentMerge pull request #4423 (diff)
downloadmonero-9f3963e8235826704b7bc6ef9e3b90613a72e16c.tar.xz
Arbitrary M/N multisig schemes:
* support in wallet2 * support in monero-wallet-cli * support in monero-wallet-rpc * support in wallet api * support in monero-gen-trusted-multisig * unit tests for multisig wallets creation
Diffstat (limited to 'src/multisig')
-rw-r--r--src/multisig/multisig.cpp44
-rw-r--r--src/multisig/multisig.h24
2 files changed, 66 insertions, 2 deletions
diff --git a/src/multisig/multisig.cpp b/src/multisig/multisig.cpp
index a0a788b7d..33d0a312f 100644
--- a/src/multisig/multisig.cpp
+++ b/src/multisig/multisig.cpp
@@ -84,6 +84,43 @@ namespace cryptonote
}
}
//-----------------------------------------------------------------
+ std::vector<crypto::public_key> generate_multisig_derivations(const account_keys &keys, const std::vector<crypto::public_key> &derivations)
+ {
+ std::vector<crypto::public_key> multisig_keys;
+ crypto::secret_key blinded_skey = get_multisig_blinded_secret_key(keys.m_spend_secret_key);
+ for (const auto &k: derivations)
+ {
+ rct::key d = rct::scalarmultKey(rct::pk2rct(k), rct::sk2rct(blinded_skey));
+ multisig_keys.push_back(rct::rct2pk(d));
+ }
+
+ return multisig_keys;
+ }
+ //-----------------------------------------------------------------
+ crypto::secret_key calculate_multisig_signer_key(const std::vector<crypto::secret_key>& multisig_keys)
+ {
+ rct::key secret_key = rct::zero();
+ for (const auto &k: multisig_keys)
+ {
+ sc_add(secret_key.bytes, secret_key.bytes, (const unsigned char*)k.data);
+ }
+
+ return rct::rct2sk(secret_key);
+ }
+ //-----------------------------------------------------------------
+ std::vector<crypto::secret_key> calculate_multisig_keys(const std::vector<crypto::public_key>& derivations)
+ {
+ std::vector<crypto::secret_key> multisig_keys;
+ multisig_keys.reserve(derivations.size());
+
+ for (const auto &k: derivations)
+ {
+ multisig_keys.emplace_back(get_multisig_blinded_secret_key(rct::rct2sk(rct::pk2rct(k))));
+ }
+
+ return multisig_keys;
+ }
+ //-----------------------------------------------------------------
crypto::secret_key generate_multisig_view_secret_key(const crypto::secret_key &skey, const std::vector<crypto::secret_key> &skeys)
{
rct::key view_skey = rct::sk2rct(get_multisig_blinded_secret_key(skey));
@@ -92,7 +129,7 @@ namespace cryptonote
return rct::rct2sk(view_skey);
}
//-----------------------------------------------------------------
- crypto::public_key generate_multisig_N1_N_spend_public_key(const std::vector<crypto::public_key> &pkeys)
+ crypto::public_key generate_multisig_M_N_spend_public_key(const std::vector<crypto::public_key> &pkeys)
{
rct::key spend_public_key = rct::identity();
for (const auto &pk: pkeys)
@@ -141,4 +178,9 @@ namespace cryptonote
return true;
}
//-----------------------------------------------------------------
+ uint32_t multisig_rounds_required(uint32_t participants, uint32_t threshold)
+ {
+ CHECK_AND_ASSERT_THROW_MES(participants >= threshold, "participants must be greater or equal than threshold");
+ return participants - threshold + 1;
+ }
}
diff --git a/src/multisig/multisig.h b/src/multisig/multisig.h
index f95611441..93a756812 100644
--- a/src/multisig/multisig.h
+++ b/src/multisig/multisig.h
@@ -41,9 +41,31 @@ namespace cryptonote
crypto::secret_key get_multisig_blinded_secret_key(const crypto::secret_key &key);
void generate_multisig_N_N(const account_keys &keys, const std::vector<crypto::public_key> &spend_keys, std::vector<crypto::secret_key> &multisig_keys, rct::key &spend_skey, rct::key &spend_pkey);
void generate_multisig_N1_N(const account_keys &keys, const std::vector<crypto::public_key> &spend_keys, std::vector<crypto::secret_key> &multisig_keys, rct::key &spend_skey, rct::key &spend_pkey);
+ /**
+ * @brief generate_multisig_derivations performs common DH key derivation.
+ * Each middle round in M/N scheme is DH exchange of public multisig keys of other participants multiplied by secret spend key of current participant.
+ * this functions does the following: new multisig key = secret spend * public multisig key
+ * @param keys - current wallet's keys
+ * @param derivations - public multisig keys of other participants
+ * @return new public multisig keys derived from previous round. This data needs to be exchange with other participants
+ */
+ std::vector<crypto::public_key> generate_multisig_derivations(const account_keys &keys, const std::vector<crypto::public_key> &derivations);
+ crypto::secret_key calculate_multisig_signer_key(const std::vector<crypto::secret_key>& derivations);
+ /**
+ * @brief calculate_multisig_keys. Calculates secret multisig keys from others' participants ones as follows: mi = H(Mi)
+ * @param derivations - others' participants public multisig keys.
+ * @return vector of current wallet's multisig secret keys
+ */
+ std::vector<crypto::secret_key> calculate_multisig_keys(const std::vector<crypto::public_key>& derivations);
crypto::secret_key generate_multisig_view_secret_key(const crypto::secret_key &skey, const std::vector<crypto::secret_key> &skeys);
- crypto::public_key generate_multisig_N1_N_spend_public_key(const std::vector<crypto::public_key> &pkeys);
+ /**
+ * @brief generate_multisig_M_N_spend_public_key calculates multisig wallet's spend public key by summing all of public multisig keys
+ * @param pkeys unique public multisig keys
+ * @return multisig wallet's spend public key
+ */
+ crypto::public_key generate_multisig_M_N_spend_public_key(const std::vector<crypto::public_key> &pkeys);
bool generate_multisig_key_image(const account_keys &keys, size_t multisig_key_index, const crypto::public_key& out_key, crypto::key_image& ki);
void generate_multisig_LR(const crypto::public_key pkey, const crypto::secret_key &k, crypto::public_key &L, crypto::public_key &R);
bool generate_multisig_composite_key_image(const account_keys &keys, const std::unordered_map<crypto::public_key, cryptonote::subaddress_index>& subaddresses, const crypto::public_key& out_key, const crypto::public_key &tx_public_key, const std::vector<crypto::public_key>& additional_tx_public_keys, size_t real_output_index, const std::vector<crypto::key_image> &pkis, crypto::key_image &ki);
+ uint32_t multisig_rounds_required(uint32_t participants, uint32_t threshold);
}