mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-12-22 11:29:23 +00:00
Added get_aux_slot
This commit is contained in:
parent
da45871f0b
commit
417c89e96f
7 changed files with 55 additions and 6 deletions
|
@ -149,6 +149,7 @@ endif()
|
||||||
|
|
||||||
include_directories(src)
|
include_directories(src)
|
||||||
include_directories(external/src)
|
include_directories(external/src)
|
||||||
|
include_directories(external/src/crypto)
|
||||||
include_directories(external/src/cryptonote)
|
include_directories(external/src/cryptonote)
|
||||||
include_directories(${UV_INCLUDE_DIR})
|
include_directories(${UV_INCLUDE_DIR})
|
||||||
include_directories(external/src/cppzmq)
|
include_directories(external/src/cppzmq)
|
||||||
|
|
8
external/src/crypto/sha256.h
vendored
8
external/src/crypto/sha256.h
vendored
|
@ -9,6 +9,10 @@
|
||||||
#ifndef SHA256_H
|
#ifndef SHA256_H
|
||||||
#define SHA256_H
|
#define SHA256_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
/*************************** HEADER FILES ***************************/
|
/*************************** HEADER FILES ***************************/
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
@ -30,4 +34,8 @@ void sha256_final(SHA256_CTX *ctx, uint8_t* hash);
|
||||||
|
|
||||||
void sha256(const void* data, uint32_t len, uint8_t* hash);
|
void sha256(const void* data, uint32_t len, uint8_t* hash);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif // SHA256_H
|
#endif // SHA256_H
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "keccak.h"
|
#include "keccak.h"
|
||||||
#include "merkle.h"
|
#include "merkle.h"
|
||||||
#include "keccak.h"
|
#include "keccak.h"
|
||||||
|
#include "sha256.h"
|
||||||
|
|
||||||
namespace p2pool {
|
namespace p2pool {
|
||||||
|
|
||||||
|
@ -271,4 +272,24 @@ bool verify_merkle_proof(hash h, const std::vector<hash>& proof, size_t index, s
|
||||||
return (h == root);
|
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
|
} // namespace p2pool
|
||||||
|
|
|
@ -21,8 +21,11 @@ namespace p2pool {
|
||||||
|
|
||||||
void merkle_hash(const std::vector<hash>& hashes, hash& root);
|
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);
|
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 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<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);
|
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
|
} // namespace p2pool
|
||||||
|
|
|
@ -272,7 +272,7 @@ for line in lines:
|
||||||
count += 1
|
count += 1
|
||||||
api = line[29:].strip()
|
api = line[29:].strip()
|
||||||
if api not in allowedAPIs:
|
if api not in allowedAPIs:
|
||||||
print('API call "{}" is not checked for Windows 7 compatibility. Check it and then add it to the list in tests/src/check_imports.py'.format(api))
|
print('API call "{}" is not checked for Windows 7 compatibility. Check it and then add it to the list in tests/src/check_win7.py'.format(api))
|
||||||
exit_code = 1
|
exit_code = 1
|
||||||
|
|
||||||
if exit_code == 0:
|
if exit_code == 0:
|
||||||
|
|
|
@ -224,4 +224,23 @@ TEST(merkle, tree)
|
||||||
check_full_tree();
|
check_full_tree();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(merkle, aux_slot)
|
||||||
|
{
|
||||||
|
hash id;
|
||||||
|
|
||||||
|
ASSERT_EQ(get_aux_slot(id, 0, 0), 0U);
|
||||||
|
ASSERT_EQ(get_aux_slot(id, 0, 1), 0U);
|
||||||
|
ASSERT_EQ(get_aux_slot(id, 0, 2), 0U);
|
||||||
|
ASSERT_EQ(get_aux_slot(id, 0, 3), 0U);
|
||||||
|
ASSERT_EQ(get_aux_slot(id, 0, 4), 0U);
|
||||||
|
ASSERT_EQ(get_aux_slot(id, 0, 5), 1U);
|
||||||
|
ASSERT_EQ(get_aux_slot(id, 0, 6), 0U);
|
||||||
|
ASSERT_EQ(get_aux_slot(id, 0, 7), 5U);
|
||||||
|
ASSERT_EQ(get_aux_slot(id, 0, 8), 0U);
|
||||||
|
ASSERT_EQ(get_aux_slot(id, 0, 9), 6U);
|
||||||
|
|
||||||
|
ASSERT_EQ(get_aux_slot(id, 0, std::numeric_limits<uint32_t>::max()), 2389612776U);
|
||||||
|
ASSERT_EQ(get_aux_slot(id, 1, std::numeric_limits<uint32_t>::max()), 1080669337U);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "gtest/gtest.h"
|
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "sha256.h"
|
#include "sha256.h"
|
||||||
}
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
namespace p2pool {
|
namespace p2pool {
|
||||||
|
|
||||||
|
@ -28,7 +25,7 @@ TEST(sha256, hashing)
|
||||||
{
|
{
|
||||||
auto check = [](const char* input, const char* output) {
|
auto check = [](const char* input, const char* output) {
|
||||||
hash h;
|
hash h;
|
||||||
sha256(input, strlen(input), h.h);
|
sha256(input, static_cast<uint32_t>(strlen(input)), h.h);
|
||||||
|
|
||||||
char buf[128];
|
char buf[128];
|
||||||
log::Stream s(buf);
|
log::Stream s(buf);
|
||||||
|
|
Loading…
Reference in a new issue