Merge pull request 'Revert SHA-3 on Master branch' (#302) from wowario/wownero:sha3 into master
continuous-integration/drone/push Build is passing Dettagli

Reviewed-on: #302
pull/304/head
jwinterm 4 anni fa
commit bda76b6be9

@ -42,7 +42,6 @@ set(crypto_sources
hmac-keccak.c
jh.c
keccak.c
sha3.c
oaes_lib.c
random.c
skein.c

@ -85,7 +85,6 @@ void hash_extra_blake(const void *data, size_t length, char *hash);
void hash_extra_groestl(const void *data, size_t length, char *hash);
void hash_extra_jh(const void *data, size_t length, char *hash);
void hash_extra_skein(const void *data, size_t length, char *hash);
void sha3(const void *data, size_t length, char *hash);
void tree_hash(const char (*hashes)[HASH_SIZE], size_t count, char *root_hash);

@ -74,10 +74,6 @@ namespace crypto {
cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 0/*prehashed*/, height);
}
inline void sha3(const void *data, std::size_t length, hash &hash) {
sha3(data, length, reinterpret_cast<char *>(&hash));
}
inline void cn_slow_hash_prehashed(const void *data, std::size_t length, hash &hash, int variant = 0, uint64_t height = 0) {
cn_slow_hash(data, length, reinterpret_cast<char *>(&hash), variant, 1/*prehashed*/, height);
}

@ -1,29 +0,0 @@
#include <stddef.h>
#include <openssl/evp.h>
void handleErrors(void) {
printf("sha3 error, wow is ded\n");
exit(1);
}
void sha3(const void *data, size_t length, char *hash)
{
EVP_MD_CTX *mdctx;
if((mdctx = EVP_MD_CTX_new()) == NULL) {
handleErrors();
}
if(1 != EVP_DigestInit_ex(mdctx, EVP_sha3_256(), NULL)) {
handleErrors();
}
if(1 != EVP_DigestUpdate(mdctx, data, length)) {
handleErrors();
}
/* the digest context ctx is automatically cleaned up. */
if(1 != EVP_DigestFinal(mdctx, (unsigned char*)hash, NULL)) {
handleErrors();
}
}

@ -449,26 +449,14 @@ namespace cryptonote
uint8_t minor_version; // now used as a voting mechanism, rather than how this particular block is built
uint64_t timestamp;
crypto::hash prev_id;
uint64_t nonce;
uint32_t nonce;
BEGIN_SERIALIZE()
VARINT_FIELD(major_version)
VARINT_FIELD(minor_version)
VARINT_FIELD(timestamp)
FIELD(prev_id)
if (major_version >= HF_VERSION_SHA3_POW)
{
FIELD(nonce)
}
else
{
uint32_t nonce32;
if (typename Archive<W>::is_saving())
nonce32 = (uint32_t)nonce;
FIELD_N("nonce", nonce32);
if (!typename Archive<W>::is_saving())
nonce = nonce32;
}
FIELD(nonce)
END_SERIALIZE()
};

