Duke
3 months ago
2 changed files with 8 additions and 752 deletions
@ -1,341 +0,0 @@ |
|||
// Copyright (c) 2016-2023 The Hush developers
|
|||
// Distributed under the GPLv3 software license, see the accompanying
|
|||
// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
|
|||
/******************************************************************************
|
|||
* Copyright © 2014-2019 The SuperNET Developers. * |
|||
* * |
|||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * |
|||
* the top-level directory of this distribution for the individual copyright * |
|||
* holder information and the developer policies on copyright and licensing. * |
|||
* * |
|||
* Unless otherwise agreed in a custom licensing agreement, no part of the * |
|||
* SuperNET software, including this file may be copied, modified, propagated * |
|||
* or distributed except according to the terms contained in the LICENSE file * |
|||
* * |
|||
* Removal or modification of this copyright notice is prohibited. * |
|||
* * |
|||
******************************************************************************/ |
|||
|
|||
/* first make a combined pk:
|
|||
|
|||
./hush-cli -ac_name=MUSIG cclib combine 18 '["02fb6aa0b96cad24d46b5da93eba3864c45ce07a73bba12da530ae841e140fcf28","0255c46dbce584e3751081b39d7fc054fc807100557e73fc444481618b5706afb4"]' |
|||
{ |
|||
"pkhash": "5cb5a225064ca6ffc1438cb2a6ac2ac65fe2d5055dc7f6c7ebffb9a231f8912b", |
|||
"combined_pk": "03f016c348437c7422eed92d865aa9789614f75327cada463eefc566126b54785b", |
|||
"result": "success" |
|||
} |
|||
|
|||
the combined_pk and pkhash will be needed for various other rpc calls |
|||
|
|||
second, send 1 coin to the combined_pk |
|||
./hush-cli -ac_name=MUSIG cclib send 18 '["03f016c348437c7422eed92d865aa9789614f75327cada463eefc566126b54785b",1]' |
|||
{ |
|||
"hex": "0400008085202f8901a980664dffc810725a79ffb89ac48be4c7b6bade9b789732fcf871acf8e81a2e010000006a47304402207e52763661ecd2c34a65d6623950be11794825db71576dc11894c606ddc317800220028fef46dc20630d0fdf22647b5d4ff0f1c47cf75f48702d0a91d5589eff99d001210255c46dbce584e3751081b39d7fc054fc807100557e73fc444481618b5706afb4ffffffff031008f60500000000302ea22c8020c71ddb3aac7f9b9e4bdacf032aaa8b8e4433c4ff9f8a43cebb9c1f5da96928a48103120c008203000401cce09aa4350000000023210255c46dbce584e3751081b39d7fc054fc807100557e73fc444481618b5706afb4ac0000000000000000266a2412782103f016c348437c7422eed92d865aa9789614f75327cada463eefc566126b54785b00000000920500000000000000000000000000", |
|||
"txid": "5ce74037a153ee210413b48d4e88638b99825a2de1a1f1aa0d36ebf93019824c", |
|||
"result": "success" |
|||
} |
|||
|
|||
sendrawtransaction of the above hex. |
|||
./hush-cli -ac_name=MUSIG getrawtransaction 5ce74037a153ee210413b48d4e88638b99825a2de1a1f1aa0d36ebf93019824c 1 |
|||
"vout": [ |
|||
{ |
|||
"value": 1.00010000, |
|||
"valueSat": 100010000, |
|||
"n": 0, |
|||
"scriptPubKey": { |
|||
"asm": "a22c8020c71ddb3aac7f9b9e4bdacf032aaa8b8e4433c4ff9f8a43cebb9c1f5da96928a48103120c008203000401 OP_CHECKCRYPTOCONDITION", |
|||
"hex": "2ea22c8020c71ddb3aac7f9b9e4bdacf032aaa8b8e4433c4ff9f8a43cebb9c1f5da96928a48103120c008203000401cc", |
|||
"reqSigs": 1, |
|||
"type": "cryptocondition", |
|||
"addresses": [ |
|||
"RKWS7jxyjPX9iaJttk8iMKf1AumanKypez" |
|||
] |
|||
} |
|||
}, |
|||
{ |
|||
"value": 8.99980000, |
|||
"valueSat": 899980000, |
|||
"n": 1, |
|||
"scriptPubKey": { |
|||
"asm": "0255c46dbce584e3751081b39d7fc054fc807100557e73fc444481618b5706afb4 OP_CHECKSIG", |
|||
"hex": "210255c46dbce584e3751081b39d7fc054fc807100557e73fc444481618b5706afb4ac", |
|||
"reqSigs": 1, |
|||
"type": "pubkey", |
|||
"addresses": [ |
|||
"RVQjvGdRbYLJ49bfH4SAFseipvwE3UdoDw" |
|||
] |
|||
} |
|||
|
|||
script: 210255c46dbce584e3751081b39d7fc054fc807100557e73fc444481618b5706afb4ac |
|||
|
|||
sendtxid: 5ce74037a153ee210413b48d4e88638b99825a2de1a1f1aa0d36ebf93019824c |
|||
|
|||
get the msg we need to sign: |
|||
|
|||
./hush-cli -ac_name=MUSIG cclib calcmsg 18 '["5ce74037a153ee210413b48d4e88638b99825a2de1a1f1aa0d36ebf93019824c","210255c46dbce584e3751081b39d7fc054fc807100557e73fc444481618b5706afb4ac"]' |
|||
|
|||
{ |
|||
"msg": "f7fb85d1412814e3c2f98b990802af6ee33dad368c6ba05c2050e9e5506fcd75", |
|||
"result": "success" |
|||
} |
|||
|
|||
the "msg" is what needs to be signed to create a valid spend |
|||
|
|||
now on each signing node, a session needs to be created: |
|||
5 args: ind, numsigners, combined_pk, pkhash, message to be signed |
|||
|
|||
on node with pubkey: 02fb6aa0b96cad24d46b5da93eba3864c45ce07a73bba12da530ae841e140fcf28 |
|||
./hush-cli -ac_name=MUSIG cclib session 18 '[0,2,"03f016c348437c7422eed92d865aa9789614f75327cada463eefc566126b54785b","5cb5a225064ca6ffc1438cb2a6ac2ac65fe2d5055dc7f6c7ebffb9a231f8912b","f7fb85d1412814e3c2f98b990802af6ee33dad368c6ba05c2050e9e5506fcd75"]' |
|||
{ |
|||
"myind": 0, |
|||
"numsigners": 2, |
|||
"commitment": "bbea1f2562eca01b9a1393c5dc188bdd44551aebf684f4459930f59dde01f7ae", |
|||
"result": "success" |
|||
} |
|||
|
|||
on node with pubkey: 0255c46dbce584e3751081b39d7fc054fc807100557e73fc444481618b5706afb4 |
|||
./hush-cli -ac_name=MUSIG cclib session 18 '[1,2,"03f016c348437c7422eed92d865aa9789614f75327cada463eefc566126b54785b","5cb5a225064ca6ffc1438cb2a6ac2ac65fe2d5055dc7f6c7ebffb9a231f8912b","f7fb85d1412814e3c2f98b990802af6ee33dad368c6ba05c2050e9e5506fcd75"]' |
|||
{ |
|||
"myind": 1, |
|||
"numsigners": 2, |
|||
"commitment": "c2291acb747a75b1a40014d8eb0cc90a1360f74d413f65f78e20a7de45eda851", |
|||
"result": "success" |
|||
} |
|||
|
|||
now we need to get the commitment from each node to the other one. the session already put the commitment for each node into the global struct. Keep in mind there is a single global struct with session unique to each cclib session call. that means no restarting any deamon in the middle of the process on any of the nodes and only call cclib session a single time. this is an artificial restriction just to simplify the initial implementation of musig |
|||
./hush-cli -ac_name=MUSIG cclib commit 18 '["5cb5a225064ca6ffc1438cb2a6ac2ac65fe2d5055dc7f6c7ebffb9a231f8912b","1","c2291acb747a75b1a40014d8eb0cc90a1360f74d413f65f78e20a7de45eda851"]' |
|||
{ |
|||
"added_index": 1, |
|||
"myind": 0, |
|||
"nonce": "02fec7a9310c959a0a97b86bc3f8c30d392d1fb51793915898c568f73f1f70476b", |
|||
"result": "success" |
|||
} |
|||
|
|||
./hush-cli -ac_name=MUSIG cclib commit 18 '["5cb5a225064ca6ffc1438cb2a6ac2ac65fe2d5055dc7f6c7ebffb9a231f8912b",0,"d242cff13fa8c9b83248e4219fda459ada146b885f2171481f1b0f66c66d94ad"]' |
|||
{ |
|||
"added_index": 0, |
|||
"myind": 1, |
|||
"nonce": "039365deaaaea089d509ba4c9f846de2baf4aa04cf6b26fa2c1cd818553e47f80c", |
|||
"result": "success" |
|||
} |
|||
|
|||
Now exchange the revealed nonces to each node: |
|||
./hush-cli -ac_name=MUSIG cclib nonce 18 '["5cb5a225064ca6ffc1438cb2a6ac2ac65fe2d5055dc7f6c7ebffb9a231f8912b","1","039365deaaaea089d509ba4c9f846de2baf4aa04cf6b26fa2c1cd818553e47f80c"]' |
|||
{ |
|||
"added_index": 1, |
|||
"myind": 0, |
|||
"partialsig": "1d65c09cd9bffe4f0604227e66cd7cd221480bbb08262fe885563a9df7cf8f5b", |
|||
"result": "success" |
|||
} |
|||
|
|||
./hush-cli -ac_name=MUSIG cclib nonce 18 '["5cb5a225064ca6ffc1438cb2a6ac2ac65fe2d5055dc7f6c7ebffb9a231f8912b",0,"02fec7a9310c959a0a97b86bc3f8c30d392d1fb51793915898c568f73f1f70476b"]' |
|||
{ |
|||
"added_index": 0, |
|||
"myind": 1, |
|||
"partialsig": "4a3795e6801b355102c617390cf5a462061e082e35dc2ed8f8b1fab54cc0769e", |
|||
"result": "success" |
|||
} |
|||
|
|||
Almost there! final step is to exchange the partial sigs between signers |
|||
./hush-cli -ac_name=MUSIG cclib partialsig 18 '["5cb5a225064ca6ffc1438cb2a6ac2ac65fe2d5055dc7f6c7ebffb9a231f8912b","1","4a3795e6801b355102c617390cf5a462061e082e35dc2ed8f8b1fab54cc0769e"]' |
|||
{ |
|||
"added_index": 1, |
|||
"result": "success", |
|||
"combinedsig": "a76f2790747ed2436a281f2660bdbee21bad9ee130b9cab6e542fa618fba1512679d568359db33a008ca39b773c32134276613e93e025ec17e083553449005f9" |
|||
} |
|||
|
|||
./hush-cli -ac_name=MUSIG cclib partialsig 18 '["5cb5a225064ca6ffc1438cb2a6ac2ac65fe2d5055dc7f6c7ebffb9a231f8912b",0,"1d65c09cd9bffe4f0604227e66cd7cd221480bbb08262fe885563a9df7cf8f5b"]' |
|||
{ |
|||
"added_index": 0, |
|||
"result": "success", |
|||
"combinedsig": "a76f2790747ed2436a281f2660bdbee21bad9ee130b9cab6e542fa618fba1512679d568359db33a008ca39b773c32134276613e93e025ec17e083553449005f9" |
|||
} |
|||
|
|||
Notice both nodes generated the same combined signature! |
|||
|
|||
Now for a sanity test, we can use the verify call to make sure this sig will work with the msg needed for the spend: |
|||
|
|||
./hush-cli -ac_name=MUSIG cclib verify 18 '["f7fb85d1412814e3c2f98b990802af6ee33dad368c6ba05c2050e9e5506fcd75","03f016c348437c7422eed92d865aa9789614f75327cada463eefc566126b54785b","a76f2790747ed2436a281f2660bdbee21bad9ee130b9cab6e542fa618fba1512679d568359db33a008ca39b773c32134276613e93e025ec17e083553449005f9"]' |
|||
{ |
|||
"msg": "f7fb85d1412814e3c2f98b990802af6ee33dad368c6ba05c2050e9e5506fcd75", |
|||
"combined_pk": "03f016c348437c7422eed92d865aa9789614f75327cada463eefc566126b54785b", |
|||
"combinedsig": "a76f2790747ed2436a281f2660bdbee21bad9ee130b9cab6e542fa618fba1512679d568359db33a008ca39b773c32134276613e93e025ec17e083553449005f9", |
|||
"result": "success" |
|||
} |
|||
|
|||
and finally the spend: sendtxid, scriptPubKey, musig |
|||
|
|||
./hush-cli -ac_name=MUSIG cclib spend 18 '["5ce74037a153ee210413b48d4e88638b99825a2de1a1f1aa0d36ebf93019824c","210255c46dbce584e3751081b39d7fc054fc807100557e73fc444481618b5706afb4ac","a76f2790747ed2436a281f2660bdbee21bad9ee130b9cab6e542fa618fba1512679d568359db33a008ca39b773c32134276613e93e025ec17e083553449005f9"]' |
|||
{ |
|||
"scriptpubkey": "210255c46dbce584e3751081b39d7fc054fc807100557e73fc444481618b5706afb4ac", |
|||
"msg": "f7fb85d1412814e3c2f98b990802af6ee33dad368c6ba05c2050e9e5506fcd75", |
|||
"combined_pk": "03f016c348437c7422eed92d865aa9789614f75327cada463eefc566126b54785b", |
|||
"combinedsig": "a76f2790747ed2436a281f2660bdbee21bad9ee130b9cab6e542fa618fba1512679d568359db33a008ca39b773c32134276613e93e025ec17e083553449005f9", |
|||
"hex": "0400008085202f89014c821930f9eb360daaf1a1e12d5a82998b63884e8db4130421ee53a13740e75c000000007b4c79a276a072a26ba067a5658021032d29d6545a2aafad795d9cf50912ecade549137 |
|||
163934dfb2895ebc0e211ce8a81409671a60db89b3bc58966f3acc80194479b1a43d868e95a11ebc5609646d18710341a8ff92a7817571980307f5d660cc00a2735ac6333e0a7191243f1263f1959a100af03800112 |
|||
a10001ffffffff0200e1f5050000000023210255c46dbce584e3751081b39d7fc054fc807100557e73fc444481618b5706afb4ac0000000000000000686a4c6512792103f016c348437c7422eed92d865aa9789614f |
|||
75327cada463eefc566126b54785b40a76f2790747ed2436a281f2660bdbee21bad9ee130b9cab6e542fa618fba1512679d568359db33a008ca39b773c32134276613e93e025ec17e083553449005f900000000a805 |
|||
00000000000000000000000000", |
|||
"txid": "910635bf69a047fc90567a83ff12e47b753f470658b6d0855ec96e07e7349a8a", |
|||
"result": "success" |
|||
} |
|||
*/ |
|||
|
|||
|
|||
#define USE_BASIC_CONFIG |
|||
#define ENABLE_MODULE_MUSIG |
|||
#include "../secp256k1/src/basic-config.h" |
|||
#include "../secp256k1/include/secp256k1.h" |
|||
#include "../secp256k1/src/ecmult.h" |
|||
#include "../secp256k1/src/ecmult_gen.h" |
|||
|
|||
typedef struct { unsigned char data[64]; } secp256k1_schnorrsig; |
|||
struct secp256k1_context_struct { |
|||
secp256k1_ecmult_context ecmult_ctx; |
|||
secp256k1_ecmult_gen_context ecmult_gen_ctx; |
|||
secp256k1_callback illegal_callback; |
|||
secp256k1_callback error_callback; |
|||
}; |
|||
|
|||
|
|||
//#include "../secp256k1/include/secp256k1.h"
|
|||
//#include "../secp256k1/include/secp256k1_schnorrsig.h"
|
|||
#include "../secp256k1/include/secp256k1_musig.h" |
|||
|
|||
#define MUSIG_PREVN 0 // for now, just use vout0 for the musig output
|
|||
#define MUSIG_TXFEE 10000 |
|||
|
|||
struct musig_info |
|||
{ |
|||
secp256k1_musig_session session; |
|||
secp256k1_pubkey combined_pk; |
|||
uint8_t *nonce_commitments,**commitment_ptrs; // 32*N_SIGNERS
|
|||
secp256k1_musig_session_signer_data *signer_data; //[N_SIGNERS];
|
|||
secp256k1_pubkey *nonces; //[N_SIGNERS];
|
|||
secp256k1_musig_partial_signature *partial_sig; //[N_SIGNERS];
|
|||
int32_t myind,num,numcommits,numnonces,numpartials; |
|||
uint8_t msg[32],pkhash[32],combpk[33]; |
|||
}; |
|||
|
|||
std::vector <struct musig_info *> MUSIG; |
|||
|
|||
struct musig_info *musig_infocreate(int32_t myind,int32_t num) |
|||
{ |
|||
int32_t i; struct musig_info *mp = (struct musig_info *)calloc(1,sizeof(*mp)); |
|||
mp->myind = myind, mp->num = num; |
|||
mp->nonce_commitments = (uint8_t *)calloc(num,32); |
|||
mp->commitment_ptrs = (uint8_t **)calloc(num,sizeof(*mp->commitment_ptrs)); |
|||
for (i=0; i<num; i++) |
|||
mp->commitment_ptrs[i] = &mp->nonce_commitments[i*32]; |
|||
mp->signer_data = (secp256k1_musig_session_signer_data *)calloc(num,sizeof(*mp->signer_data)); |
|||
mp->nonces = (secp256k1_pubkey *)calloc(num,sizeof(*mp->nonces)); |
|||
mp->partial_sig = (secp256k1_musig_partial_signature *)calloc(num,sizeof(*mp->partial_sig)); |
|||
return(mp); |
|||
} |
|||
|
|||
void musig_infofree(struct musig_info *mp) |
|||
{ |
|||
} |
|||
|
|||
CScript musig_sendopret(uint8_t funcid,CPubKey pk) |
|||
{ |
|||
CScript opret; |
|||
return(opret); |
|||
} |
|||
|
|||
uint8_t musig_sendopretdecode(CPubKey &pk,CScript scriptPubKey) |
|||
{ |
|||
return(0); |
|||
} |
|||
|
|||
CScript musig_spendopret(uint8_t funcid,CPubKey pk,std::vector<uint8_t> musig64) |
|||
{ |
|||
CScript opret; |
|||
return(opret); |
|||
} |
|||
|
|||
uint8_t musig_spendopretdecode(CPubKey &pk,std::vector<uint8_t> &musig64,CScript scriptPubKey) |
|||
{ |
|||
return(0); |
|||
} |
|||
|
|||
int32_t musig_parsepubkey(secp256k1_context *ctx,secp256k1_pubkey &spk,cJSON *item) |
|||
{ |
|||
return -1; |
|||
} |
|||
|
|||
int32_t musig_msghash(uint8_t *msg,uint256 prevhash,int32_t prevn,CTxOut vout,CPubKey pk) |
|||
{ |
|||
return(0); |
|||
} |
|||
|
|||
int32_t musig_prevoutmsg(uint8_t *msg,uint256 sendtxid,CScript scriptPubKey) |
|||
{ |
|||
return(-1); |
|||
} |
|||
|
|||
UniValue musig_calcmsg(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|||
{ |
|||
UniValue result(UniValue::VOBJ); |
|||
return result; |
|||
} |
|||
|
|||
UniValue musig_combine(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|||
{ |
|||
UniValue result(UniValue::VOBJ); |
|||
return result; |
|||
} |
|||
|
|||
UniValue musig_session(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|||
{ |
|||
UniValue result(UniValue::VOBJ); |
|||
return result; |
|||
} |
|||
|
|||
UniValue musig_commit(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|||
{ |
|||
UniValue result(UniValue::VOBJ); |
|||
return result; |
|||
} |
|||
|
|||
UniValue musig_nonce(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|||
{ |
|||
UniValue result(UniValue::VOBJ); |
|||
return result; |
|||
} |
|||
|
|||
UniValue musig_partialsig(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|||
{ |
|||
UniValue result(UniValue::VOBJ); |
|||
return result; |
|||
} |
|||
|
|||
//int testmain(void);
|
|||
UniValue musig_verify(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|||
{ |
|||
UniValue result(UniValue::VOBJ); |
|||
return result; |
|||
} |
|||
|
|||
UniValue musig_rawtxresult(UniValue &result,std::string rawtx) |
|||
{ |
|||
UniValue result(UniValue::VOBJ); |
|||
return result; |
|||
} |
|||
|
|||
UniValue musig_send(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|||
{ |
|||
UniValue result(UniValue::VOBJ); |
|||
return result; |
|||
} |
|||
|
|||
UniValue musig_spend(uint64_t txfee,struct CCcontract_info *cp,cJSON *params) |
|||
{ |
|||
UniValue result(UniValue::VOBJ); |
|||
return result; |
|||
} |
|||
|
|||
bool musig_validate(struct CCcontract_info *cp,int32_t height,Eval *eval,const CTransaction tx) |
|||
{ |
|||
return false; |
|||
} |
Loading…
Reference in new issue