No, here is an explanation of this part of code:
This code is from original bitcoin:
https://github.com/bitcoin/bitcoin/blob/master/src/rpc/mining.cpp.
while (max_tries > 0 && block.nNonce < std::numeric_limits<uint32_t>::max() && !CheckProofOfWork(block.GetHash(), block.nBits, chainman.GetConsensus()) && !chainman.m_interrupt) {
++block.nNonce;
--max_tries;
}
(what it does is iterate on once to find a nonce that satisfies the PoW, this takes exponential time obviously since it's brute forcing on nonce space)
This is the code in my fork (robocoin) that replaces the PoW:
uint256 seed = block.GetHash();
TensHashContext* ctx = tens_hash_init(seed.begin());
if (!ctx) {
return false;
}
while (max_tries > 0 && block.nNonce < std::numeric_limits<uint32_t>::max() &&
!CheckProofOfWork(block.GetPoWHashPrecomputed(ctx), block.nBits, chainman.GetConsensus()) &&
!chainman.m_interrupt) {
++block.nNonce;
--max_tries;
}
The only difference in that part of code is that it calls tens_hash_init before the loop, because this is needed to initialize the random ternary matrices used during the PoW. (would not be efficient to allocate and initialize them in the PoW loop).
This is also exponential same as in btc, bc also bruteforcing nonces in same way. Difference is that the forward pass is neural network inference (rounds of ternary matmults), instead of rounds of sha.
Cpu implementation of the hash used in pow loop is here:
https://github.com/nf-dj/robocoin/blob/main/src/crypto/tens_pow/tens_hash.cppAlso note that this part is just to make bitcoind able to mine (so can mine with bitcoin-cli etc), but this miner implementation is not efficient because only using cpu.
Also implemented some optimized miners using gpu and npu here:
https://github.com/nf-dj/robocoin/blob/main/test_pow/pow_coreml.pyhttps://github.com/nf-dj/robocoin/blob/main/test_pow/pow_pytorch.pyThese implementations use coreml and pytorch respectively to mine much faster (since bottleneck is neural net inference) and connect to node using rpc.
The coreml version is needed to make use of ANE (apple neural engine) on macs, since pytorch only supports gpu/metal.
Hope this helps to clarify why the code in GenerateBlock is exponential, just as it is in the btc case.