diff --git a/CMakeLists.txt b/CMakeLists.txt index 0171add35..37e235ca5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,7 +82,6 @@ set(HEADERS_CRYPTO src/crypto/cn/hash.h src/crypto/cn/skein_port.h src/crypto/cn/soft_aes.h - src/crypto/cn/umul128.h src/crypto/common/HugePagesInfo.h src/crypto/common/MemoryPool.h src/crypto/common/Nonce.h diff --git a/src/base/base.cmake b/src/base/base.cmake index e33d787d6..92c16c0d7 100644 --- a/src/base/base.cmake +++ b/src/base/base.cmake @@ -81,6 +81,7 @@ set(HEADERS_BASE src/base/tools/cryptonote/Signatures.h src/base/tools/cryptonote/WalletAddress.h src/base/tools/cryptonote/crypto-ops.h + src/base/tools/cryptonote/umul128.h ) set(SOURCES_BASE diff --git a/src/base/net/stratum/DaemonClient.cpp b/src/base/net/stratum/DaemonClient.cpp index c7be5807f..bb741b336 100644 --- a/src/base/net/stratum/DaemonClient.cpp +++ b/src/base/net/stratum/DaemonClient.cpp @@ -267,24 +267,6 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code) } m_blockhashingblob = Json::getString(params, "blockhashing_blob"); - if (m_apiVersion == API_DERO) { - const uint64_t offset = Json::getUint64(params, "reserved_offset"); - Cvt::toHex(m_blockhashingblob.data() + offset * 2, kBlobReserveSize * 2, Cvt::randomBytes(kBlobReserveSize).data(), kBlobReserveSize); - } - - if (pool_coin.isValid()) { - job.setAlgorithm(pool_coin.algorithm(m_blocktemplate.major_version)); - } - - if (!job.setBlob(m_blockhashingblob)) { - *code = 3; - return false; - } - - job.setSeedHash(Json::getString(params, "seed_hash")); - job.setHeight(Json::getUint64(params, kHeight)); - job.setDiff(Json::getUint64(params, "difficulty")); - job.setId(blocktemplate.data() + blocktemplate.size() - 32); if (m_blocktemplate.has_miner_signature) { if (m_pool.spendSecretKey().isEmpty()) { @@ -324,6 +306,29 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code) } uint8_t derivation[32]; + +# ifdef XMRIG_PROXY_PROJECT + // Generate unique keys for miner transaction + // TODO: make it unique for each connection + { + uint8_t* eph_public_key = m_blocktemplate.raw_blob.data() + m_blocktemplate.eph_public_key_index; + uint8_t* txkey_pub = m_blocktemplate.raw_blob.data() + m_blocktemplate.tx_pubkey_index; + uint8_t txkey_sec[32]; + + generate_keys(txkey_pub, txkey_sec); + generate_key_derivation(public_viewkey, txkey_sec, derivation); + derive_public_key(derivation, 0, public_spendkey, eph_public_key); + + Cvt::toHex(blocktemplate.data() + m_blocktemplate.eph_public_key_index * 2, 64, eph_public_key, 32); + Cvt::toHex(blocktemplate.data() + m_blocktemplate.tx_pubkey_index * 2, 64, txkey_pub, 32); + + m_blocktemplate.UpdateMinerTxHash(); + m_blocktemplate.GenerateHashingBlob(); + + Cvt::toHex(m_blockhashingblob.data() + m_blocktemplate.miner_tx_prefix_begin_index * 2, 64, m_blocktemplate.root_hash, 32); + } +# endif + if (!generate_key_derivation(m_blocktemplate.raw_blob.data() + m_blocktemplate.tx_pubkey_index, secret_viewkey, derivation)) { LOG_ERR("Failed to generate key derivation for miner signature."); *code = 9; @@ -356,6 +361,26 @@ bool xmrig::DaemonClient::parseJob(const rapidjson::Value ¶ms, int *code) job.setTimestamp(m_blocktemplate.timestamp); } + if (m_apiVersion == API_DERO) { + const uint64_t offset = Json::getUint64(params, "reserved_offset"); + Cvt::toHex(m_blockhashingblob.data() + offset * 2, kBlobReserveSize * 2, Cvt::randomBytes(kBlobReserveSize).data(), kBlobReserveSize); + } + + if (pool_coin.isValid()) { + job.setAlgorithm(pool_coin.algorithm(m_blocktemplate.major_version)); + } + + if (!job.setBlob(m_blockhashingblob)) { + *code = 3; + return false; + } + + job.setSeedHash(Json::getString(params, "seed_hash")); + job.setHeight(Json::getUint64(params, kHeight)); + job.setDiff(Json::getUint64(params, "difficulty")); + + job.setId(blocktemplate.data() + blocktemplate.size() - 32); + m_job = std::move(job); m_blocktemplateStr = std::move(blocktemplate); m_prevHash = Json::getString(params, "prev_hash"); diff --git a/src/base/tools/cryptonote/BlockTemplate.h b/src/base/tools/cryptonote/BlockTemplate.h index b2c401583..079cc021b 100644 --- a/src/base/tools/cryptonote/BlockTemplate.h +++ b/src/base/tools/cryptonote/BlockTemplate.h @@ -80,7 +80,6 @@ struct BlockTemplate bool Init(const String& blockTemplate, Coin coin); -private: void CalculateMinerTxHash(uint8_t* hash); void CalculateMerkleTreeHash(); void UpdateMinerTxHash(); diff --git a/src/base/tools/cryptonote/Signatures.cpp b/src/base/tools/cryptonote/Signatures.cpp index 44d10f8f7..d9a71b923 100644 --- a/src/base/tools/cryptonote/Signatures.cpp +++ b/src/base/tools/cryptonote/Signatures.cpp @@ -167,6 +167,30 @@ void derive_secret_key(const uint8_t* derivation, size_t output_index, const uin } +bool derive_public_key(const uint8_t* derivation, size_t output_index, const uint8_t* base, uint8_t* derived_key) +{ + ec_scalar scalar; + ge_p3 point1; + ge_p3 point2; + ge_cached point3; + ge_p1p1 point4; + ge_p2 point5; + + if (ge_frombytes_vartime(&point1, base) != 0) { + return false; + } + + derivation_to_scalar(derivation, output_index, scalar); + ge_scalarmult_base(&point2, (uint8_t*) &scalar); + ge_p3_to_cached(&point3, &point2); + ge_add(&point4, &point1, &point3); + ge_p1p1_to_p2(&point5, &point4); + ge_tobytes(derived_key, &point5); + + return true; +} + + void derive_view_secret_key(const uint8_t* spend_secret_key, uint8_t* view_secret_key) { keccak(spend_secret_key, 32, view_secret_key, 32); diff --git a/src/base/tools/cryptonote/Signatures.h b/src/base/tools/cryptonote/Signatures.h index 5fc966011..048133139 100644 --- a/src/base/tools/cryptonote/Signatures.h +++ b/src/base/tools/cryptonote/Signatures.h @@ -33,6 +33,7 @@ bool check_signature(const uint8_t* prefix_hash, const uint8_t* pub, const uint8 bool generate_key_derivation(const uint8_t* key1, const uint8_t* key2, uint8_t* derivation); void derive_secret_key(const uint8_t* derivation, size_t output_index, const uint8_t* base, uint8_t* derived_key); +bool derive_public_key(const uint8_t* derivation, size_t output_index, const uint8_t* base, uint8_t* derived_key); void derive_view_secret_key(const uint8_t* spend_secret_key, uint8_t* view_secret_key); diff --git a/src/base/tools/cryptonote/WalletAddress.cpp b/src/base/tools/cryptonote/WalletAddress.cpp index 0445626ee..394274daa 100644 --- a/src/base/tools/cryptonote/WalletAddress.cpp +++ b/src/base/tools/cryptonote/WalletAddress.cpp @@ -22,8 +22,8 @@ #include "base/crypto/keccak.h" #include "base/tools/cryptonote/BlobReader.h" #include "base/tools/cryptonote/WalletAddress.h" +#include "base/tools/cryptonote/umul128.h" #include "base/tools/Buffer.h" -#include "crypto/cn/umul128.h" #include diff --git a/src/crypto/cn/umul128.h b/src/base/tools/cryptonote/umul128.h similarity index 100% rename from src/crypto/cn/umul128.h rename to src/base/tools/cryptonote/umul128.h diff --git a/src/crypto/cn/CnHash.cpp b/src/crypto/cn/CnHash.cpp index e9232f0b4..6d826b596 100644 --- a/src/crypto/cn/CnHash.cpp +++ b/src/crypto/cn/CnHash.cpp @@ -31,7 +31,7 @@ #include "crypto/common/VirtualMemory.h" -#include "crypto/cn/umul128.h" +#include "base/tools/cryptonote/umul128.h" #if defined(XMRIG_ARM) # include "crypto/cn/CryptoNight_arm.h"