diff --git a/src/crypto/CMakeLists.txt b/src/crypto/CMakeLists.txt index 5055fc5bf..318e6dc57 100644 --- a/src/crypto/CMakeLists.txt +++ b/src/crypto/CMakeLists.txt @@ -42,7 +42,6 @@ set(crypto_sources hmac-keccak.c jh.c keccak.c - sha3.c oaes_lib.c random.c skein.c diff --git a/src/crypto/hash-ops.h b/src/crypto/hash-ops.h index d1ec7545a..0c0a81f6a 100644 --- a/src/crypto/hash-ops.h +++ b/src/crypto/hash-ops.h @@ -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); diff --git a/src/crypto/hash.h b/src/crypto/hash.h index d834062cf..f7dd0b78d 100644 --- a/src/crypto/hash.h +++ b/src/crypto/hash.h @@ -74,10 +74,6 @@ namespace crypto { cn_slow_hash(data, length, reinterpret_cast(&hash), variant, 0/*prehashed*/, height); } - inline void sha3(const void *data, std::size_t length, hash &hash) { - sha3(data, length, reinterpret_cast(&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(&hash), variant, 1/*prehashed*/, height); } diff --git a/src/crypto/sha3.c b/src/crypto/sha3.c deleted file mode 100644 index e5bb62ace..000000000 --- a/src/crypto/sha3.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include - -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(); - } -} diff --git a/src/cryptonote_basic/cryptonote_basic.h b/src/cryptonote_basic/cryptonote_basic.h index fe0909928..bc6a378f2 100644 --- a/src/cryptonote_basic/cryptonote_basic.h +++ b/src/cryptonote_basic/cryptonote_basic.h @@ -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::is_saving()) - nonce32 = (uint32_t)nonce; - FIELD_N("nonce", nonce32); - if (!typename Archive::is_saving()) - nonce = nonce32; - } + FIELD(nonce) END_SERIALIZE() }; diff --git a/src/cryptonote_basic/miner.cpp b/src/cryptonote_basic/miner.cpp index dc2d21370..34a559b83 100644 --- a/src/cryptonote_basic/miner.cpp +++ b/src/cryptonote_basic/miner.cpp @@ -144,7 +144,7 @@ namespace cryptonote m_height = height; m_block_reward = block_reward; ++m_template_no; - m_starter_nonce = crypto::rand(); + m_starter_nonce = crypto::rand(); 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(); + m_starter_nonce = crypto::rand(); 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::max(); bl.nonce++) + for(; bl.nonce != std::numeric_limits::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; diff --git a/src/cryptonote_basic/miner.h b/src/cryptonote_basic/miner.h index a2a013f5e..3cbc4e5a4 100644 --- a/src/cryptonote_basic/miner.h +++ b/src/cryptonote_basic/miner.h @@ -123,7 +123,7 @@ namespace cryptonote epee::critical_section m_template_lock; block m_template; std::atomic m_template_no; - std::atomic m_starter_nonce; + std::atomic m_starter_nonce; difficulty_type m_diffic; uint64_t m_height; volatile uint32_t m_thread_index; diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h index 909077370..86383ffa2 100644 --- a/src/cryptonote_config.h +++ b/src/cryptonote_config.h @@ -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 diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 0ca7dc457..023d4a3fc 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -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); diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp index 441f4b250..7b1b74830 100644 --- a/src/cryptonote_core/cryptonote_tx_utils.cpp +++ b/src/cryptonote_core/cryptonote_tx_utils.cpp @@ -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; diff --git a/src/hardforks/hardforks.cpp b/src/hardforks/hardforks.cpp index 6027b6829..ab2b10338 100644 --- a/src/hardforks/hardforks.cpp +++ b/src/hardforks/hardforks.cpp @@ -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]); diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 53e88a574..5fd99dbac 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -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) diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 4564aee12..cc7f8a334 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -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::serialize(nonce32, stg, hparent_section, "nonce"); - if (!is_store) - const_cast(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() diff --git a/src/rpc/message_data_structs.h b/src/rpc/message_data_structs.h index 9358fee97..085148d8a 100644 --- a/src/rpc/message_data_structs.h +++ b/src/rpc/message_data_structs.h @@ -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; diff --git a/src/rpc/rpc_payment.cpp b/src/rpc/rpc_payment.cpp index e0b78e092..edc8f0dda 100644 --- a/src/rpc/rpc_payment.cpp +++ b/src/rpc/rpc_payment.cpp @@ -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 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; diff --git a/src/rpc/rpc_payment.h b/src/rpc/rpc_payment.h index ab278f103..dcd43f8d5 100644 --- a/src/rpc/rpc_payment.h +++ b/src/rpc/rpc_payment.h @@ -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 &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 &f) const; unsigned int flush_by_age(time_t seconds = 0); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 7f2288516..712f91613 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -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 &startfunc, const std::function &contfunc, const std::function &foundfunc = NULL, const std::function &errorfunc = NULL); template void handle_payment_changes(const T &res, std::true_type) { if (res.status == CORE_RPC_STATUS_OK || res.status == CORE_RPC_STATUS_PAYMENT_REQUIRED) diff --git a/src/wallet/wallet_rpc_payments.cpp b/src/wallet/wallet_rpc_payments.cpp index e8aefa459..6527b1384 100644 --- a/src/wallet/wallet_rpc_payments.cpp +++ b/src/wallet/wallet_rpc_payments.cpp @@ -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); diff --git a/tests/hash/CMakeLists.txt b/tests/hash/CMakeLists.txt index 8929b3b61..d6b4b4c03 100644 --- a/tests/hash/CMakeLists.txt +++ b/tests/hash/CMakeLists.txt @@ -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") diff --git a/tests/hash/main.cpp b/tests/hash/main.cpp index 2a6463fb7..bf612684c 100644 --- a/tests/hash/main.cpp +++ b/tests/hash/main.cpp @@ -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(); diff --git a/tests/hash/tests-sha3.txt b/tests/hash/tests-sha3.txt deleted file mode 100644 index d13fbe70a..000000000 --- a/tests/hash/tests-sha3.txt +++ /dev/null @@ -1,3 +0,0 @@ -f1cfdca558ac0c00464ca0f3e265ec6fb32c57caeb106fbfed9f174f6b814642 77 -50bfb03895034e2fbbff0a24f030b907eddbad809b0937394b165f4ef02826cf 776f77 -c71c200337782119556e704121335c305271375cf456a1e7e12ed335394cf7b5 776f776e65726f