From 703a13dab476b1e4937eac9d30de4fe6bba89f4e Mon Sep 17 00:00:00 2001 From: Srdjan Obucina Date: Tue, 14 Apr 2020 07:27:18 +0200 Subject: [PATCH 1/4] Fix transaction verification --- .../sidechain_net_handler_bitcoin.cpp | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index d9d6a90c..5203a6b2 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -928,12 +928,14 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) switch (op_idx_0) { case chain::operation::tag::value: { - bool address_ok = false; + bool transaction_ok = false; + std::string new_pw_address = ""; son_wallet_id_type swo_id = op_obj_idx_0.get().son_wallet_id; const auto &idx = database.get_index_type().indices().get(); const auto swo = idx.find(swo_id); if (swo != idx.end()) { + auto active_sons = gpo.active_sons; vector wallet_sons = swo->sons; @@ -961,31 +963,36 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) if (active_pw_pt.count("error") && active_pw_pt.get_child("error").empty()) { std::stringstream res; boost::property_tree::json_parser::write_json(res, active_pw_pt.get_child("result")); + new_pw_address = active_pw_pt.get("result.address"); address_ok = (op_obj_idx_0.get().address == res.str()); } } - } - bool transaction_ok = false; - object_id_type object_id = op_obj_idx_1.get().object_id; - std::string op_tx_str = op_obj_idx_1.get().transaction; + if (po.proposed_transaction.operations.size() >= 2) { + object_id_type object_id = op_obj_idx_1.get().object_id; + std::string op_tx_str = op_obj_idx_1.get().transaction; - const auto &st_idx = database.get_index_type().indices().get(); - const auto st = st_idx.find(object_id); - if (st == st_idx.end()) { + const auto &st_idx = database.get_index_type().indices().get(); + const auto st = st_idx.find(object_id); + if (st == st_idx.end()) { - std::string tx_str = ""; + std::string tx_str = ""; - if (object_id.is()) { - const auto &idx = database.get_index_type().indices().get(); - const auto swo = idx.find(object_id); - if (swo != idx.end()) { - tx_str = op_tx_str; //create_primary_wallet_transaction(); + if (object_id.is()) { + const auto &idx = database.get_index_type().indices().get(); + const auto swo = idx.find(object_id); + if (swo != idx.end()) { + const auto prec_swo = std::next(swo); + tx_str = create_primary_wallet_transaction(*prec_swo, new_pw_address); + } + } + + transaction_ok = (op_tx_str == tx_str); } + } else { + transaction_ok = true; } - - transaction_ok = (op_tx_str == tx_str); } should_approve = address_ok && From 3f71b7de1f795127163bf381a08a3e862a780b1e Mon Sep 17 00:00:00 2001 From: Srdjan Obucina Date: Tue, 14 Apr 2020 07:48:59 +0200 Subject: [PATCH 2/4] Fix segfault --- .../peerplays_sidechain/sidechain_net_handler_bitcoin.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index 5203a6b2..9d07eb27 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -983,8 +983,10 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) const auto &idx = database.get_index_type().indices().get(); const auto swo = idx.find(object_id); if (swo != idx.end()) { - const auto prec_swo = std::next(swo); - tx_str = create_primary_wallet_transaction(*prec_swo, new_pw_address); + const auto prec_swo = idx.find(son_wallet_id_type(object_id.instance() - 1)); + if (prec_swo != idx.end()) { + tx_str = create_primary_wallet_transaction(*prec_swo, new_pw_address); + } } } From 5284a1487c0e19fe20850184f9f5cb2faea3e47c Mon Sep 17 00:00:00 2001 From: Srdjan Obucina Date: Tue, 14 Apr 2020 19:04:17 +0200 Subject: [PATCH 3/4] Fix transaction validation --- .../peerplays_sidechain/sidechain_net_handler_bitcoin.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index 9d07eb27..508d3e14 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -983,10 +983,7 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) const auto &idx = database.get_index_type().indices().get(); const auto swo = idx.find(object_id); if (swo != idx.end()) { - const auto prec_swo = idx.find(son_wallet_id_type(object_id.instance() - 1)); - if (prec_swo != idx.end()) { - tx_str = create_primary_wallet_transaction(*prec_swo, new_pw_address); - } + tx_str = create_primary_wallet_transaction(*swo, new_pw_address); } } From 5ec353f46b8cfb7a184d64b3ea5220a8c775faa2 Mon Sep 17 00:00:00 2001 From: Srdjan Obucina Date: Tue, 14 Apr 2020 20:42:48 +0200 Subject: [PATCH 4/4] Remove logs --- .../sidechain_net_handler_bitcoin.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index 508d3e14..16baa862 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -46,7 +46,7 @@ std::string bitcoin_rpc_client::addmultisigaddress(const uint32_t nrequired, con params = params + pubkeys + std::string("]"); body = body + params + std::string(", null, \"p2sh-segwit\"] }"); - const auto reply = send_post_request(body, true); + const auto reply = send_post_request(body); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -115,7 +115,7 @@ std::string bitcoin_rpc_client::createmultisig(const uint32_t nrequired, const s params = params + pubkeys + std::string("]"); body = body + params + std::string(", \"p2sh-segwit\" ] }"); - const auto reply = send_post_request(body, true); + const auto reply = send_post_request(body); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -341,7 +341,7 @@ uint64_t bitcoin_rpc_client::estimatesmartfee(uint16_t conf_target) { "\"method\": \"estimatesmartfee\", \"params\": [" + std::to_string(conf_target) + std::string("] }")); - const auto reply = send_post_request(body, true); + const auto reply = send_post_request(body); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -460,7 +460,7 @@ std::string bitcoin_rpc_client::gettransaction(const std::string &txid, const bo "\"gettransaction\", \"params\": [\"" + txid + "\"] }"); - const auto reply = send_post_request(body, true); + const auto reply = send_post_request(body); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__)); @@ -609,7 +609,7 @@ std::string bitcoin_rpc_client::sendrawtransaction(const std::string &tx_hex) { "\"method\": \"sendrawtransaction\", \"params\": [") + std::string("\"") + tx_hex + std::string("\"") + std::string("] }"); - const auto reply = send_post_request(body, true); + const auto reply = send_post_request(body); if (reply.body.empty()) { wlog("Bitcoin RPC call ${function} failed", ("function", __FUNCTION__));