diff --git a/src/miner.cpp b/src/miner.cpp index 3b0335a2b..8b5941dd9 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1134,36 +1134,45 @@ void static RandomXMiner() hashTarget = HASHTarget; char randomxHash[RANDOMX_HASH_SIZE]; - // Initial randomx key is chain magic + first letter of chain name which is 2^40 bits of entropy - char randomxKey[5]; + // Initial randomx key is chain magic || ac_name which is >= 2^40 bits of entropy assuming strlen(ac_name) >= 1 + // For ac_name=DRAGONX we have 4 + 7 = 11 bytes or 2^88 bits of entropy + char randomxKey[4 + strlen(SMART_CHAIN_SYMBOL)]; randomxKey[0] = ASSETCHAINS_MAGIC & 0xff; randomxKey[1] = (ASSETCHAINS_MAGIC >> 8) & 0xff; randomxKey[2] = (ASSETCHAINS_MAGIC >> 16) & 0xff; randomxKey[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff; - randomxKey[4] = SMART_CHAIN_SYMBOL[0]; + + for(int i=0; i++; i 1024 && (Mining_height % 1024 == 64)) { - // At block height 1024*N+64 we should use the blockhash of block 1024*N as key - // use blockchain data to set a new key+input for a group of blocks - // randomxKey = ... - // randomxInput = ... - } - if (randomxCache == NULL) { LogPrintf("RandomX cache is null, something is wrong, cannot mine!\n"); return; } + + // TODO: use same block key for groups of blocks + if(Mining_height > 1024 && (Mining_height % 1024 == 64)) { + // At block height 1024*N+64 we should use the blockhash of block 1024*N as randomx key + // use blockchain data to set a new key+input for a group of blocks + uint256 randomxBlockKey; + randomxBlockKey = chainActive[Mining_height - 64]->GetBlockHash(); + crypto_generichash_blake2b_state new_state; + crypto_generichash_blake2b_update(&state, (unsigned char*)&randomxBlockKey, 32); + crypto_generichash_blake2b_final(&state, randomxInput, 32); + } + + // TODO: use correct variables randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey); randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL);