ifdefelse / ProgPOW

A Programmatic Proof-of-Work for Ethash. Forked from https://github.com/ethereum-mining/ethminer
GNU General Public License v3.0
257 stars 84 forks source link

Correctness of test vectors #55

Open mmrozek opened 3 years ago

mmrozek commented 3 years ago

I'm trying to implement ProgPow 0.9.4 in Scala from the spec described here, but I have a problem matching test vectors from the repo to my results.

The problem starts in obtaining hash_init so I will focus only on this code:

  case class Hash32 (uint32s: Array[Long])

  def keccak_f800_progpow(
    st:   Array[Long]
   ): Hash32 = {
    for(r <- 0 until 22){ ProgPow.keccak_f800_round(st, r) }
    Hash32(st.take(8))
  }

  def keccak_f800_initial_pass(
    header: Hash32,
    nonce:   Array[Long],
  ): Hash32 = {

    val st = Array.fill[Long](25)(0L)

    for(i <- 0 until 8) { st(i) = header.uint32s(i) }
    st(8) = nonce(0)
    st(9) = nonce(1)
    st(10) = keccakf_rndc(0)
    st(18) = keccakf_rndc(6)

    keccak_f800_progpow(st)
  }

  def hash(
    prog_seed:  Array[Long],
    nonce:      Array[Long],
    header:     Hash32
  ): PoW = {

    val hash_init = ProgPow.keccak_f800_initial_pass(header, nonce)

    // Further code is irrelevant as long as hash_init is wrong
  }

The code is pretty straightforward and I don't see where the mistake could occur. The previous version returns values as expected (passes all vectors from repo). ProgPow.keccak_f800_round passes test vector (I am not sure why this vector is removed from your repo) and nothing changed here from the previous version.

My results of calling hash function are:

block_number: 30000
header: ffeeddccbbaa9988776655443322110000112233445566778899aabbccddeeff
nonce: 0x123456789abcdef0

hash_init: 820cbdad61f9121f6d516f1758b5d73994ac00854ff1ddeef0b7701df5caa0fe
hash_mix:  ca62b7dfb3b5e713ad23f5c70fea05a888f76b13af7998af1db374d5f6f9f77f
hash_final: 21fbd7b6c3069edebb514eb0ab76178a3b9a1d8ed9066af4f70e063670dec958

block_number: 0
header: ffeeddccbbaa9988776655443322110000112233445566778899aabbccddeeff
nonce: 0x123456789abcdef0

hash_init: 820cbdad61f9121f6d516f1758b5d73994ac00854ff1ddeef0b7701df5caa0fe
hash_mix: 649bf3c6c69d7f1d86d114341f39cc27f69d4b8f39fa92e30fbafba48562cbab
hash_final: 2ae94b9ded0f6bac6cdb4348a6481c3ca07899aef390585a19a38a554ac25228

Could you please tell me if there is sth missing in my implementation (or maybe I misunderstood something)?