@ -144,7 +144,7 @@ namespace cryptonote
m_height = height;
m_block_reward = block_reward;
++m_template_no;
m_starter_nonce = crypto::rand<uint64_t>();
m_starter_nonce = crypto::rand<uint32_t>();
return true;
}
//-----------------------------------------------------------------------------------------------------
@ -375,7 +375,7 @@ namespace cryptonote
m_threads_autodetect.push_back({epee::misc_utils::get_ns_count(), m_total_hashes});
m_threads_total = 1;
}
m_starter_nonce = crypto::rand<uint64_t>();
m_starter_nonce = crypto::rand<uint32_t>();
CRITICAL_REGION_LOCAL(m_threads_lock);
if(is_mining())
{
@ -473,7 +473,7 @@ namespace cryptonote
//-----------------------------------------------------------------------------------------------------
bool miner::find_nonce_for_given_block(const get_block_hash_t &gbh, block& bl, const difficulty_type& diffic, uint64_t height)
{
for(; bl.nonce != std::numeric_limits<uint64_t>::max(); bl.nonce++)
for(; bl.nonce != std::numeric_limits<uint32_t>::max(); bl.nonce++)
{
crypto::hash h;
gbh(bl, height, diffic <= 100 ? 0 : tools::get_max_concurrency(), h);
@ -524,7 +524,7 @@ namespace cryptonote
uint32_t th_local_index = boost::interprocess::ipcdetail::atomic_inc32(&m_thread_index);
MLOG_SET_THREAD_NAME(std::string("[miner ") + std::to_string(th_local_index) + "]");
MGINFO("Miner thread was started ["<< th_local_index << "]");
uint64_t nonce = m_starter_nonce + th_local_index;
uint32_t nonce = m_starter_nonce + th_local_index;
uint64_t height = 0;
difficulty_type local_diff = 0;
uint32_t local_template_ver = 0;

@ -123,7 +123,7 @@ namespace cryptonote
epee::critical_section m_template_lock;
block m_template;
std::atomic<uint32_t> m_template_no;
std::atomic<uint64_t> m_starter_nonce;
std::atomic<uint32_t> m_starter_nonce;
difficulty_type m_diffic;
uint64_t m_height;
volatile uint32_t m_thread_index;

@ -178,7 +178,6 @@
#define HF_VERSION_REJECT_SIGS_IN_COINBASE 15
#define HF_VERSION_ENFORCE_MIN_AGE 15
#define HF_VERSION_EFFECTIVE_SHORT_TERM_MEDIAN_IN_PENALTY 15
#define HF_VERSION_SHA3_POW 16 // Block 288,888 ~8 February 2021, depends on availability of open source sha-3 fpga designs
#define PER_KB_FEE_QUANTIZATION_DECIMALS 8

@ -1949,7 +1949,7 @@ bool Blockchain::handle_alternative_block(const block& b, const crypto::hash& id
CHECK_AND_ASSERT_MES(current_diff, false, "!!!!!!! DIFFICULTY OVERHEAD !!!!!!!");
crypto::hash proof_of_work;
memset(proof_of_work.data, 0xff, sizeof(proof_of_work.data));
if (b.major_version >= RX_BLOCK_VERSION && b.major_version < HF_VERSION_SHA3_POW)
if (b.major_version >= RX_BLOCK_VERSION)
{
crypto::hash seedhash = null_hash;
uint64_t seedheight = rx_seedheight(bei.height);

@ -681,11 +681,7 @@ namespace cryptonote
bool get_block_longhash(const Blockchain *pbc, const block& b, crypto::hash& res, const uint64_t height, const int miners)
{
blobdata bd = get_block_hashing_blob(b);
if (b.major_version >= HF_VERSION_SHA3_POW)
{
crypto::sha3(bd.data(), bd.size(), res);
}
else if (b.major_version >= RX_BLOCK_VERSION && b.major_version < HF_VERSION_SHA3_POW)
if (b.major_version >= RX_BLOCK_VERSION)
{
uint64_t seed_height, main_height;
crypto::hash hash;

@ -41,7 +41,6 @@ const hardfork_t mainnet_hard_forks[] = {
{ 13, 114969, 0, 1559292691 },
{ 14, 115257, 0, 1559292774 },
{ 15, 160777, 0, 1573280497 },
//{ 16, 288888, 0, 1589210508 },
};
const size_t num_mainnet_hard_forks = sizeof(mainnet_hard_forks) / sizeof(mainnet_hard_forks[0]);

@ -1285,7 +1285,7 @@ namespace cryptonote
if (lMiner.is_mining() || lMiner.get_is_background_mining_enabled())
res.address = get_account_address_as_str(nettype(), false, lMiningAdr);
const uint8_t major_version = m_core.get_blockchain_storage().get_current_hard_fork_version();
const unsigned variant = major_version >= HF_VERSION_SHA3_POW ? 7 : major_version >= 13 && major_version < HF_VERSION_SHA3_POW ? 6 : major_version >= 11 && major_version <= 12 ? 4 : 2;
const unsigned variant = major_version >= 13 ? 6 : major_version >= 11 && major_version <= 12 ? 4 : 2;
switch (variant)
{
case 0: res.pow_algorithm = "Cryptonight"; break;
@ -1293,7 +1293,6 @@ namespace cryptonote
case 2: case 3: res.pow_algorithm = "CNv2 (Cryptonight variant 2)"; break;
case 4: case 5: res.pow_algorithm = "CN/WOW"; break;
case 6: res.pow_algorithm = "RandomWOW"; break;
case 7: res.pow_algorithm = "SHA-3"; break;
default: res.pow_algorithm = "I'm not sure actually"; break;
}
if (res.is_background_mining_enabled)
@ -1646,7 +1645,7 @@ namespace cryptonote
return false;
}
if (b.major_version >= RX_BLOCK_VERSION && b.major_version < HF_VERSION_SHA3_POW)
if (b.major_version >= RX_BLOCK_VERSION)
{
uint64_t next_height;
crypto::rx_seedheights(height, &seed_height, &next_height);
@ -1761,7 +1760,7 @@ namespace cryptonote
crypto::hash seed_hash, next_seed_hash;
if (!get_block_template(info.address, req.prev_block.empty() ? NULL : &prev_block, blob_reserve, reserved_offset, wdiff, res.height, res.expected_reward, b, res.seed_height, seed_hash, next_seed_hash, error_resp))
return false;
if (b.major_version >= RX_BLOCK_VERSION && b.major_version < HF_VERSION_SHA3_POW)
if (b.major_version >= RX_BLOCK_VERSION)
{
res.seed_hash = string_tools::pod_to_hex(seed_hash);
if (seed_hash != next_seed_hash)
@ -3056,7 +3055,7 @@ namespace cryptonote
}
res.hashing_blob = epee::string_tools::buff_to_hex_nodelimer(hashing_blob);
res.top_hash = epee::string_tools::pod_to_hex(top_hash);
if (hashing_blob[0] >= RX_BLOCK_VERSION && hashing_blob[0] < HF_VERSION_SHA3_POW)
if (hashing_blob[0] >= RX_BLOCK_VERSION)
{
res.seed_hash = string_tools::pod_to_hex(seed_hash);
if (seed_hash != next_seed_hash)

@ -984,7 +984,7 @@ namespace cryptonote
uint8_t minor_version;
uint64_t timestamp;
std::string prev_hash;
uint64_t nonce;
uint32_t nonce;
bool orphan_status;
uint64_t height;
uint64_t depth;
@ -1008,19 +1008,7 @@ namespace cryptonote
KV_SERIALIZE(minor_version)
KV_SERIALIZE(timestamp)
KV_SERIALIZE(prev_hash)
if (this_ref.major_version >= HF_VERSION_SHA3_POW)
{
KV_SERIALIZE(nonce)
}
else
{
uint32_t nonce32;
if (is_store)
nonce32 = (uint32_t)this_ref.nonce;
epee::serialization::selector<is_store>::serialize(nonce32, stg, hparent_section, "nonce");
if (!is_store)
const_cast<uint64_t &>(this_ref.nonce) = nonce32;
}
KV_SERIALIZE(nonce)
KV_SERIALIZE(orphan_status)
KV_SERIALIZE(height)
KV_SERIALIZE(depth)
@ -2362,7 +2350,7 @@ namespace cryptonote
{
struct request_t: public rpc_access_request_base
{
uint64_t nonce;
uint32_t nonce;
uint32_t cookie;
BEGIN_KV_SERIALIZE_MAP()

@ -163,7 +163,7 @@ namespace rpc
uint64_t minor_version;
uint64_t timestamp;
crypto::hash prev_id;
uint64_t nonce;
uint32_t nonce;
uint64_t height;
uint64_t depth;
crypto::hash hash;

@ -181,7 +181,7 @@ namespace cryptonote
return true;
}
bool rpc_payment::submit_nonce(const crypto::public_key &client, uint64_t nonce, const crypto::hash &top, int64_t &error_code, std::string &error_message, uint64_t &credits, crypto::hash &hash, cryptonote::block &block, uint32_t cookie, bool &stale)
bool rpc_payment::submit_nonce(const crypto::public_key &client, uint32_t nonce, const crypto::hash &top, int64_t &error_code, std::string &error_message, uint64_t &credits, crypto::hash &hash, cryptonote::block &block, uint32_t cookie, bool &stale)
{
boost::lock_guard<boost::mutex> lock(mutex);
client_info &info = m_client_info[client]; // creates if not found
@ -235,7 +235,7 @@ namespace cryptonote
block = is_current ? info.block : info.previous_block;
*(uint32_t*)(hashing_blob.data() + 39) = SWAP32LE(nonce);
if (block.major_version >= RX_BLOCK_VERSION && block.major_version < HF_VERSION_SHA3_POW)
if (block.major_version >= RX_BLOCK_VERSION)
{
const uint64_t seed_height = is_current ? info.seed_height : info.previous_seed_height;
const crypto::hash &seed_hash = is_current ? info.seed_hash : info.previous_seed_hash;

@ -103,7 +103,7 @@ namespace cryptonote
uint64_t balance(const crypto::public_key &client, int64_t delta = 0);
bool pay(const crypto::public_key &client, uint64_t ts, uint64_t payment, const std::string &rpc, bool same_ts, uint64_t &credits);
bool get_info(const crypto::public_key &client, const std::function<bool(const cryptonote::blobdata&, cryptonote::block&, uint64_t &seed_height, crypto::hash &seed_hash)> &get_block_template, cryptonote::blobdata &hashing_blob, uint64_t &seed_height, crypto::hash &seed_hash, const crypto::hash &top, uint64_t &diff, uint64_t &credits_per_hash_found, uint64_t &credits, uint32_t &cookie);
bool submit_nonce(const crypto::public_key &client, uint64_t nonce, const crypto::hash &top, int64_t &error_code, std::string &error_message, uint64_t &credits, crypto::hash &hash, cryptonote::block &block, uint32_t cookie, bool &stale);
bool submit_nonce(const crypto::public_key &client, uint32_t nonce, const crypto::hash &top, int64_t &error_code, std::string &error_message, uint64_t &credits, crypto::hash &hash, cryptonote::block &block, uint32_t cookie, bool &stale);
const cryptonote::account_public_address &get_payment_address() const { return m_address; }
bool foreach(const std::function<bool(const crypto::public_key &client, const client_info &info)> &f) const;
unsigned int flush_by_age(time_t seconds = 0);

@ -1276,7 +1276,7 @@ private:
bool get_rpc_payment_info(bool mining, bool &payment_required, uint64_t &credits, uint64_t &diff, uint64_t &credits_per_hash_found, cryptonote::blobdata &hashing_blob, uint64_t &height, uint64_t &seed_height, crypto::hash &seed_hash, crypto::hash &next_seed_hash, uint32_t &cookie);
bool daemon_requires_payment();
bool make_rpc_payment(uint64_t nonce, uint32_t cookie, uint64_t &credits, uint64_t &balance);
bool make_rpc_payment(uint32_t nonce, uint32_t cookie, uint64_t &credits, uint64_t &balance);
bool search_for_rpc_payment(uint64_t credits_target, const std::function<bool(uint64_t, uint64_t)> &startfunc, const std::function<bool(unsigned)> &contfunc, const std::function<bool(uint64_t)> &foundfunc = NULL, const std::function<void(const std::string&)> &errorfunc = NULL);
template<typename T> void handle_payment_changes(const T &res, std::true_type) {
if (res.status == CORE_RPC_STATUS_OK || res.status == CORE_RPC_STATUS_PAYMENT_REQUIRED)

@ -75,7 +75,7 @@ bool wallet2::daemon_requires_payment()
return get_rpc_payment_info(false, payment_required, credits, diff, credits_per_hash_found, blob, height, seed_height, seed_hash, next_seed_hash, cookie) && payment_required;
}
//----------------------------------------------------------------------------------------------------
bool wallet2::make_rpc_payment(uint64_t nonce, uint32_t cookie, uint64_t &credits, uint64_t &balance)
bool wallet2::make_rpc_payment(uint32_t nonce, uint32_t cookie, uint64_t &credits, uint64_t &balance)
{
cryptonote::COMMAND_RPC_ACCESS_SUBMIT_NONCE::request req = AUTO_VAL_INIT(req);
cryptonote::COMMAND_RPC_ACCESS_SUBMIT_NONCE::response res = AUTO_VAL_INIT(res);
@ -143,7 +143,7 @@ bool wallet2::search_for_rpc_payment(uint64_t credits_target, const std::functio
const uint32_t local_nonce = nonce++; // wrapping's OK
*(uint32_t*)(hashing_blob.data() + 39) = SWAP32LE(local_nonce);
const uint8_t major_version = hashing_blob[0];
if (major_version >= RX_BLOCK_VERSION && major_version < HF_VERSION_SHA3_POW)
if (major_version >= RX_BLOCK_VERSION)
{
const int miners = 1;
crypto::rx_slow_hash(height, seed_height, seed_hash.data, hashing_blob.data(), hashing_blob.size(), hash.data, miners, 0);

@ -43,7 +43,7 @@ set_property(TARGET hash-tests
PROPERTY
FOLDER "tests")
foreach (hash IN ITEMS sha3 fast slow slow-1 slow-2 tree extra-blake extra-groestl extra-jh extra-skein)
foreach (hash IN ITEMS fast slow slow-1 slow-2 tree extra-blake extra-groestl extra-jh extra-skein)
add_test(
NAME "hash-${hash}"
COMMAND hash-tests "${hash}" "${CMAKE_CURRENT_SOURCE_DIR}/tests-${hash}.txt")

@ -84,7 +84,6 @@ struct hash_func {
} hashes[] = {{"fast", cn_fast_hash}, {"slow", cn_slow_hash_0}, {"tree", hash_tree},
{"extra-blake", hash_extra_blake}, {"extra-groestl", hash_extra_groestl},
{"extra-jh", hash_extra_jh}, {"extra-skein", hash_extra_skein},
{"sha3", sha3},
{"slow-1", cn_slow_hash_1}, {"slow-2", cn_slow_hash_2}, {"slow-4", cn_slow_hash_4}};
int test_variant2_int_sqrt();

@ -1,3 +0,0 @@
f1cfdca558ac0c00464ca0f3e265ec6fb32c57caeb106fbfed9f174f6b814642 77
50bfb03895034e2fbbff0a24f030b907eddbad809b0937394b165f4ef02826cf 776f77
c71c200337782119556e704121335c305271375cf456a1e7e12ed335394cf7b5 776f776e65726f
Caricamento…
Annulla
Salva