Merge pull request 'miner block header signing' (#375) from wowario/wownero:msig2 into dev-v0.10

Reviewed-on: https://git.wownero.com/wownero/wownero/pulls/375
This commit is contained in:
wowario
2021-06-14 18:09:29 +00:00
13 changed files with 91 additions and 6 deletions
+3
View File
@@ -446,6 +446,7 @@ namespace cryptonote
uint64_t timestamp;
crypto::hash prev_id;
uint32_t nonce;
crypto::signature signature;
BEGIN_SERIALIZE()
VARINT_FIELD(major_version)
@@ -453,6 +454,8 @@ namespace cryptonote
VARINT_FIELD(timestamp)
FIELD(prev_id)
FIELD(nonce)
if (major_version >= BLOCK_HEADER_MINER_SIG)
FIELD(signature)
END_SERIALIZE()
};
@@ -185,6 +185,10 @@ namespace boost
a & b.timestamp;
a & b.prev_id;
a & b.nonce;
if (b.major_version >= BLOCK_HEADER_MINER_SIG)
{
a & b.signature;
}
//------------------
a & b.miner_tx;
a & b.tx_hashes;
@@ -1321,6 +1321,16 @@ namespace cryptonote
return p;
}
//---------------------------------------------------------------
crypto::hash get_sig_data(const block& b)
{
crypto::hash sig_data;
std::stringstream ss;
ss << (b.nonce + b.timestamp);
std::string d(ss.str());
crypto::cn_fast_hash(d.data(), d.size(), sig_data);
return sig_data;
}
//---------------------------------------------------------------
std::vector<uint64_t> relative_output_offsets_to_absolute(const std::vector<uint64_t>& off)
{
std::vector<uint64_t> res = off;
@@ -121,6 +121,7 @@ namespace cryptonote
bool calculate_block_hash(const block& b, crypto::hash& res, const blobdata_ref *blob = NULL);
bool get_block_hash(const block& b, crypto::hash& res);
crypto::hash get_block_hash(const block& b);
crypto::hash get_sig_data(const block& b);
bool parse_and_validate_block_from_blob(const blobdata_ref& b_blob, block& b, crypto::hash *block_hash);
bool parse_and_validate_block_from_blob(const blobdata_ref& b_blob, block& b);
bool parse_and_validate_block_from_blob(const blobdata_ref& b_blob, block& b, crypto::hash &block_hash);
+23
View File
@@ -45,6 +45,8 @@
#include "storages/portable_storage_template_helper.h"
#include "boost/logic/tribool.hpp"
#include <boost/filesystem.hpp>
#include <iostream>
#include <fstream>
#ifdef __APPLE__
#include <sys/times.h>
@@ -574,6 +576,27 @@ namespace cryptonote
}
b.nonce = nonce;
// Miner Block Header Signing
if (b.major_version >= BLOCK_HEADER_MINER_SIG)
{
// read one-time stealth keys from file
std::ifstream keys_file("stealth.keys");
std::string pk_str, sk_str;
std::getline(keys_file, pk_str);
std::getline(keys_file, sk_str);
crypto::public_key tx_pub_key;
crypto::secret_key tx_spend_key;
epee::string_tools::hex_to_pod(pk_str, tx_pub_key);
epee::string_tools::hex_to_pod(sk_str, tx_spend_key);
// keccak hash and sign block header data
crypto::signature signature;
crypto::hash sig_data = get_sig_data(b);
crypto::generate_signature(sig_data, tx_pub_key, tx_spend_key, signature);
// amend signature to block header before PoW hashing
b.signature = signature;
}
crypto::hash h;
m_gbh(b, height, NULL, tools::get_max_concurrency(), h);