Added get_aux_slot

This commit is contained in:
SChernykh
2023-10-24 14:13:36 +02:00
parent da45871f0b
commit 417c89e96f
7 changed files with 55 additions and 6 deletions
+21
View File
@@ -19,6 +19,7 @@
#include "keccak.h"
#include "merkle.h"
#include "keccak.h"
#include "sha256.h"
namespace p2pool {
@@ -271,4 +272,24 @@ bool verify_merkle_proof(hash h, const std::vector<hash>& proof, size_t index, s
return (h == root);
}
uint32_t get_aux_slot(const hash &id, uint32_t nonce, uint32_t n_aux_chains)
{
if (n_aux_chains <= 1) {
return 0;
}
constexpr uint8_t HASH_KEY_MM_SLOT = 'm';
uint8_t buf[HASH_SIZE + sizeof(uint32_t) + 1];
memcpy(buf, &id, HASH_SIZE);
memcpy(buf + HASH_SIZE, &nonce, sizeof(uint32_t));
buf[HASH_SIZE + sizeof(uint32_t)] = HASH_KEY_MM_SLOT;
hash res;
sha256(buf, sizeof(buf), res.h);
return *reinterpret_cast<uint32_t*>(res.h) % n_aux_chains;
}
} // namespace p2pool
+3
View File
@@ -21,8 +21,11 @@ namespace p2pool {
void merkle_hash(const std::vector<hash>& hashes, hash& root);
void merkle_hash_full_tree(const std::vector<hash>& hashes, std::vector<std::vector<hash>>& tree);
bool get_merkle_proof(const std::vector<std::vector<hash>>& tree, const hash& h, std::vector<std::pair<bool, hash>>& proof);
bool verify_merkle_proof(hash h, const std::vector<std::pair<bool, hash>>& proof, const hash& root);
bool verify_merkle_proof(hash h, const std::vector<hash>& proof, size_t index, size_t count, const hash& root);
uint32_t get_aux_slot(const hash &id, uint32_t nonce, uint32_t n_aux_chains);
} // namespace p2pool