From a157a5c6a1933cf6e2bf3e5998a226317aaad118 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 14 Feb 2022 14:10:08 -0500 Subject: [PATCH 01/17] update --- src/Makefile.test-hush.include | 4 ++-- src/cc/CC_made_easy.md | 4 ++-- src/cc/betprotocol.cpp | 4 ++-- src/cc/betprotocol.h | 4 ++-- src/cc/channels.cpp | 8 +++---- src/cc/eval.cpp | 12 +++++------ src/cc/eval.h | 4 ++-- src/cc/gateways.cpp | 18 ++++++++-------- src/cc/importgateway.cpp | 14 ++++++------ src/cc/importpayout.cpp | 4 ++-- src/hush.h | 14 ++++++------ src/hush_bitcoind.h | 26 +++++++++++------------ src/main.cpp | 2 +- src/notarizationdb.h | 6 +++--- src/test-hush/test_eval_bet.cpp | 6 +++--- src/test-hush/test_parse_notarization.cpp | 2 +- 16 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/Makefile.test-hush.include b/src/Makefile.test-hush.include index f638ebe59..9d6379ea0 100644 --- a/src/Makefile.test-hush.include +++ b/src/Makefile.test-hush.include @@ -12,8 +12,8 @@ hush_test_SOURCES = test-hush/main.cpp # test-hush/test_cryptoconditions.cpp \ # test-hush/test_coinimport.cpp \ # test-hush/test_eval_bet.cpp \ -# test-hush/test_eval_notarisation.cpp \ -# test-hush/test_parse_notarisation.cpp \ +# test-hush/test_eval_notarization.cpp \ +# test-hush/test_parse_notarization.cpp \ # test-hush/test_addrman.cpp \ # test-hush/test_netbase_tests.cpp diff --git a/src/cc/CC_made_easy.md b/src/cc/CC_made_easy.md index 149c5321c..79655dcbc 100644 --- a/src/cc/CC_made_easy.md +++ b/src/cc/CC_made_easy.md @@ -496,13 +496,13 @@ channelsopen: Used to open channel between two pub keys (sender and receiver). Parameters: destination_pubkey, total_number_of_payments, payment_denomination. Example - channelsopen 03a8fe537de2ace0d9c210b0ff945085c9192c9abf56ea22f22ce7998f289bb7bb 10 10000000 channelspayment: - Sending payment to receiver. Condition is that the channel open tx is confirmed/notarised. Parameters: open_tx_id, payment_amount, [secret] (optional, used when receiver needs to make a payment which secret has already been revealed by sender). + Sending payment to receiver. Condition is that the channel open tx is confirmed/notarized. Parameters: open_tx_id, payment_amount, [secret] (optional, used when receiver needs to make a payment which secret has already been revealed by sender). Example - channelspayment b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 20000000 channelsclose: Marking channel as closed. This RPC only creates a tx which says that the channel is closed and will be used in refund RPC to withdraw funds from closed channel. This also notifies receiver that channel fund could be withdrawn, but the payment RPC is still available until all funds are withdrawn. Parameters: open_tx_id. Example - channelsclose b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 channelsrefund: - Withdrawing funds back to senders address. Refund can be issued only when channel close tx is confirmed/notarised. Parameters: open_tx_id, close_tx_id + Withdrawing funds back to senders address. Refund can be issued only when channel close tx is confirmed/notarized. Parameters: open_tx_id, close_tx_id Example - channelsrefund b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 bb0ea34f846247642684c7c541c435b06ee79e47893640e5d2e51023841677fd channelsinfo: Getting info about channels in which the issuer is involved, either as sender or receiver. Call without parameters give the list of available channels. Parameters: [open_tx_id] (optional - used to get info about specific channel) diff --git a/src/cc/betprotocol.cpp b/src/cc/betprotocol.cpp index d8e904287..c6b76bb2c 100644 --- a/src/cc/betprotocol.cpp +++ b/src/cc/betprotocol.cpp @@ -164,7 +164,7 @@ bool GetOpReturnHash(CScript script, uint256 &hash) /* * Crypto-Condition EVAL method that verifies a payout against a transaction - * notarised on another chain. + * notarized on another chain. * * IN: params - condition params * IN: importTx - Payout transaction on value chain (HUSH) @@ -219,7 +219,7 @@ bool Eval::ImportPayout(const std::vector params, const CTransaction &i // Check disputeTx solves momproof from vout[0] { NotarizationData data(0); - if (!GetNotarizationData(proof.notarisationHash, data)) + if (!GetNotarizationData(proof.notarizationHash, data)) return Invalid("coudnt-load-mom"); if (data.MoM != proof.branch.Exec(disputeTx.GetHash())) diff --git a/src/cc/betprotocol.h b/src/cc/betprotocol.h index 6694cb331..5dd920aba 100644 --- a/src/cc/betprotocol.h +++ b/src/cc/betprotocol.h @@ -29,12 +29,12 @@ class MoMProof { public: MerkleBranch branch; - uint256 notarisationHash; + uint256 notarizationHash; ADD_SERIALIZE_METHODS; template inline void SerializationOp(Stream& s, Operation ser_action) { READWRITE(branch); - READWRITE(notarisationHash); + READWRITE(notarizationHash); } }; diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 135d0dc9d..389de64d8 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -250,7 +250,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else if ( ConstrainVout(channelOpenTx.vout[2],1,destmarker,CC_MARKER_VALUE)==0 ) return eval->Invalid("vout.2 is CC marker to destpub or invalid amount for channelopen!"); else if (hush_txnotarizedconfirmed(opentxid) == 0) - return eval->Invalid("channelopen is not yet confirmed(notarised)!"); + return eval->Invalid("channelopen is not yet confirmed(notarized)!"); else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for channelpayment!"); else if ( IsCCInput(tx.vin[tx.vin.size()-2].scriptSig) == 0 ) @@ -311,7 +311,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else if ( ConstrainVout(channelOpenTx.vout[2],1,destmarker,CC_MARKER_VALUE)==0 ) return eval->Invalid("vout.2 is CC marker to destpub or invalid amount for channelopen!"); else if (hush_txnotarizedconfirmed(opentxid) == 0) - return eval->Invalid("channelopen is not yet confirmed(notarised)!"); + return eval->Invalid("channelopen is not yet confirmed(notarized)!"); else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for channelclose!"); else if ( IsCCInput(tx.vin[tx.vin.size()-2].scriptSig) == 0 ) @@ -352,9 +352,9 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else if ( ConstrainVout(channelOpenTx.vout[2],1,destmarker,CC_MARKER_VALUE)==0 ) return eval->Invalid("vout.2 is CC marker to destpub or invalid amount for channelopen!"); else if (hush_txnotarizedconfirmed(opentxid) == 0) - return eval->Invalid("channelopen is not yet confirmed(notarised)!"); + return eval->Invalid("channelopen is not yet confirmed(notarized)!"); else if (hush_txnotarizedconfirmed(param3) == 0) - return eval->Invalid("channelClose is not yet confirmed(notarised)!"); + return eval->Invalid("channelClose is not yet confirmed(notarized)!"); else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for channelrefund!"); else if ( IsCCInput(tx.vin[tx.vin.size()-2].scriptSig) == 0 ) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 9f362db6c..c99160a3b 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -180,14 +180,14 @@ bool Eval::CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t t return CheckTxAuthority(tx, auth); } -// Get MoM from a notarisation tx hash (on HUSH) +// Get MoM from a notarization tx hash (on HUSH) bool Eval::GetNotarizationData(const uint256 notaryHash, NotarizationData &data) const { - CTransaction notarisationTx; + CTransaction notarizationTx; CBlockIndex block; - if (!GetTxConfirmed(notaryHash, notarisationTx, block)) return false; - if (!CheckNotaryInputs(notarisationTx, block.GetHeight(), block.nTime)) return false; - if (!ParseNotarizationOpReturn(notarisationTx, data)) return false; + if (!GetTxConfirmed(notaryHash, notarizationTx, block)) return false; + if (!CheckNotaryInputs(notarizationTx, block.GetHeight(), block.nTime)) return false; + if (!ParseNotarizationOpReturn(notarizationTx, data)) return false; return true; } @@ -205,7 +205,7 @@ std::string Eval::GetAssetchainsSymbol() const /* - * Notarization data, ie, OP_RETURN payload in notarisation transactions + * Notarization data, ie, OP_RETURN payload in notarization transactions */ bool ParseNotarizationOpReturn(const CTransaction &tx, NotarizationData &data) { diff --git a/src/cc/eval.h b/src/cc/eval.h index d4581e8ef..5c6784086 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -110,7 +110,7 @@ public: virtual bool GetSpendsConfirmed(uint256 hash, std::vector &spends) const; virtual bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const; virtual int32_t GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const; - virtual bool GetNotarizationData(uint256 notarisationHash, NotarizationData &data) const; + virtual bool GetNotarizationData(uint256 notarizationHash, NotarizationData &data) const; virtual bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const; virtual uint32_t GetAssetchainsCC() const; virtual std::string GetAssetchainsSymbol() const; @@ -158,7 +158,7 @@ extern char SMART_CHAIN_SYMBOL[65]; /* - * Data from notarisation OP_RETURN from chain being notarised + * Data from notarization OP_RETURN from chain being notarized */ class NotarizationData { diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index c8036e5f2..4a38c9daf 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -613,7 +613,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & return eval->Invalid(validationError); } else if (hush_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!"); else if (myGetTransaction(deposittxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysdeposittxid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysDepositOpRet(tmptx.vout[numvouts-1].scriptPubKey,tmptxid,tmprefcoin,tmppublishers,txids,height,cointxid,claimvout,hex,proof,tmppubkey,tmpamount) != 'D') @@ -631,7 +631,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmpamount>totalsupply) return eval->Invalid("deposit amount greater then bind total supply"); else if (hush_txnotarizedconfirmed(deposittxid) == false) - return eval->Invalid("gatewaysdeposit tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysdeposit tx is not yet confirmed(notarized)!"); else if (tx.vin.size()>0) { i=0; @@ -705,7 +705,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if ( ConstrainVout(tmptx.vout[1],1,gatewaystokensaddr,amount)==0) return eval->Invalid("invalid tokens to gateways vout for gatewaysWithdraw!"); else if (hush_txnotarizedconfirmed(withdrawtxid) == false) - return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!"); else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysbind txid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') @@ -715,7 +715,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmptokenid!=tokenid) return eval->Invalid("tokenid does not match tokenid from gatewaysbind"); else if (hush_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!"); else if (IsCCInput(tx.vin[0].scriptSig) != 0) return eval->Invalid("vin.0 is normal for gatewayspartialsign!"); else if ((*cp->ismyvin)(tx.vin[tx.vin.size()-1].scriptSig) == 0 || myGetTransaction(tx.vin[tx.vin.size()-1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[tx.vin.size()-1].prevout.n].nValue!=CC_MARKER_VALUE) @@ -747,7 +747,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmptx.vout[1].nValue!=amount) return eval->Invalid("amount in opret not matching tx tokens amount!"); else if (hush_txnotarizedconfirmed(withdrawtxid) == false) - return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!"); else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysbind txid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') @@ -757,7 +757,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmptokenid!=tokenid) return eval->Invalid("tokenid does not match tokenid from gatewaysbind"); else if (hush_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!"); else if (IsCCInput(tx.vin[0].scriptSig) != 0) return eval->Invalid("vin.0 is normal for gatewayscompletesigning!"); else if ((*cp->ismyvin)(tx.vin[tx.vin.size()-1].scriptSig) == 0 || myGetTransaction(tx.vin[tx.vin.size()-1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[tx.vin.size()-1].prevout.n].nValue!=CC_MARKER_VALUE) @@ -778,7 +778,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if ((numvouts=tmptx.vout.size()) > 0 && DecodeGatewaysCompleteSigningOpRet(tmptx.vout[numvouts-1].scriptPubKey,withdrawtxid,tmprefcoin,K,hex)!='S') return eval->Invalid("invalid gatewayscompletesigning OP_RETURN data!"); else if (hush_txnotarizedconfirmed(completetxid) == false) - return eval->Invalid("gatewayscompletesigning tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayscompletesigning tx is not yet confirmed(notarized)!"); else if (myGetTransaction(withdrawtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid withdraw txid!"); else if ((numvouts=tmptx.vout.size()) > 0 && DecodeGatewaysWithdrawOpRet(tmptx.vout[numvouts-1].scriptPubKey,tmptokenid,bindtxid,tmprefcoin,pubkey,amount)!='W') @@ -786,7 +786,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmprefcoin!=refcoin) return eval->Invalid("refcoin different than in bind tx"); else if (hush_txnotarizedconfirmed(withdrawtxid) == false) - return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!"); else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysbind txid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') @@ -796,7 +796,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmptokenid!=tokenid) return eval->Invalid("tokenid does not match tokenid from gatewaysbind"); else if (hush_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!"); else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for gatewaysmarkdone!"); else if ((*cp->ismyvin)(tx.vin[tx.vin.size()-1].scriptSig) == 0 || myGetTransaction(tx.vin[tx.vin.size()-1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[tx.vin.size()-1].prevout.n].nValue!=CC_MARKER_VALUE) diff --git a/src/cc/importgateway.cpp b/src/cc/importgateway.cpp index 1afaeec94..12ab0f90e 100644 --- a/src/cc/importgateway.cpp +++ b/src/cc/importgateway.cpp @@ -361,7 +361,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact else if (tmptx.vout[1].nValue!=amount) return eval->Invalid("amount in opret not matching tx tokens amount!"); else if (hush_txnotarizedconfirmed(withdrawtxid) == false) - return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!"); else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysbind txid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeImportGatewayBindOpRet(burnaddr,tmptx.vout[numvouts-1].scriptPubKey,tmprefcoin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') @@ -369,7 +369,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact else if (tmprefcoin!=refcoin) return eval->Invalid("refcoin different than in bind tx"); else if (hush_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!"); else if (IsCCInput(tx.vin[0].scriptSig) != 0) return eval->Invalid("vin.0 is normal for gatewayspartialsign!"); else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE) @@ -403,7 +403,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact else if (tmptx.vout[1].nValue!=amount) return eval->Invalid("amount in opret not matching tx tokens amount!"); else if (hush_txnotarizedconfirmed(withdrawtxid) == false) - return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!"); else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysbind txid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeImportGatewayBindOpRet(burnaddr,tmptx.vout[numvouts-1].scriptPubKey,tmprefcoin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') @@ -411,7 +411,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact else if (tmprefcoin!=refcoin) return eval->Invalid("refcoin different than in bind tx"); else if (hush_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!"); else if (IsCCInput(tx.vin[0].scriptSig) != 0) return eval->Invalid("vin.0 is normal for gatewayscompletesigning!"); else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE) @@ -432,7 +432,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact else if ((numvouts=tmptx.vout.size()) > 0 && DecodeImportGatewayCompleteSigningOpRet(tmptx.vout[numvouts-1].scriptPubKey,withdrawtxid,tmprefcoin,K,hex)!='S') return eval->Invalid("invalid gatewayscompletesigning OP_RETURN data!"); else if (hush_txnotarizedconfirmed(completetxid) == false) - return eval->Invalid("gatewayscompletesigning tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayscompletesigning tx is not yet confirmed(notarized)!"); else if (myGetTransaction(withdrawtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid withdraw txid!"); else if ((numvouts=tmptx.vout.size()) > 0 && DecodeImportGatewayWithdrawOpRet(tmptx.vout[numvouts-1].scriptPubKey,bindtxid,tmprefcoin,pubkey,amount)!='W') @@ -440,7 +440,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact else if (tmprefcoin!=refcoin) return eval->Invalid("refcoin different than in bind tx"); else if (hush_txnotarizedconfirmed(withdrawtxid) == false) - return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!"); else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysbind txid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeImportGatewayBindOpRet(burnaddr,tmptx.vout[numvouts-1].scriptPubKey,tmprefcoin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') @@ -448,7 +448,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact else if (tmprefcoin!=refcoin) return eval->Invalid("refcoin different than in bind tx"); else if (hush_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!"); else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for gatewaysmarkdone!"); else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE) diff --git a/src/cc/importpayout.cpp b/src/cc/importpayout.cpp index a3fd90394..481e846f0 100644 --- a/src/cc/importpayout.cpp +++ b/src/cc/importpayout.cpp @@ -28,7 +28,7 @@ /* * Crypto-Condition EVAL method that verifies a payout against a transaction - * notarised on another chain. + * notarized on another chain. * * IN: params - condition params * IN: importTx - Payout transaction on value chain (HUSH) @@ -83,7 +83,7 @@ bool Eval::ImportPayout(const std::vector params, const CTransaction &i // Check disputeTx solves momproof from vout[0] { NotarizationData data; - if (!GetNotarizationData(proof.notarisationHash, data)) + if (!GetNotarizationData(proof.notarizationHash, data)) return Invalid("coudnt-load-mom"); if (data.MoM != proof.Exec(disputeTx.GetHash())) diff --git a/src/hush.h b/src/hush.h index ee9f608f2..68a5051ca 100644 --- a/src/hush.h +++ b/src/hush.h @@ -704,7 +704,7 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",SMART_CHAIN_SYMBOL,height,sp->NOTARIZED_HEIGHT,SMART_CHAIN_SYMBOL,srchash.ToString().c_str(),"HUSH",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth); } //else if ( fJustCheck ) - // return (-3); // if the notarisation is only invalid because its out of order it cannot be mined in a block with a valid one! + // return (-3); // if the notarization is only invalid because its out of order it cannot be mined in a block with a valid one! } else if ( opretlen != 149 && height > 600000 && matched != 0 ) printf("%s validated.%d notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s len.%d opretlen.%d\n",ccdata.symbol,validated,notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,SMART_CHAIN_SYMBOL,srchash.ToString().c_str(),desttxid.ToString().c_str(),len,opretlen); } @@ -764,7 +764,7 @@ int32_t hush_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys[6 int32_t hush_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) { static int32_t hwmheight; - std::vector notarisations; + std::vector notarizations; uint64_t signedmask,voutmask; char symbol[HUSH_SMART_CHAIN_MAXLEN],dest[HUSH_SMART_CHAIN_MAXLEN]; struct hush_state *sp; uint8_t scriptbuf[10001],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 zero,btctxid,txhash; int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; @@ -897,8 +897,8 @@ int32_t hush_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) notaryid = hush_voutupdate(fJustCheck,&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.LastTip()->GetBlockTime()); if ( fJustCheck && notaryid == -2 ) { - // We see a valid notarisation here, save its location. - notarisations.push_back(i); + // We see a valid notarization here, save its location. + notarizations.push_back(i); } if ( 0 && i > 0 ) { @@ -961,11 +961,11 @@ int32_t hush_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) //fprintf(stderr,"%s end connect.%d\n",SMART_CHAIN_SYMBOL,pindex->GetHeight()); if (fJustCheck) { - if ( notarisations.size() == 0 ) + if ( notarizations.size() == 0 ) return(0); - if ( notarisations.size() == 1 && notarisations[0] == 1 ) + if ( notarizations.size() == 1 && notarizations[0] == 1 ) return(1); - if ( notarisations.size() > 1 || (notarisations.size() == 1 && notarisations[0] != 1) ) + if ( notarizations.size() > 1 || (notarizations.size() == 1 && notarizations[0] != 1) ) return(-1); fprintf(stderr,"hush_connectblock: unxexpected behaviour when fJustCheck == true, report bug plz ! \n"); diff --git a/src/hush_bitcoind.h b/src/hush_bitcoind.h index 0aefbcccf..d690cc8a2 100644 --- a/src/hush_bitcoind.h +++ b/src/hush_bitcoind.h @@ -1375,7 +1375,7 @@ uint64_t hush_notarypayamount(int32_t nHeight, int64_t notarycount) int32_t hush_getnotarizedheight(uint32_t timestamp,int32_t height, uint8_t *script, int32_t len) { - // Check the notarisation is valid, and extract notarised height. + // Check the notarization is valid, and extract notarized height. uint64_t voutmask; uint8_t scriptbuf[10001]; int32_t isratification,specialtx,notarizedheight; @@ -1403,7 +1403,7 @@ uint64_t hush_notarypay(CMutableTransaction &txNew, std::vector &Notariz if ( notarypubkeys[0][0] == 0 ) return(0); - // Check the notarisation is valid. + // Check the notarization is valid. int32_t notarizedheight = hush_getnotarizedheight(timestamp, height, script, len); if ( notarizedheight == 0 ) return(0); @@ -1416,7 +1416,7 @@ uint64_t hush_notarypay(CMutableTransaction &txNew, std::vector &Notariz if ( AmountToPay == 0 ) return(0); - // loop over notarisation vins and add transaction to coinbase. + // loop over notarization vins and add transaction to coinbase. // Commented prints here can be used to verify manually the pubkeys match. for (int8_t n = 0; n < NotarizationNotaries.size(); n++) { @@ -1468,10 +1468,10 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height) if ( !GetNotarizationNotaries(notarypubkeys, numSN, pblock->vtx[1].vin, NotarizationNotaries) ) return(0); - // check a notary didnt sign twice (this would be an invalid notarisation later on and cause problems) + // check a notary didnt sign twice (this would be an invalid notarization later on and cause problems) std::set checkdupes( NotarizationNotaries.begin(), NotarizationNotaries.end() ); if ( checkdupes.size() != NotarizationNotaries.size() ) { - fprintf(stderr, "Possible notarisation is signed multiple times by same notary. It is invalid.\n"); + fprintf(stderr, "Possible notarization is signed multiple times by same notary. It is invalid.\n"); return(0); } const CChainParams& chainparams = Params(); @@ -1480,7 +1480,7 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height) CMutableTransaction txNew = CreateNewContextualCMutableTransaction(consensusParams, height); if ( pblock->vtx[1].vout.size() == 2 && pblock->vtx[1].vout[1].nValue == 0 ) { - // Get the OP_RETURN for the notarisation + // Get the OP_RETURN for the notarization uint8_t *script = (uint8_t *)&pblock->vtx[1].vout[1].scriptPubKey[0]; int32_t scriptlen = (int32_t)pblock->vtx[1].vout[1].scriptPubKey.size(); if ( script[0] == OP_RETURN ) @@ -1491,13 +1491,13 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height) } else { - fprintf(stderr, "vout 2 of notarisation is not OP_RETURN scriptlen.%i\n", scriptlen); + fprintf(stderr, "vout 2 of notarization is not OP_RETURN scriptlen.%i\n", scriptlen); return(0); } } else return(0); - // if notarypay fails, because the notarisation is not valid, exit now as txNew was not created. - // This should never happen, as the notarisation is checked before this function is called. + // if notarypay fails, because the notarization is not valid, exit now as txNew was not created. + // This should never happen, as the notarization is checked before this function is called. if ( totalsats == 0 ) { fprintf(stderr, "notary pay returned 0!\n"); @@ -1519,7 +1519,7 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height) n++; continue; } - // Check the pubkeys match the pubkeys in the notarisation. + // Check the pubkeys match the pubkeys in the notarization. script = (uint8_t *)&txout.scriptPubKey[0]; scriptlen = (int32_t)txout.scriptPubKey.size(); if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,notarypubkeys[NotarizationNotaries[n-1]],33) == 0 ) @@ -1537,7 +1537,7 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height) } if ( matches != 0 && matches == NotarizationNotaries.size() && totalsats == total ) { - //fprintf(stderr, "Validated coinbase matches notarisation in tx position 1.\n" ); + //fprintf(stderr, "Validated coinbase matches notarization in tx position 1.\n" ); return(totalsats); } return(0); @@ -1757,10 +1757,10 @@ int32_t hush_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) // We check the full validation in ConnectBlock directly to get the amount for coinbase. So just approx here. if ( slowflag == 0 && pblock->vtx[0].vout.size() > 1 ) { - // Check the notarisation tx is to the crypto address. + // Check the notarization tx is to the crypto address. if ( !hush_is_notarytx(pblock->vtx[1]) == 1 ) { - fprintf(stderr, "notarisation is not to crypto address ht.%i\n",height); + fprintf(stderr, "notarization is not to crypto address ht.%i\n",height); return(-1); } // Check min sigs. diff --git a/src/main.cpp b/src/main.cpp index 4e6fc678f..7eba3e7a3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5600,7 +5600,7 @@ bool PruneOneBlockFile(bool tempfile, const int fileNumber) } else { - // Block is not in main chain and is older than last notarised block so its safe for removal. + // Block is not in main chain and is older than last notarized block so its safe for removal. fprintf(stderr, "Block [%i] in tempfile.%i We can clear this block!\n",pindex->GetHeight(),fileNumber); // Add index to list and remove after loop? } diff --git a/src/notarizationdb.h b/src/notarizationdb.h index 53d4f7318..b6e3f7684 100644 --- a/src/notarizationdb.h +++ b/src/notarizationdb.h @@ -20,9 +20,9 @@ typedef std::vector NotarizationsInBlock; NotarizationsInBlock ScanBlockNotarizations(const CBlock &block, int nHeight); bool GetBlockNotarizations(uint256 blockHash, NotarizationsInBlock &nibs); -bool GetBackNotarization(uint256 notarisationHash, Notarization &n); -void WriteBackNotarizations(const NotarizationsInBlock notarisations, CDBBatch &batch); -void EraseBackNotarizations(const NotarizationsInBlock notarisations, CDBBatch &batch); +bool GetBackNotarization(uint256 notarizationHash, Notarization &n); +void WriteBackNotarizations(const NotarizationsInBlock notarizations, CDBBatch &batch); +void EraseBackNotarizations(const NotarizationsInBlock notarizations, CDBBatch &batch); int ScanNotarizationsDB(int height, std::string symbol, int scanLimitBlocks, Notarization& out); #endif /* HUSH_NOTARISATIONDB_H */ diff --git a/src/test-hush/test_eval_bet.cpp b/src/test-hush/test_eval_bet.cpp index 5ff210393..51c9eda42 100644 --- a/src/test-hush/test_eval_bet.cpp +++ b/src/test-hush/test_eval_bet.cpp @@ -123,9 +123,9 @@ public: return true; } - bool GetNotarizationData(uint256 notarisationHash, NotarizationData &data) const + bool GetNotarizationData(uint256 notarizationHash, NotarizationData &data) const { - if (notarisationHash == NotarizationHash()) { + if (notarizationHash == NotarizationHash()) { data.MoM = MoM; return true; } @@ -567,7 +567,7 @@ TEST_F(TestBet, testImportPayoutInvalidNotarizationHash) EvalMock eval = ebet.SetEvalMock(12); MoMProof proof = ebet.GetMoMProof(); - proof.notarisationHash = uint256(); + proof.notarizationHash = uint256(); CMutableTransaction importTx = ebet.bet.MakeImportPayoutTx( ebet.Payouts(Player2), ebet.DisputeTx(Player2), uint256(), proof); diff --git a/src/test-hush/test_parse_notarization.cpp b/src/test-hush/test_parse_notarization.cpp index 655c6d5b6..0ee04a817 100644 --- a/src/test-hush/test_parse_notarization.cpp +++ b/src/test-hush/test_parse_notarization.cpp @@ -49,6 +49,6 @@ TEST(TestParseNotarization, test__b) -// for l in `g 'parse notarisation' ~/.hush/HUSH3/debug.log | pyline 'l.split()[8]'`; do hoek decodeTx '{"hex":"'`src/hush-cli getrawtransaction "$l"`'"}' | jq '.outputs[1].script.op_return' | pyline 'import base64; print base64.b64decode(l).encode("hex")'; done +// for l in `g 'parse notarization' ~/.hush/HUSH3/debug.log | pyline 'l.split()[8]'`; do hoek decodeTx '{"hex":"'`src/hush-cli getrawtransaction "$l"`'"}' | jq '.outputs[1].script.op_return' | pyline 'import base64; print base64.b64decode(l).encode("hex")'; done } From 90bb8c7cf4eb69d0d7f8744bb90582caf36ec30e Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 29 Mar 2022 10:29:54 -0400 Subject: [PATCH 02/17] Fix incorrect comment --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7eba3e7a3..8266ccdce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1452,7 +1452,7 @@ bool CheckTransaction(uint32_t tiptime,const CTransaction& tx, CValidationState return true; } -// This is used only in RPC currently but hush_notaries()/gethushseason/getacseason is consensus +// This is and hush_notaries()/gethushseason/getacseason are all consensus code int32_t hush_isnotaryvout(char *coinaddr,uint32_t tiptime) { bool ishush3 = strncmp(SMART_CHAIN_SYMBOL, "HUSH3",5) == 0 ? true : false; bool istush = strncmp(SMART_CHAIN_SYMBOL, "TUSH",4) == 0 ? true : false; From 79a6f51c2d048fbbfa209b5ab3f1ed5771ac4fd5 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 30 Mar 2022 00:21:38 -0400 Subject: [PATCH 03/17] Update some comments and docs --- src/wallet/rpcwallet.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c4dd9c7fc..80064f6b2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -64,7 +64,7 @@ const std::string ADDR_TYPE_AMNESIA = "amnesia"; extern int32_t HUSH_INSYNC; uint32_t hush_segid32(char *coinaddr); int32_t hush_dpowconfs(int32_t height,int32_t numconfs); -int32_t hush_isnotaryvout(char *coinaddr,uint32_t tiptime); // from ac_private chains only +int32_t hush_isnotaryvout(char *coinaddr,uint32_t tiptime); // needed for ac_private=1 chains only CBlockIndex *hush_getblockindex(uint256 hash); extern string randomSietchZaddr(); extern CAmount fConsolidationTxFee; @@ -559,9 +559,9 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) "\"transactionid\" (string) The transaction id.\n" "\nExamples:\n" + HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1") - + HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1 \"donation\" \"seans outpost\"") + + HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1 \"donation\" \"Hush Puppy Freedom Fund\"") + HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1 \"\" \"\" true") - + HelpExampleRpc("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 0.1, \"donation\", \"seans outpost\"") + + HelpExampleRpc("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 0.1, \"donation\", \"Hush Puppy Freedom Fund\"") ); if ( ASSETCHAINS_PRIVATE != 0 && AmountFromValue(params[1]) > 0 ) @@ -4929,6 +4929,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk) if (fromTaddr) { txsize += CTXIN_SPEND_DUST_SIZE; //TODO: On HUSH since block 340k there can no longer be taddr change, + // (except for notary addresses) // so we can likely make a better estimation of max txsize txsize += CTXOUT_REGULAR_SIZE; // There will probably be taddr change } From 689a360b607095274ce960b3078c8524455531df Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 18 Apr 2022 00:32:11 -0400 Subject: [PATCH 04/17] Allow notary addresses in sendmany, fixes #126 --- src/wallet/rpcwallet.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 80064f6b2..edfb608e7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1502,8 +1502,6 @@ UniValue sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk) "\nAs a json rpc call\n" + HelpExampleRpc("sendmany", "\"\", {\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\":0.01,\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\":0.02}, 6, \"testing\"") ); - if ( ASSETCHAINS_PRIVATE != 0 ) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1528,6 +1526,17 @@ UniValue sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk) std::vector keys = sendTo.getKeys(); int32_t i = 0; for (const std::string& name_ : keys) { + // Allow transparent notary addresses and throw an error for anything else + // This is also a consensus check but we want to prevent it from going into the mempool + // and give an error as early as possible + if ( ASSETCHAINS_PRIVATE != 0 ) + { + if ( hush_isnotaryvout((char *)name_.c_str(),chainActive.LastTip()->nTime) == 0 ) + { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transparent " + strprintf("%s",hush_chainname()) + " address not allowed on private chain"); + } + } + CTxDestination dest = DecodeDestination(name_); if (!IsValidDestination(dest)) { CScript tmpspk; From 69cd4f79901d7d8594f76676d490da0518c59383 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 20 Apr 2022 10:51:12 -0400 Subject: [PATCH 05/17] data key (OP_RETURN) is optional in createrawtransaction --- src/rpc/rawtransaction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index a48df8e44..2619d309b 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -647,7 +647,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp, const CPubKey& "2. \"outputs\" (object, required) a json object with outputs\n" " {\n" " \"address\": x.xxx, (numeric or string, required) The key is the HUSH address or script (in hex), the numeric value (can be string) is the " + CURRENCY_UNIT + " amount\n" - " \"data\": \"hex\" (string, required) The key is \"data\", the value is hex encoded data\n" + " \"data\": \"hex\" (string, optional) The key is \"data\", the value is hex encoded data\n" " ,...\n" " }\n" "3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n" From 193a1b2a97c7d669bf03bd23d6c18793286ac09d Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 20 Apr 2022 10:52:12 -0400 Subject: [PATCH 06/17] Clarify that it is OP_RETURN data --- src/rpc/rawtransaction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 2619d309b..6c115cb67 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -647,7 +647,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp, const CPubKey& "2. \"outputs\" (object, required) a json object with outputs\n" " {\n" " \"address\": x.xxx, (numeric or string, required) The key is the HUSH address or script (in hex), the numeric value (can be string) is the " + CURRENCY_UNIT + " amount\n" - " \"data\": \"hex\" (string, optional) The key is \"data\", the value is hex encoded data\n" + " \"data\": \"hex\" (string, optional) The key is \"data\", the value is hex encoded OP_RETURN data\n" " ,...\n" " }\n" "3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n" From afe1cf153c337e49739fd6b57850e9e80fdae047 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 21 Apr 2022 22:35:21 -0400 Subject: [PATCH 07/17] Uncomment some dpow debugging --- src/hush.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hush.h b/src/hush.h index 68a5051ca..187638372 100644 --- a/src/hush.h +++ b/src/hush.h @@ -635,7 +635,7 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi ccdata.MoMdata.notarized_height = *notarizedheightp; ccdata.MoMdata.height = height; ccdata.MoMdata.txi = i; - //printf("nameoffset.%d len.%d + 36 %d opoffset.%d vs opretlen.%d\n",nameoffset,len,len+36,opoffset,opretlen); + printf("nameoffset.%d len.%d + 36 %d opoffset.%d vs opretlen.%d\n",nameoffset,len,len+36,opoffset,opretlen); if ( len+36-opoffset <= opretlen ) { len += dragon_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&MoM); @@ -645,8 +645,8 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi if ( len+sizeof(ccdata.CCid)-opoffset <= opretlen ) { len += dragon_rwnum(0,&scriptbuf[len],sizeof(ccdata.CCid),(uint8_t *)&ccdata.CCid); - //if ( ((MoMdepth>>16) & 0xffff) != (ccdata.CCid & 0xffff) ) - // fprintf(stderr,"%s CCid mismatch %u != %u\n",SMART_CHAIN_SYMBOL,((MoMdepth>>16) & 0xffff),(ccdata.CCid & 0xffff)); + if ( ((MoMdepth>>16) & 0xffff) != (ccdata.CCid & 0xffff) ) + fprintf(stderr,"%s CCid mismatch %u != %u\n",SMART_CHAIN_SYMBOL,((MoMdepth>>16) & 0xffff),(ccdata.CCid & 0xffff)); ccdata.len = sizeof(ccdata.CCid); if ( SMART_CHAIN_SYMBOL[0] != 0 ) { From 7859fdf7eb32f95a47eeef6cceaf1a9f9837d2a4 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 23 Apr 2022 10:00:35 -0400 Subject: [PATCH 08/17] More debug --- src/hush.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hush.h b/src/hush.h index 187638372..cf72b05f1 100644 --- a/src/hush.h +++ b/src/hush.h @@ -612,7 +612,7 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi notarized = 1; if ( strcmp("DPOW",ccdata.symbol) == 0 || strncmp("ZPOW",ccdata.symbol,5) == 0 || strcmp("TUSH",ccdata.symbol) == 0) notarized = 1; - if ( 0 && opretlen != 149 ) + if ( opretlen != 149 ) printf("[%s].%d (%s) matched.%d i.%d j.%d notarized.%d %llx opretlen.%d len.%d offset.%d opoffset.%d\n",SMART_CHAIN_SYMBOL,height,ccdata.symbol,matched,i,j,notarized,(long long)signedmask,opretlen,len,offset,opoffset); len += dragon_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&srchash); len += dragon_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp); From 421edc8979a3fb27e421ba92eef99f1ae324ecfb Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 2 Jun 2022 21:43:10 -0400 Subject: [PATCH 09/17] Log txid for double spends and missing anchors This makes debugging failed transactions much easier. --- src/coins.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index a83731e35..0c3af3863 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -578,13 +578,13 @@ bool CCoinsViewCache::HaveShieldedRequirements(const CTransaction& tx) const { for (const SpendDescription &spendDescription : tx.vShieldedSpend) { if (GetNullifier(spendDescription.nullifier, SAPLING)) { // Prevent double spends - LogPrintf("%s: sapling nullifier %s exists, preventing double spend\n", __FUNCTION__, spendDescription.nullifier.GetHex().c_str()); + LogPrintf("%s: sapling nullifier %s exists, preventing double spend in tx %s\n", __FUNCTION__, spendDescription.nullifier.GetHex().c_str(), tx.GetHash().GetHex().c_str()); return false; } SaplingMerkleTree tree; if (!GetSaplingAnchorAt(spendDescription.anchor, tree)) { - LogPrintf("%s: missing sapling anchor: %s \n", __FUNCTION__, spendDescription.anchor.GetHex().c_str()); + LogPrintf("%s: missing sapling anchor: %s in tx %s \n", __FUNCTION__, spendDescription.anchor.GetHex().c_str(), tx.GetHash().GetHex().c_str()); return false; } } From bdde67c35989f64db3e55cfed79ea7a66773cdd4 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Jun 2022 20:05:49 -0700 Subject: [PATCH 10/17] Initial implementation of anonsettxdelta + z_anonsetblockdelta --- src/wallet/rpcwallet.cpp | 88 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index edfb608e7..06dc0ded2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3652,6 +3652,92 @@ UniValue z_listsentbyaddress(const UniValue& params, bool fHelp,const CPubKey&) return ret; } +UniValue z_anonsetblockdelta(const UniValue& params, bool fHelp, const CPubKey& mypk) +{ + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() != 1) + throw runtime_error( + "z_anonsetblockdelta\n" + "\nReturns delta (difference) in the anonset for a given block height.\n" + "\nArguments:\n" + "1. \"height\" (number, required) The block height\n" + "\nResult:\n" + "\"delta\" (integer) An integer number.\n" + "\nExamples:\n" + + HelpExampleCli("z_anonsetblockdelta 123", "456") + + HelpExampleRpc("z_anonsetblockdelta 123", "456") + ); + + LOCK2(cs_main, pwalletMain->cs_wallet); + std::string strHeight = params[0].get_str(); + int nHeight = -1; + try { + nHeight = std::stoi(strHeight); + } catch (const std::exception &e) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter"); + } + + if (nHeight < 0 || nHeight > chainActive.Height()) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); + } + strHash = chainActive[nHeight]->GetBlockHash().GetHex(); + uint256 hash(uint256S(strHash)); + + if (mapBlockIndex.count(hash) == 0) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); + + CBlock block; + CBlockIndex* pblockindex = mapBlockIndex[hash]; + + if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0) + throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)"); + + if(!ReadBlockFromDisk(block, pblockindex,1)) + throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); + + int delta = 0; + BOOST_FOREACH(const CTransaction&tx, block.vtx) + { + // delta = shielded outputs - shielded inputs + delta += tx.vShieldedOutput.size() - tx.vShieldedSpend.size(); + } + return delta; +} + +UniValue z_anonsettxdelta(const UniValue& params, bool fHelp, const CPubKey& mypk) +{ + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() != 1) + throw runtime_error( + "z_anonsettxdelta\n" + "\nReturns delta (difference) in the anonset for a given txid.\n" + "\nArguments:\n" + "1. \"txid\" (string, required) The transaction id\n" + "\nResult:\n" + "\"delta\" (integer) An integer number.\n" + "\nExamples:\n" + + HelpExampleCli("z_anonsettxdelta txid", "123") + + HelpExampleRpc("z_anonsettxdelta txid", "123") + ); + + LOCK2(cs_main, pwalletMain->cs_wallet); + + uint256 txid; + txid.SetHex(params[0].get_str()); + + if (!pwalletMain->mapWallet.count(hash)) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id!"); + const CWalletTx& wtx = pwalletMain->mapWallet[hash]; + + // delta = shielded outputs - shielded inputs + int delta = wtx.vShieldedSpend.size() - wtx.vShieldedOutput.size(); + return delta; +} + UniValue z_getbalances(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) @@ -8352,6 +8438,8 @@ static const CRPCCommand commands[] = { "wallet", "z_listunspent", &z_listunspent, false }, { "wallet", "z_getbalance", &z_getbalance, false }, { "wallet", "z_getbalances", &z_getbalances, false }, + { "wallet", "z_anonsettxdelta", &z_anonsettxdelta, true }, + { "wallet", "z_anonsetblockdelta", &z_anonsetblockdelta, true }, { "wallet", "z_gettotalbalance", &z_gettotalbalance, false }, { "wallet", "z_mergetoaddress", &z_mergetoaddress, false }, { "wallet", "z_sendmany", &z_sendmany, false }, From c218cf1c09587acadafeb61538cb18975ecd4674 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 7 Jun 2022 23:19:06 -0400 Subject: [PATCH 11/17] Fix compile errors --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 06dc0ded2..28c987fb1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3682,7 +3682,7 @@ UniValue z_anonsetblockdelta(const UniValue& params, bool fHelp, const CPubKey& if (nHeight < 0 || nHeight > chainActive.Height()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); } - strHash = chainActive[nHeight]->GetBlockHash().GetHex(); + auto strHash = chainActive[nHeight]->GetBlockHash().GetHex(); uint256 hash(uint256S(strHash)); if (mapBlockIndex.count(hash) == 0) @@ -3729,9 +3729,9 @@ UniValue z_anonsettxdelta(const UniValue& params, bool fHelp, const CPubKey& myp uint256 txid; txid.SetHex(params[0].get_str()); - if (!pwalletMain->mapWallet.count(hash)) + if (!pwalletMain->mapWallet.count(txid)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id!"); - const CWalletTx& wtx = pwalletMain->mapWallet[hash]; + const CWalletTx& wtx = pwalletMain->mapWallet[txid]; // delta = shielded outputs - shielded inputs int delta = wtx.vShieldedSpend.size() - wtx.vShieldedOutput.size(); From cc61b19930f3337d3058f6f97105e664c6c00adc Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 7 Jun 2022 23:56:25 -0400 Subject: [PATCH 12/17] Make z_anonsettxdelta work on a tx that is not in our wallet and fix calculation --- src/wallet/rpcwallet.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 28c987fb1..189d668f3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3724,17 +3724,17 @@ UniValue z_anonsettxdelta(const UniValue& params, bool fHelp, const CPubKey& myp + HelpExampleRpc("z_anonsettxdelta txid", "123") ); - LOCK2(cs_main, pwalletMain->cs_wallet); - uint256 txid; + uint256 txid,hashBlock; + CTransaction tx; txid.SetHex(params[0].get_str()); - if (!pwalletMain->mapWallet.count(txid)) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id!"); - const CWalletTx& wtx = pwalletMain->mapWallet[txid]; + LOCK(cs_main); + if (!GetTransaction(txid, tx, hashBlock, true)) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction"); // delta = shielded outputs - shielded inputs - int delta = wtx.vShieldedSpend.size() - wtx.vShieldedOutput.size(); + int delta = tx.vShieldedOutput.size() - tx.vShieldedSpend.size(); return delta; } From e0d22ee170f8af9542f2c7dcb5d1eb0c28c1e72c Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 9 Jun 2022 03:00:50 -0700 Subject: [PATCH 13/17] Enable z_anonsetblockdelta to calculate a delta for a block range; ignore coinbase txs as optimization --- src/wallet/rpcwallet.cpp | 63 +++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 189d668f3..3a5498f19 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3657,12 +3657,15 @@ UniValue z_anonsetblockdelta(const UniValue& params, bool fHelp, const CPubKey& if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - if (fHelp || params.size() != 1) + if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "z_anonsetblockdelta\n" - "\nReturns delta (difference) in the anonset for a given block height.\n" + "\nReturns delta (difference) in the anonset for a given block height. A delta > 0 increases the anonset,\n" + "\na delta < 0 reduces the anonset and a delta=0 leaves the anonset the same. Given a single block height\n" + "\nwe calculate the delta for that block. Given two block heights, we calculate the delta for that range of blocks.\n" "\nArguments:\n" "1. \"height\" (number, required) The block height\n" + "1. \"end_height\" (number, optional) The ending block height\n" "\nResult:\n" "\"delta\" (integer) An integer number.\n" "\nExamples:\n" @@ -3698,10 +3701,55 @@ UniValue z_anonsetblockdelta(const UniValue& params, bool fHelp, const CPubKey& throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); int delta = 0; - BOOST_FOREACH(const CTransaction&tx, block.vtx) - { - // delta = shielded outputs - shielded inputs - delta += tx.vShieldedOutput.size() - tx.vShieldedSpend.size(); + + // given a single block height, we calculate delta for that height + if (params.size() == 1) { + BOOST_FOREACH(const CTransaction&tx, block.vtx) + { + // delta = shielded outputs - shielded inputs + if(!tx.IsCoinBase()) { + delta += tx.vShieldedOutput.size() - tx.vShieldedSpend.size(); + } + } + } else { + // given two blocks, we calculate delta for that range + std::string strHeight2 = params[1].get_str(); + int nHeight2 = -1; + try { + nHeight = std::stoi(strHeight2); + } catch (const std::exception &e) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid ending block height parameter"); + } + + if (nHeight2 < 0 || nHeight2 > chainActive.Height()) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Ending block height out of range"); + } + + // get the delta for every block in the range + for(int currentHeight = nHeight; currentHeight <= nHeight2; currentHeight++) { + auto strHash = chainActive[currentHeight]->GetBlockHash().GetHex(); + uint256 hash(uint256S(strHash)); + + if (mapBlockIndex.count(hash) == 0) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); + + CBlock block; + CBlockIndex* pblockindex = mapBlockIndex[hash]; + + if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0) + throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)"); + + if(!ReadBlockFromDisk(block, pblockindex,1)) + throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); + + BOOST_FOREACH(const CTransaction&tx, block.vtx) + { + // delta = shielded outputs - shielded inputs + if(!tx.IsCoinBase()) { + delta += tx.vShieldedOutput.size() - tx.vShieldedSpend.size(); + } + } + } } return delta; } @@ -3714,7 +3762,8 @@ UniValue z_anonsettxdelta(const UniValue& params, bool fHelp, const CPubKey& myp if (fHelp || params.size() != 1) throw runtime_error( "z_anonsettxdelta\n" - "\nReturns delta (difference) in the anonset for a given txid.\n" + "\nReturns delta (difference) in the anonset for a given txid. A delta > 0 increases the anonset,\n" + "\na delta < 0 reduces the anonset and a delta=0 leaves the anonset the same.\n" "\nArguments:\n" "1. \"txid\" (string, required) The transaction id\n" "\nResult:\n" From 2b336dccc0c51edbaac802a94b5c0f7e3d2cf502 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 9 Jun 2022 06:41:09 -0400 Subject: [PATCH 14/17] Fix ending height bug and check that ending height is larger than starting height --- src/wallet/rpcwallet.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3a5498f19..8e6d8b128 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3716,11 +3716,15 @@ UniValue z_anonsetblockdelta(const UniValue& params, bool fHelp, const CPubKey& std::string strHeight2 = params[1].get_str(); int nHeight2 = -1; try { - nHeight = std::stoi(strHeight2); + nHeight2 = std::stoi(strHeight2); } catch (const std::exception &e) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid ending block height parameter"); } + if (nHeight2 <= nHeight) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Ending block height must be larger than starting height"); + } + if (nHeight2 < 0 || nHeight2 > chainActive.Height()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Ending block height out of range"); } From 0a9abedc5dba747fa40d4ebfcbe2ab3ab4adae65 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 26 Jun 2022 04:40:06 -0700 Subject: [PATCH 15/17] Return size in bytes of a tx from getrawtransaction --- src/rpc/rawtransaction.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 6c115cb67..2e82c061a 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -367,6 +367,7 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp, const CPubKey& my "\nResult (if verbose > 0):\n" "{\n" " \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n" + " \"size\" : n, (numeric) The length in bytes\n" " \"txid\" : \"id\", (string) The transaction id (same as provided)\n" " \"version\" : n, (numeric) The version\n" " \"locktime\" : ttt, (numeric) The lock time\n" @@ -453,6 +454,7 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp, const CPubKey& my UniValue result(UniValue::VOBJ); result.push_back(Pair("hex", strHex)); + result.push_back(Pair("size", GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) )); TxToJSONExpanded(tx, hashBlock, result, nHeight, nConfirmations, nBlockTime); return result; } From 0ee1d068c1302e945ce457bb65c12f1d4aa82b0d Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 26 Jun 2022 17:21:33 -0700 Subject: [PATCH 16/17] These haven't existed for a long time --- src/rpc/server.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/rpc/server.h b/src/rpc/server.h index 4e301ea8c..b6a20b559 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -479,8 +479,6 @@ extern UniValue z_listoperationids(const UniValue& params, bool fHelp, const CPu extern UniValue opreturn_burn(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue rescan(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue z_validateaddress(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcmisc.cpp -extern UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcdisclosure.cpp -extern UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcdisclosure.cpp extern UniValue MoMoMdata(const UniValue& params, bool fHelp, const CPubKey& mypk); extern UniValue calc_MoM(const UniValue& params, bool fHelp, const CPubKey& mypk); From abaa623526945150f0bd1606327a7343fd8d9923 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 26 Jun 2022 17:23:10 -0700 Subject: [PATCH 17/17] This file no longer exists --- src/Makefile.gtest.include | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include index 457ef6bdf..368666e58 100644 --- a/src/Makefile.gtest.include +++ b/src/Makefile.gtest.include @@ -41,7 +41,6 @@ zcash_gtest_SOURCES += \ gtest/test_txid.cpp \ gtest/test_libzcash_utils.cpp \ gtest/test_proofs.cpp \ - gtest/test_paymentdisclosure.cpp \ gtest/test_pedersen_hash.cpp \ gtest/test_checkblock.cpp \ gtest/test_zip32.cpp