mirror of
https://git.wownero.com/wownero/RandomWOW.git
synced 2024-12-22 15:58:53 +00:00
rename 'hash v2' to 'commitment'
This commit is contained in:
parent
db273f2671
commit
07a413b9f0
@ -401,14 +401,14 @@ extern "C" {
|
|||||||
machine->getFinalResult(output, RANDOMX_HASH_SIZE);
|
machine->getFinalResult(output, RANDOMX_HASH_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void randomx_calculate_hash_v2(const void* input, size_t inputSize, const void* v1_in, void* v2_out) {
|
void randomx_calculate_commitment(const void* input, size_t inputSize, const void* hash_in, void* com_out) {
|
||||||
assert(inputSize == 0 || input != nullptr);
|
assert(inputSize == 0 || input != nullptr);
|
||||||
assert(v1_in != nullptr);
|
assert(hash_in != nullptr);
|
||||||
assert(v2_out != nullptr);
|
assert(com_out != nullptr);
|
||||||
blake2b_state state;
|
blake2b_state state;
|
||||||
blake2b_init(&state, RANDOMX_HASH_SIZE);
|
blake2b_init(&state, RANDOMX_HASH_SIZE);
|
||||||
blake2b_update(&state, input, inputSize);
|
blake2b_update(&state, input, inputSize);
|
||||||
blake2b_update(&state, v1_in, RANDOMX_HASH_SIZE);
|
blake2b_update(&state, hash_in, RANDOMX_HASH_SIZE);
|
||||||
blake2b_final(&state, v2_out, RANDOMX_HASH_SIZE);
|
blake2b_final(&state, com_out, RANDOMX_HASH_SIZE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,15 +261,15 @@ RANDOMX_EXPORT void randomx_calculate_hash_next(randomx_vm* machine, const void*
|
|||||||
RANDOMX_EXPORT void randomx_calculate_hash_last(randomx_vm* machine, void* output);
|
RANDOMX_EXPORT void randomx_calculate_hash_last(randomx_vm* machine, void* output);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate V2 hash from the V1 hash and its input.
|
* Calculate a RandomX commitment from a RandomX hash and its input.
|
||||||
*
|
*
|
||||||
* @param input is a pointer to memory that was hashed by V1. Must not be NULL.
|
* @param input is a pointer to memory that was hashed. Must not be NULL.
|
||||||
* @param inputSize is the number of bytes in the input.
|
* @param inputSize is the number of bytes in the input.
|
||||||
* @param v1_in is the V1 hash (RANDOMX_HASH_SIZE bytes).
|
* @param hash_in is the output from randomx_calculate_hash* (RANDOMX_HASH_SIZE bytes).
|
||||||
* @param output is a pointer to memory where the V2 hash will be stored. Must not
|
* @param com_out is a pointer to memory where the commitment will be stored. Must not
|
||||||
* be NULL and at least RANDOMX_HASH_SIZE bytes must be available for writing.
|
* be NULL and at least RANDOMX_HASH_SIZE bytes must be available for writing.
|
||||||
*/
|
*/
|
||||||
RANDOMX_EXPORT void randomx_calculate_hash_v2(const void* input, size_t inputSize, const void* v1_in, void* v2_out);
|
RANDOMX_EXPORT void randomx_calculate_commitment(const void* input, size_t inputSize, const void* hash_in, void* com_out);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ void printUsage(const char* executable) {
|
|||||||
std::cout << " --avx2 use optimized Argon2 for AVX2 CPUs" << std::endl;
|
std::cout << " --avx2 use optimized Argon2 for AVX2 CPUs" << std::endl;
|
||||||
std::cout << " --auto select the best options for the current CPU" << std::endl;
|
std::cout << " --auto select the best options for the current CPU" << std::endl;
|
||||||
std::cout << " --noBatch calculate hashes one by one (default: batch)" << std::endl;
|
std::cout << " --noBatch calculate hashes one by one (default: batch)" << std::endl;
|
||||||
std::cout << " --v2 calculate v2 hashes (default: v1)" << std::endl;
|
std::cout << " --commit calculate commitments instead of hashes (default: hashes)" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MemoryException : public std::exception {
|
struct MemoryException : public std::exception {
|
||||||
@ -114,7 +114,7 @@ struct DatasetAllocException : public MemoryException {
|
|||||||
|
|
||||||
using MineFunc = void(randomx_vm * vm, std::atomic<uint32_t> & atomicNonce, AtomicHash & result, uint32_t noncesCount, int thread, int cpuid);
|
using MineFunc = void(randomx_vm * vm, std::atomic<uint32_t> & atomicNonce, AtomicHash & result, uint32_t noncesCount, int thread, int cpuid);
|
||||||
|
|
||||||
template<bool batch, bool v2>
|
template<bool batch, bool commit>
|
||||||
void mine(randomx_vm* vm, std::atomic<uint32_t>& atomicNonce, AtomicHash& result, uint32_t noncesCount, int thread, int cpuid = -1) {
|
void mine(randomx_vm* vm, std::atomic<uint32_t>& atomicNonce, AtomicHash& result, uint32_t noncesCount, int thread, int cpuid = -1) {
|
||||||
if (cpuid >= 0) {
|
if (cpuid >= 0) {
|
||||||
int rc = set_thread_affinity(cpuid);
|
int rc = set_thread_affinity(cpuid);
|
||||||
@ -139,8 +139,8 @@ void mine(randomx_vm* vm, std::atomic<uint32_t>& atomicNonce, AtomicHash& result
|
|||||||
}
|
}
|
||||||
store32(noncePtr, nonce);
|
store32(noncePtr, nonce);
|
||||||
(batch ? randomx_calculate_hash_next : randomx_calculate_hash)(vm, blockTemplate, sizeof(blockTemplate), &hash);
|
(batch ? randomx_calculate_hash_next : randomx_calculate_hash)(vm, blockTemplate, sizeof(blockTemplate), &hash);
|
||||||
if (v2) {
|
if (commit) {
|
||||||
randomx_calculate_hash_v2(blockTemplate, sizeof(blockTemplate), &hash, &hash);
|
randomx_calculate_commitment(blockTemplate, sizeof(blockTemplate), &hash, &hash);
|
||||||
}
|
}
|
||||||
result.xorWith(hash);
|
result.xorWith(hash);
|
||||||
if (!batch) {
|
if (!batch) {
|
||||||
@ -150,7 +150,7 @@ void mine(randomx_vm* vm, std::atomic<uint32_t>& atomicNonce, AtomicHash& result
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
bool softAes, miningMode, verificationMode, help, largePages, jit, secure, v2;
|
bool softAes, miningMode, verificationMode, help, largePages, jit, secure, commit;
|
||||||
bool ssse3, avx2, autoFlags, noBatch;
|
bool ssse3, avx2, autoFlags, noBatch;
|
||||||
int noncesCount, threadCount, initThreadCount;
|
int noncesCount, threadCount, initThreadCount;
|
||||||
uint64_t threadAffinity;
|
uint64_t threadAffinity;
|
||||||
@ -176,7 +176,7 @@ int main(int argc, char** argv) {
|
|||||||
readOption("--avx2", argc, argv, avx2);
|
readOption("--avx2", argc, argv, avx2);
|
||||||
readOption("--auto", argc, argv, autoFlags);
|
readOption("--auto", argc, argv, autoFlags);
|
||||||
readOption("--noBatch", argc, argv, noBatch);
|
readOption("--noBatch", argc, argv, noBatch);
|
||||||
readOption("--v2", argc, argv, v2);
|
readOption("--commit", argc, argv, commit);
|
||||||
|
|
||||||
store32(&seed, seedValue);
|
store32(&seed, seedValue);
|
||||||
|
|
||||||
@ -285,8 +285,8 @@ int main(int argc, char** argv) {
|
|||||||
MineFunc* func;
|
MineFunc* func;
|
||||||
|
|
||||||
if (noBatch) {
|
if (noBatch) {
|
||||||
if (v2) {
|
if (commit) {
|
||||||
std::cout << " - v2 hashes" << std::endl;
|
std::cout << " - hash commitments" << std::endl;
|
||||||
func = &mine<false, true>;
|
func = &mine<false, true>;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -294,9 +294,9 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (v2) {
|
if (commit) {
|
||||||
//TODO: support batch mode with v2
|
//TODO: support batch mode with commitments
|
||||||
std::cout << " - v2 hashes" << std::endl;
|
std::cout << " - hash commitments" << std::endl;
|
||||||
func = &mine<false, true>;
|
func = &mine<false, true>;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -394,7 +394,7 @@ int main(int argc, char** argv) {
|
|||||||
randomx_release_cache(cache);
|
randomx_release_cache(cache);
|
||||||
std::cout << "Calculated result: ";
|
std::cout << "Calculated result: ";
|
||||||
result.print(std::cout);
|
result.print(std::cout);
|
||||||
if (noncesCount == 1000 && seedValue == 0 && !v2)
|
if (noncesCount == 1000 && seedValue == 0 && !commit)
|
||||||
std::cout << "Reference result: 10b649a3f15c7c7f88277812f2e74b337a0f20ce909af09199cccb960771cfa1" << std::endl;
|
std::cout << "Reference result: 10b649a3f15c7c7f88277812f2e74b337a0f20ce909af09199cccb960771cfa1" << std::endl;
|
||||||
if (!miningMode) {
|
if (!miningMode) {
|
||||||
std::cout << "Performance: " << 1000 * elapsed / noncesCount << " ms per hash" << std::endl;
|
std::cout << "Performance: " << 1000 * elapsed / noncesCount << " ms per hash" << std::endl;
|
||||||
|
@ -35,11 +35,11 @@ void calcStringHash(const char(&key)[K], const char(&input)[H], void* output) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<size_t K, size_t H>
|
template<size_t K, size_t H>
|
||||||
void calcStringHashV2(const char(&key)[K], const char(&input)[H], void* output) {
|
void calcStringCommitment(const char(&key)[K], const char(&input)[H], void* output) {
|
||||||
initCache(key);
|
initCache(key);
|
||||||
assert(vm != nullptr);
|
assert(vm != nullptr);
|
||||||
randomx_calculate_hash(vm, input, H - 1, output);
|
randomx_calculate_hash(vm, input, H - 1, output);
|
||||||
randomx_calculate_hash_v2(input, H - 1, output, output);
|
randomx_calculate_commitment(input, H - 1, output, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<size_t K, size_t H>
|
template<size_t K, size_t H>
|
||||||
@ -1100,9 +1100,9 @@ int main() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
runTest("RandomX v2 hash test", stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), []() {
|
runTest("Commitment test", stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), []() {
|
||||||
char hash[RANDOMX_HASH_SIZE];
|
char hash[RANDOMX_HASH_SIZE];
|
||||||
calcStringHashV2("test key 000", "This is a test", &hash);
|
calcStringCommitment("test key 000", "This is a test", &hash);
|
||||||
assert(equalsHex(hash, "d53ccf348b75291b7be76f0a7ac8208bbced734b912f6fca60539ab6f86be919"));
|
assert(equalsHex(hash, "d53ccf348b75291b7be76f0a7ac8208bbced734b912f6fca60539ab6f86be919"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user