Post
Topic
Board Development & Technical Discussion
Merits 3 from 1 user
Re: PSA: Coders making ad hoc “random” schemes are like kids playing with matches.
by
Joe_Bauers
on 27/03/2021, 19:20:28 UTC
⭐ Merited by Quickseller (3)
@nullius, I wonder if you would provide your opinion on the following simple algo I devised to determine Nfactor (https://github.com/floodyberry/scrypt-jane) based on previous block hash.

I understand that:
1) This should probably look back to a further level of confirmed block.
2) A vanityaddress could be used to "game the system" by generating a specific char for last position along with the required PoW, though this would require an extra bit of work over non-bad actors.

Apart from that, I would expect a 25% chance overall for each of the 4 options.   

Code:
unsigned char CBlockHeader::GetNfactor() const
{

    std::string spb = hashPrevBlock.ToString();
    std::string lasthashchar = spb.substr(block_length,1);

    unsigned char Nfactor = 20;
      if((spb == "0000000000000000000000000000000000000000000000000000000000000000")){
                  Nfactor = 4;}  // Genesis, all chains.

      else if((lasthashchar == "0") || (lasthashchar == "1") || (lasthashchar == "2") || (lasthashchar == "3")){
      Nfactor = 18;}
      else if((lasthashchar == "4") || (lasthashchar == "5") || (lasthashchar == "6") || (lasthashchar == "7")){
      Nfactor = 19;}
      else if((lasthashchar == "8") || (lasthashchar == "9") || (lasthashchar == "a") || (lasthashchar == "b")){
      Nfactor = 20;}
      else if((lasthashchar == "c") || (lasthashchar == "d") || (lasthashchar == "e") || (lasthashchar == "f")){
      Nfactor = 21;}
      return Nfactor;
}