1

Don't ask why but I'm trying to make an XMR miner in c# (I know this will be slower etc etc).

I'm having some issues with a test case.

I'm looking at reproducing the results from this block https://xmrchain.net/block/2663337

I'm using this library https://github.com/planetarium/RandomXSharp for the random x implementation which looks like a straight port from the c++ one.

The following code isn't hashing as expected:

uint nonce = 8069672;
var diff = "307043909480";
var powHash = "491be569e5a57f36829bc13c59b8d61cb3cc10c70fd8ee9e82ba000000000000";
var blockHash = "d6b7079eb997a9702a46d85c5c552706a32b248172a43c8bb06bde664810981d";

Flags flags = Flags.Default; byte[] hash; using (var cache = new Cache(flags, BitConverter.GetBytes(nonce))) using (var vm = new VirtualMachine(flags, cache, null)) { hash = vm.CaculateHash(Encoding.ASCII.GetBytes(blockHash));

// OUTPUTS 8148CB28C07031C34C5A78A5A3A86E19A74B1C960B6FBC12E65E1967C1F9B951
// EXPECTED 491be569e5a57f36829bc13c59b8d61cb3cc10c70fd8ee9e82ba000000000000 ??

}

Very simple question is am I inputting the variables to the virtual machine correctly or is there an issue with the implementation in the RandomXSharp Lib.

Spaceman
  • 111
  • 3

1 Answers1

2

using (var cache = new Cache(flags, BitConverter.GetBytes(nonce)))

You're not initializing the cache with the correct key (the seed hash).

hash = vm.CaculateHash(Encoding.ASCII.GetBytes(blockHash));

You're not hashing a block hashing blob (you're just hashing the block hash and that's not how you get a POW hash). See this answer.

jtgrassie
  • 19,111
  • 4
  • 14
  • 51