Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d8a30042e | |||
| a760b46501 | |||
| 9ef2d782c1 | |||
| 278654276e | |||
| 5ca2284583 | |||
| 100f6cb2d5 | |||
| 59edc8c114 |
+1
-1
@@ -31,7 +31,7 @@
|
|||||||
"-fno-exceptions -std=gnu11 -march=native -fPIC -DNDEBUG -Ofast -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2"
|
"-fno-exceptions -std=gnu11 -march=native -fPIC -DNDEBUG -Ofast -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2"
|
||||||
],
|
],
|
||||||
"cflags_cc": [
|
"cflags_cc": [
|
||||||
"-fexceptions -frtti -std=gnu++11 -march=native -fPIC -DNDEBUG -Ofast -s -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2"
|
"-fexceptions -frtti -std=c++17 -march=native -fPIC -DNDEBUG -Ofast -s -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2"
|
||||||
],
|
],
|
||||||
"xcode_settings": {
|
"xcode_settings": {
|
||||||
"OTHER_CFLAGS": [ "-fexceptions -frtti" ]
|
"OTHER_CFLAGS": [ "-fexceptions -frtti" ]
|
||||||
|
|||||||
@@ -92,6 +92,11 @@ module.exports.RavenBlockTemplate = function(rpcData, poolAddress) {
|
|||||||
|
|
||||||
txCoinbase.addOutput(scriptCompile(poolAddrHash), Math.floor(rpcData.coinbasevalue));
|
txCoinbase.addOutput(scriptCompile(poolAddrHash), Math.floor(rpcData.coinbasevalue));
|
||||||
|
|
||||||
|
// For CLORE
|
||||||
|
if (rpcData.CommunityAutonomousAddress && rpcData.CommunityAutonomousValue) {
|
||||||
|
txCoinbase.addOutput(scriptCompile(bitcoin.address.fromBase58Check(rpcData.CommunityAutonomousAddress).hash), Math.floor(rpcData.CommunityAutonomousValue));
|
||||||
|
}
|
||||||
|
|
||||||
if (rpcData.default_witness_commitment) {
|
if (rpcData.default_witness_commitment) {
|
||||||
txCoinbase.addOutput(Buffer.from(rpcData.default_witness_commitment, 'hex'), 0);
|
txCoinbase.addOutput(Buffer.from(rpcData.default_witness_commitment, 'hex'), 0);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cryptoforknote-util",
|
"name": "cryptoforknote-util",
|
||||||
"version": "14.0.1",
|
"version": "15.2.1",
|
||||||
"main": "cryptoforknote-util",
|
"main": "cryptoforknote-util",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "LucasJones",
|
"name": "LucasJones",
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define CURRENT_TRANSACTION_VERSION 1
|
#define CURRENT_TRANSACTION_VERSION 1
|
||||||
#define POU_TRANSACTION_VERSION 6
|
#define POU_TRANSACTION_VERSION 6
|
||||||
#define COLLATERAL_TRANSACTION_VERSION 7
|
#define COLLATERAL_TRANSACTION_VERSION 7
|
||||||
#define OFFSHORE_TRANSACTION_VERSION 3
|
#define HAVEN_TYPES_TRANSACTION_VERSION 8
|
||||||
#define HF_VERSION_XASSET_FEES_V2 17
|
#define OFFSHORE_TRANSACTION_VERSION 3
|
||||||
#define HF_VERSION_HAVEN2 18
|
#define HF_VERSION_XASSET_FEES_V2 17
|
||||||
#define HF_VERSION_USE_COLLATERAL 20
|
#define HF_VERSION_HAVEN2 18
|
||||||
|
#define HF_VERSION_USE_COLLATERAL 20
|
||||||
|
|
||||||
// UNLOCK TIMES
|
// UNLOCK TIMES
|
||||||
#define TX_V6_OFFSHORE_UNLOCK_BLOCKS 21*720 // 21 day unlock time
|
#define TX_V6_OFFSHORE_UNLOCK_BLOCKS 21*720 // 21 day unlock time
|
||||||
@@ -34,4 +35,5 @@ enum BLOB_TYPE {
|
|||||||
BLOB_TYPE_CRYPTONOTE_XHV = 11, // Haven
|
BLOB_TYPE_CRYPTONOTE_XHV = 11, // Haven
|
||||||
BLOB_TYPE_CRYPTONOTE_XTA = 12, // ITALO
|
BLOB_TYPE_CRYPTONOTE_XTA = 12, // ITALO
|
||||||
BLOB_TYPE_CRYPTONOTE_ZEPHYR = 13, // ZEPHYR
|
BLOB_TYPE_CRYPTONOTE_ZEPHYR = 13, // ZEPHYR
|
||||||
|
BLOB_TYPE_CRYPTONOTE_XLA = 14, // XLA
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -89,6 +89,48 @@ namespace cryptonote
|
|||||||
END_SERIALIZE()
|
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
|
struct txout_offshore
|
||||||
{
|
{
|
||||||
txout_offshore() { }
|
txout_offshore() { }
|
||||||
@@ -203,6 +245,21 @@ namespace cryptonote
|
|||||||
END_SERIALIZE()
|
END_SERIALIZE()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct txin_haven_key
|
||||||
|
{
|
||||||
|
uint64_t amount;
|
||||||
|
std::string asset_type;
|
||||||
|
std::vector<uint64_t> 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
|
struct txin_xasset
|
||||||
{
|
{
|
||||||
uint64_t amount;
|
uint64_t amount;
|
||||||
@@ -233,11 +290,11 @@ namespace cryptonote
|
|||||||
END_SERIALIZE()
|
END_SERIALIZE()
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_to_key, txin_offshore, txin_onshore, txin_xasset> txin_v;
|
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_to_key, txin_offshore, txin_onshore, txin_xasset, txin_haven_key> txin_v;
|
||||||
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_zephyr_key> txin_zephyr_v;
|
typedef boost::variant<txin_gen, txin_to_script, txin_to_scripthash, txin_zephyr_key> txin_zephyr_v;
|
||||||
|
|
||||||
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_to_tagged_key> txout_target_v;
|
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_to_tagged_key> txout_target_v;
|
||||||
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_offshore, txout_xasset> txout_xhv_target_v;
|
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_to_key, txout_offshore, txout_xasset, txout_haven_key, txout_haven_tagged_key> txout_xhv_target_v;
|
||||||
|
|
||||||
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_zephyr_tagged_key> txout_stablero_target_v;
|
typedef boost::variant<txout_to_script, txout_to_scripthash, txout_zephyr_tagged_key> txout_stablero_target_v;
|
||||||
|
|
||||||
@@ -327,62 +384,288 @@ namespace cryptonote
|
|||||||
};
|
};
|
||||||
|
|
||||||
BEGIN_SERIALIZE()
|
BEGIN_SERIALIZE()
|
||||||
VARINT_FIELD(version)
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) {
|
||||||
if (version > loki_version_2 && (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC))
|
VARINT_FIELD(version)
|
||||||
{
|
//if(version == 0 || CURRENT_TRANSACTION_VERSION < version) return false;
|
||||||
FIELD(output_unlock_times)
|
|
||||||
if (version == loki_version_3_per_output_unlock_times)
|
// Only transactions prior to HAVEN_TYPES_TRANSACTION_VERSION are permitted to be anything other than HAVEN_TYPES and need translation
|
||||||
FIELD(is_deregister)
|
if (version < HAVEN_TYPES_TRANSACTION_VERSION) {
|
||||||
}
|
|
||||||
if (blob_type != BLOB_TYPE_CRYPTONOTE_XHV || version < POU_TRANSACTION_VERSION)
|
if (version < POU_TRANSACTION_VERSION) {
|
||||||
VARINT_FIELD(unlock_time)
|
VARINT_FIELD(unlock_time)
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
|
}
|
||||||
FIELD(vin_zephyr)
|
if (!typename Archive<W>::is_saving()) {
|
||||||
else
|
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<txin_v> 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<txin_to_key>(vin_entry).amount;
|
||||||
|
in.key_offsets = boost::get<txin_to_key>(vin_entry).key_offsets;
|
||||||
|
in.k_image = boost::get<txin_to_key>(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<txin_offshore>(vin_entry).amount;
|
||||||
|
in.key_offsets = boost::get<txin_offshore>(vin_entry).key_offsets;
|
||||||
|
in.k_image = boost::get<txin_offshore>(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<txin_onshore>(vin_entry).amount;
|
||||||
|
in.key_offsets = boost::get<txin_onshore>(vin_entry).key_offsets;
|
||||||
|
in.k_image = boost::get<txin_onshore>(vin_entry).k_image;
|
||||||
|
} else if (vin_entry.type() == typeid(txin_xasset)) {
|
||||||
|
is_offshore_tx = false;
|
||||||
|
is_onshore_tx = false;
|
||||||
|
in.amount = boost::get<txin_xasset>(vin_entry).amount;
|
||||||
|
in.key_offsets = boost::get<txin_xasset>(vin_entry).key_offsets;
|
||||||
|
in.k_image = boost::get<txin_xasset>(vin_entry).k_image;
|
||||||
|
in.asset_type = boost::get<txin_xasset>(vin_entry).asset_type;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
vin.push_back(in);
|
||||||
|
}
|
||||||
|
std::vector<tx_out_xhv> vout_tmp(vout_xhv);
|
||||||
|
vout_xhv.clear();
|
||||||
|
for (size_t i=0; i<vout_tmp.size(); i++) {
|
||||||
|
txout_haven_key out;
|
||||||
|
if (vout_tmp[i].target.type() == typeid(txout_to_key)) {
|
||||||
|
out.asset_type = "XHV";
|
||||||
|
out.key = boost::get<txout_to_key>(vout_tmp[i].target).key;
|
||||||
|
} else if (vout_tmp[i].target.type() == typeid(txout_offshore)) {
|
||||||
|
out.asset_type = "XUSD";
|
||||||
|
out.key = boost::get<txout_offshore>(vout_tmp[i].target).key;
|
||||||
|
} else if (vout_tmp[i].target.type() == typeid(txout_xasset)) {
|
||||||
|
out.asset_type = boost::get<txout_xasset>(vout_tmp[i].target).asset_type;
|
||||||
|
out.key = boost::get<txout_xasset>(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<txin_v> 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<txin_haven_key>(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<txout_haven_key>(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<txout_haven_tagged_key>(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<tx_out_xhv> vout_tmp;
|
||||||
|
vout_tmp.reserve(vout_xhv.size());
|
||||||
|
output_unlock_times.resize(vout_xhv.size());
|
||||||
|
std::vector<uint32_t> collateral_indices_temp;
|
||||||
|
collateral_indices_temp.resize(2);
|
||||||
|
for (size_t i=0; i<vout_xhv.size(); i++) {
|
||||||
|
txout_haven_key outhk = boost::get<txout_haven_key>(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(vin)
|
||||||
|
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
|
|
||||||
FIELD(vout_zephyr)
|
|
||||||
else if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV)
|
|
||||||
FIELD(vout_xhv)
|
FIELD(vout_xhv)
|
||||||
else
|
FIELD(extra)
|
||||||
FIELD(vout)
|
|
||||||
|
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC)
|
|
||||||
{
|
|
||||||
if (version >= loki_version_3_per_output_unlock_times && vout.size() != output_unlock_times.size()) return false;
|
|
||||||
}
|
|
||||||
FIELD(extra)
|
|
||||||
if ((blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC) && version >= loki_version_4_tx_types)
|
|
||||||
{
|
|
||||||
VARINT_FIELD(type)
|
|
||||||
if (static_cast<uint16_t>(type) >= loki_type_count) return false;
|
|
||||||
}
|
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
|
||||||
VARINT_FIELD(pricing_record_height)
|
VARINT_FIELD(pricing_record_height)
|
||||||
VARINT_FIELD(amount_burnt)
|
VARINT_FIELD(amount_burnt)
|
||||||
VARINT_FIELD(amount_minted)
|
VARINT_FIELD(amount_minted)
|
||||||
}
|
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV && version >= OFFSHORE_TRANSACTION_VERSION) {
|
} else {
|
||||||
VARINT_FIELD(pricing_record_height)
|
|
||||||
if (version < 5)
|
VARINT_FIELD(version)
|
||||||
FIELD(offshore_data)
|
if (version > loki_version_2 && (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC))
|
||||||
if (version >= POU_TRANSACTION_VERSION)
|
|
||||||
{
|
{
|
||||||
FIELD(output_unlock_times)
|
FIELD(output_unlock_times)
|
||||||
|
if (version == loki_version_3_per_output_unlock_times)
|
||||||
|
FIELD(is_deregister)
|
||||||
}
|
}
|
||||||
if (version >= POU_TRANSACTION_VERSION && vout_xhv.size() != output_unlock_times.size()) return false;
|
|
||||||
VARINT_FIELD(amount_burnt)
|
VARINT_FIELD(unlock_time)
|
||||||
VARINT_FIELD(amount_minted)
|
|
||||||
if (version >= COLLATERAL_TRANSACTION_VERSION && amount_burnt) {
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
|
||||||
FIELD(collateral_indices)
|
FIELD(vin_zephyr)
|
||||||
if (collateral_indices.size() != 2) {
|
else
|
||||||
return false;
|
FIELD(vin)
|
||||||
}
|
|
||||||
for (const auto vout_idx: collateral_indices) {
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR)
|
||||||
if (vout_idx >= vout.size())
|
FIELD(vout_zephyr)
|
||||||
return false;
|
else
|
||||||
}
|
FIELD(vout)
|
||||||
|
|
||||||
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC)
|
||||||
|
{
|
||||||
|
if (version >= loki_version_3_per_output_unlock_times && vout.size() != output_unlock_times.size()) return false;
|
||||||
|
}
|
||||||
|
FIELD(extra)
|
||||||
|
if ((blob_type == BLOB_TYPE_CRYPTONOTE_LOKI || blob_type == BLOB_TYPE_CRYPTONOTE_XTNC) && version >= loki_version_4_tx_types)
|
||||||
|
{
|
||||||
|
VARINT_FIELD(type)
|
||||||
|
if (static_cast<uint16_t>(type) >= loki_type_count) return false;
|
||||||
|
}
|
||||||
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
||||||
|
VARINT_FIELD(pricing_record_height)
|
||||||
|
VARINT_FIELD(amount_burnt)
|
||||||
|
VARINT_FIELD(amount_minted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END_SERIALIZE()
|
END_SERIALIZE()
|
||||||
@@ -463,7 +746,10 @@ namespace cryptonote
|
|||||||
vin.size() > 0 && vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 :
|
vin.size() > 0 && vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 :
|
||||||
vin.size() > 0 && vin[0].type() == typeid(txin_offshore) ? boost::get<txin_offshore>(vin[0]).key_offsets.size() - 1 :
|
vin.size() > 0 && vin[0].type() == typeid(txin_offshore) ? boost::get<txin_offshore>(vin[0]).key_offsets.size() - 1 :
|
||||||
vin.size() > 0 && vin[0].type() == typeid(txin_onshore) ? boost::get<txin_onshore>(vin[0]).key_offsets.size() - 1 :
|
vin.size() > 0 && vin[0].type() == typeid(txin_onshore) ? boost::get<txin_onshore>(vin[0]).key_offsets.size() - 1 :
|
||||||
vin.size() > 0 && vin[0].type() == typeid(txin_xasset) ? boost::get<txin_xasset>(vin[0]).key_offsets.size() - 1 : 0);
|
vin.size() > 0 && vin[0].type() == typeid(txin_xasset) ? boost::get<txin_xasset>(vin[0]).key_offsets.size() - 1 :
|
||||||
|
vin.size() > 0 && vin[0].type() == typeid(txin_haven_key) ? boost::get<txin_haven_key>(vin[0]).key_offsets.size() - 1 :
|
||||||
|
0
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout.size(),
|
r = rct_signatures.p.serialize_rctsig_prunable(ar, rct_signatures.type, vin.size(), vout.size(),
|
||||||
vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 : 0);
|
vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(vin[0]).key_offsets.size() - 1 : 0);
|
||||||
@@ -523,6 +809,7 @@ namespace cryptonote
|
|||||||
size_t operator()(const txin_offshore& 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_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_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();}
|
size_t operator()(const txin_zephyr_key& txin) const {return txin.key_offsets.size();}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -648,6 +935,7 @@ namespace cryptonote
|
|||||||
crypto::cycle cycle;
|
crypto::cycle cycle;
|
||||||
crypto::cycle40 cycle40;
|
crypto::cycle40 cycle40;
|
||||||
crypto::cycle48 cycle48;
|
crypto::cycle48 cycle48;
|
||||||
|
crypto::signature signature;
|
||||||
|
|
||||||
BEGIN_SERIALIZE()
|
BEGIN_SERIALIZE()
|
||||||
VARINT_FIELD(major_version)
|
VARINT_FIELD(major_version)
|
||||||
@@ -669,7 +957,27 @@ namespace cryptonote
|
|||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_TUBE) FIELD(cycle40)
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_TUBE) FIELD(cycle40)
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XTA) FIELD(cycle48)
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_XTA) FIELD(cycle48)
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) FIELD(pricing_record)
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_XHV) FIELD(pricing_record)
|
||||||
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) FIELD_N("pricing_record", zephyr_pricing_record)
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_ZEPHYR) {
|
||||||
|
if (major_version >= 3)
|
||||||
|
{
|
||||||
|
FIELD_N("pricing_record", zephyr_pricing_record)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
zephyr_oracle::pricing_record_v1 pr_v1;
|
||||||
|
if (!typename Archive<W>::is_saving())
|
||||||
|
{
|
||||||
|
FIELD(pr_v1)
|
||||||
|
pr_v1.write_to_pr(zephyr_pricing_record);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pr_v1.read_from_pr(zephyr_pricing_record);
|
||||||
|
FIELD(pr_v1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (blob_type == BLOB_TYPE_CRYPTONOTE_XLA && major_version >= 13) FIELD(signature)
|
||||||
|
|
||||||
END_SERIALIZE()
|
END_SERIALIZE()
|
||||||
};
|
};
|
||||||
@@ -755,6 +1063,7 @@ VARIANT_TAG(binary_archive, cryptonote::txin_zephyr_key, 0x2);
|
|||||||
VARIANT_TAG(binary_archive, cryptonote::txin_offshore, 0x3);
|
VARIANT_TAG(binary_archive, cryptonote::txin_offshore, 0x3);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txin_onshore, 0x4);
|
VARIANT_TAG(binary_archive, cryptonote::txin_onshore, 0x4);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txin_xasset, 0x5);
|
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_script, 0x0);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txout_to_scripthash, 0x1);
|
VARIANT_TAG(binary_archive, cryptonote::txout_to_scripthash, 0x1);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txout_to_key, 0x2);
|
VARIANT_TAG(binary_archive, cryptonote::txout_to_key, 0x2);
|
||||||
@@ -762,5 +1071,7 @@ 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_to_tagged_key, 0x3);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txout_offshore, 0x3);
|
VARIANT_TAG(binary_archive, cryptonote::txout_offshore, 0x3);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::txout_xasset, 0x5);
|
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::transaction, 0xcc);
|
||||||
VARIANT_TAG(binary_archive, cryptonote::block, 0xbb);
|
VARIANT_TAG(binary_archive, cryptonote::block, 0xbb);
|
||||||
|
|||||||
@@ -247,6 +247,7 @@ namespace cryptonote
|
|||||||
t.vin[0].type() == typeid(txin_offshore) ? boost::get<txin_offshore>(t.vin[0]).key_offsets.size() - 1 :
|
t.vin[0].type() == typeid(txin_offshore) ? boost::get<txin_offshore>(t.vin[0]).key_offsets.size() - 1 :
|
||||||
t.vin[0].type() == typeid(txin_onshore) ? boost::get<txin_onshore>(t.vin[0]).key_offsets.size() - 1 :
|
t.vin[0].type() == typeid(txin_onshore) ? boost::get<txin_onshore>(t.vin[0]).key_offsets.size() - 1 :
|
||||||
t.vin[0].type() == typeid(txin_xasset) ? boost::get<txin_xasset>(t.vin[0]).key_offsets.size() - 1 :
|
t.vin[0].type() == typeid(txin_xasset) ? boost::get<txin_xasset>(t.vin[0]).key_offsets.size() - 1 :
|
||||||
|
t.vin[0].type() == typeid(txin_haven_key) ? boost::get<txin_haven_key>(t.vin[0]).key_offsets.size() - 1 :
|
||||||
0;
|
0;
|
||||||
} else {
|
} else {
|
||||||
mixin = t.vin.empty() ? 0 : t.vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(t.vin[0]).key_offsets.size() - 1 : 0;
|
mixin = t.vin.empty() ? 0 : t.vin[0].type() == typeid(txin_to_key) ? boost::get<txin_to_key>(t.vin[0]).key_offsets.size() - 1 : 0;
|
||||||
@@ -370,7 +371,7 @@ namespace cryptonote
|
|||||||
ss << b_blob;
|
ss << b_blob;
|
||||||
binary_archive<false> ba(ss);
|
binary_archive<false> ba(ss);
|
||||||
bool r = ::serialization::serialize(ba, b);
|
bool r = ::serialization::serialize(ba, b);
|
||||||
CHECK_AND_ASSERT_MES(r, false, "Failed to parse block from blob");
|
CHECK_AND_ASSERT_MES(r, false, "Failed to parse block from blob 1");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//---------------------------------------------------------------
|
//---------------------------------------------------------------
|
||||||
|
|||||||
+1
-1
@@ -145,7 +145,7 @@ NAN_METHOD(convert_blob) { // (parentBlockBuffer, cnBlobType)
|
|||||||
|
|
||||||
block b = AUTO_VAL_INIT(b);
|
block b = AUTO_VAL_INIT(b);
|
||||||
b.set_blob_type(blob_type);
|
b.set_blob_type(blob_type);
|
||||||
if (!parse_and_validate_block_from_blob(input, b)) return THROW_ERROR_EXCEPTION("Failed to parse block");
|
if (!parse_and_validate_block_from_blob(input, b)) return THROW_ERROR_EXCEPTION("Failed to parse block 2");
|
||||||
|
|
||||||
if (blob_type == BLOB_TYPE_FORKNOTE2) {
|
if (blob_type == BLOB_TYPE_FORKNOTE2) {
|
||||||
block parent_block;
|
block parent_block;
|
||||||
|
|||||||
+162
-6
@@ -236,11 +236,48 @@ namespace rct {
|
|||||||
END_SERIALIZE()
|
END_SERIALIZE()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BulletproofPlus
|
||||||
|
{
|
||||||
|
rct::keyV V;
|
||||||
|
rct::key A, A1, B;
|
||||||
|
rct::key r1, s1, d1;
|
||||||
|
rct::keyV L, R;
|
||||||
|
|
||||||
|
BulletproofPlus() {}
|
||||||
|
BulletproofPlus(const rct::key &V, const rct::key &A, const rct::key &A1, const rct::key &B, const rct::key &r1, const rct::key &s1, const rct::key &d1, const rct::keyV &L, const rct::keyV &R):
|
||||||
|
V({V}), A(A), A1(A1), B(B), r1(r1), s1(s1), d1(d1), L(L), R(R) {}
|
||||||
|
BulletproofPlus(const rct::keyV &V, const rct::key &A, const rct::key &A1, const rct::key &B, const rct::key &r1, const rct::key &s1, const rct::key &d1, const rct::keyV &L, const rct::keyV &R):
|
||||||
|
V(V), A(A), A1(A1), B(B), r1(r1), s1(s1), d1(d1), L(L), R(R) {}
|
||||||
|
|
||||||
|
bool operator==(const BulletproofPlus &other) const { return V == other.V && A == other.A && A1 == other.A1 && B == other.B && r1 == other.r1 && s1 == other.s1 && d1 == other.d1 && L == other.L && R == other.R; }
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
// Commitments aren't saved, they're restored via outPk
|
||||||
|
// FIELD(V)
|
||||||
|
FIELD(A)
|
||||||
|
FIELD(A1)
|
||||||
|
FIELD(B)
|
||||||
|
FIELD(r1)
|
||||||
|
FIELD(s1)
|
||||||
|
FIELD(d1)
|
||||||
|
FIELD(L)
|
||||||
|
FIELD(R)
|
||||||
|
|
||||||
|
if (L.empty() || L.size() != R.size())
|
||||||
|
return false;
|
||||||
|
END_SERIALIZE()
|
||||||
|
};
|
||||||
|
|
||||||
size_t n_bulletproof_amounts(const Bulletproof &proof);
|
size_t n_bulletproof_amounts(const Bulletproof &proof);
|
||||||
size_t n_bulletproof_max_amounts(const Bulletproof &proof);
|
size_t n_bulletproof_max_amounts(const Bulletproof &proof);
|
||||||
size_t n_bulletproof_amounts(const std::vector<Bulletproof> &proofs);
|
size_t n_bulletproof_amounts(const std::vector<Bulletproof> &proofs);
|
||||||
size_t n_bulletproof_max_amounts(const std::vector<Bulletproof> &proofs);
|
size_t n_bulletproof_max_amounts(const std::vector<Bulletproof> &proofs);
|
||||||
|
|
||||||
|
size_t n_bulletproof_plus_amounts(const BulletproofPlus &proof);
|
||||||
|
size_t n_bulletproof_plus_max_amounts(const BulletproofPlus &proof);
|
||||||
|
size_t n_bulletproof_plus_amounts(const std::vector<BulletproofPlus> &proofs);
|
||||||
|
size_t n_bulletproof_plus_max_amounts(const std::vector<BulletproofPlus> &proofs);
|
||||||
|
|
||||||
//A container to hold all signatures necessary for RingCT
|
//A container to hold all signatures necessary for RingCT
|
||||||
// rangeSigs holds all the rangeproof data of a transaction
|
// rangeSigs holds all the rangeproof data of a transaction
|
||||||
// MG holds the MLSAG signature of a transaction
|
// MG holds the MLSAG signature of a transaction
|
||||||
@@ -258,11 +295,18 @@ namespace rct {
|
|||||||
RCTTypeCLSAGN = 6,
|
RCTTypeCLSAGN = 6,
|
||||||
RCTTypeHaven2 = 7, // Add public mask sum terms, remove extraneous fields (txnFee_usd,txnFee_xasset,txnOffshoreFee_usd,txnOffshoreFee_xasset)
|
RCTTypeHaven2 = 7, // Add public mask sum terms, remove extraneous fields (txnFee_usd,txnFee_xasset,txnOffshoreFee_usd,txnOffshoreFee_xasset)
|
||||||
RCTTypeHaven3 = 8, // Add public mask sum term for collateral
|
RCTTypeHaven3 = 8, // Add public mask sum term for collateral
|
||||||
|
RCTTypeBulletproofPlus = 9,
|
||||||
};
|
};
|
||||||
enum RangeProofType { RangeProofBorromean, RangeProofBulletproof, RangeProofMultiOutputBulletproof, RangeProofPaddedBulletproof };
|
enum RangeProofType { RangeProofBorromean, RangeProofBulletproof, RangeProofMultiOutputBulletproof, RangeProofPaddedBulletproof };
|
||||||
struct RCTConfig {
|
struct RCTConfig {
|
||||||
RangeProofType range_proof_type;
|
RangeProofType range_proof_type;
|
||||||
int bp_version;
|
int bp_version;
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
VERSION_FIELD(0)
|
||||||
|
VARINT_FIELD(range_proof_type)
|
||||||
|
VARINT_FIELD(bp_version)
|
||||||
|
END_SERIALIZE()
|
||||||
};
|
};
|
||||||
struct rctSigBase {
|
struct rctSigBase {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
@@ -288,6 +332,64 @@ namespace rct {
|
|||||||
FIELD(type)
|
FIELD(type)
|
||||||
if (type == RCTTypeNull)
|
if (type == RCTTypeNull)
|
||||||
return ar.stream().good();
|
return ar.stream().good();
|
||||||
|
if (type != RCTTypeBulletproofPlus)
|
||||||
|
return serialize_rctsig_base_old(ar, inputs, outputs);
|
||||||
|
VARINT_FIELD(txnFee)
|
||||||
|
VARINT_FIELD(txnOffshoreFee)
|
||||||
|
// inputs/outputs not saved, only here for serialization help
|
||||||
|
// FIELD(message) - not serialized, it can be reconstructed
|
||||||
|
// FIELD(mixRing) - not serialized, it can be reconstructed
|
||||||
|
ar.tag("ecdhInfo");
|
||||||
|
ar.begin_array();
|
||||||
|
PREPARE_CUSTOM_VECTOR_SERIALIZATION(outputs, ecdhInfo);
|
||||||
|
if (ecdhInfo.size() != outputs)
|
||||||
|
return false;
|
||||||
|
for (size_t i = 0; i < outputs; ++i)
|
||||||
|
{
|
||||||
|
ar.begin_object();
|
||||||
|
if (!typename Archive<W>::is_saving())
|
||||||
|
memset(ecdhInfo[i].amount.bytes, 0, sizeof(ecdhInfo[i].amount.bytes));
|
||||||
|
crypto::hash8 &amount = (crypto::hash8&)ecdhInfo[i].amount;
|
||||||
|
FIELD(amount);
|
||||||
|
ar.end_object();
|
||||||
|
if (outputs - i > 1)
|
||||||
|
ar.delimit_array();
|
||||||
|
}
|
||||||
|
ar.end_array();
|
||||||
|
|
||||||
|
ar.tag("outPk");
|
||||||
|
ar.begin_array();
|
||||||
|
PREPARE_CUSTOM_VECTOR_SERIALIZATION(outputs, outPk);
|
||||||
|
if (outPk.size() != outputs)
|
||||||
|
return false;
|
||||||
|
for (size_t i = 0; i < outputs; ++i)
|
||||||
|
{
|
||||||
|
FIELDS(outPk[i].mask)
|
||||||
|
if (outputs - i > 1)
|
||||||
|
ar.delimit_array();
|
||||||
|
}
|
||||||
|
ar.end_array();
|
||||||
|
|
||||||
|
// if txnOffshoreFee is not 0, it is a conversion tx
|
||||||
|
if (txnOffshoreFee) {
|
||||||
|
ar.tag("maskSums");
|
||||||
|
ar.begin_array();
|
||||||
|
PREPARE_CUSTOM_VECTOR_SERIALIZATION(3, maskSums);
|
||||||
|
if (maskSums.size() != 3)
|
||||||
|
return false;
|
||||||
|
FIELDS(maskSums[0])
|
||||||
|
ar.delimit_array();
|
||||||
|
FIELDS(maskSums[1])
|
||||||
|
ar.delimit_array();
|
||||||
|
FIELDS(maskSums[2])
|
||||||
|
ar.end_array();
|
||||||
|
}
|
||||||
|
return ar.stream().good();
|
||||||
|
}
|
||||||
|
|
||||||
|
template<bool W, template <bool> class Archive>
|
||||||
|
bool serialize_rctsig_base_old(Archive<W> &ar, size_t inputs, size_t outputs)
|
||||||
|
{
|
||||||
if (type != RCTTypeFull && type != RCTTypeSimple && type != RCTTypeBulletproof && type != RCTTypeBulletproof2 && type != RCTTypeCLSAG && type != RCTTypeCLSAGN && type != RCTTypeHaven2 && type != RCTTypeHaven3)
|
if (type != RCTTypeFull && type != RCTTypeSimple && type != RCTTypeBulletproof && type != RCTTypeBulletproof2 && type != RCTTypeCLSAG && type != RCTTypeCLSAGN && type != RCTTypeHaven2 && type != RCTTypeHaven3)
|
||||||
return false;
|
return false;
|
||||||
VARINT_FIELD(txnFee)
|
VARINT_FIELD(txnFee)
|
||||||
@@ -432,10 +534,23 @@ namespace rct {
|
|||||||
}
|
}
|
||||||
return ar.stream().good();
|
return ar.stream().good();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
FIELD(type)
|
||||||
|
FIELD(message)
|
||||||
|
FIELD(mixRing)
|
||||||
|
FIELD(pseudoOuts)
|
||||||
|
FIELD(ecdhInfo)
|
||||||
|
FIELD(outPk)
|
||||||
|
VARINT_FIELD(txnFee)
|
||||||
|
VARINT_FIELD(txnOffshoreFee)
|
||||||
|
FIELD(maskSums)
|
||||||
|
END_SERIALIZE()
|
||||||
};
|
};
|
||||||
struct rctSigPrunable {
|
struct rctSigPrunable {
|
||||||
std::vector<rangeSig> rangeSigs;
|
std::vector<rangeSig> rangeSigs;
|
||||||
std::vector<Bulletproof> bulletproofs;
|
std::vector<Bulletproof> bulletproofs;
|
||||||
|
std::vector<BulletproofPlus> bulletproofs_plus;
|
||||||
std::vector<mgSig> MGs; // simple rct has N, full has 1
|
std::vector<mgSig> MGs; // simple rct has N, full has 1
|
||||||
std::vector<clsag> CLSAGs;
|
std::vector<clsag> CLSAGs;
|
||||||
keyV pseudoOuts; //C - for simple rct
|
keyV pseudoOuts; //C - for simple rct
|
||||||
@@ -444,11 +559,36 @@ namespace rct {
|
|||||||
template<bool W, template <bool> class Archive>
|
template<bool W, template <bool> class Archive>
|
||||||
bool serialize_rctsig_prunable(Archive<W> &ar, uint8_t type, size_t inputs, size_t outputs, size_t mixin)
|
bool serialize_rctsig_prunable(Archive<W> &ar, uint8_t type, size_t inputs, size_t outputs, size_t mixin)
|
||||||
{
|
{
|
||||||
|
if (inputs >= 0xffffffff)
|
||||||
|
return false;
|
||||||
|
if (outputs >= 0xffffffff)
|
||||||
|
return false;
|
||||||
|
if (mixin >= 0xffffffff)
|
||||||
|
return false;
|
||||||
if (type == RCTTypeNull)
|
if (type == RCTTypeNull)
|
||||||
return ar.stream().good();
|
return ar.stream().good();
|
||||||
if (type != RCTTypeFull && type != RCTTypeSimple && type != RCTTypeBulletproof && type != RCTTypeBulletproof2 && type != RCTTypeCLSAG && type != RCTTypeCLSAGN && type != RCTTypeHaven2 && type != RCTTypeHaven3)
|
if (type != RCTTypeFull && type != RCTTypeSimple && type != RCTTypeBulletproof && type != RCTTypeBulletproof2 && type != RCTTypeCLSAG && type != RCTTypeCLSAGN && type != RCTTypeHaven2 && type != RCTTypeHaven3 && type != RCTTypeBulletproofPlus)
|
||||||
return false;
|
return false;
|
||||||
if (type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2 || type == RCTTypeHaven3)
|
if (type == RCTTypeBulletproofPlus)
|
||||||
|
{
|
||||||
|
uint32_t nbp = bulletproofs_plus.size();
|
||||||
|
VARINT_FIELD(nbp)
|
||||||
|
ar.tag("bpp");
|
||||||
|
ar.begin_array();
|
||||||
|
if (nbp > outputs)
|
||||||
|
return false;
|
||||||
|
PREPARE_CUSTOM_VECTOR_SERIALIZATION(nbp, bulletproofs_plus);
|
||||||
|
for (size_t i = 0; i < nbp; ++i)
|
||||||
|
{
|
||||||
|
FIELDS(bulletproofs_plus[i])
|
||||||
|
if (nbp - i > 1)
|
||||||
|
ar.delimit_array();
|
||||||
|
}
|
||||||
|
if (n_bulletproof_plus_max_amounts(bulletproofs_plus) < outputs)
|
||||||
|
return false;
|
||||||
|
ar.end_array();
|
||||||
|
}
|
||||||
|
else if (type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2 || type == RCTTypeHaven3)
|
||||||
{
|
{
|
||||||
uint32_t nbp = bulletproofs.size();
|
uint32_t nbp = bulletproofs.size();
|
||||||
if (type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2 || type == RCTTypeHaven3)
|
if (type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2 || type == RCTTypeHaven3)
|
||||||
@@ -486,7 +626,7 @@ namespace rct {
|
|||||||
ar.end_array();
|
ar.end_array();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((type == RCTTypeCLSAG) || (type == RCTTypeCLSAGN) || (type == RCTTypeHaven2) || (type == RCTTypeHaven3))
|
if (type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2 || type == RCTTypeHaven3 || type == RCTTypeBulletproofPlus)
|
||||||
{
|
{
|
||||||
ar.tag("CLSAGs");
|
ar.tag("CLSAGs");
|
||||||
ar.begin_array();
|
ar.begin_array();
|
||||||
@@ -577,7 +717,7 @@ namespace rct {
|
|||||||
}
|
}
|
||||||
ar.end_array();
|
ar.end_array();
|
||||||
}
|
}
|
||||||
if (type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2 || type == RCTTypeHaven3)
|
if (type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2 || type == RCTTypeHaven3 || type == RCTTypeBulletproofPlus)
|
||||||
{
|
{
|
||||||
ar.tag("pseudoOuts");
|
ar.tag("pseudoOuts");
|
||||||
ar.begin_array();
|
ar.begin_array();
|
||||||
@@ -595,19 +735,32 @@ namespace rct {
|
|||||||
return ar.stream().good();
|
return ar.stream().good();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
FIELD(rangeSigs)
|
||||||
|
FIELD(bulletproofs)
|
||||||
|
FIELD(bulletproofs_plus)
|
||||||
|
FIELD(MGs)
|
||||||
|
FIELD(CLSAGs)
|
||||||
|
FIELD(pseudoOuts)
|
||||||
|
END_SERIALIZE()
|
||||||
};
|
};
|
||||||
struct rctSig: public rctSigBase {
|
struct rctSig: public rctSigBase {
|
||||||
rctSigPrunable p;
|
rctSigPrunable p;
|
||||||
|
|
||||||
keyV& get_pseudo_outs()
|
keyV& get_pseudo_outs()
|
||||||
{
|
{
|
||||||
return type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2 || type == RCTTypeHaven3 ? p.pseudoOuts : pseudoOuts;
|
return type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2 || type == RCTTypeHaven3 || type == RCTTypeBulletproofPlus ? p.pseudoOuts : pseudoOuts;
|
||||||
}
|
}
|
||||||
|
|
||||||
keyV const& get_pseudo_outs() const
|
keyV const& get_pseudo_outs() const
|
||||||
{
|
{
|
||||||
return type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2 || type == RCTTypeHaven3 ? p.pseudoOuts : pseudoOuts;
|
return type == RCTTypeBulletproof || type == RCTTypeBulletproof2 || type == RCTTypeCLSAG || type == RCTTypeCLSAGN || type == RCTTypeHaven2 || type == RCTTypeHaven3 || type == RCTTypeBulletproofPlus ? p.pseudoOuts : pseudoOuts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BEGIN_SERIALIZE_OBJECT()
|
||||||
|
FIELDS((rctSigBase&)*this)
|
||||||
|
FIELD(p)
|
||||||
|
END_SERIALIZE()
|
||||||
};
|
};
|
||||||
|
|
||||||
//other basepoint H = toPoint(cn_fast_hash(G)), G the basepoint
|
//other basepoint H = toPoint(cn_fast_hash(G)), G the basepoint
|
||||||
@@ -713,7 +866,9 @@ namespace rct {
|
|||||||
|
|
||||||
bool is_rct_simple(int type);
|
bool is_rct_simple(int type);
|
||||||
bool is_rct_bulletproof(int type);
|
bool is_rct_bulletproof(int type);
|
||||||
|
bool is_rct_bulletproof_plus(int type);
|
||||||
bool is_rct_borromean(int type);
|
bool is_rct_borromean(int type);
|
||||||
|
bool is_rct_clsag(int type);
|
||||||
|
|
||||||
static inline const rct::key &pk2rct(const crypto::public_key &pk) { return (const rct::key&)pk; }
|
static inline const rct::key &pk2rct(const crypto::public_key &pk) { return (const rct::key&)pk; }
|
||||||
static inline const rct::key &sk2rct(const crypto::secret_key &sk) { return (const rct::key&)sk; }
|
static inline const rct::key &sk2rct(const crypto::secret_key &sk) { return (const rct::key&)sk; }
|
||||||
@@ -769,5 +924,6 @@ VARIANT_TAG(binary_archive, rct::Bulletproof, 0x9c);
|
|||||||
VARIANT_TAG(binary_archive, rct::multisig_kLRki, 0x9d);
|
VARIANT_TAG(binary_archive, rct::multisig_kLRki, 0x9d);
|
||||||
VARIANT_TAG(binary_archive, rct::multisig_out, 0x9e);
|
VARIANT_TAG(binary_archive, rct::multisig_out, 0x9e);
|
||||||
VARIANT_TAG(binary_archive, rct::clsag, 0x9f);
|
VARIANT_TAG(binary_archive, rct::clsag, 0x9f);
|
||||||
|
VARIANT_TAG(binary_archive, rct::BulletproofPlus, 0xa0);
|
||||||
|
|
||||||
#endif /* RCTTYPES_H */
|
#endif /* RCTTYPES_H */
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ template <>
|
|||||||
struct binary_archive<false> : public binary_archive_base<std::istream, false>
|
struct binary_archive<false> : public binary_archive_base<std::istream, false>
|
||||||
{
|
{
|
||||||
explicit binary_archive(stream_type &s) : base_type(s) {
|
explicit binary_archive(stream_type &s) : base_type(s) {
|
||||||
stream_type::streampos pos = stream_.tellg();
|
auto pos = stream_.tellg();
|
||||||
stream_.seekg(0, std::ios_base::end);
|
stream_.seekg(0, std::ios_base::end);
|
||||||
eof_pos_ = stream_.tellg();
|
eof_pos_ = stream_.tellg();
|
||||||
stream_.seekg(pos);
|
stream_.seekg(pos);
|
||||||
|
|||||||
@@ -109,6 +109,13 @@ inline bool do_serialize(Archive &ar, bool &v)
|
|||||||
ar.serialize_varint(f); \
|
ar.serialize_varint(f); \
|
||||||
if (!ar.stream().good()) return false; \
|
if (!ar.stream().good()) return false; \
|
||||||
} while(0);
|
} while(0);
|
||||||
|
#define VERSION_FIELD(v) \
|
||||||
|
uint32_t version = v; \
|
||||||
|
do { \
|
||||||
|
ar.tag("version"); \
|
||||||
|
ar.serialize_varint(version); \
|
||||||
|
if (!ar.stream().good()) return false; \
|
||||||
|
} while(0);
|
||||||
|
|
||||||
namespace serialization {
|
namespace serialization {
|
||||||
namespace detail
|
namespace detail
|
||||||
|
|||||||
@@ -40,16 +40,33 @@
|
|||||||
template <template <bool> class Archive>
|
template <template <bool> class Archive>
|
||||||
bool do_serialize(Archive<false> &ar, zephyr_oracle::pricing_record &pr, uint8_t version)
|
bool do_serialize(Archive<false> &ar, zephyr_oracle::pricing_record &pr, uint8_t version)
|
||||||
{
|
{
|
||||||
// very basic sanity check
|
if (version < 3)
|
||||||
if (ar.remaining_bytes() < sizeof(zephyr_oracle::pricing_record)) {
|
{
|
||||||
ar.stream().setstate(std::ios::failbit);
|
// very basic sanity check
|
||||||
return false;
|
if (ar.remaining_bytes() < sizeof(zephyr_oracle::pricing_record_v1)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
zephyr_oracle::pricing_record_v1 pr_v1;
|
||||||
|
ar.serialize_blob(&pr_v1, sizeof(zephyr_oracle::pricing_record_v1), "");
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!pr_v1.write_to_pr(pr))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// very basic sanity check
|
||||||
|
if (ar.remaining_bytes() < sizeof(zephyr_oracle::pricing_record)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record), "");
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record), "");
|
|
||||||
if (!ar.stream().good())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,12 +76,51 @@ bool do_serialize(Archive<true> &ar, zephyr_oracle::pricing_record &pr, uint8_t
|
|||||||
{
|
{
|
||||||
ar.begin_string();
|
ar.begin_string();
|
||||||
|
|
||||||
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record), "");
|
if (version < 3)
|
||||||
|
{
|
||||||
if (!ar.stream().good())
|
zephyr_oracle::pricing_record_v1 pr_v1;
|
||||||
|
if (!pr_v1.read_from_pr(pr))
|
||||||
|
return false;
|
||||||
|
ar.serialize_blob(&pr_v1, sizeof(zephyr_oracle::pricing_record_v1), "");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record), "");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
ar.end_string();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// read
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<false> &ar, zephyr_oracle::pricing_record_v1 &pr, uint8_t version)
|
||||||
|
{
|
||||||
|
// very basic sanity check
|
||||||
|
if (ar.remaining_bytes() < sizeof(zephyr_oracle::pricing_record_v1)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record_v1), "");
|
||||||
|
if (!ar.good())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// write
|
||||||
|
template <template <bool> class Archive>
|
||||||
|
bool do_serialize(Archive<true> &ar, zephyr_oracle::pricing_record_v1 &pr, uint8_t version)
|
||||||
|
{
|
||||||
|
ar.begin_string();
|
||||||
|
ar.serialize_blob(&pr, sizeof(zephyr_oracle::pricing_record_v1), "");
|
||||||
|
if (!ar.good())
|
||||||
return false;
|
return false;
|
||||||
ar.end_string();
|
ar.end_string();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
BLOB_SERIALIZER(zephyr_oracle::pricing_record);
|
BLOB_SERIALIZER(zephyr_oracle::pricing_record);
|
||||||
|
BLOB_SERIALIZER(zephyr_oracle::pricing_record_v1);
|
||||||
|
|||||||
@@ -40,22 +40,39 @@ namespace zephyr_oracle
|
|||||||
{
|
{
|
||||||
struct pr_serialized
|
struct pr_serialized
|
||||||
{
|
{
|
||||||
uint64_t zEPHUSD;
|
uint64_t spot;
|
||||||
uint64_t zEPHRSV;
|
uint64_t moving_average;
|
||||||
|
uint64_t stable;
|
||||||
|
uint64_t stable_ma;
|
||||||
|
uint64_t reserve;
|
||||||
|
uint64_t reserve_ma;
|
||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
|
std::string signature;
|
||||||
|
|
||||||
BEGIN_KV_SERIALIZE_MAP()
|
BEGIN_KV_SERIALIZE_MAP()
|
||||||
KV_SERIALIZE(zEPHUSD)
|
KV_SERIALIZE(spot)
|
||||||
KV_SERIALIZE(zEPHRSV)
|
KV_SERIALIZE(moving_average)
|
||||||
|
KV_SERIALIZE(stable)
|
||||||
|
KV_SERIALIZE(stable_ma)
|
||||||
|
KV_SERIALIZE(reserve)
|
||||||
|
KV_SERIALIZE(reserve_ma)
|
||||||
KV_SERIALIZE(timestamp)
|
KV_SERIALIZE(timestamp)
|
||||||
|
KV_SERIALIZE(signature)
|
||||||
END_KV_SERIALIZE_MAP()
|
END_KV_SERIALIZE_MAP()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pricing_record::pricing_record() noexcept
|
pricing_record::pricing_record() noexcept
|
||||||
: zEPHUSD(0)
|
: spot(0)
|
||||||
, zEPHRSV(0)
|
, moving_average(0)
|
||||||
, timestamp(0) {}
|
, stable(0)
|
||||||
|
, stable_ma(0)
|
||||||
|
, reserve(0)
|
||||||
|
, reserve_ma(0)
|
||||||
|
, timestamp(0)
|
||||||
|
{
|
||||||
|
std::memset(signature, 0, sizeof(signature));
|
||||||
|
}
|
||||||
|
|
||||||
bool pricing_record::_load(epee::serialization::portable_storage& src, epee::serialization::section* hparent)
|
bool pricing_record::_load(epee::serialization::portable_storage& src, epee::serialization::section* hparent)
|
||||||
{
|
{
|
||||||
@@ -63,52 +80,71 @@ namespace zephyr_oracle
|
|||||||
if (in._load(src, hparent))
|
if (in._load(src, hparent))
|
||||||
{
|
{
|
||||||
// Copy everything into the local instance
|
// Copy everything into the local instance
|
||||||
zEPHUSD = in.zEPHUSD;
|
spot = in.spot;
|
||||||
zEPHRSV = in.zEPHRSV;
|
moving_average = in.moving_average;
|
||||||
|
stable = in.stable;
|
||||||
|
stable_ma = in.stable_ma;
|
||||||
|
reserve = in.reserve;
|
||||||
|
reserve_ma = in.reserve_ma;
|
||||||
timestamp = in.timestamp;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Report error here?
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pricing_record::store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const
|
bool pricing_record::store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const
|
||||||
{
|
{
|
||||||
const pr_serialized out{zEPHUSD,zEPHRSV,timestamp};
|
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{spot,moving_average,stable,stable_ma,reserve,reserve_ma,timestamp,sig_hex};
|
||||||
return out.store(dest, hparent);
|
return out.store(dest, hparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
pricing_record::pricing_record(const pricing_record& orig) noexcept
|
pricing_record::pricing_record(const pricing_record& orig) noexcept
|
||||||
: zEPHUSD(orig.zEPHUSD)
|
: spot(orig.spot)
|
||||||
, zEPHRSV(orig.zEPHRSV)
|
, moving_average(orig.moving_average)
|
||||||
, timestamp(orig.timestamp) {}
|
, stable(orig.stable)
|
||||||
|
, stable_ma(orig.stable_ma)
|
||||||
|
, reserve(orig.reserve)
|
||||||
|
, reserve_ma(orig.reserve_ma)
|
||||||
|
, timestamp(orig.timestamp)
|
||||||
|
{
|
||||||
|
std::memcpy(signature, orig.signature, sizeof(signature));
|
||||||
|
}
|
||||||
|
|
||||||
pricing_record& pricing_record::operator=(const pricing_record& orig) noexcept
|
pricing_record& pricing_record::operator=(const pricing_record& orig) noexcept
|
||||||
{
|
{
|
||||||
zEPHUSD = orig.zEPHUSD;
|
spot = orig.spot;
|
||||||
zEPHRSV = orig.zEPHRSV;
|
moving_average = orig.moving_average;
|
||||||
|
stable = orig.stable;
|
||||||
|
stable_ma = orig.stable_ma;
|
||||||
|
reserve = orig.reserve;
|
||||||
|
reserve_ma = orig.reserve_ma;
|
||||||
timestamp = orig.timestamp;
|
timestamp = orig.timestamp;
|
||||||
|
::memcpy(signature, orig.signature, sizeof(signature));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t pricing_record::operator[](const std::string& asset_type) const
|
|
||||||
{
|
|
||||||
if (asset_type == "ZEPH") {
|
|
||||||
return zEPHUSD; // ZEPH spot price
|
|
||||||
} else if (asset_type == "ZEPHUSD") {
|
|
||||||
return 1000000000000; // 1
|
|
||||||
} else if (asset_type == "ZEPHRSV") {
|
|
||||||
return zEPHRSV; // ZEPHRSV spot price
|
|
||||||
} 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
|
bool pricing_record::equal(const pricing_record& other) const noexcept
|
||||||
{
|
{
|
||||||
return ((zEPHUSD == other.zEPHUSD) &&
|
return ((spot == other.spot) &&
|
||||||
(zEPHRSV == other.zEPHRSV) &&
|
(moving_average == other.moving_average) &&
|
||||||
(timestamp == other.timestamp));
|
(stable == other.stable) &&
|
||||||
|
(stable_ma == other.stable_ma) &&
|
||||||
|
(reserve == other.reserve) &&
|
||||||
|
(reserve_ma == other.reserve_ma) &&
|
||||||
|
(timestamp == other.timestamp) &&
|
||||||
|
!::memcmp(signature, other.signature, sizeof(signature)));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pricing_record::empty() const noexcept
|
bool pricing_record::empty() const noexcept
|
||||||
@@ -117,6 +153,69 @@ namespace zephyr_oracle
|
|||||||
return (*this).equal(empty_pr);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Build the JSON string, so that we can verify the signature
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "{\"spot\":" << spot;
|
||||||
|
oss << ",\"moving_average\":" << moving_average;
|
||||||
|
oss << ",\"timestamp\":" << timestamp;
|
||||||
|
oss << "}";
|
||||||
|
std::string message = oss.str();
|
||||||
|
|
||||||
|
// 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 *)signature, 64);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pricing_record::has_missing_rates() const noexcept
|
||||||
|
{
|
||||||
|
return (spot == 0) || (moving_average == 0) || (stable == 0) || (stable_ma == 0) || (reserve == 0) || (reserve_ma == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// overload for pr validation for block
|
||||||
bool pricing_record::valid(uint32_t hf_version, uint64_t bl_timestamp, uint64_t last_bl_timestamp) const
|
bool pricing_record::valid(uint32_t hf_version, uint64_t bl_timestamp, uint64_t last_bl_timestamp) const
|
||||||
{
|
{
|
||||||
if (hf_version < 3) {
|
if (hf_version < 3) {
|
||||||
@@ -126,16 +225,29 @@ namespace zephyr_oracle
|
|||||||
|
|
||||||
if (this->empty())
|
if (this->empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (this->has_missing_rates()) {
|
||||||
|
LOG_ERROR("Pricing record has missing rates.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string const MAINNET_ORACLE_PUBLIC_KEY = "-----BEGIN PUBLIC KEY-----\n"
|
||||||
|
"MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAO5hVuc6ylYMbj3WhqOMoAcJ0SD4e3zW\n"
|
||||||
|
"edsUmhQeYwBkelAaFyxhX4ZotP+b/cFr2mX5iuND1znEnMZkyg+YmtkCAwEAAQ==\n"
|
||||||
|
"-----END PUBLIC KEY-----\n";
|
||||||
|
|
||||||
|
if (!verifySignature(MAINNET_ORACLE_PUBLIC_KEY)) {
|
||||||
|
LOG_ERROR("Invalid pricing record signature.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// validate the timestmap
|
// validate the timestmap
|
||||||
if (this->timestamp > bl_timestamp + PRICING_RECORD_VALID_TIME_DIFF_FROM_BLOCK) {
|
if (this->timestamp > bl_timestamp + PRICING_RECORD_VALID_TIME_DIFF_FROM_BLOCK) {
|
||||||
LOG_ERROR("Pricing record timestamp is too far in the future.");
|
LOG_ERROR("Pricing record timestamp is too far in the future.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->timestamp <= last_bl_timestamp) {
|
||||||
|
|
||||||
if (this->timestamp <= last_bl_timestamp - PRICING_RECORD_VALID_TIME_DIFF_FROM_BLOCK) {
|
|
||||||
LOG_ERROR("Pricing record timestamp: " << this->timestamp << ", block timestamp: " << bl_timestamp);
|
LOG_ERROR("Pricing record timestamp: " << this->timestamp << ", block timestamp: " << bl_timestamp);
|
||||||
LOG_ERROR("Pricing record timestamp is too old.");
|
LOG_ERROR("Pricing record timestamp is too old.");
|
||||||
return false;
|
return false;
|
||||||
@@ -144,3 +256,4 @@ namespace zephyr_oracle
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,15 +57,28 @@ namespace epee
|
|||||||
|
|
||||||
namespace zephyr_oracle
|
namespace zephyr_oracle
|
||||||
{
|
{
|
||||||
|
#pragma pack(push, 1)
|
||||||
|
POD_CLASS pricing_record_pre {
|
||||||
|
uint64_t zEPHUSD;
|
||||||
|
uint64_t zEPHRSV;
|
||||||
|
uint64_t timestamp;
|
||||||
|
};
|
||||||
|
#pragma pack(pop)
|
||||||
class pricing_record
|
class pricing_record
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Fields
|
// Fields
|
||||||
uint64_t zEPHUSD;
|
uint64_t spot;
|
||||||
uint64_t zEPHRSV;
|
uint64_t moving_average;
|
||||||
|
uint64_t stable;
|
||||||
|
uint64_t stable_ma;
|
||||||
|
uint64_t reserve;
|
||||||
|
uint64_t reserve_ma;
|
||||||
uint64_t timestamp;
|
uint64_t timestamp;
|
||||||
|
unsigned char signature[64];
|
||||||
|
|
||||||
// Default c'tor
|
// Default c'tor
|
||||||
pricing_record() noexcept;
|
pricing_record() noexcept;
|
||||||
//! Load from epee p2p format
|
//! Load from epee p2p format
|
||||||
@@ -76,6 +89,8 @@ namespace zephyr_oracle
|
|||||||
~pricing_record() = default;
|
~pricing_record() = default;
|
||||||
bool equal(const pricing_record& other) const noexcept;
|
bool equal(const pricing_record& other) const noexcept;
|
||||||
bool empty() const noexcept;
|
bool empty() const noexcept;
|
||||||
|
bool verifySignature(const std::string& public_key) const;
|
||||||
|
bool has_missing_rates() const noexcept;
|
||||||
bool valid(uint32_t hf_version, uint64_t bl_timestamp, uint64_t last_bl_timestamp) 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;
|
pricing_record& operator=(const pricing_record& orig) noexcept;
|
||||||
@@ -92,4 +107,34 @@ namespace zephyr_oracle
|
|||||||
return !a.equal(b);
|
return !a.equal(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class pricing_record_v1
|
||||||
|
{
|
||||||
|
|
||||||
|
public:
|
||||||
|
uint64_t zEPHUSD;
|
||||||
|
uint64_t zEPHRSV;
|
||||||
|
uint64_t timestamp;
|
||||||
|
|
||||||
|
bool write_to_pr(zephyr_oracle::pricing_record &pr)
|
||||||
|
{
|
||||||
|
pr.spot = 0;
|
||||||
|
pr.moving_average = 0;
|
||||||
|
pr.stable = 0;
|
||||||
|
pr.stable_ma = 0;
|
||||||
|
pr.reserve = 0;
|
||||||
|
pr.reserve_ma = 0;
|
||||||
|
pr.timestamp = 0;
|
||||||
|
std::memset(pr.signature, 0, sizeof(zephyr_oracle::pricing_record::signature));
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool read_from_pr(zephyr_oracle::pricing_record &pr)
|
||||||
|
{
|
||||||
|
zEPHUSD = 0;
|
||||||
|
zEPHRSV = 0;
|
||||||
|
timestamp = 0;
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
} // oracle
|
} // oracle
|
||||||
|
|||||||
Reference in New Issue
Block a user