diff --git a/binding.gyp b/binding.gyp index 1910d429..0a194182 100644 --- a/binding.gyp +++ b/binding.gyp @@ -5,7 +5,6 @@ "sources": [ "src/main.cc", "src/cryptonote_basic/cryptonote_format_utils.cpp", - "src/offshore/pricing_record.cpp", "src/zephyr_oracle/pricing_record.cpp", "src/salvium_oracle/pricing_record.cpp", "src/crypto/tree-hash.c", diff --git a/src/cryptonote_basic/cryptonote_basic.h b/src/cryptonote_basic/cryptonote_basic.h index a23b0718..0097b59d 100644 --- a/src/cryptonote_basic/cryptonote_basic.h +++ b/src/cryptonote_basic/cryptonote_basic.h @@ -15,7 +15,6 @@ #include "serialization/vector.h" #include "serialization/binary_archive.h" #include "serialization/crypto.h" -#include "serialization/pricing_record.h" #include "serialization/zephyr_pricing_record.h" #include "serialization/keyvalue_serialization.h" // eepe named serialization #include "string_tools.h" @@ -27,7 +26,6 @@ #include "ringct/rctTypes.h" #include "cryptonote_protocol/blobdatatype.h" #include "cryptonote_protocol/enums.h" -#include "offshore/pricing_record.h" #include "zephyr_oracle/pricing_record.h" #include "salvium_oracle/pricing_record.h" #include "carrot_core/core_types.h" @@ -92,68 +90,6 @@ namespace cryptonote END_SERIALIZE() }; - // outputs <= HF_VERSION_VIEW_TAGS - struct txout_haven_key - { - txout_haven_key() { } - txout_haven_key(const crypto::public_key &_key, const std::string &_asset_type, const uint64_t &_unlock_time, const bool &_is_collateral, const bool &_is_collateral_change) : key(_key), asset_type(_asset_type), unlock_time(_unlock_time), is_collateral(_is_collateral), is_collateral_change(_is_collateral_change) { } - crypto::public_key key; - std::string asset_type; - uint64_t unlock_time; - bool is_collateral; - bool is_collateral_change; - - BEGIN_SERIALIZE_OBJECT() - FIELD(key) - FIELD(asset_type) - VARINT_FIELD(unlock_time) - FIELD(is_collateral) - FIELD(is_collateral_change) - END_SERIALIZE() - }; - - // outputs >= HF_VERSION_VIEW_TAGS - struct txout_haven_tagged_key - { - txout_haven_tagged_key() { } - txout_haven_tagged_key(const crypto::public_key &_key, const std::string &_asset_type, const uint64_t &_unlock_time, const bool &_is_collateral, const bool &_is_collateral_change, const crypto::view_tag &_view_tag) : key(_key), asset_type(_asset_type), unlock_time(_unlock_time), is_collateral(_is_collateral), is_collateral_change(_is_collateral_change), view_tag(_view_tag) { } - crypto::public_key key; - std::string asset_type; - uint64_t unlock_time; - bool is_collateral; - bool is_collateral_change; - crypto::view_tag view_tag; // optimization to reduce scanning time - - BEGIN_SERIALIZE_OBJECT() - FIELD(key) - FIELD(asset_type) - VARINT_FIELD(unlock_time) - FIELD(is_collateral) - FIELD(is_collateral_change) - FIELD(view_tag) - END_SERIALIZE() - }; - - struct txout_offshore - { - txout_offshore() { } - txout_offshore(const crypto::public_key &_key) : key(_key) { } - crypto::public_key key; - }; - - struct txout_xasset - { - txout_xasset() { } - txout_xasset(const crypto::public_key &_key, const std::string &_asset_type) : key(_key), asset_type(_asset_type) { } - crypto::public_key key; - std::string asset_type; - - BEGIN_SERIALIZE_OBJECT() - FIELD(key) - FIELD(asset_type) - END_SERIALIZE() - }; - // ZEPHYR struct txout_zephyr_tagged_key { @@ -276,62 +212,6 @@ namespace cryptonote END_SERIALIZE() }; - struct txin_offshore - { - uint64_t amount; - std::vector key_offsets; - crypto::key_image k_image; - - BEGIN_SERIALIZE_OBJECT() - VARINT_FIELD(amount) - FIELD(key_offsets) - FIELD(k_image) - END_SERIALIZE() - }; - - struct txin_onshore - { - uint64_t amount; - std::vector key_offsets; - crypto::key_image k_image; - - BEGIN_SERIALIZE_OBJECT() - VARINT_FIELD(amount) - FIELD(key_offsets) - FIELD(k_image) - END_SERIALIZE() - }; - - struct txin_haven_key - { - uint64_t amount; - std::string asset_type; - std::vector key_offsets; - crypto::key_image k_image; // double spending protection - - BEGIN_SERIALIZE_OBJECT() - VARINT_FIELD(amount) - FIELD(asset_type) - FIELD(key_offsets) - FIELD(k_image) - END_SERIALIZE() - }; - - struct txin_xasset - { - uint64_t amount; - std::string asset_type; - std::vector key_offsets; - crypto::key_image k_image; // double spending protection - - BEGIN_SERIALIZE_OBJECT() - VARINT_FIELD(amount) - FIELD(asset_type) - FIELD(key_offsets) - FIELD(k_image) - END_SERIALIZE() - }; - struct txin_zephyr_key { uint64_t amount; @@ -362,12 +242,11 @@ namespace cryptonote END_SERIALIZE() }; - typedef boost::variant txin_v; + typedef boost::variant txin_v; typedef boost::variant txin_zephyr_v; typedef boost::variant txin_salvium_v; typedef boost::variant txout_target_v; - typedef boost::variant txout_xhv_target_v; typedef boost::variant txout_salvium_target_v; typedef boost::variant txout_carrot_target_v; @@ -384,17 +263,6 @@ namespace cryptonote END_SERIALIZE() }; - struct tx_out_xhv - { - uint64_t amount; - txout_xhv_target_v target; - - BEGIN_SERIALIZE_OBJECT() - VARINT_FIELD(amount) - FIELD(target) - END_SERIALIZE() - }; - struct tx_out_zephyr { uint64_t amount; @@ -552,7 +420,6 @@ namespace cryptonote std::vector vin_zephyr; std::vector vin_salvium; std::vector vout; - std::vector vout_xhv; std::vector vout_zephyr; std::vector vout_salvium; //extra @@ -560,11 +427,9 @@ namespace cryptonote // Block height to use PR from uint64_t pricing_record_height; // Circulating supply information - std::vector offshore_data; uint64_t amount_burnt; uint64_t amount_minted; std::vector output_unlock_times; - std::vector collateral_indices; // SALVIUM-SPECIFIC FIELDS // TX type @@ -580,8 +445,6 @@ namespace cryptonote std::string source_asset_type; // Destination asset type (this is only necessary for CONVERT transactions) std::string destination_asset_type; - // Circulating supply information - already provided by Haven - //uint64_t amount_burnt; // Slippage limit uint64_t amount_slippage_limit; protocol_tx_data_t protocol_tx_data; @@ -608,251 +471,8 @@ namespace cryptonote }; BEGIN_SERIALIZE() - if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) { - VARINT_FIELD(version) - //if(version == 0 || CURRENT_TRANSACTION_VERSION < version) return false; - - // Only transactions prior to HAVEN_TYPES_TRANSACTION_VERSION are permitted to be anything other than HAVEN_TYPES and need translation - if (version < HAVEN_TYPES_TRANSACTION_VERSION) { - - if (version < POU_TRANSACTION_VERSION) { - VARINT_FIELD(unlock_time) - } - if (!typename Archive::is_saving()) { - FIELD(vin) - FIELD(vout_xhv) - FIELD(extra) - if(version >= OFFSHORE_TRANSACTION_VERSION) { - VARINT_FIELD(pricing_record_height) - if (version < 5) - FIELD(offshore_data) - if (version >= POU_TRANSACTION_VERSION) { - FIELD(output_unlock_times) - if (vout_xhv.size() != output_unlock_times.size()) { - return false; - } - } - VARINT_FIELD(amount_burnt) - VARINT_FIELD(amount_minted) - if (version >= COLLATERAL_TRANSACTION_VERSION && amount_burnt) { - FIELD(collateral_indices) - if (collateral_indices.size() != 2) { - return false; - } - for (const auto vout_idx: collateral_indices) { - if (vout_idx >= vout_xhv.size()) - return false; - } - } - } - std::vector vin_tmp(vin); - bool is_conversion_tx = (amount_burnt != 0); - bool is_offshore_tx = is_conversion_tx; - bool is_onshore_tx = false; - vin.clear(); - for (auto &vin_entry: vin_tmp) { - if (vin_entry.type() == typeid(txin_gen)) { - vin.push_back(vin_entry); - continue; - } - txin_haven_key in; - if (vin_entry.type() == typeid(txin_to_key)) { - in.asset_type = "XHV"; - in.amount = boost::get(vin_entry).amount; - in.key_offsets = boost::get(vin_entry).key_offsets; - in.k_image = boost::get(vin_entry).k_image; - } else if (vin_entry.type() == typeid(txin_offshore)) { - is_offshore_tx = false; - is_onshore_tx = false; - in.asset_type = "XUSD"; - in.amount = boost::get(vin_entry).amount; - in.key_offsets = boost::get(vin_entry).key_offsets; - in.k_image = boost::get(vin_entry).k_image; - } else if (vin_entry.type() == typeid(txin_onshore)) { - is_offshore_tx = false; - is_onshore_tx = true; - in.asset_type = "XUSD"; - in.amount = boost::get(vin_entry).amount; - in.key_offsets = boost::get(vin_entry).key_offsets; - in.k_image = boost::get(vin_entry).k_image; - } else if (vin_entry.type() == typeid(txin_xasset)) { - is_offshore_tx = false; - is_onshore_tx = false; - in.amount = boost::get(vin_entry).amount; - in.key_offsets = boost::get(vin_entry).key_offsets; - in.k_image = boost::get(vin_entry).k_image; - in.asset_type = boost::get(vin_entry).asset_type; - } else { - return false; - } - vin.push_back(in); - } - std::vector vout_tmp(vout_xhv); - vout_xhv.clear(); - for (size_t i=0; i(vout_tmp[i].target).key; - } else if (vout_tmp[i].target.type() == typeid(txout_offshore)) { - out.asset_type = "XUSD"; - out.key = boost::get(vout_tmp[i].target).key; - } else if (vout_tmp[i].target.type() == typeid(txout_xasset)) { - out.asset_type = boost::get(vout_tmp[i].target).asset_type; - out.key = boost::get(vout_tmp[i].target).key; - } else { - return false; - } - out.unlock_time = (version >= POU_TRANSACTION_VERSION) ? output_unlock_times[i] : unlock_time; - out.is_collateral = false; - out.is_collateral_change = false; - if (version >= COLLATERAL_TRANSACTION_VERSION && amount_burnt) { - if (((is_onshore_tx) && - (collateral_indices[0] == i)) || - ((!is_onshore_tx) && - (is_offshore_tx) && - (collateral_indices[0] == i && collateral_indices[1] == 0))) { - out.is_collateral = true; - } - if (is_onshore_tx && collateral_indices[1] == i) { - out.is_collateral_change = true; - } - } - tx_out_xhv foo; - foo.amount = vout_tmp[i].amount; - foo.target = out; - vout_xhv.push_back(foo); - } - return true; - } - bool is_offshore_tx = (amount_burnt != 0); - bool is_onshore_tx = false; - std::vector vin_tmp; - vin_tmp.reserve(vin.size()); - for (auto &vin_entry_v: vin) { - if (vin_entry_v.type() == typeid(txin_gen)) { - vin_tmp.push_back(vin_entry_v); - continue; - } - txin_haven_key vin_entry = boost::get(vin_entry_v); - if (vin_entry.asset_type == "XHV") { - txin_to_key in; - in.amount = vin_entry.amount; - in.key_offsets = vin_entry.key_offsets; - in.k_image = vin_entry.k_image; - vin_tmp.push_back(in); - } else if (vin_entry.asset_type == "XUSD") { - is_offshore_tx = false; - int xhv_outputs = std::count_if(vout_xhv.begin(), vout_xhv.end(), [](tx_out_xhv &foo_v) { - if (foo_v.target.type() == typeid(txout_haven_key)) { - txout_haven_key out = boost::get(foo_v.target); - return out.asset_type == "XHV"; - } else if (foo_v.target.type() == typeid(txout_haven_tagged_key)) { - txout_haven_tagged_key out = boost::get(foo_v.target); - return out.asset_type == "XHV"; - } else { - return false; - } - }); - if (xhv_outputs) { - is_onshore_tx = true; - txin_onshore in; - in.amount = vin_entry.amount; - in.key_offsets = vin_entry.key_offsets; - in.k_image = vin_entry.k_image; - vin_tmp.push_back(in); - } else { - txin_offshore in; - in.amount = vin_entry.amount; - in.key_offsets = vin_entry.key_offsets; - in.k_image = vin_entry.k_image; - vin_tmp.push_back(in); - } - } else { - is_offshore_tx = false; - txin_xasset in; - in.amount = vin_entry.amount; - in.asset_type = vin_entry.asset_type; - in.key_offsets = vin_entry.key_offsets; - in.k_image = vin_entry.k_image; - vin_tmp.push_back(in); - } - } - std::vector vout_tmp; - vout_tmp.reserve(vout_xhv.size()); - output_unlock_times.resize(vout_xhv.size()); - std::vector collateral_indices_temp; - collateral_indices_temp.resize(2); - for (size_t i=0; i(vout_xhv[i].target); - tx_out_xhv foo; - foo.amount = vout_xhv[i].amount; - if (outhk.asset_type == "XHV") { - txout_to_key out; - out.key = outhk.key; - foo.target = out; - } else if (outhk.asset_type == "XUSD") { - txout_offshore out; - out.key = outhk.key; - foo.target = out; - } else { - txout_xasset out; - out.asset_type = outhk.asset_type; - out.key = outhk.key; - foo.target = out; - } - output_unlock_times[i] = outhk.unlock_time; - if (outhk.is_collateral) { - collateral_indices_temp[0] = i; - } else if (outhk.is_collateral_change) { - collateral_indices_temp[1] = i; - } - vout_tmp.push_back(foo); - } - FIELD_N("vin", vin_tmp) - FIELD_N("vout", vout_tmp) - FIELD(extra) - if(version >= OFFSHORE_TRANSACTION_VERSION) { - VARINT_FIELD(pricing_record_height) - if (version < 5) - FIELD(offshore_data) - if (version >= POU_TRANSACTION_VERSION) { - FIELD(output_unlock_times) - if (vout_xhv.size() != output_unlock_times.size()) { - return false; - } - } - VARINT_FIELD(amount_burnt) - VARINT_FIELD(amount_minted) - if (version >= COLLATERAL_TRANSACTION_VERSION && amount_burnt) { - if (collateral_indices.size() != 2) { - if ((is_offshore_tx || is_onshore_tx) && collateral_indices_temp.size() != 2) { - return false; - } - if (is_offshore_tx || is_onshore_tx) { - collateral_indices = collateral_indices_temp; - } else { - collateral_indices.clear(); - collateral_indices.push_back(0); - collateral_indices.push_back(0); - } - } - FIELD(collateral_indices) - for (const auto vout_idx: collateral_indices) { - if (vout_idx >= vout_xhv.size()) - return false; - } - } - } - return true; - } - - FIELD(vin) - FIELD(vout_xhv) - FIELD(extra) - VARINT_FIELD(pricing_record_height) - VARINT_FIELD(amount_burnt) - VARINT_FIELD(amount_minted) + if (!is_supported_blob_type(blob_type)) { + return false; } else if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) { @@ -1001,9 +621,7 @@ namespace cryptonote { ar.begin_object(); bool r; - if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) - r = rct_signatures.serialize_rctsig_base(ar, vin.size(), vout_xhv.size()); - else if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) + if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) r = rct_signatures.serialize_rctsig_base(ar, vin_zephyr.size(), vout_zephyr.size()); else if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) r = rct_signatures.serialize_rctsig_base(ar, vin_salvium.size(), vout_salvium.size()); @@ -1021,15 +639,6 @@ namespace cryptonote } else if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) { r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin_salvium.size(), vout_salvium.size(), vin_salvium[0].type() == typeid(txin_salvium_key) ? boost::get(vin_salvium[0]).key_offsets.size() - 1 : 0); - } else if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) { - r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout_xhv.size(), - vin.size() > 0 && vin[0].type() == typeid(txin_to_key) ? boost::get(vin[0]).key_offsets.size() - 1 : - vin.size() > 0 && vin[0].type() == typeid(txin_offshore) ? boost::get(vin[0]).key_offsets.size() - 1 : - vin.size() > 0 && vin[0].type() == typeid(txin_onshore) ? boost::get(vin[0]).key_offsets.size() - 1 : - vin.size() > 0 && vin[0].type() == typeid(txin_xasset) ? boost::get(vin[0]).key_offsets.size() - 1 : - vin.size() > 0 && vin[0].type() == typeid(txin_haven_key) ? boost::get(vin[0]).key_offsets.size() - 1 : - 0 - ); } else { r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout.size(), vin[0].type() == typeid(txin_to_key) ? boost::get(vin[0]).key_offsets.size() - 1 : 0); @@ -1065,16 +674,13 @@ namespace cryptonote vin.clear(); vin_zephyr.clear(); vout.clear(); - vout_xhv.clear(); vout_zephyr.clear(); extra.clear(); signatures.clear(); pricing_record_height = 0; - offshore_data.clear(); amount_burnt = 0; amount_minted = 0; output_unlock_times.clear(); - collateral_indices.clear(); // SAL sal_tx_type = cryptonote::salvium_transaction_type::UNSET; return_address = cryptonote::null_pkey; @@ -1104,10 +710,6 @@ namespace cryptonote size_t operator()(const txin_to_script& txin) const{return 0;} size_t operator()(const txin_to_scripthash& txin) const{return 0;} size_t operator()(const txin_to_key& txin) const {return txin.key_offsets.size();} - size_t operator()(const txin_offshore& txin) const {return txin.key_offsets.size();} - size_t operator()(const txin_onshore& txin) const {return txin.key_offsets.size();} - size_t operator()(const txin_xasset& txin) const {return txin.key_offsets.size();} - size_t operator()(const txin_haven_key& txin) const {return txin.key_offsets.size();} size_t operator()(const txin_zephyr_key& txin) const {return txin.key_offsets.size();} }; @@ -1249,7 +851,6 @@ namespace cryptonote crypto::hash prev_id; uint64_t nonce; uint64_t nonce8; - offshore::pricing_record pricing_record; zephyr_oracle::pricing_record zephyr_pricing_record; salvium_oracle::pricing_record salvium_pricing_record; crypto::cycle cycle; @@ -1276,9 +877,7 @@ namespace cryptonote if (blob_type == BLOB_TYPE_CRYPTONOTE_XTNC || blob_type == BLOB_TYPE_CRYPTONOTE_CUCKOO) FIELD(cycle) if (blob_type == BLOB_TYPE_CRYPTONOTE_TUBE) FIELD(cycle40) if (blob_type == BLOB_TYPE_CRYPTONOTE_XTA) FIELD(cycle48) - if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) { - FIELD(pricing_record) - } else if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) { + if (blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) { if (major_version >= 255) FIELD(salvium_pricing_record) } else if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) { if (major_version >= 6) @@ -1421,7 +1020,6 @@ namespace cryptonote } BLOB_SERIALIZER(cryptonote::txout_to_key); -BLOB_SERIALIZER(cryptonote::txout_offshore); BLOB_SERIALIZER(cryptonote::txout_to_scripthash); VARIANT_TAG(binary_archive, cryptonote::txin_gen, 0xff); @@ -1429,11 +1027,7 @@ VARIANT_TAG(binary_archive, cryptonote::txin_to_script, 0x0); VARIANT_TAG(binary_archive, cryptonote::txin_to_scripthash, 0x1); VARIANT_TAG(binary_archive, cryptonote::txin_to_key, 0x2); VARIANT_TAG(binary_archive, cryptonote::txin_zephyr_key, 0x2); -VARIANT_TAG(binary_archive, cryptonote::txin_offshore, 0x3); VARIANT_TAG(binary_archive, cryptonote::txin_salvium_key, 0x2); -VARIANT_TAG(binary_archive, cryptonote::txin_onshore, 0x4); -VARIANT_TAG(binary_archive, cryptonote::txin_xasset, 0x5); -VARIANT_TAG(binary_archive, cryptonote::txin_haven_key, 0x6); VARIANT_TAG(binary_archive, cryptonote::txout_to_script, 0x0); VARIANT_TAG(binary_archive, cryptonote::txout_to_scripthash, 0x1); VARIANT_TAG(binary_archive, cryptonote::txout_to_key, 0x2); @@ -1441,14 +1035,10 @@ VARIANT_TAG(binary_archive, cryptonote::txout_salvium_key, 0x2); VARIANT_TAG(binary_archive, cryptonote::txout_zephyr_tagged_key, 0x2); VARIANT_TAG(binary_archive, cryptonote::txout_to_tagged_key, 0x3); VARIANT_TAG(binary_archive, cryptonote::txout_salvium_tagged_key, 0x3); -VARIANT_TAG(binary_archive, cryptonote::txout_offshore, 0x3); VARIANT_TAG(binary_archive, cryptonote::txout_to_carrot_v1, 0x4); VARIANT_TAG(binary_archive, cryptonote::protocol_tx_data_t, 0x0); VARIANT_TAG(binary_archive, cryptonote::token_metadata_t, 0x0); VARIANT_TAG(binary_archive, cryptonote::erc_token_t, 0x0); VARIANT_TAG(binary_archive, cryptonote::sal_token_t, 0x1); -VARIANT_TAG(binary_archive, cryptonote::txout_xasset, 0x5); -VARIANT_TAG(binary_archive, cryptonote::txout_haven_key, 0x6); -VARIANT_TAG(binary_archive, cryptonote::txout_haven_tagged_key, 0x7); VARIANT_TAG(binary_archive, cryptonote::transaction, 0xcc); VARIANT_TAG(binary_archive, cryptonote::block, 0xbb); diff --git a/src/cryptonote_basic/cryptonote_format_utils.cpp b/src/cryptonote_basic/cryptonote_format_utils.cpp index 64a399c2..ec18557b 100644 --- a/src/cryptonote_basic/cryptonote_format_utils.cpp +++ b/src/cryptonote_basic/cryptonote_format_utils.cpp @@ -226,7 +226,7 @@ namespace cryptonote std::stringstream ss; binary_archive ba(ss); const size_t inputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM ? t.vin_salvium.size() : (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vin_zephyr.size() : t.vin.size()); - const size_t outputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM ? t.vout_salvium.size() : (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vout_zephyr.size() : (t.blob_type != BLOB_TYPE_CRYPTONOTE_XHV ? t.vout.size() : t.vout_xhv.size())); + const size_t outputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM ? t.vout_salvium.size() : (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vout_zephyr.size() : t.vout.size()); bool r = tt.rct_signatures.serialize_rctsig_base(ba, inputs, outputs); CHECK_AND_ASSERT_MES(r, false, "Failed to serialize rct signatures base"); cryptonote::get_blob_hash(ss.str(), hashes[1]); @@ -242,20 +242,12 @@ namespace cryptonote std::stringstream ss; binary_archive ba(ss); const size_t inputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM ? t.vin_salvium.size() : (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vin_zephyr.size() : t.vin.size()); - const size_t outputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM ? t.vout_salvium.size() : (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vout_zephyr.size() : (t.blob_type != BLOB_TYPE_CRYPTONOTE_XHV ? t.vout.size() : t.vout_xhv.size())); + const size_t outputs = t.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM ? t.vout_salvium.size() : (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR ? t.vout_zephyr.size() : t.vout.size()); size_t mixin; if (t.blob_type == BLOB_TYPE_CRYPTONOTE_SALVIUM) { mixin = t.vin_salvium.empty() ? 0 : t.vin_salvium[0].type() == typeid(txin_salvium_key) ? boost::get(t.vin_salvium[0]).key_offsets.size() - 1 : 0; } else if (t.blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) { mixin = t.vin_zephyr.empty() ? 0 : t.vin_zephyr[0].type() == typeid(txin_zephyr_key) ? boost::get(t.vin_zephyr[0]).key_offsets.size() - 1 : 0; - } else if (t.blob_type == BLOB_TYPE_CRYPTONOTE_XHV) { - mixin = t.vin.empty() ? 0 : - t.vin[0].type() == typeid(txin_to_key) ? boost::get(t.vin[0]).key_offsets.size() - 1 : - t.vin[0].type() == typeid(txin_offshore) ? boost::get(t.vin[0]).key_offsets.size() - 1 : - t.vin[0].type() == typeid(txin_onshore) ? boost::get(t.vin[0]).key_offsets.size() - 1 : - t.vin[0].type() == typeid(txin_xasset) ? boost::get(t.vin[0]).key_offsets.size() - 1 : - t.vin[0].type() == typeid(txin_haven_key) ? boost::get(t.vin[0]).key_offsets.size() - 1 : - 0; } else { mixin = t.vin.empty() ? 0 : t.vin[0].type() == typeid(txin_to_key) ? boost::get(t.vin[0]).key_offsets.size() - 1 : 0; } diff --git a/src/cryptonote_basic/tx_extra.h b/src/cryptonote_basic/tx_extra.h index 3d638b02..0cae3bb0 100644 --- a/src/cryptonote_basic/tx_extra.h +++ b/src/cryptonote_basic/tx_extra.h @@ -32,7 +32,6 @@ #define TX_EXTRA_PADDING_MAX_COUNT 255 #define TX_EXTRA_NONCE_MAX_COUNT 255 -#define TX_EXTRA_OFFSHORE_MAX_COUNT 255 #define TX_EXTRA_MEMO_MAX_COUNT 255 #define TX_EXTRA_TAG_PADDING 0x00 @@ -40,7 +39,6 @@ #define TX_EXTRA_NONCE 0x02 #define TX_EXTRA_MERGE_MINING_TAG 0x03 #define TX_EXTRA_TAG_ADDITIONAL_PUBKEYS 0x04 -#define TX_EXTRA_TAG_OFFSHORE 0x17 #define TX_EXTRA_TAG_MEMO 0x18 #define TX_EXTRA_TAG_SERVICE_NODE_REGISTER 0x70 #define TX_EXTRA_TAG_SERVICE_NODE_STATE_CHANGE 0x71 @@ -203,15 +201,6 @@ namespace cryptonote END_SERIALIZE() }; - struct tx_extra_offshore - { - std::string data; - - BEGIN_SERIALIZE() - FIELD(data) - END_SERIALIZE() - }; - struct tx_extra_memo { // Actual memo data as string @@ -376,7 +365,6 @@ namespace cryptonote tx_extra_merge_mining_tag, tx_extra_additional_pub_keys, tx_extra_mysterious_minergate, - tx_extra_offshore, tx_extra_memo, tx_extra_service_node_pubkey, tx_extra_service_node_register, @@ -399,7 +387,6 @@ VARIANT_TAG(binary_archive, cryptonote::tx_extra_nonce, TX_E VARIANT_TAG(binary_archive, cryptonote::tx_extra_merge_mining_tag, TX_EXTRA_MERGE_MINING_TAG); VARIANT_TAG(binary_archive, cryptonote::tx_extra_additional_pub_keys, TX_EXTRA_TAG_ADDITIONAL_PUBKEYS); VARIANT_TAG(binary_archive, cryptonote::tx_extra_mysterious_minergate, TX_EXTRA_MYSTERIOUS_MINERGATE_TAG); -VARIANT_TAG(binary_archive, cryptonote::tx_extra_offshore, TX_EXTRA_TAG_OFFSHORE); VARIANT_TAG(binary_archive, cryptonote::tx_extra_memo, TX_EXTRA_TAG_MEMO); VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_register, TX_EXTRA_TAG_SERVICE_NODE_REGISTER); VARIANT_TAG(binary_archive, cryptonote::tx_extra_service_node_state_change, TX_EXTRA_TAG_SERVICE_NODE_STATE_CHANGE); diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 754f6095..1029358c 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -1,26 +1,12 @@ #pragma once #define CURRENT_TRANSACTION_VERSION 1 -#define POU_TRANSACTION_VERSION 6 -#define COLLATERAL_TRANSACTION_VERSION 7 -#define HAVEN_TYPES_TRANSACTION_VERSION 8 -#define OFFSHORE_TRANSACTION_VERSION 3 -#define HF_VERSION_XASSET_FEES_V2 17 -#define HF_VERSION_HAVEN2 18 -#define HF_VERSION_USE_COLLATERAL 20 #define HF_VERSION_ENABLE_N_OUTS 2 #define TRANSACTION_VERSION_N_OUTS 3 #define TRANSACTION_VERSION_CARROT 4 #define TRANSACTION_VERSION_ENABLE_TOKENS 5 // UNLOCK TIMES -#define TX_V6_OFFSHORE_UNLOCK_BLOCKS 21*720 // 21 day unlock time -#define TX_V6_ONSHORE_UNLOCK_BLOCKS 360 // 12 hour unlock time -#define TX_V7_ONSHORE_UNLOCK_BLOCKS 21*720 // 21 day unlock time -#define TX_V6_XASSET_UNLOCK_BLOCKS 1440 // 2 day unlock time -#define TX_V6_OFFSHORE_UNLOCK_BLOCKS_TESTNET 60 // 2 hour unlock time - FOR TESTING ONLY -#define TX_V6_ONSHORE_UNLOCK_BLOCKS_TESTNET 30 // 1 hour unlock time - FOR TESTING ONLY -#define TX_V6_XASSET_UNLOCK_BLOCKS_TESTNET 60 // 2 hour unlock time - FOR TESTING ONLY #define PRICING_RECORD_VALID_TIME_DIFF_FROM_BLOCK 120 // seconds @@ -36,10 +22,33 @@ enum BLOB_TYPE { BLOB_TYPE_CRYPTONOTE_CUCKOO = 8, // MoneroV / Swap BLOB_TYPE_CRYPTONOTE_XTNC = 9, // XTNC BLOB_TYPE_CRYPTONOTE_TUBE = 10, // TUBE - BLOB_TYPE_CRYPTONOTE_XHV = 11, // Haven BLOB_TYPE_CRYPTONOTE_XTA = 12, // ITALO BLOB_TYPE_CRYPTONOTE_ZEPHYR = 13, // ZEPHYR BLOB_TYPE_CRYPTONOTE_XLA = 14, // XLA BLOB_TYPE_CRYPTONOTE_SALVIUM= 15, // Salvium BLOB_TYPE_CRYPTONOTE_ARQMA = 16 // Arqma }; + +inline bool is_supported_blob_type(enum BLOB_TYPE blob_type) { + switch (blob_type) { + case BLOB_TYPE_CRYPTONOTE: + case BLOB_TYPE_FORKNOTE1: + case BLOB_TYPE_FORKNOTE2: + case BLOB_TYPE_CRYPTONOTE2: + case BLOB_TYPE_CRYPTONOTE_RYO: + case BLOB_TYPE_CRYPTONOTE_LOKI: + case BLOB_TYPE_CRYPTONOTE3: + case BLOB_TYPE_AEON: + case BLOB_TYPE_CRYPTONOTE_CUCKOO: + case BLOB_TYPE_CRYPTONOTE_XTNC: + case BLOB_TYPE_CRYPTONOTE_TUBE: + case BLOB_TYPE_CRYPTONOTE_XTA: + case BLOB_TYPE_CRYPTONOTE_ZEPHYR: + case BLOB_TYPE_CRYPTONOTE_XLA: + case BLOB_TYPE_CRYPTONOTE_SALVIUM: + case BLOB_TYPE_CRYPTONOTE_ARQMA: + return true; + default: + return false; + } +} diff --git a/src/main.cc b/src/main.cc index 5b69ab9d..83c9b1e6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -42,6 +42,10 @@ inline void SetExport(Isolate* isolate, Local target, const char* name, ).Check(); } +inline void ThrowUnsupportedBlobType(Isolate* isolate) { + ThrowError(isolate, "Unsupported blob type."); +} + } // namespace // cryptonote::append_mm_tag_to_extra writes byte with TX_EXTRA_MERGE_MINING_TAG (1 here) and VARINT DEPTH (2 here) @@ -171,6 +175,7 @@ void convert_blob(const FunctionCallbackInfo& info) { // (parentBlockBuff if (!info[1]->IsNumber()) return ThrowError(isolate, "Argument 2 should be a number"); blob_type = static_cast(ToInt32(isolate, info[1])); } + if (!is_supported_blob_type(blob_type)) return ThrowUnsupportedBlobType(isolate); block b = AUTO_VAL_INIT(b); b.set_blob_type(blob_type); @@ -201,6 +206,7 @@ void get_block_id(const FunctionCallbackInfo& info) { if (!info[1]->IsNumber()) return ThrowError(isolate, "Argument 2 should be a number"); blob_type = static_cast(ToInt32(isolate, info[1])); } + if (!is_supported_blob_type(blob_type)) return ThrowUnsupportedBlobType(isolate); block b = AUTO_VAL_INIT(b); b.set_blob_type(blob_type); @@ -228,6 +234,7 @@ void construct_block_blob(const FunctionCallbackInfo& info) { // (parentB if (!info[2]->IsNumber()) return ThrowError(isolate, "Argument 3 should be a number"); blob_type = static_cast(ToInt32(isolate, info[2])); } + if (!is_supported_blob_type(blob_type)) return ThrowUnsupportedBlobType(isolate); if (Buffer::Length(nonce_buf) != (blob_type == BLOB_TYPE_AEON ? 8 : 4)) return ThrowError(isolate, "Nonce buffer has invalid size."); @@ -346,6 +353,7 @@ void construct_mm_parent_block_blob(const FunctionCallbackInfo& info) { / if (!Buffer::HasInstance(child_target)) return ThrowError(isolate, "Third argument should be a buffer object."); const enum BLOB_TYPE blob_type = static_cast(ToInt32(isolate, info[1])); + if (!is_supported_blob_type(blob_type)) return ThrowUnsupportedBlobType(isolate); blobdata input = std::string(Buffer::Data(target), Buffer::Length(target)); blobdata child_input = std::string(Buffer::Data(child_target), Buffer::Length(child_target)); @@ -382,6 +390,7 @@ void construct_mm_child_block_blob(const FunctionCallbackInfo& info) { // if (!Buffer::HasInstance(child_block_template_buf)) return ThrowError(isolate, "Third argument should be a buffer object."); const enum BLOB_TYPE blob_type = static_cast(ToInt32(isolate, info[1])); + if (!is_supported_blob_type(blob_type)) return ThrowUnsupportedBlobType(isolate); blobdata block_template_blob = std::string(Buffer::Data(block_template_buf), Buffer::Length(block_template_buf)); blobdata child_block_template_blob = std::string(Buffer::Data(child_block_template_buf), Buffer::Length(child_block_template_buf)); diff --git a/src/offshore/asset_types.h b/src/offshore/asset_types.h deleted file mode 100644 index e179d54e..00000000 --- a/src/offshore/asset_types.h +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) 2021, Haven Protocol -// 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 -#include -#include - -namespace offshore { - - const std::vector ASSET_TYPES = {"XHV", "XAG", "XAU", "XAUD", "XBTC", "XCAD", "XCHF", "XCNY", "XEUR", "XGBP", "XJPY", "XNOK", "XNZD", "XUSD"}; - - class asset_type_counts - { - - public: - - // Fields - uint64_t XHV; - uint64_t XAG; - uint64_t XAU; - uint64_t XAUD; - uint64_t XBTC; - uint64_t XCAD; - uint64_t XCHF; - uint64_t XCNY; - uint64_t XEUR; - uint64_t XGBP; - uint64_t XJPY; - uint64_t XNOK; - uint64_t XNZD; - uint64_t XUSD; - - asset_type_counts() noexcept - : XHV(0) - , XAG(0) - , XAU(0) - , XAUD(0) - , XBTC(0) - , XCAD(0) - , XCHF(0) - , XCNY(0) - , XEUR(0) - , XGBP(0) - , XJPY(0) - , XNOK(0) - , XNZD(0) - , XUSD(0) - { - } - - uint64_t operator[](const std::string asset_type) const noexcept - { - if (asset_type == "XHV") { - return XHV; - } else if (asset_type == "XUSD") { - return XUSD; - } else if (asset_type == "XAG") { - return XAG; - } else if (asset_type == "XAU") { - return XAU; - } else if (asset_type == "XAUD") { - return XAUD; - } else if (asset_type == "XBTC") { - return XBTC; - } else if (asset_type == "XCAD") { - return XCAD; - } else if (asset_type == "XCHF") { - return XCHF; - } else if (asset_type == "XCNY") { - return XCNY; - } else if (asset_type == "XEUR") { - return XEUR; - } else if (asset_type == "XGBP") { - return XGBP; - } else if (asset_type == "XJPY") { - return XJPY; - } else if (asset_type == "XNOK") { - return XNOK; - } else if (asset_type == "XNZD") { - return XNZD; - } - - return 0; - } - - void add(const std::string asset_type, const uint64_t val) - { - if (asset_type == "XHV") { - XHV += val; - } else if (asset_type == "XUSD") { - XUSD += val; - } else if (asset_type == "XAG") { - XAG += val; - } else if (asset_type == "XAU") { - XAU += val; - } else if (asset_type == "XAUD") { - XAUD += val; - } else if (asset_type == "XBTC") { - XBTC += val; - } else if (asset_type == "XCAD") { - XCAD += val; - } else if (asset_type == "XCHF") { - XCHF += val; - } else if (asset_type == "XCNY") { - XCNY += val; - } else if (asset_type == "XEUR") { - XEUR += val; - } else if (asset_type == "XGBP") { - XGBP += val; - } else if (asset_type == "XJPY") { - XJPY += val; - } else if (asset_type == "XNOK") { - XNOK += val; - } else if (asset_type == "XNZD") { - XNZD += val; - } - } - }; -} diff --git a/src/offshore/pricing_record.cpp b/src/offshore/pricing_record.cpp deleted file mode 100644 index e293d193..00000000 --- a/src/offshore/pricing_record.cpp +++ /dev/null @@ -1,452 +0,0 @@ -// Copyright (c) 2019, Haven Protocol -// 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. -// -// Portions of this code based upon code Copyright (c) 2019, The Monero Project - -#include "pricing_record.h" - -#include "serialization/keyvalue_serialization.h" -#include "storages/portable_storage.h" - -#include "string_tools.h" -namespace offshore -{ - - namespace - { - struct pr_serialized - { - uint64_t xAG; - uint64_t xAU; - uint64_t xAUD; - uint64_t xBTC; - uint64_t xCAD; - uint64_t xCHF; - uint64_t xCNY; - uint64_t xEUR; - uint64_t xGBP; - uint64_t xJPY; - uint64_t xNOK; - uint64_t xNZD; - uint64_t xUSD; - uint64_t unused1; - uint64_t unused2; - uint64_t unused3; - uint64_t timestamp; - std::string signature; - - BEGIN_KV_SERIALIZE_MAP() - KV_SERIALIZE(xAG) - KV_SERIALIZE(xAU) - KV_SERIALIZE(xAUD) - KV_SERIALIZE(xBTC) - KV_SERIALIZE(xCAD) - KV_SERIALIZE(xCHF) - KV_SERIALIZE(xCNY) - KV_SERIALIZE(xEUR) - KV_SERIALIZE(xGBP) - KV_SERIALIZE(xJPY) - KV_SERIALIZE(xNOK) - KV_SERIALIZE(xNZD) - KV_SERIALIZE(xUSD) - KV_SERIALIZE(unused1) - KV_SERIALIZE(unused2) - KV_SERIALIZE(unused3) - KV_SERIALIZE(timestamp) - KV_SERIALIZE(signature) - END_KV_SERIALIZE_MAP() - }; - } - - pricing_record::pricing_record() noexcept - : xAG(0) - , xAU(0) - , xAUD(0) - , xBTC(0) - , xCAD(0) - , xCHF(0) - , xCNY(0) - , xEUR(0) - , xGBP(0) - , xJPY(0) - , xNOK(0) - , xNZD(0) - , xUSD(0) - , unused1(0) - , unused2(0) - , unused3(0) - , timestamp(0) - { - std::memset(signature, 0, sizeof(signature)); - } - - bool pricing_record::_load(epee::serialization::portable_storage& src, epee::serialization::section* hparent) - { - pr_serialized in{}; - if (in._load(src, hparent)) - { - // Copy everything into the local instance - xAG = in.xAG; - xAU = in.xAU; - xAUD = in.xAUD; - xBTC = in.xBTC; - xCAD = in.xCAD; - xCHF = in.xCHF; - xCNY = in.xCNY; - xEUR = in.xEUR; - xGBP = in.xGBP; - xJPY = in.xJPY; - xNOK = in.xNOK; - xNZD = in.xNZD; - xUSD = in.xUSD; - unused1 = in.unused1; - unused2 = in.unused2; - unused3 = in.unused3; - timestamp = in.timestamp; - for (unsigned int i = 0; i < in.signature.length(); i += 2) { - std::string byteString = in.signature.substr(i, 2); - signature[i>>1] = (char) strtol(byteString.c_str(), NULL, 16); - } - return true; - } - - // Report error here? - return false; - } - - bool pricing_record::store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const - { - std::string sig_hex; - for (unsigned int i=0; i<64; i++) { - std::stringstream ss; - ss << std::hex << std::setw(2) << std::setfill('0') << (0xff & signature[i]); - sig_hex += ss.str(); - } - const pr_serialized out{xAG,xAU,xAUD,xBTC,xCAD,xCHF,xCNY,xEUR,xGBP,xJPY,xNOK,xNZD,xUSD,unused1,unused2,unused3,timestamp,sig_hex}; - return out.store(dest, hparent); - } - - pricing_record::pricing_record(const pricing_record& orig) noexcept - : xAG(orig.xAG) - , xAU(orig.xAU) - , xAUD(orig.xAUD) - , xBTC(orig.xBTC) - , xCAD(orig.xCAD) - , xCHF(orig.xCHF) - , xCNY(orig.xCNY) - , xEUR(orig.xEUR) - , xGBP(orig.xGBP) - , xJPY(orig.xJPY) - , xNOK(orig.xNOK) - , xNZD(orig.xNZD) - , xUSD(orig.xUSD) - , unused1(orig.unused1) - , unused2(orig.unused2) - , unused3(orig.unused3) - , timestamp(orig.timestamp) - { - std::memcpy(signature, orig.signature, sizeof(signature)); - } - - pricing_record& pricing_record::operator=(const pricing_record& orig) noexcept - { - xAG = orig.xAG; - xAU = orig.xAU; - xAUD = orig.xAUD; - xBTC = orig.xBTC; - xCAD = orig.xCAD; - xCHF = orig.xCHF; - xCNY = orig.xCNY; - xEUR = orig.xEUR; - xGBP = orig.xGBP; - xJPY = orig.xJPY; - xNOK = orig.xNOK; - xNZD = orig.xNZD; - xUSD = orig.xUSD; - unused1 = orig.unused1; - unused2 = orig.unused2; - unused3 = orig.unused3; - timestamp = orig.timestamp; - ::memcpy(signature, orig.signature, sizeof(signature)); - return *this; - } - - uint64_t pricing_record::operator[](const std::string& asset_type) const - { - if (asset_type == "XHV") { - return 1000000000000; - } else if (asset_type == "XUSD") { - return unused1; - } else if (asset_type == "XAG") { - return xAG; - } else if (asset_type == "XAU") { - return xAU; - } else if (asset_type == "XAUD") { - return xAUD; - } else if (asset_type == "XBTC") { - return xBTC; - } else if (asset_type == "XCAD") { - return xCAD; - } else if (asset_type == "XCHF") { - return xCHF; - } else if (asset_type == "XCNY") { - return xCNY; - } else if (asset_type == "XEUR") { - return xEUR; - } else if (asset_type == "XGBP") { - return xGBP; - } else if (asset_type == "XJPY") { - return xJPY; - } else if (asset_type == "XNOK") { - return xNOK; - } else if (asset_type == "XNZD") { - return xNZD; - } else { - CHECK_AND_ASSERT_THROW_MES(false, "Asset type doesn't exist in pricing record!"); - } - } - - bool pricing_record::equal(const pricing_record& other) const noexcept - { - return ((xAG == other.xAG) && - (xAU == other.xAU) && - (xAUD == other.xAUD) && - (xBTC == other.xBTC) && - (xCAD == other.xCAD) && - (xCHF == other.xCHF) && - (xCNY == other.xCNY) && - (xEUR == other.xEUR) && - (xGBP == other.xGBP) && - (xJPY == other.xJPY) && - (xNOK == other.xNOK) && - (xNZD == other.xNZD) && - (xUSD == other.xUSD) && - (unused1 == other.unused1) && - (unused2 == other.unused2) && - (unused3 == other.unused3) && - (timestamp == other.timestamp) && - !::memcmp(signature, other.signature, sizeof(signature))); - } - - bool pricing_record::empty() const noexcept - { - const pricing_record empty_pr = offshore::pricing_record(); - return (*this).equal(empty_pr); - } - - bool pricing_record::verifySignature(const std::string& public_key) const - { - CHECK_AND_ASSERT_THROW_MES(!public_key.empty(), "Pricing record verification failed. NULL public key. PK Size: " << public_key.size()); // TODO: is this necessary or the one below already covers this case, meannin it will produce empty pubkey? - - // extract the key - EVP_PKEY* pubkey; - BIO* bio = BIO_new_mem_buf(public_key.c_str(), public_key.size()); - if (!bio) { - return false; - } - pubkey = PEM_read_bio_PUBKEY(bio, NULL, NULL, NULL); - BIO_free(bio); - CHECK_AND_ASSERT_THROW_MES(pubkey != NULL, "Pricing record verification failed. NULL public key."); - - - // Convert our internal 64-byte binary representation into 128-byte hex string - std::string sig_hex; - for (unsigned int i=0; i<64; i++) { - std::stringstream ss; - ss << std::hex << std::setw(2) << std::setfill('0') << (0xff & signature[i]); - sig_hex += ss.str(); - } - - // Rebuild the OpenSSL format of the signature from the r+s values - std::string sig_rebuilt = "30"; - std::string r_rebuilt = (signature[0] == 0) ? sig_hex.substr(2, 62) : sig_hex.substr(0,64); - if (signature[(signature[0] == 0) ? 1 : 0] & 0x80) - r_rebuilt = "00" + r_rebuilt; - std::string s_rebuilt = (signature[(signature[32] == 0) ? 33 : 32] == 0) ? sig_hex.substr(66, 62) : sig_hex.substr(64,64); - if (signature[(signature[32] == 0) ? 33 : 32] & 0x80) - s_rebuilt = "00" + s_rebuilt; - size_t sig_length = (r_rebuilt.length() + s_rebuilt.length() + 8) >> 1; - std::stringstream ss; - ss << std::hex << sig_length; - sig_rebuilt += std::string(2-ss.str().length(), '0') + ss.str(); - ss.clear(); - sig_rebuilt += "02"; - size_t r_length = r_rebuilt.length() >> 1; - std::stringstream ss2; - ss2 << std::hex << r_length; - sig_rebuilt += std::string(2-ss2.str().length(), '0') + ss2.str(); - ss2.clear(); - sig_rebuilt += r_rebuilt; - sig_rebuilt += "02"; - size_t s_length = s_rebuilt.length() >> 1; - std::stringstream ss3; - ss3 << std::hex << s_length; - sig_rebuilt += std::string(2-ss3.str().length(), '0') + ss3.str(); - ss3.clear(); - sig_rebuilt += s_rebuilt; - - // Build the JSON string, so that we can verify the signature - std::ostringstream oss; - oss << "{\"xAG\":" << xAG; - oss << ",\"xAU\":" << xAU; - oss << ",\"xAUD\":" << xAUD; - oss << ",\"xBTC\":" << xBTC; - oss << ",\"xCAD\":" << xCAD; - oss << ",\"xCHF\":" << xCHF; - oss << ",\"xCNY\":" << xCNY; - oss << ",\"xEUR\":" << xEUR; - oss << ",\"xGBP\":" << xGBP; - oss << ",\"xJPY\":" << xJPY; - oss << ",\"xNOK\":" << xNOK; - oss << ",\"xNZD\":" << xNZD; - oss << ",\"xUSD\":" << xUSD; - oss << ",\"unused1\":" << unused1; - oss << ",\"unused2\":" << unused2; - oss << ",\"unused3\":" << unused3; - if (timestamp > 0) - oss << ",\"timestamp\":" << timestamp; - oss << "}"; - std::string message = oss.str(); - - // Convert signature from hex-encoded to binary - std::string compact; - for (unsigned int i = 0; i < sig_rebuilt.length(); i += 2) { - std::string byteString = sig_rebuilt.substr(i, 2); - char byte = (char) strtol(byteString.c_str(), NULL, 16); - compact += (byte); - } - - // Create a verify digest from the message - EVP_MD_CTX *ctx = EVP_MD_CTX_create(); - int ret = 0; - if (ctx) { - ret = EVP_DigestVerifyInit(ctx, NULL, EVP_sha256(), NULL, pubkey); - if (ret == 1) { - ret = EVP_DigestVerifyUpdate(ctx, message.data(), message.length()); - if (ret == 1) { - ret = EVP_DigestVerifyFinal(ctx, (const unsigned char *)compact.data(), compact.length()); - } - } - } - - // Cleanup the context we created - EVP_MD_CTX_destroy(ctx); - // Cleanup the openssl stuff - EVP_PKEY_free(pubkey); - - if (ret == 1) - return true; - - // Get the errors from OpenSSL - //ERR_print_errors_fp (stderr); - - return false; - } - - void pricing_record::set_for_height_821428() { - const std::string pr_821428 = "9b3f6f2f8f0000003d620e1202000000be71be2555120000b8627010000000000000000000000000ea0885b2270d00000000000000000000f797ff9be00b0000ddbdb005270a0000fc90cfe02b01060000000000000000000000000000000000d0a28224000e000000d643be960e0000002e8bb6a40e000000f8a817f80d00002f5d27d45cdbfbac3d0f6577103f68de30895967d7562fbd56c161ae90130f54301b1ea9d5fd062f37dac75c3d47178bc6f149d21da1ff0e8430065cb762b93a"; - this->xAG = 614976143259; - this->xAU = 8892867133; - this->xAUD = 20156914758078; - this->xBTC = 275800760; - this->xCAD = 0; - this->xCHF = 14464149948650; - this->xCNY = 0; - this->xEUR = 13059317798903; - this->xGBP = 11162715471325; - this->xJPY = 1690137827184892; - this->xNOK = 0; - this->xNZD = 0; - this->xUSD = 15393775330000; - this->unused1 = 16040600000000; - this->unused2 = 16100600000000; - this->unused3 = 15359200000000; - this->timestamp = 0; - std::string sig = "2f5d27d45cdbfbac3d0f6577103f68de30895967d7562fbd56c161ae90130f54301b1ea9d5fd062f37dac75c3d47178bc6f149d21da1ff0e8430065cb762b93a"; - int j=0; - for (unsigned int i = 0; i < sig.size(); i += 2) { - std::string byteString = sig.substr(i, 2); - this->signature[j++] = (char) strtol(byteString.c_str(), NULL, 16); - } - } - - // overload for pr validation for block - bool pricing_record::valid(uint32_t hf_version, uint64_t bl_timestamp, uint64_t last_bl_timestamp) const - { - // check for empty pr - if (hf_version >= HF_VERSION_XASSET_FEES_V2) { - if (this->empty()) - return true; - } else { - unsigned char test_sig[64]; - std::memset(test_sig, 0, sizeof(test_sig)); - if (std::memcmp(test_sig, this->signature, sizeof(this->signature)) == 0) { - return true; - } - } - - // Oracle public keys - std::string const mainnet_public_key = "-----BEGIN PUBLIC KEY-----\n" - "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE5YBxWx1AZCA9jTUk8Pr2uZ9jpfRt\n" - "KWv3Vo1/Gny+1vfaxsXhBQiG1KlHkafNGarzoL0WHW4ocqaaqF5iv8i35A==\n" - "-----END PUBLIC KEY-----\n"; - std::string const testnet_public_key = "-----BEGIN PUBLIC KEY-----\n" - "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEtWqvQh7OdXrdgXcDeBMRVfLWTW3F\n" - "wByeoVJFBfZymScJIJl46j66xG6ngnyj4ai4/QPFnSZ1I9jjMRlTWC4EPA==\n" - "-----END PUBLIC KEY-----\n"; - std::string const stagenet_public_key = "-----BEGIN PUBLIC KEY-----\n" - "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEtWqvQh7OdXrdgXcDeBMRVfLWTW3F\n" - "wByeoVJFBfZymScJIJl46j66xG6ngnyj4ai4/QPFnSZ1I9jjMRlTWC4EPA==\n" - "-----END PUBLIC KEY-----\n"; - - // Comment out all but 1 of the following lines to select the correct Oracle PK - std::string const public_key = mainnet_public_key; - //std::string const public_key = testnet_public_key; - //std::string const public_key = stagenet_public_key; - - // verify the signature - if (!verifySignature(public_key)) { - LOG_ERROR("Invalid pricing record signature."); - return false; - } - - // valiadte the timestmap - if (hf_version >= HF_VERSION_XASSET_FEES_V2) { - if (this->timestamp > bl_timestamp + PRICING_RECORD_VALID_TIME_DIFF_FROM_BLOCK) { - LOG_ERROR("Pricing record timestamp is too far in the future."); - return false; - } - if (this->timestamp <= last_bl_timestamp) { - LOG_ERROR("Pricing record timestamp is too old."); - return false; - } - } - - return true; - } - -} \ No newline at end of file diff --git a/src/offshore/pricing_record.h b/src/offshore/pricing_record.h deleted file mode 100644 index b20bbd24..00000000 --- a/src/offshore/pricing_record.h +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright (c) 2019, Haven Protocol -// 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. -// -// Portions of this code based upon code Copyright (c) 2019, The Monero Project - -#pragma once -#include "common/pod-class.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "cryptonote_config.h" -#include "crypto/hash.h" - -namespace epee -{ - namespace serialization - { - class portable_storage; - struct section; - } -} - -namespace offshore -{ - -#pragma pack(push, 1) - POD_CLASS pricing_record_old { - double xAG; - double xAU; - double xAUD; - double xBTC; - double xCAN; - double xCHF; - double xCNY; - double xEUR; - double xGBP; - double xJPY; - double xNOK; - double xNZD; - double xUSD; - double unused1; - double unused2; - double unused3; - char signature[32]; - }; -#pragma pack(pop) - - class pricing_record - { - - public: - - // Fields - uint64_t xAG; - uint64_t xAU; - uint64_t xAUD; - uint64_t xBTC; - uint64_t xCAD; - uint64_t xCHF; - uint64_t xCNY; - uint64_t xEUR; - uint64_t xGBP; - uint64_t xJPY; - uint64_t xNOK; - uint64_t xNZD; - uint64_t xUSD; - uint64_t unused1; - uint64_t unused2; - uint64_t unused3; - uint64_t timestamp; - unsigned char signature[64]; - - // Default c'tor - pricing_record() noexcept; - //! Load from epee p2p format - bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent); - //! Store in epee p2p format - bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const; - pricing_record(const pricing_record& orig) noexcept; - ~pricing_record() = default; - void set_for_height_821428(); - bool equal(const pricing_record& other) const noexcept; - bool empty() const noexcept; - bool verifySignature(const std::string& public_key) const; - bool valid(uint32_t hf_version, uint64_t bl_timestamp, uint64_t last_bl_timestamp) const; - - pricing_record& operator=(const pricing_record& orig) noexcept; - uint64_t operator[](const std::string& asset_type) const; - }; - - inline bool operator==(const pricing_record& a, const pricing_record& b) noexcept - { - return a.equal(b); - } - - inline bool operator!=(const pricing_record& a, const pricing_record& b) noexcept - { - return !a.equal(b); - } - - // did not have a timestamp - class pricing_record_v1 - { - - public: - uint64_t xAG; - uint64_t xAU; - uint64_t xAUD; - uint64_t xBTC; - uint64_t xCAD; - uint64_t xCHF; - uint64_t xCNY; - uint64_t xEUR; - uint64_t xGBP; - uint64_t xJPY; - uint64_t xNOK; - uint64_t xNZD; - uint64_t xUSD; - uint64_t unused1; - uint64_t unused2; - uint64_t unused3; - unsigned char signature[64]; - - bool write_to_pr(offshore::pricing_record &pr) - { - pr.xAG = xAG; - pr.xAU = xAU; - pr.xAUD = xAUD; - pr.xBTC = xBTC; - pr.xCAD = xCAD; - pr.xCHF = xCHF; - pr.xCNY = xCNY; - pr.xEUR = xEUR; - pr.xGBP = xGBP; - pr.xJPY = xJPY; - pr.xNOK = xNOK; - pr.xNZD = xNZD; - pr.xUSD = xUSD; - pr.unused1 = unused1; - pr.unused2 = unused2; - pr.unused3 = unused3; - pr.timestamp = 0; - ::memcpy(pr.signature, signature, sizeof(pr.signature)); - return true; - }; - - bool read_from_pr(offshore::pricing_record &pr) - { - xAG = pr.xAG; - xAU = pr.xAU; - xAUD = pr.xAUD; - xBTC = pr.xBTC; - xCAD = pr.xCAD; - xCHF = pr.xCHF; - xCNY = pr.xCNY; - xEUR = pr.xEUR; - xGBP = pr.xGBP; - xJPY = pr.xJPY; - xNOK = pr.xNOK; - xNZD = pr.xNZD; - xUSD = pr.xUSD; - unused1 = pr.unused1; - unused2 = pr.unused2; - unused3 = pr.unused3; - ::memcpy(signature, pr.signature, sizeof(signature)); - return true; - }; - }; - -} // offshore diff --git a/src/serialization/pricing_record.h b/src/serialization/pricing_record.h deleted file mode 100644 index e5b06822..00000000 --- a/src/serialization/pricing_record.h +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) 2019, Haven Protocol -// -// 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. -// -// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers - -#pragma once - -#include - -#include "serialization.h" -#include "offshore/pricing_record.h" -#include "cryptonote_config.h" - -// read -template