RandomX v2: don't update dataset when switching to/from it
What changed, and why it matters
This commit tweaks how the XMRig miner handles switching between two closely related RandomX algorithm variants (RX/0 and RX/V2). It avoids rebuilding the large RandomX dataset when the miner switches between these two variants, because they can share the same dataset. The change is a performance/correctness optimization for mining operations, not a fix for an externally exploitable security vulnerability.
No security action required. Treat as a normal functional/performance commit. If reviewing for correctness, verify that RX_0 and RX_V2 are genuinely dataset-compatible and that RxAlgo::apply() correctly updates internal algorithm state without leaving stale dataset references.
Security signals we found
Algorithm-variant equivalence logic introduced in seed comparison
Dataset readiness check reordered relative to algorithm switch
No input sanitization, bounds checking, or cryptographic changes present
Evidence from the diff
The patch modifies RandomX dataset lifecycle handling. In Miner.cpp, when a new job uses a RandomX-family algorithm, the miner now applies the algorithm via RxAlgo::apply() if it differs from the current one, instead of always checking Rx::isReady() first. In RxSeed.h, equality between seeds is relaxed so that Algorithm::RX_0 and Algorithm::RX_V2 are treated as equivalent for dataset seed comparison. This allows the same RandomX dataset to be reused when switching between RX/0 and RX/V2, avoiding a costly re-initialization. There is no evidence in the commit of memory corruption, input validation failure, or attacker-controlled behavior beyond normal mining job parameters.
Changed components
src/core/Miner.cppsrc/crypto/rx/RxSeed.hRandomX dataset/seed managementInspect captured patch +12 / −4
### src/core/Miner.cpp
@@ -59,6 +59,7 @@
# include "crypto/rx/Profiler.h"
# include "crypto/rx/Rx.h"
# include "crypto/rx/RxConfig.h"
+# include "crypto/rx/RxAlgo.h"
#endif
@@ -556,11 +557,12 @@ void xmrig::Miner::setJob(const Job &job, bool donate)
}
# ifdef XMRIG_ALGO_RANDOMX
- if (job.algorithm().family() == Algorithm::RANDOM_X && !Rx::isReady(job)) {
+ if (job.algorithm().family() == Algorithm::RANDOM_X) {
if (d_ptr->algorithm != job.algorithm()) {
stop();
+ RxAlgo::apply(job.algorithm());
}
- else {
+ else if (!Rx::isReady(job)) {
Nonce::pause(true);
Nonce::touch();
}
### src/crypto/rx/RxSeed.h
@@ -47,8 +47,8 @@ class RxSeed
inline RxSeed(const Algorithm &algorithm, const Buffer &seed) : m_algorithm(algorithm), m_data(seed) {}
inline RxSeed(const Job &job) : m_algorithm(job.algorithm()), m_data(job.seed()) {}
- inline bool isEqual(const Job &job) const { return m_algorithm == job.algorithm() && m_data == job.seed(); }
- inline bool isEqual(const RxSeed &other) const { return m_algorithm == other.m_algorithm && m_data == other.m_data; }
+ inline bool isEqual(const Job &job) const { return isEqualSeedAlgo(job.algorithm()) && m_data == job.seed(); }
+ inline bool isEqual(const RxSeed &other) const { return isEqualSeedAlgo(other.m_algorithm) && m_data == other.m_data; }
inline const Algorithm &algorithm() const { return m_algorithm; }
inline const Buffer &data() const { return m_data; }
@@ -60,6 +60,12 @@ class RxSeed
private:
Algorithm m_algorithm;
Buffer m_data;
+
+ inline bool isEqualSeedAlgo(Algorithm other) const {
+ return (m_algorithm == other) ||
+ ((m_algorithm == Algorithm::RX_0) && (other == Algorithm::RX_V2)) ||
+ ((m_algorithm == Algorithm::RX_V2) && (other == Algorithm::RX_0));
+ }
};
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.