Browse Source

Merge pull request 'Revert SHA-3 on Master branch' (#302) from wowario/wownero:sha3 into master

Reviewed-on: #302
pull/304/head
jwinterm 2 months ago
parent
commit
bda76b6be9
21 changed files with 24 additions and 94 deletions
  1. +0
    -1
      src/crypto/CMakeLists.txt
  2. +0
    -1
      src/crypto/hash-ops.h
  3. +0
    -4
      src/crypto/hash.h
  4. +0
    -29
      src/crypto/sha3.c
  5. +2
    -14
      src/cryptonote_basic/cryptonote_basic.h
  6. +4
    -4
      src/cryptonote_basic/miner.cpp
  7. +1
    -1
      src/cryptonote_basic/miner.h
  8. +0
    -1
      src/cryptonote_config.h
  9. +1
    -1
      src/cryptonote_core/blockchain.cpp
  10. +1
    -5
      src/cryptonote_core/cryptonote_tx_utils.cpp
  11. +0
    -1
      src/hardforks/hardforks.cpp
  12. +4
    -5
      src/rpc/core_rpc_server.cpp
  13. +3
    -15
      src/rpc/core_rpc_server_commands_defs.h
  14. +1
    -1
      src/rpc/message_data_structs.h
  15. +2
    -2
      src/rpc/rpc_payment.cpp
  16. +1
    -1
      src/rpc/rpc_payment.h
  17. +1
    -1
      src/wallet/wallet2.h
  18. +2
    -2
      src/wallet/wallet_rpc_payments.cpp
  19. +1
    -1
      tests/hash/CMakeLists.txt
  20. +0
    -1
      tests/hash/main.cpp
  21. +0
    -3
      tests/hash/tests-sha3.txt

+ 0
- 1
src/crypto/CMakeLists.txt View File

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

+ 0
- 1
src/crypto/hash-ops.h View File

@ -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);

+ 0
- 4
src/crypto/hash.h View File

@ -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);
}

+ 0
- 29
src/crypto/sha3.c View File

@ -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();
}
}

+ 2
- 14
src/cryptonote_basic/cryptonote_basic.h View File

@ -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()
};

+ 4
- 4
src/cryptonote_basic/miner.cpp View File

@ -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;

+ 1
- 1
src/cryptonote_basic/miner.h View File

@ -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;

+ 0
- 1
src/cryptonote_config.h View File

@ -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

+ 1
- 1
src/cryptonote_core/blockchain.cpp View File

@ -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);

+ 1
- 5
src/cryptonote_core/cryptonote_tx_utils.cpp View File

@ -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;

+ 0
- 1
src/hardforks/hardforks.cpp View File

@ -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]);

+ 4
- 5
src/rpc/core_rpc_server.cpp View File

@ -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)

+ 3
- 15
src/rpc/core_rpc_server_commands_defs.h View File

@ -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()

+ 1
- 1
src/rpc/message_data_structs.h View File

@ -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;

+ 2
- 2
src/rpc/rpc_payment.cpp View File

@ -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;

+ 1
- 1
src/rpc/rpc_payment.h View File

@ -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);

+ 1
- 1
src/wallet/wallet2.h View File

@ -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)

+ 2
- 2
src/wallet/wallet_rpc_payments.cpp View File

@ -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);

+ 1
- 1
tests/hash/CMakeLists.txt View File

@ -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")

+ 0
- 1
tests/hash/main.cpp View File

@ -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();

+ 0
- 3
tests/hash/tests-sha3.txt View File

@ -1,3 +0,0 @@
f1cfdca558ac0c00464ca0f3e265ec6fb32c57caeb106fbfed9f174f6b814642 77
50bfb03895034e2fbbff0a24f030b907eddbad809b0937394b165f4ef02826cf 776f77
c71c200337782119556e704121335c305271375cf456a1e7e12ed335394cf7b5 776f776e65726f

Loading…
Cancel
Save