Rust XMR Miner

Posted: Tue | Jul 25, 2023

Mining A crab in the sand, representing Ferris, the Rust mascot

The popular XMR mining softwares

If you mine Monero, you’ve likely used xmrig or xmr-stak. Combined, they claim 11.7k stars on github.com at the time I’m writing this post.

I began mining Monero on my GPU with xmr-stak many years ago. Some years ago, I tried mining on my CPU with xmrig and have been doing so ever since.

Unfortunately, I get fairly regular segfaults when running xmrig on my GPU. I will try to fix the issue, but I became interested in finding out if there was any mining software written in Go or Rust.

Finding mithril

Though I have been unsuccessful at finding any mining software written in Go, there is a RandomX stratum miner written in Rust called mithril. Mithril has not been updated in over a year, but I decided not to prejudge its usability.

It doesn’t have as many features as xmrig, or xmr-stak, but I wanted to try something more stable, even if it was slower. There are a few things you have to know about the Rust toolchain, otherwise, you may have some difficulties compiling the program.

The Rust ecosystem and build issues

Rust is a fine language, but something you must understand is that backwards compatibility is not guaranteed within the standard library. If you pick up the latest rust compiler and attempt cargo check on the master branch, you will see the following output:

Checking mithril v0.20.0 (/home/alexander/Projects/mithril)
error[E0635]: unknown feature `integer_atomics`
 --> src/lib.rs:4:12
  |
4 | #![feature(integer_atomics)]
  |            ^^^^^^^^^^^^^^^

warning: use of deprecated method `mithril_config::config::Config::merge`: please use 'ConfigBuilder' instead
   --> src/mithril_config.rs:119:14
    |
119 |         conf.merge(File::with_name(filename))?;
    |              ^^^^^
    |
    = note: `#[warn(deprecated)]` on by default

For more information about this error, try `rustc --explain E0635`.
warning: `mithril` (lib) generated 1 warning
error: could not compile `mithril` (lib) due to previous error; 1 warning emitted

You may think that perhaps the latest commit on master is just broken, but that is not the case. The README install instructions state that you must use the nightly build of Rust to compile correctly. Let’s try that:

# install rust nightly if you don't have it
rustup default nightly

cargo check # gives the same exact error as above

The solution

We could be nice open-source developers and fix these issues, but if we want to just compile this program, there is another way. We know when the maintainer pushed the latest commit, and we know that it compiled on that date. The simple solution, then, is to get the nightly version of Rust from that date.

# get Rust nightly from that date
rustup toolchain install nightly-2022-06-17

# cargo build with that nightly rust version
# without changing the default rust version
cargo +nightly-2022-06-17 build --release

We are golden! After you get a successful build, the rest of the documentation will get you going. If you are interested in mining software written in languages other than C++, mithril is worth exploring. I personally find a big benefit in using the Rust and Go toolchains. The ergonomics of go build and cargo build --release would be a welcome addition to compiling mining software.

I am still hoping to find an implementation in Go I can work with, but I will likely have to start writing one from scratch. The idea is to sacrifice speed for more stability and a few fancy features that the Go standard library interfaces enable.

Previous: Personal XMRig Proxy
>> Home