挖矿代码求讲解或注释

如果没看错的话,是这段吧

static inline bool octopus_hash(octopus_return_value_t *ret,
                                    const octopus_light_t light, uint64_t full_size,
                                    const octopus_h256_t header_hash,
                                    const uint64_t nonce) {
      u64 thread_result;
      std::vector<u32> result;
      std::tie(thread_result, result) = multi_eval(header_hash, nonce);
      node s_mix[MIX_NODES + 1];
      memcpy(s_mix[0].bytes, &header_hash, 32);
      s_mix[0].double_words[4] = thread_result;
      SHA3_512(s_mix->bytes, s_mix->bytes, 40);
      node *const mix = s_mix + 1;
      for (u32 w = 0; w != MIX_WORDS; ++w) {
        mix->words[w] = s_mix[0].words[w % NODE_WORDS];
      }
      static const u32 page_size = sizeof(u32) * MIX_WORDS;
      static const u32 num_full_pages = full_size / page_size;
      for (u32 i = 0; i != OCTOPUS_ACCESSES; ++i) {
        u32 const index =
            fnv(s_mix->words[0] ^ i ^ result[i], mix->words[i % MIX_WORDS]) %
            num_full_pages;
        for (u32 n = 0; n != MIX_NODES; ++n) {
          node tmp_node;
          octopus_calculate_dag_item(&tmp_node, index * MIX_NODES + n, light);
          const node *dag_node = &tmp_node;
          for (u32 w = 0; w != NODE_WORDS; ++w) {
            mix[n].words[w] = fnv(mix[n].words[w], dag_node->words[w]);
          }
        }
      }
      for (u32 w = 0; w != MIX_WORDS; w += 4) {
        u32 reduction = mix->words[w];
        reduction = fnv(reduction, mix->words[w + 1]);
        reduction = fnv(reduction, mix->words[w + 2]);
        reduction = fnv(reduction, mix->words[w + 3]);
        mix->words[w / 4] = reduction;
      }
      for (u32 i = 0; i < 8; ++i) {
        mix->words[i] = fnv(mix->words[i], mix->words[8 + i]);
      }
      SHA3_256(&ret->result, s_mix->bytes, 64 + 32);

      return true;
    }
1 Like

在spec里有算法的具体说明。


里的附录F

看到了,太棒了,感谢帮定位