Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e7a1430242 |
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cryptoforknote-util",
|
"name": "cryptoforknote-util",
|
||||||
"version": "15.5.8",
|
"version": "15.5.9",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "LucasJones",
|
"name": "LucasJones",
|
||||||
"email": "lucasjonesdev@hotmail.co.uk"
|
"email": "lucasjonesdev@hotmail.co.uk"
|
||||||
|
|||||||
@@ -223,82 +223,12 @@ namespace salvium_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());
|
|
||||||
|
|
||||||
// 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.");
|
|
||||||
|
|
||||||
// Build the JSON string, so that we can verify the signature
|
|
||||||
std::ostringstream oss;
|
|
||||||
oss << "{\"pr_version\":" << pr_version;
|
|
||||||
oss << ",\"height\":" << height;
|
|
||||||
oss << ",\"supply\":{\"SAL\":" << supply.sal <<",\"VSD\":" << supply.vsd << "}";
|
|
||||||
oss << ",\"assets\":[";
|
|
||||||
bool first = true;
|
|
||||||
for (const auto& asset: assets) {
|
|
||||||
if (first)
|
|
||||||
first=false;
|
|
||||||
else
|
|
||||||
oss << ",";
|
|
||||||
oss << "{\"asset_type\":\"" << asset.asset_type << "\",\"spot_price\":" << asset.spot_price << ",\"ma_price\":" << asset.ma_price << "}";
|
|
||||||
}
|
|
||||||
oss << "]";
|
|
||||||
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.data(), signature.size());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
// overload for pr validation for block
|
// overload for pr validation for block
|
||||||
bool pricing_record::valid(cryptonote::network_type nettype, 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 < HF_VERSION_SLIPPAGE_YIELD) {
|
|
||||||
if (!this->empty())
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->empty())
|
if (this->empty())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!verifySignature(get_config(nettype).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.");
|
||||||
|
|||||||
@@ -73,11 +73,6 @@ namespace salvium_oracle
|
|||||||
bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent);
|
bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent);
|
||||||
//! Store in epee p2p format
|
//! Store in epee p2p format
|
||||||
bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const;
|
bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const;
|
||||||
|
|
||||||
BEGIN_SERIALIZE_OBJECT()
|
|
||||||
VARINT_FIELD(sal)
|
|
||||||
VARINT_FIELD(vsd)
|
|
||||||
END_SERIALIZE()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const supply_data& a, const supply_data& b) noexcept
|
inline bool operator==(const supply_data& a, const supply_data& b) noexcept
|
||||||
@@ -95,12 +90,6 @@ namespace salvium_oracle
|
|||||||
bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent);
|
bool _load(epee::serialization::portable_storage& src, epee::serialization::section* hparent);
|
||||||
//! Store in epee p2p format
|
//! Store in epee p2p format
|
||||||
bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const;
|
bool store(epee::serialization::portable_storage& dest, epee::serialization::section* hparent) const;
|
||||||
|
|
||||||
BEGIN_SERIALIZE_OBJECT()
|
|
||||||
FIELD(asset_type)
|
|
||||||
VARINT_FIELD(spot_price)
|
|
||||||
VARINT_FIELD(ma_price)
|
|
||||||
END_SERIALIZE()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const asset_data& a, const asset_data& b) noexcept
|
inline bool operator==(const asset_data& a, const asset_data& b) noexcept
|
||||||
@@ -130,20 +119,10 @@ namespace salvium_oracle
|
|||||||
~pricing_record() noexcept;
|
~pricing_record() noexcept;
|
||||||
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 valid(uint32_t hf_version, uint64_t bl_timestamp, uint64_t last_bl_timestamp) const;
|
||||||
bool valid(cryptonote::network_type nettype, 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;
|
||||||
uint64_t operator[](const std::string& asset_type) const;
|
uint64_t operator[](const std::string& asset_type) const;
|
||||||
|
|
||||||
BEGIN_SERIALIZE_OBJECT()
|
|
||||||
VARINT_FIELD(pr_version)
|
|
||||||
VARINT_FIELD(height)
|
|
||||||
FIELD(supply)
|
|
||||||
FIELD(assets)
|
|
||||||
VARINT_FIELD(timestamp)
|
|
||||||
FIELD(signature)
|
|
||||||
END_SERIALIZE()
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool operator==(const pricing_record& a, const pricing_record& b) noexcept
|
inline bool operator==(const pricing_record& a, const pricing_record& b) noexcept
|
||||||
|
|||||||
@@ -165,4 +165,4 @@ bool do_serialize(Archive<true> &ar, salvium_oracle::pricing_record &pr, uint8_t
|
|||||||
|
|
||||||
//BLOB_SERIALIZER(salvium_oracle::supply_data);
|
//BLOB_SERIALIZER(salvium_oracle::supply_data);
|
||||||
//BLOB_SERIALIZER(salvium_oracle::asset_data);
|
//BLOB_SERIALIZER(salvium_oracle::asset_data);
|
||||||
//BLOB_SERIALIZER(salvium_oracle::pricing_record);
|
BLOB_SERIALIZER(salvium_oracle::pricing_record);
|
||||||
|
|||||||
Reference in New Issue
Block a user