2016-05-13 19:45:20 +00:00
|
|
|
// Copyright (c) 2016, Monero Research Labs
|
|
|
|
//
|
|
|
|
// Author: Shen Noether <shen.noether@gmx.com>
|
|
|
|
//
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without modification, are
|
|
|
|
// permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// 1. Redistributions of source code must retain the above copyright notice, this list of
|
|
|
|
// conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
|
|
|
// of conditions and the following disclaimer in the documentation and/or other
|
|
|
|
// materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// 3. Neither the name of the copyright holder nor the names of its contributors may be
|
|
|
|
// used to endorse or promote products derived from this software without specific
|
|
|
|
// prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
|
|
|
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
//#define DBG
|
|
|
|
|
|
|
|
#ifndef RCTSIGS_H
|
|
|
|
#define RCTSIGS_H
|
|
|
|
|
|
|
|
#include <cstddef>
|
|
|
|
#include <vector>
|
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
#include "crypto/generic-ops.h"
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include "crypto/random.h"
|
|
|
|
#include "crypto/keccak.h"
|
|
|
|
}
|
|
|
|
#include "crypto/crypto.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "rctTypes.h"
|
|
|
|
#include "rctOps.h"
|
|
|
|
|
|
|
|
//Define this flag when debugging to get additional info on the console
|
|
|
|
#ifdef DBG
|
|
|
|
#define DP(x) dp(x)
|
|
|
|
#else
|
|
|
|
#define DP(x)
|
|
|
|
#endif
|
|
|
|
|
2018-03-05 07:16:30 +00:00
|
|
|
namespace hw {
|
|
|
|
class device;
|
|
|
|
}
|
2016-05-13 19:45:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace rct {
|
|
|
|
|
2016-11-17 23:17:21 +00:00
|
|
|
boroSig genBorromean(const key64 x, const key64 P1, const key64 P2, const bits indices);
|
|
|
|
bool verifyBorromean(const boroSig &bb, const key64 P1, const key64 P2);
|
2016-05-13 19:45:20 +00:00
|
|
|
|
|
|
|
//Multilayered Spontaneous Anonymous Group Signatures (MLSAG signatures)
|
|
|
|
//These are aka MG signatutes in earlier drafts of the ring ct paper
|
2018-06-23 19:15:29 +00:00
|
|
|
// c.f. https://eprint.iacr.org/2015/1098 section 2.
|
2016-05-13 19:45:20 +00:00
|
|
|
// Gen creates a signature which proves that for some column in the keymatrix "pk"
|
|
|
|
// the signer knows a secret key for each row in that column
|
|
|
|
// Ver verifies that the MG sig was created correctly
|
2018-02-20 16:01:27 +00:00
|
|
|
mgSig MLSAG_Gen(const key &message, const keyM & pk, const keyV & xx, const multisig_kLRki *kLRki, key *mscout, const unsigned int index, size_t dsRows, hw::device &hwdev);
|
2016-10-08 21:16:23 +00:00
|
|
|
bool MLSAG_Ver(const key &message, const keyM &pk, const mgSig &sig, size_t dsRows);
|
2016-05-13 19:45:20 +00:00
|
|
|
//mgSig MLSAG_Gen_Old(const keyM & pk, const keyV & xx, const int index);
|
|
|
|
|
|
|
|
//proveRange and verRange
|
|
|
|
//proveRange gives C, and mask such that \sumCi = C
|
2018-06-23 19:15:29 +00:00
|
|
|
// c.f. https://eprint.iacr.org/2015/1098 section 5.1
|
2016-05-13 19:45:20 +00:00
|
|
|
// and Ci is a commitment to either 0 or 2^i, i=0,...,63
|
|
|
|
// thus this proves that "amount" is in [0, 2^64]
|
|
|
|
// mask is a such that C = aG + bH, and b = amount
|
|
|
|
//verRange verifies that \sum Ci = C and that each Ci is a commitment to 0 or 2^i
|
|
|
|
rangeSig proveRange(key & C, key & mask, const xmr_amount & amount);
|
2016-05-14 20:58:31 +00:00
|
|
|
bool verRange(const key & C, const rangeSig & as);
|
2016-05-13 19:45:20 +00:00
|
|
|
|
|
|
|
//Ring-ct MG sigs
|
|
|
|
//Prove:
|
2018-06-23 19:15:29 +00:00
|
|
|
// c.f. https://eprint.iacr.org/2015/1098 section 4. definition 10.
|
2016-05-13 19:45:20 +00:00
|
|
|
// This does the MG sig on the "dest" part of the given key matrix, and
|
|
|
|
// the last row is the sum of input commitments from that column - sum output commitments
|
|
|
|
// this shows that sum inputs = sum outputs
|
|
|
|
//Ver:
|
|
|
|
// verifies the above sig is created corretly
|
2018-02-20 16:01:27 +00:00
|
|
|
mgSig proveRctMG(const ctkeyM & pubs, const ctkeyV & inSk, const keyV &outMasks, const ctkeyV & outPk, const multisig_kLRki *kLRki, key *mscout, unsigned int index, key txnFee, const key &message, hw::device &hwdev);
|
|
|
|
mgSig proveRctMGSimple(const key & message, const ctkeyV & pubs, const ctkey & inSk, const key &a , const key &Cout, const multisig_kLRki *kLRki, key *mscout, unsigned int index, hw::device &hwdev);
|
2016-08-27 21:20:45 +00:00
|
|
|
bool verRctMG(const mgSig &mg, const ctkeyM & pubs, const ctkeyV & outPk, key txnFee, const key &message);
|
2016-08-09 10:38:54 +00:00
|
|
|
bool verRctMGSimple(const key &message, const mgSig &mg, const ctkeyV & pubs, const key & C);
|
2016-05-13 19:45:20 +00:00
|
|
|
|
|
|
|
//These functions get keys from blockchain
|
|
|
|
//replace these when connecting blockchain
|
|
|
|
//getKeyFromBlockchain grabs a key from the blockchain at "reference_index" to mix with
|
|
|
|
//populateFromBlockchain creates a keymatrix with "mixin" columns and one of the columns is inPk
|
|
|
|
// the return value are the key matrix, and the index where inPk was put (random).
|
|
|
|
void getKeyFromBlockchain(ctkey & a, size_t reference_index);
|
2017-10-10 14:47:08 +00:00
|
|
|
std::tuple<ctkeyM, xmr_amount> populateFromBlockchain(ctkeyV inPk, int mixin);
|
2016-05-13 19:45:20 +00:00
|
|
|
|
|
|
|
//RingCT protocol
|
|
|
|
//genRct:
|
|
|
|
// creates an rctSig with all data necessary to verify the rangeProofs and that the signer owns one of the
|
|
|
|
// columns that are claimed as inputs, and that the sum of inputs = sum of outputs.
|
|
|
|
// Also contains masked "amount" and "mask" so the receiver can see how much they received
|
|
|
|
//verRct:
|
|
|
|
// verifies that all signatures (rangeProogs, MG sig, sum inputs = outputs) are correct
|
2018-06-23 19:15:29 +00:00
|
|
|
//decodeRct: (c.f. https://eprint.iacr.org/2015/1098 section 5.1.1)
|
2016-05-13 19:45:20 +00:00
|
|
|
// uses the attached ecdh info to find the amounts represented by each output commitment
|
|
|
|
// must know the destination private key to find the correct amount, else will return a random number
|
2018-01-17 21:50:03 +00:00
|
|
|
rctSig genRct(const key &message, const ctkeyV & inSk, const keyV & destinations, const std::vector<xmr_amount> & amounts, const ctkeyM &mixRing, const keyV &amount_keys, const multisig_kLRki *kLRki, multisig_out *msout, unsigned int index, ctkeyV &outSk, RangeProofType range_proof_type, hw::device &hwdev);
|
2018-02-20 16:01:27 +00:00
|
|
|
rctSig genRct(const key &message, const ctkeyV & inSk, const ctkeyV & inPk, const keyV & destinations, const std::vector<xmr_amount> & amounts, const keyV &amount_keys, const multisig_kLRki *kLRki, multisig_out *msout, const int mixin, hw::device &hwdev);
|
|
|
|
rctSig genRctSimple(const key & message, const ctkeyV & inSk, const ctkeyV & inPk, const keyV & destinations, const std::vector<xmr_amount> & inamounts, const std::vector<xmr_amount> & outamounts, const keyV &amount_keys, const std::vector<multisig_kLRki> *kLRki, multisig_out *msout, xmr_amount txnFee, unsigned int mixin, hw::device &hwdev);
|
2018-01-17 21:50:03 +00:00
|
|
|
rctSig genRctSimple(const key & message, const ctkeyV & inSk, const keyV & destinations, const std::vector<xmr_amount> & inamounts, const std::vector<xmr_amount> & outamounts, xmr_amount txnFee, const ctkeyM & mixRing, const keyV &amount_keys, const std::vector<multisig_kLRki> *kLRki, multisig_out *msout, const std::vector<unsigned int> & index, ctkeyV &outSk, RangeProofType range_proof_type, hw::device &hwdev);
|
2017-01-14 13:29:08 +00:00
|
|
|
bool verRct(const rctSig & rv, bool semantics);
|
|
|
|
static inline bool verRct(const rctSig & rv) { return verRct(rv, true) && verRct(rv, false); }
|
2018-02-03 14:36:29 +00:00
|
|
|
bool verRctSemanticsSimple(const rctSig & rv);
|
|
|
|
bool verRctSemanticsSimple(const std::vector<const rctSig*> & rv);
|
|
|
|
bool verRctNonSemanticsSimple(const rctSig & rv);
|
|
|
|
static inline bool verRctSimple(const rctSig & rv) { return verRctSemanticsSimple(rv) && verRctNonSemanticsSimple(rv); }
|
2018-02-20 16:01:27 +00:00
|
|
|
xmr_amount decodeRct(const rctSig & rv, const key & sk, unsigned int i, key & mask, hw::device &hwdev);
|
|
|
|
xmr_amount decodeRct(const rctSig & rv, const key & sk, unsigned int i, hw::device &hwdev);
|
|
|
|
xmr_amount decodeRctSimple(const rctSig & rv, const key & sk, unsigned int i, key & mask, hw::device &hwdev);
|
|
|
|
xmr_amount decodeRctSimple(const rctSig & rv, const key & sk, unsigned int i, hw::device &hwdev);
|
Add N/N multisig tx generation and signing
Scheme by luigi1111:
Multisig for RingCT on Monero
2 of 2
User A (coordinator):
Spendkey b,B
Viewkey a,A (shared)
User B:
Spendkey c,C
Viewkey a,A (shared)
Public Address: C+B, A
Both have their own watch only wallet via C+B, a
A will coordinate spending process (though B could easily as well, coordinator is more needed for more participants)
A and B watch for incoming outputs
B creates "half" key images for discovered output D:
I2_D = (Hs(aR)+c) * Hp(D)
B also creates 1.5 random keypairs (one scalar and 2 pubkeys; one on base G and one on base Hp(D)) for each output, storing the scalar(k) (linked to D),
and sending the pubkeys with I2_D.
A also creates "half" key images:
I1_D = (Hs(aR)+b) * Hp(D)
Then I_D = I1_D + I2_D
Having I_D allows A to check spent status of course, but more importantly allows A to actually build a transaction prefix (and thus transaction).
A builds the transaction until most of the way through MLSAG_Gen, adding the 2 pubkeys (per input) provided with I2_D
to his own generated ones where they are needed (secret row L, R).
At this point, A has a mostly completed transaction (but with an invalid/incomplete signature). A sends over the tx and includes r,
which allows B (with the recipient's address) to verify the destination and amount (by reconstructing the stealth address and decoding ecdhInfo).
B then finishes the signature by computing ss[secret_index][0] = ss[secret_index][0] + k - cc[secret_index]*c (secret indices need to be passed as well).
B can then broadcast the tx, or send it back to A for broadcasting. Once B has completed the signing (and verified the tx to be valid), he can add the full I_D
to his cache, allowing him to verify spent status as well.
NOTE:
A and B *must* present key A and B to each other with a valid signature proving they know a and b respectively.
Otherwise, trickery like the following becomes possible:
A creates viewkey a,A, spendkey b,B, and sends a,A,B to B.
B creates a fake key C = zG - B. B sends C back to A.
The combined spendkey C+B then equals zG, allowing B to spend funds at any time!
The signature fixes this, because B does not know a c corresponding to C (and thus can't produce a signature).
2 of 3
User A (coordinator)
Shared viewkey a,A
"spendkey" j,J
User B
"spendkey" k,K
User C
"spendkey" m,M
A collects K and M from B and C
B collects J and M from A and C
C collects J and K from A and B
A computes N = nG, n = Hs(jK)
A computes O = oG, o = Hs(jM)
B anc C compute P = pG, p = Hs(kM) || Hs(mK)
B and C can also compute N and O respectively if they wish to be able to coordinate
Address: N+O+P, A
The rest follows as above. The coordinator possesses 2 of 3 needed keys; he can get the other
needed part of the signature/key images from either of the other two.
Alternatively, if secure communication exists between parties:
A gives j to B
B gives k to C
C gives m to A
Address: J+K+M, A
3 of 3
Identical to 2 of 2, except the coordinator must collect the key images from both of the others.
The transaction must also be passed an additional hop: A -> B -> C (or A -> C -> B), who can then broadcast it
or send it back to A.
N-1 of N
Generally the same as 2 of 3, except participants need to be arranged in a ring to pass their keys around
(using either the secure or insecure method).
For example (ignoring viewkey so letters line up):
[4 of 5]
User: spendkey
A: a
B: b
C: c
D: d
E: e
a -> B, b -> C, c -> D, d -> E, e -> A
Order of signing does not matter, it just must reach n-1 users. A "remaining keys" list must be passed around with
the transaction so the signers know if they should use 1 or both keys.
Collecting key image parts becomes a little messy, but basically every wallet sends over both of their parts with a tag for each.
Thia way the coordinating wallet can keep track of which images have been added and which wallet they come from. Reasoning:
1. The key images must be added only once (coordinator will get key images for key a from both A and B, he must add only one to get the proper key actual key image)
2. The coordinator must keep track of which helper pubkeys came from which wallet (discussed in 2 of 2 section). The coordinator
must choose only one set to use, then include his choice in the "remaining keys" list so the other wallets know which of their keys to use.
You can generalize it further to N-2 of N or even M of N, but I'm not sure there's legitimate demand to justify the complexity. It might
also be straightforward enough to support with minimal changes from N-1 format.
You basically just give each user additional keys for each additional "-1" you desire. N-2 would be 3 keys per user, N-3 4 keys, etc.
The process is somewhat cumbersome:
To create a N/N multisig wallet:
- each participant creates a normal wallet
- each participant runs "prepare_multisig", and sends the resulting string to every other participant
- each participant runs "make_multisig N A B C D...", with N being the threshold and A B C D... being the strings received from other participants (the threshold must currently equal N)
As txes are received, participants' wallets will need to synchronize so that those new outputs may be spent:
- each participant runs "export_multisig FILENAME", and sends the FILENAME file to every other participant
- each participant runs "import_multisig A B C D...", with A B C D... being the filenames received from other participants
Then, a transaction may be initiated:
- one of the participants runs "transfer ADDRESS AMOUNT"
- this partly signed transaction will be written to the "multisig_monero_tx" file
- the initiator sends this file to another participant
- that other participant runs "sign_multisig multisig_monero_tx"
- the resulting transaction is written to the "multisig_monero_tx" file again
- if the threshold was not reached, the file must be sent to another participant, until enough have signed
- the last participant to sign runs "submit_multisig multisig_monero_tx" to relay the transaction to the Monero network
2017-06-03 21:34:26 +00:00
|
|
|
|
|
|
|
bool signMultisig(rctSig &rv, const std::vector<unsigned int> &indices, const keyV &k, const multisig_out &msout, const key &secret_key);
|
2016-05-13 19:45:20 +00:00
|
|
|
}
|
|
|
|
#endif /* RCTSIGS_H */
|
|
|
|
|