From 6ace8b0028640872e6b6d4de88f711955c2d5c7f Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 22 Jan 2022 22:18:00 -0500 Subject: [PATCH 001/255] Start to add RandomX support --- src/hush_globals.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hush_globals.h b/src/hush_globals.h index 7e0a4c17f..e663d3be9 100644 --- a/src/hush_globals.h +++ b/src/hush_globals.h @@ -80,9 +80,9 @@ uint8_t ASSETCHAINS_CCDISABLES[256]; std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; #define _ASSETCHAINS_EQUIHASH 0 -uint32_t ASSETCHAINS_NUMALGOS = 3; +uint32_t ASSETCHAINS_NUMALGOS = 4; uint32_t ASSETCHAINS_EQUIHASH = _ASSETCHAINS_EQUIHASH; -const char *ASSETCHAINS_ALGORITHMS[] = {"equihash"}; +const char *ASSETCHAINS_ALGORITHMS[] = {"equihash", "randomx"}; uint64_t ASSETCHAINS_NONCEMASK[] = {0xffff}; uint32_t ASSETCHAINS_NONCESHIFT[] = {32}; uint32_t ASSETCHAINS_HASHESPERROUND[] = {1}; From 26d78bedb55077d3e59d9a1b876639e96687a3bf Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 22 Jan 2022 22:31:46 -0500 Subject: [PATCH 002/255] Use a completely different function for RandomX mining to minimize potential of equihash consensus bugs --- src/hush_globals.h | 7 ++++++- src/miner.cpp | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/hush_globals.h b/src/hush_globals.h index e663d3be9..9dc68449f 100644 --- a/src/hush_globals.h +++ b/src/hush_globals.h @@ -79,9 +79,14 @@ uint64_t ASSETCHAINS_ENDSUBSIDY[ASSETCHAINS_MAX_ERAS+1],ASSETCHAINS_REWARD[ASSET uint8_t ASSETCHAINS_CCDISABLES[256]; std::vector ASSETCHAINS_PRICES,ASSETCHAINS_STOCKS; + +// this is the offset in the ASSETCHAINS_ALGORITHMS array #define _ASSETCHAINS_EQUIHASH 0 -uint32_t ASSETCHAINS_NUMALGOS = 4; +#define _ASSETCHAINS_RANDOMX 1 + +uint32_t ASSETCHAINS_NUMALGOS = 4; // there are different variants of equihash with different (N,K) uint32_t ASSETCHAINS_EQUIHASH = _ASSETCHAINS_EQUIHASH; +uint32_t ASSETCHAINS_RANDOMX = _ASSETCHAINS_RANDOMX; const char *ASSETCHAINS_ALGORITHMS[] = {"equihash", "randomx"}; uint64_t ASSETCHAINS_NONCEMASK[] = {0xffff}; uint32_t ASSETCHAINS_NONCESHIFT[] = {32}; diff --git a/src/miner.cpp b/src/miner.cpp index 02d52abcd..79f791159 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1528,11 +1528,17 @@ void static BitcoinMiner() for (int i = 0; i < nThreads; i++) { #ifdef ENABLE_WALLET - if ( ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) + if ( ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) { minerThreads->create_thread(boost::bind(&BitcoinMiner, pwallet)); + } else if (ASSETCHAINS_ALGO == ASSETCHAINS_RANDOMX ) { + minerThreads->create_thread(boost::bind(&RandomXMiner, pwallet)); + } #else - if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) + if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) { minerThreads->create_thread(&BitcoinMiner); + } else if (ASSETCHAINS_ALGO == ASSETCHAINS_RANDOMX) { + minerThreads->create_thread(&RandomXMiner); + } #endif } } From 36140a5457067cfb1cf2ae20085d6a15c30d0654 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 22 Jan 2022 23:57:27 -0500 Subject: [PATCH 003/255] Import RandomX from https://github.com/tevador/RandomX/commit/df6e15e1303034831dc14128d654c157ddc0dce3 without audits/ directory --- src/RandomX/.gitattributes | 3 + src/RandomX/.gitignore | 9 + src/RandomX/CMakeLists.txt | 236 ++++ src/RandomX/LICENSE | 27 + src/RandomX/README.md | 158 +++ src/RandomX/doc/configuration.md | 287 +++++ src/RandomX/doc/design.md | 650 ++++++++++ src/RandomX/doc/program.asm | 985 +++++++++++++++ src/RandomX/doc/specs.md | 943 ++++++++++++++ src/RandomX/doc/tevador.asc | 13 + src/RandomX/randomx.sln | 177 +++ src/RandomX/src/aes_hash.cpp | 322 +++++ src/RandomX/src/aes_hash.hpp | 43 + src/RandomX/src/allocator.cpp | 60 + src/RandomX/src/allocator.hpp | 46 + src/RandomX/src/argon2.h | 261 ++++ src/RandomX/src/argon2_avx2.c | 174 +++ src/RandomX/src/argon2_core.c | 411 +++++++ src/RandomX/src/argon2_core.h | 163 +++ src/RandomX/src/argon2_ref.c | 187 +++ src/RandomX/src/argon2_ssse3.c | 182 +++ src/RandomX/src/asm/configuration.asm | 48 + .../src/asm/program_epilogue_linux.inc | 10 + .../src/asm/program_epilogue_store.inc | 19 + .../src/asm/program_epilogue_win64.inc | 24 + src/RandomX/src/asm/program_loop_load.inc | 28 + src/RandomX/src/asm/program_loop_store.inc | 18 + .../src/asm/program_prologue_linux.inc | 35 + .../src/asm/program_prologue_win64.inc | 48 + src/RandomX/src/asm/program_read_dataset.inc | 16 + .../asm/program_read_dataset_sshash_fin.inc | 10 + .../asm/program_read_dataset_sshash_init.inc | 17 + .../src/asm/program_sshash_constants.inc | 24 + src/RandomX/src/asm/program_sshash_load.inc | 8 + .../src/asm/program_sshash_prefetch.inc | 4 + src/RandomX/src/asm/program_xmm_constants.inc | 6 + src/RandomX/src/asm/randomx_reciprocal.inc | 7 + src/RandomX/src/assembly_generator_x86.cpp | 611 +++++++++ src/RandomX/src/assembly_generator_x86.hpp | 94 ++ src/RandomX/src/blake2/blake2-impl.h | 76 ++ src/RandomX/src/blake2/blake2.h | 116 ++ src/RandomX/src/blake2/blake2b.c | 409 ++++++ src/RandomX/src/blake2/blamka-round-avx2.h | 189 +++ src/RandomX/src/blake2/blamka-round-ref.h | 73 ++ src/RandomX/src/blake2/blamka-round-ssse3.h | 162 +++ src/RandomX/src/blake2/endian.h | 107 ++ src/RandomX/src/blake2_generator.cpp | 62 + src/RandomX/src/blake2_generator.hpp | 46 + src/RandomX/src/bytecode_machine.cpp | 482 ++++++++ src/RandomX/src/bytecode_machine.hpp | 322 +++++ src/RandomX/src/common.hpp | 187 +++ src/RandomX/src/configuration.h | 125 ++ src/RandomX/src/cpu.cpp | 76 ++ src/RandomX/src/cpu.hpp | 49 + src/RandomX/src/dataset.cpp | 196 +++ src/RandomX/src/dataset.hpp | 103 ++ src/RandomX/src/instruction.cpp | 390 ++++++ src/RandomX/src/instruction.hpp | 149 +++ src/RandomX/src/instruction_weights.hpp | 73 ++ src/RandomX/src/instructions_portable.cpp | 208 ++++ src/RandomX/src/intrin_portable.h | 751 +++++++++++ src/RandomX/src/jit_compiler.hpp | 41 + src/RandomX/src/jit_compiler_a64.cpp | 1072 ++++++++++++++++ src/RandomX/src/jit_compiler_a64.hpp | 128 ++ src/RandomX/src/jit_compiler_a64_static.S | 591 +++++++++ src/RandomX/src/jit_compiler_a64_static.hpp | 51 + src/RandomX/src/jit_compiler_fallback.hpp | 76 ++ src/RandomX/src/jit_compiler_x86.cpp | 845 +++++++++++++ src/RandomX/src/jit_compiler_x86.hpp | 142 +++ src/RandomX/src/jit_compiler_x86_static.S | 230 ++++ src/RandomX/src/jit_compiler_x86_static.asm | 223 ++++ src/RandomX/src/jit_compiler_x86_static.hpp | 50 + src/RandomX/src/program.hpp | 71 ++ src/RandomX/src/randomx.cpp | 397 ++++++ src/RandomX/src/randomx.h | 267 ++++ src/RandomX/src/reciprocal.c | 80 ++ src/RandomX/src/reciprocal.h | 48 + src/RandomX/src/soft_aes.cpp | 364 ++++++ src/RandomX/src/soft_aes.h | 46 + src/RandomX/src/superscalar.cpp | 903 ++++++++++++++ src/RandomX/src/superscalar.hpp | 60 + src/RandomX/src/superscalar_program.hpp | 84 ++ src/RandomX/src/tests/affinity.cpp | 117 ++ src/RandomX/src/tests/affinity.hpp | 39 + src/RandomX/src/tests/api-example1.c | 25 + src/RandomX/src/tests/api-example2.cpp | 51 + src/RandomX/src/tests/benchmark.cpp | 407 ++++++ src/RandomX/src/tests/code-generator.cpp | 124 ++ src/RandomX/src/tests/jit-performance.cpp | 44 + src/RandomX/src/tests/perf-simulation.cpp | 662 ++++++++++ src/RandomX/src/tests/rng-tests.cpp | 93 ++ src/RandomX/src/tests/runtime-distr.cpp | 172 +++ src/RandomX/src/tests/scratchpad-entropy.cpp | 50 + src/RandomX/src/tests/stopwatch.hpp | 84 ++ .../src/tests/superscalar-avalanche.cpp | 48 + src/RandomX/src/tests/superscalar-init.cpp | 55 + src/RandomX/src/tests/superscalar-stats.cpp | 52 + src/RandomX/src/tests/tests.cpp | 1096 +++++++++++++++++ src/RandomX/src/tests/utility.hpp | 124 ++ src/RandomX/src/virtual_machine.cpp | 143 +++ src/RandomX/src/virtual_machine.hpp | 91 ++ src/RandomX/src/virtual_memory.cpp | 203 +++ src/RandomX/src/virtual_memory.hpp | 42 + src/RandomX/src/vm_compiled.cpp | 80 ++ src/RandomX/src/vm_compiled.hpp | 77 ++ src/RandomX/src/vm_compiled_light.cpp | 70 ++ src/RandomX/src/vm_compiled_light.hpp | 68 + src/RandomX/src/vm_interpreted.cpp | 131 ++ src/RandomX/src/vm_interpreted.hpp | 75 ++ src/RandomX/src/vm_interpreted_light.cpp | 55 + src/RandomX/src/vm_interpreted_light.hpp | 61 + src/RandomX/vcxproj/api-example1.vcxproj | 131 ++ .../vcxproj/api-example1.vcxproj.filters | 27 + src/RandomX/vcxproj/api-example2.vcxproj | 128 ++ .../vcxproj/api-example2.vcxproj.filters | 22 + src/RandomX/vcxproj/benchmark.vcxproj | 132 ++ src/RandomX/vcxproj/benchmark.vcxproj.filters | 30 + src/RandomX/vcxproj/code-generator.vcxproj | 129 ++ .../vcxproj/code-generator.vcxproj.filters | 22 + src/RandomX/vcxproj/h2inc.ps1 | 90 ++ src/RandomX/vcxproj/jit-performance.vcxproj | 128 ++ .../vcxproj/jit-performance.vcxproj.filters | 22 + src/RandomX/vcxproj/perf-simulation.vcxproj | 128 ++ .../vcxproj/perf-simulation.vcxproj.filters | 22 + src/RandomX/vcxproj/randomx-dll.vcxproj | 217 ++++ .../vcxproj/randomx-dll.vcxproj.filters | 185 +++ src/RandomX/vcxproj/randomx.vcxproj | 207 ++++ src/RandomX/vcxproj/randomx.vcxproj.filters | 212 ++++ src/RandomX/vcxproj/runtime-distr.vcxproj | 128 ++ .../vcxproj/runtime-distr.vcxproj.filters | 22 + .../vcxproj/scratchpad-entropy.vcxproj | 128 ++ .../scratchpad-entropy.vcxproj.filters | 22 + .../vcxproj/superscalar-avalanche.vcxproj | 130 ++ .../superscalar-avalanche.vcxproj.filters | 22 + src/RandomX/vcxproj/superscalar-init.vcxproj | 130 ++ .../vcxproj/superscalar-init.vcxproj.filters | 22 + src/RandomX/vcxproj/superscalar-stats.vcxproj | 128 ++ .../vcxproj/superscalar-stats.vcxproj.filters | 22 + src/RandomX/vcxproj/tests.vcxproj | 133 ++ src/RandomX/vcxproj/tests.vcxproj.filters | 27 + 140 files changed, 23569 insertions(+) create mode 100644 src/RandomX/.gitattributes create mode 100644 src/RandomX/.gitignore create mode 100644 src/RandomX/CMakeLists.txt create mode 100644 src/RandomX/LICENSE create mode 100644 src/RandomX/README.md create mode 100644 src/RandomX/doc/configuration.md create mode 100644 src/RandomX/doc/design.md create mode 100644 src/RandomX/doc/program.asm create mode 100644 src/RandomX/doc/specs.md create mode 100644 src/RandomX/doc/tevador.asc create mode 100644 src/RandomX/randomx.sln create mode 100644 src/RandomX/src/aes_hash.cpp create mode 100644 src/RandomX/src/aes_hash.hpp create mode 100644 src/RandomX/src/allocator.cpp create mode 100644 src/RandomX/src/allocator.hpp create mode 100644 src/RandomX/src/argon2.h create mode 100644 src/RandomX/src/argon2_avx2.c create mode 100644 src/RandomX/src/argon2_core.c create mode 100644 src/RandomX/src/argon2_core.h create mode 100644 src/RandomX/src/argon2_ref.c create mode 100644 src/RandomX/src/argon2_ssse3.c create mode 100644 src/RandomX/src/asm/configuration.asm create mode 100644 src/RandomX/src/asm/program_epilogue_linux.inc create mode 100644 src/RandomX/src/asm/program_epilogue_store.inc create mode 100644 src/RandomX/src/asm/program_epilogue_win64.inc create mode 100644 src/RandomX/src/asm/program_loop_load.inc create mode 100644 src/RandomX/src/asm/program_loop_store.inc create mode 100644 src/RandomX/src/asm/program_prologue_linux.inc create mode 100644 src/RandomX/src/asm/program_prologue_win64.inc create mode 100644 src/RandomX/src/asm/program_read_dataset.inc create mode 100644 src/RandomX/src/asm/program_read_dataset_sshash_fin.inc create mode 100644 src/RandomX/src/asm/program_read_dataset_sshash_init.inc create mode 100644 src/RandomX/src/asm/program_sshash_constants.inc create mode 100644 src/RandomX/src/asm/program_sshash_load.inc create mode 100644 src/RandomX/src/asm/program_sshash_prefetch.inc create mode 100644 src/RandomX/src/asm/program_xmm_constants.inc create mode 100644 src/RandomX/src/asm/randomx_reciprocal.inc create mode 100644 src/RandomX/src/assembly_generator_x86.cpp create mode 100644 src/RandomX/src/assembly_generator_x86.hpp create mode 100644 src/RandomX/src/blake2/blake2-impl.h create mode 100644 src/RandomX/src/blake2/blake2.h create mode 100644 src/RandomX/src/blake2/blake2b.c create mode 100644 src/RandomX/src/blake2/blamka-round-avx2.h create mode 100644 src/RandomX/src/blake2/blamka-round-ref.h create mode 100644 src/RandomX/src/blake2/blamka-round-ssse3.h create mode 100644 src/RandomX/src/blake2/endian.h create mode 100644 src/RandomX/src/blake2_generator.cpp create mode 100644 src/RandomX/src/blake2_generator.hpp create mode 100644 src/RandomX/src/bytecode_machine.cpp create mode 100644 src/RandomX/src/bytecode_machine.hpp create mode 100644 src/RandomX/src/common.hpp create mode 100644 src/RandomX/src/configuration.h create mode 100644 src/RandomX/src/cpu.cpp create mode 100644 src/RandomX/src/cpu.hpp create mode 100644 src/RandomX/src/dataset.cpp create mode 100644 src/RandomX/src/dataset.hpp create mode 100644 src/RandomX/src/instruction.cpp create mode 100644 src/RandomX/src/instruction.hpp create mode 100644 src/RandomX/src/instruction_weights.hpp create mode 100644 src/RandomX/src/instructions_portable.cpp create mode 100644 src/RandomX/src/intrin_portable.h create mode 100644 src/RandomX/src/jit_compiler.hpp create mode 100644 src/RandomX/src/jit_compiler_a64.cpp create mode 100644 src/RandomX/src/jit_compiler_a64.hpp create mode 100644 src/RandomX/src/jit_compiler_a64_static.S create mode 100644 src/RandomX/src/jit_compiler_a64_static.hpp create mode 100644 src/RandomX/src/jit_compiler_fallback.hpp create mode 100644 src/RandomX/src/jit_compiler_x86.cpp create mode 100644 src/RandomX/src/jit_compiler_x86.hpp create mode 100644 src/RandomX/src/jit_compiler_x86_static.S create mode 100644 src/RandomX/src/jit_compiler_x86_static.asm create mode 100644 src/RandomX/src/jit_compiler_x86_static.hpp create mode 100644 src/RandomX/src/program.hpp create mode 100644 src/RandomX/src/randomx.cpp create mode 100644 src/RandomX/src/randomx.h create mode 100644 src/RandomX/src/reciprocal.c create mode 100644 src/RandomX/src/reciprocal.h create mode 100644 src/RandomX/src/soft_aes.cpp create mode 100644 src/RandomX/src/soft_aes.h create mode 100644 src/RandomX/src/superscalar.cpp create mode 100644 src/RandomX/src/superscalar.hpp create mode 100644 src/RandomX/src/superscalar_program.hpp create mode 100644 src/RandomX/src/tests/affinity.cpp create mode 100644 src/RandomX/src/tests/affinity.hpp create mode 100644 src/RandomX/src/tests/api-example1.c create mode 100644 src/RandomX/src/tests/api-example2.cpp create mode 100644 src/RandomX/src/tests/benchmark.cpp create mode 100644 src/RandomX/src/tests/code-generator.cpp create mode 100644 src/RandomX/src/tests/jit-performance.cpp create mode 100644 src/RandomX/src/tests/perf-simulation.cpp create mode 100644 src/RandomX/src/tests/rng-tests.cpp create mode 100644 src/RandomX/src/tests/runtime-distr.cpp create mode 100644 src/RandomX/src/tests/scratchpad-entropy.cpp create mode 100644 src/RandomX/src/tests/stopwatch.hpp create mode 100644 src/RandomX/src/tests/superscalar-avalanche.cpp create mode 100644 src/RandomX/src/tests/superscalar-init.cpp create mode 100644 src/RandomX/src/tests/superscalar-stats.cpp create mode 100644 src/RandomX/src/tests/tests.cpp create mode 100644 src/RandomX/src/tests/utility.hpp create mode 100644 src/RandomX/src/virtual_machine.cpp create mode 100644 src/RandomX/src/virtual_machine.hpp create mode 100644 src/RandomX/src/virtual_memory.cpp create mode 100644 src/RandomX/src/virtual_memory.hpp create mode 100644 src/RandomX/src/vm_compiled.cpp create mode 100644 src/RandomX/src/vm_compiled.hpp create mode 100644 src/RandomX/src/vm_compiled_light.cpp create mode 100644 src/RandomX/src/vm_compiled_light.hpp create mode 100644 src/RandomX/src/vm_interpreted.cpp create mode 100644 src/RandomX/src/vm_interpreted.hpp create mode 100644 src/RandomX/src/vm_interpreted_light.cpp create mode 100644 src/RandomX/src/vm_interpreted_light.hpp create mode 100644 src/RandomX/vcxproj/api-example1.vcxproj create mode 100644 src/RandomX/vcxproj/api-example1.vcxproj.filters create mode 100644 src/RandomX/vcxproj/api-example2.vcxproj create mode 100644 src/RandomX/vcxproj/api-example2.vcxproj.filters create mode 100644 src/RandomX/vcxproj/benchmark.vcxproj create mode 100644 src/RandomX/vcxproj/benchmark.vcxproj.filters create mode 100644 src/RandomX/vcxproj/code-generator.vcxproj create mode 100644 src/RandomX/vcxproj/code-generator.vcxproj.filters create mode 100644 src/RandomX/vcxproj/h2inc.ps1 create mode 100644 src/RandomX/vcxproj/jit-performance.vcxproj create mode 100644 src/RandomX/vcxproj/jit-performance.vcxproj.filters create mode 100644 src/RandomX/vcxproj/perf-simulation.vcxproj create mode 100644 src/RandomX/vcxproj/perf-simulation.vcxproj.filters create mode 100644 src/RandomX/vcxproj/randomx-dll.vcxproj create mode 100644 src/RandomX/vcxproj/randomx-dll.vcxproj.filters create mode 100644 src/RandomX/vcxproj/randomx.vcxproj create mode 100644 src/RandomX/vcxproj/randomx.vcxproj.filters create mode 100644 src/RandomX/vcxproj/runtime-distr.vcxproj create mode 100644 src/RandomX/vcxproj/runtime-distr.vcxproj.filters create mode 100644 src/RandomX/vcxproj/scratchpad-entropy.vcxproj create mode 100644 src/RandomX/vcxproj/scratchpad-entropy.vcxproj.filters create mode 100644 src/RandomX/vcxproj/superscalar-avalanche.vcxproj create mode 100644 src/RandomX/vcxproj/superscalar-avalanche.vcxproj.filters create mode 100644 src/RandomX/vcxproj/superscalar-init.vcxproj create mode 100644 src/RandomX/vcxproj/superscalar-init.vcxproj.filters create mode 100644 src/RandomX/vcxproj/superscalar-stats.vcxproj create mode 100644 src/RandomX/vcxproj/superscalar-stats.vcxproj.filters create mode 100644 src/RandomX/vcxproj/tests.vcxproj create mode 100644 src/RandomX/vcxproj/tests.vcxproj.filters diff --git a/src/RandomX/.gitattributes b/src/RandomX/.gitattributes new file mode 100644 index 000000000..2b93d4173 --- /dev/null +++ b/src/RandomX/.gitattributes @@ -0,0 +1,3 @@ +.gitignore export-ignore +.gitattributes export-ignore +audits export-ignore diff --git a/src/RandomX/.gitignore b/src/RandomX/.gitignore new file mode 100644 index 000000000..ec94c2c69 --- /dev/null +++ b/src/RandomX/.gitignore @@ -0,0 +1,9 @@ +bin/ +obj/ +*.user +*.suo +.vs +x64/ +Release/ +Debug/ +build/ diff --git a/src/RandomX/CMakeLists.txt b/src/RandomX/CMakeLists.txt new file mode 100644 index 000000000..f41f606b9 --- /dev/null +++ b/src/RandomX/CMakeLists.txt @@ -0,0 +1,236 @@ +# Copyright (c) 2019, The Monero Project +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are +# permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other +# materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be +# used to endorse or promote products derived from this software without specific +# prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +cmake_minimum_required(VERSION 3.5) + +project(RandomX) + +set(randomx_sources +src/aes_hash.cpp +src/argon2_ref.c +src/argon2_ssse3.c +src/argon2_avx2.c +src/bytecode_machine.cpp +src/cpu.cpp +src/dataset.cpp +src/soft_aes.cpp +src/virtual_memory.cpp +src/vm_interpreted.cpp +src/allocator.cpp +src/assembly_generator_x86.cpp +src/instruction.cpp +src/randomx.cpp +src/superscalar.cpp +src/vm_compiled.cpp +src/vm_interpreted_light.cpp +src/argon2_core.c +src/blake2_generator.cpp +src/instructions_portable.cpp +src/reciprocal.c +src/virtual_machine.cpp +src/vm_compiled_light.cpp +src/blake2/blake2b.c) + +if(NOT ARCH_ID) + # allow cross compiling + if(CMAKE_SYSTEM_PROCESSOR STREQUAL "") + set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_HOST_SYSTEM_PROCESSOR}) + endif() + string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" ARCH_ID) +endif() + +if(NOT ARM_ID) + set(ARM_ID "${ARCH_ID}") +endif() + +if(NOT ARCH) + set(ARCH "default") +endif() + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) + message(STATUS "Setting default build type: ${CMAKE_BUILD_TYPE}") +endif() + +include(CheckCXXCompilerFlag) +include(CheckCCompilerFlag) + +function(add_flag flag) + string(REPLACE "-" "_" supported_cxx ${flag}_cxx) + check_cxx_compiler_flag(${flag} ${supported_cxx}) + if(${${supported_cxx}}) + message(STATUS "Setting CXX flag ${flag}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE) + endif() + string(REPLACE "-" "_" supported_c ${flag}_c) + check_c_compiler_flag(${flag} ${supported_c}) + if(${${supported_c}}) + message(STATUS "Setting C flag ${flag}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE) + endif() +endfunction() + +# x86-64 +if(ARCH_ID STREQUAL "x86_64" OR ARCH_ID STREQUAL "x86-64" OR ARCH_ID STREQUAL "amd64") + list(APPEND randomx_sources + src/jit_compiler_x86.cpp) + + if(MSVC) + enable_language(ASM_MASM) + list(APPEND randomx_sources src/jit_compiler_x86_static.asm) + + set_property(SOURCE src/jit_compiler_x86_static.asm PROPERTY LANGUAGE ASM_MASM) + + set_source_files_properties(src/argon2_avx2.c COMPILE_FLAGS /arch:AVX2) + + set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} /DRELWITHDEBINFO") + set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /DRELWITHDEBINFO") + + add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/src/asm/configuration.asm + COMMAND powershell -ExecutionPolicy Bypass -File h2inc.ps1 ..\\src\\configuration.h > ..\\src\\asm\\configuration.asm SET ERRORLEVEL = 0 + COMMENT "Generating configuration.asm at ${CMAKE_CURRENT_SOURCE_DIR}" + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/vcxproj) + add_custom_target(generate-asm + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/asm/configuration.asm) + else() + list(APPEND randomx_sources src/jit_compiler_x86_static.S) + + # cheat because cmake and ccache hate each other + set_property(SOURCE src/jit_compiler_x86_static.S PROPERTY LANGUAGE C) + set_property(SOURCE src/jit_compiler_x86_static.S PROPERTY XCODE_EXPLICIT_FILE_TYPE sourcecode.asm) + + if(ARCH STREQUAL "native") + add_flag("-march=native") + else() + # default build has hardware AES enabled (software AES can be selected at runtime) + add_flag("-maes") + check_c_compiler_flag(-mssse3 HAVE_SSSE3) + if(HAVE_SSSE3) + set_source_files_properties(src/argon2_ssse3.c COMPILE_FLAGS -mssse3) + endif() + check_c_compiler_flag(-mavx2 HAVE_AVX2) + if(HAVE_AVX2) + set_source_files_properties(src/argon2_avx2.c COMPILE_FLAGS -mavx2) + endif() + endif() + endif() +endif() + +# PowerPC +if(ARCH_ID STREQUAL "ppc64" OR ARCH_ID STREQUAL "ppc64le") + if(ARCH STREQUAL "native") + add_flag("-mcpu=native") + endif() + # PowerPC AES requires ALTIVEC (POWER7+), so it cannot be enabled in the default build +endif() + +# ARMv8 +if(ARM_ID STREQUAL "aarch64" OR ARM_ID STREQUAL "arm64" OR ARM_ID STREQUAL "armv8-a") + list(APPEND randomx_sources + src/jit_compiler_a64_static.S + src/jit_compiler_a64.cpp) + # cheat because cmake and ccache hate each other + set_property(SOURCE src/jit_compiler_a64_static.S PROPERTY LANGUAGE C) + set_property(SOURCE src/jit_compiler_a64_static.S PROPERTY XCODE_EXPLICIT_FILE_TYPE sourcecode.asm) + + # not sure if this check is needed + include(CheckIncludeFile) + check_include_file(asm/hwcap.h HAVE_HWCAP) + if(HAVE_HWCAP) + add_definitions(-DHAVE_HWCAP) + endif() + + if(ARCH STREQUAL "native") + add_flag("-march=native") + else() + # default build has hardware AES enabled (software AES can be selected at runtime) + add_flag("-march=armv8-a+crypto") + endif() +endif() + +set(RANDOMX_INCLUDE "${CMAKE_CURRENT_SOURCE_DIR}/src" CACHE STRING "RandomX Include path") + +add_library(randomx ${randomx_sources}) + +if(TARGET generate-asm) + add_dependencies(randomx generate-asm) +endif() + +set_property(TARGET randomx PROPERTY POSITION_INDEPENDENT_CODE ON) +set_property(TARGET randomx PROPERTY CXX_STANDARD 11) +set_property(TARGET randomx PROPERTY CXX_STANDARD_REQUIRED ON) +set_property(TARGET randomx PROPERTY PUBLIC_HEADER src/randomx.h) + +include(GNUInstallDirs) +install(TARGETS randomx + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + +add_executable(randomx-tests + src/tests/tests.cpp) +target_link_libraries(randomx-tests + PRIVATE randomx) +set_property(TARGET randomx-tests PROPERTY POSITION_INDEPENDENT_CODE ON) +set_property(TARGET randomx-tests PROPERTY CXX_STANDARD 11) + +add_executable(randomx-codegen + src/tests/code-generator.cpp) +target_link_libraries(randomx-codegen + PRIVATE randomx) + +set_property(TARGET randomx-codegen PROPERTY POSITION_INDEPENDENT_CODE ON) +set_property(TARGET randomx-codegen PROPERTY CXX_STANDARD 11) + +if(NOT Threads_FOUND AND UNIX AND NOT APPLE) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads) +endif() + +add_executable(randomx-benchmark + src/tests/benchmark.cpp + src/tests/affinity.cpp) +target_link_libraries(randomx-benchmark + PRIVATE randomx + PRIVATE ${CMAKE_THREAD_LIBS_INIT}) + +include(CheckCXXSourceCompiles) +check_cxx_source_compiles(" +#include +#include +int main() { + std::atomic a; + a.is_lock_free(); +}" HAVE_CXX_ATOMICS) + +if(NOT HAVE_CXX_ATOMICS) + target_link_libraries(randomx-benchmark + PRIVATE "atomic") +endif() +set_property(TARGET randomx-benchmark PROPERTY POSITION_INDEPENDENT_CODE ON) +set_property(TARGET randomx-benchmark PROPERTY CXX_STANDARD 11) diff --git a/src/RandomX/LICENSE b/src/RandomX/LICENSE new file mode 100644 index 000000000..b1572ae82 --- /dev/null +++ b/src/RandomX/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2018-2019, tevador + +Copyright (c) 2014-2019, The Monero Project + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/RandomX/README.md b/src/RandomX/README.md new file mode 100644 index 000000000..4c1dabb65 --- /dev/null +++ b/src/RandomX/README.md @@ -0,0 +1,158 @@ +# RandomX +RandomX is a proof-of-work (PoW) algorithm that is optimized for general-purpose CPUs. RandomX uses random code execution (hence the name) together with several memory-hard techniques to minimize the efficiency advantage of specialized hardware. + +## Overview + +RandomX utilizes a virtual machine that executes programs in a special instruction set that consists of integer math, floating point math and branches. These programs can be translated into the CPU's native machine code on the fly (example: [program.asm](doc/program.asm)). At the end, the outputs of the executed programs are consolidated into a 256-bit result using a cryptographic hashing function ([Blake2b](https://blake2.net/)). + +RandomX can operate in two main modes with different memory requirements: + +* **Fast mode** - requires 2080 MiB of shared memory. +* **Light mode** - requires only 256 MiB of shared memory, but runs significantly slower + +Both modes are interchangeable as they give the same results. The fast mode is suitable for "mining", while the light mode is expected to be used only for proof verification. + +## Documentation + +Full specification is available in [specs.md](doc/specs.md). + +Design description and analysis is available in [design.md](doc/design.md). + +## Audits + +Between May and August 2019, RandomX was audited by 4 independent security research teams: + +* [Trail of Bits](https://www.trailofbits.com/) (28 000 USD) +* [X41 D-SEC](https://www.x41-dsec.de/) (42 000 EUR) +* [Kudelski Security](https://www.kudelskisecurity.com/) (18 250 CHF) +* [QuarksLab](https://quarkslab.com/en/) (52 800 USD) + +The first audit was generously funded by [Arweave](https://www.arweave.org/), one of the early adopters of RandomX. The remaining three audits were funded by donations from the [Monero community](https://ccs.getmonero.org/proposals/RandomX-audit.html). All four audits were coordinated by [OSTIF](https://ostif.org/). + +Final reports from all four audits are available in the [audits](audits/) directory. None of the audits found any critical vulnerabilities, but several changes in the algorithm and the code were made as a direct result of the audits. More details can be found in the [final report by OSTIF](https://ostif.org/four-audits-of-randomx-for-monero-and-arweave-have-been-completed-results/). + +## Build + +RandomX is written in C++11 and builds a static library with a C API provided by header file [randomx.h](src/randomx.h). Minimal API usage example is provided in [api-example1.c](src/tests/api-example1.c). The reference code includes a `randomx-benchmark` and `randomx-tests` executables for testing. + +### Linux + +Build dependencies: `cmake` (minimum 2.8.7) and `gcc` (minimum version 4.8, but version 7+ is recommended). + +To build optimized binaries for your machine, run: +``` +git clone https://github.com/tevador/RandomX.git +cd RandomX +mkdir build && cd build +cmake -DARCH=native .. +make +``` + +To build portable binaries, omit the `ARCH` option when executing cmake. + +### Windows + +On Windows, it is possible to build using MinGW (same procedure as on Linux) or using Visual Studio (solution file is provided). + +### Precompiled binaries + +Precompiled `randomx-benchmark` binaries are available on the [Releases page](https://github.com/tevador/RandomX/releases). + +## Proof of work + +RandomX was primarily designed as a PoW algorithm for [Monero](https://www.getmonero.org/). The recommended usage is following: + +* The key `K` is selected to be the hash of a block in the blockchain - this block is called the 'key block'. For optimal mining and verification performance, the key should change every 2048 blocks (~2.8 days) and there should be a delay of 64 blocks (~2 hours) between the key block and the change of the key `K`. This can be achieved by changing the key when `blockHeight % 2048 == 64` and selecting key block such that `keyBlockHeight % 2048 == 0`. +* The input `H` is the standard hashing blob with a selected nonce value. + +RandomX was successfully activated on the Monero network on the 30th November 2019. + +If you wish to use RandomX as a PoW algorithm for your cryptocurrency, please follow the [configuration guidelines](doc/configuration.md). + +**Note**: To achieve ASIC resistance, the key `K` must change and must not be miner-selectable. We recommend to use blockchain data as the key in a similar way to the Monero example above. If blockchain data cannot be used for some reason, use a predefined sequence of keys. + +### CPU performance +The table below lists the performance of selected CPUs using the optimal number of threads (T) and large pages (if possible), in hashes per second (H/s). "CNv4" refers to the CryptoNight variant 4 (CN/R) hashrate measured using [XMRig](https://github.com/xmrig/xmrig) v2.14.1. "Fast mode" and "Light mode" are the two modes of RandomX. + +|CPU|RAM|OS|AES|CNv4|Fast mode|Light mode| +|---|---|--|---|-----|------|--------------| +Intel Core i9-9900K|32G DDR4-3200|Windows 10|hw|660 (8T)|5770 (8T)|1160 (16T)| +AMD Ryzen 7 1700|16G DDR4-2666|Ubuntu 16.04|hw|520 (8T)|4100 (8T)|620 (16T)| +Intel Core i7-8550U|16G DDR4-2400|Windows 10|hw|200 (4T)|1700 (4T)|350 (8T)| +Intel Core i3-3220|4G DDR3-1333|Ubuntu 16.04|soft|42 (4T)|510 (4T)|150 (4T)| +Raspberry Pi 3|1G LPDDR2|Ubuntu 16.04|soft|3.5 (4T)|-|20 (4T)| + +Note that RandomX currently includes a JIT compiler for x86-64 and ARM64. Other architectures have to use the portable interpreter, which is much slower. + +### GPU performance + +SChernykh is developing GPU mining code for RandomX. Benchmarks are included in the following repositories: + +* [CUDA miner](https://github.com/SChernykh/RandomX_CUDA) - NVIDIA GPUs. +* [OpenCL miner](https://github.com/SChernykh/RandomX_OpenCL) - only for AMD Vega and AMD Polaris GPUs (uses GCN machine code). + +The code from the above repositories is included in the open source miner [XMRig](https://github.com/xmrig/xmrig). + +Note that GPUs are at a disadvantage when running RandomX since the algorithm was designed to be efficient on CPUs. + +# FAQ + +### Which CPU is best for mining RandomX? + +Most Intel and AMD CPUs made since 2011 should be fairly efficient at RandomX. More specifically, efficient mining requires: + +* 64-bit architecture +* IEEE 754 compliant floating point unit +* Hardware AES support ([AES-NI](https://en.wikipedia.org/wiki/AES_instruction_set) extension for x86, Cryptography extensions for ARMv8) +* 16 KiB of L1 cache, 256 KiB of L2 cache and 2 MiB of L3 cache per mining thread +* Support for large memory pages +* At least 2.5 GiB of free RAM per NUMA node +* Multiple memory channels may be required: + * DDR3 memory is limited to about 1500-2000 H/s per channel (depending on frequency and timings) + * DDR4 memory is limited to about 4000-6000 H/s per channel (depending on frequency and timings) + +### Does RandomX facilitate botnets/malware mining or web mining? + +Due to the way the algorithm works, mining malware is much easier to detect. [RandomX Sniffer](https://github.com/tevador/randomx-sniffer) is a proof of concept tool that can detect illicit mining activity on Windows. + +Efficient mining requires more than 2 GiB of memory, which also disqualifies many low-end machines such as IoT devices, which are often parts of large botnets. + +Web mining is infeasible due to the large memory requirement and the lack of directed rounding support for floating point operations in both Javascript and WebAssembly. + +### Since RandomX uses floating point math, does it give reproducible results on different platforms? + +RandomX uses only operations that are guaranteed to give correctly rounded results by the [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754) standard: addition, subtraction, multiplication, division and square root. Special care is taken to avoid corner cases such as NaN values or denormals. + +The reference implementation has been validated on the following platforms: +* x86 (32-bit, little-endian) +* x86-64 (64-bit, little-endian) +* ARMv7+VFPv3 (32-bit, little-endian) +* ARMv8 (64-bit, little-endian) +* PPC64 (64-bit, big-endian) + +### Can FPGAs mine RandomX? + +RandomX generates multiple unique programs for every hash, so FPGAs cannot dynamically reconfigure their circuitry because typical FPGA takes tens of seconds to load a bitstream. It is also not possible to generate bitstreams for RandomX programs in advance due to the sheer number of combinations (there are 2512 unique programs). + +Sufficiently large FPGAs can mine RandomX in a [soft microprocessor](https://en.wikipedia.org/wiki/Soft_microprocessor) configuration by emulating a CPU. Under these circumstances, an FPGA will be much less efficient than a CPU or a specialized chip (ASIC). + +## Acknowledgements +* [tevador](https://github.com/tevador) - author +* [SChernykh](https://github.com/SChernykh) - contributed significantly to the design of RandomX +* [hyc](https://github.com/hyc) - original idea of using random code execution for PoW +* [Other contributors](https://github.com/tevador/RandomX/graphs/contributors) + +RandomX uses some source code from the following 3rd party repositories: +* Argon2d, Blake2b hashing functions: https://github.com/P-H-C/phc-winner-argon2 + +The author of RandomX declares no competing financial interest. + +## Donations + +If you'd like to use RandomX, please consider donating to help cover the development cost of the algorithm. + +Author's XMR address: +``` +845xHUh5GvfHwc2R8DVJCE7BT2sd4YEcmjG8GNSdmeNsP5DTEjXd1CNgxTcjHjiFuthRHAoVEJjM7GyKzQKLJtbd56xbh7V +``` +Total donations received: ~3.86 XMR (as of 30th August 2019). Thanks to all contributors. diff --git a/src/RandomX/doc/configuration.md b/src/RandomX/doc/configuration.md new file mode 100644 index 000000000..27b7c66d0 --- /dev/null +++ b/src/RandomX/doc/configuration.md @@ -0,0 +1,287 @@ +# RandomX configuration + +RandomX has 45 customizable parameters (see table below). We recommend each project using RandomX to select a unique configuration to prevent network attacks from hashpower rental services. + +These parameters can be modified in source file [configuration.h](../src/configuration.h). + +|parameter|description|default value| +|---------|-----|-------| +|`RANDOMX_ARGON_MEMORY`|The number of 1 KiB Argon2 blocks in the Cache| `262144`| +|`RANDOMX_ARGON_ITERATIONS`|The number of Argon2d iterations for Cache initialization|`3`| +|`RANDOMX_ARGON_LANES`|The number of parallel lanes for Cache initialization|`1`| +|`RANDOMX_ARGON_SALT`|Argon2 salt|`"RandomX\x03"`| +|`RANDOMX_CACHE_ACCESSES`|The number of random Cache accesses per Dataset item|`8`| +|`RANDOMX_SUPERSCALAR_LATENCY`|Target latency for SuperscalarHash (in cycles of the reference CPU)|`170`| +|`RANDOMX_DATASET_BASE_SIZE`|Dataset base size in bytes|`2147483648`| +|`RANDOMX_DATASET_EXTRA_SIZE`|Dataset extra size in bytes|`33554368`| +|`RANDOMX_PROGRAM_SIZE`|The number of instructions in a RandomX program|`256`| +|`RANDOMX_PROGRAM_ITERATIONS`|The number of iterations per program|`2048`| +|`RANDOMX_PROGRAM_COUNT`|The number of programs per hash|`8`| +|`RANDOMX_JUMP_BITS`|Jump condition mask size in bits|`8`| +|`RANDOMX_JUMP_OFFSET`|Jump condition mask offset in bits|`8`| +|`RANDOMX_SCRATCHPAD_L3`|Scratchpad size in bytes|`2097152`| +|`RANDOMX_SCRATCHPAD_L2`|Scratchpad L2 size in bytes|`262144`| +|`RANDOMX_SCRATCHPAD_L1`|Scratchpad L1 size in bytes|`16384`| +|`RANDOMX_FREQ_*` (29x)|Instruction frequencies|multiple values| + +Not all of the parameters can be changed safely and most parameters have some contraints on what values can be selected (checked at compile-time). + +**Disclaimer: The compile-time checks only prevent obviously broken configurations. Passing the checks does not imply that the configuration is safe and will not cause crashes or other issues. We recommend that each non-standard configuration is thoroughly tested before being deployed.** + +### RANDOMX_ARGON_MEMORY + +This parameter determines the amount of memory needed in the light mode. Memory is specified in KiB (1 KiB = 1024 bytes). + +#### Permitted values +Integer powers of 2 in the range 8 - 2097152. + +#### Notes +Lower sizes will reduce the memory-hardness of the algorithm. + +### RANDOMX_ARGON_ITERATIONS + +Determines the number of passes of Argon2 that are used to generate the Cache. + +#### Permitted values +Any positive 32-bit integer. + +#### Notes +The time needed to initialize the Cache is proportional to the value of this constant. + +### RANDOMX_ARGON_LANES + +The number of parallel lanes for Cache initialization. + +#### Permitted values +Integers in the range 1 - 16777215. + +#### Notes +This parameter determines how many threads can be used for Cache initialization. + +### RANDOMX_ARGON_SALT + +Salt value for Cache initialization. + +#### Permitted values +A string of at least 8 characters. + +#### Note +Every implementation should choose a unique salt value. + +### RANDOMX_CACHE_ACCESSES + +The number of random Cache access per Dataset item. + +#### Permitted values +Any integer greater than 1. + +#### Notes +This value directly determines the performance ratio between the 'fast' and 'light' modes. + +### RANDOMX_SUPERSCALAR_LATENCY +Target latency for SuperscalarHash, in cycles of the reference CPU. + +#### Permitted values +Integers in the range 1 - 10000. + +#### Notes +The default value was tuned so that a high-performance superscalar CPU running at 2-4 GHz will execute SuperscalarHash in similar time it takes to load data from RAM (40-80 ns). Using a lower value will make Dataset generation (and light mode) more memory bound, while increasing this value will make Dataset generation (and light mode) more compute bound. + +### RANDOMX_DATASET_BASE_SIZE + +Dataset base size in bytes. + +#### Permitted values +Integer powers of 2 in the range 64 - 4294967296 (inclusive). + +#### Note +This constant affects the memory requirements in fast mode. Some values are unsafe depending on other parameters. See [Unsafe configurations](#unsafe-configurations). + +### RANDOMX_DATASET_EXTRA_SIZE + +Dataset extra size in bytes. + +#### Permitted values +Non-negative integer divisible by 64. + +#### Note +This constant affects the memory requirements in fast mode. Some values are unsafe depending on other parameters. See [Unsafe configurations](#unsafe-configurations). + +### RANDOMX_PROGRAM_SIZE + +The number of instructions in a RandomX program. + +#### Permitted values +Positive integers divisible by 8 in the range 8 - 32768 (inclusive). + +#### Notes +Smaller values will make RandomX more DRAM-latency bound, while higher values will make RandomX more compute-bound. Some values are unsafe. See [Unsafe configurations](#unsafe-configurations). + +### RANDOMX_PROGRAM_ITERATIONS + +The number of iterations per program. + +#### Permitted values +Any positive integer. + +#### Notes +Time per hash increases linearly with this constant. Smaller values will increase the overhead of program compilation, while larger values may allow more time for optimizations. Some values are unsafe. See [Unsafe configurations](#unsafe-configurations). + +### RANDOMX_PROGRAM_COUNT + +The number of programs per hash. + +#### Permitted values +Any positive integer. + +#### Notes +Time per hash increases linearly with this constant. Some values are unsafe. See [Unsafe configurations](#unsafe-configurations). + +### RANDOMX_JUMP_BITS +Jump condition mask size in bits. + +#### Permitted values +Positive integers. The sum of `RANDOMX_JUMP_BITS` and `RANDOMX_JUMP_OFFSET` must not exceed 16. + +#### Notes +This determines the jump probability of the CBRANCH instruction. The default value of 8 results in jump probability of 1/28 = 1/256. Increasing this constant will decrease the rate of jumps (and vice versa). + +### RANDOMX_JUMP_OFFSET +Jump condition mask offset in bits. + +#### Permitted values +Non-negative integers. The sum of `RANDOMX_JUMP_BITS` and `RANDOMX_JUMP_OFFSET` must not exceed 16. + +#### Notes +Since the low-order bits of RandomX registers are slightly biased, this offset moves the condition mask to higher bits, which are less biased. Using values smaller than the default may result in a slightly lower jump probability than the theoretical value calculated from `RANDOMX_JUMP_BITS`. + +### RANDOMX_SCRATCHPAD_L3 +RandomX Scratchpad size in bytes. + +#### Permitted values +Any integer power of 2. Must be larger than or equal to `RANDOMX_SCRATCHPAD_L2`. + +#### Notes + +The default value of 2 MiB was selected to match the typical cache/core ratio of desktop processors. Using a lower value will make RandomX more core-bound, while using larger values will make the algorithm more latency-bound. Some values are unsafe depending on other parameters. See [Unsafe configurations](#unsafe-configurations). + +### RANDOMX_SCRATCHPAD_L2 + +Scratchpad L2 size in bytes. + +#### Permitted values +Any integer power of 2. Must be larger than or equal to `RANDOMX_SCRATCHPAD_L1`. + +#### Notes +The default value of 256 KiB was selected to match the typical per-core L2 cache size of desktop processors. Using a lower value will make RandomX more core-bound, while using larger values will make the algorithm more latency-bound. + +### RANDOMX_SCRATCHPAD_L1 + +Scratchpad L1 size in bytes. + +#### Permitted values +Any integer power of 2. The minimum is 64 bytes. + +#### Notes +The default value of 16 KiB was selected to be about half of the per-core L1 cache size of desktop processors. Using a lower value will make RandomX more core-bound, while using larger values will make the algorithm more latency-bound. + +### RANDOMX_FREQ_* + +Instruction frequencies (per 256 instructions). + +#### Permitted values +There is a total of 29 different instructions. The sum of frequencies must be equal to 256. + +#### Notes + +Making changes to the default values is not recommended. The only exceptions are the instruction pairs IROR_R/IROL_R, FADD_R/FSUB_R and FADD_M/FSUB_M, which are functionally equivalent. Example of a safe custom configuration: + +||default|custom| +|-|------|------|-| +|`RANDOMX_FREQ_IROR_R`|8|5| +|`RANDOMX_FREQ_IROL_R`|2|5| + +||default|custom| +|-|------|------| +|`RANDOMX_FREQ_FADD_R`|16|17| +|`RANDOMX_FREQ_FSUB_R`|16|15| + +||default|custom| +|-|------|------| +|`RANDOMX_FREQ_FADD_M`|5|4| +|`RANDOMX_FREQ_FSUB_M`|5|6| + +## Unsafe configurations + +There are some configurations that are considered 'unsafe' because they affect the security of the algorithm against attacks. If the conditions listed below are not satisfied, the configuration is unsafe and a compilation error is emitted when building the RandomX library. + +These checks can be disabled by definining `RANDOMX_UNSAFE` when building RandomX, e.g. by using `-DRANDOMX_UNSAFE` command line switch in GCC or MSVC. It is not recommended to disable these checks except for testing purposes. + + +### 1. Memory-time tradeoffs + +#### Condition +```` +RANDOMX_CACHE_ACCESSES * RANDOMX_ARGON_MEMORY * 1024 + 33554432 >= RANDOMX_DATASET_BASE_SIZE + RANDOMX_DATASET_EXTRA_SIZE +```` + +Configurations not satisfying this condition are vulnerable to memory-time tradeoffs, which enables efficient mining in light mode. + +#### Solutions + +* Increase `RANDOMX_CACHE_ACCESSES` or `RANDOMX_ARGON_MEMORY`. +* Decrease `RANDOMX_DATASET_BASE_SIZE` or `RANDOMX_DATASET_EXTRA_SIZE`. + +### 2. Insufficient Scratchpad writes + +#### Condition +```` +(128 + RANDOMX_PROGRAM_SIZE * RANDOMX_FREQ_ISTORE / 256) * (RANDOMX_PROGRAM_COUNT * RANDOMX_PROGRAM_ITERATIONS) >= RANDOMX_SCRATCHPAD_L3 +```` + +Configurations not satisfying this condition are vulnerable to Scratchpad size optimizations due to low amount of writes. + +#### Solutions + +* Increase `RANDOMX_PROGRAM_SIZE`, `RANDOMX_FREQ_ISTORE`, `RANDOMX_PROGRAM_COUNT` or `RANDOMX_PROGRAM_ITERATIONS`. +* Decrease `RANDOMX_SCRATCHPAD_L3`. + +### 3. Program filtering strategies + +#### Condition +``` +RANDOMX_PROGRAM_COUNT > 1 +``` + +Configurations not satisfying this condition are vulnerable to program filtering strategies. + +#### Solution + +* Increase `RANDOMX_PROGRAM_COUNT` to at least 2. + +### 4. Low program entropy + +#### Condition +``` +RANDOMX_PROGRAM_SIZE >= 64 +``` + +Configurations not satisfying this condition do not have a sufficient number of instruction combinations. + +#### Solution + +* Increase `RANDOMX_PROGRAM_SIZE` to at least 64. + +### 5. High compilation overhead + +#### Condition +``` +RANDOMX_PROGRAM_ITERATIONS >= 400 +``` + +Configurations not satisfying this condition have a program compilation overhead exceeding 10%. + +#### Solution + +* Increase `RANDOMX_PROGRAM_ITERATIONS` to at least 400. + diff --git a/src/RandomX/doc/design.md b/src/RandomX/doc/design.md new file mode 100644 index 000000000..7a1b8ef22 --- /dev/null +++ b/src/RandomX/doc/design.md @@ -0,0 +1,650 @@ +# RandomX design +To minimize the performance advantage of specialized hardware, a proof of work (PoW) algorithm must achieve *device binding* by targeting specific features of existing general-purpose hardware. This is a complex task because we have to target a large class of devices with different architectures from different manufacturers. + +There are two distinct classes of general processing devices: central processing units (CPUs) and graphics processing units (GPUs). RandomX targets CPUs for the following reasons: + +* CPUs, being less specialized devices, are more prevalent and widely accessible. A CPU-bound algorithm is more egalitarian and allows more participants to join the network. This is one of the goals stated in the original CryptoNote whitepaper [[1](https://cryptonote.org/whitepaper.pdf)]. +* A large common subset of native hardware instructions exists among different CPU architectures. The same cannot be said about GPUs. For example, there is no common integer multiplication instruction for NVIDIA and AMD GPUs [[2](https://github.com/ifdefelse/ProgPOW/issues/16)]. +* All major CPU instruction sets are well documented with multiple open source compilers available. In comparison, GPU instruction sets are usually proprietary and may require vendor specific closed-source drivers for maximum performance. + +## 1. Design considerations + +The most basic idea of a CPU-bound proof of work is that the "work" must be dynamic. This takes advantage of the fact that CPUs accept two kinds of inputs: *data* (the main input) and *code* (which specifies what to perform with the data). + +Conversely, typical cryptographic hashing functions [[3](https://en.wikipedia.org/wiki/Cryptographic_hash_function)] do not represent suitable work for the CPU because their only input is *data*, while the sequence of operations is fixed and can be performed more efficiently by a specialized integrated circuit. + +### 1.1 Dynamic proof of work + +A dynamic proof of work algorithm can generally consist of the following 4 steps: + +1) Generate a random program. +2) Translate it into the native machine code of the CPU. +3) Execute the program. +4) Transform the output of the program into a cryptographically secure value. + +The actual 'useful' CPU-bound work is performed in step 3, so the algorithm must be tuned to minimize the overhead of the remaining steps. + +#### 1.1.1 Generating a random program + +Early attempts at a dynamic proof of work design were based on generating a program in a high-level language, such as C or Javascript [[4](https://github.com/hyc/randprog), [5](https://github.com/tevador/RandomJS)]. However, this is very inefficient for two main reasons: + +* High level languages have a complex syntax, so generating a valid program is relatively slow since it requires the creation of an abstract syntax tree (ASL). +* Once the source code of the program is generated, the compiler will generally parse the textual representation back into the ASL, which makes the whole process of generating source code redundant. + +The fastest way to generate a random program is to use a *logic-less* generator - simply filling a buffer with random data. This of course requires designing a syntaxless programming language (or instruction set) in which all random bit strings represent valid programs. + +#### 1.1.2 Translating the program into machine code + +This step is inevitable because we don't want to limit the algorithm to a specific CPU architecture. In order to generate machine code as fast as possible, we need our instruction set to be as close to native hardware as possible, while still generic enough to support different architectures. There is not enough time for expensive optimizations during code compilation. + +#### 1.1.3 Executing the program + +The actual program execution should utilize as many CPU components as possible. Some of the features that should be utilized in the program are: + +* multi-level caches (L1, L2, L3) +* μop cache [[6](https://en.wikipedia.org/wiki/CPU_cache#Micro-operation_(%CE%BCop_or_uop)_cache)] +* arithmetic logic unit (ALU) +* floating point unit (FPU) +* memory controller +* instruction level parallelism [[7](https://en.wikipedia.org/wiki/Instruction-level_parallelism)] + * superscalar execution [[8](https://en.wikipedia.org/wiki/Superscalar_processor)] + * out-of-order execution [[9](https://en.wikipedia.org/wiki/Out-of-order_execution)] + * speculative execution [[10](https://en.wikipedia.org/wiki/Speculative_execution)] + * register renaming [[11](https://en.wikipedia.org/wiki/Register_renaming)] + +Chapter 2 describes how the RandomX VM takes advantages of these features. + +#### 1.1.4 Calculating the final result + +Blake2b [[12](https://blake2.net/)] is a cryptographically secure hashing function that was specifically designed to be fast in software, especially on modern 64-bit processors, where it's around three times faster than SHA-3 and can run at a speed of around 3 clock cycles per byte of input. This function is an ideal candidate to be used in a CPU-friendly proof of work. + +For processing larger amounts of data in a cryptographically secure way, the Advanced Encryption Standard (AES) [[13](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard)] can provide the fastest processing speed because many modern CPUs support hardware acceleration of these operations. See chapter 3 for more details about the use of AES in RandomX. + +### 1.2 The "Easy program problem" + +When a random program is generated, one may choose to execute it only when it's favorable. This strategy is viable for two main reasons: + +1. The runtime of randomly generated programs typically follows a log-normal distribution [[14](https://en.wikipedia.org/wiki/Log-normal_distribution)] (also see Appendix C). A generated program may be quickly analyzed and if it's likely to have above-average runtime, program execution may be skipped and a new program may be generated instead. This can significantly boost performance especially in case the runtime distribution has a heavy tail (many long-running outliers) and if program generation is cheap. +2. An implementation may choose to optimize for a subset of the features required for program execution. For example, the support for some operations (such as division) may be dropped or some instruction sequences may be implemented more efficiently. Generated programs would then be analyzed and be executed only if they match the specific requirements of the optimized implementation. + +These strategies of searching for programs of particular properties deviate from the objectives of this proof of work, so they must be eliminated. This can be achieved by requiring a sequence of *N* random programs to be executed such that each program is generated from the output of the previous one. The output of the final program is then used as the result. + +``` + +---------------+ +---------------+ +---------------+ +---------------+ + | | | | | | | | +input --> | program 1 | --> | program 2 | --> ... --> | program (N-1) | --> | program N | --> result + | | | | | | | | + +---------------+ +---------------+ +---------------+ +---------------+ +``` + +The principle is that after the first program is executed, a miner has to either commit to finishing the whole chain (which may include unfavorable programs) or start over and waste the effort expended on the unfinished chain. Examples of how this affects the hashrate of different mining strategies are given in Appendix A. + +Additionally, this chained program execution has the benefit of equalizing the runtime for the whole chain since the relative deviation of a sum of identically distributed runtimes is decreased. + +### 1.3 Verification time + +Since the purpose of the proof of work is to be used in a trustless peer-to-peer network, network participants must be able to quickly verify if a proof is valid or not. This puts an upper bound on the complexity of the proof of work algorithm. In particular, we set a goal for RandomX to be at least as fast to verify as the CryptoNight hash function [[15](https://cryptonote.org/cns/cns008.txt)], which it aims to replace. + +### 1.4 Memory-hardness + +Besides pure computational resources, such as ALUs and FPUs, CPUs usually have access to a large amount of memory in the form of DRAM [[16](https://en.wikipedia.org/wiki/Dynamic_random-access_memory)]. The performance of the memory subsystem is typically tuned to match the compute capabilities, for example [[17](https://en.wikipedia.org/wiki/Multi-channel_memory_architecture)]: + +* single channel memory for embedded and low power CPUs +* dual channel memory for desktop CPUs +* triple or quad channel memory for workstation CPUs +* six or eight channel memory for high-end server CPUs + +In order to utilize the external memory as well as the on-chip memory controllers, the proof of work algorithm should access a large memory buffer (called the "Dataset"). The Dataset must be: + +1. larger than what can be stored on-chip (to require external memory) +2. dynamic (to require writable memory) + +The maximum amount of SRAM that can be put on a single chip is more than 512 MiB for a 16 nm process and more than 2 GiB for a 7 nm process [[18](https://www.grin-forum.org/t/obelisk-grn1-chip-details/4571)]. Ideally, the size of the Dataset should be at least 4 GiB. However, due to constraints on the verification time (see below), the size used by RandomX was selected to be 2080 MiB. While a single chip can theoretically be made with this amount of SRAM using current technology (7 nm in 2019), the feasibility of such solution is questionable, at least in the near future. + +#### 1.4.1 Light-client verification + +While it's reasonable to require >2 GiB for dedicated mining systems that solve the proof of work, an option must be provided for light clients to verify the proof using a much lower amount of memory. + +The ratio of memory required for the 'fast' and 'light' modes must be chosen carefully not to make the light mode viable for mining. In particular, the area-time (AT) product of the light mode should not be smaller than the AT product of the fast mode. Reduction of the AT product is a common way of measuring tradeoff attacks [[19](https://eprint.iacr.org/2015/227.pdf)]. + +Given the constraints described in the previous chapters, the maximum possible performance ratio between the fast and the light verification modes was empirically determined to be 8. This is because: + +1. Further increase of the light verification time would violate the constraints set out in chapter 1.3. +2. Further decrease of the fast mode runtime would violate the constraints set out in chapter 1.1, in particular the overhead time of program generation and result calculation would become too high. + +Additionally, 256 MiB was selected as the maximum amount of memory that can be required in the light-client mode. This amount is acceptable even for small single-board computers such as the Raspberry Pi. + +To keep a constant memory-time product, the maximum fast-mode memory requirement is: +``` +8 * 256 MiB = 2048 MiB +``` +This can be further increased since the light mode requires additional chip area for the SuperscalarHash function (see chapter 3.4 and chapter 6 of the Specification). Assuming a conservative estimate of 0.2 mm2 per SuperscalarHash core and DRAM density of 0.149 Gb/mm2 [[20](http://en.thelec.kr/news/articleView.html?idxno=20)], the additional memory is: + +``` +8 * 0.2 * 0.149 * 1024 / 8 = 30.5 MiB +``` +or 32 MiB when rounded to the nearest power of 2. The total memory requirement of the fast mode can be 2080 MiB with a roughly constant AT product. + +## 2. Virtual machine architecture + +This section describes the design of the RandomX virtual machine (VM). + +### 2.1 Instruction set + +RandomX uses a fixed-length instruction encoding with 8 bytes per instruction. This allows a 32-bit immediate value to be included in the instruction word. The interpretation of the instruction word bits was chosen so that any 8-byte word is a valid instruction. This allows for very efficient random program generation (see chapter 1.1.1). + +#### 2.1.1 Instruction complexity + +The VM is a complex instruction set machine that allows both register and memory addressed operands. However, each RandomX instructions translates to only 1-7 x86 instructions (1.8 on average). It is important to keep the instruction complexity relatively low to minimize the efficiency advantage of specialized hardware with a tailored instruction set. + +### 2.2 Program + +The program executed by the VM has the form of a loop consisting of 256 random instructions. + +* 256 instructions is long enough to provide a large number of possible programs and enough space for branches. The number of different programs that can be generated is limited to 2512 = 1.3e+154, which is the number of possible seed values of the random generator. +* 256 instructions is short enough so that high-performance CPUs can execute one iteration in similar time it takes to fetch data from DRAM. This is advantageous because it allows Dataset accesses to be synchronized and fully prefetchable (see chapter 2.9). +* Since the program is a loop, it can take advantage of the μop cache [[6](https://en.wikipedia.org/wiki/CPU_cache#Micro-operation_(%CE%BCop_or_uop)_cache)] that is present in some x86 CPUs. Running a loop from the μop cache allows the CPU to power down the x86 instruction decoders, which should help to equalize the power efficiency between x86 and architectures with simple instruction decoding. + +### 2.3 Registers + +The VM uses 8 integer registers and 12 floating point registers. This is the maximum that can be allocated as physical registers in x86-64, which has the fewest architectural registers among common 64-bit CPU architectures. Using more registers would put x86 CPUs at a disadvantage since they would have to use memory to store VM register contents. + +### 2.4 Integer operations + +RandomX uses all primitive integer operations that have high output entropy: addition (IADD_RS, IADD_M), subtraction (ISUB_R, ISUB_M, INEG_R), multiplication (IMUL_R, IMUL_M, IMULH_R, IMULH_M, ISMULH_R, ISMULH_M, IMUL_RCP), exclusive or (IXOR_R, IXOR_M) and rotation (IROR_R, IROL_R). + +#### 2.4.1 IADD_RS + +The IADD_RS instruction utilizes the address calculation logic of CPUs and can be performed in a single hardware instruction by most CPUs (x86 `lea`, arm `add`). + +#### 2.4.2 IMUL_RCP + +Because integer division is not fully pipelined in CPUs and can be made faster in ASICs, the IMUL_RCP instruction requires only one division per program to calculate the reciprocal. This forces an ASIC to include a hardware divider without giving them a performance advantage during program execution. + +#### 2.4.3 IROR_R/IROL_R + +Rotation instructions are split between rotate right and rotate left with a 4:1 ratio. Rotate right has a higher frequency because some architecures (like ARM) don't support rotate left natively (it must be emulated using rotate right). + +#### 2.4.4 ISWAP_R + +This instruction can be executed efficiently by CPUs that support register renaming/move elimination. + +### 2.5 Floating point operations + +RandomX uses double precision floating point operations, which are supported by the majority of CPUs and require more complex hardware than single precision. All operations are performed as 128-bit vector operations, which is also supported by all major CPU architectures. + +RandomX uses five operations that are guaranteed by the IEEE 754 standard to give correctly rounded results: addition, subtraction, multiplication, division and square root. All 4 rounding modes defined by the standard are used. + +#### 2.5.1 Floating point register groups + +The domains of floating point operations are separated into "additive" operations, which use register group F and "multiplicative" operations, which use register group E. This is done to prevent addition/subtraction from becoming no-op when a small number is added to a large number. Since the range of the F group registers is limited to around `±3.0e+14`, adding or subtracting a floating point number with absolute value larger than 1 always changes at least 5 fraction bits. + +Because the limited range of group F registers would allow the use of a more efficient fixed-point representation (with 80-bit numbers), the FSCAL instruction manipulates the binary representation of the floating point format to make this optimization more difficult. + +Group E registers are restricted to positive values, which avoids `NaN` results (such as square root of a negative number or `0 * ∞`). Division uses only memory source operand to avoid being optimized into multiplication by constant reciprocal. The exponent of group E memory operands is set to a value between -255 and 0 to avoid division and multiplication by 0 and to increase the range of numbers that can be obtained. The approximate range of possible group E register values is `1.7E-77` to `infinity`. + +Approximate distribution of floating point register values at the end of each program loop is shown in these figures (left - group F, right - group E): + +![Imgur](https://i.imgur.com/64G4qE8.png) + +*(Note: bins are marked by the left-side value of the interval, e.g. bin marked `1e-40` contains values from `1e-40` to `1e-20`.)* + +The small number of F register values at `1e+14` is caused by the FSCAL instruction, which significantly increases the range of the register values. + +Group E registers cover a very large range of values. About 2% of programs produce at least one `infinity` value. + +To maximize entropy and also to fit into one 64-byte cache line, floating point registers are combined using the XOR operation at the end of each iteration before being stored into the Scratchpad. + +### 2.6 Branches + +Modern CPUs invest a lot of die area and energy to handle branches. This includes: + +* Branch predictor unit [[21](https://en.wikipedia.org/wiki/Branch_predictor)] +* Checkpoint/rollback states that allow the CPU to recover in case of a branch misprediction. + +To take advantage of speculative designs, the random programs should contain branches. However, if branch prediction fails, the speculatively executed instructions are thrown away, which results in a certain amount of wasted energy with each misprediction. Therefore we should aim to minimize the number of mispredictions. + +Additionally, branches in the code are essential because they significantly reduce the amount of static optimizations that can be made. For example, consider the following x86 instruction sequence: +```asm + ... +branch_target_00: + ... + xor r8, r9 + test r10, 2088960 + je branch_target_00 + xor r8, r9 + ... +``` +The XOR operations would normally cancel out, but cannot be optimized away due to the branch because the result will be different if the branch is taken. Similarly, the ISWAP_R instruction could be always statically optimized out if it wasn't for branches. + +In general, random branches must be designed in such way that: + +1. Infinite loops are not possible. +1. The number of mispredicted branches is small. +1. Branch condition depends on a runtime value to disable static branch optimizations. + +#### 2.6.1 Branch prediction + +Unfortunately, we haven't found a way how to utilize branch prediction in RandomX. Because RandomX is a consensus protocol, all the rules must be set out in advance, which includes the rules for branches. Fully predictable branches cannot depend on the runtime value of any VM register (since register values are pseudorandom and unpredictable), so they would have to be static and therefore easily optimizable by specialized hardware. + +#### 2.6.2 CBRANCH instruction + +RandomX therefore uses random branches with a jump probability of 1/256 and branch condition that depends on an integer register value. These branches will be predicted as "not taken" by the CPU. Such branches are "free" in most CPU designs unless they are taken. While this doesn't take advantage of the branch predictors, speculative designs will see a significant performance boost compared to non-speculative branch handling - see Appendix B for more information. + +The branching conditions and jump targets are chosen in such way that infinite loops in RandomX code are impossible because the register controlling the branch will never be modified in the repeated code block. Each CBRANCH instruction can jump up to twice in a row. Handling CBRANCH using predicated execution [[22](https://en.wikipedia.org/wiki/Predication_(computer_architecture))] is impractical because the branch is not taken most of the time. + +### 2.7 Instruction-level parallelism + +CPUs improve their performance using several techniques that utilize instruction-level parallelism of the executed code. These techniques include: + +* Having multiple execution units that can execute operations in parallel (*superscalar execution*). +* Executing instruction not in program order, but in the order of operand availability (*out-of-order execution*). +* Predicting which way branches will go to enhance the benefits of both superscalar and out-of-order execution. + +RandomX benefits from all these optimizations. See Appendix B for a detailed analysis. + +### 2.8 Scratchpad + +The Scratchpad is used as read-write memory. Its size was selected to fit entirely into CPU cache. + +#### 2.8.1 Scratchpad levels + +The Scratchpad is split into 3 levels to mimic the typical CPU cache hierarchy [[23](https://en.wikipedia.org/wiki/CPU_cache)]. Most VM instructions access "L1" and "L2" Scratchpad because L1 and L2 CPU caches are located close to the CPU execution units and provide the best random access latency. The ratio of reads from L1 and L2 is 3:1, which matches the inverse ratio of typical latencies (see table below). + +|CPU μ-architecture|L1 latency|L2 latency|L3 latency|source| +|----------------|----------|----------|----------|------| +ARM Cortex A55|2|6|-|[[24](https://www.anandtech.com/show/11441/dynamiq-and-arms-new-cpus-cortex-a75-a55/4)] +|AMD Zen+|4|12|40|[[25](https://en.wikichip.org/wiki/amd/microarchitectures/zen%2B#Memory_Hierarchy)]| +|Intel Skylake|4|12|42|[[26](https://en.wikichip.org/wiki/intel/microarchitectures/skylake_(client)#Memory_Hierarchy)] + +The L3 cache is much larger and located further from the CPU core. As a result, its access latencies are much higher and can cause stalls in program execution. + +RandomX therefore performs only 2 random accesses into "L3" Scratchpad per program iteration (steps 2 and 3 in chapter 4.6.2 of the Specification). Register values from a given iteration are written into the same locations they were loaded from, which guarantees that the required cache lines have been moved into the faster L1 or L2 caches. + +Additionally, integer instructions that read from a fixed address also use the whole "L3" Scratchpad (Table 5.1.4 of the Specification) because repetitive accesses will ensure that the cache line will be placed in the L1 cache of the CPU. This shows that the Scratchpad level doesn't always directly correspond to the same CPU cache level. + +#### 2.8.2 Scratchpad writes + +There are two ways the Scratchpad is modified during VM execution: + +1. At the end of each program iteration, all register values are written into "L3" Scratchpad (see Specification chapter 4.6.2, steps 9 and 11). This writes a total of 128 bytes per iteration in two 64-byte blocks. +2. The ISTORE instruction does explicit stores. On average, there are 16 stores per program, out of which 2 stores are into the "L3" level. Each ISTORE instruction writes 8 bytes. + +The image below shows an example of the distribution of writes to the Scratchpad. Each pixel in the image represents 8 bytes of the Scratchpad. Red pixels represent portions of the Scratchpad that have been overwritten at least once during hash calculation. The "L1" and "L2" levels are on the left side (almost completely overwritten). The right side of the scratchpad represents the bottom 1792 KiB. Only about 66% of it are overwritten, but the writes are spread uniformly and randomly. + +![Imgur](https://i.imgur.com/pRz6aBG.png) + +See Appendix D for the analysis of Scratchpad entropy. + +#### 2.8.3 Read-write ratio + +Programs make, on average, 39 reads (instructions IADD_M, ISUB_M, IMUL_M, IMULH_M, ISMULH_M, IXOR_M, FADD_M, FSUB_M, FDIV_M) and 16 writes (instruction ISTORE) to the Scratchpad per program iteration. Additional 128 bytes are read and written implicitly to initialize and store register values. 64 bytes of data is read from the Dataset per iteration. In total: + +* The average amount of data read from memory per program iteration is: 39 * 8 + 128 + 64 = **504 bytes**. +* The average mount of data written to memory per program iteration is: 16 * 8 + 128 = **256 bytes**. + +This is close to a 2:1 read/write ratio, which CPUs are optimized for. + +### 2.9 Dataset + +Since the Scratchpad is usually stored in the CPU cache, only Dataset accesses utilize the memory controllers. + +RandomX randomly reads from the Dataset once per program iteration (16384 times per hash result). Since the Dataset must be stored in DRAM, it provides a natural parallelization limit, because DRAM cannot do more than about 25 million random accesses per second per bank group. Each separately addressable bank group allows a throughput of around 1500 H/s. + +All Dataset accesses read one CPU cache line (64 bytes) and are fully prefetched. The time to execute one program iteration described in chapter 4.6.2 of the Specification is about the same as typical DRAM access latency (50-100 ns). + +#### 2.9.1 Cache + +The Cache, which is used for light verification and Dataset construction, is about 8 times smaller than the Dataset. To keep a constant area-time product, each Dataset item is constructed from 8 random Cache accesses. + +Because 256 MiB is small enough to be included on-chip, RandomX uses a custom high-latency, high-power mixing function ("SuperscalarHash") which defeats the benefits of using low-latency memory and the energy required to calculate SuperscalarHash makes light mode very inefficient for mining (see chapter 3.4). + +Using less than 256 MiB of memory is not possible due to the use of tradeoff-resistant Argon2d with 3 iterations. When using 3 iterations (passes), halving the memory usage increases computational cost 3423 times for the best tradeoff attack [[27](https://eprint.iacr.org/2015/430.pdf)]. + +## 3. Custom functions + +### 3.1 AesGenerator1R + +AesGenerator1R was designed for the fastest possible generation of pseudorandom data to fill the Scratchpad. It takes advantage of hardware accelerated AES in modern CPUs. Only one AES round is performed per 16 bytes of output, which results in throughput exceeding 20 GB/s in most modern CPUs. + +AesGenerator1R gives a good output distribution provided that it's initialized with a sufficiently 'random' initial state (see Appendix F). + +### 3.2 AesGenerator4R + +AesGenerator4R uses 4 AES rounds to generate pseudorandom data for Program Buffer initialization. Since 2 AES rounds are sufficient for full avalanche of all input bits [[28](https://csrc.nist.gov/csrc/media/projects/cryptographic-standards-and-guidelines/documents/aes-development/rijndael-ammended.pdf)], AesGenerator4R has excellent statistical properties (see Appendix F) while maintaining very good performance. + +The reversible nature of this generator is not an issue since the generator state is always initialized using the output of a non-reversible hashing function (Blake2b). + +### 3.3 AesHash1R + +AesHash was designed for the fastest possible calculation of the Scratchpad fingerprint. It interprets the Scratchpad as a set of AES round keys, so it's equivalent to AES encryption with 32768 rounds. Two extra rounds are performed at the end to ensure avalanche of all Scratchpad bits in each lane. + +The reversible nature of AesHash1R is not a problem for two main reasons: + +* It is not possible to directly control the input of AesHash1R. +* The output of AesHash1R is passed into the Blake2b hashing function, which is not reversible. + +### 3.4 SuperscalarHash + +SuperscalarHash was designed to burn as much power as possible while the CPU is waiting for data to be loaded from DRAM. The target latency of 170 cycles corresponds to the usual DRAM latency of 40-80 ns and clock frequency of 2-4 GHz. ASIC devices designed for light-mode mining with low-latency memory will be bottlenecked by SuperscalarHash when calculating Dataset items and their efficiency will be destroyed by the high power usage of SuperscalarHash. + +The average SuperscalarHash function contains a total of 450 instructions, out of which 155 are 64-bit multiplications. On average, the longest dependency chain is 95 instructions long. An ASIC design for light-mode mining, with 256 MiB of on-die memory and 1-cycle latency for all operations, will need on average 95 * 8 = 760 cycles to construct a Dataset item, assuming unlimited parallelization. It will have to execute 155 * 8 = 1240 64-bit multiplications per item, which will consume energy comparable to loading 64 bytes from DRAM. + +## Appendix + +### A. The effect of chaining VM executions + +Chapter 1.2 describes why `N` random programs are chained to prevent mining strategies that search for 'easy' programs. RandomX uses a value of `N = 8`. + +Let's define `Q` as the ratio of acceptable programs in a strategy that uses filtering. For example `Q = 0.75` means that 25% of programs are rejected. + +For `N = 1`, there are no wasted program executions and the only cost is program generation and the filtering itself. The calculations below assume that these costs are zero and the only real cost is program execution. However, this is a simplification because program generation in RandomX is not free (the first program generation requires full Scratchpad initialization), but it describes a best-case scenario for an attacker. + + + For `N > 1`, the first program can be filtered as usual, but after the program is executed, there is a chance of `1-Q` that the next program should be rejected and we have wasted one program execution. + +For `N` chained executions, the chance is only QN that all programs in the chain are acceptable. However, during each attempt to find such chain, we will waste the execution of some programs. For `N = 8`, the number of wasted programs per attempt is equal to (1-Q)*(1+2\*Q+3\*Q2+4\*Q3+5\*Q4+6\*Q5+7\*Q6) (approximately 2.5 for `Q = 0.75`). + +Let's consider 3 mining strategies: + +#### Strategy I + +Honest miner that doesn't reject any programs (`Q = 1`). + +#### Strategy II + +Miner that uses optimized custom hardware that cannot execute 25% of programs (`Q = 0.75`), but supported programs can be executed 50% faster. + +#### Strategy III + +Miner that can execute all programs, but rejects 25% of the slowest programs for the first program in the chain. This gives a 5% performance boost for the first program in the chain (this matches the runtime distribution from Appendix C). + +#### Results + +The table below lists the results for the above 3 strategies and different values of `N`. The columns **N(I)**, **N(II)** and **N(III)** list the number of programs that each strategy has to execute on average to get one valid hash result (this includes programs wasted in rejected chains). Columns **Speed(I)**, **Speed(II)** and **Speed(III)** list the average mining performance relative to strategy I. + +|N|N(I)|N(II)|N(III)|Speed(I)|Speed(II)|Speed(III)| +|---|----|----|----|---------|---------|---------| +|1|1|1|1|1.00|1.50|1.05| +|2|2|2.3|2|1.00|1.28|1.02| +|4|4|6.5|4|1.00|0.92|1.01| +|8|8|27.0|8|1.00|0.44|1.00| + +For `N = 8`, strategy II will perform at less than half the speed of the honest miner despite having a 50% performance advantage for selected programs. The small statistical advantage of strategy III is negligible with `N = 8`. + +### B. Performance simulation + +As discussed in chapter 2.7, RandomX aims to take advantage of the complex design of modern high-performance CPUs. To evaluate the impact of superscalar, out-of-order and speculative execution, we performed a simplified CPU simulation. Source code is available in [perf-simulation.cpp](../src/tests/perf-simulation.cpp). + +#### CPU model + +The model CPU uses a 3-stage pipeline to achieve an ideal throughput of 1 instruction per cycle: +``` + (1) (2) (3) ++------------------+ +----------------+ +----------------+ +| Instruction | | | | | +| fetch | ---> | Memory access | ---> | Execute | +| + decode | | | | | ++------------------+ +----------------+ +----------------+ +``` +The 3 stages are: + +1. Instruction fetch and decode. This stage loads the instruction from the Program Buffer and decodes the instruction operation and operands. +2. Memory access. If this instruction uses a memory operand, it is loaded from the Scratchpad in this stage. This includes the calculation of the memory address. Stores are also performed in this stage. The value of the address register must be available in this stage. +3. Execute. This stage executes the instruction using the operands retrieved in the previous stages and writes the results into the register file. + +Note that this is an optimistically short pipeline that would not allow very high clock speeds. Designs using a longer pipeline would significantly increase the benefits of speculative execution. + +#### Superscalar execution + +Our model CPU contains two kinds of components: + +* Execution unit (EXU) - it is used to perform the actual integer or floating point operation. All RandomX instructions except ISTORE must use an execution unit in the 3rd pipeline stage. All operations are considered to take only 1 clock cycle. +* Memory unit (MEM) - it is used for loads and stores into Scratchpad. All memory instructions (including ISTORE) use a memory unit in the 2nd pipeline stage. + +A superscalar design will contain multiple execution or memory units to improve performance. + +#### Out-of-order execution + +The simulation model supports two designs: + +1. **In-order** - all instructions are executed in the order they appear in the Program Buffer. This design will stall if a dependency is encountered or the required EXU/MEM unit is not available. +2. **Out-of-order** - doesn't execute instructions in program order, but an instruction can be executed when its operands are ready and the required EXU/MEM units are available. + +#### Branch handling + +The simulation model supports two types of branch handling: + +1. **Non-speculative** - when a branch is encountered, the pipeline is stalled. This typically adds a 3-cycle penalty for each branch. +2. **Speculative** - all branches are predicted not taken and the pipeline is flushed if a misprediction occurs (probability of 1/256). + +#### Results + +The following 10 designs were simulated and the average number of clock cycles to execute a RandomX program (256 instructions) was measured. + +|design|superscalar config.|reordering|branch handling|execution time [cycles]|IPC| +|-------|-----------|----------|---------------|-----------------------|---| +|#1|1 EXU + 1 MEM|in-order|non-speculative|293|0.87| +|#2|1 EXU + 1 MEM|in-order|speculative|262|0.98| +|#3|2 EXU + 1 MEM|in-order|non-speculative|197|1.3| +|#4|2 EXU + 1 MEM|in-order|speculative|161|1.6| +|#5|2 EXU + 1 MEM|out-of-order|non-speculative|144|1.8| +|#6|2 EXU + 1 MEM|out-of-order|speculative|122|2.1| +|#7|4 EXU + 2 MEM|in-order|non-speculative|135|1.9| +|#8|4 EXU + 2 MEM|in-order|speculative|99|2.6| +|#9|4 EXU + 2 MEM|out-of-order|non-speculative|89|2.9| +|#10|4 EXU + 2 MEM|out-of-order|speculative|64|4.0| + +The benefits of superscalar, out-of-order and speculative designs are clearly demonstrated. + +### C. RandomX runtime distribution + +Runtime numbers were measured on AMD Ryzen 7 1700 running at 3.0 GHz using 1 core. Source code to measure program execution and verification times is available in [runtime-distr.cpp](../src/tests/runtime-distr.cpp). Source code to measure the performance of the x86 JIT compiler is available in [jit-performance.cpp](../src/tests/jit-performance.cpp). + +#### Fast mode - program execution + +The following figure shows the distribution of the runtimes of a single VM program (in fast mode). This includes: program generation, JIT compilation, VM execution and Blake2b hash of the register file. Program generation and JIT compilation was measured to take 3.6 μs per program. + +![Imgur](https://i.imgur.com/ikv2z2i.png) + +AMD Ryzen 7 1700 can calculate 625 hashes per second in fast mode (using 1 thread), which means a single hash result takes 1600 μs (1.6 ms). This consists of (approximately): + +* 1480 μs for VM execution (8 programs) +* 45 μs for initial Scratchpad fill (AesGenerator1R). +* 45 μs for final Scratchpad hash (AesHash1R). +* 30 μs for program generation and JIT compilation (8 programs) + +This gives a total overhead of 7.5% (time per hash spent not executing VM). + +#### Light mode - verification time + +The following figure shows the distribution of times to calculate 1 hash result using the light mode. Most of the time is spent executing SuperscalarHash to calculate Dataset items (13.2 ms out of 14.8 ms). The average verification time exactly matches the performance of the CryptoNight algorithm. + +![Imgur](https://i.imgur.com/VtwwJT8.png) + +### D. Scratchpad entropy analysis + +The average entropy of the Scratchpad after 8 program executions was approximated using the LZMA compression algorithm: + +1. Hash resuls were calculated and the final scratchpads were written to disk as files with '.spad' extension (source code: [scratchpad-entropy.cpp](../src/tests/scratchpad-entropy.cpp)) +2. The files were compressed using 7-Zip [[29](https://www.7-zip.org/)] in Ultra compression mode: `7z.exe a -t7z -m0=lzma2 -mx=9 scratchpads.7z *.spad` + +The size of the resulting archive is approximately 99.98% of the uncompressed size of the scratchpad files. This shows that the Scratchpad retains high entropy during VM execution. + +### E. SuperscalarHash analysis + +SuperscalarHash is a custom function used by RandomX to generate Dataset items. It operates on 8 integer registers and uses a random sequence of instructions. About 1/3 of the instructions are multiplications. + +The following figure shows the sensitivity of SuperscalarHash to changing a single bit of an input register: + +![Imgur](https://i.imgur.com/ztZ0V0G.png) + +This shows that SuperscalaHash has quite low sensitivity to high-order bits and somewhat decreased sensitivity to the lowest-order bits. Sensitivity is highest for bits 3-53 (inclusive). + +When calculating a Dataset item, the input of the first SuperscalarHash depends only on the item number. To ensure a good distribution of results, the constants described in section 7.3 of the Specification were chosen to provide unique values of bits 3-53 for *all* item numbers in the range 0-34078718 (the Dataset contains 34078719 items). All initial register values for all Dataset item numbers were checked to make sure bits 3-53 of each register are unique and there are no collisions (source code: [superscalar-init.cpp](../src/tests/superscalar-init.cpp)). While this is not strictly necessary to get unique output from SuperscalarHash, it's a security precaution that mitigates the non-perfect avalanche properties of the randomly generated SuperscalarHash instances. + +### F. Statistical tests of RNG + +Both AesGenerator1R and AesGenerator4R were tested using the TestU01 library [[30](http://simul.iro.umontreal.ca/testu01/tu01.html)] intended for empirical testing of random number generators. The source code is available in [rng-tests.cpp](../src/tests/rng-tests.cpp). + +The tests sample about 200 MB ("SmallCrush" test), 500 GB ("Crush" test) or 4 TB ("BigCrush" test) of output from each generator. This is considerably more than the amounts generated in RandomX (2176 bytes for AesGenerator4R and 2 MiB for AesGenerator1R), so failures in the tests don't necessarily imply that the generators are not suitable for their use case. + + +#### AesGenerator4R +The generator passes all tests in the "BigCrush" suite when initialized using the Blake2b hash function: + +``` +$ bin/rng-tests 1 +state0 = 67e8bbe567a1c18c91a316faf19fab73 +state1 = 39f7c0e0a8d96512c525852124fdc9fe +state2 = 7abb07b2c90e04f098261e323eee8159 +state3 = 3df534c34cdfbb4e70f8c0e1826f4cf7 + +... + +========= Summary results of BigCrush ========= + + Version: TestU01 1.2.3 + Generator: AesGenerator4R + Number of statistics: 160 + Total CPU time: 02:50:18.34 + + All tests were passed +``` + + +The generator passes all tests in the "Crush" suite even with an initial state set to all zeroes. +``` +$ bin/rng-tests 0 +state0 = 00000000000000000000000000000000 +state1 = 00000000000000000000000000000000 +state2 = 00000000000000000000000000000000 +state3 = 00000000000000000000000000000000 + +... + +========= Summary results of Crush ========= + + Version: TestU01 1.2.3 + Generator: AesGenerator4R + Number of statistics: 144 + Total CPU time: 00:25:17.95 + + All tests were passed +``` + +#### AesGenerator1R + +The generator passes all tests in the "Crush" suite when initialized using the Blake2b hash function. + +``` +$ bin/rng-tests 1 +state0 = 67e8bbe567a1c18c91a316faf19fab73 +state1 = 39f7c0e0a8d96512c525852124fdc9fe +state2 = 7abb07b2c90e04f098261e323eee8159 +state3 = 3df534c34cdfbb4e70f8c0e1826f4cf7 + +... + +========= Summary results of Crush ========= + + Version: TestU01 1.2.3 + Generator: AesGenerator1R + Number of statistics: 144 + Total CPU time: 00:25:06.07 + + All tests were passed + +``` + +When the initial state is initialized to all zeroes, the generator fails 1 test out of 144 tests in the "Crush" suite: + +``` +$ bin/rng-tests 0 +state0 = 00000000000000000000000000000000 +state1 = 00000000000000000000000000000000 +state2 = 00000000000000000000000000000000 +state3 = 00000000000000000000000000000000 + +... + +========= Summary results of Crush ========= + + Version: TestU01 1.2.3 + Generator: AesGenerator1R + Number of statistics: 144 + Total CPU time: 00:26:12.75 + The following tests gave p-values outside [0.001, 0.9990]: + (eps means a value < 1.0e-300): + (eps1 means a value < 1.0e-15): + + Test p-value + ---------------------------------------------- + 12 BirthdaySpacings, t = 3 1 - 4.4e-5 + ---------------------------------------------- + All other tests were passed + +``` + +## References + +[1] CryptoNote whitepaper - https://cryptonote.org/whitepaper.pdf + +[2] ProgPoW: Inefficient integer multiplications - https://github.com/ifdefelse/ProgPOW/issues/16 + +[3] Cryptographic Hashing function - https://en.wikipedia.org/wiki/Cryptographic_hash_function + +[4] randprog - https://github.com/hyc/randprog + +[5] RandomJS - https://github.com/tevador/RandomJS + +[6] μop cache - https://en.wikipedia.org/wiki/CPU_cache#Micro-operation_(%CE%BCop_or_uop)_cache + +[7] Instruction-level parallelism - https://en.wikipedia.org/wiki/Instruction-level_parallelism + +[8] Superscalar processor - https://en.wikipedia.org/wiki/Superscalar_processor + +[9] Out-of-order execution - https://en.wikipedia.org/wiki/Out-of-order_execution + +[10] Speculative execution - https://en.wikipedia.org/wiki/Speculative_execution + +[11] Register renaming - https://en.wikipedia.org/wiki/Register_renaming + +[12] Blake2 hashing function - https://blake2.net/ + +[13] Advanced Encryption Standard - https://en.wikipedia.org/wiki/Advanced_Encryption_Standard + +[14] Log-normal distribution - https://en.wikipedia.org/wiki/Log-normal_distribution + +[15] CryptoNight hash function - https://cryptonote.org/cns/cns008.txt + +[16] Dynamic random-access memory - https://en.wikipedia.org/wiki/Dynamic_random-access_memory + +[17] Multi-channel memory architecture - https://en.wikipedia.org/wiki/Multi-channel_memory_architecture + +[18] Obelisk GRN1 chip details - https://www.grin-forum.org/t/obelisk-grn1-chip-details/4571 + +[19] Biryukov et al.: Tradeoff Cryptanalysis of Memory-Hard Functions - https://eprint.iacr.org/2015/227.pdf + +[20] SK Hynix 20nm DRAM density - http://en.thelec.kr/news/articleView.html?idxno=20 + +[21] Branch predictor - https://en.wikipedia.org/wiki/Branch_predictor + +[22] Predication - https://en.wikipedia.org/wiki/Predication_(computer_architecture) + +[23] CPU cache - https://en.wikipedia.org/wiki/CPU_cache + +[24] Cortex-A55 Microarchitecture - https://www.anandtech.com/show/11441/dynamiq-and-arms-new-cpus-cortex-a75-a55/4 + +[25] AMD Zen+ Microarchitecture - https://en.wikichip.org/wiki/amd/microarchitectures/zen%2B#Memory_Hierarchy + +[26] Intel Skylake Microarchitecture - https://en.wikichip.org/wiki/intel/microarchitectures/skylake_(client)#Memory_Hierarchy + +[27] Biryukov et al.: Fast and Tradeoff-Resilient Memory-Hard Functions for +Cryptocurrencies and Password Hashing - https://eprint.iacr.org/2015/430.pdf Table 2, page 8 + +[28] J. Daemen, V. Rijmen: AES Proposal: Rijndael - https://csrc.nist.gov/csrc/media/projects/cryptographic-standards-and-guidelines/documents/aes-development/rijndael-ammended.pdf page 28 + +[29] 7-Zip File archiver - https://www.7-zip.org/ + +[30] TestU01 library - http://simul.iro.umontreal.ca/testu01/tu01.html diff --git a/src/RandomX/doc/program.asm b/src/RandomX/doc/program.asm new file mode 100644 index 000000000..93c32f8a0 --- /dev/null +++ b/src/RandomX/doc/program.asm @@ -0,0 +1,985 @@ +randomx_isn_0: + ; ISMULH_R r0, r3 + mov rax, r8 + imul r11 + mov r8, rdx +randomx_isn_1: + ; IROR_R r0, r6 + mov ecx, r14d + ror r8, cl +randomx_isn_2: + ; FADD_R f1, a2 + addpd xmm1, xmm10 +randomx_isn_3: + ; IXOR_M r1, L1[r5+1954652011] + lea eax, [r13d+1954652011] + and eax, 16376 + xor r9, qword ptr [rsi+rax] +randomx_isn_4: + ; FMUL_R e2, a3 + mulpd xmm6, xmm11 +randomx_isn_5: + ; FADD_M f0, L2[r0-772804104] + lea eax, [r8d-772804104] + and eax, 262136 + cvtdq2pd xmm12, qword ptr [rsi+rax] + addpd xmm0, xmm12 +randomx_isn_6: + ; IMUL_R r6, r4 + imul r14, r12 +randomx_isn_7: + ; CBRANCH r5, 1674196118, COND 2 + add r13, 1674196118 + test r13, 261120 + jz randomx_isn_0 +randomx_isn_8: + ; ISWAP_R r7, r6 + xchg r15, r14 +randomx_isn_9: + ; ISTORE L1[r1-439821682], r3 + lea eax, [r9d-439821682] + and eax, 16376 + mov qword ptr [rsi+rax], r11 +randomx_isn_10: + ; IXOR_R r2, r4 + xor r10, r12 +randomx_isn_11: + ; FADD_R f2, a1 + addpd xmm2, xmm9 +randomx_isn_12: + ; IXOR_M r0, L1[r1+952699079] + lea eax, [r9d+952699079] + and eax, 16376 + xor r8, qword ptr [rsi+rax] +randomx_isn_13: + ; ISMULH_R r5, r2 + mov rax, r13 + imul r10 + mov r13, rdx +randomx_isn_14: + ; INEG_R r4 + neg r12 +randomx_isn_15: + ; INEG_R r1 + neg r9 +randomx_isn_16: + ; IMUL_M r3, L1[r2+620091535] + lea eax, [r10d+620091535] + and eax, 16376 + imul r11, qword ptr [rsi+rax] +randomx_isn_17: + ; FADD_R f1, a0 + addpd xmm1, xmm8 +randomx_isn_18: + ; IMUL_RCP r5, 2611385784 + mov rax, 15169754503470242065 + imul r13, rax +randomx_isn_19: + ; IXOR_R r2, 922368940 + xor r10, 922368940 +randomx_isn_20: + ; FADD_R f3, a1 + addpd xmm3, xmm9 +randomx_isn_21: + ; IXOR_R r3, r6 + xor r11, r14 +randomx_isn_22: + ; FSWAP_R e1 + shufpd xmm5, xmm5, 1 +randomx_isn_23: + ; ISUB_R r0, r5 + sub r8, r13 +randomx_isn_24: + ; ISTORE L1[r6-1574415460], r7 + lea eax, [r14d-1574415460] + and eax, 16376 + mov qword ptr [rsi+rax], r15 +randomx_isn_25: + ; FADD_M f3, L1[r3+1766115210] + lea eax, [r11d+1766115210] + and eax, 16376 + cvtdq2pd xmm12, qword ptr [rsi+rax] + addpd xmm3, xmm12 +randomx_isn_26: + ; FSCAL_R f1 + xorps xmm1, xmm15 +randomx_isn_27: + ; CBRANCH r2, 1731738265, COND 6 + add r10, 1731746457 + test r10, 4177920 + jz randomx_isn_20 +randomx_isn_28: + ; IXOR_R r4, r1 + xor r12, r9 +randomx_isn_29: + ; CBRANCH r4, 1937048537, COND 3 + add r12, 1937050585 + test r12, 522240 + jz randomx_isn_29 +randomx_isn_30: + ; ISWAP_R r3, r5 + xchg r11, r13 +randomx_isn_31: + ; ISMULH_R r7, r5 + mov rax, r15 + imul r13 + mov r15, rdx +randomx_isn_32: + ; IMULH_M r6, L1[r2+1879111790] + lea ecx, [r10d+1879111790] + and ecx, 16376 + mov rax, r14 + mul qword ptr [rsi+rcx] + mov r14, rdx +randomx_isn_33: + ; IMUL_R r5, r0 + imul r13, r8 +randomx_isn_34: + ; ISWAP_R r5, r0 + xchg r13, r8 +randomx_isn_35: + ; CBRANCH r4, 1174490916, COND 5 + add r12, 1174499108 + test r12, 2088960 + jz randomx_isn_30 +randomx_isn_36: + ; CBRANCH r6, -1852457840, COND 8 + add r14, -1852490608 + test r14, 16711680 + jz randomx_isn_36 +randomx_isn_37: + ; ISMULH_R r2, r0 + mov rax, r10 + imul r8 + mov r10, rdx +randomx_isn_38: + ; ISUB_R r2, r0 + sub r10, r8 +randomx_isn_39: + ; ISTORE L1[r0-38118463], r5 + lea eax, [r8d-38118463] + and eax, 16376 + mov qword ptr [rsi+rax], r13 +randomx_isn_40: + ; IXOR_R r0, r1 + xor r8, r9 +randomx_isn_41: + ; IMUL_R r6, r4 + imul r14, r12 +randomx_isn_42: + ; ISUB_R r7, r5 + sub r15, r13 +randomx_isn_43: + ; FDIV_M e0, L1[r2+1052956160] + lea eax, [r10d+1052956160] + and eax, 16376 + cvtdq2pd xmm12, qword ptr [rsi+rax] + andps xmm12, xmm13 + orps xmm12, xmm14 + divpd xmm4, xmm12 +randomx_isn_44: + ; CBRANCH r1, 1870241002, COND 11 + add r9, 1870241002 + test r9, 133693440 + jz randomx_isn_37 +randomx_isn_45: + ; IXOR_R r1, r4 + xor r9, r12 +randomx_isn_46: + ; FMUL_R e3, a1 + mulpd xmm7, xmm9 +randomx_isn_47: + ; IXOR_M r0, L1[r2+839895331] + lea eax, [r10d+839895331] + and eax, 16376 + xor r8, qword ptr [rsi+rax] +randomx_isn_48: + ; CBRANCH r2, -2128896196, COND 6 + add r10, -2128879812 + test r10, 4177920 + jz randomx_isn_45 +randomx_isn_49: + ; CFROUND r1, 13 + mov rax, r9 + and eax, 24576 + or eax, 40896 + push rax + ldmxcsr dword ptr [rsp] + pop rax +randomx_isn_50: + ; ISWAP_R r3, r1 + xchg r11, r9 +randomx_isn_51: + ; IMUL_RCP r1, 4205062916 + mov rax, 9420568026795290117 + imul r9, rax +randomx_isn_52: + ; FSUB_R f0, a0 + subpd xmm0, xmm8 +randomx_isn_53: + ; IMUL_R r7, r6 + imul r15, r14 +randomx_isn_54: + ; IADD_RS r1, r2, SHFT 3 + lea r9, [r9+r10*8] +randomx_isn_55: + ; FSQRT_R e3 + sqrtpd xmm7, xmm7 +randomx_isn_56: + ; FMUL_R e1, a0 + mulpd xmm5, xmm8 +randomx_isn_57: + ; IMUL_RCP r3, 303101651 + mov rax, 16336962008634921950 + imul r11, rax +randomx_isn_58: + ; IMUL_RCP r1, 3375482677 + mov rax, 11735827153567160432 + imul r9, rax +randomx_isn_59: + ; CBRANCH r6, 2116776661, COND 12 + add r14, 2117300949 + test r14, 267386880 + jz randomx_isn_49 +randomx_isn_60: + ; IMUL_R r3, r4 + imul r11, r12 +randomx_isn_61: + ; FMUL_R e3, a0 + mulpd xmm7, xmm8 +randomx_isn_62: + ; ISUB_R r3, 1514378938 + sub r11, 1514378938 +randomx_isn_63: + ; FMUL_R e2, a0 + mulpd xmm6, xmm8 +randomx_isn_64: + ; ISUB_R r4, r6 + sub r12, r14 +randomx_isn_65: + ; FDIV_M e2, L1[r0+1496571595] + lea eax, [r8d+1496571595] + and eax, 16376 + cvtdq2pd xmm12, qword ptr [rsi+rax] + andps xmm12, xmm13 + orps xmm12, xmm14 + divpd xmm6, xmm12 +randomx_isn_66: + ; FSUB_R f0, a2 + subpd xmm0, xmm10 +randomx_isn_67: + ; FDIV_M e3, L2[r7-2139079025] + lea eax, [r15d-2139079025] + and eax, 262136 + cvtdq2pd xmm12, qword ptr [rsi+rax] + andps xmm12, xmm13 + orps xmm12, xmm14 + divpd xmm7, xmm12 +randomx_isn_68: + ; FSUB_R f2, a2 + subpd xmm2, xmm10 +randomx_isn_69: + ; CBRANCH r3, -1165095866, COND 7 + add r11, -1165063098 + test r11, 8355840 + jz randomx_isn_63 +randomx_isn_70: + ; IMULH_R r0, r7 + mov rax, r8 + mul r15 + mov r8, rdx +randomx_isn_71: + ; FMUL_R e2, a0 + mulpd xmm6, xmm8 +randomx_isn_72: + ; FMUL_R e0, a3 + mulpd xmm4, xmm11 +randomx_isn_73: + ; IMUL_RCP r6, 1636610180 + mov rax, 12102479179596746977 + imul r14, rax +randomx_isn_74: + ; FMUL_R e2, a2 + mulpd xmm6, xmm10 +randomx_isn_75: + ; ISTORE L2[r2+473418592], r3 + lea eax, [r10d+473418592] + and eax, 262136 + mov qword ptr [rsi+rax], r11 +randomx_isn_76: + ; IADD_M r1, L1[r3-989917936] + lea eax, [r11d-989917936] + and eax, 16376 + add r9, qword ptr [rsi+rax] +randomx_isn_77: + ; CBRANCH r2, 1519854177, COND 7 + add r10, 1519886945 + test r10, 8355840 + jz randomx_isn_70 +randomx_isn_78: + ; IMUL_R r2, r6 + imul r10, r14 +randomx_isn_79: + ; IMUL_R r4, r1 + imul r12, r9 +randomx_isn_80: + ; FMUL_R e2, a1 + mulpd xmm6, xmm9 +randomx_isn_81: + ; FSCAL_R f2 + xorps xmm2, xmm15 +randomx_isn_82: + ; IXOR_M r2, L1[r1+192323103] + lea eax, [r9d+192323103] + and eax, 16376 + xor r10, qword ptr [rsi+rax] +randomx_isn_83: + ; IMUL_R r7, r4 + imul r15, r12 +randomx_isn_84: + ; FADD_R f2, a0 + addpd xmm2, xmm8 +randomx_isn_85: + ; FSUB_M f1, L2[r6-1549504487] + lea eax, [r14d-1549504487] + and eax, 262136 + cvtdq2pd xmm12, qword ptr [rsi+rax] + subpd xmm1, xmm12 +randomx_isn_86: + ; FSUB_R f0, a3 + subpd xmm0, xmm11 +randomx_isn_87: + ; CFROUND r3, 31 + mov rax, r11 + rol rax, 46 + and eax, 24576 + or eax, 40896 + push rax + ldmxcsr dword ptr [rsp] + pop rax +randomx_isn_88: + ; IXOR_R r5, r6 + xor r13, r14 +randomx_isn_89: + ; FADD_R f3, a2 + addpd xmm3, xmm10 +randomx_isn_90: + ; FADD_R f3, a0 + addpd xmm3, xmm8 +randomx_isn_91: + ; FSQRT_R e1 + sqrtpd xmm5, xmm5 +randomx_isn_92: + ; ISUB_R r6, r2 + sub r14, r10 +randomx_isn_93: + ; ISUB_R r0, r4 + sub r8, r12 +randomx_isn_94: + ; FADD_R f1, a2 + addpd xmm1, xmm10 +randomx_isn_95: + ; IMUL_R r1, r2 + imul r9, r10 +randomx_isn_96: + ; FSCAL_R f1 + xorps xmm1, xmm15 +randomx_isn_97: + ; ISTORE L1[r7-1901001017], r7 + lea eax, [r15d-1901001017] + and eax, 16376 + mov qword ptr [rsi+rax], r15 +randomx_isn_98: + ; FADD_R f1, a3 + addpd xmm1, xmm11 +randomx_isn_99: + ; CBRANCH r2, -425599201, COND 9 + add r10, -425533665 + test r10, 33423360 + jz randomx_isn_83 +randomx_isn_100: + ; IXOR_R r4, r6 + xor r12, r14 +randomx_isn_101: + ; FMUL_R e0, a3 + mulpd xmm4, xmm11 +randomx_isn_102: + ; FADD_M f0, L1[r0+1590646897] + lea eax, [r8d+1590646897] + and eax, 16376 + cvtdq2pd xmm12, qword ptr [rsi+rax] + addpd xmm0, xmm12 +randomx_isn_103: + ; FMUL_R e0, a1 + mulpd xmm4, xmm9 +randomx_isn_104: + ; IMUL_R r4, r7 + imul r12, r15 +randomx_isn_105: + ; ISUB_R r1, r0 + sub r9, r8 +randomx_isn_106: + ; FSUB_R f1, a2 + subpd xmm1, xmm10 +randomx_isn_107: + ; FMUL_R e1, a1 + mulpd xmm5, xmm9 +randomx_isn_108: + ; FMUL_R e1, a2 + mulpd xmm5, xmm10 +randomx_isn_109: + ; FADD_R f3, a2 + addpd xmm3, xmm10 +randomx_isn_110: + ; IXOR_R r0, r3 + xor r8, r11 +randomx_isn_111: + ; IMUL_R r0, 1421329412 + imul r8, 1421329412 +randomx_isn_112: + ; FSUB_R f0, a2 + subpd xmm0, xmm10 +randomx_isn_113: + ; IMUL_R r5, r4 + imul r13, r12 +randomx_isn_114: + ; IADD_RS r7, r3, SHFT 2 + lea r15, [r15+r11*4] +randomx_isn_115: + ; FADD_R f3, a3 + addpd xmm3, xmm11 +randomx_isn_116: + ; ISTORE L1[r3-160363922], r0 + lea eax, [r11d-160363922] + and eax, 16376 + mov qword ptr [rsi+rax], r8 +randomx_isn_117: + ; IMULH_R r0, r6 + mov rax, r8 + mul r14 + mov r8, rdx +randomx_isn_118: + ; FSWAP_R f2 + shufpd xmm2, xmm2, 1 +randomx_isn_119: + ; FMUL_R e1, a0 + mulpd xmm5, xmm8 +randomx_isn_120: + ; IROR_R r0, 12 + ror r8, 12 +randomx_isn_121: + ; FADD_M f0, L1[r0+282806289] + lea eax, [r8d+282806289] + and eax, 16376 + cvtdq2pd xmm12, qword ptr [rsi+rax] + addpd xmm0, xmm12 +randomx_isn_122: + ; FADD_M f3, L1[r7+1601529113] + lea eax, [r15d+1601529113] + and eax, 16376 + cvtdq2pd xmm12, qword ptr [rsi+rax] + addpd xmm3, xmm12 +randomx_isn_123: + ; IMUL_RCP r2, 2522040806 + mov rax, 15707153176462985744 + imul r10, rax +randomx_isn_124: + ; ISUB_M r0, L1[r3+974906597] + lea eax, [r11d+974906597] + and eax, 16376 + sub r8, qword ptr [rsi+rax] +randomx_isn_125: + ; CBRANCH r2, 1508706439, COND 14 + add r10, 1506609287 + test r10, 1069547520 + jz randomx_isn_124 +randomx_isn_126: + ; IXOR_R r4, r5 + xor r12, r13 +randomx_isn_127: + ; IMUL_R r7, r2 + imul r15, r10 +randomx_isn_128: + ; IROR_R r4, r0 + mov ecx, r8d + ror r12, cl +randomx_isn_129: + ; CBRANCH r0, -497803311, COND 3 + add r8, -497804335 + test r8, 522240 + jz randomx_isn_126 +randomx_isn_130: + ; FSUB_M f0, L1[r3+1789853646] + lea eax, [r11d+1789853646] + and eax, 16376 + cvtdq2pd xmm12, qword ptr [rsi+rax] + subpd xmm0, xmm12 +randomx_isn_131: + ; ISMULH_R r6, r3 + mov rax, r14 + imul r11 + mov r14, rdx +randomx_isn_132: + ; FMUL_R e0, a3 + mulpd xmm4, xmm11 +randomx_isn_133: + ; FSUB_R f2, a1 + subpd xmm2, xmm9 +randomx_isn_134: + ; CBRANCH r3, -1567551204, COND 11 + add r11, -1567026916 + test r11, 133693440 + jz randomx_isn_130 +randomx_isn_135: + ; FSUB_M f2, L2[r5+1167508659] + lea eax, [r13d+1167508659] + and eax, 262136 + cvtdq2pd xmm12, qword ptr [rsi+rax] + subpd xmm2, xmm12 +randomx_isn_136: + ; IMUL_R r4, r0 + imul r12, r8 +randomx_isn_137: + ; IMULH_R r7, r6 + mov rax, r15 + mul r14 + mov r15, rdx +randomx_isn_138: + ; FMUL_R e3, a2 + mulpd xmm7, xmm10 +randomx_isn_139: + ; IMUL_R r2, r6 + imul r10, r14 +randomx_isn_140: + ; ISTORE L1[r0+1277653290], r3 + lea eax, [r8d+1277653290] + and eax, 16376 + mov qword ptr [rsi+rax], r11 +randomx_isn_141: + ; IXOR_M r0, L1[r6-2131931958] + lea eax, [r14d-2131931958] + and eax, 16376 + xor r8, qword ptr [rsi+rax] +randomx_isn_142: + ; FSUB_R f3, a3 + subpd xmm3, xmm11 +randomx_isn_143: + ; IROL_R r6, r1 + mov ecx, r9d + rol r14, cl +randomx_isn_144: + ; FADD_R f1, a3 + addpd xmm1, xmm11 +randomx_isn_145: + ; FMUL_R e0, a3 + mulpd xmm4, xmm11 +randomx_isn_146: + ; FSQRT_R e0 + sqrtpd xmm4, xmm4 +randomx_isn_147: + ; IADD_RS r7, r4, SHFT 0 + lea r15, [r15+r12*1] +randomx_isn_148: + ; FSUB_R f3, a1 + subpd xmm3, xmm9 +randomx_isn_149: + ; ISTORE L2[r1-1073333533], r3 + lea eax, [r9d-1073333533] + and eax, 262136 + mov qword ptr [rsi+rax], r11 +randomx_isn_150: + ; FMUL_R e3, a3 + mulpd xmm7, xmm11 +randomx_isn_151: + ; ISUB_R r6, r3 + sub r14, r11 +randomx_isn_152: + ; IMULH_M r7, L2[r1+1647843648] + lea ecx, [r9d+1647843648] + and ecx, 262136 + mov rax, r15 + mul qword ptr [rsi+rcx] + mov r15, rdx +randomx_isn_153: + ; FMUL_R e0, a0 + mulpd xmm4, xmm8 +randomx_isn_154: + ; IROR_R r3, r0 + mov ecx, r8d + ror r11, cl +randomx_isn_155: + ; IADD_M r3, L1[r7-1322060518] + lea eax, [r15d-1322060518] + and eax, 16376 + add r11, qword ptr [rsi+rax] +randomx_isn_156: + ; CBRANCH r3, 608981196, COND 1 + add r11, 608981708 + test r11, 130560 + jz randomx_isn_156 +randomx_isn_157: + ; FSUB_M f0, L2[r7-252644586] + lea eax, [r15d-252644586] + and eax, 262136 + cvtdq2pd xmm12, qword ptr [rsi+rax] + subpd xmm0, xmm12 +randomx_isn_158: + ; CBRANCH r2, 868397474, COND 15 + add r10, 864203170 + test r10, 2139095040 + jz randomx_isn_157 +randomx_isn_159: + ; ISUB_R r5, r3 + sub r13, r11 +randomx_isn_160: + ; FMUL_R e0, a0 + mulpd xmm4, xmm8 +randomx_isn_161: + ; FMUL_R e2, a1 + mulpd xmm6, xmm9 +randomx_isn_162: + ; CBRANCH r0, 887338591, COND 6 + add r8, 887346783 + test r8, 4177920 + jz randomx_isn_159 +randomx_isn_163: + ; IADD_RS r3, r3, SHFT 3 + lea r11, [r11+r11*8] +randomx_isn_164: + ; IMUL_RCP r7, 3593878304 + mov rax, 11022655166993703745 + imul r15, rax +randomx_isn_165: + ; CBRANCH r0, 1452880957, COND 13 + add r8, 1453929533 + test r8, 534773760 + jz randomx_isn_163 +randomx_isn_166: + ; ISUB_M r6, L2[r3+1539038396] + lea eax, [r11d+1539038396] + and eax, 262136 + sub r14, qword ptr [rsi+rax] +randomx_isn_167: + ; IMUL_RCP r3, 1202036339 + mov rax, 16477905023274079568 + imul r11, rax +randomx_isn_168: + ; CBRANCH r1, -1295757940, COND 13 + add r9, -1293660788 + test r9, 534773760 + jz randomx_isn_166 +randomx_isn_169: + ; FADD_M f2, L1[r2+876697387] + lea eax, [r10d+876697387] + and eax, 16376 + cvtdq2pd xmm12, qword ptr [rsi+rax] + addpd xmm2, xmm12 +randomx_isn_170: + ; IMUL_R r0, r6 + imul r8, r14 +randomx_isn_171: + ; FMUL_R e1, a3 + mulpd xmm5, xmm11 +randomx_isn_172: + ; FMUL_R e0, a2 + mulpd xmm4, xmm10 +randomx_isn_173: + ; FSUB_M f3, L1[r2-1083472792] + lea eax, [r10d-1083472792] + and eax, 16376 + cvtdq2pd xmm12, qword ptr [rsi+rax] + subpd xmm3, xmm12 +randomx_isn_174: + ; CBRANCH r1, -1476890738, COND 14 + add r9, -1478987890 + test r9, 1069547520 + jz randomx_isn_169 +randomx_isn_175: + ; ISUB_R r4, r7 + sub r12, r15 +randomx_isn_176: + ; ISUB_R r0, 1685118604 + sub r8, 1685118604 +randomx_isn_177: + ; FMUL_R e0, a1 + mulpd xmm4, xmm9 +randomx_isn_178: + ; ISUB_M r0, L1[r7-1897974312] + lea eax, [r15d-1897974312] + and eax, 16376 + sub r8, qword ptr [rsi+rax] +randomx_isn_179: + ; IXOR_R r4, r0 + xor r12, r8 +randomx_isn_180: + ; IXOR_R r7, r2 + xor r15, r10 +randomx_isn_181: + ; FSCAL_R f1 + xorps xmm1, xmm15 +randomx_isn_182: + ; ISWAP_R r6, r2 + xchg r14, r10 +randomx_isn_183: + ; IADD_RS r3, r1, SHFT 3 + lea r11, [r11+r9*8] +randomx_isn_184: + ; ISTORE L1[r6-1997634426], r7 + lea eax, [r14d-1997634426] + and eax, 16376 + mov qword ptr [rsi+rax], r15 +randomx_isn_185: + ; IXOR_R r2, r7 + xor r10, r15 +randomx_isn_186: + ; IMUL_R r4, r3 + imul r12, r11 +randomx_isn_187: + ; IMUL_RCP r7, 1830833174 + mov rax, 10818593911149047378 + imul r15, rax +randomx_isn_188: + ; FMUL_R e0, a2 + mulpd xmm4, xmm10 +randomx_isn_189: + ; FADD_R f1, a3 + addpd xmm1, xmm11 +randomx_isn_190: + ; CBRANCH r7, 121030040, COND 15 + add r15, 129418648 + test r15, 2139095040 + jz randomx_isn_188 +randomx_isn_191: + ; IADD_RS r6, r1, SHFT 0 + lea r14, [r14+r9*1] +randomx_isn_192: + ; FSUB_R f3, a2 + subpd xmm3, xmm10 +randomx_isn_193: + ; CBRANCH r5, 1139434462, COND 11 + add r13, 1139434462 + test r13, 133693440 + jz randomx_isn_191 +randomx_isn_194: + ; FMUL_R e2, a0 + mulpd xmm6, xmm8 +randomx_isn_195: + ; FMUL_R e2, a3 + mulpd xmm6, xmm11 +randomx_isn_196: + ; CBRANCH r4, 429294077, COND 2 + add r12, 429295101 + test r12, 261120 + jz randomx_isn_194 +randomx_isn_197: + ; IMUL_R r1, r2 + imul r9, r10 +randomx_isn_198: + ; FMUL_R e3, a0 + mulpd xmm7, xmm8 +randomx_isn_199: + ; IMUL_R r2, r3 + imul r10, r11 +randomx_isn_200: + ; IMUL_RCP r1, 193535702 + mov rax, 12792885514067893012 + imul r9, rax +randomx_isn_201: + ; IMUL_R r0, r5 + imul r8, r13 +randomx_isn_202: + ; ISUB_R r1, r2 + sub r9, r10 +randomx_isn_203: + ; FSUB_R f0, a3 + subpd xmm0, xmm11 +randomx_isn_204: + ; FSQRT_R e3 + sqrtpd xmm7, xmm7 +randomx_isn_205: + ; FMUL_R e0, a3 + mulpd xmm4, xmm11 +randomx_isn_206: + ; IMUL_R r2, r1 + imul r10, r9 +randomx_isn_207: + ; IADD_RS r1, r1, SHFT 3 + lea r9, [r9+r9*8] +randomx_isn_208: + ; ISUB_R r6, r4 + sub r14, r12 +randomx_isn_209: + ; ISUB_R r0, r7 + sub r8, r15 +randomx_isn_210: + ; IADD_M r6, L1[r1+313140284] + lea eax, [r9d+313140284] + and eax, 16376 + add r14, qword ptr [rsi+rax] +randomx_isn_211: + ; CBRANCH r4, 1358359929, COND 11 + add r12, 1358622073 + test r12, 133693440 + jz randomx_isn_197 +randomx_isn_212: + ; FSQRT_R e0 + sqrtpd xmm4, xmm4 +randomx_isn_213: + ; ISTORE L1[r3+18641493], r5 + lea eax, [r11d+18641493] + and eax, 16376 + mov qword ptr [rsi+rax], r13 +randomx_isn_214: + ; CBRANCH r2, 1232471888, COND 7 + add r10, 1232504656 + test r10, 8355840 + jz randomx_isn_212 +randomx_isn_215: + ; IADD_M r1, L1[r3+1138069575] + lea eax, [r11d+1138069575] + and eax, 16376 + add r9, qword ptr [rsi+rax] +randomx_isn_216: + ; FSQRT_R e0 + sqrtpd xmm4, xmm4 +randomx_isn_217: + ; IMUL_R r3, r4 + imul r11, r12 +randomx_isn_218: + ; FMUL_R e3, a3 + mulpd xmm7, xmm11 +randomx_isn_219: + ; IROL_R r7, r1 + mov ecx, r9d + rol r15, cl +randomx_isn_220: + ; FMUL_R e2, a1 + mulpd xmm6, xmm9 +randomx_isn_221: + ; IXOR_M r2, L3[697832] + xor r10, qword ptr [rsi+697832] +randomx_isn_222: + ; IADD_RS r1, r6, SHFT 2 + lea r9, [r9+r14*4] +randomx_isn_223: + ; ISWAP_R r6, r2 + xchg r14, r10 +randomx_isn_224: + ; ISUB_R r0, r1 + sub r8, r9 +randomx_isn_225: + ; FSQRT_R e3 + sqrtpd xmm7, xmm7 +randomx_isn_226: + ; ISUB_R r5, r1 + sub r13, r9 +randomx_isn_227: + ; ISTORE L1[r0+238217802], r2 + lea eax, [r8d+238217802] + and eax, 16376 + mov qword ptr [rsi+rax], r10 +randomx_isn_228: + ; IMUL_RCP r5, 324261767 + mov rax, 15270872674734795667 + imul r13, rax +randomx_isn_229: + ; FSCAL_R f0 + xorps xmm0, xmm15 +randomx_isn_230: + ; FSQRT_R e3 + sqrtpd xmm7, xmm7 +randomx_isn_231: + ; IROL_R r1, r5 + mov ecx, r13d + rol r9, cl +randomx_isn_232: + ; ISUB_R r6, r1 + sub r14, r9 +randomx_isn_233: + ; FADD_R f2, a0 + addpd xmm2, xmm8 +randomx_isn_234: + ; FADD_R f1, a3 + addpd xmm1, xmm11 +randomx_isn_235: + ; IXOR_R r3, 1240450588 + xor r11, 1240450588 +randomx_isn_236: + ; FSUB_R f1, a2 + subpd xmm1, xmm10 +randomx_isn_237: + ; IMULH_R r6, r3 + mov rax, r14 + mul r11 + mov r14, rdx +randomx_isn_238: + ; FSUB_R f1, a3 + subpd xmm1, xmm11 +randomx_isn_239: + ; FSUB_R f1, a2 + subpd xmm1, xmm10 +randomx_isn_240: + ; FSUB_M f1, L1[r7+1330184615] + lea eax, [r15d+1330184615] + and eax, 16376 + cvtdq2pd xmm12, qword ptr [rsi+rax] + subpd xmm1, xmm12 +randomx_isn_241: + ; FMUL_R e2, a3 + mulpd xmm6, xmm11 +randomx_isn_242: + ; CBRANCH r3, -427325404, COND 11 + add r11, -427063260 + test r11, 133693440 + jz randomx_isn_236 +randomx_isn_243: + ; IMUL_R r5, r7 + imul r13, r15 +randomx_isn_244: + ; FMUL_R e3, a3 + mulpd xmm7, xmm11 +randomx_isn_245: + ; ISMULH_M r7, L1[r0-84959236] + lea ecx, [r8d-84959236] + and ecx, 16376 + mov rax, r15 + imul qword ptr [rsi+rcx] + mov r15, rdx +randomx_isn_246: + ; IMUL_R r6, r1 + imul r14, r9 +randomx_isn_247: + ; FMUL_R e2, a1 + mulpd xmm6, xmm9 +randomx_isn_248: + ; IADD_M r1, L2[r3+1223504721] + lea eax, [r11d+1223504721] + and eax, 262136 + add r9, qword ptr [rsi+rax] +randomx_isn_249: + ; FADD_R f1, a2 + addpd xmm1, xmm10 +randomx_isn_250: + ; IXOR_M r4, L1[r2-1447740505] + lea eax, [r10d-1447740505] + and eax, 16376 + xor r12, qword ptr [rsi+rax] +randomx_isn_251: + ; IXOR_R r0, r5 + xor r8, r13 +randomx_isn_252: + ; CBRANCH r4, -1337905977, COND 4 + add r12, -1337903929 + test r12, 1044480 + jz randomx_isn_251 +randomx_isn_253: + ; FSUB_R f1, a1 + subpd xmm1, xmm9 +randomx_isn_254: + ; FMUL_R e0, a0 + mulpd xmm4, xmm8 +randomx_isn_255: + ; CBRANCH r5, 437071043, COND 11 + add r13, 436808899 + test r13, 133693440 + jz randomx_isn_253 diff --git a/src/RandomX/doc/specs.md b/src/RandomX/doc/specs.md new file mode 100644 index 000000000..f2ab8b24b --- /dev/null +++ b/src/RandomX/doc/specs.md @@ -0,0 +1,943 @@ +# RandomX + +RandomX is a proof of work (PoW) algorithm which was designed to close the gap between general-purpose CPUs and specialized hardware. The core of the algorithm is a simulation of a virtual CPU. + +#### Table of contents + +1. [Definitions](#1-definitions) +1. [Algorithm description](#2-algorithm-description) +1. [Custom functions](#3-custom-functions) +1. [Virtual Machine](#4-virtual-machine) +1. [Instruction set](#5-instruction-set) +1. [SuperscalarHash](#6-superscalarhash) +1. [Dataset](#7-dataset) + + +## 1. Definitions + +### 1.1 General definitions + +**Hash256** and **Hash512** refer to the [Blake2b](https://blake2.net/blake2_20130129.pdf) hashing function with a 256-bit and 512-bit output size, respectively. + +**Floating point format** refers to the [IEEE-754 double precision floating point format](https://en.wikipedia.org/wiki/Double-precision_floating-point_format) with a sign bit, 11-bit exponent and 52-bit fraction. + +**Argon2d** is a tradeoff-resistant variant of [Argon2](https://github.com/P-H-C/phc-winner-argon2/blob/master/argon2-specs.pdf), a memory-hard password derivation function. + +**AesGenerator1R** refers to an AES-based pseudo-random number generator described in chapter 3.2. It's initialized with a 512-bit seed value and is capable of producing more than 10 bytes per clock cycle. + +**AesGenerator4R** is a slower but more secure AES-based pseudo-random number generator described in chapter 3.3. It's initialized with a 512-bit seed value. + +**AesHash1R** refers to an AES-based fingerprinting function described in chapter 3.4. It's capable of processing more than 10 bytes per clock cycle and produces a 512-bit output. + +**BlakeGenerator** refers to a custom pseudo-random number generator described in chapter 3.5. It's based on the Blake2b hashing function. + +**SuperscalarHash** refers to a custom diffusion function designed to run efficiently on superscalar CPUs (see chapter 7). It transforms a 64-byte input value into a 64-byte output value. + +**Virtual Machine** or **VM** refers to the RandomX virtual machine as described in chapter 4. + +**Programming the VM** refers to the act of loading a program and configuration into the VM. This is described in chapter 4.5. + +**Executing the VM** refers to the act of running the program loop as described in chapter 4.6. + +**Scratchpad** refers to the workspace memory of the VM. The whole scratchpad is structured into 3 levels: L3 -> L2 -> L1 with each lower level being a subset of the higher levels. + +**Register File** refers to a 256-byte sequence formed by concatenating VM registers in little-endian format in the following order: `r0`-`r7`, `f0`-`f3`, `e0`-`e3` and `a0`-`a3`. + +**Program Buffer** refers to the buffer from which the VM reads instructions. + +**Cache** refers to a read-only buffer initialized by Argon2d as described in chapter 7.1. + +**Dataset** refers to a large read-only buffer described in chapter 7. It is constructed from the Cache using the SuperscalarHash function. + +### 1.2 Configurable parameters +RandomX has several configurable parameters that are listed in Table 1.2.1 with their default values. + +*Table 1.2.1 - Configurable parameters* + +|parameter|description|default value| +|---------|-----|-------| +|`RANDOMX_ARGON_MEMORY`|The number of 1 KiB Argon2 blocks in the Cache| `262144`| +|`RANDOMX_ARGON_ITERATIONS`|The number of Argon2d iterations for Cache initialization|`3`| +|`RANDOMX_ARGON_LANES`|The number of parallel lanes for Cache initialization|`1`| +|`RANDOMX_ARGON_SALT`|Argon2 salt|`"RandomX\x03"`| +|`RANDOMX_CACHE_ACCESSES`|The number of random Cache accesses per Dataset item|`8`| +|`RANDOMX_SUPERSCALAR_LATENCY`|Target latency for SuperscalarHash (in cycles of the reference CPU)|`170`| +|`RANDOMX_DATASET_BASE_SIZE`|Dataset base size in bytes|`2147483648`| +|`RANDOMX_DATASET_EXTRA_SIZE`|Dataset extra size in bytes|`33554368`| +|`RANDOMX_PROGRAM_SIZE`|The number of instructions in a RandomX program|`256`| +|`RANDOMX_PROGRAM_ITERATIONS`|The number of iterations per program|`2048`| +|`RANDOMX_PROGRAM_COUNT`|The number of programs per hash|`8`| +|`RANDOMX_JUMP_BITS`|Jump condition mask size in bits|`8`| +|`RANDOMX_JUMP_OFFSET`|Jump condition mask offset in bits|`8`| +|`RANDOMX_SCRATCHPAD_L3`|Scratchpad L3 size in bytes|`2097152`| +|`RANDOMX_SCRATCHPAD_L2`|Scratchpad L2 size in bytes|`262144`| +|`RANDOMX_SCRATCHPAD_L1`|Scratchpad L1 size in bytes|`16384`| + +Instruction frequencies listed in Tables 5.2.1, 5.3.1, 5.4.1 and 5.5.1 are also configurable. + + +## 2. Algorithm description + +The RandomX algorithm accepts two input values: + +* String `K` with a size of 0-60 bytes (key) +* String `H` of arbitrary length (the value to be hashed) + +and outputs a 256-bit result `R`. + +The algorithm consists of the following steps: + +1. The Dataset is initialized using the key value `K` (described in chapter 7). +1. 64-byte seed `S` is calculated as `S = Hash512(H)`. +1. Let `gen1 = AesGenerator1R(S)`. +1. The Scratchpad is filled with `RANDOMX_SCRATCHPAD_L3` random bytes using generator `gen1`. +1. Let `gen4 = AesGenerator4R(gen1.state)` (use the final state of `gen1`). +1. The value of the VM register `fprc` is set to 0 (default rounding mode - chapter 4.3). +1. The VM is programmed using `128 + 8 * RANDOMX_PROGRAM_SIZE` random bytes using generator `gen4` (chapter 4.5). +1. The VM is executed (chapter 4.6). +1. A new 64-byte seed is calculated as `S = Hash512(RegisterFile)`. +1. Set `gen4.state = S` (modify the state of the generator). +1. Steps 7-10 are performed a total of `RANDOMX_PROGRAM_COUNT` times. The last iteration skips steps 9 and 10. +1. Scratchpad fingerprint is calculated as `A = AesHash1R(Scratchpad)`. +1. Bytes 192-255 of the Register File are set to the value of `A`. +1. Result is calculated as `R = Hash256(RegisterFile)`. + +The input of the `Hash512` function in step 9 is the following 256 bytes: +``` + +---------------------------------+ + | registers r0-r7 | (64 bytes) + +---------------------------------+ + | registers f0-f3 | (64 bytes) + +---------------------------------+ + | registers e0-e3 | (64 bytes) + +---------------------------------+ + | registers a0-a3 | (64 bytes) + +---------------------------------+ +``` + +The input of the `Hash256` function in step 14 is the following 256 bytes: +``` + +---------------------------------+ + | registers r0-r7 | (64 bytes) + +---------------------------------+ + | registers f0-f3 | (64 bytes) + +---------------------------------+ + | registers e0-e3 | (64 bytes) + +---------------------------------+ + | AesHash1R(Scratchpad) | (64 bytes) + +---------------------------------+ +``` + +## 3 Custom functions + +### 3.1 Definitions + +Two of the custom functions are based on the [Advanced Encryption Standard](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard) (AES). + +**AES encryption round** refers to the application of the ShiftRows, SubBytes and MixColumns transformations followed by a XOR with the round key. + +**AES decryption round** refers to the application of inverse ShiftRows, inverse SubBytes and inverse MixColumns transformations followed by a XOR with the round key. + +### 3.2 AesGenerator1R + +AesGenerator1R produces a sequence of pseudo-random bytes. + +The internal state of the generator consists of 64 bytes arranged into four columns of 16 bytes each. During each output iteration, every column is decrypted (columns 0, 2) or encrypted (columns 1, 3) with one AES round using the following round keys (one key per column): + +``` +key0 = 53 a5 ac 6d 09 66 71 62 2b 55 b5 db 17 49 f4 b4 +key1 = 07 af 7c 6d 0d 71 6a 84 78 d3 25 17 4e dc a1 0d +key2 = f1 62 12 3f c6 7e 94 9f 4f 79 c0 f4 45 e3 20 3e +key3 = 35 81 ef 6a 7c 31 ba b1 88 4c 31 16 54 91 16 49 +``` +These keys were generated as: +``` +key0, key1, key2, key3 = Hash512("RandomX AesGenerator1R keys") +``` + + +Single iteration produces 64 bytes of output which also become the new generator state. +``` +state0 (16 B) state1 (16 B) state2 (16 B) state3 (16 B) + | | | | + AES decrypt AES encrypt AES decrypt AES encrypt + (key0) (key1) (key2) (key3) + | | | | + v v v v + state0' state1' state2' state3' +``` + +### 3.3 AesGenerator4R + +AesGenerator4R works similar way as AesGenerator1R, except it uses 4 rounds per column. Columns 0 and 1 use a different set of keys than columns 2 and 3. + +``` +state0 (16 B) state1 (16 B) state2 (16 B) state3 (16 B) + | | | | + AES decrypt AES encrypt AES decrypt AES encrypt + (key0) (key0) (key4) (key4) + | | | | + v v v v + AES decrypt AES encrypt AES decrypt AES encrypt + (key1) (key1) (key5) (key5) + | | | | + v v v v + AES decrypt AES encrypt AES decrypt AES encrypt + (key2) (key2) (key6) (key6) + | | | | + v v v v + AES decrypt AES encrypt AES decrypt AES encrypt + (key3) (key3) (key7) (key7) + | | | | + v v v v + state0' state1' state2' state3' +``` + +AesGenerator4R uses the following 8 round keys: + +``` +key0 = dd aa 21 64 db 3d 83 d1 2b 6d 54 2f 3f d2 e5 99 +key1 = 50 34 0e b2 55 3f 91 b6 53 9d f7 06 e5 cd df a5 +key2 = 04 d9 3e 5c af 7b 5e 51 9f 67 a4 0a bf 02 1c 17 +key3 = 63 37 62 85 08 5d 8f e7 85 37 67 cd 91 d2 de d8 +key4 = 73 6f 82 b5 a6 a7 d6 e3 6d 8b 51 3d b4 ff 9e 22 +key5 = f3 6b 56 c7 d9 b3 10 9c 4e 4d 02 e9 d2 b7 72 b2 +key6 = e7 c9 73 f2 8b a3 65 f7 0a 66 a9 2b a7 ef 3b f6 +key7 = 09 d6 7c 7a de 39 58 91 fd d1 06 0c 2d 76 b0 c0 +``` +These keys were generated as: +``` +key0, key1, key2, key3 = Hash512("RandomX AesGenerator4R keys 0-3") +key4, key5, key6, key7 = Hash512("RandomX AesGenerator4R keys 4-7") +``` + +### 3.4 AesHash1R + +AesHash1R calculates a 512-bit fingerprint of its input. + +AesHash1R has a 64-byte internal state, which is arranged into four columns of 16 bytes each. The initial state is: + +``` +state0 = 0d 2c b5 92 de 56 a8 9f 47 db 82 cc ad 3a 98 d7 +state1 = 6e 99 8d 33 98 b7 c7 15 5a 12 9e f5 57 80 e7 ac +state2 = 17 00 77 6a d0 c7 62 ae 6b 50 79 50 e4 7c a0 e8 +state3 = 0c 24 0a 63 8d 82 ad 07 05 00 a1 79 48 49 99 7e +``` + +The initial state vectors were generated as: +``` +state0, state1, state2, state3 = Hash512("RandomX AesHash1R state") +``` + +The input is processed in 64-byte blocks. Each input block is considered to be a set of four AES round keys `key0`, `key1`, `key2`, `key3`. Each state column is encrypted (columns 0, 2) or decrypted (columns 1, 3) with one AES round using the corresponding round key: + +``` +state0 (16 B) state1 (16 B) state2 (16 B) state3 (16 B) + | | | | + AES encrypt AES decrypt AES encrypt AES decrypt + (key0) (key1) (key2) (key3) + | | | | + v v v v + state0' state1' state2' state3' +``` + +When all input bytes have been processed, the state is processed with two additional AES rounds with the following extra keys (one key per round, same pair of keys for all columns): + +``` +xkey0 = 89 83 fa f6 9f 94 24 8b bf 56 dc 90 01 02 89 06 +xkey1 = d1 63 b2 61 3c e0 f4 51 c6 43 10 ee 9b f9 18 ed +``` + +The extra keys were generated as: +``` +xkey0, xkey1 = Hash256("RandomX AesHash1R xkeys") +``` + +``` +state0 (16 B) state1 (16 B) state2 (16 B) state3 (16 B) + | | | | + AES encrypt AES decrypt AES encrypt AES decrypt + (xkey0) (xkey0) (xkey0) (xkey0) + | | | | + v v v v + AES encrypt AES decrypt AES encrypt AES decrypt + (xkey1) (xkey1) (xkey1) (xkey1) + | | | | + v v v v +finalState0 finalState1 finalState2 finalState3 +``` + +The final state is the output of the function. + +### 3.5 BlakeGenerator + +BlakeGenerator is a simple pseudo-random number generator based on the Blake2b hashing function. It has a 64-byte internal state `S`. + +#### 3.5.1 Initialization + +The internal state is initialized from a seed value `K` (0-60 bytes long). The seed value is written into the internal state and padded with zeroes. Then the internal state is initialized as `S = Hash512(S)`. + +#### 3.5.2 Random number generation + +The generator can generate 1 byte or 4 bytes at a time by supplying data from its internal state `S`. If there are not enough unused bytes left, the internal state is reinitialized as `S = Hash512(S)`. + +## 4. Virtual Machine + +The components of the RandomX virtual machine are summarized in Fig. 4.1. + +*Figure 4.1 - Virtual Machine* + +![Imgur](https://i.imgur.com/Enk42b8.png) + +The VM is a complex instruction set computer ([CISC](https://en.wikipedia.org/wiki/Complex_instruction_set_computer)). All data are loaded and stored in little-endian byte order. Signed integer numbers are represented using [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement). + +### 4.1 Dataset + +Dataset is described in detail in chapter 7. It's a large read-only buffer. Its size is equal to `RANDOMX_DATASET_BASE_SIZE + RANDOMX_DATASET_EXTRA_SIZE` bytes. Each program uses only a random subset of the Dataset of size `RANDOMX_DATASET_BASE_SIZE`. All Dataset accesses read an aligned 64-byte item. + +### 4.2 Scratchpad + +Scratchpad represents the workspace memory of the VM. Its size is `RANDOMX_SCRATCHPAD_L3` bytes and it's divided into 3 "levels": + +* The whole scratchpad is the third level "L3". +* The first `RANDOMX_SCRATCHPAD_L2` bytes of the scratchpad is the second level "L2". +* The first `RANDOMX_SCRATCHPAD_L1` bytes of the scratchpad is the first level "L1". + +The scratchpad levels are inclusive, i.e. L3 contains both L2 and L1 and L2 contains L1. + +To access a particular scratchpad level, bitwise AND with a mask according to table 4.2.1 is applied to the memory address. + +*Table 4.2.1: Scratchpad access masks* + +|Level|8-byte aligned mask|64-byte aligned mask| +|---------|-|-| +|L1|`(RANDOMX_SCRATCHPAD_L1 - 1) & ~7`|-| +|L2|`(RANDOMX_SCRATCHPAD_L2 - 1) & ~7`|-| +|L3|`(RANDOMX_SCRATCHPAD_L3 - 1) & ~7`|`(RANDOMX_SCRATCHPAD_L3 - 1) & ~63`| + +### 4.3 Registers + +The VM has 8 integer registers `r0`-`r7` (group R) and a total of 12 floating point registers split into 3 groups: `f0`-`f3` (group F), `e0`-`e3` (group E) and `a0`-`a3` (group A). Integer registers are 64 bits wide, while floating point registers are 128 bits wide and contain a pair of numbers in floating point format. The lower and upper half of floating point registers are not separately addressable. + +Additionally, there are 3 internal registers `ma`, `mx` and `fprc`. + +Integer registers `r0`-`r7` can be the source or the destination operands of integer instructions or may be used as address registers for accessing the Scratchpad. + +Floating point registers `a0`-`a3` are read-only and their value is fixed for a given VM program. They can be the source operand of any floating point instruction. The value of these registers is restricted to the interval `[1, 4294967296)`. + +Floating point registers `f0`-`f3` are the "additive" registers, which can be the destination of floating point addition and subtraction instructions. The absolute value of these registers will not exceed about `3.0e+14`. + +Floating point registers `e0`-`e3` are the "multiplicative" registers, which can be the destination of floating point multiplication, division and square root instructions. Their value is always positive. + +`ma` and `mx` are the memory registers. Both are 32 bits wide. `ma` contains the memory address of the next Dataset read and `mx` contains the address of the next Dataset prefetch. The values of `ma` and `mx` registers are always aligned to be a multiple of 64. + +The 2-bit `fprc` register determines the rounding mode of all floating point operations according to Table 4.3.1. The four rounding modes are defined by the IEEE 754 standard. + +*Table 4.3.1: Rounding modes* + +|`fprc`|rounding mode| +|-------|------------| +|0|roundTiesToEven| +|1|roundTowardNegative| +|2|roundTowardPositive| +|3|roundTowardZero| + +#### 4.3.1 Group F register conversion + +When an 8-byte value read from the memory is to be converted to an F group register value or operand, it is interpreted as a pair of 32-bit signed integers (in little endian, two's complement format) and converted to floating point format. This conversion is exact and doesn't need rounding because only 30 bits of the fraction significand are needed to represent the integer value. + +#### 4.3.2 Group E register conversion + +When an 8-byte value read from the memory is to be converted to an E group register value or operand, the same conversion procedure is applied as for F group registers (see 4.3.1) with additional post-processing steps for each of the two floating point values: + +1. The sign bit is set to `0`. +2. Bits 0-2 of the exponent are set to the constant value of 0112. +3. Bits 3-6 of the exponent are set to the value of the exponent mask described in chapter 4.5.6. This value is fixed for a given VM program. +4. The bottom 22 bits of the fraction significand are set to the value of the fraction mask described in chapter 4.5.6. This value is fixed for a given VM program. + +### 4.4 Program buffer + +The Program buffer stores the program to be executed by the VM. The program consists of `RANDOMX_PROGRAM_SIZE` instructions. Each instruction is encoded by an 8-byte word. The instruction set is described in chapter 5. + +### 4.5 VM programming + +The VM requires `128 + 8 * RANDOMX_PROGRAM_SIZE` bytes to be programmed. This is split into two parts: + +* `128` bytes of configuration data = 16 quadwords (16×8 bytes), used according to Table 4.5.1 +* `8 * RANDOMX_PROGRAM_SIZE` bytes of program data, copied directly into the Program Buffer + +*Table 4.5.1 - Configuration data* + +|quadword|description| +|-----|-----------| +|0|initialize low half of register `a0`| +|1|initialize high half of register `a0`| +|2|initialize low half of register `a1`| +|3|initialize high half of register `a1`| +|4|initialize low half of register `a2`| +|5|initialize high half of register `a2`| +|6|initialize low half of register `a3`| +|7|initialize high half of register `a3`| +|8|initialize register `ma`| +|9|(reserved)| +|10|initialize register `mx`| +|11|(reserved)| +|12|select address registers| +|13|select Dataset offset| +|14|initialize register masks for low half of group E registers| +|15|initialize register masks for high half of group E registers| + +#### 4.5.2 Group A register initialization + +The values of the floating point registers `a0`-`a3` are initialized using configuration quadwords 0-7 to have the following value: + ++1.fraction x 2exponent + +The fraction has full 52 bits of precision and the exponent value ranges from 0 to 31. These values are obtained from the initialization quadword (in little endian format) according to Table 4.5.2. + +*Table 4.5.2 - Group A register initialization* + +|bits|description| +|----|-----------| +|0-51|fraction| +|52-58|(reserved)| +|59-63|exponent| + +#### 4.5.3 Memory registers + +Registers `ma` and `mx` are initialized using the low 32 bits of quadwords 8 and 10 in little endian format. + +#### 4.5.4 Address registers + +Bits 0-3 of quadword 12 are used to select 4 address registers for program execution. Each bit chooses one register from a pair of integer registers according to Table 4.5.3. + +*Table 4.5.3 - Address registers* + +|address register (bit)|value = 0|value = 1| +|----------------------|-|-| +|`readReg0` (0)|`r0`|`r1`| +|`readReg1` (1)|`r2`|`r3`| +|`readReg2` (2)|`r4`|`r5`| +|`readReg3` (3)|`r6`|`r7`| + +#### 4.5.5 Dataset offset + +The `datasetOffset` is calculated as the remainder of dividing quadword 13 by `RANDOMX_DATASET_EXTRA_SIZE / 64 + 1`. The result is multiplied by `64`. This offset is used when reading values from the Dataset. + +#### 4.5.6 Group E register masks + +These masks are used for the conversion of group E registers (see 4.3.2). The low and high halves each have their own masks initialized from quadwords 14 and 15. The fraction mask is given by bits 0-21 and the exponent mask by bits 60-63 of the initialization quadword. + +### 4.6 VM execution + +During VM execution, 3 additional temporary registers are used: `ic`, `spAddr0` and `spAddr1`. Program execution consists of initialization and loop execution. + +#### 4.6.1 Initialization + +1. `ic` register is set to `RANDOMX_PROGRAM_ITERATIONS`. +2. `spAddr0` is set to the value of `mx`. +3. `spAddr1` is set to the value of `ma`. +4. The values of all integer registers `r0`-`r7` are set to zero. + +#### 4.6.2 Loop execution + +The loop described below is repeated until the value of the `ic` register reaches zero. + +1. XOR of registers `readReg0` and `readReg1` (see Table 4.5.3) is calculated and `spAddr0` is XORed with the low 32 bits of the result and `spAddr1` with the high 32 bits. +2. `spAddr0` is used to perform a 64-byte aligned read from Scratchpad level 3 (using mask from Table 4.2.1). The 64 bytes are XORed with all integer registers in order `r0`-`r7`. +3. `spAddr1` is used to perform a 64-byte aligned read from Scratchpad level 3 (using mask from Table 4.2.1). Each floating point register `f0`-`f3` and `e0`-`e3` is initialized using an 8-byte value according to the conversion rules from chapters 4.3.1 and 4.3.2. +4. The 256 instructions stored in the Program Buffer are executed. +5. The `mx` register is XORed with the low 32 bits of registers `readReg2` and `readReg3` (see Table 4.5.3). +6. A 64-byte Dataset item at address `datasetOffset + mx % RANDOMX_DATASET_BASE_SIZE` is prefetched from the Dataset (it will be used during the next iteration). +7. A 64-byte Dataset item at address `datasetOffset + ma % RANDOMX_DATASET_BASE_SIZE` is loaded from the Dataset. The 64 bytes are XORed with all integer registers in order `r0`-`r7`. +8. The values of registers `mx` and `ma` are swapped. +9. The values of all integer registers `r0`-`r7` are written to the Scratchpad (L3) at address `spAddr1` (64-byte aligned). +10. Register `f0` is XORed with register `e0` and the result is stored in register `f0`. Register `f1` is XORed with register `e1` and the result is stored in register `f1`. Register `f2` is XORed with register `e2` and the result is stored in register `f2`. Register `f3` is XORed with register `e3` and the result is stored in register `f3`. +11. The values of registers `f0`-`f3` are written to the Scratchpad (L3) at address `spAddr0` (64-byte aligned). +12. `spAddr0` and `spAddr1` are both set to zero. +13. `ic` is decreased by 1. + + +## 5. Instruction set + +The VM executes programs in a special instruction set, which was designed in such way that any random 8-byte word is a valid instruction and any sequence of valid instructions is a valid program. Because there are no "syntax" rules, generating a random program is as easy as filling the program buffer with random data. + +### 5.1 Instruction encoding + +Each instruction word is 64 bits long. Instruction fields are encoded as shown in Fig. 5.1. + +*Figure 5.1 - Instruction encoding* + +![Imgur](https://i.imgur.com/FtkWRwe.png) + +#### 5.1.1 opcode +There are 256 opcodes, which are distributed between 29 distinct instructions. Each instruction can be encoded using multiple opcodes (the number of opcodes specifies the frequency of the instruction in a random program). + +*Table 5.1.1: Instruction groups* + +|group|# instructions|# opcodes|| +|---------|-----------------|----|-| +|integer |17|120|46.9%| +|floating point |9|94|36.7%| +|control |2|26|10.2%| +|store |1|16|6.2%| +||**29**|**256**|**100%** + +All instructions are described below in chapters 5.2 - 5.5. + +#### 5.1.2 dst +Destination register. Only bits 0-1 (register groups A, F, E) or 0-2 (groups R, F+E) are used to encode a register according to Table 5.1.2. + +*Table 5.1.2: Addressable register groups* + +|index|R|A|F|E|F+E| +|--|--|--|--|--|--| +|0|`r0`|`a0`|`f0`|`e0`|`f0`| +|1|`r1`|`a1`|`f1`|`e1`|`f1`| +|2|`r2`|`a2`|`f2`|`e2`|`f2`| +|3|`r3`|`a3`|`f3`|`e3`|`f3`| +|4|`r4`||||`e0`| +|5|`r5`||||`e1`| +|6|`r6`||||`e2`| +|7|`r7`||||`e3`| + +#### 5.1.3 src + +The `src` flag encodes a source operand register according to Table 5.1.2 (only bits 0-1 or 0-2 are used). + +Some integer instructions use a constant value as the source operand in cases when `dst` and `src` encode the same register (see Table 5.2.1). + +For register-memory instructions, the source operand is used to calculate the memory address. + +#### 5.1.4 mod + +The `mod` flag is encoded as: + +*Table 5.1.3: mod flag encoding* + +|`mod` bits|description|range of values| +|----|--------|----| +|0-1|`mod.mem` flag|0-3| +|2-3|`mod.shift` flag|0-3| +|4-7|`mod.cond` flag|0-15| + +The `mod.mem` flag selects between Scratchpad levels L1 and L2 when reading from or writing to memory except for two cases: + +* it's a memory read and `dst` and `src` encode the same register +* it's a memory write `mod.cond` is 14 or 15 + +In these two cases, the Scratchpad level is L3 (see Table 5.1.4). + +*Table 5.1.4: memory access Scratchpad level* + +|condition|Scratchpad level| +|---------|-| +|`src == dst` (read)|L3| +|`mod.cond >= 14` (write)|L3| +|`mod.mem == 0`|L2| +|`mod.mem != 0`|L1| + +The address for reading/writing is calculated by applying bitwise AND operation to the address and the 8-byte aligned address mask listed in Table 4.2.1. + +The `mod.cond` and `mod.shift` flags are used by some instructions (see 5.2, 5.4). + +#### 5.1.5 imm32 +A 32-bit immediate value that can be used as the source operand and is used to calculate addresses for memory operations. The immediate value is sign-extended to 64 bits unless specified otherwise. + +### 5.2 Integer instructions +For integer instructions, the destination is always an integer register (register group R). Source operand (if applicable) can be either an integer register or memory value. If `dst` and `src` refer to the same register, most instructions use `0` or `imm32` instead of the register. This is indicated in the 'src == dst' column in Table 5.2.1. + +`[mem]` indicates a memory operand loaded as an 8-byte value from the address `src + imm32`. + +*Table 5.2.1 Integer instructions* + +|frequency|instruction|dst|src|`src == dst ?`|operation| +|-|-|-|-|-|-| +|16/256|IADD_RS|R|R|`src = dst`|`dst = dst + (src << mod.shift) (+ imm32)`| +|7/256|IADD_M|R|R|`src = 0`|`dst = dst + [mem]`| +|16/256|ISUB_R|R|R|`src = imm32`|`dst = dst - src`| +|7/256|ISUB_M|R|R|`src = 0`|`dst = dst - [mem]`| +|16/256|IMUL_R|R|R|`src = imm32`|`dst = dst * src`| +|4/256|IMUL_M|R|R|`src = 0`|`dst = dst * [mem]`| +|4/256|IMULH_R|R|R|`src = dst`|`dst = (dst * src) >> 64`| +|1/256|IMULH_M|R|R|`src = 0`|`dst = (dst * [mem]) >> 64`| +|4/256|ISMULH_R|R|R|`src = dst`|`dst = (dst * src) >> 64` (signed)| +|1/256|ISMULH_M|R|R|`src = 0`|`dst = (dst * [mem]) >> 64` (signed)| +|8/256|IMUL_RCP|R|-|-|dst = 2x / imm32 * dst| +|2/256|INEG_R|R|-|-|`dst = -dst`| +|15/256|IXOR_R|R|R|`src = imm32`|`dst = dst ^ src`| +|5/256|IXOR_M|R|R|`src = 0`|`dst = dst ^ [mem]`| +|8/256|IROR_R|R|R|`src = imm32`|`dst = dst >>> src`| +|2/256|IROL_R|R|R|`src = imm32`|`dst = dst <<< src`| +|4/256|ISWAP_R|R|R|`src = dst`|`temp = src; src = dst; dst = temp`| + +#### 5.2.1 IADD_RS + +This instructions adds the values of two registers (modulo 264). The value of the second operand is shifted left by 0-3 bits (determined by the `mod.shift` flag). Additionally, if `dst` is register `r5`, the immediate value `imm32` is added to the result. + +#### 5.2.2 IADD_M + +64-bit integer addition operation (performed modulo 264) with a memory source operand. + +#### 5.2.3 ISUB_R, ISUB_M + +64-bit integer subtraction (performed modulo 264). ISUB_R uses register source operand, ISUB_M uses a memory source operand. + +#### 5.2.4 IMUL_R, IMUL_M + +64-bit integer multiplication (performed modulo 264). IMUL_R uses a register source operand, IMUL_M uses a memory source operand. + +#### 5.2.5 IMULH_R, IMULH_M, ISMULH_R, ISMULH_M +These instructions output the high 64 bits of the whole 128-bit multiplication result. The result differs for signed and unsigned multiplication (IMULH is unsigned, ISMULH is signed). The variants with a register source operand perform a squaring operation if `dst` equals `src`. + +#### 5.2.6 IMUL_RCP +If `imm32` equals 0 or is a power of 2, IMUL_RCP is a no-op. In other cases, the instruction multiplies the destination register by a reciprocal of `imm32` (the immediate value is zero-extended and treated as unsigned). The reciprocal is calculated as rcp = 2x / imm32 by choosing the largest integer `x` such that rcp < 264. + +#### 5.2.7 INEG_R +Performs two's complement negation of the destination register. + +#### 5.2.8 IXOR_R, IXOR_M +64-bit exclusive OR operation. IXOR_R uses a register source operand, IXOR_M uses a memory source operand. + +#### 5.2.9 IROR_R, IROL_R +Performs a cyclic shift (rotation) of the destination register. Source operand (shift count) is implicitly masked to 6 bits. IROR rotates bits right, IROL left. + +#### 5.2.9 ISWAP_R +This instruction swaps the values of two registers. If source and destination refer to the same register, the result is a no-op. + +### 5.3 Floating point instructions +For floating point instructions, the destination can be a group F or group E register. Source operand is either a group A register or a memory value. + +`[mem]` indicates a memory operand loaded as an 8-byte value from the address `src + imm32` and converted according to the rules in chapters 4.3.1 (group F) or 4.3.2 (group E). The lower and upper memory operands are denoted as `[mem][0]` and `[mem][1]`. + +All floating point operations are rounded according to the current value of the `fprc` register (see Table 4.3.1). Due to restrictions on the values of the floating point registers, no operation results in `NaN` or a denormal number. + +*Table 5.3.1 Floating point instructions* + +|frequency|instruction|dst|src|operation| +|-|-|-|-|-| +|4/256|FSWAP_R|F+E|-|`(dst0, dst1) = (dst1, dst0)`| +|16/256|FADD_R|F|A|`(dst0, dst1) = (dst0 + src0, dst1 + src1)`| +|5/256|FADD_M|F|R|`(dst0, dst1) = (dst0 + [mem][0], dst1 + [mem][1])`| +|16/256|FSUB_R|F|A|`(dst0, dst1) = (dst0 - src0, dst1 - src1)`| +|5/256|FSUB_M|F|R|`(dst0, dst1) = (dst0 - [mem][0], dst1 - [mem][1])`| +|6/256|FSCAL_R|F|-|(dst0, dst1) = (-2x0 * dst0, -2x1 * dst1)| +|32/256|FMUL_R|E|A|`(dst0, dst1) = (dst0 * src0, dst1 * src1)`| +|4/256|FDIV_M|E|R|`(dst0, dst1) = (dst0 / [mem][0], dst1 / [mem][1])`| +|6/256|FSQRT_R|E|-|`(dst0, dst1) = (√dst0, √dst1)`| + +#### 5.3.1 FSWAP_R + +Swaps the lower and upper halves of the destination register. This is the only instruction that is applicable to both F an E register groups. + +#### 5.3.2 FADD_R, FADD_M + +Double precision floating point addition. FADD_R uses a group A register source operand, FADD_M uses a memory operand. + +#### 5.3.3 FSUB_R, FSUB_M + +Double precision floating point subtraction. FSUB_R uses a group A register source operand, FSUB_M uses a memory operand. + +#### 5.3.4 FSCAL_R +This instruction negates the number and multiplies it by 2x. `x` is calculated by taking the 4 least significant digits of the biased exponent and interpreting them as a binary number using the digit set `{+1, -1}` as opposed to the traditional `{0, 1}`. The possible values of `x` are all odd numbers from -15 to +15. + +The mathematical operation described above is equivalent to a bitwise XOR of the binary representation with the value of `0x80F0000000000000`. + +#### 5.3.5 FMUL_R + +Double precision floating point multiplication. This instruction uses only a register source operand. + +#### 5.3.6 FDIV_M + +Double precision floating point division. This instruction uses only a memory source operand. + +#### 5.3.7 FSQRT_R + +Double precision floating point square root of the destination register. + +### 5.4 Control instructions + +There are 2 control instructions. + +*Table 5.4.1 - Control instructions* + +|frequency|instruction|dst|src|operation| +|-|-|-|-|-| +|1/256|CFROUND|-|R|`fprc = src >>> imm32` +|25/256|CBRANCH|R|-|`dst = dst + cimm`, conditional jump + +#### 5.4.1 CFROUND +This instruction calculates a 2-bit value by rotating the source register right by `imm32` bits and taking the 2 least significant bits (the value of the source register is unaffected). The result is stored in the `fprc` register. This changes the rounding mode of all subsequent floating point instructions. + +#### 5.4.2 CBRANCH + +This instruction adds an immediate value `cimm` (constructed from `imm32`, see below) to the destination register and then performs a conditional jump in the Program Buffer based on the value of the destination register. The target of the jump is the instruction following the instruction when register `dst` was last modified. + +At the beginning of each program iteration, all registers are considered to be unmodified. A register is considered as modified by an instruction in the following cases: + +* It is the destination register of an integer instruction except IMUL_RCP and ISWAP_R. +* It is the destination register of IMUL_RCP and `imm32` is not zero or a power of 2. +* It is the source or the destination register of ISWAP_R and the destination and source registers are distinct. +* The CBRANCH instruction is considered to modify all integer registers. + +If register `dst` has not been modified yet, the jump target is the first instruction in the Program Buffer. + +The CBRANCH instruction performs the following steps: + +1. A constant `b` is calculated as `mod.cond + RANDOMX_JUMP_OFFSET`. +1. A constant `cimm` is constructed as sign-extended `imm32` with bit `b` set to 1 and bit `b-1` set to 0 (if `b > 0`). +1. `cimm` is added to the destination register. +1. If bits `b` to `b + RANDOMX_JUMP_BITS - 1` of the destination register are zero, the jump is executed (target is the instruction following the instruction where `dst` was last modified). + +Bits in immediate and register values are numbered from 0 to 63 with 0 being the least significant bit. For example, for `b = 10` and `RANDOMX_JUMP_BITS = 8`, the bits are arranged like this: + +``` +cimm = SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSMMMMMMMMMMMMMMMMMMMMM10MMMMMMMMM + dst = ..............................................XXXXXXXX.......... +``` + +`S` is a copied sign bit from `imm32`. `M` denotes bits of `imm32`. The 9th bit is set to 0 and the 10th bit is set to 1. This value will be added to `dst`. + +The second line uses `X` to mark bits of `dst` that will be checked by the condition. If all these bits are 0 after adding `cimm`, the jump is executed. + +The construction of the CBRANCH instruction ensures that no inifinite loops are possible in the program. + +### 5.5 Store instruction +There is one explicit store instruction for integer values. + +`[mem]` indicates the destination is an 8-byte value at the address `dst + imm32`. + +*Table 5.5.1 - Store instruction* + +|frequency|instruction|dst|src|operation| +|-|-|-|-|-| +|16/256|ISTORE|R|R|`[mem] = src` + +#### 5.5.1 ISTORE +This instruction stores the value of the source integer register to the memory at the address calculated from the value of the destination register. The `src` and `dst` can be the same register. + +## 6. SuperscalarHash + +SuperscalarHash is a custom diffusion function that was designed to burn as much power as possible using only the CPU's integer ALUs. + +The input and output of SuperscalarHash are 8 integer registers `r0`-`r7`, each 64 bits wide. The output of SuperscalarHash is used to construct the Dataset (see chapter 7.3). + +### 6.1 Instructions +The body of SuperscalarHash is a random sequence of instructions that can run on the Virtual Machine. SuperscalarHash uses a reduced set of only integer register-register instructions listed in Table 6.1.1. `dst` refers to the destination register, `src` to the source register. + +*Table 6.1.1 - SuperscalarHash instructions* + +|freq. †|instruction|Macro-ops|operation|rules| +|-|-|-|-|-| +|0.11|ISUB_R|`sub_rr`|`dst = dst - src`|`dst != src`| +|0.11|IXOR_R|`xor_rr`|`dst = dst ^ src`|`dst != src`| +|0.11|IADD_RS|`lea_sib`|`dst = dst + (src << mod.shift)`|`dst != src`, `dst != r5` +|0.22|IMUL_R|`imul_rr`|`dst = dst * src`|`dst != src`| +|0.11|IROR_C|`ror_ri`|`dst = dst >>> imm32`|`imm32 % 64 != 0` +|0.10|IADD_C|`add_ri`|`dst = dst + imm32`| +|0.10|IXOR_C|`xor_ri`|`dst = dst ^ imm32`| +|0.03|IMULH_R|`mov_rr`,`mul_r`,`mov_rr`|`dst = (dst * src) >> 64`| +|0.03|ISMULH_R|`mov_rr`,`imul_r`,`mov_rr`|`dst = (dst * src) >> 64` (signed)| +|0.06|IMUL_RCP|`mov_ri`,`imul_rr`|dst = 2x / imm32 * dst|`imm32 != 0`, imm32 != 2N| + +† Frequencies are approximate. Instructions are generated based on complex rules. + +#### 6.1.1 ISUB_R +See chapter 5.2.3. Source and destination are always distinct registers. + +#### 6.1.2 IXOR_R +See chapter 5.2.8. Source and destination are always distinct registers. + +#### 6.1.3 IADD_RS +See chapter 5.2.1. Source and destination are always distinct registers and register `r5` cannot be the destination. + +#### 6.1.4 IMUL_R +See chapter 5.2.4. Source and destination are always distinct registers. + +#### 6.1.5 IROR_C +The destination register is rotated right. The rotation count is given by `imm32` masked to 6 bits and cannot be 0. + +#### 6.1.6 IADD_C +A sign-extended `imm32` is added to the destination register. + +#### 6.1.7 IXOR_C +The destination register is XORed with a sign-extended `imm32`. + +#### 6.1.8 IMULH_R, ISMULH_R +See chapter 5.2.5. + +#### 6.1.9 IMUL_RCP +See chapter 5.2.6. `imm32` is never 0 or a power of 2. + +### 6.2 The reference CPU + +Unlike a standard RandomX program, a SuperscalarHash program is generated using a strict set of rules to achieve the maximum performance on a superscalar CPU. For this purpose, the generator runs a simulation of a reference CPU. + +The reference CPU is loosely based on the [Intel Ivy Bridge microarchitecture](https://en.wikipedia.org/wiki/Ivy_Bridge_(microarchitecture)). It has the following properties: + +* The CPU has 3 integer execution ports P0, P1 and P5 that can execute instructions in parallel. Multiplication can run only on port P1. +* Each of the Superscalar instructions listed in Table 6.1.1 consist of one or more *Macro-ops*. Each Macro-op has certain execution latency (in cycles) and size (in bytes) as shown in Table 6.2.1. +* Each of the Macro-ops listed in Table 6.2.1 consists of 0-2 *Micro-ops* that can go to a subset of the 3 execution ports. If a Macro-op consists of 2 Micro-ops, both must be executed together. +* The CPU can decode at most 16 bytes of code per cycle and at most 4 Micro-ops per cycle. + +*Table 6.2.1 - Macro-ops* + +|Macro-op|latency|size|1st Micro-op|2nd Micro-op| +|-|-|-|-|-| +|`sub_rr`|1|3|P015|-| +|`xor_rr`|1|3|P015|-| +|`lea_sib`|1|4|P01|-| +|`imul_rr`|3|4|P1|-| +|`ror_ri`|1|4|P05|-| +|`add_ri`|1|7, 8, 9|P015|-| +|`xor_ri`|1|7, 8, 9|P015|-| +|`mov_rr`|0|3|-|-| +|`mul_r`|4|3|P1|P5| +|`imul_r`|4|3|P1|P5| +|`mov_ri`|1|10|P015|-| + +* P015 - Micro-op can be executed on any port +* P01 - Micro-op can be executed on ports P0 or P1 +* P05 - Micro-op can be executed on ports P0 or P5 +* P1 - Micro-op can be executed only on port P1 +* P5 - Micro-op can be executed only on port P5 + +Macro-ops `add_ri` and `xor_ri` can be optionally padded to a size of 8 or 9 bytes for code alignment purposes. `mov_rr` has 0 execution latency and doesn't use an execution port, but still occupies space during the decoding stage (see chapter 6.3.1). + +### 6.3 CPU simulation + +SuperscalarHash programs are generated to maximize the usage of all 3 execution ports of the reference CPU. The generation consists of 4 stages: + +* Decoding stage +* Instruction selection +* Port assignment +* Operand assignment + +Program generation is complete when one of two conditions is met: + +1. An instruction is scheduled for execution on cycle that is equal to or greater than `RANDOMX_SUPERSCALAR_LATENCY` +1. The number of generated instructions reaches `3 * RANDOMX_SUPERSCALAR_LATENCY + 2`. + +#### 6.3.1 Decoding stage + +The generator produces instructions in groups of 3 or 4 Macro-op slots such that the size of each group is exactly 16 bytes. + +*Table 6.3.1 - Decoder configurations* + +|decoder group|configuration| +|-------------|-------------| +|0|4-8-4| +|1|7-3-3-3| +|2|3-7-3-3| +|3|4-9-3| +|4|4-4-4-4| +|5|3-3-10| + +The rules for the selection of the decoder group are following: + +* If the currently processed instruction is IMULH_R or ISMULH_R, the next decode group is group 5 (the only group that starts with a 3-byte slot and has only 3 slots). +* If the total number of multiplications that have been generated is less than or equal to the current decoding cycle, the next decode group is group 4. +* If the currently processed instruction is IMUL_RCP, the next decode group is group 0 or 3 (must begin with a 4-byte slot for multiplication). +* Otherwise a random decode group is selected from groups 0-3. + +#### 6.3.2 Instruction selection + +Instructions are selected based on the size of the current decode group slot - see Table 6.3.2. + +*Table 6.3.2 - Decoder configurations* + +|slot size|note|instructions| +|-------------|-------------|-----| +|3|-|ISUB_R, IXOR_R +|3|last slot in the group|ISUB_R, IXOR_R, IMULH_R, ISMULH_R| +|4|decode group 4, not the last slot|IMUL_R| +|4|-|IROR_C, IADD_RS| +|7,8,9|-|IADD_C, IXOR_C| +|10|-|IMUL_RCP| + +#### 6.3.3 Port assignment + +Micro-ops are issued to execution ports as soon as an available port is free. The scheduling is done optimistically by checking port availability in order P5 -> P0 -> P1 to not overload port P1 (multiplication) by instructions that can go to any port. The cycle when all Micro-ops of an instruction can be executed is called the 'scheduleCycle'. + +#### 6.3.4 Operand assignment + +The source operand (if needed) is selected first. is it selected from the group of registers that are available at the 'scheduleCycle' of the instruction. A register is available if the latency of its last operation has elapsed. + +The destination operand is selected with more strict rules (see column 'rules' in Table 6.1.1): + +* value must be ready at the required cycle +* cannot be the same as the source register unless the instruction allows it (see column 'rules' in Table 6.1.1) + * this avoids optimizable operations such as `reg ^ reg` or `reg - reg` + * it also increases intermixing of register values +* register cannot be multiplied twice in a row unless `allowChainedMul` is true + * this avoids accumulation of trailing zeroes in registers due to excessive multiplication + * `allowChainedMul` is set to true if an attempt to find source/destination registers failed (this is quite rare, but prevents a catastrophic failure of the generator) +* either the last instruction applied to the register or its source must be different than the current instruction + * this avoids optimizable instruction sequences such as `r1 = r1 ^ r2; r1 = r1 ^ r2` (can be eliminated) or `reg = reg >>> C1; reg = reg >>> C2` (can be reduced to one rotation) or `reg = reg + C1; reg = reg + C2` (can be reduced to one addition) +* register `r5` cannot be the destination of the IADD_RS instruction (limitation of the x86 lea instruction) + +## 7. Dataset + +The Dataset is a read-only memory structure that is used during program execution (chapter 4.6.2, steps 6 and 7). The size of the Dataset is `RANDOMX_DATASET_BASE_SIZE + RANDOMX_DATASET_EXTRA_SIZE` bytes and it's divided into 64-byte 'items'. + +In order to allow PoW verification with a lower amount of memory, the Dataset is constructed in two steps using an intermediate structure called the "Cache", which can be used to calculate Dataset items on the fly. + +The whole Dataset is constructed from the key value `K`, which is an input parameter of RandomX. The whole Dataset needs to be recalculated everytime the key value changes. Fig. 7.1 shows the process of Dataset construction. Note: the maximum supported length of `K` is 60 bytes. Using a longer key results in implementation-defined behavior. + +*Figure 7.1 - Dataset construction* + +![Imgur](https://i.imgur.com/86h5SbW.png) + +### 7.1 Cache construction + +The key `K` is expanded into the Cache using the "memory fill" function of Argon2d with parameters according to Table 7.1.1. The key is used as the "password" field. + +*Table 7.1.1 - Argon2 parameters* + +|parameter|value| +|------------|--| +|parallelism|`RANDOMX_ARGON_LANES`| +|output size|0| +|memory|`RANDOMX_ARGON_MEMORY`| +|iterations|`RANDOMX_ARGON_ITERATIONS`| +|version|`0x13`| +|hash type|0 (Argon2d)| +|password|key value `K`| +|salt|`RANDOMX_ARGON_SALT` +|secret size|0| +|assoc. data size|0| + +The finalizer and output calculation steps of Argon2 are omitted. The output is the filled memory array. + +### 7.2 SuperscalarHash initialization + +The key value `K` is used to initialize a BlakeGenerator (see chapter 3.5), which is then used to generate 8 SuperscalarHash instances for Dataset initialization. + +### 7.3 Dataset block generation +Dataset items are numbered sequentially with `itemNumber` starting from 0. Each 64-byte Dataset item is generated independently using 8 SuperscalarHash functions (generated according to chapter 7.2) and by XORing randomly selected data from the Cache (constructed according to chapter 7.1). + +The item data is represented by 8 64-bit integer registers: `r0`-`r7`. + +1. The register values are initialized as follows (`*` = multiplication, `^` = XOR): + * `r0 = (itemNumber + 1) * 6364136223846793005` + * `r1 = r0 ^ 9298411001130361340` + * `r2 = r0 ^ 12065312585734608966` + * `r3 = r0 ^ 9306329213124626780` + * `r4 = r0 ^ 5281919268842080866` + * `r5 = r0 ^ 10536153434571861004` + * `r6 = r0 ^ 3398623926847679864` + * `r7 = r0 ^ 9549104520008361294` +1. Let `cacheIndex = itemNumber` +1. Let `i = 0` +1. Load a 64-byte item from the Cache. The item index is given by `cacheIndex` modulo the total number of 64-byte items in Cache. +1. Execute `SuperscalarHash[i](r0, r1, r2, r3, r4, r5, r6, r7)`, where `SuperscalarHash[i]` refers to the i-th SuperscalarHash function. This modifies the values of the registers `r0`-`r7`. +1. XOR all registers with the 64 bytes loaded in step 4 (8 bytes per column in order `r0`-`r7`). +1. Set `cacheIndex` to the value of the register that has the longest dependency chain in the SuperscalarHash function executed in step 5. +1. Set `i = i + 1` and go back to step 4 if `i < RANDOMX_CACHE_ACCESSES`. +1. Concatenate registers `r0`-`r7` in little endian format to get the final Dataset item data. + +The constants used to initialize register values in step 1 were determined as follows: + +* Multiplier `6364136223846793005` was selected because it gives an excellent distribution for linear generators (D. Knuth: The Art of Computer Programming – Vol 2., also listed in [Commonly used LCG parameters](https://en.wikipedia.org/wiki/Linear_congruential_generator#Parameters_in_common_use)) +* XOR constants used to initialize registers `r1`-`r7` were determined by calculating `Hash512` of the ASCII value `"RandomX SuperScalarHash initialize"` and taking bytes 8-63 as 7 little-endian unsigned 64-bit integers. Additionally, the constant for `r1` was increased by 233+700 and the constant for `r3` was increased by 214 (these changes are necessary to ensure that all registers have unique initial values for all values of `itemNumber`). + diff --git a/src/RandomX/doc/tevador.asc b/src/RandomX/doc/tevador.asc new file mode 100644 index 000000000..b998f1ef2 --- /dev/null +++ b/src/RandomX/doc/tevador.asc @@ -0,0 +1,13 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- + +mDMEXd+PeBYJKwYBBAHaRw8BAQdAZ0nqJ+nRYoScG2QLX62pl+WO1+Mkv6Yyt2Kb +ntGUuLq0G3RldmFkb3IgPHRldmFkb3JAZ21haWwuY29tPoiWBBMWCAA+FiEEMoWj +LVEwdmMs6CUQWijIaue9c6YFAl3fj3gCGwMFCQWnqDgFCwkIBwIGFQoJCAsCBBYC +AwECHgECF4AACgkQWijIaue9c6YBFQD+N1XTUqSCZp9jB/yTHQ9ahSaIUMtmuvdT +So2s+quudP4A/R5wLwukpfGN9UZ4cfpmKCJ9jO1HJ2udmlGMsJbQpDAIuDgEXd+P +eBIKKwYBBAGXVQEFAQEHQBNbQuPcDojMCkRb5B5u7Ld/AFLClOh+6ElL+u61rIY/ +AwEIB4h+BBgWCAAmFiEEMoWjLVEwdmMs6CUQWijIaue9c6YFAl3fj3gCGwwFCQWn +qDgACgkQWijIaue9c6YJvgD+IY1Q9mCM1P1iZIoXuafRihXJ7UgVXpQqW2yoaUT3 +bfQA/RkisI2eElYoOjdwPszPP6VfL5+SViwDmDuJG2P5llgE +=V4vd +-----END PGP PUBLIC KEY BLOCK----- diff --git a/src/RandomX/randomx.sln b/src/RandomX/randomx.sln new file mode 100644 index 000000000..3f003b78e --- /dev/null +++ b/src/RandomX/randomx.sln @@ -0,0 +1,177 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.28307.572 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "randomx", "vcxproj\randomx.vcxproj", "{3346A4AD-C438-4324-8B77-47A16452954B}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{4A4A689F-86AF-41C0-A974-1080506D0923}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "superscalar-avalanche", "vcxproj\superscalar-avalanche.vcxproj", "{CF34A7EF-7DC9-4077-94A5-76F5425EA938}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "superscalar-init", "vcxproj\superscalar-init.vcxproj", "{E59DC709-9B12-4A53-BAF3-79398821C376}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "superscalar-stats", "vcxproj\superscalar-stats.vcxproj", "{0173D560-8C12-46B3-B467-0C6E7573AA0B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "benchmark", "vcxproj\benchmark.vcxproj", "{1E8A2E2F-9F9F-43AA-BB19-9107FEC64A70}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "api-example1", "vcxproj\api-example1.vcxproj", "{83EA3E54-5D91-4E01-8EF6-C1E718334F83}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "api-example2", "vcxproj\api-example2.vcxproj", "{44947B9C-E6B1-4C06-BD01-F8EF43B59223}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "code-generator", "vcxproj\code-generator.vcxproj", "{3E490DEC-1874-43AA-92DA-1AC57C217EAC}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scratchpad-entropy", "vcxproj\scratchpad-entropy.vcxproj", "{FF8BD408-AFD8-43C6-BE98-4D03B37E840B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "jit-performance", "vcxproj\jit-performance.vcxproj", "{535F2111-FA81-4C76-A354-EDD2F9AA00E3}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "perf-simulation", "vcxproj\perf-simulation.vcxproj", "{F1FC7AC0-2773-4A57-AFA7-56BB07216AA2}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "runtime-distr", "vcxproj\runtime-distr.vcxproj", "{F207EC8C-C55F-46C0-8851-887A71574F54}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "randomx-dll", "vcxproj\randomx-dll.vcxproj", "{59560AD8-18E3-463E-A941-BBD808EC7C83}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tests", "vcxproj\tests.vcxproj", "{41F3F4DF-8113-4029-9915-FDDC44C43D49}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3346A4AD-C438-4324-8B77-47A16452954B}.Debug|x64.ActiveCfg = Debug|x64 + {3346A4AD-C438-4324-8B77-47A16452954B}.Debug|x64.Build.0 = Debug|x64 + {3346A4AD-C438-4324-8B77-47A16452954B}.Debug|x86.ActiveCfg = Debug|Win32 + {3346A4AD-C438-4324-8B77-47A16452954B}.Debug|x86.Build.0 = Debug|Win32 + {3346A4AD-C438-4324-8B77-47A16452954B}.Release|x64.ActiveCfg = Release|x64 + {3346A4AD-C438-4324-8B77-47A16452954B}.Release|x64.Build.0 = Release|x64 + {3346A4AD-C438-4324-8B77-47A16452954B}.Release|x86.ActiveCfg = Release|Win32 + {3346A4AD-C438-4324-8B77-47A16452954B}.Release|x86.Build.0 = Release|Win32 + {CF34A7EF-7DC9-4077-94A5-76F5425EA938}.Debug|x64.ActiveCfg = Debug|x64 + {CF34A7EF-7DC9-4077-94A5-76F5425EA938}.Debug|x64.Build.0 = Debug|x64 + {CF34A7EF-7DC9-4077-94A5-76F5425EA938}.Debug|x86.ActiveCfg = Debug|Win32 + {CF34A7EF-7DC9-4077-94A5-76F5425EA938}.Debug|x86.Build.0 = Debug|Win32 + {CF34A7EF-7DC9-4077-94A5-76F5425EA938}.Release|x64.ActiveCfg = Release|x64 + {CF34A7EF-7DC9-4077-94A5-76F5425EA938}.Release|x64.Build.0 = Release|x64 + {CF34A7EF-7DC9-4077-94A5-76F5425EA938}.Release|x86.ActiveCfg = Release|Win32 + {CF34A7EF-7DC9-4077-94A5-76F5425EA938}.Release|x86.Build.0 = Release|Win32 + {E59DC709-9B12-4A53-BAF3-79398821C376}.Debug|x64.ActiveCfg = Debug|x64 + {E59DC709-9B12-4A53-BAF3-79398821C376}.Debug|x64.Build.0 = Debug|x64 + {E59DC709-9B12-4A53-BAF3-79398821C376}.Debug|x86.ActiveCfg = Debug|Win32 + {E59DC709-9B12-4A53-BAF3-79398821C376}.Debug|x86.Build.0 = Debug|Win32 + {E59DC709-9B12-4A53-BAF3-79398821C376}.Release|x64.ActiveCfg = Release|x64 + {E59DC709-9B12-4A53-BAF3-79398821C376}.Release|x64.Build.0 = Release|x64 + {E59DC709-9B12-4A53-BAF3-79398821C376}.Release|x86.ActiveCfg = Release|Win32 + {E59DC709-9B12-4A53-BAF3-79398821C376}.Release|x86.Build.0 = Release|Win32 + {0173D560-8C12-46B3-B467-0C6E7573AA0B}.Debug|x64.ActiveCfg = Debug|x64 + {0173D560-8C12-46B3-B467-0C6E7573AA0B}.Debug|x64.Build.0 = Debug|x64 + {0173D560-8C12-46B3-B467-0C6E7573AA0B}.Debug|x86.ActiveCfg = Debug|Win32 + {0173D560-8C12-46B3-B467-0C6E7573AA0B}.Debug|x86.Build.0 = Debug|Win32 + {0173D560-8C12-46B3-B467-0C6E7573AA0B}.Release|x64.ActiveCfg = Release|x64 + {0173D560-8C12-46B3-B467-0C6E7573AA0B}.Release|x64.Build.0 = Release|x64 + {0173D560-8C12-46B3-B467-0C6E7573AA0B}.Release|x86.ActiveCfg = Release|Win32 + {0173D560-8C12-46B3-B467-0C6E7573AA0B}.Release|x86.Build.0 = Release|Win32 + {1E8A2E2F-9F9F-43AA-BB19-9107FEC64A70}.Debug|x64.ActiveCfg = Debug|x64 + {1E8A2E2F-9F9F-43AA-BB19-9107FEC64A70}.Debug|x64.Build.0 = Debug|x64 + {1E8A2E2F-9F9F-43AA-BB19-9107FEC64A70}.Debug|x86.ActiveCfg = Debug|Win32 + {1E8A2E2F-9F9F-43AA-BB19-9107FEC64A70}.Debug|x86.Build.0 = Debug|Win32 + {1E8A2E2F-9F9F-43AA-BB19-9107FEC64A70}.Release|x64.ActiveCfg = Release|x64 + {1E8A2E2F-9F9F-43AA-BB19-9107FEC64A70}.Release|x64.Build.0 = Release|x64 + {1E8A2E2F-9F9F-43AA-BB19-9107FEC64A70}.Release|x86.ActiveCfg = Release|Win32 + {1E8A2E2F-9F9F-43AA-BB19-9107FEC64A70}.Release|x86.Build.0 = Release|Win32 + {83EA3E54-5D91-4E01-8EF6-C1E718334F83}.Debug|x64.ActiveCfg = Debug|x64 + {83EA3E54-5D91-4E01-8EF6-C1E718334F83}.Debug|x64.Build.0 = Debug|x64 + {83EA3E54-5D91-4E01-8EF6-C1E718334F83}.Debug|x86.ActiveCfg = Debug|Win32 + {83EA3E54-5D91-4E01-8EF6-C1E718334F83}.Debug|x86.Build.0 = Debug|Win32 + {83EA3E54-5D91-4E01-8EF6-C1E718334F83}.Release|x64.ActiveCfg = Release|x64 + {83EA3E54-5D91-4E01-8EF6-C1E718334F83}.Release|x64.Build.0 = Release|x64 + {83EA3E54-5D91-4E01-8EF6-C1E718334F83}.Release|x86.ActiveCfg = Release|Win32 + {83EA3E54-5D91-4E01-8EF6-C1E718334F83}.Release|x86.Build.0 = Release|Win32 + {44947B9C-E6B1-4C06-BD01-F8EF43B59223}.Debug|x64.ActiveCfg = Debug|x64 + {44947B9C-E6B1-4C06-BD01-F8EF43B59223}.Debug|x64.Build.0 = Debug|x64 + {44947B9C-E6B1-4C06-BD01-F8EF43B59223}.Debug|x86.ActiveCfg = Debug|Win32 + {44947B9C-E6B1-4C06-BD01-F8EF43B59223}.Debug|x86.Build.0 = Debug|Win32 + {44947B9C-E6B1-4C06-BD01-F8EF43B59223}.Release|x64.ActiveCfg = Release|x64 + {44947B9C-E6B1-4C06-BD01-F8EF43B59223}.Release|x64.Build.0 = Release|x64 + {44947B9C-E6B1-4C06-BD01-F8EF43B59223}.Release|x86.ActiveCfg = Release|Win32 + {44947B9C-E6B1-4C06-BD01-F8EF43B59223}.Release|x86.Build.0 = Release|Win32 + {3E490DEC-1874-43AA-92DA-1AC57C217EAC}.Debug|x64.ActiveCfg = Debug|x64 + {3E490DEC-1874-43AA-92DA-1AC57C217EAC}.Debug|x64.Build.0 = Debug|x64 + {3E490DEC-1874-43AA-92DA-1AC57C217EAC}.Debug|x86.ActiveCfg = Debug|Win32 + {3E490DEC-1874-43AA-92DA-1AC57C217EAC}.Debug|x86.Build.0 = Debug|Win32 + {3E490DEC-1874-43AA-92DA-1AC57C217EAC}.Release|x64.ActiveCfg = Release|x64 + {3E490DEC-1874-43AA-92DA-1AC57C217EAC}.Release|x64.Build.0 = Release|x64 + {3E490DEC-1874-43AA-92DA-1AC57C217EAC}.Release|x86.ActiveCfg = Release|Win32 + {3E490DEC-1874-43AA-92DA-1AC57C217EAC}.Release|x86.Build.0 = Release|Win32 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Debug|x64.ActiveCfg = Debug|x64 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Debug|x64.Build.0 = Debug|x64 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Debug|x86.ActiveCfg = Debug|Win32 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Debug|x86.Build.0 = Debug|Win32 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Release|x64.ActiveCfg = Release|x64 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Release|x64.Build.0 = Release|x64 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Release|x86.ActiveCfg = Release|Win32 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B}.Release|x86.Build.0 = Release|Win32 + {535F2111-FA81-4C76-A354-EDD2F9AA00E3}.Debug|x64.ActiveCfg = Debug|x64 + {535F2111-FA81-4C76-A354-EDD2F9AA00E3}.Debug|x64.Build.0 = Debug|x64 + {535F2111-FA81-4C76-A354-EDD2F9AA00E3}.Debug|x86.ActiveCfg = Debug|Win32 + {535F2111-FA81-4C76-A354-EDD2F9AA00E3}.Debug|x86.Build.0 = Debug|Win32 + {535F2111-FA81-4C76-A354-EDD2F9AA00E3}.Release|x64.ActiveCfg = Release|x64 + {535F2111-FA81-4C76-A354-EDD2F9AA00E3}.Release|x64.Build.0 = Release|x64 + {535F2111-FA81-4C76-A354-EDD2F9AA00E3}.Release|x86.ActiveCfg = Release|Win32 + {535F2111-FA81-4C76-A354-EDD2F9AA00E3}.Release|x86.Build.0 = Release|Win32 + {F1FC7AC0-2773-4A57-AFA7-56BB07216AA2}.Debug|x64.ActiveCfg = Debug|x64 + {F1FC7AC0-2773-4A57-AFA7-56BB07216AA2}.Debug|x64.Build.0 = Debug|x64 + {F1FC7AC0-2773-4A57-AFA7-56BB07216AA2}.Debug|x86.ActiveCfg = Debug|Win32 + {F1FC7AC0-2773-4A57-AFA7-56BB07216AA2}.Debug|x86.Build.0 = Debug|Win32 + {F1FC7AC0-2773-4A57-AFA7-56BB07216AA2}.Release|x64.ActiveCfg = Release|x64 + {F1FC7AC0-2773-4A57-AFA7-56BB07216AA2}.Release|x64.Build.0 = Release|x64 + {F1FC7AC0-2773-4A57-AFA7-56BB07216AA2}.Release|x86.ActiveCfg = Release|Win32 + {F1FC7AC0-2773-4A57-AFA7-56BB07216AA2}.Release|x86.Build.0 = Release|Win32 + {F207EC8C-C55F-46C0-8851-887A71574F54}.Debug|x64.ActiveCfg = Debug|x64 + {F207EC8C-C55F-46C0-8851-887A71574F54}.Debug|x64.Build.0 = Debug|x64 + {F207EC8C-C55F-46C0-8851-887A71574F54}.Debug|x86.ActiveCfg = Debug|Win32 + {F207EC8C-C55F-46C0-8851-887A71574F54}.Debug|x86.Build.0 = Debug|Win32 + {F207EC8C-C55F-46C0-8851-887A71574F54}.Release|x64.ActiveCfg = Release|x64 + {F207EC8C-C55F-46C0-8851-887A71574F54}.Release|x64.Build.0 = Release|x64 + {F207EC8C-C55F-46C0-8851-887A71574F54}.Release|x86.ActiveCfg = Release|Win32 + {F207EC8C-C55F-46C0-8851-887A71574F54}.Release|x86.Build.0 = Release|Win32 + {59560AD8-18E3-463E-A941-BBD808EC7C83}.Debug|x64.ActiveCfg = Debug|x64 + {59560AD8-18E3-463E-A941-BBD808EC7C83}.Debug|x64.Build.0 = Debug|x64 + {59560AD8-18E3-463E-A941-BBD808EC7C83}.Debug|x86.ActiveCfg = Debug|Win32 + {59560AD8-18E3-463E-A941-BBD808EC7C83}.Debug|x86.Build.0 = Debug|Win32 + {59560AD8-18E3-463E-A941-BBD808EC7C83}.Release|x64.ActiveCfg = Release|x64 + {59560AD8-18E3-463E-A941-BBD808EC7C83}.Release|x64.Build.0 = Release|x64 + {59560AD8-18E3-463E-A941-BBD808EC7C83}.Release|x86.ActiveCfg = Release|Win32 + {59560AD8-18E3-463E-A941-BBD808EC7C83}.Release|x86.Build.0 = Release|Win32 + {41F3F4DF-8113-4029-9915-FDDC44C43D49}.Debug|x64.ActiveCfg = Debug|x64 + {41F3F4DF-8113-4029-9915-FDDC44C43D49}.Debug|x64.Build.0 = Debug|x64 + {41F3F4DF-8113-4029-9915-FDDC44C43D49}.Debug|x86.ActiveCfg = Debug|Win32 + {41F3F4DF-8113-4029-9915-FDDC44C43D49}.Debug|x86.Build.0 = Debug|Win32 + {41F3F4DF-8113-4029-9915-FDDC44C43D49}.Release|x64.ActiveCfg = Release|x64 + {41F3F4DF-8113-4029-9915-FDDC44C43D49}.Release|x64.Build.0 = Release|x64 + {41F3F4DF-8113-4029-9915-FDDC44C43D49}.Release|x86.ActiveCfg = Release|Win32 + {41F3F4DF-8113-4029-9915-FDDC44C43D49}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {CF34A7EF-7DC9-4077-94A5-76F5425EA938} = {4A4A689F-86AF-41C0-A974-1080506D0923} + {E59DC709-9B12-4A53-BAF3-79398821C376} = {4A4A689F-86AF-41C0-A974-1080506D0923} + {0173D560-8C12-46B3-B467-0C6E7573AA0B} = {4A4A689F-86AF-41C0-A974-1080506D0923} + {1E8A2E2F-9F9F-43AA-BB19-9107FEC64A70} = {4A4A689F-86AF-41C0-A974-1080506D0923} + {83EA3E54-5D91-4E01-8EF6-C1E718334F83} = {4A4A689F-86AF-41C0-A974-1080506D0923} + {44947B9C-E6B1-4C06-BD01-F8EF43B59223} = {4A4A689F-86AF-41C0-A974-1080506D0923} + {3E490DEC-1874-43AA-92DA-1AC57C217EAC} = {4A4A689F-86AF-41C0-A974-1080506D0923} + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B} = {4A4A689F-86AF-41C0-A974-1080506D0923} + {535F2111-FA81-4C76-A354-EDD2F9AA00E3} = {4A4A689F-86AF-41C0-A974-1080506D0923} + {F1FC7AC0-2773-4A57-AFA7-56BB07216AA2} = {4A4A689F-86AF-41C0-A974-1080506D0923} + {F207EC8C-C55F-46C0-8851-887A71574F54} = {4A4A689F-86AF-41C0-A974-1080506D0923} + {41F3F4DF-8113-4029-9915-FDDC44C43D49} = {4A4A689F-86AF-41C0-A974-1080506D0923} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {4EBC03DB-AE37-4141-8147-692F16E0ED02} + EndGlobalSection +EndGlobal diff --git a/src/RandomX/src/aes_hash.cpp b/src/RandomX/src/aes_hash.cpp new file mode 100644 index 000000000..a3b7395bc --- /dev/null +++ b/src/RandomX/src/aes_hash.cpp @@ -0,0 +1,322 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "soft_aes.h" +#include + +//NOTE: The functions below were tuned for maximum performance +//and are not cryptographically secure outside of the scope of RandomX. +//It's not recommended to use them as general hash functions and PRNGs. + +//AesHash1R: +//state0, state1, state2, state3 = Blake2b-512("RandomX AesHash1R state") +//xkey0, xkey1 = Blake2b-256("RandomX AesHash1R xkeys") + +#define AES_HASH_1R_STATE0 0xd7983aad, 0xcc82db47, 0x9fa856de, 0x92b52c0d +#define AES_HASH_1R_STATE1 0xace78057, 0xf59e125a, 0x15c7b798, 0x338d996e +#define AES_HASH_1R_STATE2 0xe8a07ce4, 0x5079506b, 0xae62c7d0, 0x6a770017 +#define AES_HASH_1R_STATE3 0x7e994948, 0x79a10005, 0x07ad828d, 0x630a240c + +#define AES_HASH_1R_XKEY0 0x06890201, 0x90dc56bf, 0x8b24949f, 0xf6fa8389 +#define AES_HASH_1R_XKEY1 0xed18f99b, 0xee1043c6, 0x51f4e03c, 0x61b263d1 + +/* + Calculate a 512-bit hash of 'input' using 4 lanes of AES. + The input is treated as a set of round keys for the encryption + of the initial state. + + 'inputSize' must be a multiple of 64. + + For a 2 MiB input, this has the same security as 32768-round + AES encryption. + + Hashing throughput: >20 GiB/s per CPU core with hardware AES +*/ +template +void hashAes1Rx4(const void *input, size_t inputSize, void *hash) { + assert(inputSize % 64 == 0); + const uint8_t* inptr = (uint8_t*)input; + const uint8_t* inputEnd = inptr + inputSize; + + rx_vec_i128 state0, state1, state2, state3; + rx_vec_i128 in0, in1, in2, in3; + + //intial state + state0 = rx_set_int_vec_i128(AES_HASH_1R_STATE0); + state1 = rx_set_int_vec_i128(AES_HASH_1R_STATE1); + state2 = rx_set_int_vec_i128(AES_HASH_1R_STATE2); + state3 = rx_set_int_vec_i128(AES_HASH_1R_STATE3); + + //process 64 bytes at a time in 4 lanes + while (inptr < inputEnd) { + in0 = rx_load_vec_i128((rx_vec_i128*)inptr + 0); + in1 = rx_load_vec_i128((rx_vec_i128*)inptr + 1); + in2 = rx_load_vec_i128((rx_vec_i128*)inptr + 2); + in3 = rx_load_vec_i128((rx_vec_i128*)inptr + 3); + + state0 = aesenc(state0, in0); + state1 = aesdec(state1, in1); + state2 = aesenc(state2, in2); + state3 = aesdec(state3, in3); + + inptr += 64; + } + + //two extra rounds to achieve full diffusion + rx_vec_i128 xkey0 = rx_set_int_vec_i128(AES_HASH_1R_XKEY0); + rx_vec_i128 xkey1 = rx_set_int_vec_i128(AES_HASH_1R_XKEY1); + + state0 = aesenc(state0, xkey0); + state1 = aesdec(state1, xkey0); + state2 = aesenc(state2, xkey0); + state3 = aesdec(state3, xkey0); + + state0 = aesenc(state0, xkey1); + state1 = aesdec(state1, xkey1); + state2 = aesenc(state2, xkey1); + state3 = aesdec(state3, xkey1); + + //output hash + rx_store_vec_i128((rx_vec_i128*)hash + 0, state0); + rx_store_vec_i128((rx_vec_i128*)hash + 1, state1); + rx_store_vec_i128((rx_vec_i128*)hash + 2, state2); + rx_store_vec_i128((rx_vec_i128*)hash + 3, state3); +} + +template void hashAes1Rx4(const void *input, size_t inputSize, void *hash); +template void hashAes1Rx4(const void *input, size_t inputSize, void *hash); + +//AesGenerator1R: +//key0, key1, key2, key3 = Blake2b-512("RandomX AesGenerator1R keys") + +#define AES_GEN_1R_KEY0 0xb4f44917, 0xdbb5552b, 0x62716609, 0x6daca553 +#define AES_GEN_1R_KEY1 0x0da1dc4e, 0x1725d378, 0x846a710d, 0x6d7caf07 +#define AES_GEN_1R_KEY2 0x3e20e345, 0xf4c0794f, 0x9f947ec6, 0x3f1262f1 +#define AES_GEN_1R_KEY3 0x49169154, 0x16314c88, 0xb1ba317c, 0x6aef8135 + +/* + Fill 'buffer' with pseudorandom data based on 512-bit 'state'. + The state is encrypted using a single AES round per 16 bytes of output + in 4 lanes. + + 'outputSize' must be a multiple of 64. + + The modified state is written back to 'state' to allow multiple + calls to this function. +*/ +template +void fillAes1Rx4(void *state, size_t outputSize, void *buffer) { + assert(outputSize % 64 == 0); + const uint8_t* outptr = (uint8_t*)buffer; + const uint8_t* outputEnd = outptr + outputSize; + + rx_vec_i128 state0, state1, state2, state3; + rx_vec_i128 key0, key1, key2, key3; + + key0 = rx_set_int_vec_i128(AES_GEN_1R_KEY0); + key1 = rx_set_int_vec_i128(AES_GEN_1R_KEY1); + key2 = rx_set_int_vec_i128(AES_GEN_1R_KEY2); + key3 = rx_set_int_vec_i128(AES_GEN_1R_KEY3); + + state0 = rx_load_vec_i128((rx_vec_i128*)state + 0); + state1 = rx_load_vec_i128((rx_vec_i128*)state + 1); + state2 = rx_load_vec_i128((rx_vec_i128*)state + 2); + state3 = rx_load_vec_i128((rx_vec_i128*)state + 3); + + while (outptr < outputEnd) { + state0 = aesdec(state0, key0); + state1 = aesenc(state1, key1); + state2 = aesdec(state2, key2); + state3 = aesenc(state3, key3); + + rx_store_vec_i128((rx_vec_i128*)outptr + 0, state0); + rx_store_vec_i128((rx_vec_i128*)outptr + 1, state1); + rx_store_vec_i128((rx_vec_i128*)outptr + 2, state2); + rx_store_vec_i128((rx_vec_i128*)outptr + 3, state3); + + outptr += 64; + } + + rx_store_vec_i128((rx_vec_i128*)state + 0, state0); + rx_store_vec_i128((rx_vec_i128*)state + 1, state1); + rx_store_vec_i128((rx_vec_i128*)state + 2, state2); + rx_store_vec_i128((rx_vec_i128*)state + 3, state3); +} + +template void fillAes1Rx4(void *state, size_t outputSize, void *buffer); +template void fillAes1Rx4(void *state, size_t outputSize, void *buffer); + +//AesGenerator4R: +//key0, key1, key2, key3 = Blake2b-512("RandomX AesGenerator4R keys 0-3") +//key4, key5, key6, key7 = Blake2b-512("RandomX AesGenerator4R keys 4-7") + +#define AES_GEN_4R_KEY0 0x99e5d23f, 0x2f546d2b, 0xd1833ddb, 0x6421aadd +#define AES_GEN_4R_KEY1 0xa5dfcde5, 0x06f79d53, 0xb6913f55, 0xb20e3450 +#define AES_GEN_4R_KEY2 0x171c02bf, 0x0aa4679f, 0x515e7baf, 0x5c3ed904 +#define AES_GEN_4R_KEY3 0xd8ded291, 0xcd673785, 0xe78f5d08, 0x85623763 +#define AES_GEN_4R_KEY4 0x229effb4, 0x3d518b6d, 0xe3d6a7a6, 0xb5826f73 +#define AES_GEN_4R_KEY5 0xb272b7d2, 0xe9024d4e, 0x9c10b3d9, 0xc7566bf3 +#define AES_GEN_4R_KEY6 0xf63befa7, 0x2ba9660a, 0xf765a38b, 0xf273c9e7 +#define AES_GEN_4R_KEY7 0xc0b0762d, 0x0c06d1fd, 0x915839de, 0x7a7cd609 + +template +void fillAes4Rx4(void *state, size_t outputSize, void *buffer) { + assert(outputSize % 64 == 0); + const uint8_t* outptr = (uint8_t*)buffer; + const uint8_t* outputEnd = outptr + outputSize; + + rx_vec_i128 state0, state1, state2, state3; + rx_vec_i128 key0, key1, key2, key3, key4, key5, key6, key7; + + key0 = rx_set_int_vec_i128(AES_GEN_4R_KEY0); + key1 = rx_set_int_vec_i128(AES_GEN_4R_KEY1); + key2 = rx_set_int_vec_i128(AES_GEN_4R_KEY2); + key3 = rx_set_int_vec_i128(AES_GEN_4R_KEY3); + key4 = rx_set_int_vec_i128(AES_GEN_4R_KEY4); + key5 = rx_set_int_vec_i128(AES_GEN_4R_KEY5); + key6 = rx_set_int_vec_i128(AES_GEN_4R_KEY6); + key7 = rx_set_int_vec_i128(AES_GEN_4R_KEY7); + + state0 = rx_load_vec_i128((rx_vec_i128*)state + 0); + state1 = rx_load_vec_i128((rx_vec_i128*)state + 1); + state2 = rx_load_vec_i128((rx_vec_i128*)state + 2); + state3 = rx_load_vec_i128((rx_vec_i128*)state + 3); + + while (outptr < outputEnd) { + state0 = aesdec(state0, key0); + state1 = aesenc(state1, key0); + state2 = aesdec(state2, key4); + state3 = aesenc(state3, key4); + + state0 = aesdec(state0, key1); + state1 = aesenc(state1, key1); + state2 = aesdec(state2, key5); + state3 = aesenc(state3, key5); + + state0 = aesdec(state0, key2); + state1 = aesenc(state1, key2); + state2 = aesdec(state2, key6); + state3 = aesenc(state3, key6); + + state0 = aesdec(state0, key3); + state1 = aesenc(state1, key3); + state2 = aesdec(state2, key7); + state3 = aesenc(state3, key7); + + rx_store_vec_i128((rx_vec_i128*)outptr + 0, state0); + rx_store_vec_i128((rx_vec_i128*)outptr + 1, state1); + rx_store_vec_i128((rx_vec_i128*)outptr + 2, state2); + rx_store_vec_i128((rx_vec_i128*)outptr + 3, state3); + + outptr += 64; + } +} + +template void fillAes4Rx4(void *state, size_t outputSize, void *buffer); +template void fillAes4Rx4(void *state, size_t outputSize, void *buffer); + +template +void hashAndFillAes1Rx4(void *scratchpad, size_t scratchpadSize, void *hash, void* fill_state) { + uint8_t* scratchpadPtr = (uint8_t*)scratchpad; + const uint8_t* scratchpadEnd = scratchpadPtr + scratchpadSize; + + // initial state + rx_vec_i128 hash_state0 = rx_set_int_vec_i128(AES_HASH_1R_STATE0); + rx_vec_i128 hash_state1 = rx_set_int_vec_i128(AES_HASH_1R_STATE1); + rx_vec_i128 hash_state2 = rx_set_int_vec_i128(AES_HASH_1R_STATE2); + rx_vec_i128 hash_state3 = rx_set_int_vec_i128(AES_HASH_1R_STATE3); + + const rx_vec_i128 key0 = rx_set_int_vec_i128(AES_GEN_1R_KEY0); + const rx_vec_i128 key1 = rx_set_int_vec_i128(AES_GEN_1R_KEY1); + const rx_vec_i128 key2 = rx_set_int_vec_i128(AES_GEN_1R_KEY2); + const rx_vec_i128 key3 = rx_set_int_vec_i128(AES_GEN_1R_KEY3); + + rx_vec_i128 fill_state0 = rx_load_vec_i128((rx_vec_i128*)fill_state + 0); + rx_vec_i128 fill_state1 = rx_load_vec_i128((rx_vec_i128*)fill_state + 1); + rx_vec_i128 fill_state2 = rx_load_vec_i128((rx_vec_i128*)fill_state + 2); + rx_vec_i128 fill_state3 = rx_load_vec_i128((rx_vec_i128*)fill_state + 3); + + constexpr int PREFETCH_DISTANCE = 4096; + const char* prefetchPtr = ((const char*)scratchpad) + PREFETCH_DISTANCE; + scratchpadEnd -= PREFETCH_DISTANCE; + + for (int i = 0; i < 2; ++i) { + //process 64 bytes at a time in 4 lanes + while (scratchpadPtr < scratchpadEnd) { + hash_state0 = aesenc(hash_state0, rx_load_vec_i128((rx_vec_i128*)scratchpadPtr + 0)); + hash_state1 = aesdec(hash_state1, rx_load_vec_i128((rx_vec_i128*)scratchpadPtr + 1)); + hash_state2 = aesenc(hash_state2, rx_load_vec_i128((rx_vec_i128*)scratchpadPtr + 2)); + hash_state3 = aesdec(hash_state3, rx_load_vec_i128((rx_vec_i128*)scratchpadPtr + 3)); + + fill_state0 = aesdec(fill_state0, key0); + fill_state1 = aesenc(fill_state1, key1); + fill_state2 = aesdec(fill_state2, key2); + fill_state3 = aesenc(fill_state3, key3); + + rx_store_vec_i128((rx_vec_i128*)scratchpadPtr + 0, fill_state0); + rx_store_vec_i128((rx_vec_i128*)scratchpadPtr + 1, fill_state1); + rx_store_vec_i128((rx_vec_i128*)scratchpadPtr + 2, fill_state2); + rx_store_vec_i128((rx_vec_i128*)scratchpadPtr + 3, fill_state3); + + rx_prefetch_t0(prefetchPtr); + + scratchpadPtr += 64; + prefetchPtr += 64; + } + prefetchPtr = (const char*) scratchpad; + scratchpadEnd += PREFETCH_DISTANCE; + } + + rx_store_vec_i128((rx_vec_i128*)fill_state + 0, fill_state0); + rx_store_vec_i128((rx_vec_i128*)fill_state + 1, fill_state1); + rx_store_vec_i128((rx_vec_i128*)fill_state + 2, fill_state2); + rx_store_vec_i128((rx_vec_i128*)fill_state + 3, fill_state3); + + //two extra rounds to achieve full diffusion + rx_vec_i128 xkey0 = rx_set_int_vec_i128(AES_HASH_1R_XKEY0); + rx_vec_i128 xkey1 = rx_set_int_vec_i128(AES_HASH_1R_XKEY1); + + hash_state0 = aesenc(hash_state0, xkey0); + hash_state1 = aesdec(hash_state1, xkey0); + hash_state2 = aesenc(hash_state2, xkey0); + hash_state3 = aesdec(hash_state3, xkey0); + + hash_state0 = aesenc(hash_state0, xkey1); + hash_state1 = aesdec(hash_state1, xkey1); + hash_state2 = aesenc(hash_state2, xkey1); + hash_state3 = aesdec(hash_state3, xkey1); + + //output hash + rx_store_vec_i128((rx_vec_i128*)hash + 0, hash_state0); + rx_store_vec_i128((rx_vec_i128*)hash + 1, hash_state1); + rx_store_vec_i128((rx_vec_i128*)hash + 2, hash_state2); + rx_store_vec_i128((rx_vec_i128*)hash + 3, hash_state3); +} + +template void hashAndFillAes1Rx4(void *scratchpad, size_t scratchpadSize, void *hash, void* fill_state); +template void hashAndFillAes1Rx4(void *scratchpad, size_t scratchpadSize, void *hash, void* fill_state); diff --git a/src/RandomX/src/aes_hash.hpp b/src/RandomX/src/aes_hash.hpp new file mode 100644 index 000000000..9f75f73ae --- /dev/null +++ b/src/RandomX/src/aes_hash.hpp @@ -0,0 +1,43 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include + +template +void hashAes1Rx4(const void *input, size_t inputSize, void *hash); + +template +void fillAes1Rx4(void *state, size_t outputSize, void *buffer); + +template +void fillAes4Rx4(void *state, size_t outputSize, void *buffer); + +template +void hashAndFillAes1Rx4(void *scratchpad, size_t scratchpadSize, void *hash, void* fill_state); diff --git a/src/RandomX/src/allocator.cpp b/src/RandomX/src/allocator.cpp new file mode 100644 index 000000000..4c6d86e05 --- /dev/null +++ b/src/RandomX/src/allocator.cpp @@ -0,0 +1,60 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include "allocator.hpp" +#include "intrin_portable.h" +#include "virtual_memory.hpp" +#include "common.hpp" + +namespace randomx { + + template + void* AlignedAllocator::allocMemory(size_t count) { + void *mem = rx_aligned_alloc(count, alignment); + if (mem == nullptr) + throw std::bad_alloc(); + return mem; + } + + template + void AlignedAllocator::freeMemory(void* ptr, size_t count) { + rx_aligned_free(ptr); + } + + template struct AlignedAllocator; + + void* LargePageAllocator::allocMemory(size_t count) { + return allocLargePagesMemory(count); + } + + void LargePageAllocator::freeMemory(void* ptr, size_t count) { + freePagedMemory(ptr, count); + }; + +} \ No newline at end of file diff --git a/src/RandomX/src/allocator.hpp b/src/RandomX/src/allocator.hpp new file mode 100644 index 000000000..d7aa3f95d --- /dev/null +++ b/src/RandomX/src/allocator.hpp @@ -0,0 +1,46 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include + +namespace randomx { + + template + struct AlignedAllocator { + static void* allocMemory(size_t); + static void freeMemory(void*, size_t); + }; + + struct LargePageAllocator { + static void* allocMemory(size_t); + static void freeMemory(void*, size_t); + }; + +} \ No newline at end of file diff --git a/src/RandomX/src/argon2.h b/src/RandomX/src/argon2.h new file mode 100644 index 000000000..9052f42a5 --- /dev/null +++ b/src/RandomX/src/argon2.h @@ -0,0 +1,261 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Original code from Argon2 reference source code package used under CC0 Licence + * https://github.com/P-H-C/phc-winner-argon2 + * Copyright 2015 + * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves +*/ + +#pragma once + +#include +#include +#include + +/* + * Argon2 input parameter restrictions + */ + + /* Minimum and maximum number of lanes (degree of parallelism) */ +#define ARGON2_MIN_LANES UINT32_C(1) +#define ARGON2_MAX_LANES UINT32_C(0xFFFFFF) + +/* Minimum and maximum number of threads */ +#define ARGON2_MIN_THREADS UINT32_C(1) +#define ARGON2_MAX_THREADS UINT32_C(0xFFFFFF) + +/* Number of synchronization points between lanes per pass */ +#define ARGON2_SYNC_POINTS UINT32_C(4) + +/* Minimum and maximum digest size in bytes */ +#define ARGON2_MIN_OUTLEN UINT32_C(4) +#define ARGON2_MAX_OUTLEN UINT32_C(0xFFFFFFFF) + +/* Minimum and maximum number of memory blocks (each of BLOCK_SIZE bytes) */ +#define ARGON2_MIN_MEMORY (2 * ARGON2_SYNC_POINTS) /* 2 blocks per slice */ + +#define ARGON2_MIN(a, b) ((a) < (b) ? (a) : (b)) +/* Max memory size is addressing-space/2, topping at 2^32 blocks (4 TB) */ +#define ARGON2_MAX_MEMORY_BITS \ + ARGON2_MIN(UINT32_C(32), (sizeof(void *) * CHAR_BIT - 10 - 1)) +#define ARGON2_MAX_MEMORY \ + ARGON2_MIN(UINT32_C(0xFFFFFFFF), UINT64_C(1) << ARGON2_MAX_MEMORY_BITS) + +/* Minimum and maximum number of passes */ +#define ARGON2_MIN_TIME UINT32_C(1) +#define ARGON2_MAX_TIME UINT32_C(0xFFFFFFFF) + +/* Minimum and maximum password length in bytes */ +#define ARGON2_MIN_PWD_LENGTH UINT32_C(0) +#define ARGON2_MAX_PWD_LENGTH UINT32_C(0xFFFFFFFF) + +/* Minimum and maximum associated data length in bytes */ +#define ARGON2_MIN_AD_LENGTH UINT32_C(0) +#define ARGON2_MAX_AD_LENGTH UINT32_C(0xFFFFFFFF) + +/* Minimum and maximum salt length in bytes */ +#define ARGON2_MIN_SALT_LENGTH UINT32_C(8) +#define ARGON2_MAX_SALT_LENGTH UINT32_C(0xFFFFFFFF) + +/* Minimum and maximum key length in bytes */ +#define ARGON2_MIN_SECRET UINT32_C(0) +#define ARGON2_MAX_SECRET UINT32_C(0xFFFFFFFF) + +/* Flags to determine which fields are securely wiped (default = no wipe). */ +#define ARGON2_DEFAULT_FLAGS UINT32_C(0) +#define ARGON2_FLAG_CLEAR_PASSWORD (UINT32_C(1) << 0) +#define ARGON2_FLAG_CLEAR_SECRET (UINT32_C(1) << 1) + + +/* Error codes */ +typedef enum Argon2_ErrorCodes { + ARGON2_OK = 0, + + ARGON2_OUTPUT_PTR_NULL = -1, + + ARGON2_OUTPUT_TOO_SHORT = -2, + ARGON2_OUTPUT_TOO_LONG = -3, + + ARGON2_PWD_TOO_SHORT = -4, + ARGON2_PWD_TOO_LONG = -5, + + ARGON2_SALT_TOO_SHORT = -6, + ARGON2_SALT_TOO_LONG = -7, + + ARGON2_AD_TOO_SHORT = -8, + ARGON2_AD_TOO_LONG = -9, + + ARGON2_SECRET_TOO_SHORT = -10, + ARGON2_SECRET_TOO_LONG = -11, + + ARGON2_TIME_TOO_SMALL = -12, + ARGON2_TIME_TOO_LARGE = -13, + + ARGON2_MEMORY_TOO_LITTLE = -14, + ARGON2_MEMORY_TOO_MUCH = -15, + + ARGON2_LANES_TOO_FEW = -16, + ARGON2_LANES_TOO_MANY = -17, + + ARGON2_PWD_PTR_MISMATCH = -18, /* NULL ptr with non-zero length */ + ARGON2_SALT_PTR_MISMATCH = -19, /* NULL ptr with non-zero length */ + ARGON2_SECRET_PTR_MISMATCH = -20, /* NULL ptr with non-zero length */ + ARGON2_AD_PTR_MISMATCH = -21, /* NULL ptr with non-zero length */ + + ARGON2_MEMORY_ALLOCATION_ERROR = -22, + + ARGON2_FREE_MEMORY_CBK_NULL = -23, + ARGON2_ALLOCATE_MEMORY_CBK_NULL = -24, + + ARGON2_INCORRECT_PARAMETER = -25, + ARGON2_INCORRECT_TYPE = -26, + + ARGON2_OUT_PTR_MISMATCH = -27, + + ARGON2_THREADS_TOO_FEW = -28, + ARGON2_THREADS_TOO_MANY = -29, + + ARGON2_MISSING_ARGS = -30, + + ARGON2_ENCODING_FAIL = -31, + + ARGON2_DECODING_FAIL = -32, + + ARGON2_THREAD_FAIL = -33, + + ARGON2_DECODING_LENGTH_FAIL = -34, + + ARGON2_VERIFY_MISMATCH = -35 +} argon2_error_codes; + +/* Memory allocator types --- for external allocation */ +typedef int(*allocate_fptr)(uint8_t **memory, size_t bytes_to_allocate); +typedef void(*deallocate_fptr)(uint8_t *memory, size_t bytes_to_allocate); + +/* Argon2 external data structures */ + +/* + ***** + * Context: structure to hold Argon2 inputs: + * output array and its length, + * password and its length, + * salt and its length, + * secret and its length, + * associated data and its length, + * number of passes, amount of used memory (in KBytes, can be rounded up a bit) + * number of parallel threads that will be run. + * All the parameters above affect the output hash value. + * Additionally, two function pointers can be provided to allocate and + * deallocate the memory (if NULL, memory will be allocated internally). + * Also, three flags indicate whether to erase password, secret as soon as they + * are pre-hashed (and thus not needed anymore), and the entire memory + ***** + * Simplest situation: you have output array out[8], password is stored in + * pwd[32], salt is stored in salt[16], you do not have keys nor associated + * data. You need to spend 1 GB of RAM and you run 5 passes of Argon2d with + * 4 parallel lanes. + * You want to erase the password, but you're OK with last pass not being + * erased. You want to use the default memory allocator. + * Then you initialize: + Argon2_Context(out,8,pwd,32,salt,16,NULL,0,NULL,0,5,1<<20,4,4,NULL,NULL,true,false,false,false) + */ +typedef struct Argon2_Context { + uint8_t *out; /* output array */ + uint32_t outlen; /* digest length */ + + uint8_t *pwd; /* password array */ + uint32_t pwdlen; /* password length */ + + uint8_t *salt; /* salt array */ + uint32_t saltlen; /* salt length */ + + uint8_t *secret; /* key array */ + uint32_t secretlen; /* key length */ + + uint8_t *ad; /* associated data array */ + uint32_t adlen; /* associated data length */ + + uint32_t t_cost; /* number of passes */ + uint32_t m_cost; /* amount of memory requested (KB) */ + uint32_t lanes; /* number of lanes */ + uint32_t threads; /* maximum number of threads */ + + uint32_t version; /* version number */ + + allocate_fptr allocate_cbk; /* pointer to memory allocator */ + deallocate_fptr free_cbk; /* pointer to memory deallocator */ + + uint32_t flags; /* array of bool options */ +} argon2_context; + +/* Argon2 primitive type */ +typedef enum Argon2_type { + Argon2_d = 0, + Argon2_i = 1, + Argon2_id = 2 +} argon2_type; + +/* Version of the algorithm */ +typedef enum Argon2_version { + ARGON2_VERSION_10 = 0x10, + ARGON2_VERSION_13 = 0x13, + ARGON2_VERSION_NUMBER = ARGON2_VERSION_13 +} argon2_version; + +//Argon2 instance - forward declaration +typedef struct Argon2_instance_t argon2_instance_t; + +//Argon2 position = forward declaration +typedef struct Argon2_position_t argon2_position_t; + +//Argon2 implementation function +typedef void randomx_argon2_impl(const argon2_instance_t* instance, + argon2_position_t position); + +#if defined(__cplusplus) +extern "C" { +#endif + +/* + * Function that fills the segment using previous segments also from other + * threads + * @param context current context + * @param instance Pointer to the current instance + * @param position Current position + * @pre all block pointers must be valid + */ +void randomx_argon2_fill_segment_ref(const argon2_instance_t* instance, + argon2_position_t position); + +randomx_argon2_impl *randomx_argon2_impl_ssse3(); +randomx_argon2_impl *randomx_argon2_impl_avx2(); + +#if defined(__cplusplus) +} +#endif diff --git a/src/RandomX/src/argon2_avx2.c b/src/RandomX/src/argon2_avx2.c new file mode 100644 index 000000000..213530326 --- /dev/null +++ b/src/RandomX/src/argon2_avx2.c @@ -0,0 +1,174 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Original code from Argon2 reference source code package used under CC0 Licence + * https://github.com/P-H-C/phc-winner-argon2 + * Copyright 2015 + * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves +*/ + +#include +#include +#include + +#include "argon2.h" + +void randomx_argon2_fill_segment_avx2(const argon2_instance_t* instance, + argon2_position_t position); + +randomx_argon2_impl* randomx_argon2_impl_avx2() { +#if defined(__AVX2__) + return &randomx_argon2_fill_segment_avx2; +#endif + return NULL; +} + +#if defined(__AVX2__) + +#include "argon2_core.h" + +#include "blake2/blamka-round-avx2.h" +#include "blake2/blake2-impl.h" +#include "blake2/blake2.h" + +static void fill_block(__m256i* state, const block* ref_block, + block* next_block, int with_xor) { + __m256i block_XY[ARGON2_HWORDS_IN_BLOCK]; + unsigned int i; + + if (with_xor) { + for (i = 0; i < ARGON2_HWORDS_IN_BLOCK; i++) { + state[i] = _mm256_xor_si256( + state[i], _mm256_loadu_si256((const __m256i*)ref_block->v + i)); + block_XY[i] = _mm256_xor_si256( + state[i], _mm256_loadu_si256((const __m256i*)next_block->v + i)); + } + } + else { + for (i = 0; i < ARGON2_HWORDS_IN_BLOCK; i++) { + block_XY[i] = state[i] = _mm256_xor_si256( + state[i], _mm256_loadu_si256((const __m256i*)ref_block->v + i)); + } + } + + for (i = 0; i < 4; ++i) { + BLAKE2_ROUND_1(state[8 * i + 0], state[8 * i + 4], state[8 * i + 1], state[8 * i + 5], + state[8 * i + 2], state[8 * i + 6], state[8 * i + 3], state[8 * i + 7]); + } + + for (i = 0; i < 4; ++i) { + BLAKE2_ROUND_2(state[0 + i], state[4 + i], state[8 + i], state[12 + i], + state[16 + i], state[20 + i], state[24 + i], state[28 + i]); + } + + for (i = 0; i < ARGON2_HWORDS_IN_BLOCK; i++) { + state[i] = _mm256_xor_si256(state[i], block_XY[i]); + _mm256_storeu_si256((__m256i*)next_block->v + i, state[i]); + } +} + +void randomx_argon2_fill_segment_avx2(const argon2_instance_t* instance, + argon2_position_t position) { + block* ref_block = NULL, * curr_block = NULL; + block address_block, input_block; + uint64_t pseudo_rand, ref_index, ref_lane; + uint32_t prev_offset, curr_offset; + uint32_t starting_index, i; + __m256i state[ARGON2_HWORDS_IN_BLOCK]; + + if (instance == NULL) { + return; + } + + starting_index = 0; + + if ((0 == position.pass) && (0 == position.slice)) { + starting_index = 2; /* we have already generated the first two blocks */ + } + + /* Offset of the current block */ + curr_offset = position.lane * instance->lane_length + + position.slice * instance->segment_length + starting_index; + + if (0 == curr_offset % instance->lane_length) { + /* Last block in this lane */ + prev_offset = curr_offset + instance->lane_length - 1; + } + else { + /* Previous block */ + prev_offset = curr_offset - 1; + } + + memcpy(state, ((instance->memory + prev_offset)->v), ARGON2_BLOCK_SIZE); + + for (i = starting_index; i < instance->segment_length; + ++i, ++curr_offset, ++prev_offset) { + /*1.1 Rotating prev_offset if needed */ + if (curr_offset % instance->lane_length == 1) { + prev_offset = curr_offset - 1; + } + + /* 1.2 Computing the index of the reference block */ + /* 1.2.1 Taking pseudo-random value from the previous block */ + pseudo_rand = instance->memory[prev_offset].v[0]; + + /* 1.2.2 Computing the lane of the reference block */ + ref_lane = ((pseudo_rand >> 32)) % instance->lanes; + + if ((position.pass == 0) && (position.slice == 0)) { + /* Can not reference other lanes yet */ + ref_lane = position.lane; + } + + /* 1.2.3 Computing the number of possible reference block within the + * lane. + */ + position.index = i; + ref_index = randomx_argon2_index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, + ref_lane == position.lane); + + /* 2 Creating a new block */ + ref_block = + instance->memory + instance->lane_length * ref_lane + ref_index; + curr_block = instance->memory + curr_offset; + if (ARGON2_VERSION_10 == instance->version) { + /* version 1.2.1 and earlier: overwrite, not XOR */ + fill_block(state, ref_block, curr_block, 0); + } + else { + if (0 == position.pass) { + fill_block(state, ref_block, curr_block, 0); + } + else { + fill_block(state, ref_block, curr_block, 1); + } + } + } +} + +#endif diff --git a/src/RandomX/src/argon2_core.c b/src/RandomX/src/argon2_core.c new file mode 100644 index 000000000..f2e7f3d1a --- /dev/null +++ b/src/RandomX/src/argon2_core.c @@ -0,0 +1,411 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Original code from Argon2 reference source code package used under CC0 Licence + * https://github.com/P-H-C/phc-winner-argon2 + * Copyright 2015 + * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves +*/ + + /*For memory wiping*/ +#ifdef _MSC_VER +#include +#include /* For SecureZeroMemory */ +#endif +#if defined __STDC_LIB_EXT1__ +#define __STDC_WANT_LIB_EXT1__ 1 +#endif +#define VC_GE_2005(version) (version >= 1400) + +#include +#include +#include + +#include "argon2_core.h" +#include "blake2/blake2.h" +#include "blake2/blake2-impl.h" + +#ifdef GENKAT +#include "genkat.h" +#endif + +#if defined(__clang__) +#if __has_attribute(optnone) +#define NOT_OPTIMIZED __attribute__((optnone)) +#endif +#elif defined(__GNUC__) +#define GCC_VERSION \ + (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) +#if GCC_VERSION >= 40400 +#define NOT_OPTIMIZED __attribute__((optimize("O0"))) +#endif +#endif +#ifndef NOT_OPTIMIZED +#define NOT_OPTIMIZED +#endif + +/***************Instance and Position constructors**********/ + +static void load_block(block *dst, const void *input) { + unsigned i; + for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i) { + dst->v[i] = load64((const uint8_t *)input + i * sizeof(dst->v[i])); + } +} + +static void store_block(void *output, const block *src) { + unsigned i; + for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i) { + store64((uint8_t *)output + i * sizeof(src->v[i]), src->v[i]); + } +} + +uint32_t randomx_argon2_index_alpha(const argon2_instance_t *instance, + const argon2_position_t *position, uint32_t pseudo_rand, + int same_lane) { + /* + * Pass 0: + * This lane : all already finished segments plus already constructed + * blocks in this segment + * Other lanes : all already finished segments + * Pass 1+: + * This lane : (SYNC_POINTS - 1) last segments plus already constructed + * blocks in this segment + * Other lanes : (SYNC_POINTS - 1) last segments + */ + uint32_t reference_area_size; + uint64_t relative_position; + uint32_t start_position, absolute_position; + + if (0 == position->pass) { + /* First pass */ + if (0 == position->slice) { + /* First slice */ + reference_area_size = + position->index - 1; /* all but the previous */ + } + else { + if (same_lane) { + /* The same lane => add current segment */ + reference_area_size = + position->slice * instance->segment_length + + position->index - 1; + } + else { + reference_area_size = + position->slice * instance->segment_length + + ((position->index == 0) ? (-1) : 0); + } + } + } + else { + /* Second pass */ + if (same_lane) { + reference_area_size = instance->lane_length - + instance->segment_length + position->index - + 1; + } + else { + reference_area_size = instance->lane_length - + instance->segment_length + + ((position->index == 0) ? (-1) : 0); + } + } + + /* 1.2.4. Mapping pseudo_rand to 0.. and produce + * relative position */ + relative_position = pseudo_rand; + relative_position = relative_position * relative_position >> 32; + relative_position = reference_area_size - 1 - + (reference_area_size * relative_position >> 32); + + /* 1.2.5 Computing starting position */ + start_position = 0; + + if (0 != position->pass) { + start_position = (position->slice == ARGON2_SYNC_POINTS - 1) + ? 0 + : (position->slice + 1) * instance->segment_length; + } + + /* 1.2.6. Computing absolute position */ + absolute_position = (start_position + relative_position) % + instance->lane_length; /* absolute position */ + return absolute_position; +} + +/* Single-threaded version for p=1 case */ +static int fill_memory_blocks_st(argon2_instance_t *instance) { + uint32_t r, s, l; + + for (r = 0; r < instance->passes; ++r) { + for (s = 0; s < ARGON2_SYNC_POINTS; ++s) { + for (l = 0; l < instance->lanes; ++l) { + argon2_position_t position = { r, l, (uint8_t)s, 0 }; + //fill the segment using the selected implementation + instance->impl(instance, position); + } + } + } + return ARGON2_OK; +} + +int randomx_argon2_fill_memory_blocks(argon2_instance_t *instance) { + if (instance == NULL || instance->lanes == 0) { + return ARGON2_INCORRECT_PARAMETER; + } + return fill_memory_blocks_st(instance); +} + +int randomx_argon2_validate_inputs(const argon2_context *context) { + if (NULL == context) { + return ARGON2_INCORRECT_PARAMETER; + } + + /* Validate password (required param) */ + if (NULL == context->pwd) { + if (0 != context->pwdlen) { + return ARGON2_PWD_PTR_MISMATCH; + } + } + + if (ARGON2_MIN_PWD_LENGTH > context->pwdlen) { + return ARGON2_PWD_TOO_SHORT; + } + + if (ARGON2_MAX_PWD_LENGTH < context->pwdlen) { + return ARGON2_PWD_TOO_LONG; + } + + /* Validate salt (required param) */ + if (NULL == context->salt) { + if (0 != context->saltlen) { + return ARGON2_SALT_PTR_MISMATCH; + } + } + + if (ARGON2_MIN_SALT_LENGTH > context->saltlen) { + return ARGON2_SALT_TOO_SHORT; + } + + if (ARGON2_MAX_SALT_LENGTH < context->saltlen) { + return ARGON2_SALT_TOO_LONG; + } + + /* Validate secret (optional param) */ + if (NULL == context->secret) { + if (0 != context->secretlen) { + return ARGON2_SECRET_PTR_MISMATCH; + } + } + else { + if (ARGON2_MIN_SECRET > context->secretlen) { + return ARGON2_SECRET_TOO_SHORT; + } + if (ARGON2_MAX_SECRET < context->secretlen) { + return ARGON2_SECRET_TOO_LONG; + } + } + + /* Validate associated data (optional param) */ + if (NULL == context->ad) { + if (0 != context->adlen) { + return ARGON2_AD_PTR_MISMATCH; + } + } + else { + if (ARGON2_MIN_AD_LENGTH > context->adlen) { + return ARGON2_AD_TOO_SHORT; + } + if (ARGON2_MAX_AD_LENGTH < context->adlen) { + return ARGON2_AD_TOO_LONG; + } + } + + /* Validate memory cost */ + if (ARGON2_MIN_MEMORY > context->m_cost) { + return ARGON2_MEMORY_TOO_LITTLE; + } + + if (ARGON2_MAX_MEMORY < context->m_cost) { + return ARGON2_MEMORY_TOO_MUCH; + } + + if (context->m_cost < 8 * context->lanes) { + return ARGON2_MEMORY_TOO_LITTLE; + } + + /* Validate time cost */ + if (ARGON2_MIN_TIME > context->t_cost) { + return ARGON2_TIME_TOO_SMALL; + } + + if (ARGON2_MAX_TIME < context->t_cost) { + return ARGON2_TIME_TOO_LARGE; + } + + /* Validate lanes */ + if (ARGON2_MIN_LANES > context->lanes) { + return ARGON2_LANES_TOO_FEW; + } + + if (ARGON2_MAX_LANES < context->lanes) { + return ARGON2_LANES_TOO_MANY; + } + + /* Validate threads */ + if (ARGON2_MIN_THREADS > context->threads) { + return ARGON2_THREADS_TOO_FEW; + } + + if (ARGON2_MAX_THREADS < context->threads) { + return ARGON2_THREADS_TOO_MANY; + } + + if (NULL != context->allocate_cbk && NULL == context->free_cbk) { + return ARGON2_FREE_MEMORY_CBK_NULL; + } + + if (NULL == context->allocate_cbk && NULL != context->free_cbk) { + return ARGON2_ALLOCATE_MEMORY_CBK_NULL; + } + + return ARGON2_OK; +} + +void rxa2_fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) { + uint32_t l; + /* Make the first and second block in each lane as G(H0||0||i) or + G(H0||1||i) */ + uint8_t blockhash_bytes[ARGON2_BLOCK_SIZE]; + for (l = 0; l < instance->lanes; ++l) { + + store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 0); + store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH + 4, l); + blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash, + ARGON2_PREHASH_SEED_LENGTH); + load_block(&instance->memory[l * instance->lane_length + 0], + blockhash_bytes); + + store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 1); + blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash, + ARGON2_PREHASH_SEED_LENGTH); + load_block(&instance->memory[l * instance->lane_length + 1], + blockhash_bytes); + } +} + +void rxa2_initial_hash(uint8_t *blockhash, argon2_context *context, argon2_type type) { + blake2b_state BlakeHash; + uint8_t value[sizeof(uint32_t)]; + + if (NULL == context || NULL == blockhash) { + return; + } + + blake2b_init(&BlakeHash, ARGON2_PREHASH_DIGEST_LENGTH); + + store32(&value, context->lanes); + blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + + store32(&value, context->outlen); + blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + + store32(&value, context->m_cost); + blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + + store32(&value, context->t_cost); + blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + + store32(&value, context->version); + blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + + store32(&value, (uint32_t)type); + blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + + store32(&value, context->pwdlen); + blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + + if (context->pwd != NULL) { + blake2b_update(&BlakeHash, (const uint8_t *)context->pwd, + context->pwdlen); + } + + store32(&value, context->saltlen); + blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + + if (context->salt != NULL) { + blake2b_update(&BlakeHash, (const uint8_t *)context->salt, context->saltlen); + } + + store32(&value, context->secretlen); + blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + + if (context->secret != NULL) { + blake2b_update(&BlakeHash, (const uint8_t *)context->secret, + context->secretlen); + } + + store32(&value, context->adlen); + blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + + if (context->ad != NULL) { + blake2b_update(&BlakeHash, (const uint8_t *)context->ad, + context->adlen); + } + + blake2b_final(&BlakeHash, blockhash, ARGON2_PREHASH_DIGEST_LENGTH); +} + +int randomx_argon2_initialize(argon2_instance_t *instance, argon2_context *context) { + uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH]; + int result = ARGON2_OK; + + if (instance == NULL || context == NULL) + return ARGON2_INCORRECT_PARAMETER; + instance->context_ptr = context; + + /* 1. Memory allocation */ + //RandomX takes care of memory allocation + + /* 2. Initial hashing */ + /* H_0 + 8 extra bytes to produce the first blocks */ + /* uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH]; */ + /* Hashing all inputs */ + rxa2_initial_hash(blockhash, context, instance->type); + /* Zeroing 8 extra bytes */ + /*rxa2_clear_internal_memory(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, + ARGON2_PREHASH_SEED_LENGTH - + ARGON2_PREHASH_DIGEST_LENGTH);*/ + + /* 3. Creating first blocks, we always have at least two blocks in a slice + */ + rxa2_fill_first_blocks(blockhash, instance); + + return ARGON2_OK; +} diff --git a/src/RandomX/src/argon2_core.h b/src/RandomX/src/argon2_core.h new file mode 100644 index 000000000..def27c6da --- /dev/null +++ b/src/RandomX/src/argon2_core.h @@ -0,0 +1,163 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Original code from Argon2 reference source code package used under CC0 Licence + * https://github.com/P-H-C/phc-winner-argon2 + * Copyright 2015 + * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves +*/ + +#ifndef ARGON2_CORE_H +#define ARGON2_CORE_H + +#include +#include "argon2.h" + +#if defined(__cplusplus) +extern "C" { +#endif + +#define CONST_CAST(x) (x)(uintptr_t) + + /**********************Argon2 internal constants*******************************/ + +enum argon2_core_constants { + /* Memory block size in bytes */ + ARGON2_BLOCK_SIZE = 1024, + ARGON2_QWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 8, + ARGON2_OWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 16, + ARGON2_HWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 32, + ARGON2_512BIT_WORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 64, + + /* Number of pseudo-random values generated by one call to Blake in Argon2i + to + generate reference block positions */ + ARGON2_ADDRESSES_IN_BLOCK = 128, + + /* Pre-hashing digest length and its extension*/ + ARGON2_PREHASH_DIGEST_LENGTH = 64, + ARGON2_PREHASH_SEED_LENGTH = 72 +}; + +/*************************Argon2 internal data types***********************/ + +/* + * Structure for the (1KB) memory block implemented as 128 64-bit words. + * Memory blocks can be copied, XORed. Internal words can be accessed by [] (no + * bounds checking). + */ +typedef struct block_ { uint64_t v[ARGON2_QWORDS_IN_BLOCK]; } block; + +/* + * Argon2 instance: memory pointer, number of passes, amount of memory, type, + * and derived values. + * Used to evaluate the number and location of blocks to construct in each + * thread + */ +typedef struct Argon2_instance_t { + block *memory; /* Memory pointer */ + uint32_t version; + uint32_t passes; /* Number of passes */ + uint32_t memory_blocks; /* Number of blocks in memory */ + uint32_t segment_length; + uint32_t lane_length; + uint32_t lanes; + uint32_t threads; + argon2_type type; + int print_internals; /* whether to print the memory blocks */ + argon2_context *context_ptr; /* points back to original context */ + randomx_argon2_impl *impl; +} argon2_instance_t; + +/* + * Argon2 position: where we construct the block right now. Used to distribute + * work between threads. + */ +typedef struct Argon2_position_t { + uint32_t pass; + uint32_t lane; + uint8_t slice; + uint32_t index; +} argon2_position_t; + +/*Struct that holds the inputs for thread handling FillSegment*/ +typedef struct Argon2_thread_data { + argon2_instance_t *instance_ptr; + argon2_position_t pos; +} argon2_thread_data; + +/*************************Argon2 core functions********************************/ + +/* + * Computes absolute position of reference block in the lane following a skewed + * distribution and using a pseudo-random value as input + * @param instance Pointer to the current instance + * @param position Pointer to the current position + * @param pseudo_rand 32-bit pseudo-random value used to determine the position + * @param same_lane Indicates if the block will be taken from the current lane. + * If so we can reference the current segment + * @pre All pointers must be valid + */ +uint32_t randomx_argon2_index_alpha(const argon2_instance_t *instance, + const argon2_position_t *position, uint32_t pseudo_rand, + int same_lane); + +/* + * Function that validates all inputs against predefined restrictions and return + * an error code + * @param context Pointer to current Argon2 context + * @return ARGON2_OK if everything is all right, otherwise one of error codes + * (all defined in + */ +int randomx_argon2_validate_inputs(const argon2_context *context); + +/* + * Function allocates memory, hashes the inputs with Blake, and creates first + * two blocks. Returns the pointer to the main memory with 2 blocks per lane + * initialized + * @param context Pointer to the Argon2 internal structure containing memory + * pointer, and parameters for time and space requirements. + * @param instance Current Argon2 instance + * @return Zero if successful, -1 if memory failed to allocate. @context->state + * will be modified if successful. + */ +int randomx_argon2_initialize(argon2_instance_t *instance, argon2_context *context); + +/* + * Function that fills the entire memory t_cost times based on the first two + * blocks in each lane + * @param instance Pointer to the current instance + * @return ARGON2_OK if successful, @context->state + */ +int randomx_argon2_fill_memory_blocks(argon2_instance_t* instance); + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/src/RandomX/src/argon2_ref.c b/src/RandomX/src/argon2_ref.c new file mode 100644 index 000000000..dc4a8049b --- /dev/null +++ b/src/RandomX/src/argon2_ref.c @@ -0,0 +1,187 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Original code from Argon2 reference source code package used under CC0 Licence + * https://github.com/P-H-C/phc-winner-argon2 + * Copyright 2015 + * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves +*/ + +#include +#include +#include + +#include "argon2.h" +#include "argon2_core.h" + +#include "blake2/blamka-round-ref.h" +#include "blake2/blake2-impl.h" +#include "blake2/blake2.h" + +static void copy_block(block* dst, const block* src) { + memcpy(dst->v, src->v, sizeof(uint64_t) * ARGON2_QWORDS_IN_BLOCK); +} + +static void xor_block(block* dst, const block* src) { + int i; + for (i = 0; i < ARGON2_QWORDS_IN_BLOCK; ++i) { + dst->v[i] ^= src->v[i]; + } +} + + /* + * Function fills a new memory block and optionally XORs the old block over the new one. + * @next_block must be initialized. + * @param prev_block Pointer to the previous block + * @param ref_block Pointer to the reference block + * @param next_block Pointer to the block to be constructed + * @param with_xor Whether to XOR into the new block (1) or just overwrite (0) + * @pre all block pointers must be valid + */ +static void fill_block(const block *prev_block, const block *ref_block, + block *next_block, int with_xor) { + block blockR, block_tmp; + unsigned i; + + copy_block(&blockR, ref_block); + xor_block(&blockR, prev_block); + copy_block(&block_tmp, &blockR); + /* Now blockR = ref_block + prev_block and block_tmp = ref_block + prev_block */ + if (with_xor) { + /* Saving the next block contents for XOR over: */ + xor_block(&block_tmp, next_block); + /* Now blockR = ref_block + prev_block and + block_tmp = ref_block + prev_block + next_block */ + } + + /* Apply Blake2 on columns of 64-bit words: (0,1,...,15) , then + (16,17,..31)... finally (112,113,...127) */ + for (i = 0; i < 8; ++i) { + BLAKE2_ROUND_NOMSG( + blockR.v[16 * i], blockR.v[16 * i + 1], blockR.v[16 * i + 2], + blockR.v[16 * i + 3], blockR.v[16 * i + 4], blockR.v[16 * i + 5], + blockR.v[16 * i + 6], blockR.v[16 * i + 7], blockR.v[16 * i + 8], + blockR.v[16 * i + 9], blockR.v[16 * i + 10], blockR.v[16 * i + 11], + blockR.v[16 * i + 12], blockR.v[16 * i + 13], blockR.v[16 * i + 14], + blockR.v[16 * i + 15]); + } + + /* Apply Blake2 on rows of 64-bit words: (0,1,16,17,...112,113), then + (2,3,18,19,...,114,115).. finally (14,15,30,31,...,126,127) */ + for (i = 0; i < 8; i++) { + BLAKE2_ROUND_NOMSG( + blockR.v[2 * i], blockR.v[2 * i + 1], blockR.v[2 * i + 16], + blockR.v[2 * i + 17], blockR.v[2 * i + 32], blockR.v[2 * i + 33], + blockR.v[2 * i + 48], blockR.v[2 * i + 49], blockR.v[2 * i + 64], + blockR.v[2 * i + 65], blockR.v[2 * i + 80], blockR.v[2 * i + 81], + blockR.v[2 * i + 96], blockR.v[2 * i + 97], blockR.v[2 * i + 112], + blockR.v[2 * i + 113]); + } + + copy_block(next_block, &block_tmp); + xor_block(next_block, &blockR); +} + +void randomx_argon2_fill_segment_ref(const argon2_instance_t *instance, + argon2_position_t position) { + block *ref_block = NULL, *curr_block = NULL; + block address_block, input_block, zero_block; + uint64_t pseudo_rand, ref_index, ref_lane; + uint32_t prev_offset, curr_offset; + uint32_t starting_index; + uint32_t i; + + if (instance == NULL) { + return; + } + + starting_index = 0; + + if ((0 == position.pass) && (0 == position.slice)) { + starting_index = 2; /* we have already generated the first two blocks */ + } + + /* Offset of the current block */ + curr_offset = position.lane * instance->lane_length + + position.slice * instance->segment_length + starting_index; + + if (0 == curr_offset % instance->lane_length) { + /* Last block in this lane */ + prev_offset = curr_offset + instance->lane_length - 1; + } + else { + /* Previous block */ + prev_offset = curr_offset - 1; + } + + for (i = starting_index; i < instance->segment_length; + ++i, ++curr_offset, ++prev_offset) { + /*1.1 Rotating prev_offset if needed */ + if (curr_offset % instance->lane_length == 1) { + prev_offset = curr_offset - 1; + } + + /* 1.2 Computing the index of the reference block */ + /* 1.2.1 Taking pseudo-random value from the previous block */ + pseudo_rand = instance->memory[prev_offset].v[0]; + + /* 1.2.2 Computing the lane of the reference block */ + ref_lane = ((pseudo_rand >> 32)) % instance->lanes; + + if ((position.pass == 0) && (position.slice == 0)) { + /* Can not reference other lanes yet */ + ref_lane = position.lane; + } + + /* 1.2.3 Computing the number of possible reference block within the + * lane. + */ + position.index = i; + ref_index = randomx_argon2_index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, + ref_lane == position.lane); + + /* 2 Creating a new block */ + ref_block = + instance->memory + instance->lane_length * ref_lane + ref_index; + curr_block = instance->memory + curr_offset; + if (ARGON2_VERSION_10 == instance->version) { + /* version 1.2.1 and earlier: overwrite, not XOR */ + fill_block(instance->memory + prev_offset, ref_block, curr_block, 0); + } + else { + if (0 == position.pass) { + fill_block(instance->memory + prev_offset, ref_block, + curr_block, 0); + } + else { + fill_block(instance->memory + prev_offset, ref_block, + curr_block, 1); + } + } + } +} diff --git a/src/RandomX/src/argon2_ssse3.c b/src/RandomX/src/argon2_ssse3.c new file mode 100644 index 000000000..778edd7de --- /dev/null +++ b/src/RandomX/src/argon2_ssse3.c @@ -0,0 +1,182 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Original code from Argon2 reference source code package used under CC0 Licence + * https://github.com/P-H-C/phc-winner-argon2 + * Copyright 2015 + * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves +*/ + +#include +#include +#include + +#include "argon2.h" + +#if defined(_MSC_VER) //MSVC doesn't define SSSE3 +#define __SSSE3__ +#endif + +void randomx_argon2_fill_segment_ssse3(const argon2_instance_t* instance, + argon2_position_t position); + +randomx_argon2_impl* randomx_argon2_impl_ssse3() { +#if defined(__SSSE3__) + return &randomx_argon2_fill_segment_ssse3; +#endif + return NULL; +} + +#if defined(__SSSE3__) + +#include /* for _mm_shuffle_epi8 and _mm_alignr_epi8 */ + +#include "argon2_core.h" + +#include "blake2/blamka-round-ssse3.h" +#include "blake2/blake2-impl.h" +#include "blake2/blake2.h" + +static void fill_block(__m128i* state, const block* ref_block, + block* next_block, int with_xor) { + __m128i block_XY[ARGON2_OWORDS_IN_BLOCK]; + unsigned int i; + + if (with_xor) { + for (i = 0; i < ARGON2_OWORDS_IN_BLOCK; i++) { + state[i] = _mm_xor_si128( + state[i], _mm_loadu_si128((const __m128i*)ref_block->v + i)); + block_XY[i] = _mm_xor_si128( + state[i], _mm_loadu_si128((const __m128i*)next_block->v + i)); + } + } + else { + for (i = 0; i < ARGON2_OWORDS_IN_BLOCK; i++) { + block_XY[i] = state[i] = _mm_xor_si128( + state[i], _mm_loadu_si128((const __m128i*)ref_block->v + i)); + } + } + + for (i = 0; i < 8; ++i) { + BLAKE2_ROUND(state[8 * i + 0], state[8 * i + 1], state[8 * i + 2], + state[8 * i + 3], state[8 * i + 4], state[8 * i + 5], + state[8 * i + 6], state[8 * i + 7]); + } + + for (i = 0; i < 8; ++i) { + BLAKE2_ROUND(state[8 * 0 + i], state[8 * 1 + i], state[8 * 2 + i], + state[8 * 3 + i], state[8 * 4 + i], state[8 * 5 + i], + state[8 * 6 + i], state[8 * 7 + i]); + } + + for (i = 0; i < ARGON2_OWORDS_IN_BLOCK; i++) { + state[i] = _mm_xor_si128(state[i], block_XY[i]); + _mm_storeu_si128((__m128i*)next_block->v + i, state[i]); + } +} + +void randomx_argon2_fill_segment_ssse3(const argon2_instance_t* instance, + argon2_position_t position) { + block* ref_block = NULL, * curr_block = NULL; + block address_block, input_block; + uint64_t pseudo_rand, ref_index, ref_lane; + uint32_t prev_offset, curr_offset; + uint32_t starting_index, i; + __m128i state[ARGON2_OWORDS_IN_BLOCK]; + + if (instance == NULL) { + return; + } + + starting_index = 0; + + if ((0 == position.pass) && (0 == position.slice)) { + starting_index = 2; /* we have already generated the first two blocks */ + } + + /* Offset of the current block */ + curr_offset = position.lane * instance->lane_length + + position.slice * instance->segment_length + starting_index; + + if (0 == curr_offset % instance->lane_length) { + /* Last block in this lane */ + prev_offset = curr_offset + instance->lane_length - 1; + } + else { + /* Previous block */ + prev_offset = curr_offset - 1; + } + + memcpy(state, ((instance->memory + prev_offset)->v), ARGON2_BLOCK_SIZE); + + for (i = starting_index; i < instance->segment_length; + ++i, ++curr_offset, ++prev_offset) { + /*1.1 Rotating prev_offset if needed */ + if (curr_offset % instance->lane_length == 1) { + prev_offset = curr_offset - 1; + } + + /* 1.2 Computing the index of the reference block */ + /* 1.2.1 Taking pseudo-random value from the previous block */ + pseudo_rand = instance->memory[prev_offset].v[0]; + + /* 1.2.2 Computing the lane of the reference block */ + ref_lane = ((pseudo_rand >> 32)) % instance->lanes; + + if ((position.pass == 0) && (position.slice == 0)) { + /* Can not reference other lanes yet */ + ref_lane = position.lane; + } + + /* 1.2.3 Computing the number of possible reference block within the + * lane. + */ + position.index = i; + ref_index = randomx_argon2_index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, + ref_lane == position.lane); + + /* 2 Creating a new block */ + ref_block = + instance->memory + instance->lane_length * ref_lane + ref_index; + curr_block = instance->memory + curr_offset; + if (ARGON2_VERSION_10 == instance->version) { + /* version 1.2.1 and earlier: overwrite, not XOR */ + fill_block(state, ref_block, curr_block, 0); + } + else { + if (0 == position.pass) { + fill_block(state, ref_block, curr_block, 0); + } + else { + fill_block(state, ref_block, curr_block, 1); + } + } + } +} + +#endif diff --git a/src/RandomX/src/asm/configuration.asm b/src/RandomX/src/asm/configuration.asm new file mode 100644 index 000000000..794d7ad01 --- /dev/null +++ b/src/RandomX/src/asm/configuration.asm @@ -0,0 +1,48 @@ +; File start: ..\src\configuration.h +RANDOMX_ARGON_MEMORY EQU 262144t +RANDOMX_ARGON_ITERATIONS EQU 3t +RANDOMX_ARGON_LANES EQU 1t +RANDOMX_ARGON_SALT TEXTEQU <"RandomX\x03"> +RANDOMX_CACHE_ACCESSES EQU 8t +RANDOMX_SUPERSCALAR_LATENCY EQU 170t +RANDOMX_DATASET_BASE_SIZE EQU 2147483648t +RANDOMX_DATASET_EXTRA_SIZE EQU 33554368t +RANDOMX_PROGRAM_SIZE EQU 256t +RANDOMX_PROGRAM_ITERATIONS EQU 2048t +RANDOMX_PROGRAM_COUNT EQU 8t +RANDOMX_SCRATCHPAD_L3 EQU 2097152t +RANDOMX_SCRATCHPAD_L2 EQU 262144t +RANDOMX_SCRATCHPAD_L1 EQU 16384t +RANDOMX_JUMP_BITS EQU 8t +RANDOMX_JUMP_OFFSET EQU 8t +RANDOMX_FREQ_IADD_RS EQU 16t +RANDOMX_FREQ_IADD_M EQU 7t +RANDOMX_FREQ_ISUB_R EQU 16t +RANDOMX_FREQ_ISUB_M EQU 7t +RANDOMX_FREQ_IMUL_R EQU 16t +RANDOMX_FREQ_IMUL_M EQU 4t +RANDOMX_FREQ_IMULH_R EQU 4t +RANDOMX_FREQ_IMULH_M EQU 1t +RANDOMX_FREQ_ISMULH_R EQU 4t +RANDOMX_FREQ_ISMULH_M EQU 1t +RANDOMX_FREQ_IMUL_RCP EQU 8t +RANDOMX_FREQ_INEG_R EQU 2t +RANDOMX_FREQ_IXOR_R EQU 15t +RANDOMX_FREQ_IXOR_M EQU 5t +RANDOMX_FREQ_IROR_R EQU 8t +RANDOMX_FREQ_IROL_R EQU 2t +RANDOMX_FREQ_ISWAP_R EQU 4t +RANDOMX_FREQ_FSWAP_R EQU 4t +RANDOMX_FREQ_FADD_R EQU 16t +RANDOMX_FREQ_FADD_M EQU 5t +RANDOMX_FREQ_FSUB_R EQU 16t +RANDOMX_FREQ_FSUB_M EQU 5t +RANDOMX_FREQ_FSCAL_R EQU 6t +RANDOMX_FREQ_FMUL_R EQU 32t +RANDOMX_FREQ_FDIV_M EQU 4t +RANDOMX_FREQ_FSQRT_R EQU 6t +RANDOMX_FREQ_CBRANCH EQU 25t +RANDOMX_FREQ_CFROUND EQU 1t +RANDOMX_FREQ_ISTORE EQU 16t +RANDOMX_FREQ_NOP EQU 0t +; File end: ..\src\configuration.h diff --git a/src/RandomX/src/asm/program_epilogue_linux.inc b/src/RandomX/src/asm/program_epilogue_linux.inc new file mode 100644 index 000000000..eaacae547 --- /dev/null +++ b/src/RandomX/src/asm/program_epilogue_linux.inc @@ -0,0 +1,10 @@ + ;# restore callee-saved registers - System V AMD64 ABI + pop r15 + pop r14 + pop r13 + pop r12 + pop rbp + pop rbx + + ;# program finished + ret 0 \ No newline at end of file diff --git a/src/RandomX/src/asm/program_epilogue_store.inc b/src/RandomX/src/asm/program_epilogue_store.inc new file mode 100644 index 000000000..b94fa4d99 --- /dev/null +++ b/src/RandomX/src/asm/program_epilogue_store.inc @@ -0,0 +1,19 @@ + ;# save VM register values + pop rcx + mov qword ptr [rcx+0], r8 + mov qword ptr [rcx+8], r9 + mov qword ptr [rcx+16], r10 + mov qword ptr [rcx+24], r11 + mov qword ptr [rcx+32], r12 + mov qword ptr [rcx+40], r13 + mov qword ptr [rcx+48], r14 + mov qword ptr [rcx+56], r15 + movdqa xmmword ptr [rcx+64], xmm0 + movdqa xmmword ptr [rcx+80], xmm1 + movdqa xmmword ptr [rcx+96], xmm2 + movdqa xmmword ptr [rcx+112], xmm3 + lea rcx, [rcx+64] + movdqa xmmword ptr [rcx+64], xmm4 + movdqa xmmword ptr [rcx+80], xmm5 + movdqa xmmword ptr [rcx+96], xmm6 + movdqa xmmword ptr [rcx+112], xmm7 \ No newline at end of file diff --git a/src/RandomX/src/asm/program_epilogue_win64.inc b/src/RandomX/src/asm/program_epilogue_win64.inc new file mode 100644 index 000000000..8d70a0a3f --- /dev/null +++ b/src/RandomX/src/asm/program_epilogue_win64.inc @@ -0,0 +1,24 @@ + ;# restore callee-saved registers - Microsoft x64 calling convention + movdqu xmm15, xmmword ptr [rsp] + movdqu xmm14, xmmword ptr [rsp+16] + movdqu xmm13, xmmword ptr [rsp+32] + movdqu xmm12, xmmword ptr [rsp+48] + movdqu xmm11, xmmword ptr [rsp+64] + add rsp, 80 + movdqu xmm10, xmmword ptr [rsp] + movdqu xmm9, xmmword ptr [rsp+16] + movdqu xmm8, xmmword ptr [rsp+32] + movdqu xmm7, xmmword ptr [rsp+48] + movdqu xmm6, xmmword ptr [rsp+64] + add rsp, 80 + pop r15 + pop r14 + pop r13 + pop r12 + pop rsi + pop rdi + pop rbp + pop rbx + + ;# program finished + ret diff --git a/src/RandomX/src/asm/program_loop_load.inc b/src/RandomX/src/asm/program_loop_load.inc new file mode 100644 index 000000000..c29332313 --- /dev/null +++ b/src/RandomX/src/asm/program_loop_load.inc @@ -0,0 +1,28 @@ + lea rcx, [rsi+rax] + push rcx + xor r8, qword ptr [rcx+0] + xor r9, qword ptr [rcx+8] + xor r10, qword ptr [rcx+16] + xor r11, qword ptr [rcx+24] + xor r12, qword ptr [rcx+32] + xor r13, qword ptr [rcx+40] + xor r14, qword ptr [rcx+48] + xor r15, qword ptr [rcx+56] + lea rcx, [rsi+rdx] + push rcx + cvtdq2pd xmm0, qword ptr [rcx+0] + cvtdq2pd xmm1, qword ptr [rcx+8] + cvtdq2pd xmm2, qword ptr [rcx+16] + cvtdq2pd xmm3, qword ptr [rcx+24] + cvtdq2pd xmm4, qword ptr [rcx+32] + cvtdq2pd xmm5, qword ptr [rcx+40] + cvtdq2pd xmm6, qword ptr [rcx+48] + cvtdq2pd xmm7, qword ptr [rcx+56] + andps xmm4, xmm13 + andps xmm5, xmm13 + andps xmm6, xmm13 + andps xmm7, xmm13 + orps xmm4, xmm14 + orps xmm5, xmm14 + orps xmm6, xmm14 + orps xmm7, xmm14 diff --git a/src/RandomX/src/asm/program_loop_store.inc b/src/RandomX/src/asm/program_loop_store.inc new file mode 100644 index 000000000..1ba1635c6 --- /dev/null +++ b/src/RandomX/src/asm/program_loop_store.inc @@ -0,0 +1,18 @@ + pop rcx + mov qword ptr [rcx+0], r8 + mov qword ptr [rcx+8], r9 + mov qword ptr [rcx+16], r10 + mov qword ptr [rcx+24], r11 + mov qword ptr [rcx+32], r12 + mov qword ptr [rcx+40], r13 + mov qword ptr [rcx+48], r14 + mov qword ptr [rcx+56], r15 + pop rcx + xorpd xmm0, xmm4 + xorpd xmm1, xmm5 + xorpd xmm2, xmm6 + xorpd xmm3, xmm7 + movapd xmmword ptr [rcx+0], xmm0 + movapd xmmword ptr [rcx+16], xmm1 + movapd xmmword ptr [rcx+32], xmm2 + movapd xmmword ptr [rcx+48], xmm3 diff --git a/src/RandomX/src/asm/program_prologue_linux.inc b/src/RandomX/src/asm/program_prologue_linux.inc new file mode 100644 index 000000000..033584a7e --- /dev/null +++ b/src/RandomX/src/asm/program_prologue_linux.inc @@ -0,0 +1,35 @@ + ;# callee-saved registers - System V AMD64 ABI + push rbx + push rbp + push r12 + push r13 + push r14 + push r15 + + ;# function arguments + mov rbx, rcx ;# loop counter + push rdi ;# RegisterFile& registerFile + mov rcx, rdi + mov rbp, qword ptr [rsi] ;# "mx", "ma" + mov rdi, qword ptr [rsi+8] ;# uint8_t* dataset + mov rsi, rdx ;# uint8_t* scratchpad + + mov rax, rbp + ror rbp, 32 + + ;# zero integer registers + xor r8, r8 + xor r9, r9 + xor r10, r10 + xor r11, r11 + xor r12, r12 + xor r13, r13 + xor r14, r14 + xor r15, r15 + + ;# load constant registers + lea rcx, [rcx+120] + movapd xmm8, xmmword ptr [rcx+72] + movapd xmm9, xmmword ptr [rcx+88] + movapd xmm10, xmmword ptr [rcx+104] + movapd xmm11, xmmword ptr [rcx+120] diff --git a/src/RandomX/src/asm/program_prologue_win64.inc b/src/RandomX/src/asm/program_prologue_win64.inc new file mode 100644 index 000000000..10f21d375 --- /dev/null +++ b/src/RandomX/src/asm/program_prologue_win64.inc @@ -0,0 +1,48 @@ + ;# callee-saved registers - Microsoft x64 calling convention + push rbx + push rbp + push rdi + push rsi + push r12 + push r13 + push r14 + push r15 + sub rsp, 80 + movdqu xmmword ptr [rsp+64], xmm6 + movdqu xmmword ptr [rsp+48], xmm7 + movdqu xmmword ptr [rsp+32], xmm8 + movdqu xmmword ptr [rsp+16], xmm9 + movdqu xmmword ptr [rsp+0], xmm10 + sub rsp, 80 + movdqu xmmword ptr [rsp+64], xmm11 + movdqu xmmword ptr [rsp+48], xmm12 + movdqu xmmword ptr [rsp+32], xmm13 + movdqu xmmword ptr [rsp+16], xmm14 + movdqu xmmword ptr [rsp+0], xmm15 + + ;# function arguments + push rcx ;# RegisterFile& registerFile + mov rbp, qword ptr [rdx] ;# "mx", "ma" + mov rdi, qword ptr [rdx+8] ;# uint8_t* dataset + mov rsi, r8 ;# uint8_t* scratchpad + mov rbx, r9 ;# loop counter + + mov rax, rbp + ror rbp, 32 + + ;# zero integer registers + xor r8, r8 + xor r9, r9 + xor r10, r10 + xor r11, r11 + xor r12, r12 + xor r13, r13 + xor r14, r14 + xor r15, r15 + + ;# load constant registers + lea rcx, [rcx+120] + movapd xmm8, xmmword ptr [rcx+72] + movapd xmm9, xmmword ptr [rcx+88] + movapd xmm10, xmmword ptr [rcx+104] + movapd xmm11, xmmword ptr [rcx+120] diff --git a/src/RandomX/src/asm/program_read_dataset.inc b/src/RandomX/src/asm/program_read_dataset.inc new file mode 100644 index 000000000..9c61092f9 --- /dev/null +++ b/src/RandomX/src/asm/program_read_dataset.inc @@ -0,0 +1,16 @@ + mov ecx, ebp ;# ecx = ma + and ecx, RANDOMX_DATASET_BASE_MASK + xor r8, qword ptr [rdi+rcx] + ror rbp, 32 ;# swap "ma" and "mx" + xor rbp, rax ;# modify "mx" + mov edx, ebp ;# edx = mx + and edx, RANDOMX_DATASET_BASE_MASK + prefetchnta byte ptr [rdi+rdx] + xor r9, qword ptr [rdi+rcx+8] + xor r10, qword ptr [rdi+rcx+16] + xor r11, qword ptr [rdi+rcx+24] + xor r12, qword ptr [rdi+rcx+32] + xor r13, qword ptr [rdi+rcx+40] + xor r14, qword ptr [rdi+rcx+48] + xor r15, qword ptr [rdi+rcx+56] + \ No newline at end of file diff --git a/src/RandomX/src/asm/program_read_dataset_sshash_fin.inc b/src/RandomX/src/asm/program_read_dataset_sshash_fin.inc new file mode 100644 index 000000000..f5a067d2c --- /dev/null +++ b/src/RandomX/src/asm/program_read_dataset_sshash_fin.inc @@ -0,0 +1,10 @@ + mov rbx, qword ptr [rsp+64] + xor r8, qword ptr [rsp+56] + xor r9, qword ptr [rsp+48] + xor r10, qword ptr [rsp+40] + xor r11, qword ptr [rsp+32] + xor r12, qword ptr [rsp+24] + xor r13, qword ptr [rsp+16] + xor r14, qword ptr [rsp+8] + xor r15, qword ptr [rsp+0] + add rsp, 72 \ No newline at end of file diff --git a/src/RandomX/src/asm/program_read_dataset_sshash_init.inc b/src/RandomX/src/asm/program_read_dataset_sshash_init.inc new file mode 100644 index 000000000..9491f3d2f --- /dev/null +++ b/src/RandomX/src/asm/program_read_dataset_sshash_init.inc @@ -0,0 +1,17 @@ + sub rsp, 72 + mov qword ptr [rsp+64], rbx + mov qword ptr [rsp+56], r8 + mov qword ptr [rsp+48], r9 + mov qword ptr [rsp+40], r10 + mov qword ptr [rsp+32], r11 + mov qword ptr [rsp+24], r12 + mov qword ptr [rsp+16], r13 + mov qword ptr [rsp+8], r14 + mov qword ptr [rsp+0], r15 + ror rbp, 32 ;# swap "ma" and "mx" + xor rbp, rax ;# modify "mx" + mov rbx, rbp ;# ebx = ma + shr rbx, 38 + and ebx, RANDOMX_DATASET_BASE_MASK / 64 ;# ebx = Dataset block number + ;# add ebx, datasetOffset / 64 + ;# call 32768 \ No newline at end of file diff --git a/src/RandomX/src/asm/program_sshash_constants.inc b/src/RandomX/src/asm/program_sshash_constants.inc new file mode 100644 index 000000000..53dc1755c --- /dev/null +++ b/src/RandomX/src/asm/program_sshash_constants.inc @@ -0,0 +1,24 @@ +r0_mul: + ;#/ 6364136223846793005 + db 45, 127, 149, 76, 45, 244, 81, 88 +r1_add: + ;#/ 9298411001130361340 + db 252, 161, 245, 89, 138, 151, 10, 129 +r2_add: + ;#/ 12065312585734608966 + db 70, 216, 194, 56, 223, 153, 112, 167 +r3_add: + ;#/ 9306329213124626780 + db 92, 73, 34, 191, 28, 185, 38, 129 +r4_add: + ;#/ 5281919268842080866 + db 98, 138, 159, 23, 151, 37, 77, 73 +r5_add: + ;#/ 10536153434571861004 + db 12, 236, 170, 206, 185, 239, 55, 146 +r6_add: + ;#/ 3398623926847679864 + db 120, 45, 230, 108, 116, 86, 42, 47 +r7_add: + ;#/ 9549104520008361294 + db 78, 229, 44, 182, 247, 59, 133, 132 \ No newline at end of file diff --git a/src/RandomX/src/asm/program_sshash_load.inc b/src/RandomX/src/asm/program_sshash_load.inc new file mode 100644 index 000000000..535135691 --- /dev/null +++ b/src/RandomX/src/asm/program_sshash_load.inc @@ -0,0 +1,8 @@ + xor r8, qword ptr [rbx+0] + xor r9, qword ptr [rbx+8] + xor r10, qword ptr [rbx+16] + xor r11, qword ptr [rbx+24] + xor r12, qword ptr [rbx+32] + xor r13, qword ptr [rbx+40] + xor r14, qword ptr [rbx+48] + xor r15, qword ptr [rbx+56] \ No newline at end of file diff --git a/src/RandomX/src/asm/program_sshash_prefetch.inc b/src/RandomX/src/asm/program_sshash_prefetch.inc new file mode 100644 index 000000000..26efb5159 --- /dev/null +++ b/src/RandomX/src/asm/program_sshash_prefetch.inc @@ -0,0 +1,4 @@ + and rbx, RANDOMX_CACHE_MASK + shl rbx, 6 + add rbx, rdi + prefetchnta byte ptr [rbx] \ No newline at end of file diff --git a/src/RandomX/src/asm/program_xmm_constants.inc b/src/RandomX/src/asm/program_xmm_constants.inc new file mode 100644 index 000000000..296237a45 --- /dev/null +++ b/src/RandomX/src/asm/program_xmm_constants.inc @@ -0,0 +1,6 @@ +mantissaMask: + db 255, 255, 255, 255, 255, 255, 255, 0, 255, 255, 255, 255, 255, 255, 255, 0 +exp240: + db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +scaleMask: + db 0, 0, 0, 0, 0, 0, 240, 128, 0, 0, 0, 0, 0, 0, 240, 128 \ No newline at end of file diff --git a/src/RandomX/src/asm/randomx_reciprocal.inc b/src/RandomX/src/asm/randomx_reciprocal.inc new file mode 100644 index 000000000..e1f22fdc6 --- /dev/null +++ b/src/RandomX/src/asm/randomx_reciprocal.inc @@ -0,0 +1,7 @@ + mov edx, 1 + mov r8, rcx + xor eax, eax + bsr rcx, rcx + shl rdx, cl + div r8 + ret \ No newline at end of file diff --git a/src/RandomX/src/assembly_generator_x86.cpp b/src/RandomX/src/assembly_generator_x86.cpp new file mode 100644 index 000000000..e7e5258b7 --- /dev/null +++ b/src/RandomX/src/assembly_generator_x86.cpp @@ -0,0 +1,611 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include "assembly_generator_x86.hpp" +#include "common.hpp" +#include "reciprocal.h" +#include "program.hpp" +#include "superscalar.hpp" + +namespace randomx { + + static const char* regR[] = { "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" }; + static const char* regR32[] = { "r8d", "r9d", "r10d", "r11d", "r12d", "r13d", "r14d", "r15d" }; + static const char* regFE[] = { "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7" }; + static const char* regF[] = { "xmm0", "xmm1", "xmm2", "xmm3" }; + static const char* regE[] = { "xmm4", "xmm5", "xmm6", "xmm7" }; + static const char* regA[] = { "xmm8", "xmm9", "xmm10", "xmm11" }; + + static const char* tempRegx = "xmm12"; + static const char* mantissaMaskReg = "xmm13"; + static const char* exponentMaskReg = "xmm14"; + static const char* scaleMaskReg = "xmm15"; + static const char* regIc = "rbx"; + static const char* regIc32 = "ebx"; + static const char* regIc8 = "bl"; + static const char* regScratchpadAddr = "rsi"; + + void AssemblyGeneratorX86::generateProgram(Program& prog) { + for (unsigned i = 0; i < RegistersCount; ++i) { + registerUsage[i] = -1; + } + asmCode.str(std::string()); //clear + for (unsigned i = 0; i < prog.getSize(); ++i) { + asmCode << "randomx_isn_" << i << ":" << std::endl; + Instruction& instr = prog(i); + instr.src %= RegistersCount; + instr.dst %= RegistersCount; + generateCode(instr, i); + } + } + + void AssemblyGeneratorX86::generateAsm(SuperscalarProgram& prog) { + asmCode.str(std::string()); //clear +#ifdef RANDOMX_ALIGN + asmCode << "ALIGN 16" << std::endl; +#endif + for (unsigned i = 0; i < prog.getSize(); ++i) { + Instruction& instr = prog(i); + switch ((SuperscalarInstructionType)instr.opcode) + { + case SuperscalarInstructionType::ISUB_R: + asmCode << "sub " << regR[instr.dst] << ", " << regR[instr.src] << std::endl; + break; + case SuperscalarInstructionType::IXOR_R: + asmCode << "xor " << regR[instr.dst] << ", " << regR[instr.src] << std::endl; + break; + case SuperscalarInstructionType::IADD_RS: + asmCode << "lea " << regR[instr.dst] << ", [" << regR[instr.dst] << "+" << regR[instr.src] << "*" << (1 << (instr.getModShift())) << "]" << std::endl; + break; + case SuperscalarInstructionType::IMUL_R: + asmCode << "imul " << regR[instr.dst] << ", " << regR[instr.src] << std::endl; + break; + case SuperscalarInstructionType::IROR_C: + asmCode << "ror " << regR[instr.dst] << ", " << instr.getImm32() << std::endl; + break; + case SuperscalarInstructionType::IADD_C7: + asmCode << "add " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl; + break; + case SuperscalarInstructionType::IXOR_C7: + asmCode << "xor " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl; + break; + case SuperscalarInstructionType::IADD_C8: + asmCode << "add " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl; +#ifdef RANDOMX_ALIGN + asmCode << "nop" << std::endl; +#endif + break; + case SuperscalarInstructionType::IXOR_C8: + asmCode << "xor " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl; +#ifdef RANDOMX_ALIGN + asmCode << "nop" << std::endl; +#endif + break; + case SuperscalarInstructionType::IADD_C9: + asmCode << "add " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl; +#ifdef RANDOMX_ALIGN + asmCode << "xchg ax, ax ;nop" << std::endl; +#endif + break; + case SuperscalarInstructionType::IXOR_C9: + asmCode << "xor " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl; +#ifdef RANDOMX_ALIGN + asmCode << "xchg ax, ax ;nop" << std::endl; +#endif + break; + case SuperscalarInstructionType::IMULH_R: + asmCode << "mov rax, " << regR[instr.dst] << std::endl; + asmCode << "mul " << regR[instr.src] << std::endl; + asmCode << "mov " << regR[instr.dst] << ", rdx" << std::endl; + break; + case SuperscalarInstructionType::ISMULH_R: + asmCode << "mov rax, " << regR[instr.dst] << std::endl; + asmCode << "imul " << regR[instr.src] << std::endl; + asmCode << "mov " << regR[instr.dst] << ", rdx" << std::endl; + break; + case SuperscalarInstructionType::IMUL_RCP: + asmCode << "mov rax, " << (int64_t)randomx_reciprocal(instr.getImm32()) << std::endl; + asmCode << "imul " << regR[instr.dst] << ", rax" << std::endl; + break; + default: + UNREACHABLE; + } + } + } + + void AssemblyGeneratorX86::generateC(SuperscalarProgram& prog) { + asmCode.str(std::string()); //clear + asmCode << "#include " << std::endl; + asmCode << "#if defined(__SIZEOF_INT128__)" << std::endl; + asmCode << " static inline uint64_t mulh(uint64_t a, uint64_t b) {" << std::endl; + asmCode << " return ((unsigned __int128)a * b) >> 64;" << std::endl; + asmCode << " }" << std::endl; + asmCode << " static inline int64_t smulh(int64_t a, int64_t b) {" << std::endl; + asmCode << " return ((__int128)a * b) >> 64;" << std::endl; + asmCode << " }" << std::endl; + asmCode << " #define HAVE_MULH" << std::endl; + asmCode << " #define HAVE_SMULH" << std::endl; + asmCode << "#endif" << std::endl; + asmCode << "#if defined(_MSC_VER)" << std::endl; + asmCode << " #define HAS_VALUE(X) X ## 0" << std::endl; + asmCode << " #define EVAL_DEFINE(X) HAS_VALUE(X)" << std::endl; + asmCode << " #include " << std::endl; + asmCode << " #include " << std::endl; + asmCode << " static __inline uint64_t rotr(uint64_t x , int c) {" << std::endl; + asmCode << " return _rotr64(x, c);" << std::endl; + asmCode << " }" << std::endl; + asmCode << " #define HAVE_ROTR" << std::endl; + asmCode << " #if EVAL_DEFINE(__MACHINEARM64_X64(1))" << std::endl; + asmCode << " static __inline uint64_t mulh(uint64_t a, uint64_t b) {" << std::endl; + asmCode << " return __umulh(a, b);" << std::endl; + asmCode << " }" << std::endl; + asmCode << " #define HAVE_MULH" << std::endl; + asmCode << " #endif" << std::endl; + asmCode << " #if EVAL_DEFINE(__MACHINEX64(1))" << std::endl; + asmCode << " static __inline int64_t smulh(int64_t a, int64_t b) {" << std::endl; + asmCode << " int64_t hi;" << std::endl; + asmCode << " _mul128(a, b, &hi);" << std::endl; + asmCode << " return hi;" << std::endl; + asmCode << " }" << std::endl; + asmCode << " #define HAVE_SMULH" << std::endl; + asmCode << " #endif" << std::endl; + asmCode << "#endif" << std::endl; + asmCode << "#ifndef HAVE_ROTR" << std::endl; + asmCode << " static inline uint64_t rotr(uint64_t a, int b) {" << std::endl; + asmCode << " return (a >> b) | (a << (64 - b));" << std::endl; + asmCode << " }" << std::endl; + asmCode << " #define HAVE_ROTR" << std::endl; + asmCode << "#endif" << std::endl; + asmCode << "#if !defined(HAVE_MULH) || !defined(HAVE_SMULH) || !defined(HAVE_ROTR)" << std::endl; + asmCode << " #error \"Required functions are not defined\"" << std::endl; + asmCode << "#endif" << std::endl; + asmCode << "void superScalar(uint64_t r[8]) {" << std::endl; + asmCode << "uint64_t r8 = r[0], r9 = r[1], r10 = r[2], r11 = r[3], r12 = r[4], r13 = r[5], r14 = r[6], r15 = r[7];" << std::endl; + for (unsigned i = 0; i < prog.getSize(); ++i) { + Instruction& instr = prog(i); + switch ((SuperscalarInstructionType)instr.opcode) + { + case SuperscalarInstructionType::ISUB_R: + asmCode << regR[instr.dst] << " -= " << regR[instr.src] << ";" << std::endl; + break; + case SuperscalarInstructionType::IXOR_R: + asmCode << regR[instr.dst] << " ^= " << regR[instr.src] << ";" << std::endl; + break; + case SuperscalarInstructionType::IADD_RS: + asmCode << regR[instr.dst] << " += " << regR[instr.src] << "*" << (1 << (instr.getModShift())) << ";" << std::endl; + break; + case SuperscalarInstructionType::IMUL_R: + asmCode << regR[instr.dst] << " *= " << regR[instr.src] << ";" << std::endl; + break; + case SuperscalarInstructionType::IROR_C: + asmCode << regR[instr.dst] << " = rotr(" << regR[instr.dst] << ", " << instr.getImm32() << ");" << std::endl; + break; + case SuperscalarInstructionType::IADD_C7: + case SuperscalarInstructionType::IADD_C8: + case SuperscalarInstructionType::IADD_C9: + asmCode << regR[instr.dst] << " += " << (int32_t)instr.getImm32() << ";" << std::endl; + break; + case SuperscalarInstructionType::IXOR_C7: + case SuperscalarInstructionType::IXOR_C8: + case SuperscalarInstructionType::IXOR_C9: + asmCode << regR[instr.dst] << " ^= " << (int32_t)instr.getImm32() << ";" << std::endl; + break; + case SuperscalarInstructionType::IMULH_R: + asmCode << regR[instr.dst] << " = mulh(" << regR[instr.dst] << ", " << regR[instr.src] << ");" << std::endl; + break; + case SuperscalarInstructionType::ISMULH_R: + asmCode << regR[instr.dst] << " = smulh(" << regR[instr.dst] << ", " << regR[instr.src] << ");" << std::endl; + break; + case SuperscalarInstructionType::IMUL_RCP: + asmCode << regR[instr.dst] << " *= " << (int64_t)randomx_reciprocal(instr.getImm32()) << ";" << std::endl; + break; + default: + UNREACHABLE; + } + } + asmCode << "r[0] = r8; r[1] = r9; r[2] = r10; r[3] = r11; r[4] = r12; r[5] = r13; r[6] = r14; r[7] = r15;" << std::endl; + asmCode << "}" << std::endl; + } + + void AssemblyGeneratorX86::traceint(Instruction& instr) { + if (trace) { + asmCode << "\tpush " << regR[instr.dst] << std::endl; + } + } + + void AssemblyGeneratorX86::traceflt(Instruction& instr) { + if (trace) { + asmCode << "\tpush 0" << std::endl; + } + } + + void AssemblyGeneratorX86::tracenop(Instruction& instr) { + if (trace) { + asmCode << "\tpush 0" << std::endl; + } + } + + void AssemblyGeneratorX86::generateCode(Instruction& instr, int i) { + asmCode << "\t; " << instr; + auto generator = engine[instr.opcode]; + (this->*generator)(instr, i); + } + + void AssemblyGeneratorX86::genAddressReg(Instruction& instr, const char* reg = "eax") { + asmCode << "\tlea " << reg << ", [" << regR32[instr.src] << std::showpos << (int32_t)instr.getImm32() << std::noshowpos << "]" << std::endl; + asmCode << "\tand " << reg << ", " << ((instr.getModMem()) ? ScratchpadL1Mask : ScratchpadL2Mask) << std::endl; + } + + void AssemblyGeneratorX86::genAddressRegDst(Instruction& instr, int maskAlign = 8) { + asmCode << "\tlea eax, [" << regR32[instr.dst] << std::showpos << (int32_t)instr.getImm32() << std::noshowpos << "]" << std::endl; + int mask; + if (instr.getModCond() < StoreL3Condition) { + mask = instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask; + } + else { + mask = ScratchpadL3Mask; + } + asmCode << "\tand eax" << ", " << (mask & (-maskAlign)) << std::endl; + } + + int32_t AssemblyGeneratorX86::genAddressImm(Instruction& instr) { + return (int32_t)instr.getImm32() & ScratchpadL3Mask; + } + + void AssemblyGeneratorX86::h_IADD_RS(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if(instr.dst == RegisterNeedsDisplacement) + asmCode << "\tlea " << regR[instr.dst] << ", [" << regR[instr.dst] << "+" << regR[instr.src] << "*" << (1 << (instr.getModShift())) << std::showpos << (int32_t)instr.getImm32() << std::noshowpos << "]" << std::endl; + else + asmCode << "\tlea " << regR[instr.dst] << ", [" << regR[instr.dst] << "+" << regR[instr.src] << "*" << (1 << (instr.getModShift())) << "]" << std::endl; + traceint(instr); + } + + void AssemblyGeneratorX86::h_IADD_M(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + genAddressReg(instr); + asmCode << "\tadd " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+rax]" << std::endl; + } + else { + asmCode << "\tadd " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+" << genAddressImm(instr) << "]" << std::endl; + } + traceint(instr); + } + + void AssemblyGeneratorX86::h_ISUB_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + asmCode << "\tsub " << regR[instr.dst] << ", " << regR[instr.src] << std::endl; + } + else { + asmCode << "\tsub " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl; + } + traceint(instr); + } + + void AssemblyGeneratorX86::h_ISUB_M(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + genAddressReg(instr); + asmCode << "\tsub " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+rax]" << std::endl; + } + else { + asmCode << "\tsub " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+" << genAddressImm(instr) << "]" << std::endl; + } + traceint(instr); + } + + void AssemblyGeneratorX86::h_IMUL_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + asmCode << "\timul " << regR[instr.dst] << ", " << regR[instr.src] << std::endl; + } + else { + asmCode << "\timul " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl; + } + traceint(instr); + } + + void AssemblyGeneratorX86::h_IMUL_M(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + genAddressReg(instr); + asmCode << "\timul " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+rax]" << std::endl; + } + else { + asmCode << "\timul " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+" << genAddressImm(instr) << "]" << std::endl; + } + traceint(instr); + } + + void AssemblyGeneratorX86::h_IMULH_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + asmCode << "\tmov rax, " << regR[instr.dst] << std::endl; + asmCode << "\tmul " << regR[instr.src] << std::endl; + asmCode << "\tmov " << regR[instr.dst] << ", rdx" << std::endl; + traceint(instr); + } + + void AssemblyGeneratorX86::h_IMULH_M(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + genAddressReg(instr, "ecx"); + asmCode << "\tmov rax, " << regR[instr.dst] << std::endl; + asmCode << "\tmul qword ptr [" << regScratchpadAddr << "+rcx]" << std::endl; + } + else { + asmCode << "\tmov rax, " << regR[instr.dst] << std::endl; + asmCode << "\tmul qword ptr [" << regScratchpadAddr << "+" << genAddressImm(instr) << "]" << std::endl; + } + asmCode << "\tmov " << regR[instr.dst] << ", rdx" << std::endl; + traceint(instr); + } + + void AssemblyGeneratorX86::h_ISMULH_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + asmCode << "\tmov rax, " << regR[instr.dst] << std::endl; + asmCode << "\timul " << regR[instr.src] << std::endl; + asmCode << "\tmov " << regR[instr.dst] << ", rdx" << std::endl; + traceint(instr); + } + + void AssemblyGeneratorX86::h_ISMULH_M(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + genAddressReg(instr, "ecx"); + asmCode << "\tmov rax, " << regR[instr.dst] << std::endl; + asmCode << "\timul qword ptr [" << regScratchpadAddr << "+rcx]" << std::endl; + } + else { + asmCode << "\tmov rax, " << regR[instr.dst] << std::endl; + asmCode << "\timul qword ptr [" << regScratchpadAddr << "+" << genAddressImm(instr) << "]" << std::endl; + } + asmCode << "\tmov " << regR[instr.dst] << ", rdx" << std::endl; + traceint(instr); + } + + void AssemblyGeneratorX86::h_INEG_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + asmCode << "\tneg " << regR[instr.dst] << std::endl; + traceint(instr); + } + + void AssemblyGeneratorX86::h_IXOR_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + asmCode << "\txor " << regR[instr.dst] << ", " << regR[instr.src] << std::endl; + } + else { + asmCode << "\txor " << regR[instr.dst] << ", " << (int32_t)instr.getImm32() << std::endl; + } + traceint(instr); + } + + void AssemblyGeneratorX86::h_IXOR_M(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + genAddressReg(instr); + asmCode << "\txor " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+rax]" << std::endl; + } + else { + asmCode << "\txor " << regR[instr.dst] << ", qword ptr [" << regScratchpadAddr << "+" << genAddressImm(instr) << "]" << std::endl; + } + traceint(instr); + } + + void AssemblyGeneratorX86::h_IROR_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + asmCode << "\tmov ecx, " << regR32[instr.src] << std::endl; + asmCode << "\tror " << regR[instr.dst] << ", cl" << std::endl; + } + else { + asmCode << "\tror " << regR[instr.dst] << ", " << (instr.getImm32() & 63) << std::endl; + } + traceint(instr); + } + + void AssemblyGeneratorX86::h_IROL_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + asmCode << "\tmov ecx, " << regR32[instr.src] << std::endl; + asmCode << "\trol " << regR[instr.dst] << ", cl" << std::endl; + } + else { + asmCode << "\trol " << regR[instr.dst] << ", " << (instr.getImm32() & 63) << std::endl; + } + traceint(instr); + } + + void AssemblyGeneratorX86::h_IMUL_RCP(Instruction& instr, int i) { + uint64_t divisor = instr.getImm32(); + if (!isZeroOrPowerOf2(divisor)) { + registerUsage[instr.dst] = i; + asmCode << "\tmov rax, " << randomx_reciprocal(divisor) << std::endl; + asmCode << "\timul " << regR[instr.dst] << ", rax" << std::endl; + traceint(instr); + } + else { + tracenop(instr); + } + } + + void AssemblyGeneratorX86::h_ISWAP_R(Instruction& instr, int i) { + if (instr.src != instr.dst) { + registerUsage[instr.dst] = i; + registerUsage[instr.src] = i; + asmCode << "\txchg " << regR[instr.dst] << ", " << regR[instr.src] << std::endl; + traceint(instr); + } + else { + tracenop(instr); + } + } + + void AssemblyGeneratorX86::h_FSWAP_R(Instruction& instr, int i) { + asmCode << "\tshufpd " << regFE[instr.dst] << ", " << regFE[instr.dst] << ", 1" << std::endl; + traceflt(instr); + } + + void AssemblyGeneratorX86::h_FADD_R(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + instr.src %= RegisterCountFlt; + asmCode << "\taddpd " << regF[instr.dst] << ", " << regA[instr.src] << std::endl; + traceflt(instr); + } + + void AssemblyGeneratorX86::h_FADD_M(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + genAddressReg(instr); + asmCode << "\tcvtdq2pd " << tempRegx << ", qword ptr [" << regScratchpadAddr << "+rax]" << std::endl; + asmCode << "\taddpd " << regF[instr.dst] << ", " << tempRegx << std::endl; + traceflt(instr); + } + + void AssemblyGeneratorX86::h_FSUB_R(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + instr.src %= RegisterCountFlt; + asmCode << "\tsubpd " << regF[instr.dst] << ", " << regA[instr.src] << std::endl; + traceflt(instr); + } + + void AssemblyGeneratorX86::h_FSUB_M(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + genAddressReg(instr); + asmCode << "\tcvtdq2pd " << tempRegx << ", qword ptr [" << regScratchpadAddr << "+rax]" << std::endl; + asmCode << "\tsubpd " << regF[instr.dst] << ", " << tempRegx << std::endl; + traceflt(instr); + } + + void AssemblyGeneratorX86::h_FSCAL_R(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + asmCode << "\txorps " << regF[instr.dst] << ", " << scaleMaskReg << std::endl; + traceflt(instr); + } + + void AssemblyGeneratorX86::h_FMUL_R(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + instr.src %= RegisterCountFlt; + asmCode << "\tmulpd " << regE[instr.dst] << ", " << regA[instr.src] << std::endl; + traceflt(instr); + } + + void AssemblyGeneratorX86::h_FDIV_M(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + genAddressReg(instr); + asmCode << "\tcvtdq2pd " << tempRegx << ", qword ptr [" << regScratchpadAddr << "+rax]" << std::endl; + asmCode << "\tandps " << tempRegx << ", " << mantissaMaskReg << std::endl; + asmCode << "\torps " << tempRegx << ", " << exponentMaskReg << std::endl; + asmCode << "\tdivpd " << regE[instr.dst] << ", " << tempRegx << std::endl; + traceflt(instr); + } + + void AssemblyGeneratorX86::h_FSQRT_R(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + asmCode << "\tsqrtpd " << regE[instr.dst] << ", " << regE[instr.dst] << std::endl; + traceflt(instr); + } + + void AssemblyGeneratorX86::h_CFROUND(Instruction& instr, int i) { + asmCode << "\tmov rax, " << regR[instr.src] << std::endl; + int rotate = (13 - (instr.getImm32() & 63)) & 63; + if (rotate != 0) + asmCode << "\trol rax, " << rotate << std::endl; + asmCode << "\tand eax, 24576" << std::endl; + asmCode << "\tor eax, 40896" << std::endl; + asmCode << "\tpush rax" << std::endl; + asmCode << "\tldmxcsr dword ptr [rsp]" << std::endl; + asmCode << "\tpop rax" << std::endl; + tracenop(instr); + } + + void AssemblyGeneratorX86::h_CBRANCH(Instruction& instr, int i) { + int reg = instr.dst; + int target = registerUsage[reg] + 1; + int shift = instr.getModCond() + ConditionOffset; + int32_t imm = instr.getImm32() | (1L << shift); + if (ConditionOffset > 0 || shift > 0) + imm &= ~(1L << (shift - 1)); + asmCode << "\tadd " << regR[reg] << ", " << imm << std::endl; + asmCode << "\ttest " << regR[reg] << ", " << (ConditionMask << shift) << std::endl; + asmCode << "\tjz randomx_isn_" << target << std::endl; + //mark all registers as used + for (unsigned j = 0; j < RegistersCount; ++j) { + registerUsage[j] = i; + } + } + + void AssemblyGeneratorX86::h_ISTORE(Instruction& instr, int i) { + genAddressRegDst(instr); + asmCode << "\tmov qword ptr [" << regScratchpadAddr << "+rax], " << regR[instr.src] << std::endl; + tracenop(instr); + } + + void AssemblyGeneratorX86::h_NOP(Instruction& instr, int i) { + asmCode << "\tnop" << std::endl; + tracenop(instr); + } + +#include "instruction_weights.hpp" +#define INST_HANDLE(x) REPN(&AssemblyGeneratorX86::h_##x, WT(x)) + + InstructionGenerator AssemblyGeneratorX86::engine[256] = { + INST_HANDLE(IADD_RS) + INST_HANDLE(IADD_M) + INST_HANDLE(ISUB_R) + INST_HANDLE(ISUB_M) + INST_HANDLE(IMUL_R) + INST_HANDLE(IMUL_M) + INST_HANDLE(IMULH_R) + INST_HANDLE(IMULH_M) + INST_HANDLE(ISMULH_R) + INST_HANDLE(ISMULH_M) + INST_HANDLE(IMUL_RCP) + INST_HANDLE(INEG_R) + INST_HANDLE(IXOR_R) + INST_HANDLE(IXOR_M) + INST_HANDLE(IROR_R) + INST_HANDLE(IROL_R) + INST_HANDLE(ISWAP_R) + INST_HANDLE(FSWAP_R) + INST_HANDLE(FADD_R) + INST_HANDLE(FADD_M) + INST_HANDLE(FSUB_R) + INST_HANDLE(FSUB_M) + INST_HANDLE(FSCAL_R) + INST_HANDLE(FMUL_R) + INST_HANDLE(FDIV_M) + INST_HANDLE(FSQRT_R) + INST_HANDLE(CBRANCH) + INST_HANDLE(CFROUND) + INST_HANDLE(ISTORE) + INST_HANDLE(NOP) + }; +} \ No newline at end of file diff --git a/src/RandomX/src/assembly_generator_x86.hpp b/src/RandomX/src/assembly_generator_x86.hpp new file mode 100644 index 000000000..e96239885 --- /dev/null +++ b/src/RandomX/src/assembly_generator_x86.hpp @@ -0,0 +1,94 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include "common.hpp" +#include + +namespace randomx { + + class Program; + class SuperscalarProgram; + class AssemblyGeneratorX86; + class Instruction; + + typedef void(AssemblyGeneratorX86::*InstructionGenerator)(Instruction&, int); + + class AssemblyGeneratorX86 { + public: + void generateProgram(Program& prog); + void generateAsm(SuperscalarProgram& prog); + void generateC(SuperscalarProgram& prog); + void printCode(std::ostream& os) { + os << asmCode.rdbuf(); + } + private: + void genAddressReg(Instruction&, const char*); + void genAddressRegDst(Instruction&, int); + int32_t genAddressImm(Instruction&); + void generateCode(Instruction&, int); + void traceint(Instruction&); + void traceflt(Instruction&); + void tracenop(Instruction&); + void h_IADD_RS(Instruction&, int); + void h_IADD_M(Instruction&, int); + void h_ISUB_R(Instruction&, int); + void h_ISUB_M(Instruction&, int); + void h_IMUL_R(Instruction&, int); + void h_IMUL_M(Instruction&, int); + void h_IMULH_R(Instruction&, int); + void h_IMULH_M(Instruction&, int); + void h_ISMULH_R(Instruction&, int); + void h_ISMULH_M(Instruction&, int); + void h_IMUL_RCP(Instruction&, int); + void h_INEG_R(Instruction&, int); + void h_IXOR_R(Instruction&, int); + void h_IXOR_M(Instruction&, int); + void h_IROR_R(Instruction&, int); + void h_IROL_R(Instruction&, int); + void h_ISWAP_R(Instruction&, int); + void h_FSWAP_R(Instruction&, int); + void h_FADD_R(Instruction&, int); + void h_FADD_M(Instruction&, int); + void h_FSUB_R(Instruction&, int); + void h_FSUB_M(Instruction&, int); + void h_FSCAL_R(Instruction&, int); + void h_FMUL_R(Instruction&, int); + void h_FDIV_M(Instruction&, int); + void h_FSQRT_R(Instruction&, int); + void h_CBRANCH(Instruction&, int); + void h_CFROUND(Instruction&, int); + void h_ISTORE(Instruction&, int); + void h_NOP(Instruction&, int); + + static InstructionGenerator engine[256]; + std::stringstream asmCode; + int registerUsage[RegistersCount]; + }; +} \ No newline at end of file diff --git a/src/RandomX/src/blake2/blake2-impl.h b/src/RandomX/src/blake2/blake2-impl.h new file mode 100644 index 000000000..617f7c8a3 --- /dev/null +++ b/src/RandomX/src/blake2/blake2-impl.h @@ -0,0 +1,76 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Original code from Argon2 reference source code package used under CC0 Licence + * https://github.com/P-H-C/phc-winner-argon2 + * Copyright 2015 + * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves +*/ + +#ifndef PORTABLE_BLAKE2_IMPL_H +#define PORTABLE_BLAKE2_IMPL_H + +#include + +#include "endian.h" + +static FORCE_INLINE uint64_t load48(const void *src) { + const uint8_t *p = (const uint8_t *)src; + uint64_t w = *p++; + w |= (uint64_t)(*p++) << 8; + w |= (uint64_t)(*p++) << 16; + w |= (uint64_t)(*p++) << 24; + w |= (uint64_t)(*p++) << 32; + w |= (uint64_t)(*p++) << 40; + return w; +} + +static FORCE_INLINE void store48(void *dst, uint64_t w) { + uint8_t *p = (uint8_t *)dst; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; +} + +static FORCE_INLINE uint32_t rotr32(const uint32_t w, const unsigned c) { + return (w >> c) | (w << (32 - c)); +} + +static FORCE_INLINE uint64_t rotr64(const uint64_t w, const unsigned c) { + return (w >> c) | (w << (64 - c)); +} + +#endif diff --git a/src/RandomX/src/blake2/blake2.h b/src/RandomX/src/blake2/blake2.h new file mode 100644 index 000000000..3d15be136 --- /dev/null +++ b/src/RandomX/src/blake2/blake2.h @@ -0,0 +1,116 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Original code from Argon2 reference source code package used under CC0 Licence + * https://github.com/P-H-C/phc-winner-argon2 + * Copyright 2015 + * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves +*/ + +#ifndef PORTABLE_BLAKE2_H +#define PORTABLE_BLAKE2_H + +#include +#include + +#if defined(__cplusplus) +extern "C" { +#endif + + enum blake2b_constant { + BLAKE2B_BLOCKBYTES = 128, + BLAKE2B_OUTBYTES = 64, + BLAKE2B_KEYBYTES = 64, + BLAKE2B_SALTBYTES = 16, + BLAKE2B_PERSONALBYTES = 16 + }; + +#pragma pack(push, 1) + typedef struct __blake2b_param { + uint8_t digest_length; /* 1 */ + uint8_t key_length; /* 2 */ + uint8_t fanout; /* 3 */ + uint8_t depth; /* 4 */ + uint32_t leaf_length; /* 8 */ + uint64_t node_offset; /* 16 */ + uint8_t node_depth; /* 17 */ + uint8_t inner_length; /* 18 */ + uint8_t reserved[14]; /* 32 */ + uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */ + uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */ + } blake2b_param; +#pragma pack(pop) + + typedef struct __blake2b_state { + uint64_t h[8]; + uint64_t t[2]; + uint64_t f[2]; + uint8_t buf[BLAKE2B_BLOCKBYTES]; + unsigned buflen; + unsigned outlen; + uint8_t last_node; + } blake2b_state; + + /* Ensure param structs have not been wrongly padded */ + /* Poor man's static_assert */ + enum { + blake2_size_check_0 = 1 / !!(CHAR_BIT == 8), + blake2_size_check_2 = + 1 / !!(sizeof(blake2b_param) == sizeof(uint64_t) * CHAR_BIT) + }; + + //randomx namespace +#define blake2b_init randomx_blake2b_init +#define blake2b_init_key randomx_blake2b_init_key +#define blake2b_init_param randomx_blake2b_init_param +#define blake2b_update randomx_blake2b_update +#define blake2b_final randomx_blake2b_final +#define blake2b randomx_blake2b +#define blake2b_long randomx_blake2b_long + + /* Streaming API */ + int blake2b_init(blake2b_state *S, size_t outlen); + int blake2b_init_key(blake2b_state *S, size_t outlen, const void *key, + size_t keylen); + int blake2b_init_param(blake2b_state *S, const blake2b_param *P); + int blake2b_update(blake2b_state *S, const void *in, size_t inlen); + int blake2b_final(blake2b_state *S, void *out, size_t outlen); + + /* Simple API */ + int blake2b(void *out, size_t outlen, const void *in, size_t inlen, + const void *key, size_t keylen); + + /* Argon2 Team - Begin Code */ + int blake2b_long(void *out, size_t outlen, const void *in, size_t inlen); + /* Argon2 Team - End Code */ + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/src/RandomX/src/blake2/blake2b.c b/src/RandomX/src/blake2/blake2b.c new file mode 100644 index 000000000..b9f1b565c --- /dev/null +++ b/src/RandomX/src/blake2/blake2b.c @@ -0,0 +1,409 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Original code from Argon2 reference source code package used under CC0 Licence + * https://github.com/P-H-C/phc-winner-argon2 + * Copyright 2015 + * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves +*/ + +#include +#include +#include + +#include "blake2.h" +#include "blake2-impl.h" + +static const uint64_t blake2b_IV[8] = { + UINT64_C(0x6a09e667f3bcc908), UINT64_C(0xbb67ae8584caa73b), + UINT64_C(0x3c6ef372fe94f82b), UINT64_C(0xa54ff53a5f1d36f1), + UINT64_C(0x510e527fade682d1), UINT64_C(0x9b05688c2b3e6c1f), + UINT64_C(0x1f83d9abfb41bd6b), UINT64_C(0x5be0cd19137e2179) }; + +static const unsigned int blake2b_sigma[12][16] = { + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, + {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3}, + {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4}, + {7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8}, + {9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13}, + {2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9}, + {12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11}, + {13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10}, + {6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5}, + {10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0}, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, + {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3}, +}; + +static FORCE_INLINE void blake2b_set_lastnode(blake2b_state *S) { + S->f[1] = (uint64_t)-1; +} + +static FORCE_INLINE void blake2b_set_lastblock(blake2b_state *S) { + if (S->last_node) { + blake2b_set_lastnode(S); + } + S->f[0] = (uint64_t)-1; +} + +static FORCE_INLINE void blake2b_increment_counter(blake2b_state *S, + uint64_t inc) { + S->t[0] += inc; + S->t[1] += (S->t[0] < inc); +} + +static FORCE_INLINE void blake2b_invalidate_state(blake2b_state *S) { + //clear_internal_memory(S, sizeof(*S)); /* wipe */ + blake2b_set_lastblock(S); /* invalidate for further use */ +} + +static FORCE_INLINE void blake2b_init0(blake2b_state *S) { + memset(S, 0, sizeof(*S)); + memcpy(S->h, blake2b_IV, sizeof(S->h)); +} + +int blake2b_init_param(blake2b_state *S, const blake2b_param *P) { + const unsigned char *p = (const unsigned char *)P; + unsigned int i; + + if (NULL == P || NULL == S) { + return -1; + } + + blake2b_init0(S); + /* IV XOR Parameter Block */ + for (i = 0; i < 8; ++i) { + S->h[i] ^= load64(&p[i * sizeof(S->h[i])]); + } + S->outlen = P->digest_length; + return 0; +} + +/* Sequential blake2b initialization */ +int blake2b_init(blake2b_state *S, size_t outlen) { + blake2b_param P; + + if (S == NULL) { + return -1; + } + + if ((outlen == 0) || (outlen > BLAKE2B_OUTBYTES)) { + blake2b_invalidate_state(S); + return -1; + } + + /* Setup Parameter Block for unkeyed BLAKE2 */ + P.digest_length = (uint8_t)outlen; + P.key_length = 0; + P.fanout = 1; + P.depth = 1; + P.leaf_length = 0; + P.node_offset = 0; + P.node_depth = 0; + P.inner_length = 0; + memset(P.reserved, 0, sizeof(P.reserved)); + memset(P.salt, 0, sizeof(P.salt)); + memset(P.personal, 0, sizeof(P.personal)); + + return blake2b_init_param(S, &P); +} + +int blake2b_init_key(blake2b_state *S, size_t outlen, const void *key, size_t keylen) { + blake2b_param P; + + if (S == NULL) { + return -1; + } + + if ((outlen == 0) || (outlen > BLAKE2B_OUTBYTES)) { + blake2b_invalidate_state(S); + return -1; + } + + if ((key == 0) || (keylen == 0) || (keylen > BLAKE2B_KEYBYTES)) { + blake2b_invalidate_state(S); + return -1; + } + + /* Setup Parameter Block for keyed BLAKE2 */ + P.digest_length = (uint8_t)outlen; + P.key_length = (uint8_t)keylen; + P.fanout = 1; + P.depth = 1; + P.leaf_length = 0; + P.node_offset = 0; + P.node_depth = 0; + P.inner_length = 0; + memset(P.reserved, 0, sizeof(P.reserved)); + memset(P.salt, 0, sizeof(P.salt)); + memset(P.personal, 0, sizeof(P.personal)); + + if (blake2b_init_param(S, &P) < 0) { + blake2b_invalidate_state(S); + return -1; + } + + { + uint8_t block[BLAKE2B_BLOCKBYTES]; + memset(block, 0, BLAKE2B_BLOCKBYTES); + memcpy(block, key, keylen); + blake2b_update(S, block, BLAKE2B_BLOCKBYTES); + /* Burn the key from stack */ + //clear_internal_memory(block, BLAKE2B_BLOCKBYTES); + } + return 0; +} + +static void blake2b_compress(blake2b_state *S, const uint8_t *block) { + uint64_t m[16]; + uint64_t v[16]; + unsigned int i, r; + + for (i = 0; i < 16; ++i) { + m[i] = load64(block + i * sizeof(m[i])); + } + + for (i = 0; i < 8; ++i) { + v[i] = S->h[i]; + } + + v[8] = blake2b_IV[0]; + v[9] = blake2b_IV[1]; + v[10] = blake2b_IV[2]; + v[11] = blake2b_IV[3]; + v[12] = blake2b_IV[4] ^ S->t[0]; + v[13] = blake2b_IV[5] ^ S->t[1]; + v[14] = blake2b_IV[6] ^ S->f[0]; + v[15] = blake2b_IV[7] ^ S->f[1]; + +#define G(r, i, a, b, c, d) \ + do { \ + a = a + b + m[blake2b_sigma[r][2 * i + 0]]; \ + d = rotr64(d ^ a, 32); \ + c = c + d; \ + b = rotr64(b ^ c, 24); \ + a = a + b + m[blake2b_sigma[r][2 * i + 1]]; \ + d = rotr64(d ^ a, 16); \ + c = c + d; \ + b = rotr64(b ^ c, 63); \ + } while ((void)0, 0) + +#define ROUND(r) \ + do { \ + G(r, 0, v[0], v[4], v[8], v[12]); \ + G(r, 1, v[1], v[5], v[9], v[13]); \ + G(r, 2, v[2], v[6], v[10], v[14]); \ + G(r, 3, v[3], v[7], v[11], v[15]); \ + G(r, 4, v[0], v[5], v[10], v[15]); \ + G(r, 5, v[1], v[6], v[11], v[12]); \ + G(r, 6, v[2], v[7], v[8], v[13]); \ + G(r, 7, v[3], v[4], v[9], v[14]); \ + } while ((void)0, 0) + + for (r = 0; r < 12; ++r) { + ROUND(r); + } + + for (i = 0; i < 8; ++i) { + S->h[i] = S->h[i] ^ v[i] ^ v[i + 8]; + } + +#undef G +#undef ROUND +} + +int blake2b_update(blake2b_state *S, const void *in, size_t inlen) { + const uint8_t *pin = (const uint8_t *)in; + + if (inlen == 0) { + return 0; + } + + /* Sanity check */ + if (S == NULL || in == NULL) { + return -1; + } + + /* Is this a reused state? */ + if (S->f[0] != 0) { + return -1; + } + + if (S->buflen + inlen > BLAKE2B_BLOCKBYTES) { + /* Complete current block */ + size_t left = S->buflen; + size_t fill = BLAKE2B_BLOCKBYTES - left; + memcpy(&S->buf[left], pin, fill); + blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES); + blake2b_compress(S, S->buf); + S->buflen = 0; + inlen -= fill; + pin += fill; + /* Avoid buffer copies when possible */ + while (inlen > BLAKE2B_BLOCKBYTES) { + blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES); + blake2b_compress(S, pin); + inlen -= BLAKE2B_BLOCKBYTES; + pin += BLAKE2B_BLOCKBYTES; + } + } + memcpy(&S->buf[S->buflen], pin, inlen); + S->buflen += (unsigned int)inlen; + return 0; +} + +int blake2b_final(blake2b_state *S, void *out, size_t outlen) { + uint8_t buffer[BLAKE2B_OUTBYTES] = { 0 }; + unsigned int i; + + /* Sanity checks */ + if (S == NULL || out == NULL || outlen < S->outlen) { + return -1; + } + + /* Is this a reused state? */ + if (S->f[0] != 0) { + return -1; + } + + blake2b_increment_counter(S, S->buflen); + blake2b_set_lastblock(S); + memset(&S->buf[S->buflen], 0, BLAKE2B_BLOCKBYTES - S->buflen); /* Padding */ + blake2b_compress(S, S->buf); + + for (i = 0; i < 8; ++i) { /* Output full hash to temp buffer */ + store64(buffer + sizeof(S->h[i]) * i, S->h[i]); + } + + memcpy(out, buffer, S->outlen); + //clear_internal_memory(buffer, sizeof(buffer)); + //clear_internal_memory(S->buf, sizeof(S->buf)); + //clear_internal_memory(S->h, sizeof(S->h)); + return 0; +} + +int blake2b(void *out, size_t outlen, const void *in, size_t inlen, + const void *key, size_t keylen) { + blake2b_state S; + int ret = -1; + + /* Verify parameters */ + if (NULL == in && inlen > 0) { + goto fail; + } + + if (NULL == out || outlen == 0 || outlen > BLAKE2B_OUTBYTES) { + goto fail; + } + + if ((NULL == key && keylen > 0) || keylen > BLAKE2B_KEYBYTES) { + goto fail; + } + + if (keylen > 0) { + if (blake2b_init_key(&S, outlen, key, keylen) < 0) { + goto fail; + } + } + else { + if (blake2b_init(&S, outlen) < 0) { + goto fail; + } + } + + if (blake2b_update(&S, in, inlen) < 0) { + goto fail; + } + ret = blake2b_final(&S, out, outlen); + +fail: + //clear_internal_memory(&S, sizeof(S)); + return ret; +} + +/* Argon2 Team - Begin Code */ +int blake2b_long(void *pout, size_t outlen, const void *in, size_t inlen) { + uint8_t *out = (uint8_t *)pout; + blake2b_state blake_state; + uint8_t outlen_bytes[sizeof(uint32_t)] = { 0 }; + int ret = -1; + + if (outlen > UINT32_MAX) { + goto fail; + } + + /* Ensure little-endian byte order! */ + store32(outlen_bytes, (uint32_t)outlen); + +#define TRY(statement) \ + do { \ + ret = statement; \ + if (ret < 0) { \ + goto fail; \ + } \ + } while ((void)0, 0) + + if (outlen <= BLAKE2B_OUTBYTES) { + TRY(blake2b_init(&blake_state, outlen)); + TRY(blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes))); + TRY(blake2b_update(&blake_state, in, inlen)); + TRY(blake2b_final(&blake_state, out, outlen)); + } + else { + uint32_t toproduce; + uint8_t out_buffer[BLAKE2B_OUTBYTES]; + uint8_t in_buffer[BLAKE2B_OUTBYTES]; + TRY(blake2b_init(&blake_state, BLAKE2B_OUTBYTES)); + TRY(blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes))); + TRY(blake2b_update(&blake_state, in, inlen)); + TRY(blake2b_final(&blake_state, out_buffer, BLAKE2B_OUTBYTES)); + memcpy(out, out_buffer, BLAKE2B_OUTBYTES / 2); + out += BLAKE2B_OUTBYTES / 2; + toproduce = (uint32_t)outlen - BLAKE2B_OUTBYTES / 2; + + while (toproduce > BLAKE2B_OUTBYTES) { + memcpy(in_buffer, out_buffer, BLAKE2B_OUTBYTES); + TRY(blake2b(out_buffer, BLAKE2B_OUTBYTES, in_buffer, + BLAKE2B_OUTBYTES, NULL, 0)); + memcpy(out, out_buffer, BLAKE2B_OUTBYTES / 2); + out += BLAKE2B_OUTBYTES / 2; + toproduce -= BLAKE2B_OUTBYTES / 2; + } + + memcpy(in_buffer, out_buffer, BLAKE2B_OUTBYTES); + TRY(blake2b(out_buffer, toproduce, in_buffer, BLAKE2B_OUTBYTES, NULL, + 0)); + memcpy(out, out_buffer, toproduce); + } +fail: + //clear_internal_memory(&blake_state, sizeof(blake_state)); + return ret; +#undef TRY +} +/* Argon2 Team - End Code */ + diff --git a/src/RandomX/src/blake2/blamka-round-avx2.h b/src/RandomX/src/blake2/blamka-round-avx2.h new file mode 100644 index 000000000..483826179 --- /dev/null +++ b/src/RandomX/src/blake2/blamka-round-avx2.h @@ -0,0 +1,189 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Original code from Argon2 reference source code package used under CC0 Licence + * https://github.com/P-H-C/phc-winner-argon2 + * Copyright 2015 + * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves +*/ + +#ifndef BLAKE_ROUND_MKA_OPT_H +#define BLAKE_ROUND_MKA_OPT_H + +#include "blake2-impl.h" + +#ifdef __GNUC__ +#include +#else +#include +#endif + +#define rotr32(x) _mm256_shuffle_epi32(x, _MM_SHUFFLE(2, 3, 0, 1)) +#define rotr24(x) _mm256_shuffle_epi8(x, _mm256_setr_epi8(3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10, 3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10)) +#define rotr16(x) _mm256_shuffle_epi8(x, _mm256_setr_epi8(2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9, 2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9)) +#define rotr63(x) _mm256_xor_si256(_mm256_srli_epi64((x), 63), _mm256_add_epi64((x), (x))) + +#define G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + do { \ + __m256i ml = _mm256_mul_epu32(A0, B0); \ + ml = _mm256_add_epi64(ml, ml); \ + A0 = _mm256_add_epi64(A0, _mm256_add_epi64(B0, ml)); \ + D0 = _mm256_xor_si256(D0, A0); \ + D0 = rotr32(D0); \ + \ + ml = _mm256_mul_epu32(C0, D0); \ + ml = _mm256_add_epi64(ml, ml); \ + C0 = _mm256_add_epi64(C0, _mm256_add_epi64(D0, ml)); \ + \ + B0 = _mm256_xor_si256(B0, C0); \ + B0 = rotr24(B0); \ + \ + ml = _mm256_mul_epu32(A1, B1); \ + ml = _mm256_add_epi64(ml, ml); \ + A1 = _mm256_add_epi64(A1, _mm256_add_epi64(B1, ml)); \ + D1 = _mm256_xor_si256(D1, A1); \ + D1 = rotr32(D1); \ + \ + ml = _mm256_mul_epu32(C1, D1); \ + ml = _mm256_add_epi64(ml, ml); \ + C1 = _mm256_add_epi64(C1, _mm256_add_epi64(D1, ml)); \ + \ + B1 = _mm256_xor_si256(B1, C1); \ + B1 = rotr24(B1); \ + } while((void)0, 0); + +#define G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + do { \ + __m256i ml = _mm256_mul_epu32(A0, B0); \ + ml = _mm256_add_epi64(ml, ml); \ + A0 = _mm256_add_epi64(A0, _mm256_add_epi64(B0, ml)); \ + D0 = _mm256_xor_si256(D0, A0); \ + D0 = rotr16(D0); \ + \ + ml = _mm256_mul_epu32(C0, D0); \ + ml = _mm256_add_epi64(ml, ml); \ + C0 = _mm256_add_epi64(C0, _mm256_add_epi64(D0, ml)); \ + B0 = _mm256_xor_si256(B0, C0); \ + B0 = rotr63(B0); \ + \ + ml = _mm256_mul_epu32(A1, B1); \ + ml = _mm256_add_epi64(ml, ml); \ + A1 = _mm256_add_epi64(A1, _mm256_add_epi64(B1, ml)); \ + D1 = _mm256_xor_si256(D1, A1); \ + D1 = rotr16(D1); \ + \ + ml = _mm256_mul_epu32(C1, D1); \ + ml = _mm256_add_epi64(ml, ml); \ + C1 = _mm256_add_epi64(C1, _mm256_add_epi64(D1, ml)); \ + B1 = _mm256_xor_si256(B1, C1); \ + B1 = rotr63(B1); \ + } while((void)0, 0); + +#define DIAGONALIZE_1(A0, B0, C0, D0, A1, B1, C1, D1) \ + do { \ + B0 = _mm256_permute4x64_epi64(B0, _MM_SHUFFLE(0, 3, 2, 1)); \ + C0 = _mm256_permute4x64_epi64(C0, _MM_SHUFFLE(1, 0, 3, 2)); \ + D0 = _mm256_permute4x64_epi64(D0, _MM_SHUFFLE(2, 1, 0, 3)); \ + \ + B1 = _mm256_permute4x64_epi64(B1, _MM_SHUFFLE(0, 3, 2, 1)); \ + C1 = _mm256_permute4x64_epi64(C1, _MM_SHUFFLE(1, 0, 3, 2)); \ + D1 = _mm256_permute4x64_epi64(D1, _MM_SHUFFLE(2, 1, 0, 3)); \ + } while((void)0, 0); + +#define DIAGONALIZE_2(A0, A1, B0, B1, C0, C1, D0, D1) \ + do { \ + __m256i tmp1 = _mm256_blend_epi32(B0, B1, 0xCC); \ + __m256i tmp2 = _mm256_blend_epi32(B0, B1, 0x33); \ + B1 = _mm256_permute4x64_epi64(tmp1, _MM_SHUFFLE(2,3,0,1)); \ + B0 = _mm256_permute4x64_epi64(tmp2, _MM_SHUFFLE(2,3,0,1)); \ + \ + tmp1 = C0; \ + C0 = C1; \ + C1 = tmp1; \ + \ + tmp1 = _mm256_blend_epi32(D0, D1, 0xCC); \ + tmp2 = _mm256_blend_epi32(D0, D1, 0x33); \ + D0 = _mm256_permute4x64_epi64(tmp1, _MM_SHUFFLE(2,3,0,1)); \ + D1 = _mm256_permute4x64_epi64(tmp2, _MM_SHUFFLE(2,3,0,1)); \ + } while(0); + +#define UNDIAGONALIZE_1(A0, B0, C0, D0, A1, B1, C1, D1) \ + do { \ + B0 = _mm256_permute4x64_epi64(B0, _MM_SHUFFLE(2, 1, 0, 3)); \ + C0 = _mm256_permute4x64_epi64(C0, _MM_SHUFFLE(1, 0, 3, 2)); \ + D0 = _mm256_permute4x64_epi64(D0, _MM_SHUFFLE(0, 3, 2, 1)); \ + \ + B1 = _mm256_permute4x64_epi64(B1, _MM_SHUFFLE(2, 1, 0, 3)); \ + C1 = _mm256_permute4x64_epi64(C1, _MM_SHUFFLE(1, 0, 3, 2)); \ + D1 = _mm256_permute4x64_epi64(D1, _MM_SHUFFLE(0, 3, 2, 1)); \ + } while((void)0, 0); + +#define UNDIAGONALIZE_2(A0, A1, B0, B1, C0, C1, D0, D1) \ + do { \ + __m256i tmp1 = _mm256_blend_epi32(B0, B1, 0xCC); \ + __m256i tmp2 = _mm256_blend_epi32(B0, B1, 0x33); \ + B0 = _mm256_permute4x64_epi64(tmp1, _MM_SHUFFLE(2,3,0,1)); \ + B1 = _mm256_permute4x64_epi64(tmp2, _MM_SHUFFLE(2,3,0,1)); \ + \ + tmp1 = C0; \ + C0 = C1; \ + C1 = tmp1; \ + \ + tmp1 = _mm256_blend_epi32(D0, D1, 0x33); \ + tmp2 = _mm256_blend_epi32(D0, D1, 0xCC); \ + D0 = _mm256_permute4x64_epi64(tmp1, _MM_SHUFFLE(2,3,0,1)); \ + D1 = _mm256_permute4x64_epi64(tmp2, _MM_SHUFFLE(2,3,0,1)); \ + } while((void)0, 0); + +#define BLAKE2_ROUND_1(A0, A1, B0, B1, C0, C1, D0, D1) \ + do{ \ + G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + \ + DIAGONALIZE_1(A0, B0, C0, D0, A1, B1, C1, D1) \ + \ + G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + \ + UNDIAGONALIZE_1(A0, B0, C0, D0, A1, B1, C1, D1) \ + } while((void)0, 0); + +#define BLAKE2_ROUND_2(A0, A1, B0, B1, C0, C1, D0, D1) \ + do{ \ + G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + \ + DIAGONALIZE_2(A0, A1, B0, B1, C0, C1, D0, D1) \ + \ + G1_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + G2_AVX2(A0, A1, B0, B1, C0, C1, D0, D1) \ + \ + UNDIAGONALIZE_2(A0, A1, B0, B1, C0, C1, D0, D1) \ + } while((void)0, 0); + +#endif /* BLAKE_ROUND_MKA_OPT_H */ diff --git a/src/RandomX/src/blake2/blamka-round-ref.h b/src/RandomX/src/blake2/blamka-round-ref.h new file mode 100644 index 000000000..f1fb50bf8 --- /dev/null +++ b/src/RandomX/src/blake2/blamka-round-ref.h @@ -0,0 +1,73 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Original code from Argon2 reference source code package used under CC0 Licence + * https://github.com/P-H-C/phc-winner-argon2 + * Copyright 2015 + * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves +*/ + +#ifndef BLAKE_ROUND_MKA_H +#define BLAKE_ROUND_MKA_H + +#include "blake2.h" +#include "blake2-impl.h" + + /* designed by the Lyra PHC team */ +static FORCE_INLINE uint64_t fBlaMka(uint64_t x, uint64_t y) { + const uint64_t m = UINT64_C(0xFFFFFFFF); + const uint64_t xy = (x & m) * (y & m); + return x + y + 2 * xy; +} + +#define G(a, b, c, d) \ + do { \ + a = fBlaMka(a, b); \ + d = rotr64(d ^ a, 32); \ + c = fBlaMka(c, d); \ + b = rotr64(b ^ c, 24); \ + a = fBlaMka(a, b); \ + d = rotr64(d ^ a, 16); \ + c = fBlaMka(c, d); \ + b = rotr64(b ^ c, 63); \ + } while ((void)0, 0) + +#define BLAKE2_ROUND_NOMSG(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, \ + v12, v13, v14, v15) \ + do { \ + G(v0, v4, v8, v12); \ + G(v1, v5, v9, v13); \ + G(v2, v6, v10, v14); \ + G(v3, v7, v11, v15); \ + G(v0, v5, v10, v15); \ + G(v1, v6, v11, v12); \ + G(v2, v7, v8, v13); \ + G(v3, v4, v9, v14); \ + } while ((void)0, 0) + +#endif diff --git a/src/RandomX/src/blake2/blamka-round-ssse3.h b/src/RandomX/src/blake2/blamka-round-ssse3.h new file mode 100644 index 000000000..f2d3b5d05 --- /dev/null +++ b/src/RandomX/src/blake2/blamka-round-ssse3.h @@ -0,0 +1,162 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Original code from Argon2 reference source code package used under CC0 Licence + * https://github.com/P-H-C/phc-winner-argon2 + * Copyright 2015 + * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves +*/ + +#ifndef BLAKE_ROUND_MKA_OPT_H +#define BLAKE_ROUND_MKA_OPT_H + +#include "blake2-impl.h" + +#ifdef __GNUC__ +#include +#else +#include +#endif + +#ifdef _mm_roti_epi64 //clang defines it using the XOP instruction set +#undef _mm_roti_epi64 +#endif + +#define r16 \ + (_mm_setr_epi8(2, 3, 4, 5, 6, 7, 0, 1, 10, 11, 12, 13, 14, 15, 8, 9)) +#define r24 \ + (_mm_setr_epi8(3, 4, 5, 6, 7, 0, 1, 2, 11, 12, 13, 14, 15, 8, 9, 10)) +#define _mm_roti_epi64(x, c) \ + (-(c) == 32) \ + ? _mm_shuffle_epi32((x), _MM_SHUFFLE(2, 3, 0, 1)) \ + : (-(c) == 24) \ + ? _mm_shuffle_epi8((x), r24) \ + : (-(c) == 16) \ + ? _mm_shuffle_epi8((x), r16) \ + : (-(c) == 63) \ + ? _mm_xor_si128(_mm_srli_epi64((x), -(c)), \ + _mm_add_epi64((x), (x))) \ + : _mm_xor_si128(_mm_srli_epi64((x), -(c)), \ + _mm_slli_epi64((x), 64 - (-(c)))) + +static FORCE_INLINE __m128i fBlaMka(__m128i x, __m128i y) { + const __m128i z = _mm_mul_epu32(x, y); + return _mm_add_epi64(_mm_add_epi64(x, y), _mm_add_epi64(z, z)); +} + +#define G1(A0, B0, C0, D0, A1, B1, C1, D1) \ + do { \ + A0 = fBlaMka(A0, B0); \ + A1 = fBlaMka(A1, B1); \ + \ + D0 = _mm_xor_si128(D0, A0); \ + D1 = _mm_xor_si128(D1, A1); \ + \ + D0 = _mm_roti_epi64(D0, -32); \ + D1 = _mm_roti_epi64(D1, -32); \ + \ + C0 = fBlaMka(C0, D0); \ + C1 = fBlaMka(C1, D1); \ + \ + B0 = _mm_xor_si128(B0, C0); \ + B1 = _mm_xor_si128(B1, C1); \ + \ + B0 = _mm_roti_epi64(B0, -24); \ + B1 = _mm_roti_epi64(B1, -24); \ + } while ((void)0, 0) + +#define G2(A0, B0, C0, D0, A1, B1, C1, D1) \ + do { \ + A0 = fBlaMka(A0, B0); \ + A1 = fBlaMka(A1, B1); \ + \ + D0 = _mm_xor_si128(D0, A0); \ + D1 = _mm_xor_si128(D1, A1); \ + \ + D0 = _mm_roti_epi64(D0, -16); \ + D1 = _mm_roti_epi64(D1, -16); \ + \ + C0 = fBlaMka(C0, D0); \ + C1 = fBlaMka(C1, D1); \ + \ + B0 = _mm_xor_si128(B0, C0); \ + B1 = _mm_xor_si128(B1, C1); \ + \ + B0 = _mm_roti_epi64(B0, -63); \ + B1 = _mm_roti_epi64(B1, -63); \ + } while ((void)0, 0) + +#define DIAGONALIZE(A0, B0, C0, D0, A1, B1, C1, D1) \ + do { \ + __m128i t0 = _mm_alignr_epi8(B1, B0, 8); \ + __m128i t1 = _mm_alignr_epi8(B0, B1, 8); \ + B0 = t0; \ + B1 = t1; \ + \ + t0 = C0; \ + C0 = C1; \ + C1 = t0; \ + \ + t0 = _mm_alignr_epi8(D1, D0, 8); \ + t1 = _mm_alignr_epi8(D0, D1, 8); \ + D0 = t1; \ + D1 = t0; \ + } while ((void)0, 0) + +#define UNDIAGONALIZE(A0, B0, C0, D0, A1, B1, C1, D1) \ + do { \ + __m128i t0 = _mm_alignr_epi8(B0, B1, 8); \ + __m128i t1 = _mm_alignr_epi8(B1, B0, 8); \ + B0 = t0; \ + B1 = t1; \ + \ + t0 = C0; \ + C0 = C1; \ + C1 = t0; \ + \ + t0 = _mm_alignr_epi8(D0, D1, 8); \ + t1 = _mm_alignr_epi8(D1, D0, 8); \ + D0 = t1; \ + D1 = t0; \ + } while ((void)0, 0) + +#define BLAKE2_ROUND(A0, A1, B0, B1, C0, C1, D0, D1) \ + do { \ + G1(A0, B0, C0, D0, A1, B1, C1, D1); \ + G2(A0, B0, C0, D0, A1, B1, C1, D1); \ + \ + DIAGONALIZE(A0, B0, C0, D0, A1, B1, C1, D1); \ + \ + G1(A0, B0, C0, D0, A1, B1, C1, D1); \ + G2(A0, B0, C0, D0, A1, B1, C1, D1); \ + \ + UNDIAGONALIZE(A0, B0, C0, D0, A1, B1, C1, D1); \ + } while ((void)0, 0) + + +#endif /* BLAKE_ROUND_MKA_OPT_H */ diff --git a/src/RandomX/src/blake2/endian.h b/src/RandomX/src/blake2/endian.h new file mode 100644 index 000000000..c7afed261 --- /dev/null +++ b/src/RandomX/src/blake2/endian.h @@ -0,0 +1,107 @@ +#pragma once +#include +#include + +#if defined(_MSC_VER) +#define FORCE_INLINE __inline +#elif defined(__GNUC__) || defined(__clang__) +#define FORCE_INLINE __inline__ +#else +#define FORCE_INLINE +#endif + + /* Argon2 Team - Begin Code */ + /* + Not an exhaustive list, but should cover the majority of modern platforms + Additionally, the code will always be correct---this is only a performance + tweak. + */ +#if (defined(__BYTE_ORDER__) && \ + (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) || \ + defined(__LITTLE_ENDIAN__) || defined(__ARMEL__) || defined(__MIPSEL__) || \ + defined(__AARCH64EL__) || defined(__amd64__) || defined(__i386__) || \ + defined(_M_IX86) || defined(_M_X64) || defined(_M_AMD64) || \ + defined(_M_ARM) +#define NATIVE_LITTLE_ENDIAN +#endif + /* Argon2 Team - End Code */ + +static FORCE_INLINE uint32_t load32(const void *src) { +#if defined(NATIVE_LITTLE_ENDIAN) + uint32_t w; + memcpy(&w, src, sizeof w); + return w; +#else + const uint8_t *p = (const uint8_t *)src; + uint32_t w = *p++; + w |= (uint32_t)(*p++) << 8; + w |= (uint32_t)(*p++) << 16; + w |= (uint32_t)(*p++) << 24; + return w; +#endif +} + +static FORCE_INLINE uint64_t load64_native(const void *src) { + uint64_t w; + memcpy(&w, src, sizeof w); + return w; +} + +static FORCE_INLINE uint64_t load64(const void *src) { +#if defined(NATIVE_LITTLE_ENDIAN) + return load64_native(src); +#else + const uint8_t *p = (const uint8_t *)src; + uint64_t w = *p++; + w |= (uint64_t)(*p++) << 8; + w |= (uint64_t)(*p++) << 16; + w |= (uint64_t)(*p++) << 24; + w |= (uint64_t)(*p++) << 32; + w |= (uint64_t)(*p++) << 40; + w |= (uint64_t)(*p++) << 48; + w |= (uint64_t)(*p++) << 56; + return w; +#endif +} + +static FORCE_INLINE void store32(void *dst, uint32_t w) { +#if defined(NATIVE_LITTLE_ENDIAN) + memcpy(dst, &w, sizeof w); +#else + uint8_t *p = (uint8_t *)dst; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; +#endif +} + +static FORCE_INLINE void store64_native(void *dst, uint64_t w) { + memcpy(dst, &w, sizeof w); +} + +static FORCE_INLINE void store64(void *dst, uint64_t w) { +#if defined(NATIVE_LITTLE_ENDIAN) + store64_native(dst, w); +#else + uint8_t *p = (uint8_t *)dst; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; + w >>= 8; + *p++ = (uint8_t)w; +#endif +} diff --git a/src/RandomX/src/blake2_generator.cpp b/src/RandomX/src/blake2_generator.cpp new file mode 100644 index 000000000..3f2d028c3 --- /dev/null +++ b/src/RandomX/src/blake2_generator.cpp @@ -0,0 +1,62 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include "blake2/blake2.h" +#include "blake2/endian.h" +#include "blake2_generator.hpp" + +namespace randomx { + + constexpr int maxSeedSize = 60; + + Blake2Generator::Blake2Generator(const void* seed, size_t seedSize, int nonce) : dataIndex(sizeof(data)) { + memset(data, 0, sizeof(data)); + memcpy(data, seed, seedSize > maxSeedSize ? maxSeedSize : seedSize); + store32(&data[maxSeedSize], nonce); + } + + uint8_t Blake2Generator::getByte() { + checkData(1); + return data[dataIndex++]; + } + + uint32_t Blake2Generator::getUInt32() { + checkData(4); + auto ret = load32(&data[dataIndex]); + dataIndex += 4; + return ret; + } + + void Blake2Generator::checkData(const size_t bytesNeeded) { + if (dataIndex + bytesNeeded > sizeof(data)) { + blake2b(data, sizeof(data), data, sizeof(data), nullptr, 0); + dataIndex = 0; + } + } +} \ No newline at end of file diff --git a/src/RandomX/src/blake2_generator.hpp b/src/RandomX/src/blake2_generator.hpp new file mode 100644 index 000000000..5e7f61f25 --- /dev/null +++ b/src/RandomX/src/blake2_generator.hpp @@ -0,0 +1,46 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include + +namespace randomx { + + class Blake2Generator { + public: + Blake2Generator(const void* seed, size_t seedSize, int nonce = 0); + uint8_t getByte(); + uint32_t getUInt32(); + private: + void checkData(const size_t); + + uint8_t data[64]; + size_t dataIndex; + }; +} \ No newline at end of file diff --git a/src/RandomX/src/bytecode_machine.cpp b/src/RandomX/src/bytecode_machine.cpp new file mode 100644 index 000000000..7d8e902d2 --- /dev/null +++ b/src/RandomX/src/bytecode_machine.cpp @@ -0,0 +1,482 @@ +/* +Copyright (c) 2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "bytecode_machine.hpp" +#include "reciprocal.h" + +namespace randomx { + + const int_reg_t BytecodeMachine::zero = 0; + +#define INSTR_CASE(x) case InstructionType::x: \ + exe_ ## x(ibc, pc, scratchpad, config); \ + break; + + void BytecodeMachine::executeInstruction(RANDOMX_EXE_ARGS) { + switch (ibc.type) + { + INSTR_CASE(IADD_RS) + INSTR_CASE(IADD_M) + INSTR_CASE(ISUB_R) + INSTR_CASE(ISUB_M) + INSTR_CASE(IMUL_R) + INSTR_CASE(IMUL_M) + INSTR_CASE(IMULH_R) + INSTR_CASE(IMULH_M) + INSTR_CASE(ISMULH_R) + INSTR_CASE(ISMULH_M) + INSTR_CASE(INEG_R) + INSTR_CASE(IXOR_R) + INSTR_CASE(IXOR_M) + INSTR_CASE(IROR_R) + INSTR_CASE(IROL_R) + INSTR_CASE(ISWAP_R) + INSTR_CASE(FSWAP_R) + INSTR_CASE(FADD_R) + INSTR_CASE(FADD_M) + INSTR_CASE(FSUB_R) + INSTR_CASE(FSUB_M) + INSTR_CASE(FSCAL_R) + INSTR_CASE(FMUL_R) + INSTR_CASE(FDIV_M) + INSTR_CASE(FSQRT_R) + INSTR_CASE(CBRANCH) + INSTR_CASE(CFROUND) + INSTR_CASE(ISTORE) + + case InstructionType::NOP: + break; + + case InstructionType::IMUL_RCP: //executed as IMUL_R + default: + UNREACHABLE; + } + } + + void BytecodeMachine::compileInstruction(RANDOMX_GEN_ARGS) { + int opcode = instr.opcode; + + if (opcode < ceil_IADD_RS) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::IADD_RS; + ibc.idst = &nreg->r[dst]; + if (dst != RegisterNeedsDisplacement) { + ibc.isrc = &nreg->r[src]; + ibc.shift = instr.getModShift(); + ibc.imm = 0; + } + else { + ibc.isrc = &nreg->r[src]; + ibc.shift = instr.getModShift(); + ibc.imm = signExtend2sCompl(instr.getImm32()); + } + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_IADD_M) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::IADD_M; + ibc.idst = &nreg->r[dst]; + ibc.imm = signExtend2sCompl(instr.getImm32()); + if (src != dst) { + ibc.isrc = &nreg->r[src]; + ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask); + } + else { + ibc.isrc = &zero; + ibc.memMask = ScratchpadL3Mask; + } + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_ISUB_R) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::ISUB_R; + ibc.idst = &nreg->r[dst]; + if (src != dst) { + ibc.isrc = &nreg->r[src]; + } + else { + ibc.imm = signExtend2sCompl(instr.getImm32()); + ibc.isrc = &ibc.imm; + } + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_ISUB_M) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::ISUB_M; + ibc.idst = &nreg->r[dst]; + ibc.imm = signExtend2sCompl(instr.getImm32()); + if (src != dst) { + ibc.isrc = &nreg->r[src]; + ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask); + } + else { + ibc.isrc = &zero; + ibc.memMask = ScratchpadL3Mask; + } + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_IMUL_R) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::IMUL_R; + ibc.idst = &nreg->r[dst]; + if (src != dst) { + ibc.isrc = &nreg->r[src]; + } + else { + ibc.imm = signExtend2sCompl(instr.getImm32()); + ibc.isrc = &ibc.imm; + } + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_IMUL_M) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::IMUL_M; + ibc.idst = &nreg->r[dst]; + ibc.imm = signExtend2sCompl(instr.getImm32()); + if (src != dst) { + ibc.isrc = &nreg->r[src]; + ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask); + } + else { + ibc.isrc = &zero; + ibc.memMask = ScratchpadL3Mask; + } + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_IMULH_R) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::IMULH_R; + ibc.idst = &nreg->r[dst]; + ibc.isrc = &nreg->r[src]; + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_IMULH_M) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::IMULH_M; + ibc.idst = &nreg->r[dst]; + ibc.imm = signExtend2sCompl(instr.getImm32()); + if (src != dst) { + ibc.isrc = &nreg->r[src]; + ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask); + } + else { + ibc.isrc = &zero; + ibc.memMask = ScratchpadL3Mask; + } + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_ISMULH_R) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::ISMULH_R; + ibc.idst = &nreg->r[dst]; + ibc.isrc = &nreg->r[src]; + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_ISMULH_M) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::ISMULH_M; + ibc.idst = &nreg->r[dst]; + ibc.imm = signExtend2sCompl(instr.getImm32()); + if (src != dst) { + ibc.isrc = &nreg->r[src]; + ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask); + } + else { + ibc.isrc = &zero; + ibc.memMask = ScratchpadL3Mask; + } + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_IMUL_RCP) { + uint64_t divisor = instr.getImm32(); + if (!isZeroOrPowerOf2(divisor)) { + auto dst = instr.dst % RegistersCount; + ibc.type = InstructionType::IMUL_R; + ibc.idst = &nreg->r[dst]; + ibc.imm = randomx_reciprocal(divisor); + ibc.isrc = &ibc.imm; + registerUsage[dst] = i; + } + else { + ibc.type = InstructionType::NOP; + } + return; + } + + if (opcode < ceil_INEG_R) { + auto dst = instr.dst % RegistersCount; + ibc.type = InstructionType::INEG_R; + ibc.idst = &nreg->r[dst]; + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_IXOR_R) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::IXOR_R; + ibc.idst = &nreg->r[dst]; + if (src != dst) { + ibc.isrc = &nreg->r[src]; + } + else { + ibc.imm = signExtend2sCompl(instr.getImm32()); + ibc.isrc = &ibc.imm; + } + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_IXOR_M) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::IXOR_M; + ibc.idst = &nreg->r[dst]; + ibc.imm = signExtend2sCompl(instr.getImm32()); + if (src != dst) { + ibc.isrc = &nreg->r[src]; + ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask); + } + else { + ibc.isrc = &zero; + ibc.memMask = ScratchpadL3Mask; + } + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_IROR_R) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::IROR_R; + ibc.idst = &nreg->r[dst]; + if (src != dst) { + ibc.isrc = &nreg->r[src]; + } + else { + ibc.imm = instr.getImm32(); + ibc.isrc = &ibc.imm; + } + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_IROL_R) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::IROL_R; + ibc.idst = &nreg->r[dst]; + if (src != dst) { + ibc.isrc = &nreg->r[src]; + } + else { + ibc.imm = instr.getImm32(); + ibc.isrc = &ibc.imm; + } + registerUsage[dst] = i; + return; + } + + if (opcode < ceil_ISWAP_R) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + if (src != dst) { + ibc.idst = &nreg->r[dst]; + ibc.isrc = &nreg->r[src]; + ibc.type = InstructionType::ISWAP_R; + registerUsage[dst] = i; + registerUsage[src] = i; + } + else { + ibc.type = InstructionType::NOP; + } + return; + } + + if (opcode < ceil_FSWAP_R) { + auto dst = instr.dst % RegistersCount; + ibc.type = InstructionType::FSWAP_R; + if (dst < RegisterCountFlt) + ibc.fdst = &nreg->f[dst]; + else + ibc.fdst = &nreg->e[dst - RegisterCountFlt]; + return; + } + + if (opcode < ceil_FADD_R) { + auto dst = instr.dst % RegisterCountFlt; + auto src = instr.src % RegisterCountFlt; + ibc.type = InstructionType::FADD_R; + ibc.fdst = &nreg->f[dst]; + ibc.fsrc = &nreg->a[src]; + return; + } + + if (opcode < ceil_FADD_M) { + auto dst = instr.dst % RegisterCountFlt; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::FADD_M; + ibc.fdst = &nreg->f[dst]; + ibc.isrc = &nreg->r[src]; + ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask); + ibc.imm = signExtend2sCompl(instr.getImm32()); + return; + } + + if (opcode < ceil_FSUB_R) { + auto dst = instr.dst % RegisterCountFlt; + auto src = instr.src % RegisterCountFlt; + ibc.type = InstructionType::FSUB_R; + ibc.fdst = &nreg->f[dst]; + ibc.fsrc = &nreg->a[src]; + return; + } + + if (opcode < ceil_FSUB_M) { + auto dst = instr.dst % RegisterCountFlt; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::FSUB_M; + ibc.fdst = &nreg->f[dst]; + ibc.isrc = &nreg->r[src]; + ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask); + ibc.imm = signExtend2sCompl(instr.getImm32()); + return; + } + + if (opcode < ceil_FSCAL_R) { + auto dst = instr.dst % RegisterCountFlt; + ibc.fdst = &nreg->f[dst]; + ibc.type = InstructionType::FSCAL_R; + return; + } + + if (opcode < ceil_FMUL_R) { + auto dst = instr.dst % RegisterCountFlt; + auto src = instr.src % RegisterCountFlt; + ibc.type = InstructionType::FMUL_R; + ibc.fdst = &nreg->e[dst]; + ibc.fsrc = &nreg->a[src]; + return; + } + + if (opcode < ceil_FDIV_M) { + auto dst = instr.dst % RegisterCountFlt; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::FDIV_M; + ibc.fdst = &nreg->e[dst]; + ibc.isrc = &nreg->r[src]; + ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask); + ibc.imm = signExtend2sCompl(instr.getImm32()); + return; + } + + if (opcode < ceil_FSQRT_R) { + auto dst = instr.dst % RegisterCountFlt; + ibc.type = InstructionType::FSQRT_R; + ibc.fdst = &nreg->e[dst]; + return; + } + + if (opcode < ceil_CBRANCH) { + ibc.type = InstructionType::CBRANCH; + //jump condition + int creg = instr.dst % RegistersCount; + ibc.idst = &nreg->r[creg]; + ibc.target = registerUsage[creg]; + int shift = instr.getModCond() + ConditionOffset; + ibc.imm = signExtend2sCompl(instr.getImm32()) | (1ULL << shift); + if (ConditionOffset > 0 || shift > 0) //clear the bit below the condition mask - this limits the number of successive jumps to 2 + ibc.imm &= ~(1ULL << (shift - 1)); + ibc.memMask = ConditionMask << shift; + //mark all registers as used + for (unsigned j = 0; j < RegistersCount; ++j) { + registerUsage[j] = i; + } + return; + } + + if (opcode < ceil_CFROUND) { + auto src = instr.src % RegistersCount; + ibc.isrc = &nreg->r[src]; + ibc.type = InstructionType::CFROUND; + ibc.imm = instr.getImm32() & 63; + return; + } + + if (opcode < ceil_ISTORE) { + auto dst = instr.dst % RegistersCount; + auto src = instr.src % RegistersCount; + ibc.type = InstructionType::ISTORE; + ibc.idst = &nreg->r[dst]; + ibc.isrc = &nreg->r[src]; + ibc.imm = signExtend2sCompl(instr.getImm32()); + if (instr.getModCond() < StoreL3Condition) + ibc.memMask = (instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask); + else + ibc.memMask = ScratchpadL3Mask; + return; + } + + if (opcode < ceil_NOP) { + ibc.type = InstructionType::NOP; + return; + } + + UNREACHABLE; + } +} diff --git a/src/RandomX/src/bytecode_machine.hpp b/src/RandomX/src/bytecode_machine.hpp new file mode 100644 index 000000000..5e82e0d37 --- /dev/null +++ b/src/RandomX/src/bytecode_machine.hpp @@ -0,0 +1,322 @@ +/* +Copyright (c) 2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include "common.hpp" +#include "intrin_portable.h" +#include "instruction.hpp" +#include "program.hpp" + +namespace randomx { + + //register file in machine byte order + struct NativeRegisterFile { + int_reg_t r[RegistersCount] = { 0 }; + rx_vec_f128 f[RegisterCountFlt]; + rx_vec_f128 e[RegisterCountFlt]; + rx_vec_f128 a[RegisterCountFlt]; + }; + + struct InstructionByteCode { + union { + int_reg_t* idst; + rx_vec_f128* fdst; + }; + union { + const int_reg_t* isrc; + const rx_vec_f128* fsrc; + }; + union { + uint64_t imm; + int64_t simm; + }; + InstructionType type; + union { + int16_t target; + uint16_t shift; + }; + uint32_t memMask; + }; + +#define OPCODE_CEIL_DECLARE(curr, prev) constexpr int ceil_ ## curr = ceil_ ## prev + RANDOMX_FREQ_ ## curr; + constexpr int ceil_NULL = 0; + OPCODE_CEIL_DECLARE(IADD_RS, NULL); + OPCODE_CEIL_DECLARE(IADD_M, IADD_RS); + OPCODE_CEIL_DECLARE(ISUB_R, IADD_M); + OPCODE_CEIL_DECLARE(ISUB_M, ISUB_R); + OPCODE_CEIL_DECLARE(IMUL_R, ISUB_M); + OPCODE_CEIL_DECLARE(IMUL_M, IMUL_R); + OPCODE_CEIL_DECLARE(IMULH_R, IMUL_M); + OPCODE_CEIL_DECLARE(IMULH_M, IMULH_R); + OPCODE_CEIL_DECLARE(ISMULH_R, IMULH_M); + OPCODE_CEIL_DECLARE(ISMULH_M, ISMULH_R); + OPCODE_CEIL_DECLARE(IMUL_RCP, ISMULH_M); + OPCODE_CEIL_DECLARE(INEG_R, IMUL_RCP); + OPCODE_CEIL_DECLARE(IXOR_R, INEG_R); + OPCODE_CEIL_DECLARE(IXOR_M, IXOR_R); + OPCODE_CEIL_DECLARE(IROR_R, IXOR_M); + OPCODE_CEIL_DECLARE(IROL_R, IROR_R); + OPCODE_CEIL_DECLARE(ISWAP_R, IROL_R); + OPCODE_CEIL_DECLARE(FSWAP_R, ISWAP_R); + OPCODE_CEIL_DECLARE(FADD_R, FSWAP_R); + OPCODE_CEIL_DECLARE(FADD_M, FADD_R); + OPCODE_CEIL_DECLARE(FSUB_R, FADD_M); + OPCODE_CEIL_DECLARE(FSUB_M, FSUB_R); + OPCODE_CEIL_DECLARE(FSCAL_R, FSUB_M); + OPCODE_CEIL_DECLARE(FMUL_R, FSCAL_R); + OPCODE_CEIL_DECLARE(FDIV_M, FMUL_R); + OPCODE_CEIL_DECLARE(FSQRT_R, FDIV_M); + OPCODE_CEIL_DECLARE(CBRANCH, FSQRT_R); + OPCODE_CEIL_DECLARE(CFROUND, CBRANCH); + OPCODE_CEIL_DECLARE(ISTORE, CFROUND); + OPCODE_CEIL_DECLARE(NOP, ISTORE); +#undef OPCODE_CEIL_DECLARE + +#define RANDOMX_EXE_ARGS InstructionByteCode& ibc, int& pc, uint8_t* scratchpad, ProgramConfiguration& config +#define RANDOMX_GEN_ARGS Instruction& instr, int i, InstructionByteCode& ibc + + class BytecodeMachine; + + typedef void(BytecodeMachine::*InstructionGenBytecode)(RANDOMX_GEN_ARGS); + + class BytecodeMachine { + public: + void beginCompilation(NativeRegisterFile& regFile) { + for (unsigned i = 0; i < RegistersCount; ++i) { + registerUsage[i] = -1; + } + nreg = ®File; + } + + void compileProgram(Program& program, InstructionByteCode bytecode[RANDOMX_PROGRAM_SIZE], NativeRegisterFile& regFile) { + beginCompilation(regFile); + for (unsigned i = 0; i < RANDOMX_PROGRAM_SIZE; ++i) { + auto& instr = program(i); + auto& ibc = bytecode[i]; + compileInstruction(instr, i, ibc); + } + } + + static void executeBytecode(InstructionByteCode bytecode[RANDOMX_PROGRAM_SIZE], uint8_t* scratchpad, ProgramConfiguration& config) { + for (int pc = 0; pc < RANDOMX_PROGRAM_SIZE; ++pc) { + auto& ibc = bytecode[pc]; + executeInstruction(ibc, pc, scratchpad, config); + } + } + + void compileInstruction(RANDOMX_GEN_ARGS) +#ifdef RANDOMX_GEN_TABLE + { + auto generator = genTable[instr.opcode]; + (this->*generator)(instr, i, ibc); + } +#else + ; +#endif + + static void executeInstruction(RANDOMX_EXE_ARGS); + + static void exe_IADD_RS(RANDOMX_EXE_ARGS) { + *ibc.idst += (*ibc.isrc << ibc.shift) + ibc.imm; + } + + static void exe_IADD_M(RANDOMX_EXE_ARGS) { + *ibc.idst += load64(getScratchpadAddress(ibc, scratchpad)); + } + + static void exe_ISUB_R(RANDOMX_EXE_ARGS) { + *ibc.idst -= *ibc.isrc; + } + + static void exe_ISUB_M(RANDOMX_EXE_ARGS) { + *ibc.idst -= load64(getScratchpadAddress(ibc, scratchpad)); + } + + static void exe_IMUL_R(RANDOMX_EXE_ARGS) { + *ibc.idst *= *ibc.isrc; + } + + static void exe_IMUL_M(RANDOMX_EXE_ARGS) { + *ibc.idst *= load64(getScratchpadAddress(ibc, scratchpad)); + } + + static void exe_IMULH_R(RANDOMX_EXE_ARGS) { + *ibc.idst = mulh(*ibc.idst, *ibc.isrc); + } + + static void exe_IMULH_M(RANDOMX_EXE_ARGS) { + *ibc.idst = mulh(*ibc.idst, load64(getScratchpadAddress(ibc, scratchpad))); + } + + static void exe_ISMULH_R(RANDOMX_EXE_ARGS) { + *ibc.idst = smulh(unsigned64ToSigned2sCompl(*ibc.idst), unsigned64ToSigned2sCompl(*ibc.isrc)); + } + + static void exe_ISMULH_M(RANDOMX_EXE_ARGS) { + *ibc.idst = smulh(unsigned64ToSigned2sCompl(*ibc.idst), unsigned64ToSigned2sCompl(load64(getScratchpadAddress(ibc, scratchpad)))); + } + + static void exe_INEG_R(RANDOMX_EXE_ARGS) { + *ibc.idst = ~(*ibc.idst) + 1; //two's complement negative + } + + static void exe_IXOR_R(RANDOMX_EXE_ARGS) { + *ibc.idst ^= *ibc.isrc; + } + + static void exe_IXOR_M(RANDOMX_EXE_ARGS) { + *ibc.idst ^= load64(getScratchpadAddress(ibc, scratchpad)); + } + + static void exe_IROR_R(RANDOMX_EXE_ARGS) { + *ibc.idst = rotr(*ibc.idst, *ibc.isrc & 63); + } + + static void exe_IROL_R(RANDOMX_EXE_ARGS) { + *ibc.idst = rotl(*ibc.idst, *ibc.isrc & 63); + } + + static void exe_ISWAP_R(RANDOMX_EXE_ARGS) { + int_reg_t temp = *ibc.isrc; + *(int_reg_t*)ibc.isrc = *ibc.idst; + *ibc.idst = temp; + } + + static void exe_FSWAP_R(RANDOMX_EXE_ARGS) { + *ibc.fdst = rx_swap_vec_f128(*ibc.fdst); + } + + static void exe_FADD_R(RANDOMX_EXE_ARGS) { + *ibc.fdst = rx_add_vec_f128(*ibc.fdst, *ibc.fsrc); + } + + static void exe_FADD_M(RANDOMX_EXE_ARGS) { + rx_vec_f128 fsrc = rx_cvt_packed_int_vec_f128(getScratchpadAddress(ibc, scratchpad)); + *ibc.fdst = rx_add_vec_f128(*ibc.fdst, fsrc); + } + + static void exe_FSUB_R(RANDOMX_EXE_ARGS) { + *ibc.fdst = rx_sub_vec_f128(*ibc.fdst, *ibc.fsrc); + } + + static void exe_FSUB_M(RANDOMX_EXE_ARGS) { + rx_vec_f128 fsrc = rx_cvt_packed_int_vec_f128(getScratchpadAddress(ibc, scratchpad)); + *ibc.fdst = rx_sub_vec_f128(*ibc.fdst, fsrc); + } + + static void exe_FSCAL_R(RANDOMX_EXE_ARGS) { + const rx_vec_f128 mask = rx_set1_vec_f128(0x80F0000000000000); + *ibc.fdst = rx_xor_vec_f128(*ibc.fdst, mask); + } + + static void exe_FMUL_R(RANDOMX_EXE_ARGS) { + *ibc.fdst = rx_mul_vec_f128(*ibc.fdst, *ibc.fsrc); + } + + static void exe_FDIV_M(RANDOMX_EXE_ARGS) { + rx_vec_f128 fsrc = maskRegisterExponentMantissa( + config, + rx_cvt_packed_int_vec_f128(getScratchpadAddress(ibc, scratchpad)) + ); + *ibc.fdst = rx_div_vec_f128(*ibc.fdst, fsrc); + } + + static void exe_FSQRT_R(RANDOMX_EXE_ARGS) { + *ibc.fdst = rx_sqrt_vec_f128(*ibc.fdst); + } + + static void exe_CBRANCH(RANDOMX_EXE_ARGS) { + *ibc.idst += ibc.imm; + if ((*ibc.idst & ibc.memMask) == 0) { + pc = ibc.target; + } + } + + static void exe_CFROUND(RANDOMX_EXE_ARGS) { + rx_set_rounding_mode(rotr(*ibc.isrc, ibc.imm) % 4); + } + + static void exe_ISTORE(RANDOMX_EXE_ARGS) { + store64(scratchpad + ((*ibc.idst + ibc.imm) & ibc.memMask), *ibc.isrc); + } + protected: + static rx_vec_f128 maskRegisterExponentMantissa(ProgramConfiguration& config, rx_vec_f128 x) { + const rx_vec_f128 xmantissaMask = rx_set_vec_f128(dynamicMantissaMask, dynamicMantissaMask); + const rx_vec_f128 xexponentMask = rx_load_vec_f128((const double*)&config.eMask); + x = rx_and_vec_f128(x, xmantissaMask); + x = rx_or_vec_f128(x, xexponentMask); + return x; + } + + private: + static const int_reg_t zero; + int registerUsage[RegistersCount]; + NativeRegisterFile* nreg; + + static void* getScratchpadAddress(InstructionByteCode& ibc, uint8_t* scratchpad) { + uint32_t addr = (*ibc.isrc + ibc.imm) & ibc.memMask; + return scratchpad + addr; + } + +#ifdef RANDOMX_GEN_TABLE + static InstructionGenBytecode genTable[256]; + + void gen_IADD_RS(RANDOMX_GEN_ARGS); + void gen_IADD_M(RANDOMX_GEN_ARGS); + void gen_ISUB_R(RANDOMX_GEN_ARGS); + void gen_ISUB_M(RANDOMX_GEN_ARGS); + void gen_IMUL_R(RANDOMX_GEN_ARGS); + void gen_IMUL_M(RANDOMX_GEN_ARGS); + void gen_IMULH_R(RANDOMX_GEN_ARGS); + void gen_IMULH_M(RANDOMX_GEN_ARGS); + void gen_ISMULH_R(RANDOMX_GEN_ARGS); + void gen_ISMULH_M(RANDOMX_GEN_ARGS); + void gen_IMUL_RCP(RANDOMX_GEN_ARGS); + void gen_INEG_R(RANDOMX_GEN_ARGS); + void gen_IXOR_R(RANDOMX_GEN_ARGS); + void gen_IXOR_M(RANDOMX_GEN_ARGS); + void gen_IROR_R(RANDOMX_GEN_ARGS); + void gen_IROL_R(RANDOMX_GEN_ARGS); + void gen_ISWAP_R(RANDOMX_GEN_ARGS); + void gen_FSWAP_R(RANDOMX_GEN_ARGS); + void gen_FADD_R(RANDOMX_GEN_ARGS); + void gen_FADD_M(RANDOMX_GEN_ARGS); + void gen_FSUB_R(RANDOMX_GEN_ARGS); + void gen_FSUB_M(RANDOMX_GEN_ARGS); + void gen_FSCAL_R(RANDOMX_GEN_ARGS); + void gen_FMUL_R(RANDOMX_GEN_ARGS); + void gen_FDIV_M(RANDOMX_GEN_ARGS); + void gen_FSQRT_R(RANDOMX_GEN_ARGS); + void gen_CBRANCH(RANDOMX_GEN_ARGS); + void gen_CFROUND(RANDOMX_GEN_ARGS); + void gen_ISTORE(RANDOMX_GEN_ARGS); + void gen_NOP(RANDOMX_GEN_ARGS); +#endif + }; +} diff --git a/src/RandomX/src/common.hpp b/src/RandomX/src/common.hpp new file mode 100644 index 000000000..a77feb3bf --- /dev/null +++ b/src/RandomX/src/common.hpp @@ -0,0 +1,187 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include +#include +#include "blake2/endian.h" +#include "configuration.h" +#include "randomx.h" + +namespace randomx { + + static_assert(RANDOMX_ARGON_MEMORY >= 8, "RANDOMX_ARGON_MEMORY must be at least 8."); + static_assert(RANDOMX_ARGON_MEMORY <= 2097152, "RANDOMX_ARGON_MEMORY must not exceed 2097152."); + static_assert((RANDOMX_ARGON_MEMORY & (RANDOMX_ARGON_MEMORY - 1)) == 0, "RANDOMX_ARGON_MEMORY must be a power of 2."); + static_assert(RANDOMX_ARGON_ITERATIONS > 0 && RANDOMX_ARGON_ITERATIONS < UINT32_MAX, "RANDOMX_ARGON_ITERATIONS must be a positive 32-bit integer."); + static_assert(RANDOMX_ARGON_LANES > 0 && RANDOMX_ARGON_LANES <= 16777215, "RANDOMX_ARGON_LANES out of range"); + static_assert(RANDOMX_DATASET_BASE_SIZE >= 64, "RANDOMX_DATASET_BASE_SIZE must be at least 64."); + static_assert((RANDOMX_DATASET_BASE_SIZE & (RANDOMX_DATASET_BASE_SIZE - 1)) == 0, "RANDOMX_DATASET_BASE_SIZE must be a power of 2."); + static_assert(RANDOMX_DATASET_BASE_SIZE <= 4294967296ULL, "RANDOMX_DATASET_BASE_SIZE must not exceed 4294967296."); + static_assert(RANDOMX_DATASET_EXTRA_SIZE % 64 == 0, "RANDOMX_DATASET_EXTRA_SIZE must be divisible by 64."); + static_assert((uint64_t)RANDOMX_DATASET_BASE_SIZE + RANDOMX_DATASET_EXTRA_SIZE <= 17179869184, "Dataset size must not exceed 16 GiB."); + static_assert(RANDOMX_PROGRAM_SIZE > 0, "RANDOMX_PROGRAM_SIZE must be greater than 0"); + static_assert(RANDOMX_PROGRAM_SIZE <= 32768, "RANDOMX_PROGRAM_SIZE must not exceed 32768"); + static_assert(RANDOMX_PROGRAM_ITERATIONS > 0, "RANDOMX_PROGRAM_ITERATIONS must be greater than 0"); + static_assert(RANDOMX_PROGRAM_COUNT > 0, "RANDOMX_PROGRAM_COUNT must be greater than 0"); + static_assert((RANDOMX_SCRATCHPAD_L3 & (RANDOMX_SCRATCHPAD_L3 - 1)) == 0, "RANDOMX_SCRATCHPAD_L3 must be a power of 2."); + static_assert(RANDOMX_SCRATCHPAD_L3 >= RANDOMX_SCRATCHPAD_L2, "RANDOMX_SCRATCHPAD_L3 must be greater than or equal to RANDOMX_SCRATCHPAD_L2."); + static_assert((RANDOMX_SCRATCHPAD_L2 & (RANDOMX_SCRATCHPAD_L2 - 1)) == 0, "RANDOMX_SCRATCHPAD_L2 must be a power of 2."); + static_assert(RANDOMX_SCRATCHPAD_L2 >= RANDOMX_SCRATCHPAD_L1, "RANDOMX_SCRATCHPAD_L2 must be greater than or equal to RANDOMX_SCRATCHPAD_L1."); + static_assert(RANDOMX_SCRATCHPAD_L1 >= 64, "RANDOMX_SCRATCHPAD_L1 must be at least 64."); + static_assert((RANDOMX_SCRATCHPAD_L1 & (RANDOMX_SCRATCHPAD_L1 - 1)) == 0, "RANDOMX_SCRATCHPAD_L1 must be a power of 2."); + static_assert(RANDOMX_CACHE_ACCESSES > 1, "RANDOMX_CACHE_ACCESSES must be greater than 1"); + static_assert(RANDOMX_SUPERSCALAR_LATENCY > 0, "RANDOMX_SUPERSCALAR_LATENCY must be greater than 0"); + static_assert(RANDOMX_SUPERSCALAR_LATENCY <= 10000, "RANDOMX_SUPERSCALAR_LATENCY must not exceed 10000"); + static_assert(RANDOMX_JUMP_BITS > 0, "RANDOMX_JUMP_BITS must be greater than 0."); + static_assert(RANDOMX_JUMP_OFFSET >= 0, "RANDOMX_JUMP_OFFSET must be greater than or equal to 0."); + static_assert(RANDOMX_JUMP_BITS + RANDOMX_JUMP_OFFSET <= 16, "RANDOMX_JUMP_BITS + RANDOMX_JUMP_OFFSET must not exceed 16."); + + constexpr int wtSum = RANDOMX_FREQ_IADD_RS + RANDOMX_FREQ_IADD_M + RANDOMX_FREQ_ISUB_R + \ + RANDOMX_FREQ_ISUB_M + RANDOMX_FREQ_IMUL_R + RANDOMX_FREQ_IMUL_M + RANDOMX_FREQ_IMULH_R + \ + RANDOMX_FREQ_IMULH_M + RANDOMX_FREQ_ISMULH_R + RANDOMX_FREQ_ISMULH_M + RANDOMX_FREQ_IMUL_RCP + \ + RANDOMX_FREQ_INEG_R + RANDOMX_FREQ_IXOR_R + RANDOMX_FREQ_IXOR_M + RANDOMX_FREQ_IROR_R + RANDOMX_FREQ_IROL_R + RANDOMX_FREQ_ISWAP_R + \ + RANDOMX_FREQ_FSWAP_R + RANDOMX_FREQ_FADD_R + RANDOMX_FREQ_FADD_M + RANDOMX_FREQ_FSUB_R + RANDOMX_FREQ_FSUB_M + \ + RANDOMX_FREQ_FSCAL_R + RANDOMX_FREQ_FMUL_R + RANDOMX_FREQ_FDIV_M + RANDOMX_FREQ_FSQRT_R + RANDOMX_FREQ_CBRANCH + \ + RANDOMX_FREQ_CFROUND + RANDOMX_FREQ_ISTORE + RANDOMX_FREQ_NOP; + + static_assert(wtSum == 256, "Sum of instruction frequencies must be 256."); + + + constexpr uint32_t ArgonBlockSize = 1024; + constexpr int ArgonSaltSize = sizeof("" RANDOMX_ARGON_SALT) - 1; + static_assert(ArgonSaltSize >= 8, "RANDOMX_ARGON_SALT must be at least 8 characters long"); + constexpr int SuperscalarMaxSize = 3 * RANDOMX_SUPERSCALAR_LATENCY + 2; + constexpr size_t CacheLineSize = RANDOMX_DATASET_ITEM_SIZE; + constexpr int ScratchpadSize = RANDOMX_SCRATCHPAD_L3; + constexpr uint32_t CacheLineAlignMask = (RANDOMX_DATASET_BASE_SIZE - 1) & ~(CacheLineSize - 1); + constexpr uint32_t CacheSize = RANDOMX_ARGON_MEMORY * ArgonBlockSize; + constexpr uint64_t DatasetSize = RANDOMX_DATASET_BASE_SIZE + RANDOMX_DATASET_EXTRA_SIZE; + constexpr uint32_t DatasetExtraItems = RANDOMX_DATASET_EXTRA_SIZE / RANDOMX_DATASET_ITEM_SIZE; + constexpr uint32_t ConditionMask = ((1 << RANDOMX_JUMP_BITS) - 1); + constexpr int ConditionOffset = RANDOMX_JUMP_OFFSET; + constexpr int StoreL3Condition = 14; + + //Prevent some unsafe configurations. +#ifndef RANDOMX_UNSAFE + static_assert((uint64_t)ArgonBlockSize * RANDOMX_CACHE_ACCESSES * RANDOMX_ARGON_MEMORY + 33554432 >= (uint64_t)RANDOMX_DATASET_BASE_SIZE + RANDOMX_DATASET_EXTRA_SIZE, "Unsafe configuration: Memory-time tradeoffs"); + static_assert((128 + RANDOMX_PROGRAM_SIZE * RANDOMX_FREQ_ISTORE / 256) * (RANDOMX_PROGRAM_COUNT * RANDOMX_PROGRAM_ITERATIONS) >= RANDOMX_SCRATCHPAD_L3, "Unsafe configuration: Insufficient Scratchpad writes"); + static_assert(RANDOMX_PROGRAM_COUNT > 1, "Unsafe configuration: Program filtering strategies"); + static_assert(RANDOMX_PROGRAM_SIZE >= 64, "Unsafe configuration: Low program entropy"); + static_assert(RANDOMX_PROGRAM_ITERATIONS >= 400, "Unsafe configuration: High compilation overhead"); +#endif + +#ifdef TRACE + constexpr bool trace = true; +#else + constexpr bool trace = false; +#endif + +#ifndef UNREACHABLE +#ifdef __GNUC__ +#define UNREACHABLE __builtin_unreachable() +#elif _MSC_VER +#define UNREACHABLE __assume(false) +#else +#define UNREACHABLE +#endif +#endif + +#if defined(_M_X64) || defined(__x86_64__) + #define RANDOMX_HAVE_COMPILER 1 + class JitCompilerX86; + using JitCompiler = JitCompilerX86; +#elif defined(__aarch64__) + #define RANDOMX_HAVE_COMPILER 1 + class JitCompilerA64; + using JitCompiler = JitCompilerA64; +#else + #define RANDOMX_HAVE_COMPILER 0 + class JitCompilerFallback; + using JitCompiler = JitCompilerFallback; +#endif + + using addr_t = uint32_t; + + using int_reg_t = uint64_t; + + struct fpu_reg_t { + double lo; + double hi; + }; + + constexpr uint32_t ScratchpadL1 = RANDOMX_SCRATCHPAD_L1 / sizeof(int_reg_t); + constexpr uint32_t ScratchpadL2 = RANDOMX_SCRATCHPAD_L2 / sizeof(int_reg_t); + constexpr uint32_t ScratchpadL3 = RANDOMX_SCRATCHPAD_L3 / sizeof(int_reg_t); + constexpr int ScratchpadL1Mask = (ScratchpadL1 - 1) * 8; + constexpr int ScratchpadL2Mask = (ScratchpadL2 - 1) * 8; + constexpr int ScratchpadL1Mask16 = (ScratchpadL1 / 2 - 1) * 16; + constexpr int ScratchpadL2Mask16 = (ScratchpadL2 / 2 - 1) * 16; + constexpr int ScratchpadL3Mask = (ScratchpadL3 - 1) * 8; + constexpr int ScratchpadL3Mask64 = (ScratchpadL3 / 8 - 1) * 64; + constexpr int RegistersCount = 8; + constexpr int RegisterCountFlt = RegistersCount / 2; + constexpr int RegisterNeedsDisplacement = 5; //x86 r13 register + constexpr int RegisterNeedsSib = 4; //x86 r12 register + + inline bool isZeroOrPowerOf2(uint64_t x) { + return (x & (x - 1)) == 0; + } + + constexpr int mantissaSize = 52; + constexpr int exponentSize = 11; + constexpr uint64_t mantissaMask = (1ULL << mantissaSize) - 1; + constexpr uint64_t exponentMask = (1ULL << exponentSize) - 1; + constexpr int exponentBias = 1023; + constexpr int dynamicExponentBits = 4; + constexpr int staticExponentBits = 4; + constexpr uint64_t constExponentBits = 0x300; + constexpr uint64_t dynamicMantissaMask = (1ULL << (mantissaSize + dynamicExponentBits)) - 1; + + struct MemoryRegisters { + addr_t mx, ma; + uint8_t* memory = nullptr; + }; + + //register file in little-endian byte order + struct RegisterFile { + int_reg_t r[RegistersCount]; + fpu_reg_t f[RegisterCountFlt]; + fpu_reg_t e[RegisterCountFlt]; + fpu_reg_t a[RegisterCountFlt]; + }; + + typedef void(ProgramFunc)(RegisterFile&, MemoryRegisters&, uint8_t* /* scratchpad */, uint64_t); + typedef void(DatasetInitFunc)(randomx_cache* cache, uint8_t* dataset, uint32_t startBlock, uint32_t endBlock); + + typedef void(DatasetDeallocFunc)(randomx_dataset*); + typedef void(CacheDeallocFunc)(randomx_cache*); + typedef void(CacheInitializeFunc)(randomx_cache*, const void*, size_t); +} diff --git a/src/RandomX/src/configuration.h b/src/RandomX/src/configuration.h new file mode 100644 index 000000000..84400ddce --- /dev/null +++ b/src/RandomX/src/configuration.h @@ -0,0 +1,125 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +//Cache size in KiB. Must be a power of 2. +#define RANDOMX_ARGON_MEMORY 262144 + +//Number of Argon2d iterations for Cache initialization. +#define RANDOMX_ARGON_ITERATIONS 3 + +//Number of parallel lanes for Cache initialization. +#define RANDOMX_ARGON_LANES 1 + +//Argon2d salt +#define RANDOMX_ARGON_SALT "RandomX\x03" + +//Number of random Cache accesses per Dataset item. Minimum is 2. +#define RANDOMX_CACHE_ACCESSES 8 + +//Target latency for SuperscalarHash (in cycles of the reference CPU). +#define RANDOMX_SUPERSCALAR_LATENCY 170 + +//Dataset base size in bytes. Must be a power of 2. +#define RANDOMX_DATASET_BASE_SIZE 2147483648 + +//Dataset extra size. Must be divisible by 64. +#define RANDOMX_DATASET_EXTRA_SIZE 33554368 + +//Number of instructions in a RandomX program. Must be divisible by 8. +#define RANDOMX_PROGRAM_SIZE 256 + +//Number of iterations during VM execution. +#define RANDOMX_PROGRAM_ITERATIONS 2048 + +//Number of chained VM executions per hash. +#define RANDOMX_PROGRAM_COUNT 8 + +//Scratchpad L3 size in bytes. Must be a power of 2. +#define RANDOMX_SCRATCHPAD_L3 2097152 + +//Scratchpad L2 size in bytes. Must be a power of two and less than or equal to RANDOMX_SCRATCHPAD_L3. +#define RANDOMX_SCRATCHPAD_L2 262144 + +//Scratchpad L1 size in bytes. Must be a power of two (minimum 64) and less than or equal to RANDOMX_SCRATCHPAD_L2. +#define RANDOMX_SCRATCHPAD_L1 16384 + +//Jump condition mask size in bits. +#define RANDOMX_JUMP_BITS 8 + +//Jump condition mask offset in bits. The sum of RANDOMX_JUMP_BITS and RANDOMX_JUMP_OFFSET must not exceed 16. +#define RANDOMX_JUMP_OFFSET 8 + +/* +Instruction frequencies (per 256 opcodes) +Total sum of frequencies must be 256 +*/ + +//Integer instructions +#define RANDOMX_FREQ_IADD_RS 16 +#define RANDOMX_FREQ_IADD_M 7 +#define RANDOMX_FREQ_ISUB_R 16 +#define RANDOMX_FREQ_ISUB_M 7 +#define RANDOMX_FREQ_IMUL_R 16 +#define RANDOMX_FREQ_IMUL_M 4 +#define RANDOMX_FREQ_IMULH_R 4 +#define RANDOMX_FREQ_IMULH_M 1 +#define RANDOMX_FREQ_ISMULH_R 4 +#define RANDOMX_FREQ_ISMULH_M 1 +#define RANDOMX_FREQ_IMUL_RCP 8 +#define RANDOMX_FREQ_INEG_R 2 +#define RANDOMX_FREQ_IXOR_R 15 +#define RANDOMX_FREQ_IXOR_M 5 +#define RANDOMX_FREQ_IROR_R 8 +#define RANDOMX_FREQ_IROL_R 2 +#define RANDOMX_FREQ_ISWAP_R 4 + +//Floating point instructions +#define RANDOMX_FREQ_FSWAP_R 4 +#define RANDOMX_FREQ_FADD_R 16 +#define RANDOMX_FREQ_FADD_M 5 +#define RANDOMX_FREQ_FSUB_R 16 +#define RANDOMX_FREQ_FSUB_M 5 +#define RANDOMX_FREQ_FSCAL_R 6 +#define RANDOMX_FREQ_FMUL_R 32 +#define RANDOMX_FREQ_FDIV_M 4 +#define RANDOMX_FREQ_FSQRT_R 6 + +//Control instructions +#define RANDOMX_FREQ_CBRANCH 25 +#define RANDOMX_FREQ_CFROUND 1 + +//Store instruction +#define RANDOMX_FREQ_ISTORE 16 + +//No-op instruction +#define RANDOMX_FREQ_NOP 0 +/* ------ + 256 +*/ diff --git a/src/RandomX/src/cpu.cpp b/src/RandomX/src/cpu.cpp new file mode 100644 index 000000000..44ac402ce --- /dev/null +++ b/src/RandomX/src/cpu.cpp @@ -0,0 +1,76 @@ +/* +Copyright (c) 2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "cpu.hpp" + +#if defined(_M_X64) || defined(__x86_64__) + #define HAVE_CPUID + #if defined(_MSC_VER) + #include + #define cpuid(info, x) __cpuidex(info, x, 0) + #else //GCC + #include + void cpuid(int info[4], int InfoType) { + __cpuid_count(InfoType, 0, info[0], info[1], info[2], info[3]); + } + #endif +#endif + +#if defined(HAVE_HWCAP) + #include + #include +#endif + +namespace randomx { + + Cpu::Cpu() : aes_(false), ssse3_(false), avx2_(false) { +#ifdef HAVE_CPUID + int info[4]; + cpuid(info, 0); + int nIds = info[0]; + if (nIds >= 0x00000001) { + cpuid(info, 0x00000001); + ssse3_ = (info[2] & (1 << 9)) != 0; + aes_ = (info[2] & (1 << 25)) != 0; + } + if (nIds >= 0x00000007) { + cpuid(info, 0x00000007); + avx2_ = (info[1] & (1 << 5)) != 0; + } +#elif defined(__aarch64__) + #if defined(HWCAP_AES) + long hwcaps = getauxval(AT_HWCAP); + aes_ = (hwcaps & HWCAP_AES) != 0; + #elif defined(__APPLE__) + aes_ = true; + #endif +#endif + //TODO POWER8 AES + } + +} diff --git a/src/RandomX/src/cpu.hpp b/src/RandomX/src/cpu.hpp new file mode 100644 index 000000000..516dd47a2 --- /dev/null +++ b/src/RandomX/src/cpu.hpp @@ -0,0 +1,49 @@ +/* +Copyright (c) 2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +namespace randomx { + + class Cpu { + public: + Cpu(); + bool hasAes() const { + return aes_; + } + bool hasSsse3() const { + return ssse3_; + } + bool hasAvx2() const { + return avx2_; + } + private: + bool aes_, ssse3_, avx2_; + }; + +} diff --git a/src/RandomX/src/dataset.cpp b/src/RandomX/src/dataset.cpp new file mode 100644 index 000000000..675c5abc5 --- /dev/null +++ b/src/RandomX/src/dataset.cpp @@ -0,0 +1,196 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/* Original code from Argon2 reference source code package used under CC0 Licence + * https://github.com/P-H-C/phc-winner-argon2 + * Copyright 2015 + * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves +*/ + +#include +#include +#include +#include +#include +#include +#include + +#include "common.hpp" +#include "dataset.hpp" +#include "virtual_memory.hpp" +#include "superscalar.hpp" +#include "blake2_generator.hpp" +#include "reciprocal.h" +#include "blake2/endian.h" +#include "argon2.h" +#include "argon2_core.h" +#include "jit_compiler.hpp" +#include "intrin_portable.h" + +static_assert(RANDOMX_ARGON_MEMORY % (RANDOMX_ARGON_LANES * ARGON2_SYNC_POINTS) == 0, "RANDOMX_ARGON_MEMORY - invalid value"); +static_assert(ARGON2_BLOCK_SIZE == randomx::ArgonBlockSize, "Unpexpected value of ARGON2_BLOCK_SIZE"); + +namespace randomx { + + template + void deallocCache(randomx_cache* cache) { + if (cache->memory != nullptr) + Allocator::freeMemory(cache->memory, CacheSize); + if (cache->jit != nullptr) + delete cache->jit; + } + + template void deallocCache(randomx_cache* cache); + template void deallocCache(randomx_cache* cache); + + void initCache(randomx_cache* cache, const void* key, size_t keySize) { + uint32_t memory_blocks, segment_length; + argon2_instance_t instance; + argon2_context context; + + context.out = nullptr; + context.outlen = 0; + context.pwd = CONST_CAST(uint8_t *)key; + context.pwdlen = (uint32_t)keySize; + context.salt = CONST_CAST(uint8_t *)RANDOMX_ARGON_SALT; + context.saltlen = (uint32_t)randomx::ArgonSaltSize; + context.secret = NULL; + context.secretlen = 0; + context.ad = NULL; + context.adlen = 0; + context.t_cost = RANDOMX_ARGON_ITERATIONS; + context.m_cost = RANDOMX_ARGON_MEMORY; + context.lanes = RANDOMX_ARGON_LANES; + context.threads = 1; + context.allocate_cbk = NULL; + context.free_cbk = NULL; + context.flags = ARGON2_DEFAULT_FLAGS; + context.version = ARGON2_VERSION_NUMBER; + + int inputsValid = randomx_argon2_validate_inputs(&context); + assert(inputsValid == ARGON2_OK); + + /* 2. Align memory size */ + /* Minimum memory_blocks = 8L blocks, where L is the number of lanes */ + memory_blocks = context.m_cost; + + segment_length = memory_blocks / (context.lanes * ARGON2_SYNC_POINTS); + + instance.version = context.version; + instance.memory = NULL; + instance.passes = context.t_cost; + instance.memory_blocks = memory_blocks; + instance.segment_length = segment_length; + instance.lane_length = segment_length * ARGON2_SYNC_POINTS; + instance.lanes = context.lanes; + instance.threads = context.threads; + instance.type = Argon2_d; + instance.memory = (block*)cache->memory; + instance.impl = cache->argonImpl; + + if (instance.threads > instance.lanes) { + instance.threads = instance.lanes; + } + + /* 3. Initialization: Hashing inputs, allocating memory, filling first + * blocks + */ + randomx_argon2_initialize(&instance, &context); + + randomx_argon2_fill_memory_blocks(&instance); + + cache->reciprocalCache.clear(); + randomx::Blake2Generator gen(key, keySize); + for (int i = 0; i < RANDOMX_CACHE_ACCESSES; ++i) { + randomx::generateSuperscalar(cache->programs[i], gen); + for (unsigned j = 0; j < cache->programs[i].getSize(); ++j) { + auto& instr = cache->programs[i](j); + if ((SuperscalarInstructionType)instr.opcode == SuperscalarInstructionType::IMUL_RCP) { + auto rcp = randomx_reciprocal(instr.getImm32()); + instr.setImm32(cache->reciprocalCache.size()); + cache->reciprocalCache.push_back(rcp); + } + } + } + } + + void initCacheCompile(randomx_cache* cache, const void* key, size_t keySize) { + initCache(cache, key, keySize); + cache->jit->enableWriting(); + cache->jit->generateSuperscalarHash(cache->programs, cache->reciprocalCache); + cache->jit->generateDatasetInitCode(); + cache->jit->enableExecution(); + } + + constexpr uint64_t superscalarMul0 = 6364136223846793005ULL; + constexpr uint64_t superscalarAdd1 = 9298411001130361340ULL; + constexpr uint64_t superscalarAdd2 = 12065312585734608966ULL; + constexpr uint64_t superscalarAdd3 = 9306329213124626780ULL; + constexpr uint64_t superscalarAdd4 = 5281919268842080866ULL; + constexpr uint64_t superscalarAdd5 = 10536153434571861004ULL; + constexpr uint64_t superscalarAdd6 = 3398623926847679864ULL; + constexpr uint64_t superscalarAdd7 = 9549104520008361294ULL; + + static inline uint8_t* getMixBlock(uint64_t registerValue, uint8_t *memory) { + constexpr uint32_t mask = CacheSize / CacheLineSize - 1; + return memory + (registerValue & mask) * CacheLineSize; + } + + void initDatasetItem(randomx_cache* cache, uint8_t* out, uint64_t itemNumber) { + int_reg_t rl[8]; + uint8_t* mixBlock; + uint64_t registerValue = itemNumber; + rl[0] = (itemNumber + 1) * superscalarMul0; + rl[1] = rl[0] ^ superscalarAdd1; + rl[2] = rl[0] ^ superscalarAdd2; + rl[3] = rl[0] ^ superscalarAdd3; + rl[4] = rl[0] ^ superscalarAdd4; + rl[5] = rl[0] ^ superscalarAdd5; + rl[6] = rl[0] ^ superscalarAdd6; + rl[7] = rl[0] ^ superscalarAdd7; + for (unsigned i = 0; i < RANDOMX_CACHE_ACCESSES; ++i) { + mixBlock = getMixBlock(registerValue, cache->memory); + rx_prefetch_nta(mixBlock); + SuperscalarProgram& prog = cache->programs[i]; + + executeSuperscalar(rl, prog, &cache->reciprocalCache); + + for (unsigned q = 0; q < 8; ++q) + rl[q] ^= load64_native(mixBlock + 8 * q); + + registerValue = rl[prog.getAddressRegister()]; + } + + memcpy(out, &rl, CacheLineSize); + } + + void initDataset(randomx_cache* cache, uint8_t* dataset, uint32_t startItem, uint32_t endItem) { + for (uint32_t itemNumber = startItem; itemNumber < endItem; ++itemNumber, dataset += CacheLineSize) + initDatasetItem(cache, dataset, itemNumber); + } +} diff --git a/src/RandomX/src/dataset.hpp b/src/RandomX/src/dataset.hpp new file mode 100644 index 000000000..d01911f9a --- /dev/null +++ b/src/RandomX/src/dataset.hpp @@ -0,0 +1,103 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include +#include +#include "common.hpp" +#include "superscalar_program.hpp" +#include "allocator.hpp" +#include "argon2.h" + +/* Global scope for C binding */ +struct randomx_dataset { + uint8_t* memory = nullptr; + randomx::DatasetDeallocFunc* dealloc; +}; + +/* Global scope for C binding */ +struct randomx_cache { + uint8_t* memory = nullptr; + randomx::CacheDeallocFunc* dealloc; + randomx::JitCompiler* jit; + randomx::CacheInitializeFunc* initialize; + randomx::DatasetInitFunc* datasetInit; + randomx::SuperscalarProgram programs[RANDOMX_CACHE_ACCESSES]; + std::vector reciprocalCache; + std::string cacheKey; + randomx_argon2_impl* argonImpl; + + bool isInitialized() { + return programs[0].getSize() != 0; + } +}; + +//A pointer to a standard-layout struct object points to its initial member +static_assert(std::is_standard_layout(), "randomx_dataset must be a standard-layout struct"); + +//the following assert fails when compiling Debug in Visual Studio (JIT mode will crash in Debug) +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && defined(_DEBUG) +#define TO_STR(x) #x +#define STR(x) TO_STR(x) +#pragma message ( __FILE__ "(" STR(__LINE__) ") warning: check std::is_standard_layout() is disabled for Debug configuration. JIT mode will crash." ) +#undef STR +#undef TO_STR +#else +static_assert(std::is_standard_layout(), "randomx_cache must be a standard-layout struct"); +#endif + +namespace randomx { + + using DefaultAllocator = AlignedAllocator; + + template + void deallocDataset(randomx_dataset* dataset) { + if (dataset->memory != nullptr) + Allocator::freeMemory(dataset->memory, DatasetSize); + } + + template + void deallocCache(randomx_cache* cache); + + void initCache(randomx_cache*, const void*, size_t); + void initCacheCompile(randomx_cache*, const void*, size_t); + void initDatasetItem(randomx_cache* cache, uint8_t* out, uint64_t blockNumber); + void initDataset(randomx_cache* cache, uint8_t* dataset, uint32_t startBlock, uint32_t endBlock); + + inline randomx_argon2_impl* selectArgonImpl(randomx_flags flags) { + if (flags & RANDOMX_FLAG_ARGON2_AVX2) { + return randomx_argon2_impl_avx2(); + } + if (flags & RANDOMX_FLAG_ARGON2_SSSE3) { + return randomx_argon2_impl_ssse3(); + } + return &randomx_argon2_fill_segment_ref; + } +} diff --git a/src/RandomX/src/instruction.cpp b/src/RandomX/src/instruction.cpp new file mode 100644 index 000000000..12e6f49b9 --- /dev/null +++ b/src/RandomX/src/instruction.cpp @@ -0,0 +1,390 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "instruction.hpp" +#include "common.hpp" + +namespace randomx { + + void Instruction::print(std::ostream& os) const { + os << names[opcode] << " "; + auto handler = engine[opcode]; + (this->*handler)(os); + } + + void Instruction::genAddressReg(std::ostream& os, int srcIndex) const { + os << (getModMem() ? "L1" : "L2") << "[r" << srcIndex << std::showpos << (int32_t)getImm32() << std::noshowpos << "]"; + } + + void Instruction::genAddressRegDst(std::ostream& os, int dstIndex) const { + if (getModCond() < StoreL3Condition) + os << (getModMem() ? "L1" : "L2"); + else + os << "L3"; + os << "[r" << dstIndex << std::showpos << (int32_t)getImm32() << std::noshowpos << "]"; + } + + void Instruction::genAddressImm(std::ostream& os) const { + os << "L3" << "[" << (getImm32() & ScratchpadL3Mask) << "]"; + } + + void Instruction::h_IADD_RS(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + os << "r" << dstIndex << ", r" << srcIndex; + if(dstIndex == RegisterNeedsDisplacement) { + os << ", " << (int32_t)getImm32(); + } + os << ", SHFT " << getModShift() << std::endl; + } + + void Instruction::h_IADD_M(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + if (dstIndex != srcIndex) { + os << "r" << dstIndex << ", "; + genAddressReg(os, srcIndex); + os << std::endl; + } + else { + os << "r" << dstIndex << ", "; + genAddressImm(os); + os << std::endl; + } + } + + void Instruction::h_ISUB_R(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + if (dstIndex != srcIndex) { + os << "r" << dstIndex << ", r" << srcIndex << std::endl; + } + else { + os << "r" << dstIndex << ", " << (int32_t)getImm32() << std::endl; + } + } + + void Instruction::h_ISUB_M(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + if (dstIndex != srcIndex) { + os << "r" << dstIndex << ", "; + genAddressReg(os, srcIndex); + os << std::endl; + } + else { + os << "r" << dstIndex << ", "; + genAddressImm(os); + os << std::endl; + } + } + + void Instruction::h_IMUL_R(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + if (dstIndex != srcIndex) { + os << "r" << dstIndex << ", r" << srcIndex << std::endl; + } + else { + os << "r" << dstIndex << ", " << (int32_t)getImm32() << std::endl; + } + } + + void Instruction::h_IMUL_M(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + if (dstIndex != srcIndex) { + os << "r" << dstIndex << ", "; + genAddressReg(os, srcIndex); + os << std::endl; + } + else { + os << "r" << dstIndex << ", "; + genAddressImm(os); + os << std::endl; + } + } + + void Instruction::h_IMULH_R(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + os << "r" << dstIndex << ", r" << srcIndex << std::endl; + } + + void Instruction::h_IMULH_M(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + if (dstIndex != srcIndex) { + os << "r" << dstIndex << ", "; + genAddressReg(os, srcIndex); + os << std::endl; + } + else { + os << "r" << dstIndex << ", "; + genAddressImm(os); + os << std::endl; + } + } + + void Instruction::h_ISMULH_R(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + os << "r" << dstIndex << ", r" << srcIndex << std::endl; + } + + void Instruction::h_ISMULH_M(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + if (dstIndex != srcIndex) { + os << "r" << dstIndex << ", "; + genAddressReg(os, srcIndex); + os << std::endl; + } + else { + os << "r" << dstIndex << ", "; + genAddressImm(os); + os << std::endl; + } + } + + void Instruction::h_INEG_R(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + os << "r" << dstIndex << std::endl; + } + + void Instruction::h_IXOR_R(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + if (dstIndex != srcIndex) { + os << "r" << dstIndex << ", r" << srcIndex << std::endl; + } + else { + os << "r" << dstIndex << ", " << (int32_t)getImm32() << std::endl; + } + } + + void Instruction::h_IXOR_M(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + if (dstIndex != srcIndex) { + os << "r" << dstIndex << ", "; + genAddressReg(os, srcIndex); + os << std::endl; + } + else { + os << "r" << dstIndex << ", "; + genAddressImm(os); + os << std::endl; + } + } + + void Instruction::h_IROR_R(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + if (dstIndex != srcIndex) { + os << "r" << dstIndex << ", r" << srcIndex << std::endl; + } + else { + os << "r" << dstIndex << ", " << (getImm32() & 63) << std::endl; + } + } + + void Instruction::h_IROL_R(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + if (dstIndex != srcIndex) { + os << "r" << dstIndex << ", r" << srcIndex << std::endl; + } + else { + os << "r" << dstIndex << ", " << (getImm32() & 63) << std::endl; + } + } + + void Instruction::h_IMUL_RCP(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + os << "r" << dstIndex << ", " << getImm32() << std::endl; + } + + void Instruction::h_ISWAP_R(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + os << "r" << dstIndex << ", r" << srcIndex << std::endl; + } + + void Instruction::h_FSWAP_R(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + const char reg = (dstIndex >= RegisterCountFlt) ? 'e' : 'f'; + dstIndex %= RegisterCountFlt; + os << reg << dstIndex << std::endl; + } + + void Instruction::h_FADD_R(std::ostream& os) const { + auto dstIndex = dst % RegisterCountFlt; + auto srcIndex = src % RegisterCountFlt; + os << "f" << dstIndex << ", a" << srcIndex << std::endl; + } + + void Instruction::h_FADD_M(std::ostream& os) const { + auto dstIndex = dst % RegisterCountFlt; + auto srcIndex = src % RegistersCount; + os << "f" << dstIndex << ", "; + genAddressReg(os, srcIndex); + os << std::endl; + } + + void Instruction::h_FSUB_R(std::ostream& os) const { + auto dstIndex = dst % RegisterCountFlt; + auto srcIndex = src % RegisterCountFlt; + os << "f" << dstIndex << ", a" << srcIndex << std::endl; + } + + void Instruction::h_FSUB_M(std::ostream& os) const { + auto dstIndex = dst % RegisterCountFlt; + auto srcIndex = src % RegistersCount; + os << "f" << dstIndex << ", "; + genAddressReg(os, srcIndex); + os << std::endl; + } + + void Instruction::h_FSCAL_R(std::ostream& os) const { + auto dstIndex = dst % RegisterCountFlt; + os << "f" << dstIndex << std::endl; + } + + void Instruction::h_FMUL_R(std::ostream& os) const { + auto dstIndex = dst % RegisterCountFlt; + auto srcIndex = src % RegisterCountFlt; + os << "e" << dstIndex << ", a" << srcIndex << std::endl; + } + + void Instruction::h_FDIV_M(std::ostream& os) const { + auto dstIndex = dst % RegisterCountFlt; + auto srcIndex = src % RegistersCount; + os << "e" << dstIndex << ", "; + genAddressReg(os, srcIndex); + os << std::endl; + } + + void Instruction::h_FSQRT_R(std::ostream& os) const { + auto dstIndex = dst % RegisterCountFlt; + os << "e" << dstIndex << std::endl; + } + + void Instruction::h_CFROUND(std::ostream& os) const { + auto srcIndex = src % RegistersCount; + os << "r" << srcIndex << ", " << (getImm32() & 63) << std::endl; + } + + void Instruction::h_CBRANCH(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + os << "r" << dstIndex << ", " << (int32_t)getImm32() << ", COND " << (int)(getModCond()) << std::endl; + } + + void Instruction::h_ISTORE(std::ostream& os) const { + auto dstIndex = dst % RegistersCount; + auto srcIndex = src % RegistersCount; + genAddressRegDst(os, dstIndex); + os << ", r" << srcIndex << std::endl; + } + + void Instruction::h_NOP(std::ostream& os) const { + os << std::endl; + } + +#include "instruction_weights.hpp" +#define INST_NAME(x) REPN(#x, WT(x)) +#define INST_HANDLE(x) REPN(&Instruction::h_##x, WT(x)) + + const char* Instruction::names[256] = { + INST_NAME(IADD_RS) + INST_NAME(IADD_M) + INST_NAME(ISUB_R) + INST_NAME(ISUB_M) + INST_NAME(IMUL_R) + INST_NAME(IMUL_M) + INST_NAME(IMULH_R) + INST_NAME(IMULH_M) + INST_NAME(ISMULH_R) + INST_NAME(ISMULH_M) + INST_NAME(IMUL_RCP) + INST_NAME(INEG_R) + INST_NAME(IXOR_R) + INST_NAME(IXOR_M) + INST_NAME(IROR_R) + INST_NAME(IROL_R) + INST_NAME(ISWAP_R) + INST_NAME(FSWAP_R) + INST_NAME(FADD_R) + INST_NAME(FADD_M) + INST_NAME(FSUB_R) + INST_NAME(FSUB_M) + INST_NAME(FSCAL_R) + INST_NAME(FMUL_R) + INST_NAME(FDIV_M) + INST_NAME(FSQRT_R) + INST_NAME(CBRANCH) + INST_NAME(CFROUND) + INST_NAME(ISTORE) + INST_NAME(NOP) + }; + + InstructionFormatter Instruction::engine[256] = { + INST_HANDLE(IADD_RS) + INST_HANDLE(IADD_M) + INST_HANDLE(ISUB_R) + INST_HANDLE(ISUB_M) + INST_HANDLE(IMUL_R) + INST_HANDLE(IMUL_M) + INST_HANDLE(IMULH_R) + INST_HANDLE(IMULH_M) + INST_HANDLE(ISMULH_R) + INST_HANDLE(ISMULH_M) + INST_HANDLE(IMUL_RCP) + INST_HANDLE(INEG_R) + INST_HANDLE(IXOR_R) + INST_HANDLE(IXOR_M) + INST_HANDLE(IROR_R) + INST_HANDLE(IROL_R) + INST_HANDLE(ISWAP_R) + INST_HANDLE(FSWAP_R) + INST_HANDLE(FADD_R) + INST_HANDLE(FADD_M) + INST_HANDLE(FSUB_R) + INST_HANDLE(FSUB_M) + INST_HANDLE(FSCAL_R) + INST_HANDLE(FMUL_R) + INST_HANDLE(FDIV_M) + INST_HANDLE(FSQRT_R) + INST_HANDLE(CBRANCH) + INST_HANDLE(CFROUND) + INST_HANDLE(ISTORE) + INST_HANDLE(NOP) + }; + +} \ No newline at end of file diff --git a/src/RandomX/src/instruction.hpp b/src/RandomX/src/instruction.hpp new file mode 100644 index 000000000..b1863b5ed --- /dev/null +++ b/src/RandomX/src/instruction.hpp @@ -0,0 +1,149 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include +#include +#include "blake2/endian.h" + +namespace randomx { + + class Instruction; + + typedef void(Instruction::*InstructionFormatter)(std::ostream&) const; + + enum class InstructionType : uint16_t { + IADD_RS = 0, + IADD_M = 1, + ISUB_R = 2, + ISUB_M = 3, + IMUL_R = 4, + IMUL_M = 5, + IMULH_R = 6, + IMULH_M = 7, + ISMULH_R = 8, + ISMULH_M = 9, + IMUL_RCP = 10, + INEG_R = 11, + IXOR_R = 12, + IXOR_M = 13, + IROR_R = 14, + IROL_R = 15, + ISWAP_R = 16, + FSWAP_R = 17, + FADD_R = 18, + FADD_M = 19, + FSUB_R = 20, + FSUB_M = 21, + FSCAL_R = 22, + FMUL_R = 23, + FDIV_M = 24, + FSQRT_R = 25, + CBRANCH = 26, + CFROUND = 27, + ISTORE = 28, + NOP = 29, + }; + + class Instruction { + public: + uint32_t getImm32() const { + return load32(&imm32); + } + void setImm32(uint32_t val) { + return store32(&imm32, val); + } + const char* getName() const { + return names[opcode]; + } + friend std::ostream& operator<<(std::ostream& os, const Instruction& i) { + i.print(os); + return os; + } + int getModMem() const { + return mod % 4; //bits 0-1 + } + int getModShift() const { + return (mod >> 2) % 4; //bits 2-3 + } + int getModCond() const { + return mod >> 4; //bits 4-7 + } + void setMod(uint8_t val) { + mod = val; + } + + uint8_t opcode; + uint8_t dst; + uint8_t src; + uint8_t mod; + uint32_t imm32; + private: + void print(std::ostream&) const; + static const char* names[256]; + static InstructionFormatter engine[256]; + void genAddressReg(std::ostream& os, int) const; + void genAddressImm(std::ostream& os) const; + void genAddressRegDst(std::ostream&, int) const; + void h_IADD_RS(std::ostream&) const; + void h_IADD_M(std::ostream&) const; + void h_ISUB_R(std::ostream&) const; + void h_ISUB_M(std::ostream&) const; + void h_IMUL_R(std::ostream&) const; + void h_IMUL_M(std::ostream&) const; + void h_IMULH_R(std::ostream&) const; + void h_IMULH_M(std::ostream&) const; + void h_ISMULH_R(std::ostream&) const; + void h_ISMULH_M(std::ostream&) const; + void h_IMUL_RCP(std::ostream&) const; + void h_INEG_R(std::ostream&) const; + void h_IXOR_R(std::ostream&) const; + void h_IXOR_M(std::ostream&) const; + void h_IROR_R(std::ostream&) const; + void h_IROL_R(std::ostream&) const; + void h_ISWAP_R(std::ostream&) const; + void h_FSWAP_R(std::ostream&) const; + void h_FADD_R(std::ostream&) const; + void h_FADD_M(std::ostream&) const; + void h_FSUB_R(std::ostream&) const; + void h_FSUB_M(std::ostream&) const; + void h_FSCAL_R(std::ostream&) const; + void h_FMUL_R(std::ostream&) const; + void h_FDIV_M(std::ostream&) const; + void h_FSQRT_R(std::ostream&) const; + void h_CBRANCH(std::ostream&) const; + void h_CFROUND(std::ostream&) const; + void h_ISTORE(std::ostream&) const; + void h_NOP(std::ostream&) const; + }; + + static_assert(sizeof(Instruction) == 8, "Invalid size of struct randomx::Instruction"); + static_assert(std::is_standard_layout(), "randomx::Instruction must be a standard-layout struct"); +} \ No newline at end of file diff --git a/src/RandomX/src/instruction_weights.hpp b/src/RandomX/src/instruction_weights.hpp new file mode 100644 index 000000000..f6c887349 --- /dev/null +++ b/src/RandomX/src/instruction_weights.hpp @@ -0,0 +1,73 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#define REP0(x) +#define REP1(x) x, +#define REP2(x) REP1(x) x, +#define REP3(x) REP2(x) x, +#define REP4(x) REP3(x) x, +#define REP5(x) REP4(x) x, +#define REP6(x) REP5(x) x, +#define REP7(x) REP6(x) x, +#define REP8(x) REP7(x) x, +#define REP9(x) REP8(x) x, +#define REP10(x) REP9(x) x, +#define REP11(x) REP10(x) x, +#define REP12(x) REP11(x) x, +#define REP13(x) REP12(x) x, +#define REP14(x) REP13(x) x, +#define REP15(x) REP14(x) x, +#define REP16(x) REP15(x) x, +#define REP17(x) REP16(x) x, +#define REP18(x) REP17(x) x, +#define REP19(x) REP18(x) x, +#define REP20(x) REP19(x) x, +#define REP21(x) REP20(x) x, +#define REP22(x) REP21(x) x, +#define REP23(x) REP22(x) x, +#define REP24(x) REP23(x) x, +#define REP25(x) REP24(x) x, +#define REP26(x) REP25(x) x, +#define REP27(x) REP26(x) x, +#define REP28(x) REP27(x) x, +#define REP29(x) REP28(x) x, +#define REP30(x) REP29(x) x, +#define REP31(x) REP30(x) x, +#define REP32(x) REP31(x) x, +#define REP33(x) REP32(x) x, +#define REP40(x) REP32(x) REP8(x) +#define REP64(x) REP32(x) REP32(x) +#define REP128(x) REP32(x) REP32(x) REP32(x) REP32(x) +#define REP232(x) REP128(x) REP40(x) REP40(x) REP24(x) +#define REP256(x) REP128(x) REP128(x) +#define REPNX(x,N) REP##N(x) +#define REPN(x,N) REPNX(x,N) +#define NUM(x) x +#define WT(x) NUM(RANDOMX_FREQ_##x) diff --git a/src/RandomX/src/instructions_portable.cpp b/src/RandomX/src/instructions_portable.cpp new file mode 100644 index 000000000..d74672714 --- /dev/null +++ b/src/RandomX/src/instructions_portable.cpp @@ -0,0 +1,208 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include "common.hpp" +#include "intrin_portable.h" +#include "blake2/endian.h" + +#if defined(__SIZEOF_INT128__) + typedef unsigned __int128 uint128_t; + typedef __int128 int128_t; + uint64_t mulh(uint64_t a, uint64_t b) { + return ((uint128_t)a * b) >> 64; + } + int64_t smulh(int64_t a, int64_t b) { + return ((int128_t)a * b) >> 64; + } + #define HAVE_MULH + #define HAVE_SMULH +#endif + +#if defined(_MSC_VER) + #define HAS_VALUE(X) X ## 0 + #define EVAL_DEFINE(X) HAS_VALUE(X) + #include + #include + + uint64_t rotl(uint64_t x, unsigned int c) { + return _rotl64(x, c); + } + uint64_t rotr(uint64_t x, unsigned int c) { + return _rotr64(x, c); + } + #define HAVE_ROTL + #define HAVE_ROTR + + #if EVAL_DEFINE(__MACHINEARM64_X64(1)) + uint64_t mulh(uint64_t a, uint64_t b) { + return __umulh(a, b); + } + #define HAVE_MULH + #endif + + #if EVAL_DEFINE(__MACHINEX64(1)) + int64_t smulh(int64_t a, int64_t b) { + int64_t hi; + _mul128(a, b, &hi); + return hi; + } + #define HAVE_SMULH + #endif + + static void setRoundMode_(uint32_t mode) { + _controlfp(mode, _MCW_RC); + } + #define HAVE_SETROUNDMODE_IMPL +#endif + +#ifndef HAVE_SETROUNDMODE_IMPL + static void setRoundMode_(uint32_t mode) { + fesetround(mode); + } +#endif + +#ifndef HAVE_ROTR + uint64_t rotr(uint64_t a, unsigned int b) { + return (a >> b) | (a << (-b & 63)); + } + #define HAVE_ROTR +#endif + +#ifndef HAVE_ROTL + uint64_t rotl(uint64_t a, unsigned int b) { + return (a << b) | (a >> (-b & 63)); + } + #define HAVE_ROTL +#endif + +#ifndef HAVE_MULH + #define LO(x) ((x)&0xffffffff) + #define HI(x) ((x)>>32) + uint64_t mulh(uint64_t a, uint64_t b) { + uint64_t ah = HI(a), al = LO(a); + uint64_t bh = HI(b), bl = LO(b); + uint64_t x00 = al * bl; + uint64_t x01 = al * bh; + uint64_t x10 = ah * bl; + uint64_t x11 = ah * bh; + uint64_t m1 = LO(x10) + LO(x01) + HI(x00); + uint64_t m2 = HI(x10) + HI(x01) + LO(x11) + HI(m1); + uint64_t m3 = HI(x11) + HI(m2); + + return (m3 << 32) + LO(m2); + } + #define HAVE_MULH +#endif + +#ifndef HAVE_SMULH + int64_t smulh(int64_t a, int64_t b) { + int64_t hi = mulh(a, b); + if (a < 0LL) hi -= b; + if (b < 0LL) hi -= a; + return hi; + } + #define HAVE_SMULH +#endif + +#ifdef RANDOMX_DEFAULT_FENV + +void rx_reset_float_state() { + setRoundMode_(FE_TONEAREST); + rx_set_double_precision(); //set precision to 53 bits if needed by the platform +} + +void rx_set_rounding_mode(uint32_t mode) { + switch (mode & 3) { + case RoundDown: + setRoundMode_(FE_DOWNWARD); + break; + case RoundUp: + setRoundMode_(FE_UPWARD); + break; + case RoundToZero: + setRoundMode_(FE_TOWARDZERO); + break; + case RoundToNearest: + setRoundMode_(FE_TONEAREST); + break; + default: + UNREACHABLE; + } +} + +uint32_t rx_get_rounding_mode() { + switch (fegetround()) { + case FE_DOWNWARD: + return RoundDown; + case FE_UPWARD: + return RoundUp; + case FE_TOWARDZERO: + return RoundToZero; + case FE_TONEAREST: + return RoundToNearest; + default: + UNREACHABLE; + } +} + +#endif + +#ifdef RANDOMX_USE_X87 + +#if defined(_MSC_VER) && defined(_M_IX86) + +void rx_set_double_precision() { + _control87(_PC_53, _MCW_PC); +} + +#elif defined(__i386) + +void rx_set_double_precision() { + uint16_t volatile x87cw; + asm volatile("fstcw %0" : "=m" (x87cw)); + x87cw &= ~0x300; + x87cw |= 0x200; + asm volatile("fldcw %0" : : "m" (x87cw)); +} + +#endif + +#endif //RANDOMX_USE_X87 + +union double_ser_t { + double f; + uint64_t i; +}; + +double loadDoublePortable(const void* addr) { + double_ser_t ds; + ds.i = load64(addr); + return ds.f; +} diff --git a/src/RandomX/src/intrin_portable.h b/src/RandomX/src/intrin_portable.h new file mode 100644 index 000000000..05f6cd33b --- /dev/null +++ b/src/RandomX/src/intrin_portable.h @@ -0,0 +1,751 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include "blake2/endian.h" + +constexpr int32_t unsigned32ToSigned2sCompl(uint32_t x) { + return (-1 == ~0) ? (int32_t)x : (x > INT32_MAX ? (-(int32_t)(UINT32_MAX - x) - 1) : (int32_t)x); +} + +constexpr int64_t unsigned64ToSigned2sCompl(uint64_t x) { + return (-1 == ~0) ? (int64_t)x : (x > INT64_MAX ? (-(int64_t)(UINT64_MAX - x) - 1) : (int64_t)x); +} + +constexpr uint64_t signExtend2sCompl(uint32_t x) { + return (-1 == ~0) ? (int64_t)(int32_t)(x) : (x > INT32_MAX ? (x | 0xffffffff00000000ULL) : (uint64_t)x); +} + +constexpr int RoundToNearest = 0; +constexpr int RoundDown = 1; +constexpr int RoundUp = 2; +constexpr int RoundToZero = 3; + +//MSVC doesn't define __SSE2__, so we have to define it manually if SSE2 is available +#if !defined(__SSE2__) && (defined(_M_X64) || (defined(_M_IX86_FP) && _M_IX86_FP == 2)) +#define __SSE2__ 1 +#endif + +//MSVC doesn't define __AES__ +#if defined(_MSC_VER) && defined(__SSE2__) +#define __AES__ +#endif + +//the library "sqrt" function provided by MSVC for x86 targets doesn't give +//the correct results, so we have to use inline assembly to call x87 fsqrt directly +#if !defined(__SSE2__) +#if defined(_MSC_VER) && defined(_M_IX86) +inline double __cdecl rx_sqrt(double x) { + __asm { + fld x + fsqrt + } +} +#define rx_sqrt rx_sqrt + +void rx_set_double_precision(); +#define RANDOMX_USE_X87 + +#elif defined(__i386) + +void rx_set_double_precision(); +#define RANDOMX_USE_X87 + +#endif +#endif //__SSE2__ + +#if !defined(rx_sqrt) +#define rx_sqrt sqrt +#endif + +#if !defined(RANDOMX_USE_X87) +#define rx_set_double_precision(x) +#endif + +#ifdef __SSE2__ +#ifdef __GNUC__ +#include +#else +#include +#endif + +typedef __m128i rx_vec_i128; +typedef __m128d rx_vec_f128; + +#define rx_aligned_alloc(a, b) _mm_malloc(a,b) +#define rx_aligned_free(a) _mm_free(a) +#define rx_prefetch_nta(x) _mm_prefetch((const char *)(x), _MM_HINT_NTA) +#define rx_prefetch_t0(x) _mm_prefetch((const char *)(x), _MM_HINT_T0) + +#define rx_load_vec_f128 _mm_load_pd +#define rx_store_vec_f128 _mm_store_pd +#define rx_add_vec_f128 _mm_add_pd +#define rx_sub_vec_f128 _mm_sub_pd +#define rx_mul_vec_f128 _mm_mul_pd +#define rx_div_vec_f128 _mm_div_pd +#define rx_sqrt_vec_f128 _mm_sqrt_pd + +FORCE_INLINE rx_vec_f128 rx_swap_vec_f128(rx_vec_f128 a) { + return _mm_shuffle_pd(a, a, 1); +} + +FORCE_INLINE rx_vec_f128 rx_set_vec_f128(uint64_t x1, uint64_t x0) { + return _mm_castsi128_pd(_mm_set_epi64x(x1, x0)); +} + +FORCE_INLINE rx_vec_f128 rx_set1_vec_f128(uint64_t x) { + return _mm_castsi128_pd(_mm_set1_epi64x(x)); +} + +#define rx_xor_vec_f128 _mm_xor_pd +#define rx_and_vec_f128 _mm_and_pd +#define rx_or_vec_f128 _mm_or_pd + +#ifdef __AES__ + +#define rx_aesenc_vec_i128 _mm_aesenc_si128 +#define rx_aesdec_vec_i128 _mm_aesdec_si128 + +#define HAVE_AES 1 + +#endif //__AES__ + +FORCE_INLINE int rx_vec_i128_x(rx_vec_i128 a) { + return _mm_cvtsi128_si32(a); +} + +FORCE_INLINE int rx_vec_i128_y(rx_vec_i128 a) { + return _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0x55)); +} + +FORCE_INLINE int rx_vec_i128_z(rx_vec_i128 a) { + return _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0xaa)); +} + +FORCE_INLINE int rx_vec_i128_w(rx_vec_i128 a) { + return _mm_cvtsi128_si32(_mm_shuffle_epi32(a, 0xff)); +} + +#define rx_set_int_vec_i128 _mm_set_epi32 +#define rx_xor_vec_i128 _mm_xor_si128 +#define rx_load_vec_i128 _mm_load_si128 +#define rx_store_vec_i128 _mm_store_si128 + +FORCE_INLINE rx_vec_f128 rx_cvt_packed_int_vec_f128(const void* addr) { + __m128i ix = _mm_loadl_epi64((const __m128i*)addr); + return _mm_cvtepi32_pd(ix); +} + +constexpr uint32_t rx_mxcsr_default = 0x9FC0; //Flush to zero, denormals are zero, default rounding mode, all exceptions disabled + +FORCE_INLINE void rx_reset_float_state() { + _mm_setcsr(rx_mxcsr_default); +} + +FORCE_INLINE void rx_set_rounding_mode(uint32_t mode) { + _mm_setcsr(rx_mxcsr_default | (mode << 13)); +} + +FORCE_INLINE uint32_t rx_get_rounding_mode() { + return (_mm_getcsr() >> 13) & 3; +} + +#elif defined(__PPC64__) && defined(__ALTIVEC__) && defined(__VSX__) //sadly only POWER7 and newer will be able to use SIMD acceleration. Earlier processors cant use doubles or 64 bit integers with SIMD +#include +#include +#include +#include +#undef vector +#undef pixel +#undef bool + +typedef __vector uint8_t __m128i; +typedef __vector uint32_t __m128l; +typedef __vector int __m128li; +typedef __vector uint64_t __m128ll; +typedef __vector double __m128d; + +typedef __m128i rx_vec_i128; +typedef __m128d rx_vec_f128; +typedef union{ + rx_vec_i128 i; + rx_vec_f128 d; + uint64_t u64[2]; + double d64[2]; + uint32_t u32[4]; + int i32[4]; +} vec_u; + +#define rx_aligned_alloc(a, b) malloc(a) +#define rx_aligned_free(a) free(a) +#define rx_prefetch_nta(x) +#define rx_prefetch_t0(x) + +/* Splat 64-bit long long to 2 64-bit long longs */ +FORCE_INLINE __m128i vec_splat2sd (int64_t scalar) +{ return (__m128i) vec_splats (scalar); } + +FORCE_INLINE rx_vec_f128 rx_load_vec_f128(const double* pd) { +#if defined(NATIVE_LITTLE_ENDIAN) + return (rx_vec_f128)vec_vsx_ld(0,pd); +#else + vec_u t; + t.u64[0] = load64(pd + 0); + t.u64[1] = load64(pd + 1); + return (rx_vec_f128)t.d; +#endif +} + +FORCE_INLINE void rx_store_vec_f128(double* mem_addr, rx_vec_f128 a) { +#if defined(NATIVE_LITTLE_ENDIAN) + vec_vsx_st(a,0,(rx_vec_f128*)mem_addr); +#else + vec_u _a; + _a.d = a; + store64(mem_addr + 0, _a.u64[0]); + store64(mem_addr + 1, _a.u64[1]); +#endif +} + +FORCE_INLINE rx_vec_f128 rx_swap_vec_f128(rx_vec_f128 a) { + return (rx_vec_f128)vec_perm((__m128i)a,(__m128i)a,(__m128i){8,9,10,11,12,13,14,15,0,1,2,3,4,5,6,7}); +} + +FORCE_INLINE rx_vec_f128 rx_add_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + return (rx_vec_f128)vec_add(a,b); +} + +FORCE_INLINE rx_vec_f128 rx_sub_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + return (rx_vec_f128)vec_sub(a,b); +} + +FORCE_INLINE rx_vec_f128 rx_mul_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + return (rx_vec_f128)vec_mul(a,b); +} + +FORCE_INLINE rx_vec_f128 rx_div_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + return (rx_vec_f128)vec_div(a,b); +} + +FORCE_INLINE rx_vec_f128 rx_sqrt_vec_f128(rx_vec_f128 a) { + return (rx_vec_f128)vec_sqrt(a); +} + +FORCE_INLINE rx_vec_i128 rx_set1_long_vec_i128(uint64_t a) { + return (rx_vec_i128)vec_splat2sd(a); +} + +FORCE_INLINE rx_vec_f128 rx_vec_i128_vec_f128(rx_vec_i128 a) { + return (rx_vec_f128)a; +} + +FORCE_INLINE rx_vec_f128 rx_set_vec_f128(uint64_t x1, uint64_t x0) { + return (rx_vec_f128)(__m128ll){x0,x1}; +} + +FORCE_INLINE rx_vec_f128 rx_set1_vec_f128(uint64_t x) { + return (rx_vec_f128)vec_splat2sd(x); +} + +FORCE_INLINE rx_vec_f128 rx_xor_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + return (rx_vec_f128)vec_xor(a,b); +} + +FORCE_INLINE rx_vec_f128 rx_and_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + return (rx_vec_f128)vec_and(a,b); +} + +FORCE_INLINE rx_vec_f128 rx_or_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + return (rx_vec_f128)vec_or(a,b); +} + +#if defined(__CRYPTO__) + +FORCE_INLINE __m128ll vrev(__m128i v){ +#if defined(NATIVE_LITTLE_ENDIAN) + return (__m128ll)vec_perm((__m128i)v,(__m128i){0},(__m128i){15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0}); +#else + return (__m128ll)vec_perm((__m128i)v,(__m128i){0},(__m128i){3,2,1,0, 7,6,5,4, 11,10,9,8, 15,14,13,12}); +#endif +} + +FORCE_INLINE rx_vec_i128 rx_aesenc_vec_i128(rx_vec_i128 v, rx_vec_i128 rkey) { + __m128ll _v = vrev(v); + __m128ll _rkey = vrev(rkey); + __m128ll result = vrev((__m128i)__builtin_crypto_vcipher(_v,_rkey)); + return (rx_vec_i128)result; +} + +FORCE_INLINE rx_vec_i128 rx_aesdec_vec_i128(rx_vec_i128 v, rx_vec_i128 rkey) { + __m128ll _v = vrev(v); + __m128ll zero = (__m128ll){0}; + __m128ll out = vrev((__m128i)__builtin_crypto_vncipher(_v,zero)); + return (rx_vec_i128)vec_xor((__m128i)out,rkey); +} +#define HAVE_AES 1 + +#endif //__CRYPTO__ + +FORCE_INLINE int rx_vec_i128_x(rx_vec_i128 a) { + vec_u _a; + _a.i = a; + return _a.i32[0]; +} + +FORCE_INLINE int rx_vec_i128_y(rx_vec_i128 a) { + vec_u _a; + _a.i = a; + return _a.i32[1]; +} + +FORCE_INLINE int rx_vec_i128_z(rx_vec_i128 a) { + vec_u _a; + _a.i = a; + return _a.i32[2]; +} + +FORCE_INLINE int rx_vec_i128_w(rx_vec_i128 a) { + vec_u _a; + _a.i = a; + return _a.i32[3]; +} + +FORCE_INLINE rx_vec_i128 rx_set_int_vec_i128(int _I3, int _I2, int _I1, int _I0) { + return (rx_vec_i128)((__m128li){_I0,_I1,_I2,_I3}); +}; + +FORCE_INLINE rx_vec_i128 rx_xor_vec_i128(rx_vec_i128 _A, rx_vec_i128 _B) { + return (rx_vec_i128)vec_xor(_A,_B); +} + +FORCE_INLINE rx_vec_i128 rx_load_vec_i128(rx_vec_i128 const *_P) { +#if defined(NATIVE_LITTLE_ENDIAN) + return *_P; +#else + uint32_t* ptr = (uint32_t*)_P; + vec_u c; + c.u32[0] = load32(ptr + 0); + c.u32[1] = load32(ptr + 1); + c.u32[2] = load32(ptr + 2); + c.u32[3] = load32(ptr + 3); + return (rx_vec_i128)c.i; +#endif +} + +FORCE_INLINE void rx_store_vec_i128(rx_vec_i128 *_P, rx_vec_i128 _B) { +#if defined(NATIVE_LITTLE_ENDIAN) + *_P = _B; +#else + uint32_t* ptr = (uint32_t*)_P; + vec_u B; + B.i = _B; + store32(ptr + 0, B.u32[0]); + store32(ptr + 1, B.u32[1]); + store32(ptr + 2, B.u32[2]); + store32(ptr + 3, B.u32[3]); +#endif +} + +FORCE_INLINE rx_vec_f128 rx_cvt_packed_int_vec_f128(const void* addr) { + vec_u x; + x.d64[0] = (double)unsigned32ToSigned2sCompl(load32((uint8_t*)addr + 0)); + x.d64[1] = (double)unsigned32ToSigned2sCompl(load32((uint8_t*)addr + 4)); + return (rx_vec_f128)x.d; +} + +#define RANDOMX_DEFAULT_FENV + +#elif defined(__aarch64__) + +#include +#include +#include + +typedef uint8x16_t rx_vec_i128; +typedef float64x2_t rx_vec_f128; + +inline void* rx_aligned_alloc(size_t size, size_t align) { + void* p; + if (posix_memalign(&p, align, size) == 0) + return p; + + return 0; +}; + +#define rx_aligned_free(a) free(a) + +inline void rx_prefetch_nta(void* ptr) { + asm volatile ("prfm pldl1strm, [%0]\n" : : "r" (ptr)); +} + +inline void rx_prefetch_t0(const void* ptr) { + asm volatile ("prfm pldl1strm, [%0]\n" : : "r" (ptr)); +} + +FORCE_INLINE rx_vec_f128 rx_load_vec_f128(const double* pd) { + return vld1q_f64((const float64_t*)pd); +} + +FORCE_INLINE void rx_store_vec_f128(double* mem_addr, rx_vec_f128 val) { + vst1q_f64((float64_t*)mem_addr, val); +} + +FORCE_INLINE rx_vec_f128 rx_swap_vec_f128(rx_vec_f128 a) { + float64x2_t temp; + temp = vcopyq_laneq_f64(temp, 1, a, 1); + a = vcopyq_laneq_f64(a, 1, a, 0); + return vcopyq_laneq_f64(a, 0, temp, 1); +} + +FORCE_INLINE rx_vec_f128 rx_set_vec_f128(uint64_t x1, uint64_t x0) { + uint64x2_t temp0 = vdupq_n_u64(x0); + uint64x2_t temp1 = vdupq_n_u64(x1); + return vreinterpretq_f64_u64(vcopyq_laneq_u64(temp0, 1, temp1, 0)); +} + +FORCE_INLINE rx_vec_f128 rx_set1_vec_f128(uint64_t x) { + return vreinterpretq_f64_u64(vdupq_n_u64(x)); +} + +#define rx_add_vec_f128 vaddq_f64 +#define rx_sub_vec_f128 vsubq_f64 +#define rx_mul_vec_f128 vmulq_f64 +#define rx_div_vec_f128 vdivq_f64 +#define rx_sqrt_vec_f128 vsqrtq_f64 + +FORCE_INLINE rx_vec_f128 rx_xor_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + return vreinterpretq_f64_u8(veorq_u8(vreinterpretq_u8_f64(a), vreinterpretq_u8_f64(b))); +} + +FORCE_INLINE rx_vec_f128 rx_and_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + return vreinterpretq_f64_u8(vandq_u8(vreinterpretq_u8_f64(a), vreinterpretq_u8_f64(b))); +} + +FORCE_INLINE rx_vec_f128 rx_or_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + return vreinterpretq_f64_u8(vorrq_u8(vreinterpretq_u8_f64(a), vreinterpretq_u8_f64(b))); +} + +#ifdef __ARM_FEATURE_CRYPTO + + +FORCE_INLINE rx_vec_i128 rx_aesenc_vec_i128(rx_vec_i128 a, rx_vec_i128 key) { + const uint8x16_t zero = { 0 }; + return vaesmcq_u8(vaeseq_u8(a, zero)) ^ key; +} + +FORCE_INLINE rx_vec_i128 rx_aesdec_vec_i128(rx_vec_i128 a, rx_vec_i128 key) { + const uint8x16_t zero = { 0 }; + return vaesimcq_u8(vaesdq_u8(a, zero)) ^ key; +} + +#define HAVE_AES 1 + +#endif + +#define rx_xor_vec_i128 veorq_u8 + +FORCE_INLINE int rx_vec_i128_x(rx_vec_i128 a) { + return vgetq_lane_s32(vreinterpretq_s32_u8(a), 0); +} + +FORCE_INLINE int rx_vec_i128_y(rx_vec_i128 a) { + return vgetq_lane_s32(vreinterpretq_s32_u8(a), 1); +} + +FORCE_INLINE int rx_vec_i128_z(rx_vec_i128 a) { + return vgetq_lane_s32(vreinterpretq_s32_u8(a), 2); +} + +FORCE_INLINE int rx_vec_i128_w(rx_vec_i128 a) { + return vgetq_lane_s32(vreinterpretq_s32_u8(a), 3); +} + +FORCE_INLINE rx_vec_i128 rx_set_int_vec_i128(int _I3, int _I2, int _I1, int _I0) { + int32_t data[4]; + data[0] = _I0; + data[1] = _I1; + data[2] = _I2; + data[3] = _I3; + return vreinterpretq_u8_s32(vld1q_s32(data)); +}; + +#define rx_xor_vec_i128 veorq_u8 + +FORCE_INLINE rx_vec_i128 rx_load_vec_i128(const rx_vec_i128* mem_addr) { + return vld1q_u8((const uint8_t*)mem_addr); +} + +FORCE_INLINE void rx_store_vec_i128(rx_vec_i128* mem_addr, rx_vec_i128 val) { + vst1q_u8((uint8_t*)mem_addr, val); +} + +FORCE_INLINE rx_vec_f128 rx_cvt_packed_int_vec_f128(const void* addr) { + double lo = unsigned32ToSigned2sCompl(load32((uint8_t*)addr + 0)); + double hi = unsigned32ToSigned2sCompl(load32((uint8_t*)addr + 4)); + rx_vec_f128 x; + x = vsetq_lane_f64(lo, x, 0); + x = vsetq_lane_f64(hi, x, 1); + return x; +} + +#define RANDOMX_DEFAULT_FENV + +#else //portable fallback + +#include +#include +#include +#include + +typedef union { + uint64_t u64[2]; + uint32_t u32[4]; + uint16_t u16[8]; + uint8_t u8[16]; +} rx_vec_i128; + +typedef union { + struct { + double lo; + double hi; + }; + rx_vec_i128 i; +} rx_vec_f128; + +#define rx_aligned_alloc(a, b) malloc(a) +#define rx_aligned_free(a) free(a) +#define rx_prefetch_nta(x) +#define rx_prefetch_t0(x) + +FORCE_INLINE rx_vec_f128 rx_load_vec_f128(const double* pd) { + rx_vec_f128 x; + x.i.u64[0] = load64(pd + 0); + x.i.u64[1] = load64(pd + 1); + return x; +} + +FORCE_INLINE void rx_store_vec_f128(double* mem_addr, rx_vec_f128 a) { + store64(mem_addr + 0, a.i.u64[0]); + store64(mem_addr + 1, a.i.u64[1]); +} + +FORCE_INLINE rx_vec_f128 rx_swap_vec_f128(rx_vec_f128 a) { + double temp = a.hi; + a.hi = a.lo; + a.lo = temp; + return a; +} + +FORCE_INLINE rx_vec_f128 rx_add_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + rx_vec_f128 x; + x.lo = a.lo + b.lo; + x.hi = a.hi + b.hi; + return x; +} + +FORCE_INLINE rx_vec_f128 rx_sub_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + rx_vec_f128 x; + x.lo = a.lo - b.lo; + x.hi = a.hi - b.hi; + return x; +} + +FORCE_INLINE rx_vec_f128 rx_mul_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + rx_vec_f128 x; + x.lo = a.lo * b.lo; + x.hi = a.hi * b.hi; + return x; +} + +FORCE_INLINE rx_vec_f128 rx_div_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + rx_vec_f128 x; + x.lo = a.lo / b.lo; + x.hi = a.hi / b.hi; + return x; +} + +FORCE_INLINE rx_vec_f128 rx_sqrt_vec_f128(rx_vec_f128 a) { + rx_vec_f128 x; + x.lo = rx_sqrt(a.lo); + x.hi = rx_sqrt(a.hi); + return x; +} + +FORCE_INLINE rx_vec_i128 rx_set1_long_vec_i128(uint64_t a) { + rx_vec_i128 x; + x.u64[0] = a; + x.u64[1] = a; + return x; +} + +FORCE_INLINE rx_vec_f128 rx_vec_i128_vec_f128(rx_vec_i128 a) { + rx_vec_f128 x; + x.i = a; + return x; +} + +FORCE_INLINE rx_vec_f128 rx_set_vec_f128(uint64_t x1, uint64_t x0) { + rx_vec_f128 v; + v.i.u64[0] = x0; + v.i.u64[1] = x1; + return v; +} + +FORCE_INLINE rx_vec_f128 rx_set1_vec_f128(uint64_t x) { + rx_vec_f128 v; + v.i.u64[0] = x; + v.i.u64[1] = x; + return v; +} + +FORCE_INLINE rx_vec_f128 rx_xor_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + rx_vec_f128 x; + x.i.u64[0] = a.i.u64[0] ^ b.i.u64[0]; + x.i.u64[1] = a.i.u64[1] ^ b.i.u64[1]; + return x; +} + +FORCE_INLINE rx_vec_f128 rx_and_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + rx_vec_f128 x; + x.i.u64[0] = a.i.u64[0] & b.i.u64[0]; + x.i.u64[1] = a.i.u64[1] & b.i.u64[1]; + return x; +} + +FORCE_INLINE rx_vec_f128 rx_or_vec_f128(rx_vec_f128 a, rx_vec_f128 b) { + rx_vec_f128 x; + x.i.u64[0] = a.i.u64[0] | b.i.u64[0]; + x.i.u64[1] = a.i.u64[1] | b.i.u64[1]; + return x; +} + +FORCE_INLINE int rx_vec_i128_x(rx_vec_i128 a) { + return a.u32[0]; +} + +FORCE_INLINE int rx_vec_i128_y(rx_vec_i128 a) { + return a.u32[1]; +} + +FORCE_INLINE int rx_vec_i128_z(rx_vec_i128 a) { + return a.u32[2]; +} + +FORCE_INLINE int rx_vec_i128_w(rx_vec_i128 a) { + return a.u32[3]; +} + +FORCE_INLINE rx_vec_i128 rx_set_int_vec_i128(int _I3, int _I2, int _I1, int _I0) { + rx_vec_i128 v; + v.u32[0] = _I0; + v.u32[1] = _I1; + v.u32[2] = _I2; + v.u32[3] = _I3; + return v; +}; + +FORCE_INLINE rx_vec_i128 rx_xor_vec_i128(rx_vec_i128 _A, rx_vec_i128 _B) { + rx_vec_i128 c; + c.u32[0] = _A.u32[0] ^ _B.u32[0]; + c.u32[1] = _A.u32[1] ^ _B.u32[1]; + c.u32[2] = _A.u32[2] ^ _B.u32[2]; + c.u32[3] = _A.u32[3] ^ _B.u32[3]; + return c; +} + +FORCE_INLINE rx_vec_i128 rx_load_vec_i128(rx_vec_i128 const*_P) { +#if defined(NATIVE_LITTLE_ENDIAN) + return *_P; +#else + uint32_t* ptr = (uint32_t*)_P; + rx_vec_i128 c; + c.u32[0] = load32(ptr + 0); + c.u32[1] = load32(ptr + 1); + c.u32[2] = load32(ptr + 2); + c.u32[3] = load32(ptr + 3); + return c; +#endif +} + +FORCE_INLINE void rx_store_vec_i128(rx_vec_i128 *_P, rx_vec_i128 _B) { +#if defined(NATIVE_LITTLE_ENDIAN) + *_P = _B; +#else + uint32_t* ptr = (uint32_t*)_P; + store32(ptr + 0, _B.u32[0]); + store32(ptr + 1, _B.u32[1]); + store32(ptr + 2, _B.u32[2]); + store32(ptr + 3, _B.u32[3]); +#endif +} + +FORCE_INLINE rx_vec_f128 rx_cvt_packed_int_vec_f128(const void* addr) { + rx_vec_f128 x; + x.lo = (double)unsigned32ToSigned2sCompl(load32((uint8_t*)addr + 0)); + x.hi = (double)unsigned32ToSigned2sCompl(load32((uint8_t*)addr + 4)); + return x; +} + +#define RANDOMX_DEFAULT_FENV + +#endif + +#ifndef HAVE_AES +static const char* platformError = "Platform doesn't support hardware AES"; + +#include + +FORCE_INLINE rx_vec_i128 rx_aesenc_vec_i128(rx_vec_i128 v, rx_vec_i128 rkey) { + throw std::runtime_error(platformError); +} + +FORCE_INLINE rx_vec_i128 rx_aesdec_vec_i128(rx_vec_i128 v, rx_vec_i128 rkey) { + throw std::runtime_error(platformError); +} + +#define HAVE_AES 0 + +#endif + +#ifdef RANDOMX_DEFAULT_FENV + +void rx_reset_float_state(); + +void rx_set_rounding_mode(uint32_t mode); + +uint32_t rx_get_rounding_mode(); + +#endif + +double loadDoublePortable(const void* addr); +uint64_t mulh(uint64_t, uint64_t); +int64_t smulh(int64_t, int64_t); +uint64_t rotl(uint64_t, unsigned int); +uint64_t rotr(uint64_t, unsigned int); diff --git a/src/RandomX/src/jit_compiler.hpp b/src/RandomX/src/jit_compiler.hpp new file mode 100644 index 000000000..17fdad4e3 --- /dev/null +++ b/src/RandomX/src/jit_compiler.hpp @@ -0,0 +1,41 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#if defined(_M_X64) || defined(__x86_64__) +#include "jit_compiler_x86.hpp" +#elif defined(__aarch64__) +#include "jit_compiler_a64.hpp" +#else +#include "jit_compiler_fallback.hpp" +#endif + +#if defined(__OpenBSD__) || defined(__NetBSD__) || (defined(__APPLE__) && defined(__aarch64__)) +#define RANDOMX_FORCE_SECURE +#endif diff --git a/src/RandomX/src/jit_compiler_a64.cpp b/src/RandomX/src/jit_compiler_a64.cpp new file mode 100644 index 000000000..e45774e93 --- /dev/null +++ b/src/RandomX/src/jit_compiler_a64.cpp @@ -0,0 +1,1072 @@ +/* +Copyright (c) 2018-2019, tevador +Copyright (c) 2019, SChernykh + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "jit_compiler_a64.hpp" +#include "superscalar.hpp" +#include "program.hpp" +#include "reciprocal.h" +#include "virtual_memory.hpp" + +namespace ARMV8A { + +constexpr uint32_t B = 0x14000000; +constexpr uint32_t EOR = 0xCA000000; +constexpr uint32_t EOR32 = 0x4A000000; +constexpr uint32_t ADD = 0x8B000000; +constexpr uint32_t SUB = 0xCB000000; +constexpr uint32_t MUL = 0x9B007C00; +constexpr uint32_t UMULH = 0x9BC07C00; +constexpr uint32_t SMULH = 0x9B407C00; +constexpr uint32_t MOVZ = 0xD2800000; +constexpr uint32_t MOVN = 0x92800000; +constexpr uint32_t MOVK = 0xF2800000; +constexpr uint32_t ADD_IMM_LO = 0x91000000; +constexpr uint32_t ADD_IMM_HI = 0x91400000; +constexpr uint32_t LDR_LITERAL = 0x58000000; +constexpr uint32_t ROR = 0x9AC02C00; +constexpr uint32_t ROR_IMM = 0x93C00000; +constexpr uint32_t MOV_REG = 0xAA0003E0; +constexpr uint32_t MOV_VREG_EL = 0x6E080400; +constexpr uint32_t FADD = 0x4E60D400; +constexpr uint32_t FSUB = 0x4EE0D400; +constexpr uint32_t FEOR = 0x6E201C00; +constexpr uint32_t FMUL = 0x6E60DC00; +constexpr uint32_t FDIV = 0x6E60FC00; +constexpr uint32_t FSQRT = 0x6EE1F800; + +} + +namespace randomx { + +static const size_t CodeSize = ((uint8_t*)randomx_init_dataset_aarch64_end) - ((uint8_t*)randomx_program_aarch64); +static const size_t MainLoopBegin = ((uint8_t*)randomx_program_aarch64_main_loop) - ((uint8_t*)randomx_program_aarch64); +static const size_t PrologueSize = ((uint8_t*)randomx_program_aarch64_vm_instructions) - ((uint8_t*)randomx_program_aarch64); +static const size_t ImulRcpLiteralsEnd = ((uint8_t*)randomx_program_aarch64_imul_rcp_literals_end) - ((uint8_t*)randomx_program_aarch64); + +static const size_t CalcDatasetItemSize = + // Prologue + ((uint8_t*)randomx_calc_dataset_item_aarch64_prefetch - (uint8_t*)randomx_calc_dataset_item_aarch64) + + // Main loop + RANDOMX_CACHE_ACCESSES * ( + // Main loop prologue + ((uint8_t*)randomx_calc_dataset_item_aarch64_mix - ((uint8_t*)randomx_calc_dataset_item_aarch64_prefetch)) + 4 + + // Inner main loop (instructions) + ((RANDOMX_SUPERSCALAR_LATENCY * 3) + 2) * 16 + + // Main loop epilogue + ((uint8_t*)randomx_calc_dataset_item_aarch64_store_result - (uint8_t*)randomx_calc_dataset_item_aarch64_mix) + 4 + ) + + // Epilogue + ((uint8_t*)randomx_calc_dataset_item_aarch64_end - (uint8_t*)randomx_calc_dataset_item_aarch64_store_result); + +constexpr uint32_t IntRegMap[8] = { 4, 5, 6, 7, 12, 13, 14, 15 }; + +template static constexpr size_t Log2(T value) { return (value > 1) ? (Log2(value / 2) + 1) : 0; } + +JitCompilerA64::JitCompilerA64() + : code((uint8_t*) allocMemoryPages(CodeSize + CalcDatasetItemSize)) + , literalPos(ImulRcpLiteralsEnd) + , num32bitLiterals(0) +{ + memset(reg_changed_offset, 0, sizeof(reg_changed_offset)); + memcpy(code, (void*) randomx_program_aarch64, CodeSize); + +#ifdef __GNUC__ + __builtin___clear_cache(reinterpret_cast(code), reinterpret_cast(code + CodeSize)); +#endif +} + +JitCompilerA64::~JitCompilerA64() +{ + freePagedMemory(code, CodeSize + CalcDatasetItemSize); +} + +void JitCompilerA64::enableWriting() +{ + setPagesRW(code, CodeSize + CalcDatasetItemSize); +} + +void JitCompilerA64::enableExecution() +{ + setPagesRX(code, CodeSize + CalcDatasetItemSize); +} + +void JitCompilerA64::enableAll() +{ + setPagesRWX(code, CodeSize + CalcDatasetItemSize); +} + +void JitCompilerA64::generateProgram(Program& program, ProgramConfiguration& config) +{ + uint32_t codePos = MainLoopBegin + 4; + + // and w16, w10, ScratchpadL3Mask64 + emit32(0x121A0000 | 16 | (10 << 5) | ((Log2(RANDOMX_SCRATCHPAD_L3) - 7) << 10), code, codePos); + + // and w17, w18, ScratchpadL3Mask64 + emit32(0x121A0000 | 17 | (18 << 5) | ((Log2(RANDOMX_SCRATCHPAD_L3) - 7) << 10), code, codePos); + + codePos = PrologueSize; + literalPos = ImulRcpLiteralsEnd; + num32bitLiterals = 0; + + for (uint32_t i = 0; i < RegistersCount; ++i) + reg_changed_offset[i] = codePos; + + for (uint32_t i = 0; i < program.getSize(); ++i) + { + Instruction& instr = program(i); + instr.src %= RegistersCount; + instr.dst %= RegistersCount; + (this->*engine[instr.opcode])(instr, codePos); + } + + // Update spMix2 + // eor w18, config.readReg2, config.readReg3 + emit32(ARMV8A::EOR32 | 18 | (IntRegMap[config.readReg2] << 5) | (IntRegMap[config.readReg3] << 16), code, codePos); + + // Jump back to the main loop + const uint32_t offset = (((uint8_t*)randomx_program_aarch64_vm_instructions_end) - ((uint8_t*)randomx_program_aarch64)) - codePos; + emit32(ARMV8A::B | (offset / 4), code, codePos); + + // and w18, w18, CacheLineAlignMask + codePos = (((uint8_t*)randomx_program_aarch64_cacheline_align_mask1) - ((uint8_t*)randomx_program_aarch64)); + emit32(0x121A0000 | 18 | (18 << 5) | ((Log2(RANDOMX_DATASET_BASE_SIZE) - 7) << 10), code, codePos); + + // and w10, w10, CacheLineAlignMask + codePos = (((uint8_t*)randomx_program_aarch64_cacheline_align_mask2) - ((uint8_t*)randomx_program_aarch64)); + emit32(0x121A0000 | 10 | (10 << 5) | ((Log2(RANDOMX_DATASET_BASE_SIZE) - 7) << 10), code, codePos); + + // Update spMix1 + // eor x10, config.readReg0, config.readReg1 + codePos = ((uint8_t*)randomx_program_aarch64_update_spMix1) - ((uint8_t*)randomx_program_aarch64); + emit32(ARMV8A::EOR | 10 | (IntRegMap[config.readReg0] << 5) | (IntRegMap[config.readReg1] << 16), code, codePos); + +#ifdef __GNUC__ + __builtin___clear_cache(reinterpret_cast(code + MainLoopBegin), reinterpret_cast(code + codePos)); +#endif +} + +void JitCompilerA64::generateProgramLight(Program& program, ProgramConfiguration& config, uint32_t datasetOffset) +{ + uint32_t codePos = MainLoopBegin + 4; + + // and w16, w10, ScratchpadL3Mask64 + emit32(0x121A0000 | 16 | (10 << 5) | ((Log2(RANDOMX_SCRATCHPAD_L3) - 7) << 10), code, codePos); + + // and w17, w18, ScratchpadL3Mask64 + emit32(0x121A0000 | 17 | (18 << 5) | ((Log2(RANDOMX_SCRATCHPAD_L3) - 7) << 10), code, codePos); + + codePos = PrologueSize; + literalPos = ImulRcpLiteralsEnd; + num32bitLiterals = 0; + + for (uint32_t i = 0; i < RegistersCount; ++i) + reg_changed_offset[i] = codePos; + + for (uint32_t i = 0; i < program.getSize(); ++i) + { + Instruction& instr = program(i); + instr.src %= RegistersCount; + instr.dst %= RegistersCount; + (this->*engine[instr.opcode])(instr, codePos); + } + + // Update spMix2 + // eor w18, config.readReg2, config.readReg3 + emit32(ARMV8A::EOR32 | 18 | (IntRegMap[config.readReg2] << 5) | (IntRegMap[config.readReg3] << 16), code, codePos); + + // Jump back to the main loop + const uint32_t offset = (((uint8_t*)randomx_program_aarch64_vm_instructions_end_light) - ((uint8_t*)randomx_program_aarch64)) - codePos; + emit32(ARMV8A::B | (offset / 4), code, codePos); + + // and w2, w9, CacheLineAlignMask + codePos = (((uint8_t*)randomx_program_aarch64_light_cacheline_align_mask) - ((uint8_t*)randomx_program_aarch64)); + emit32(0x121A0000 | 2 | (9 << 5) | ((Log2(RANDOMX_DATASET_BASE_SIZE) - 7) << 10), code, codePos); + + // Update spMix1 + // eor x10, config.readReg0, config.readReg1 + codePos = ((uint8_t*)randomx_program_aarch64_update_spMix1) - ((uint8_t*)randomx_program_aarch64); + emit32(ARMV8A::EOR | 10 | (IntRegMap[config.readReg0] << 5) | (IntRegMap[config.readReg1] << 16), code, codePos); + + // Apply dataset offset + codePos = ((uint8_t*)randomx_program_aarch64_light_dataset_offset) - ((uint8_t*)randomx_program_aarch64); + + datasetOffset /= CacheLineSize; + const uint32_t imm_lo = datasetOffset & ((1 << 12) - 1); + const uint32_t imm_hi = datasetOffset >> 12; + + emit32(ARMV8A::ADD_IMM_LO | 2 | (2 << 5) | (imm_lo << 10), code, codePos); + emit32(ARMV8A::ADD_IMM_HI | 2 | (2 << 5) | (imm_hi << 10), code, codePos); + +#ifdef __GNUC__ + __builtin___clear_cache(reinterpret_cast(code + MainLoopBegin), reinterpret_cast(code + codePos)); +#endif +} + +template +void JitCompilerA64::generateSuperscalarHash(SuperscalarProgram(&programs)[N], std::vector &reciprocalCache) +{ + uint32_t codePos = CodeSize; + + uint8_t* p1 = (uint8_t*)randomx_calc_dataset_item_aarch64; + uint8_t* p2 = (uint8_t*)randomx_calc_dataset_item_aarch64_prefetch; + memcpy(code + codePos, p1, p2 - p1); + codePos += p2 - p1; + + num32bitLiterals = 64; + constexpr uint32_t tmp_reg = 12; + + for (size_t i = 0; i < N; ++i) + { + // and x11, x10, CacheSize / CacheLineSize - 1 + emit32(0x92400000 | 11 | (10 << 5) | ((Log2(CacheSize / CacheLineSize) - 1) << 10), code, codePos); + + p1 = ((uint8_t*)randomx_calc_dataset_item_aarch64_prefetch) + 4; + p2 = (uint8_t*)randomx_calc_dataset_item_aarch64_mix; + memcpy(code + codePos, p1, p2 - p1); + codePos += p2 - p1; + + SuperscalarProgram& prog = programs[i]; + const size_t progSize = prog.getSize(); + + uint32_t jmp_pos = codePos; + codePos += 4; + + // Fill in literal pool + for (size_t j = 0; j < progSize; ++j) + { + const Instruction& instr = prog(j); + if (static_cast(instr.opcode) == randomx::SuperscalarInstructionType::IMUL_RCP) + emit64(reciprocalCache[instr.getImm32()], code, codePos); + } + + // Jump over literal pool + uint32_t literal_pos = jmp_pos; + emit32(ARMV8A::B | ((codePos - jmp_pos) / 4), code, literal_pos); + + for (size_t j = 0; j < progSize; ++j) + { + const Instruction& instr = prog(j); + const uint32_t src = instr.src; + const uint32_t dst = instr.dst; + + switch (static_cast(instr.opcode)) + { + case randomx::SuperscalarInstructionType::ISUB_R: + emit32(ARMV8A::SUB | dst | (dst << 5) | (src << 16), code, codePos); + break; + case randomx::SuperscalarInstructionType::IXOR_R: + emit32(ARMV8A::EOR | dst | (dst << 5) | (src << 16), code, codePos); + break; + case randomx::SuperscalarInstructionType::IADD_RS: + emit32(ARMV8A::ADD | dst | (dst << 5) | (instr.getModShift() << 10) | (src << 16), code, codePos); + break; + case randomx::SuperscalarInstructionType::IMUL_R: + emit32(ARMV8A::MUL | dst | (dst << 5) | (src << 16), code, codePos); + break; + case randomx::SuperscalarInstructionType::IROR_C: + emit32(ARMV8A::ROR_IMM | dst | (dst << 5) | ((instr.getImm32() & 63) << 10) | (dst << 16), code, codePos); + break; + case randomx::SuperscalarInstructionType::IADD_C7: + case randomx::SuperscalarInstructionType::IADD_C8: + case randomx::SuperscalarInstructionType::IADD_C9: + emitAddImmediate(dst, dst, instr.getImm32(), code, codePos); + break; + case randomx::SuperscalarInstructionType::IXOR_C7: + case randomx::SuperscalarInstructionType::IXOR_C8: + case randomx::SuperscalarInstructionType::IXOR_C9: + emitMovImmediate(tmp_reg, instr.getImm32(), code, codePos); + emit32(ARMV8A::EOR | dst | (dst << 5) | (tmp_reg << 16), code, codePos); + break; + case randomx::SuperscalarInstructionType::IMULH_R: + emit32(ARMV8A::UMULH | dst | (dst << 5) | (src << 16), code, codePos); + break; + case randomx::SuperscalarInstructionType::ISMULH_R: + emit32(ARMV8A::SMULH | dst | (dst << 5) | (src << 16), code, codePos); + break; + case randomx::SuperscalarInstructionType::IMUL_RCP: + { + int32_t offset = (literal_pos - codePos) / 4; + offset &= (1 << 19) - 1; + literal_pos += 8; + + // ldr tmp_reg, reciprocal + emit32(ARMV8A::LDR_LITERAL | tmp_reg | (offset << 5), code, codePos); + + // mul dst, dst, tmp_reg + emit32(ARMV8A::MUL | dst | (dst << 5) | (tmp_reg << 16), code, codePos); + } + break; + default: + break; + } + } + + p1 = (uint8_t*)randomx_calc_dataset_item_aarch64_mix; + p2 = (uint8_t*)randomx_calc_dataset_item_aarch64_store_result; + memcpy(code + codePos, p1, p2 - p1); + codePos += p2 - p1; + + // Update registerValue + emit32(ARMV8A::MOV_REG | 10 | (prog.getAddressRegister() << 16), code, codePos); + } + + p1 = (uint8_t*)randomx_calc_dataset_item_aarch64_store_result; + p2 = (uint8_t*)randomx_calc_dataset_item_aarch64_end; + memcpy(code + codePos, p1, p2 - p1); + codePos += p2 - p1; + +#ifdef __GNUC__ + __builtin___clear_cache(reinterpret_cast(code + CodeSize), reinterpret_cast(code + codePos)); +#endif +} + +template void JitCompilerA64::generateSuperscalarHash(SuperscalarProgram(&programs)[RANDOMX_CACHE_ACCESSES], std::vector &reciprocalCache); + +DatasetInitFunc* JitCompilerA64::getDatasetInitFunc() +{ + return (DatasetInitFunc*)(code + (((uint8_t*)randomx_init_dataset_aarch64) - ((uint8_t*)randomx_program_aarch64))); +} + +size_t JitCompilerA64::getCodeSize() +{ + return CodeSize; +} + +void JitCompilerA64::emitMovImmediate(uint32_t dst, uint32_t imm, uint8_t* code, uint32_t& codePos) +{ + uint32_t k = codePos; + + if (imm < (1 << 16)) + { + // movz tmp_reg, imm32 (16 low bits) + emit32(ARMV8A::MOVZ | dst | (imm << 5), code, k); + } + else + { + if (num32bitLiterals < 64) + { + if (static_cast(imm) < 0) + { + // smov dst, vN.s[M] + emit32(0x4E042C00 | dst | ((num32bitLiterals / 4) << 5) | ((num32bitLiterals % 4) << 19), code, k); + } + else + { + // umov dst, vN.s[M] + emit32(0x0E043C00 | dst | ((num32bitLiterals / 4) << 5) | ((num32bitLiterals % 4) << 19), code, k); + } + + ((uint32_t*)(code + ImulRcpLiteralsEnd))[num32bitLiterals] = imm; + ++num32bitLiterals; + } + else + { + if (static_cast(imm) < 0) + { + // movn tmp_reg, ~imm32 (16 high bits) + emit32(ARMV8A::MOVN | dst | (1 << 21) | ((~imm >> 16) << 5), code, k); + } + else + { + // movz tmp_reg, imm32 (16 high bits) + emit32(ARMV8A::MOVZ | dst | (1 << 21) | ((imm >> 16) << 5), code, k); + } + + // movk tmp_reg, imm32 (16 low bits) + emit32(ARMV8A::MOVK | dst | ((imm & 0xFFFF) << 5), code, k); + } + } + + codePos = k; +} + +void JitCompilerA64::emitAddImmediate(uint32_t dst, uint32_t src, uint32_t imm, uint8_t* code, uint32_t& codePos) +{ + uint32_t k = codePos; + + if (imm < (1 << 24)) + { + const uint32_t imm_lo = imm & ((1 << 12) - 1); + const uint32_t imm_hi = imm >> 12; + + if (imm_lo && imm_hi) + { + emit32(ARMV8A::ADD_IMM_LO | dst | (src << 5) | (imm_lo << 10), code, k); + emit32(ARMV8A::ADD_IMM_HI | dst | (dst << 5) | (imm_hi << 10), code, k); + } + else if (imm_lo) + { + emit32(ARMV8A::ADD_IMM_LO | dst | (src << 5) | (imm_lo << 10), code, k); + } + else + { + emit32(ARMV8A::ADD_IMM_HI | dst | (src << 5) | (imm_hi << 10), code, k); + } + } + else + { + constexpr uint32_t tmp_reg = 18; + emitMovImmediate(tmp_reg, imm, code, k); + + // add dst, src, tmp_reg + emit32(ARMV8A::ADD | dst | (src << 5) | (tmp_reg << 16), code, k); + } + + codePos = k; +} + +template +void JitCompilerA64::emitMemLoad(uint32_t dst, uint32_t src, Instruction& instr, uint8_t* code, uint32_t& codePos) +{ + uint32_t k = codePos; + + uint32_t imm = instr.getImm32(); + + if (src != dst) + { + imm &= instr.getModMem() ? (RANDOMX_SCRATCHPAD_L1 - 1) : (RANDOMX_SCRATCHPAD_L2 - 1); + emitAddImmediate(tmp_reg, src, imm, code, k); + + constexpr uint32_t t = 0x927d0000 | tmp_reg | (tmp_reg << 5); + constexpr uint32_t andInstrL1 = t | ((Log2(RANDOMX_SCRATCHPAD_L1) - 4) << 10); + constexpr uint32_t andInstrL2 = t | ((Log2(RANDOMX_SCRATCHPAD_L2) - 4) << 10); + + emit32(instr.getModMem() ? andInstrL1 : andInstrL2, code, k); + + // ldr tmp_reg, [x2, tmp_reg] + emit32(0xf8606840 | tmp_reg | (tmp_reg << 16), code, k); + } + else + { + imm = (imm & ScratchpadL3Mask) >> 3; + emitMovImmediate(tmp_reg, imm, code, k); + + // ldr tmp_reg, [x2, tmp_reg, lsl 3] + emit32(0xf8607840 | tmp_reg | (tmp_reg << 16), code, k); + } + + codePos = k; +} + +template +void JitCompilerA64::emitMemLoadFP(uint32_t src, Instruction& instr, uint8_t* code, uint32_t& codePos) +{ + uint32_t k = codePos; + + uint32_t imm = instr.getImm32(); + constexpr uint32_t tmp_reg = 18; + + imm &= instr.getModMem() ? (RANDOMX_SCRATCHPAD_L1 - 1) : (RANDOMX_SCRATCHPAD_L2 - 1); + emitAddImmediate(tmp_reg, src, imm, code, k); + + constexpr uint32_t t = 0x927d0000 | tmp_reg | (tmp_reg << 5); + constexpr uint32_t andInstrL1 = t | ((Log2(RANDOMX_SCRATCHPAD_L1) - 4) << 10); + constexpr uint32_t andInstrL2 = t | ((Log2(RANDOMX_SCRATCHPAD_L2) - 4) << 10); + + emit32(instr.getModMem() ? andInstrL1 : andInstrL2, code, k); + + // add tmp_reg, x2, tmp_reg + emit32(ARMV8A::ADD | tmp_reg | (2 << 5) | (tmp_reg << 16), code, k); + + // ldpsw tmp_reg, tmp_reg + 1, [tmp_reg] + emit32(0x69400000 | tmp_reg | (tmp_reg << 5) | ((tmp_reg + 1) << 10), code, k); + + // ins tmp_reg_fp.d[0], tmp_reg + emit32(0x4E081C00 | tmp_reg_fp | (tmp_reg << 5), code, k); + + // ins tmp_reg_fp.d[1], tmp_reg + 1 + emit32(0x4E181C00 | tmp_reg_fp | ((tmp_reg + 1) << 5), code, k); + + // scvtf tmp_reg_fp.2d, tmp_reg_fp.2d + emit32(0x4E61D800 | tmp_reg_fp | (tmp_reg_fp << 5), code, k); + + codePos = k; +} + +void JitCompilerA64::h_IADD_RS(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + const uint32_t shift = instr.getModShift(); + + // add dst, src << shift + emit32(ARMV8A::ADD | dst | (dst << 5) | (shift << 10) | (src << 16), code, k); + + if (instr.dst == RegisterNeedsDisplacement) + emitAddImmediate(dst, dst, instr.getImm32(), code, k); + + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_IADD_M(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + + constexpr uint32_t tmp_reg = 18; + emitMemLoad(dst, src, instr, code, k); + + // add dst, dst, tmp_reg + emit32(ARMV8A::ADD | dst | (dst << 5) | (tmp_reg << 16), code, k); + + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_ISUB_R(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + + if (src != dst) + { + // sub dst, dst, src + emit32(ARMV8A::SUB | dst | (dst << 5) | (src << 16), code, k); + } + else + { + emitAddImmediate(dst, dst, -instr.getImm32(), code, k); + } + + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_ISUB_M(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + + constexpr uint32_t tmp_reg = 18; + emitMemLoad(dst, src, instr, code, k); + + // sub dst, dst, tmp_reg + emit32(ARMV8A::SUB | dst | (dst << 5) | (tmp_reg << 16), code, k); + + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_IMUL_R(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + + if (src == dst) + { + src = 18; + emitMovImmediate(src, instr.getImm32(), code, k); + } + + // mul dst, dst, src + emit32(ARMV8A::MUL | dst | (dst << 5) | (src << 16), code, k); + + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_IMUL_M(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + + constexpr uint32_t tmp_reg = 18; + emitMemLoad(dst, src, instr, code, k); + + // sub dst, dst, tmp_reg + emit32(ARMV8A::MUL | dst | (dst << 5) | (tmp_reg << 16), code, k); + + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_IMULH_R(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + + // umulh dst, dst, src + emit32(ARMV8A::UMULH | dst | (dst << 5) | (src << 16), code, k); + + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_IMULH_M(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + + constexpr uint32_t tmp_reg = 18; + emitMemLoad(dst, src, instr, code, k); + + // umulh dst, dst, tmp_reg + emit32(ARMV8A::UMULH | dst | (dst << 5) | (tmp_reg << 16), code, k); + + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_ISMULH_R(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + + // smulh dst, dst, src + emit32(ARMV8A::SMULH | dst | (dst << 5) | (src << 16), code, k); + + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_ISMULH_M(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + + constexpr uint32_t tmp_reg = 18; + emitMemLoad(dst, src, instr, code, k); + + // smulh dst, dst, tmp_reg + emit32(ARMV8A::SMULH | dst | (dst << 5) | (tmp_reg << 16), code, k); + + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_IMUL_RCP(Instruction& instr, uint32_t& codePos) +{ + const uint64_t divisor = instr.getImm32(); + if (isZeroOrPowerOf2(divisor)) + return; + + uint32_t k = codePos; + + constexpr uint32_t tmp_reg = 18; + const uint32_t dst = IntRegMap[instr.dst]; + + constexpr uint64_t N = 1ULL << 63; + const uint64_t q = N / divisor; + const uint64_t r = N % divisor; +#ifdef __GNUC__ + const uint64_t shift = 64 - __builtin_clzll(divisor); +#else + uint64_t shift = 32; + for (uint64_t k = 1U << 31; (k & divisor) == 0; k >>= 1) + --shift; +#endif + + const uint32_t literal_id = (ImulRcpLiteralsEnd - literalPos) / sizeof(uint64_t); + + literalPos -= sizeof(uint64_t); + *(uint64_t*)(code + literalPos) = (q << shift) + ((r << shift) / divisor); + + if (literal_id < 13) + { + static constexpr uint32_t literal_regs[13] = { 30 << 16, 29 << 16, 28 << 16, 27 << 16, 26 << 16, 25 << 16, 24 << 16, 23 << 16, 22 << 16, 21 << 16, 20 << 16, 11 << 16, 0 }; + + // mul dst, dst, literal_reg + emit32(ARMV8A::MUL | dst | (dst << 5) | literal_regs[literal_id], code, k); + } + else + { + // ldr tmp_reg, reciprocal + const uint32_t offset = (literalPos - k) / 4; + emit32(ARMV8A::LDR_LITERAL | tmp_reg | (offset << 5), code, k); + + // mul dst, dst, tmp_reg + emit32(ARMV8A::MUL | dst | (dst << 5) | (tmp_reg << 16), code, k); + } + + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_INEG_R(Instruction& instr, uint32_t& codePos) +{ + const uint32_t dst = IntRegMap[instr.dst]; + + // sub dst, xzr, dst + emit32(ARMV8A::SUB | dst | (31 << 5) | (dst << 16), code, codePos); + + reg_changed_offset[instr.dst] = codePos; +} + +void JitCompilerA64::h_IXOR_R(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + + if (src == dst) + { + src = 18; + emitMovImmediate(src, instr.getImm32(), code, k); + } + + // eor dst, dst, src + emit32(ARMV8A::EOR | dst | (dst << 5) | (src << 16), code, k); + + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_IXOR_M(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + + constexpr uint32_t tmp_reg = 18; + emitMemLoad(dst, src, instr, code, k); + + // eor dst, dst, tmp_reg + emit32(ARMV8A::EOR | dst | (dst << 5) | (tmp_reg << 16), code, k); + + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_IROR_R(Instruction& instr, uint32_t& codePos) +{ + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + + if (src != dst) + { + // ror dst, dst, src + emit32(ARMV8A::ROR | dst | (dst << 5) | (src << 16), code, codePos); + } + else + { + // ror dst, dst, imm + emit32(ARMV8A::ROR_IMM | dst | (dst << 5) | ((instr.getImm32() & 63) << 10) | (dst << 16), code, codePos); + } + + reg_changed_offset[instr.dst] = codePos; +} + +void JitCompilerA64::h_IROL_R(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + + if (src != dst) + { + constexpr uint32_t tmp_reg = 18; + + // sub tmp_reg, xzr, src + emit32(ARMV8A::SUB | tmp_reg | (31 << 5) | (src << 16), code, k); + + // ror dst, dst, tmp_reg + emit32(ARMV8A::ROR | dst | (dst << 5) | (tmp_reg << 16), code, k); + } + else + { + // ror dst, dst, imm + emit32(ARMV8A::ROR_IMM | dst | (dst << 5) | ((-instr.getImm32() & 63) << 10) | (dst << 16), code, k); + } + + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_ISWAP_R(Instruction& instr, uint32_t& codePos) +{ + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + + if (src == dst) + return; + + uint32_t k = codePos; + + constexpr uint32_t tmp_reg = 18; + emit32(ARMV8A::MOV_REG | tmp_reg | (dst << 16), code, k); + emit32(ARMV8A::MOV_REG | dst | (src << 16), code, k); + emit32(ARMV8A::MOV_REG | src | (tmp_reg << 16), code, k); + + reg_changed_offset[instr.src] = k; + reg_changed_offset[instr.dst] = k; + codePos = k; +} + +void JitCompilerA64::h_FSWAP_R(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t dst = instr.dst + 16; + + constexpr uint32_t tmp_reg_fp = 28; + constexpr uint32_t src_index1 = 1 << 14; + constexpr uint32_t dst_index1 = 1 << 20; + + emit32(ARMV8A::MOV_VREG_EL | tmp_reg_fp | (dst << 5) | src_index1, code, k); + emit32(ARMV8A::MOV_VREG_EL | dst | (dst << 5) | dst_index1, code, k); + emit32(ARMV8A::MOV_VREG_EL | dst | (tmp_reg_fp << 5), code, k); + + codePos = k; +} + +void JitCompilerA64::h_FADD_R(Instruction& instr, uint32_t& codePos) +{ + const uint32_t src = (instr.src % 4) + 24; + const uint32_t dst = (instr.dst % 4) + 16; + + emit32(ARMV8A::FADD | dst | (dst << 5) | (src << 16), code, codePos); +} + +void JitCompilerA64::h_FADD_M(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = (instr.dst % 4) + 16; + + constexpr uint32_t tmp_reg_fp = 28; + emitMemLoadFP(src, instr, code, k); + + emit32(ARMV8A::FADD | dst | (dst << 5) | (tmp_reg_fp << 16), code, k); + + codePos = k; +} + +void JitCompilerA64::h_FSUB_R(Instruction& instr, uint32_t& codePos) +{ + const uint32_t src = (instr.src % 4) + 24; + const uint32_t dst = (instr.dst % 4) + 16; + + emit32(ARMV8A::FSUB | dst | (dst << 5) | (src << 16), code, codePos); +} + +void JitCompilerA64::h_FSUB_M(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = (instr.dst % 4) + 16; + + constexpr uint32_t tmp_reg_fp = 28; + emitMemLoadFP(src, instr, code, k); + + emit32(ARMV8A::FSUB | dst | (dst << 5) | (tmp_reg_fp << 16), code, k); + + codePos = k; +} + +void JitCompilerA64::h_FSCAL_R(Instruction& instr, uint32_t& codePos) +{ + const uint32_t dst = (instr.dst % 4) + 16; + + emit32(ARMV8A::FEOR | dst | (dst << 5) | (31 << 16), code, codePos); +} + +void JitCompilerA64::h_FMUL_R(Instruction& instr, uint32_t& codePos) +{ + const uint32_t src = (instr.src % 4) + 24; + const uint32_t dst = (instr.dst % 4) + 20; + + emit32(ARMV8A::FMUL | dst | (dst << 5) | (src << 16), code, codePos); +} + +void JitCompilerA64::h_FDIV_M(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = (instr.dst % 4) + 20; + + constexpr uint32_t tmp_reg_fp = 28; + emitMemLoadFP(src, instr, code, k); + + // and tmp_reg_fp, tmp_reg_fp, and_mask_reg + emit32(0x4E201C00 | tmp_reg_fp | (tmp_reg_fp << 5) | (29 << 16), code, k); + + // orr tmp_reg_fp, tmp_reg_fp, or_mask_reg + emit32(0x4EA01C00 | tmp_reg_fp | (tmp_reg_fp << 5) | (30 << 16), code, k); + + emit32(ARMV8A::FDIV | dst | (dst << 5) | (tmp_reg_fp << 16), code, k); + + codePos = k; +} + +void JitCompilerA64::h_FSQRT_R(Instruction& instr, uint32_t& codePos) +{ + const uint32_t dst = (instr.dst % 4) + 20; + + emit32(ARMV8A::FSQRT | dst | (dst << 5), code, codePos); +} + +void JitCompilerA64::h_CBRANCH(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t dst = IntRegMap[instr.dst]; + const uint32_t modCond = instr.getModCond(); + const uint32_t shift = modCond + ConditionOffset; + const uint32_t imm = (instr.getImm32() | (1U << shift)) & ~(1U << (shift - 1)); + + emitAddImmediate(dst, dst, imm, code, k); + + // tst dst, mask + static_assert((ConditionMask == 0xFF) && (ConditionOffset == 8), "Update tst encoding for different mask and offset"); + emit32((0xF2781C1F - (modCond << 16)) | (dst << 5), code, k); + + int32_t offset = reg_changed_offset[instr.dst]; + offset = ((offset - k) >> 2) & ((1 << 19) - 1); + + // beq target + emit32(0x54000000 | (offset << 5), code, k); + + for (uint32_t i = 0; i < RegistersCount; ++i) + reg_changed_offset[i] = k; + + codePos = k; +} + +void JitCompilerA64::h_CFROUND(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + + constexpr uint32_t tmp_reg = 18; + constexpr uint32_t fpcr_tmp_reg = 8; + + // ror tmp_reg, src, imm + emit32(ARMV8A::ROR_IMM | tmp_reg | (src << 5) | ((instr.getImm32() & 63) << 10) | (src << 16), code, k); + + // bfi fpcr_tmp_reg, tmp_reg, 40, 2 + emit32(0xB3580400 | fpcr_tmp_reg | (tmp_reg << 5), code, k); + + // rbit tmp_reg, fpcr_tmp_reg + emit32(0xDAC00000 | tmp_reg | (fpcr_tmp_reg << 5), code, k); + + // msr fpcr, tmp_reg + emit32(0xD51B4400 | tmp_reg, code, k); + + codePos = k; +} + +void JitCompilerA64::h_ISTORE(Instruction& instr, uint32_t& codePos) +{ + uint32_t k = codePos; + + const uint32_t src = IntRegMap[instr.src]; + const uint32_t dst = IntRegMap[instr.dst]; + constexpr uint32_t tmp_reg = 18; + + uint32_t imm = instr.getImm32(); + + if (instr.getModCond() < StoreL3Condition) + imm &= instr.getModMem() ? (RANDOMX_SCRATCHPAD_L1 - 1) : (RANDOMX_SCRATCHPAD_L2 - 1); + else + imm &= RANDOMX_SCRATCHPAD_L3 - 1; + + emitAddImmediate(tmp_reg, dst, imm, code, k); + + constexpr uint32_t t = 0x927d0000 | tmp_reg | (tmp_reg << 5); + constexpr uint32_t andInstrL1 = t | ((Log2(RANDOMX_SCRATCHPAD_L1) - 4) << 10); + constexpr uint32_t andInstrL2 = t | ((Log2(RANDOMX_SCRATCHPAD_L2) - 4) << 10); + constexpr uint32_t andInstrL3 = t | ((Log2(RANDOMX_SCRATCHPAD_L3) - 4) << 10); + + emit32((instr.getModCond() < StoreL3Condition) ? (instr.getModMem() ? andInstrL1 : andInstrL2) : andInstrL3, code, k); + + // str src, [x2, tmp_reg] + emit32(0xF8206840 | src | (tmp_reg << 16), code, k); + + codePos = k; +} + +void JitCompilerA64::h_NOP(Instruction& instr, uint32_t& codePos) +{ +} + +#include "instruction_weights.hpp" +#define INST_HANDLE(x) REPN(&JitCompilerA64::h_##x, WT(x)) + + InstructionGeneratorA64 JitCompilerA64::engine[256] = { + INST_HANDLE(IADD_RS) + INST_HANDLE(IADD_M) + INST_HANDLE(ISUB_R) + INST_HANDLE(ISUB_M) + INST_HANDLE(IMUL_R) + INST_HANDLE(IMUL_M) + INST_HANDLE(IMULH_R) + INST_HANDLE(IMULH_M) + INST_HANDLE(ISMULH_R) + INST_HANDLE(ISMULH_M) + INST_HANDLE(IMUL_RCP) + INST_HANDLE(INEG_R) + INST_HANDLE(IXOR_R) + INST_HANDLE(IXOR_M) + INST_HANDLE(IROR_R) + INST_HANDLE(IROL_R) + INST_HANDLE(ISWAP_R) + INST_HANDLE(FSWAP_R) + INST_HANDLE(FADD_R) + INST_HANDLE(FADD_M) + INST_HANDLE(FSUB_R) + INST_HANDLE(FSUB_M) + INST_HANDLE(FSCAL_R) + INST_HANDLE(FMUL_R) + INST_HANDLE(FDIV_M) + INST_HANDLE(FSQRT_R) + INST_HANDLE(CBRANCH) + INST_HANDLE(CFROUND) + INST_HANDLE(ISTORE) + INST_HANDLE(NOP) + }; +} diff --git a/src/RandomX/src/jit_compiler_a64.hpp b/src/RandomX/src/jit_compiler_a64.hpp new file mode 100644 index 000000000..a02824ffb --- /dev/null +++ b/src/RandomX/src/jit_compiler_a64.hpp @@ -0,0 +1,128 @@ +/* +Copyright (c) 2018-2019, tevador +Copyright (c) 2019, SChernykh + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include +#include +#include "common.hpp" +#include "jit_compiler_a64_static.hpp" + +namespace randomx { + + class Program; + struct ProgramConfiguration; + class SuperscalarProgram; + class Instruction; + + typedef void(JitCompilerA64::*InstructionGeneratorA64)(Instruction&, uint32_t&); + + class JitCompilerA64 { + public: + JitCompilerA64(); + ~JitCompilerA64(); + + void generateProgram(Program&, ProgramConfiguration&); + void generateProgramLight(Program&, ProgramConfiguration&, uint32_t); + + template + void generateSuperscalarHash(SuperscalarProgram(&programs)[N], std::vector &); + + void generateDatasetInitCode() {} + + ProgramFunc* getProgramFunc() { return reinterpret_cast(code); } + DatasetInitFunc* getDatasetInitFunc(); + uint8_t* getCode() { return code; } + size_t getCodeSize(); + + void enableWriting(); + void enableExecution(); + void enableAll(); + + private: + static InstructionGeneratorA64 engine[256]; + uint32_t reg_changed_offset[8]; + uint8_t* code; + uint32_t literalPos; + uint32_t num32bitLiterals; + + static void emit32(uint32_t val, uint8_t* code, uint32_t& codePos) + { + *(uint32_t*)(code + codePos) = val; + codePos += sizeof(val); + } + + static void emit64(uint64_t val, uint8_t* code, uint32_t& codePos) + { + *(uint64_t*)(code + codePos) = val; + codePos += sizeof(val); + } + + void emitMovImmediate(uint32_t dst, uint32_t imm, uint8_t* code, uint32_t& codePos); + void emitAddImmediate(uint32_t dst, uint32_t src, uint32_t imm, uint8_t* code, uint32_t& codePos); + + template + void emitMemLoad(uint32_t dst, uint32_t src, Instruction& instr, uint8_t* code, uint32_t& codePos); + + template + void emitMemLoadFP(uint32_t src, Instruction& instr, uint8_t* code, uint32_t& codePos); + + void h_IADD_RS(Instruction&, uint32_t&); + void h_IADD_M(Instruction&, uint32_t&); + void h_ISUB_R(Instruction&, uint32_t&); + void h_ISUB_M(Instruction&, uint32_t&); + void h_IMUL_R(Instruction&, uint32_t&); + void h_IMUL_M(Instruction&, uint32_t&); + void h_IMULH_R(Instruction&, uint32_t&); + void h_IMULH_M(Instruction&, uint32_t&); + void h_ISMULH_R(Instruction&, uint32_t&); + void h_ISMULH_M(Instruction&, uint32_t&); + void h_IMUL_RCP(Instruction&, uint32_t&); + void h_INEG_R(Instruction&, uint32_t&); + void h_IXOR_R(Instruction&, uint32_t&); + void h_IXOR_M(Instruction&, uint32_t&); + void h_IROR_R(Instruction&, uint32_t&); + void h_IROL_R(Instruction&, uint32_t&); + void h_ISWAP_R(Instruction&, uint32_t&); + void h_FSWAP_R(Instruction&, uint32_t&); + void h_FADD_R(Instruction&, uint32_t&); + void h_FADD_M(Instruction&, uint32_t&); + void h_FSUB_R(Instruction&, uint32_t&); + void h_FSUB_M(Instruction&, uint32_t&); + void h_FSCAL_R(Instruction&, uint32_t&); + void h_FMUL_R(Instruction&, uint32_t&); + void h_FDIV_M(Instruction&, uint32_t&); + void h_FSQRT_R(Instruction&, uint32_t&); + void h_CBRANCH(Instruction&, uint32_t&); + void h_CFROUND(Instruction&, uint32_t&); + void h_ISTORE(Instruction&, uint32_t&); + void h_NOP(Instruction&, uint32_t&); + }; +} diff --git a/src/RandomX/src/jit_compiler_a64_static.S b/src/RandomX/src/jit_compiler_a64_static.S new file mode 100644 index 000000000..4886fcf3c --- /dev/null +++ b/src/RandomX/src/jit_compiler_a64_static.S @@ -0,0 +1,591 @@ +# Copyright (c) 2018-2019, tevador +# Copyright (c) 2019, SChernykh +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#if defined(__APPLE__) +#define DECL(x) _##x +#else +#define DECL(x) x +#endif + + .arch armv8-a + .text + .global DECL(randomx_program_aarch64) + .global DECL(randomx_program_aarch64_main_loop) + .global DECL(randomx_program_aarch64_vm_instructions) + .global DECL(randomx_program_aarch64_imul_rcp_literals_end) + .global DECL(randomx_program_aarch64_vm_instructions_end) + .global DECL(randomx_program_aarch64_cacheline_align_mask1) + .global DECL(randomx_program_aarch64_cacheline_align_mask2) + .global DECL(randomx_program_aarch64_update_spMix1) + .global DECL(randomx_program_aarch64_vm_instructions_end_light) + .global DECL(randomx_program_aarch64_light_cacheline_align_mask) + .global DECL(randomx_program_aarch64_light_dataset_offset) + .global DECL(randomx_init_dataset_aarch64) + .global DECL(randomx_init_dataset_aarch64_end) + .global DECL(randomx_calc_dataset_item_aarch64) + .global DECL(randomx_calc_dataset_item_aarch64_prefetch) + .global DECL(randomx_calc_dataset_item_aarch64_mix) + .global DECL(randomx_calc_dataset_item_aarch64_store_result) + .global DECL(randomx_calc_dataset_item_aarch64_end) + +#include "configuration.h" + +# Register allocation + +# x0 -> pointer to reg buffer and then literal for IMUL_RCP +# x1 -> pointer to mem buffer and then to dataset +# x2 -> pointer to scratchpad +# x3 -> loop counter +# x4 -> "r0" +# x5 -> "r1" +# x6 -> "r2" +# x7 -> "r3" +# x8 -> fpcr (reversed bits) +# x9 -> mx, ma +# x10 -> spMix1 +# x11 -> literal for IMUL_RCP +# x12 -> "r4" +# x13 -> "r5" +# x14 -> "r6" +# x15 -> "r7" +# x16 -> spAddr0 +# x17 -> spAddr1 +# x18 -> temporary +# x19 -> temporary +# x20 -> literal for IMUL_RCP +# x21 -> literal for IMUL_RCP +# x22 -> literal for IMUL_RCP +# x23 -> literal for IMUL_RCP +# x24 -> literal for IMUL_RCP +# x25 -> literal for IMUL_RCP +# x26 -> literal for IMUL_RCP +# x27 -> literal for IMUL_RCP +# x28 -> literal for IMUL_RCP +# x29 -> literal for IMUL_RCP +# x30 -> literal for IMUL_RCP + +# v0-v15 -> store 32-bit literals +# v16 -> "f0" +# v17 -> "f1" +# v18 -> "f2" +# v19 -> "f3" +# v20 -> "e0" +# v21 -> "e1" +# v22 -> "e2" +# v23 -> "e3" +# v24 -> "a0" +# v25 -> "a1" +# v26 -> "a2" +# v27 -> "a3" +# v28 -> temporary +# v29 -> E 'and' mask = 0x00ffffffffffffff00ffffffffffffff +# v30 -> E 'or' mask = 0x3*00000000******3*00000000****** +# v31 -> scale mask = 0x81f000000000000081f0000000000000 + + .balign 4 +DECL(randomx_program_aarch64): + # Save callee-saved registers + sub sp, sp, 192 + stp x16, x17, [sp] + stp x18, x19, [sp, 16] + stp x20, x21, [sp, 32] + stp x22, x23, [sp, 48] + stp x24, x25, [sp, 64] + stp x26, x27, [sp, 80] + stp x28, x29, [sp, 96] + stp x8, x30, [sp, 112] + stp d8, d9, [sp, 128] + stp d10, d11, [sp, 144] + stp d12, d13, [sp, 160] + stp d14, d15, [sp, 176] + + # Zero integer registers + mov x4, xzr + mov x5, xzr + mov x6, xzr + mov x7, xzr + mov x12, xzr + mov x13, xzr + mov x14, xzr + mov x15, xzr + + # Load ma, mx and dataset pointer + ldp x9, x1, [x1] + + # Load initial spMix value + mov x10, x9 + + # Load group A registers + ldp q24, q25, [x0, 192] + ldp q26, q27, [x0, 224] + + # Load E 'and' mask + mov x16, 0x00FFFFFFFFFFFFFF + ins v29.d[0], x16 + ins v29.d[1], x16 + + # Load E 'or' mask (stored in reg.f[0]) + ldr q30, [x0, 64] + + # Load scale mask + mov x16, 0x80f0000000000000 + ins v31.d[0], x16 + ins v31.d[1], x16 + + # Read fpcr + mrs x8, fpcr + rbit x8, x8 + + # Save x0 + str x0, [sp, -16]! + + # Read literals + ldr x0, literal_x0 + ldr x11, literal_x11 + ldr x20, literal_x20 + ldr x21, literal_x21 + ldr x22, literal_x22 + ldr x23, literal_x23 + ldr x24, literal_x24 + ldr x25, literal_x25 + ldr x26, literal_x26 + ldr x27, literal_x27 + ldr x28, literal_x28 + ldr x29, literal_x29 + ldr x30, literal_x30 + + ldr q0, literal_v0 + ldr q1, literal_v1 + ldr q2, literal_v2 + ldr q3, literal_v3 + ldr q4, literal_v4 + ldr q5, literal_v5 + ldr q6, literal_v6 + ldr q7, literal_v7 + ldr q8, literal_v8 + ldr q9, literal_v9 + ldr q10, literal_v10 + ldr q11, literal_v11 + ldr q12, literal_v12 + ldr q13, literal_v13 + ldr q14, literal_v14 + ldr q15, literal_v15 + +DECL(randomx_program_aarch64_main_loop): + # spAddr0 = spMix1 & ScratchpadL3Mask64; + # spAddr1 = (spMix1 >> 32) & ScratchpadL3Mask64; + lsr x18, x10, 32 + + # Actual mask will be inserted by JIT compiler + and w16, w10, 1 + and w17, w18, 1 + + # x16 = scratchpad + spAddr0 + # x17 = scratchpad + spAddr1 + add x16, x16, x2 + add x17, x17, x2 + + # xor integer registers with scratchpad data (spAddr0) + ldp x18, x19, [x16] + eor x4, x4, x18 + eor x5, x5, x19 + ldp x18, x19, [x16, 16] + eor x6, x6, x18 + eor x7, x7, x19 + ldp x18, x19, [x16, 32] + eor x12, x12, x18 + eor x13, x13, x19 + ldp x18, x19, [x16, 48] + eor x14, x14, x18 + eor x15, x15, x19 + + # Load group F registers (spAddr1) + ldpsw x18, x19, [x17] + ins v16.d[0], x18 + ins v16.d[1], x19 + ldpsw x18, x19, [x17, 8] + ins v17.d[0], x18 + ins v17.d[1], x19 + ldpsw x18, x19, [x17, 16] + ins v18.d[0], x18 + ins v18.d[1], x19 + ldpsw x18, x19, [x17, 24] + ins v19.d[0], x18 + ins v19.d[1], x19 + scvtf v16.2d, v16.2d + scvtf v17.2d, v17.2d + scvtf v18.2d, v18.2d + scvtf v19.2d, v19.2d + + # Load group E registers (spAddr1) + ldpsw x18, x19, [x17, 32] + ins v20.d[0], x18 + ins v20.d[1], x19 + ldpsw x18, x19, [x17, 40] + ins v21.d[0], x18 + ins v21.d[1], x19 + ldpsw x18, x19, [x17, 48] + ins v22.d[0], x18 + ins v22.d[1], x19 + ldpsw x18, x19, [x17, 56] + ins v23.d[0], x18 + ins v23.d[1], x19 + scvtf v20.2d, v20.2d + scvtf v21.2d, v21.2d + scvtf v22.2d, v22.2d + scvtf v23.2d, v23.2d + and v20.16b, v20.16b, v29.16b + and v21.16b, v21.16b, v29.16b + and v22.16b, v22.16b, v29.16b + and v23.16b, v23.16b, v29.16b + orr v20.16b, v20.16b, v30.16b + orr v21.16b, v21.16b, v30.16b + orr v22.16b, v22.16b, v30.16b + orr v23.16b, v23.16b, v30.16b + + # Execute VM instructions +DECL(randomx_program_aarch64_vm_instructions): + + # buffer for generated instructions + # FDIV_M is the largest instruction taking up to 12 ARMv8 instructions + .fill RANDOMX_PROGRAM_SIZE*12,4,0 + +literal_x0: .fill 1,8,0 +literal_x11: .fill 1,8,0 +literal_x20: .fill 1,8,0 +literal_x21: .fill 1,8,0 +literal_x22: .fill 1,8,0 +literal_x23: .fill 1,8,0 +literal_x24: .fill 1,8,0 +literal_x25: .fill 1,8,0 +literal_x26: .fill 1,8,0 +literal_x27: .fill 1,8,0 +literal_x28: .fill 1,8,0 +literal_x29: .fill 1,8,0 +literal_x30: .fill 1,8,0 +DECL(randomx_program_aarch64_imul_rcp_literals_end): + +literal_v0: .fill 2,8,0 +literal_v1: .fill 2,8,0 +literal_v2: .fill 2,8,0 +literal_v3: .fill 2,8,0 +literal_v4: .fill 2,8,0 +literal_v5: .fill 2,8,0 +literal_v6: .fill 2,8,0 +literal_v7: .fill 2,8,0 +literal_v8: .fill 2,8,0 +literal_v9: .fill 2,8,0 +literal_v10: .fill 2,8,0 +literal_v11: .fill 2,8,0 +literal_v12: .fill 2,8,0 +literal_v13: .fill 2,8,0 +literal_v14: .fill 2,8,0 +literal_v15: .fill 2,8,0 + +DECL(randomx_program_aarch64_vm_instructions_end): + # Calculate dataset pointer for dataset read + # Do it here to break false dependency from readReg2 and readReg3 (see next line) + lsr x10, x9, 32 + + # mx ^= r[readReg2] ^ r[readReg3]; + eor x9, x9, x18 + + # Calculate dataset pointer for dataset prefetch + mov w18, w9 +DECL(randomx_program_aarch64_cacheline_align_mask1): + # Actual mask will be inserted by JIT compiler + and x18, x18, 1 + add x18, x18, x1 + + # Prefetch dataset data + prfm pldl2strm, [x18] + + # mx <-> ma + ror x9, x9, 32 + +DECL(randomx_program_aarch64_cacheline_align_mask2): + # Actual mask will be inserted by JIT compiler + and x10, x10, 1 + add x10, x10, x1 + +DECL(randomx_program_aarch64_xor_with_dataset_line): +rx_program_xor_with_dataset_line: + # xor integer registers with dataset data + ldp x18, x19, [x10] + eor x4, x4, x18 + eor x5, x5, x19 + ldp x18, x19, [x10, 16] + eor x6, x6, x18 + eor x7, x7, x19 + ldp x18, x19, [x10, 32] + eor x12, x12, x18 + eor x13, x13, x19 + ldp x18, x19, [x10, 48] + eor x14, x14, x18 + eor x15, x15, x19 + +DECL(randomx_program_aarch64_update_spMix1): + # JIT compiler will replace it with "eor x10, config.readReg0, config.readReg1" + eor x10, x0, x0 + + # Store integer registers to scratchpad (spAddr1) + stp x4, x5, [x17, 0] + stp x6, x7, [x17, 16] + stp x12, x13, [x17, 32] + stp x14, x15, [x17, 48] + + # xor group F and group E registers + eor v16.16b, v16.16b, v20.16b + eor v17.16b, v17.16b, v21.16b + eor v18.16b, v18.16b, v22.16b + eor v19.16b, v19.16b, v23.16b + + # Store FP registers to scratchpad (spAddr0) + stp q16, q17, [x16, 0] + stp q18, q19, [x16, 32] + + subs x3, x3, 1 + bne DECL(randomx_program_aarch64_main_loop) + + # Restore x0 + ldr x0, [sp], 16 + + # Store integer registers + stp x4, x5, [x0, 0] + stp x6, x7, [x0, 16] + stp x12, x13, [x0, 32] + stp x14, x15, [x0, 48] + + # Store FP registers + stp q16, q17, [x0, 64] + stp q18, q19, [x0, 96] + stp q20, q21, [x0, 128] + stp q22, q23, [x0, 160] + + # Restore callee-saved registers + ldp x16, x17, [sp] + ldp x18, x19, [sp, 16] + ldp x20, x21, [sp, 32] + ldp x22, x23, [sp, 48] + ldp x24, x25, [sp, 64] + ldp x26, x27, [sp, 80] + ldp x28, x29, [sp, 96] + ldp x8, x30, [sp, 112] + ldp d8, d9, [sp, 128] + ldp d10, d11, [sp, 144] + ldp d12, d13, [sp, 160] + ldp d14, d15, [sp, 176] + add sp, sp, 192 + + ret + +DECL(randomx_program_aarch64_vm_instructions_end_light): + sub sp, sp, 96 + stp x0, x1, [sp, 64] + stp x2, x30, [sp, 80] + + # mx ^= r[readReg2] ^ r[readReg3]; + eor x9, x9, x18 + + # mx <-> ma + ror x9, x9, 32 + + # x0 -> pointer to cache memory + mov x0, x1 + + # x1 -> pointer to output + mov x1, sp + +DECL(randomx_program_aarch64_light_cacheline_align_mask): + # Actual mask will be inserted by JIT compiler + and w2, w9, 1 + + # x2 -> item number + lsr x2, x2, 6 + +DECL(randomx_program_aarch64_light_dataset_offset): + # Apply dataset offset (filled in by JIT compiler) + add x2, x2, 0 + add x2, x2, 0 + + bl rx_calc_dataset_item + + mov x10, sp + ldp x0, x1, [sp, 64] + ldp x2, x30, [sp, 80] + add sp, sp, 96 + + b rx_program_xor_with_dataset_line + + + +# Input parameters +# +# x0 -> pointer to cache +# x1 -> pointer to dataset memory at startItem +# x2 -> start item +# x3 -> end item + +DECL(randomx_init_dataset_aarch64): + # Save x30 (return address) + str x30, [sp, -16]! + + # Load pointer to cache memory + ldr x0, [x0] + +DECL(randomx_init_dataset_aarch64_main_loop): + bl rx_calc_dataset_item + add x1, x1, 64 + add x2, x2, 1 + cmp x2, x3 + bne DECL(randomx_init_dataset_aarch64_main_loop) + + # Restore x30 (return address) + ldr x30, [sp], 16 + + ret + +DECL(randomx_init_dataset_aarch64_end): + +# Input parameters +# +# x0 -> pointer to cache memory +# x1 -> pointer to output +# x2 -> item number +# +# Register allocation +# +# x0-x7 -> output value (calculated dataset item) +# x8 -> pointer to cache memory +# x9 -> pointer to output +# x10 -> registerValue +# x11 -> mixBlock +# x12 -> temporary +# x13 -> temporary + +DECL(randomx_calc_dataset_item_aarch64): +rx_calc_dataset_item: + sub sp, sp, 112 + stp x0, x1, [sp] + stp x2, x3, [sp, 16] + stp x4, x5, [sp, 32] + stp x6, x7, [sp, 48] + stp x8, x9, [sp, 64] + stp x10, x11, [sp, 80] + stp x12, x13, [sp, 96] + + ldr x12, superscalarMul0 + + mov x8, x0 + mov x9, x1 + mov x10, x2 + + # rl[0] = (itemNumber + 1) * superscalarMul0; + madd x0, x2, x12, x12 + + # rl[1] = rl[0] ^ superscalarAdd1; + ldr x12, superscalarAdd1 + eor x1, x0, x12 + + # rl[2] = rl[0] ^ superscalarAdd2; + ldr x12, superscalarAdd2 + eor x2, x0, x12 + + # rl[3] = rl[0] ^ superscalarAdd3; + ldr x12, superscalarAdd3 + eor x3, x0, x12 + + # rl[4] = rl[0] ^ superscalarAdd4; + ldr x12, superscalarAdd4 + eor x4, x0, x12 + + # rl[5] = rl[0] ^ superscalarAdd5; + ldr x12, superscalarAdd5 + eor x5, x0, x12 + + # rl[6] = rl[0] ^ superscalarAdd6; + ldr x12, superscalarAdd6 + eor x6, x0, x12 + + # rl[7] = rl[0] ^ superscalarAdd7; + ldr x12, superscalarAdd7 + eor x7, x0, x12 + + b rx_calc_dataset_item_prefetch + +superscalarMul0: .quad 6364136223846793005 +superscalarAdd1: .quad 9298411001130361340 +superscalarAdd2: .quad 12065312585734608966 +superscalarAdd3: .quad 9306329213124626780 +superscalarAdd4: .quad 5281919268842080866 +superscalarAdd5: .quad 10536153434571861004 +superscalarAdd6: .quad 3398623926847679864 +superscalarAdd7: .quad 9549104520008361294 + +# Prefetch -> SuperScalar hash -> Mix will be repeated N times + +DECL(randomx_calc_dataset_item_aarch64_prefetch): +rx_calc_dataset_item_prefetch: + # Actual mask will be inserted by JIT compiler + and x11, x10, 1 + add x11, x8, x11, lsl 6 + prfm pldl2strm, [x11] + + # Generated SuperScalar hash program goes here + +DECL(randomx_calc_dataset_item_aarch64_mix): + ldp x12, x13, [x11] + eor x0, x0, x12 + eor x1, x1, x13 + ldp x12, x13, [x11, 16] + eor x2, x2, x12 + eor x3, x3, x13 + ldp x12, x13, [x11, 32] + eor x4, x4, x12 + eor x5, x5, x13 + ldp x12, x13, [x11, 48] + eor x6, x6, x12 + eor x7, x7, x13 + +DECL(randomx_calc_dataset_item_aarch64_store_result): + stp x0, x1, [x9] + stp x2, x3, [x9, 16] + stp x4, x5, [x9, 32] + stp x6, x7, [x9, 48] + + ldp x0, x1, [sp] + ldp x2, x3, [sp, 16] + ldp x4, x5, [sp, 32] + ldp x6, x7, [sp, 48] + ldp x8, x9, [sp, 64] + ldp x10, x11, [sp, 80] + ldp x12, x13, [sp, 96] + add sp, sp, 112 + + ret + +DECL(randomx_calc_dataset_item_aarch64_end): diff --git a/src/RandomX/src/jit_compiler_a64_static.hpp b/src/RandomX/src/jit_compiler_a64_static.hpp new file mode 100644 index 000000000..a9b922e29 --- /dev/null +++ b/src/RandomX/src/jit_compiler_a64_static.hpp @@ -0,0 +1,51 @@ +/* +Copyright (c) 2018-2019, tevador +Copyright (c) 2019, SChernykh + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +extern "C" { + void randomx_program_aarch64(void* reg, void* mem, void* scratchpad, uint64_t iterations); + void randomx_program_aarch64_main_loop(); + void randomx_program_aarch64_vm_instructions(); + void randomx_program_aarch64_imul_rcp_literals_end(); + void randomx_program_aarch64_vm_instructions_end(); + void randomx_program_aarch64_cacheline_align_mask1(); + void randomx_program_aarch64_cacheline_align_mask2(); + void randomx_program_aarch64_update_spMix1(); + void randomx_program_aarch64_vm_instructions_end_light(); + void randomx_program_aarch64_light_cacheline_align_mask(); + void randomx_program_aarch64_light_dataset_offset(); + void randomx_init_dataset_aarch64(); + void randomx_init_dataset_aarch64_end(); + void randomx_calc_dataset_item_aarch64(); + void randomx_calc_dataset_item_aarch64_prefetch(); + void randomx_calc_dataset_item_aarch64_mix(); + void randomx_calc_dataset_item_aarch64_store_result(); + void randomx_calc_dataset_item_aarch64_end(); +} diff --git a/src/RandomX/src/jit_compiler_fallback.hpp b/src/RandomX/src/jit_compiler_fallback.hpp new file mode 100644 index 000000000..57a6dbf99 --- /dev/null +++ b/src/RandomX/src/jit_compiler_fallback.hpp @@ -0,0 +1,76 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include +#include +#include "common.hpp" + +namespace randomx { + + class Program; + struct ProgramConfiguration; + class SuperscalarProgram; + + class JitCompilerFallback { + public: + JitCompilerFallback() { + throw std::runtime_error("JIT compilation is not supported on this platform"); + } + void generateProgram(Program&, ProgramConfiguration&) { + + } + void generateProgramLight(Program&, ProgramConfiguration&, uint32_t) { + + } + template + void generateSuperscalarHash(SuperscalarProgram(&programs)[N], std::vector &) { + + } + void generateDatasetInitCode() { + + } + ProgramFunc* getProgramFunc() { + return nullptr; + } + DatasetInitFunc* getDatasetInitFunc() { + return nullptr; + } + uint8_t* getCode() { + return nullptr; + } + size_t getCodeSize() { + return 0; + } + void enableWriting() {} + void enableExecution() {} + void enableAll() {} + }; +} \ No newline at end of file diff --git a/src/RandomX/src/jit_compiler_x86.cpp b/src/RandomX/src/jit_compiler_x86.cpp new file mode 100644 index 000000000..e75f76328 --- /dev/null +++ b/src/RandomX/src/jit_compiler_x86.cpp @@ -0,0 +1,845 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include +#include "jit_compiler_x86.hpp" +#include "jit_compiler_x86_static.hpp" +#include "superscalar.hpp" +#include "program.hpp" +#include "reciprocal.h" +#include "virtual_memory.hpp" + +namespace randomx { + /* + + REGISTER ALLOCATION: + + ; rax -> temporary + ; rbx -> iteration counter "ic" + ; rcx -> temporary + ; rdx -> temporary + ; rsi -> scratchpad pointer + ; rdi -> dataset pointer + ; rbp -> memory registers "ma" (high 32 bits), "mx" (low 32 bits) + ; rsp -> stack pointer + ; r8 -> "r0" + ; r9 -> "r1" + ; r10 -> "r2" + ; r11 -> "r3" + ; r12 -> "r4" + ; r13 -> "r5" + ; r14 -> "r6" + ; r15 -> "r7" + ; xmm0 -> "f0" + ; xmm1 -> "f1" + ; xmm2 -> "f2" + ; xmm3 -> "f3" + ; xmm4 -> "e0" + ; xmm5 -> "e1" + ; xmm6 -> "e2" + ; xmm7 -> "e3" + ; xmm8 -> "a0" + ; xmm9 -> "a1" + ; xmm10 -> "a2" + ; xmm11 -> "a3" + ; xmm12 -> temporary + ; xmm13 -> E 'and' mask = 0x00ffffffffffffff00ffffffffffffff + ; xmm14 -> E 'or' mask = 0x3*00000000******3*00000000****** + ; xmm15 -> scale mask = 0x81f000000000000081f0000000000000 + + */ + + //Calculate the required code buffer size that is sufficient for the largest possible program: + + constexpr size_t MaxRandomXInstrCodeSize = 32; //FDIV_M requires up to 32 bytes of x86 code + constexpr size_t MaxSuperscalarInstrSize = 14; //IMUL_RCP requires 14 bytes of x86 code + constexpr size_t SuperscalarProgramHeader = 128; //overhead per superscalar program + constexpr size_t CodeAlign = 4096; //align code size to a multiple of 4 KiB + constexpr size_t ReserveCodeSize = CodeAlign; //function prologue/epilogue + reserve + + constexpr size_t RandomXCodeSize = alignSize(ReserveCodeSize + MaxRandomXInstrCodeSize * RANDOMX_PROGRAM_SIZE, CodeAlign); + constexpr size_t SuperscalarSize = alignSize(ReserveCodeSize + (SuperscalarProgramHeader + MaxSuperscalarInstrSize * SuperscalarMaxSize) * RANDOMX_CACHE_ACCESSES, CodeAlign); + + static_assert(RandomXCodeSize < INT32_MAX / 2, "RandomXCodeSize is too large"); + static_assert(SuperscalarSize < INT32_MAX / 2, "SuperscalarSize is too large"); + + constexpr uint32_t CodeSize = RandomXCodeSize + SuperscalarSize; + + constexpr int32_t superScalarHashOffset = RandomXCodeSize; + +#if defined(_MSC_VER) && (defined(_DEBUG) || defined (RELWITHDEBINFO)) +#define ADDR(x) ((((uint8_t*)&x)[0] == 0xE9) ? (((uint8_t*)&x) + *(const int32_t*)(((uint8_t*)&x) + 1) + 5) : ((uint8_t*)&x)) +#else +#define ADDR(x) ((uint8_t*)&x) +#endif + + const uint8_t* codePrologue = ADDR(randomx_program_prologue); + const uint8_t* codeLoopBegin = ADDR(randomx_program_loop_begin); + const uint8_t* codeLoopLoad = ADDR(randomx_program_loop_load); + const uint8_t* codeProgamStart = ADDR(randomx_program_start); + const uint8_t* codeReadDataset = ADDR(randomx_program_read_dataset); + const uint8_t* codeReadDatasetLightSshInit = ADDR(randomx_program_read_dataset_sshash_init); + const uint8_t* codeReadDatasetLightSshFin = ADDR(randomx_program_read_dataset_sshash_fin); + const uint8_t* codeDatasetInit = ADDR(randomx_dataset_init); + const uint8_t* codeLoopStore = ADDR(randomx_program_loop_store); + const uint8_t* codeLoopEnd = ADDR(randomx_program_loop_end); + const uint8_t* codeEpilogue = ADDR(randomx_program_epilogue); + const uint8_t* codeProgramEnd = ADDR(randomx_program_end); + const uint8_t* codeShhLoad = ADDR(randomx_sshash_load); + const uint8_t* codeShhPrefetch = ADDR(randomx_sshash_prefetch); + const uint8_t* codeShhEnd = ADDR(randomx_sshash_end); + const uint8_t* codeShhInit = ADDR(randomx_sshash_init); + + const int32_t prologueSize = codeLoopBegin - codePrologue; + const int32_t loopLoadSize = codeProgamStart - codeLoopLoad; + const int32_t readDatasetSize = codeReadDatasetLightSshInit - codeReadDataset; + const int32_t readDatasetLightInitSize = codeReadDatasetLightSshFin - codeReadDatasetLightSshInit; + const int32_t readDatasetLightFinSize = codeLoopStore - codeReadDatasetLightSshFin; + const int32_t loopStoreSize = codeLoopEnd - codeLoopStore; + const int32_t datasetInitSize = codeEpilogue - codeDatasetInit; + const int32_t epilogueSize = codeShhLoad - codeEpilogue; + const int32_t codeSshLoadSize = codeShhPrefetch - codeShhLoad; + const int32_t codeSshPrefetchSize = codeShhEnd - codeShhPrefetch; + const int32_t codeSshInitSize = codeProgramEnd - codeShhInit; + + const int32_t epilogueOffset = CodeSize - epilogueSize; + + static const uint8_t REX_ADD_RR[] = { 0x4d, 0x03 }; + static const uint8_t REX_ADD_RM[] = { 0x4c, 0x03 }; + static const uint8_t REX_SUB_RR[] = { 0x4d, 0x2b }; + static const uint8_t REX_SUB_RM[] = { 0x4c, 0x2b }; + static const uint8_t REX_MOV_RR[] = { 0x41, 0x8b }; + static const uint8_t REX_MOV_RR64[] = { 0x49, 0x8b }; + static const uint8_t REX_MOV_R64R[] = { 0x4c, 0x8b }; + static const uint8_t REX_IMUL_RR[] = { 0x4d, 0x0f, 0xaf }; + static const uint8_t REX_IMUL_RRI[] = { 0x4d, 0x69 }; + static const uint8_t REX_IMUL_RM[] = { 0x4c, 0x0f, 0xaf }; + static const uint8_t REX_MUL_R[] = { 0x49, 0xf7 }; + static const uint8_t REX_MUL_M[] = { 0x48, 0xf7 }; + static const uint8_t REX_81[] = { 0x49, 0x81 }; + static const uint8_t AND_EAX_I = 0x25; + static const uint8_t MOV_EAX_I = 0xb8; + static const uint8_t MOV_RAX_I[] = { 0x48, 0xb8 }; + static const uint8_t MOV_RCX_I[] = { 0x48, 0xb9 }; + static const uint8_t REX_LEA[] = { 0x4f, 0x8d }; + static const uint8_t REX_MUL_MEM[] = { 0x48, 0xf7, 0x24, 0x0e }; + static const uint8_t REX_IMUL_MEM[] = { 0x48, 0xf7, 0x2c, 0x0e }; + static const uint8_t REX_SHR_RAX[] = { 0x48, 0xc1, 0xe8 }; + static const uint8_t RAX_ADD_SBB_1[] = { 0x48, 0x83, 0xC0, 0x01, 0x48, 0x83, 0xD8, 0x00 }; + static const uint8_t MUL_RCX[] = { 0x48, 0xf7, 0xe1 }; + static const uint8_t REX_SHR_RDX[] = { 0x48, 0xc1, 0xea }; + static const uint8_t REX_SH[] = { 0x49, 0xc1 }; + static const uint8_t MOV_RCX_RAX_SAR_RCX_63[] = { 0x48, 0x89, 0xc1, 0x48, 0xc1, 0xf9, 0x3f }; + static const uint8_t AND_ECX_I[] = { 0x81, 0xe1 }; + static const uint8_t ADD_RAX_RCX[] = { 0x48, 0x01, 0xC8 }; + static const uint8_t SAR_RAX_I8[] = { 0x48, 0xC1, 0xF8 }; + static const uint8_t NEG_RAX[] = { 0x48, 0xF7, 0xD8 }; + static const uint8_t ADD_R_RAX[] = { 0x4C, 0x03 }; + static const uint8_t XOR_EAX_EAX[] = { 0x33, 0xC0 }; + static const uint8_t ADD_RDX_R[] = { 0x4c, 0x01 }; + static const uint8_t SUB_RDX_R[] = { 0x4c, 0x29 }; + static const uint8_t SAR_RDX_I8[] = { 0x48, 0xC1, 0xFA }; + static const uint8_t TEST_RDX_RDX[] = { 0x48, 0x85, 0xD2 }; + static const uint8_t SETS_AL_ADD_RDX_RAX[] = { 0x0F, 0x98, 0xC0, 0x48, 0x03, 0xD0 }; + static const uint8_t REX_NEG[] = { 0x49, 0xF7 }; + static const uint8_t REX_XOR_RR[] = { 0x4D, 0x33 }; + static const uint8_t REX_XOR_RI[] = { 0x49, 0x81 }; + static const uint8_t REX_XOR_RM[] = { 0x4c, 0x33 }; + static const uint8_t REX_ROT_CL[] = { 0x49, 0xd3 }; + static const uint8_t REX_ROT_I8[] = { 0x49, 0xc1 }; + static const uint8_t SHUFPD[] = { 0x66, 0x0f, 0xc6 }; + static const uint8_t REX_ADDPD[] = { 0x66, 0x41, 0x0f, 0x58 }; + static const uint8_t REX_CVTDQ2PD_XMM12[] = { 0xf3, 0x44, 0x0f, 0xe6, 0x24, 0x06 }; + static const uint8_t REX_SUBPD[] = { 0x66, 0x41, 0x0f, 0x5c }; + static const uint8_t REX_XORPS[] = { 0x41, 0x0f, 0x57 }; + static const uint8_t REX_MULPD[] = { 0x66, 0x41, 0x0f, 0x59 }; + static const uint8_t REX_MAXPD[] = { 0x66, 0x41, 0x0f, 0x5f }; + static const uint8_t REX_DIVPD[] = { 0x66, 0x41, 0x0f, 0x5e }; + static const uint8_t SQRTPD[] = { 0x66, 0x0f, 0x51 }; + static const uint8_t AND_OR_MOV_LDMXCSR[] = { 0x25, 0x00, 0x60, 0x00, 0x00, 0x0D, 0xC0, 0x9F, 0x00, 0x00, 0x50, 0x0F, 0xAE, 0x14, 0x24, 0x58 }; + static const uint8_t ROL_RAX[] = { 0x48, 0xc1, 0xc0 }; + static const uint8_t XOR_ECX_ECX[] = { 0x33, 0xC9 }; + static const uint8_t REX_CMP_R32I[] = { 0x41, 0x81 }; + static const uint8_t REX_CMP_M32I[] = { 0x81, 0x3c, 0x06 }; + static const uint8_t MOVAPD[] = { 0x66, 0x0f, 0x29 }; + static const uint8_t REX_MOV_MR[] = { 0x4c, 0x89 }; + static const uint8_t REX_XOR_EAX[] = { 0x41, 0x33 }; + static const uint8_t SUB_EBX[] = { 0x83, 0xEB, 0x01 }; + static const uint8_t JNZ[] = { 0x0f, 0x85 }; + static const uint8_t JMP = 0xe9; + static const uint8_t REX_XOR_RAX_R64[] = { 0x49, 0x33 }; + static const uint8_t REX_XCHG[] = { 0x4d, 0x87 }; + static const uint8_t REX_ANDPS_XMM12[] = { 0x45, 0x0F, 0x54, 0xE5, 0x45, 0x0F, 0x56, 0xE6 }; + static const uint8_t REX_PADD[] = { 0x66, 0x44, 0x0f }; + static const uint8_t PADD_OPCODES[] = { 0xfc, 0xfd, 0xfe, 0xd4 }; + static const uint8_t CALL = 0xe8; + static const uint8_t REX_ADD_I[] = { 0x49, 0x81 }; + static const uint8_t REX_TEST[] = { 0x49, 0xF7 }; + static const uint8_t JZ[] = { 0x0f, 0x84 }; + static const uint8_t RET = 0xc3; + static const uint8_t LEA_32[] = { 0x41, 0x8d }; + static const uint8_t MOVNTI[] = { 0x4c, 0x0f, 0xc3 }; + static const uint8_t ADD_EBX_I[] = { 0x81, 0xc3 }; + + static const uint8_t NOP1[] = { 0x90 }; + static const uint8_t NOP2[] = { 0x66, 0x90 }; + static const uint8_t NOP3[] = { 0x66, 0x66, 0x90 }; + static const uint8_t NOP4[] = { 0x0F, 0x1F, 0x40, 0x00 }; + static const uint8_t NOP5[] = { 0x0F, 0x1F, 0x44, 0x00, 0x00 }; + static const uint8_t NOP6[] = { 0x66, 0x0F, 0x1F, 0x44, 0x00, 0x00 }; + static const uint8_t NOP7[] = { 0x0F, 0x1F, 0x80, 0x00, 0x00, 0x00, 0x00 }; + static const uint8_t NOP8[] = { 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00 }; + + static const uint8_t* NOPX[] = { NOP1, NOP2, NOP3, NOP4, NOP5, NOP6, NOP7, NOP8 }; + + size_t JitCompilerX86::getCodeSize() { + return CodeSize; + } + + JitCompilerX86::JitCompilerX86() { + code = (uint8_t*)allocMemoryPages(CodeSize); + memcpy(code, codePrologue, prologueSize); + memcpy(code + epilogueOffset, codeEpilogue, epilogueSize); + } + + JitCompilerX86::~JitCompilerX86() { + freePagedMemory(code, CodeSize); + } + + void JitCompilerX86::enableAll() { + setPagesRWX(code, CodeSize); + } + + void JitCompilerX86::enableWriting() { + setPagesRW(code, CodeSize); + } + + void JitCompilerX86::enableExecution() { + setPagesRX(code, CodeSize); + } + + void JitCompilerX86::generateProgram(Program& prog, ProgramConfiguration& pcfg) { + generateProgramPrologue(prog, pcfg); + memcpy(code + codePos, codeReadDataset, readDatasetSize); + codePos += readDatasetSize; + generateProgramEpilogue(prog, pcfg); + } + + void JitCompilerX86::generateProgramLight(Program& prog, ProgramConfiguration& pcfg, uint32_t datasetOffset) { + generateProgramPrologue(prog, pcfg); + emit(codeReadDatasetLightSshInit, readDatasetLightInitSize); + emit(ADD_EBX_I); + emit32(datasetOffset / CacheLineSize); + emitByte(CALL); + emit32(superScalarHashOffset - (codePos + 4)); + emit(codeReadDatasetLightSshFin, readDatasetLightFinSize); + generateProgramEpilogue(prog, pcfg); + } + + template + void JitCompilerX86::generateSuperscalarHash(SuperscalarProgram(&programs)[N], std::vector &reciprocalCache) { + memcpy(code + superScalarHashOffset, codeShhInit, codeSshInitSize); + codePos = superScalarHashOffset + codeSshInitSize; + for (unsigned j = 0; j < N; ++j) { + SuperscalarProgram& prog = programs[j]; + for (unsigned i = 0; i < prog.getSize(); ++i) { + Instruction& instr = prog(i); + generateSuperscalarCode(instr, reciprocalCache); + } + emit(codeShhLoad, codeSshLoadSize); + if (j < N - 1) { + emit(REX_MOV_RR64); + emitByte(0xd8 + prog.getAddressRegister()); + emit(codeShhPrefetch, codeSshPrefetchSize); +#ifdef RANDOMX_ALIGN + int align = (codePos % 16); + while (align != 0) { + int nopSize = 16 - align; + if (nopSize > 8) nopSize = 8; + emit(NOPX[nopSize - 1], nopSize); + align = (codePos % 16); + } +#endif + } + } + emitByte(RET); + } + + template + void JitCompilerX86::generateSuperscalarHash(SuperscalarProgram(&programs)[RANDOMX_CACHE_ACCESSES], std::vector &reciprocalCache); + + void JitCompilerX86::generateDatasetInitCode() { + memcpy(code, codeDatasetInit, datasetInitSize); + } + + void JitCompilerX86::generateProgramPrologue(Program& prog, ProgramConfiguration& pcfg) { + instructionOffsets.clear(); + for (unsigned i = 0; i < RegistersCount; ++i) { + registerUsage[i] = -1; + } + + codePos = prologueSize; + memcpy(code + codePos - 48, &pcfg.eMask, sizeof(pcfg.eMask)); + memcpy(code + codePos, codeLoopLoad, loopLoadSize); + codePos += loopLoadSize; + for (unsigned i = 0; i < prog.getSize(); ++i) { + Instruction& instr = prog(i); + instr.src %= RegistersCount; + instr.dst %= RegistersCount; + generateCode(instr, i); + } + emit(REX_MOV_RR); + emitByte(0xc0 + pcfg.readReg2); + emit(REX_XOR_EAX); + emitByte(0xc0 + pcfg.readReg3); + } + + void JitCompilerX86::generateProgramEpilogue(Program& prog, ProgramConfiguration& pcfg) { + emit(REX_MOV_RR64); + emitByte(0xc0 + pcfg.readReg0); + emit(REX_XOR_RAX_R64); + emitByte(0xc0 + pcfg.readReg1); + emit(ADDR(randomx_prefetch_scratchpad), ADDR(randomx_prefetch_scratchpad_end) - ADDR(randomx_prefetch_scratchpad)); + memcpy(code + codePos, codeLoopStore, loopStoreSize); + codePos += loopStoreSize; + emit(SUB_EBX); + emit(JNZ); + emit32(prologueSize - codePos - 4); + emitByte(JMP); + emit32(epilogueOffset - codePos - 4); + } + + void JitCompilerX86::generateCode(Instruction& instr, int i) { + instructionOffsets.push_back(codePos); + auto generator = engine[instr.opcode]; + (this->*generator)(instr, i); + } + + void JitCompilerX86::generateSuperscalarCode(Instruction& instr, std::vector &reciprocalCache) { + switch ((SuperscalarInstructionType)instr.opcode) + { + case randomx::SuperscalarInstructionType::ISUB_R: + emit(REX_SUB_RR); + emitByte(0xc0 + 8 * instr.dst + instr.src); + break; + case randomx::SuperscalarInstructionType::IXOR_R: + emit(REX_XOR_RR); + emitByte(0xc0 + 8 * instr.dst + instr.src); + break; + case randomx::SuperscalarInstructionType::IADD_RS: + emit(REX_LEA); + emitByte(0x04 + 8 * instr.dst); + genSIB(instr.getModShift(), instr.src, instr.dst); + break; + case randomx::SuperscalarInstructionType::IMUL_R: + emit(REX_IMUL_RR); + emitByte(0xc0 + 8 * instr.dst + instr.src); + break; + case randomx::SuperscalarInstructionType::IROR_C: + emit(REX_ROT_I8); + emitByte(0xc8 + instr.dst); + emitByte(instr.getImm32() & 63); + break; + case randomx::SuperscalarInstructionType::IADD_C7: + emit(REX_81); + emitByte(0xc0 + instr.dst); + emit32(instr.getImm32()); + break; + case randomx::SuperscalarInstructionType::IXOR_C7: + emit(REX_XOR_RI); + emitByte(0xf0 + instr.dst); + emit32(instr.getImm32()); + break; + case randomx::SuperscalarInstructionType::IADD_C8: + emit(REX_81); + emitByte(0xc0 + instr.dst); + emit32(instr.getImm32()); +#ifdef RANDOMX_ALIGN + emit(NOP1); +#endif + break; + case randomx::SuperscalarInstructionType::IXOR_C8: + emit(REX_XOR_RI); + emitByte(0xf0 + instr.dst); + emit32(instr.getImm32()); +#ifdef RANDOMX_ALIGN + emit(NOP1); +#endif + break; + case randomx::SuperscalarInstructionType::IADD_C9: + emit(REX_81); + emitByte(0xc0 + instr.dst); + emit32(instr.getImm32()); +#ifdef RANDOMX_ALIGN + emit(NOP2); +#endif + break; + case randomx::SuperscalarInstructionType::IXOR_C9: + emit(REX_XOR_RI); + emitByte(0xf0 + instr.dst); + emit32(instr.getImm32()); +#ifdef RANDOMX_ALIGN + emit(NOP2); +#endif + break; + case randomx::SuperscalarInstructionType::IMULH_R: + emit(REX_MOV_RR64); + emitByte(0xc0 + instr.dst); + emit(REX_MUL_R); + emitByte(0xe0 + instr.src); + emit(REX_MOV_R64R); + emitByte(0xc2 + 8 * instr.dst); + break; + case randomx::SuperscalarInstructionType::ISMULH_R: + emit(REX_MOV_RR64); + emitByte(0xc0 + instr.dst); + emit(REX_MUL_R); + emitByte(0xe8 + instr.src); + emit(REX_MOV_R64R); + emitByte(0xc2 + 8 * instr.dst); + break; + case randomx::SuperscalarInstructionType::IMUL_RCP: + emit(MOV_RAX_I); + emit64(reciprocalCache[instr.getImm32()]); + emit(REX_IMUL_RM); + emitByte(0xc0 + 8 * instr.dst); + break; + default: + UNREACHABLE; + } + } + + void JitCompilerX86::genAddressReg(Instruction& instr, bool rax = true) { + emit(LEA_32); + emitByte(0x80 + instr.src + (rax ? 0 : 8)); + if (instr.src == RegisterNeedsSib) { + emitByte(0x24); + } + emit32(instr.getImm32()); + if (rax) + emitByte(AND_EAX_I); + else + emit(AND_ECX_I); + emit32(instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask); + } + + void JitCompilerX86::genAddressRegDst(Instruction& instr) { + emit(LEA_32); + emitByte(0x80 + instr.dst); + if (instr.dst == RegisterNeedsSib) { + emitByte(0x24); + } + emit32(instr.getImm32()); + emitByte(AND_EAX_I); + if (instr.getModCond() < StoreL3Condition) { + emit32(instr.getModMem() ? ScratchpadL1Mask : ScratchpadL2Mask); + } + else { + emit32(ScratchpadL3Mask); + } + } + + void JitCompilerX86::genAddressImm(Instruction& instr) { + emit32(instr.getImm32() & ScratchpadL3Mask); + } + + void JitCompilerX86::h_IADD_RS(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + emit(REX_LEA); + if (instr.dst == RegisterNeedsDisplacement) + emitByte(0xac); + else + emitByte(0x04 + 8 * instr.dst); + genSIB(instr.getModShift(), instr.src, instr.dst); + if (instr.dst == RegisterNeedsDisplacement) + emit32(instr.getImm32()); + } + + void JitCompilerX86::h_IADD_M(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + genAddressReg(instr); + emit(REX_ADD_RM); + emitByte(0x04 + 8 * instr.dst); + emitByte(0x06); + } + else { + emit(REX_ADD_RM); + emitByte(0x86 + 8 * instr.dst); + genAddressImm(instr); + } + } + + void JitCompilerX86::genSIB(int scale, int index, int base) { + emitByte((scale << 6) | (index << 3) | base); + } + + void JitCompilerX86::h_ISUB_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + emit(REX_SUB_RR); + emitByte(0xc0 + 8 * instr.dst + instr.src); + } + else { + emit(REX_81); + emitByte(0xe8 + instr.dst); + emit32(instr.getImm32()); + } + } + + void JitCompilerX86::h_ISUB_M(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + genAddressReg(instr); + emit(REX_SUB_RM); + emitByte(0x04 + 8 * instr.dst); + emitByte(0x06); + } + else { + emit(REX_SUB_RM); + emitByte(0x86 + 8 * instr.dst); + genAddressImm(instr); + } + } + + void JitCompilerX86::h_IMUL_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + emit(REX_IMUL_RR); + emitByte(0xc0 + 8 * instr.dst + instr.src); + } + else { + emit(REX_IMUL_RRI); + emitByte(0xc0 + 9 * instr.dst); + emit32(instr.getImm32()); + } + } + + void JitCompilerX86::h_IMUL_M(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + genAddressReg(instr); + emit(REX_IMUL_RM); + emitByte(0x04 + 8 * instr.dst); + emitByte(0x06); + } + else { + emit(REX_IMUL_RM); + emitByte(0x86 + 8 * instr.dst); + genAddressImm(instr); + } + } + + void JitCompilerX86::h_IMULH_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + emit(REX_MOV_RR64); + emitByte(0xc0 + instr.dst); + emit(REX_MUL_R); + emitByte(0xe0 + instr.src); + emit(REX_MOV_R64R); + emitByte(0xc2 + 8 * instr.dst); + } + + void JitCompilerX86::h_IMULH_M(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + genAddressReg(instr, false); + emit(REX_MOV_RR64); + emitByte(0xc0 + instr.dst); + emit(REX_MUL_MEM); + } + else { + emit(REX_MOV_RR64); + emitByte(0xc0 + instr.dst); + emit(REX_MUL_M); + emitByte(0xa6); + genAddressImm(instr); + } + emit(REX_MOV_R64R); + emitByte(0xc2 + 8 * instr.dst); + } + + void JitCompilerX86::h_ISMULH_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + emit(REX_MOV_RR64); + emitByte(0xc0 + instr.dst); + emit(REX_MUL_R); + emitByte(0xe8 + instr.src); + emit(REX_MOV_R64R); + emitByte(0xc2 + 8 * instr.dst); + } + + void JitCompilerX86::h_ISMULH_M(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + genAddressReg(instr, false); + emit(REX_MOV_RR64); + emitByte(0xc0 + instr.dst); + emit(REX_IMUL_MEM); + } + else { + emit(REX_MOV_RR64); + emitByte(0xc0 + instr.dst); + emit(REX_MUL_M); + emitByte(0xae); + genAddressImm(instr); + } + emit(REX_MOV_R64R); + emitByte(0xc2 + 8 * instr.dst); + } + + void JitCompilerX86::h_IMUL_RCP(Instruction& instr, int i) { + uint64_t divisor = instr.getImm32(); + if (!isZeroOrPowerOf2(divisor)) { + registerUsage[instr.dst] = i; + emit(MOV_RAX_I); + emit64(randomx_reciprocal_fast(divisor)); + emit(REX_IMUL_RM); + emitByte(0xc0 + 8 * instr.dst); + } + } + + void JitCompilerX86::h_INEG_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + emit(REX_NEG); + emitByte(0xd8 + instr.dst); + } + + void JitCompilerX86::h_IXOR_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + emit(REX_XOR_RR); + emitByte(0xc0 + 8 * instr.dst + instr.src); + } + else { + emit(REX_XOR_RI); + emitByte(0xf0 + instr.dst); + emit32(instr.getImm32()); + } + } + + void JitCompilerX86::h_IXOR_M(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + genAddressReg(instr); + emit(REX_XOR_RM); + emitByte(0x04 + 8 * instr.dst); + emitByte(0x06); + } + else { + emit(REX_XOR_RM); + emitByte(0x86 + 8 * instr.dst); + genAddressImm(instr); + } + } + + void JitCompilerX86::h_IROR_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + emit(REX_MOV_RR); + emitByte(0xc8 + instr.src); + emit(REX_ROT_CL); + emitByte(0xc8 + instr.dst); + } + else { + emit(REX_ROT_I8); + emitByte(0xc8 + instr.dst); + emitByte(instr.getImm32() & 63); + } + } + + void JitCompilerX86::h_IROL_R(Instruction& instr, int i) { + registerUsage[instr.dst] = i; + if (instr.src != instr.dst) { + emit(REX_MOV_RR); + emitByte(0xc8 + instr.src); + emit(REX_ROT_CL); + emitByte(0xc0 + instr.dst); + } + else { + emit(REX_ROT_I8); + emitByte(0xc0 + instr.dst); + emitByte(instr.getImm32() & 63); + } + } + + void JitCompilerX86::h_ISWAP_R(Instruction& instr, int i) { + if (instr.src != instr.dst) { + registerUsage[instr.dst] = i; + registerUsage[instr.src] = i; + emit(REX_XCHG); + emitByte(0xc0 + instr.src + 8 * instr.dst); + } + } + + void JitCompilerX86::h_FSWAP_R(Instruction& instr, int i) { + emit(SHUFPD); + emitByte(0xc0 + 9 * instr.dst); + emitByte(1); + } + + void JitCompilerX86::h_FADD_R(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + instr.src %= RegisterCountFlt; + emit(REX_ADDPD); + emitByte(0xc0 + instr.src + 8 * instr.dst); + } + + void JitCompilerX86::h_FADD_M(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + genAddressReg(instr); + emit(REX_CVTDQ2PD_XMM12); + emit(REX_ADDPD); + emitByte(0xc4 + 8 * instr.dst); + } + + void JitCompilerX86::h_FSUB_R(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + instr.src %= RegisterCountFlt; + emit(REX_SUBPD); + emitByte(0xc0 + instr.src + 8 * instr.dst); + } + + void JitCompilerX86::h_FSUB_M(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + genAddressReg(instr); + emit(REX_CVTDQ2PD_XMM12); + emit(REX_SUBPD); + emitByte(0xc4 + 8 * instr.dst); + } + + void JitCompilerX86::h_FSCAL_R(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + emit(REX_XORPS); + emitByte(0xc7 + 8 * instr.dst); + } + + void JitCompilerX86::h_FMUL_R(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + instr.src %= RegisterCountFlt; + emit(REX_MULPD); + emitByte(0xe0 + instr.src + 8 * instr.dst); + } + + void JitCompilerX86::h_FDIV_M(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + genAddressReg(instr); + emit(REX_CVTDQ2PD_XMM12); + emit(REX_ANDPS_XMM12); + emit(REX_DIVPD); + emitByte(0xe4 + 8 * instr.dst); + } + + void JitCompilerX86::h_FSQRT_R(Instruction& instr, int i) { + instr.dst %= RegisterCountFlt; + emit(SQRTPD); + emitByte(0xe4 + 9 * instr.dst); + } + + void JitCompilerX86::h_CFROUND(Instruction& instr, int i) { + emit(REX_MOV_RR64); + emitByte(0xc0 + instr.src); + int rotate = (13 - (instr.getImm32() & 63)) & 63; + if (rotate != 0) { + emit(ROL_RAX); + emitByte(rotate); + } + emit(AND_OR_MOV_LDMXCSR); + } + + void JitCompilerX86::h_CBRANCH(Instruction& instr, int i) { + int reg = instr.dst; + int target = registerUsage[reg] + 1; + emit(REX_ADD_I); + emitByte(0xc0 + reg); + int shift = instr.getModCond() + ConditionOffset; + uint32_t imm = instr.getImm32() | (1UL << shift); + if (ConditionOffset > 0 || shift > 0) + imm &= ~(1UL << (shift - 1)); + emit32(imm); + emit(REX_TEST); + emitByte(0xc0 + reg); + emit32(ConditionMask << shift); + emit(JZ); + emit32(instructionOffsets[target] - (codePos + 4)); + //mark all registers as used + for (unsigned j = 0; j < RegistersCount; ++j) { + registerUsage[j] = i; + } + } + + void JitCompilerX86::h_ISTORE(Instruction& instr, int i) { + genAddressRegDst(instr); + emit(REX_MOV_MR); + emitByte(0x04 + 8 * instr.src); + emitByte(0x06); + } + + void JitCompilerX86::h_NOP(Instruction& instr, int i) { + emit(NOP1); + } + +#include "instruction_weights.hpp" +#define INST_HANDLE(x) REPN(&JitCompilerX86::h_##x, WT(x)) + + InstructionGeneratorX86 JitCompilerX86::engine[256] = { + INST_HANDLE(IADD_RS) + INST_HANDLE(IADD_M) + INST_HANDLE(ISUB_R) + INST_HANDLE(ISUB_M) + INST_HANDLE(IMUL_R) + INST_HANDLE(IMUL_M) + INST_HANDLE(IMULH_R) + INST_HANDLE(IMULH_M) + INST_HANDLE(ISMULH_R) + INST_HANDLE(ISMULH_M) + INST_HANDLE(IMUL_RCP) + INST_HANDLE(INEG_R) + INST_HANDLE(IXOR_R) + INST_HANDLE(IXOR_M) + INST_HANDLE(IROR_R) + INST_HANDLE(IROL_R) + INST_HANDLE(ISWAP_R) + INST_HANDLE(FSWAP_R) + INST_HANDLE(FADD_R) + INST_HANDLE(FADD_M) + INST_HANDLE(FSUB_R) + INST_HANDLE(FSUB_M) + INST_HANDLE(FSCAL_R) + INST_HANDLE(FMUL_R) + INST_HANDLE(FDIV_M) + INST_HANDLE(FSQRT_R) + INST_HANDLE(CBRANCH) + INST_HANDLE(CFROUND) + INST_HANDLE(ISTORE) + INST_HANDLE(NOP) + }; + +} diff --git a/src/RandomX/src/jit_compiler_x86.hpp b/src/RandomX/src/jit_compiler_x86.hpp new file mode 100644 index 000000000..e95685f9c --- /dev/null +++ b/src/RandomX/src/jit_compiler_x86.hpp @@ -0,0 +1,142 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include +#include +#include "common.hpp" + +namespace randomx { + + class Program; + struct ProgramConfiguration; + class SuperscalarProgram; + class JitCompilerX86; + class Instruction; + + typedef void(JitCompilerX86::*InstructionGeneratorX86)(Instruction&, int); + + class JitCompilerX86 { + public: + JitCompilerX86(); + ~JitCompilerX86(); + void generateProgram(Program&, ProgramConfiguration&); + void generateProgramLight(Program&, ProgramConfiguration&, uint32_t); + template + void generateSuperscalarHash(SuperscalarProgram (&programs)[N], std::vector &); + void generateDatasetInitCode(); + ProgramFunc* getProgramFunc() { + return (ProgramFunc*)code; + } + DatasetInitFunc* getDatasetInitFunc() { + return (DatasetInitFunc*)code; + } + uint8_t* getCode() { + return code; + } + size_t getCodeSize(); + void enableWriting(); + void enableExecution(); + void enableAll(); + private: + static InstructionGeneratorX86 engine[256]; + std::vector instructionOffsets; + int registerUsage[RegistersCount]; + uint8_t* code; + int32_t codePos; + + void generateProgramPrologue(Program&, ProgramConfiguration&); + void generateProgramEpilogue(Program&, ProgramConfiguration&); + void genAddressReg(Instruction&, bool); + void genAddressRegDst(Instruction&); + void genAddressImm(Instruction&); + void genSIB(int scale, int index, int base); + + void generateCode(Instruction&, int); + void generateSuperscalarCode(Instruction &, std::vector &); + + void emitByte(uint8_t val) { + code[codePos] = val; + codePos++; + } + + void emit32(uint32_t val) { + memcpy(code + codePos, &val, sizeof val); + codePos += sizeof val; + } + + void emit64(uint64_t val) { + memcpy(code + codePos, &val, sizeof val); + codePos += sizeof val; + } + + template + void emit(const uint8_t (&src)[N]) { + emit(src, N); + } + + void emit(const uint8_t* src, size_t count) { + memcpy(code + codePos, src, count); + codePos += count; + } + + void h_IADD_RS(Instruction&, int); + void h_IADD_M(Instruction&, int); + void h_ISUB_R(Instruction&, int); + void h_ISUB_M(Instruction&, int); + void h_IMUL_R(Instruction&, int); + void h_IMUL_M(Instruction&, int); + void h_IMULH_R(Instruction&, int); + void h_IMULH_M(Instruction&, int); + void h_ISMULH_R(Instruction&, int); + void h_ISMULH_M(Instruction&, int); + void h_IMUL_RCP(Instruction&, int); + void h_INEG_R(Instruction&, int); + void h_IXOR_R(Instruction&, int); + void h_IXOR_M(Instruction&, int); + void h_IROR_R(Instruction&, int); + void h_IROL_R(Instruction&, int); + void h_ISWAP_R(Instruction&, int); + void h_FSWAP_R(Instruction&, int); + void h_FADD_R(Instruction&, int); + void h_FADD_M(Instruction&, int); + void h_FSUB_R(Instruction&, int); + void h_FSUB_M(Instruction&, int); + void h_FSCAL_R(Instruction&, int); + void h_FMUL_R(Instruction&, int); + void h_FDIV_M(Instruction&, int); + void h_FSQRT_R(Instruction&, int); + void h_CBRANCH(Instruction&, int); + void h_CFROUND(Instruction&, int); + void h_ISTORE(Instruction&, int); + void h_NOP(Instruction&, int); + }; + +} \ No newline at end of file diff --git a/src/RandomX/src/jit_compiler_x86_static.S b/src/RandomX/src/jit_compiler_x86_static.S new file mode 100644 index 000000000..9193b21a1 --- /dev/null +++ b/src/RandomX/src/jit_compiler_x86_static.S @@ -0,0 +1,230 @@ +# Copyright (c) 2018-2019, tevador +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# * Neither the name of the copyright holder nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +.intel_syntax noprefix +#if defined(__APPLE__) +.text +#define DECL(x) _##x +#else +.section .text +#define DECL(x) x +#endif + +#if defined(__WIN32__) || defined(__CYGWIN__) +#define WINABI +#endif + +.global DECL(randomx_prefetch_scratchpad) +.global DECL(randomx_prefetch_scratchpad_end) +.global DECL(randomx_program_prologue) +.global DECL(randomx_program_loop_begin) +.global DECL(randomx_program_loop_load) +.global DECL(randomx_program_start) +.global DECL(randomx_program_read_dataset) +.global DECL(randomx_program_read_dataset_sshash_init) +.global DECL(randomx_program_read_dataset_sshash_fin) +.global DECL(randomx_program_loop_store) +.global DECL(randomx_program_loop_end) +.global DECL(randomx_dataset_init) +.global DECL(randomx_program_epilogue) +.global DECL(randomx_sshash_load) +.global DECL(randomx_sshash_prefetch) +.global DECL(randomx_sshash_end) +.global DECL(randomx_sshash_init) +.global DECL(randomx_program_end) +.global DECL(randomx_reciprocal_fast) + +#include "configuration.h" + +#define RANDOMX_SCRATCHPAD_MASK (RANDOMX_SCRATCHPAD_L3-64) +#define RANDOMX_DATASET_BASE_MASK (RANDOMX_DATASET_BASE_SIZE-64) +#define RANDOMX_CACHE_MASK (RANDOMX_ARGON_MEMORY*16-1) +#define RANDOMX_ALIGN 4096 +#define SUPERSCALAR_OFFSET ((((RANDOMX_ALIGN + 32 * RANDOMX_PROGRAM_SIZE) - 1) / (RANDOMX_ALIGN) + 1) * (RANDOMX_ALIGN)) + +#define db .byte + +DECL(randomx_prefetch_scratchpad): + mov rdx, rax + and eax, RANDOMX_SCRATCHPAD_MASK + prefetcht0 [rsi+rax] + ror rdx, 32 + and edx, RANDOMX_SCRATCHPAD_MASK + prefetcht0 [rsi+rdx] + +DECL(randomx_prefetch_scratchpad_end): + +.balign 64 +DECL(randomx_program_prologue): +#if defined(WINABI) + #include "asm/program_prologue_win64.inc" +#else + #include "asm/program_prologue_linux.inc" +#endif + movapd xmm13, xmmword ptr [mantissaMask+rip] + movapd xmm14, xmmword ptr [exp240+rip] + movapd xmm15, xmmword ptr [scaleMask+rip] + mov rdx, rax + and eax, RANDOMX_SCRATCHPAD_MASK + ror rdx, 32 + and edx, RANDOMX_SCRATCHPAD_MASK + jmp rx_program_loop_begin + +.balign 64 + #include "asm/program_xmm_constants.inc" + +.balign 64 +DECL(randomx_program_loop_begin): +rx_program_loop_begin: + nop + +DECL(randomx_program_loop_load): + #include "asm/program_loop_load.inc" + +DECL(randomx_program_start): + nop + +DECL(randomx_program_read_dataset): + #include "asm/program_read_dataset.inc" + +DECL(randomx_program_read_dataset_sshash_init): + #include "asm/program_read_dataset_sshash_init.inc" + +DECL(randomx_program_read_dataset_sshash_fin): + #include "asm/program_read_dataset_sshash_fin.inc" + +DECL(randomx_program_loop_store): + #include "asm/program_loop_store.inc" + +DECL(randomx_program_loop_end): + nop + +.balign 64 +DECL(randomx_dataset_init): +rx_dataset_init: + push rbx + push rbp + push r12 + push r13 + push r14 + push r15 +#if defined(WINABI) + push rdi + push rsi + mov rdi, qword ptr [rcx] ;# cache->memory + mov rsi, rdx ;# dataset + mov rbp, r8 ;# block index + push r9 ;# max. block index +#else + mov rdi, qword ptr [rdi] ;# cache->memory + ;# dataset in rsi + mov rbp, rdx ;# block index + push rcx ;# max. block index +#endif +init_block_loop: + prefetchw byte ptr [rsi] + mov rbx, rbp + .byte 232 ;# 0xE8 = call + .int SUPERSCALAR_OFFSET - (call_offset - rx_dataset_init) +call_offset: + mov qword ptr [rsi+0], r8 + mov qword ptr [rsi+8], r9 + mov qword ptr [rsi+16], r10 + mov qword ptr [rsi+24], r11 + mov qword ptr [rsi+32], r12 + mov qword ptr [rsi+40], r13 + mov qword ptr [rsi+48], r14 + mov qword ptr [rsi+56], r15 + add rbp, 1 + add rsi, 64 + cmp rbp, qword ptr [rsp] + jb init_block_loop + pop rax +#if defined(WINABI) + pop rsi + pop rdi +#endif + pop r15 + pop r14 + pop r13 + pop r12 + pop rbp + pop rbx + ret + +.balign 64 +DECL(randomx_program_epilogue): + #include "asm/program_epilogue_store.inc" +#if defined(WINABI) + #include "asm/program_epilogue_win64.inc" +#else + #include "asm/program_epilogue_linux.inc" +#endif + +.balign 64 +DECL(randomx_sshash_load): + #include "asm/program_sshash_load.inc" + +DECL(randomx_sshash_prefetch): + #include "asm/program_sshash_prefetch.inc" + +DECL(randomx_sshash_end): + nop + +.balign 64 +DECL(randomx_sshash_init): + lea r8, [rbx+1] + #include "asm/program_sshash_prefetch.inc" + imul r8, qword ptr [r0_mul+rip] + mov r9, qword ptr [r1_add+rip] + xor r9, r8 + mov r10, qword ptr [r2_add+rip] + xor r10, r8 + mov r11, qword ptr [r3_add+rip] + xor r11, r8 + mov r12, qword ptr [r4_add+rip] + xor r12, r8 + mov r13, qword ptr [r5_add+rip] + xor r13, r8 + mov r14, qword ptr [r6_add+rip] + xor r14, r8 + mov r15, qword ptr [r7_add+rip] + xor r15, r8 + jmp rx_program_end + +.balign 64 + #include "asm/program_sshash_constants.inc" + +.balign 64 +DECL(randomx_program_end): +rx_program_end: + nop + +DECL(randomx_reciprocal_fast): +#if !defined(WINABI) + mov rcx, rdi +#endif + #include "asm/randomx_reciprocal.inc" diff --git a/src/RandomX/src/jit_compiler_x86_static.asm b/src/RandomX/src/jit_compiler_x86_static.asm new file mode 100644 index 000000000..a37c716cc --- /dev/null +++ b/src/RandomX/src/jit_compiler_x86_static.asm @@ -0,0 +1,223 @@ +; Copyright (c) 2018-2019, tevador +; +; All rights reserved. +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions are met: +; * Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; * Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the distribution. +; * Neither the name of the copyright holder nor the +; names of its contributors may be used to endorse or promote products +; derived from this software without specific prior written permission. +; +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +; DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +; FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +; CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +; OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +IFDEF RAX + +_RANDOMX_JITX86_STATIC SEGMENT PAGE READ EXECUTE + +PUBLIC randomx_prefetch_scratchpad +PUBLIC randomx_prefetch_scratchpad_end +PUBLIC randomx_program_prologue +PUBLIC randomx_program_loop_begin +PUBLIC randomx_program_loop_load +PUBLIC randomx_program_start +PUBLIC randomx_program_read_dataset +PUBLIC randomx_program_read_dataset_sshash_init +PUBLIC randomx_program_read_dataset_sshash_fin +PUBLIC randomx_dataset_init +PUBLIC randomx_program_loop_store +PUBLIC randomx_program_loop_end +PUBLIC randomx_program_epilogue +PUBLIC randomx_sshash_load +PUBLIC randomx_sshash_prefetch +PUBLIC randomx_sshash_end +PUBLIC randomx_sshash_init +PUBLIC randomx_program_end +PUBLIC randomx_reciprocal_fast + +include asm/configuration.asm + +RANDOMX_SCRATCHPAD_MASK EQU (RANDOMX_SCRATCHPAD_L3-64) +RANDOMX_DATASET_BASE_MASK EQU (RANDOMX_DATASET_BASE_SIZE-64) +RANDOMX_CACHE_MASK EQU (RANDOMX_ARGON_MEMORY*16-1) +RANDOMX_ALIGN EQU 4096 +SUPERSCALAR_OFFSET EQU ((((RANDOMX_ALIGN + 32 * RANDOMX_PROGRAM_SIZE) - 1) / (RANDOMX_ALIGN) + 1) * (RANDOMX_ALIGN)) + +randomx_prefetch_scratchpad PROC + mov rdx, rax + and eax, RANDOMX_SCRATCHPAD_MASK + prefetcht0 [rsi+rax] + ror rdx, 32 + and edx, RANDOMX_SCRATCHPAD_MASK + prefetcht0 [rsi+rdx] +randomx_prefetch_scratchpad ENDP + +randomx_prefetch_scratchpad_end PROC +randomx_prefetch_scratchpad_end ENDP + +ALIGN 64 +randomx_program_prologue PROC + include asm/program_prologue_win64.inc + movapd xmm13, xmmword ptr [mantissaMask] + movapd xmm14, xmmword ptr [exp240] + movapd xmm15, xmmword ptr [scaleMask] + mov rdx, rax + and eax, RANDOMX_SCRATCHPAD_MASK + ror rdx, 32 + and edx, RANDOMX_SCRATCHPAD_MASK + jmp rx_program_loop_begin +randomx_program_prologue ENDP + +ALIGN 64 + include asm/program_xmm_constants.inc + +ALIGN 64 +randomx_program_loop_begin PROC +rx_program_loop_begin:: + nop +randomx_program_loop_begin ENDP + +randomx_program_loop_load PROC + include asm/program_loop_load.inc +randomx_program_loop_load ENDP + +randomx_program_start PROC + nop +randomx_program_start ENDP + +randomx_program_read_dataset PROC + include asm/program_read_dataset.inc +randomx_program_read_dataset ENDP + +randomx_program_read_dataset_sshash_init PROC + include asm/program_read_dataset_sshash_init.inc +randomx_program_read_dataset_sshash_init ENDP + +randomx_program_read_dataset_sshash_fin PROC + include asm/program_read_dataset_sshash_fin.inc +randomx_program_read_dataset_sshash_fin ENDP + +randomx_program_loop_store PROC + include asm/program_loop_store.inc +randomx_program_loop_store ENDP + +randomx_program_loop_end PROC + nop +randomx_program_loop_end ENDP + +ALIGN 64 +randomx_dataset_init PROC + push rbx + push rbp + push rdi + push rsi + push r12 + push r13 + push r14 + push r15 + mov rdi, qword ptr [rcx] ;# cache->memory + mov rsi, rdx ;# dataset + mov rbp, r8 ;# block index + push r9 ;# max. block index +init_block_loop: + prefetchw byte ptr [rsi] + mov rbx, rbp + db 232 ;# 0xE8 = call + dd SUPERSCALAR_OFFSET - distance + distance equ $ - offset randomx_dataset_init + mov qword ptr [rsi+0], r8 + mov qword ptr [rsi+8], r9 + mov qword ptr [rsi+16], r10 + mov qword ptr [rsi+24], r11 + mov qword ptr [rsi+32], r12 + mov qword ptr [rsi+40], r13 + mov qword ptr [rsi+48], r14 + mov qword ptr [rsi+56], r15 + add rbp, 1 + add rsi, 64 + cmp rbp, qword ptr [rsp] + jb init_block_loop + pop r9 + pop r15 + pop r14 + pop r13 + pop r12 + pop rsi + pop rdi + pop rbp + pop rbx + ret +randomx_dataset_init ENDP + +ALIGN 64 +randomx_program_epilogue PROC + include asm/program_epilogue_store.inc + include asm/program_epilogue_win64.inc +randomx_program_epilogue ENDP + +ALIGN 64 +randomx_sshash_load PROC + include asm/program_sshash_load.inc +randomx_sshash_load ENDP + +randomx_sshash_prefetch PROC + include asm/program_sshash_prefetch.inc +randomx_sshash_prefetch ENDP + +randomx_sshash_end PROC + nop +randomx_sshash_end ENDP + +ALIGN 64 +randomx_sshash_init PROC + lea r8, [rbx+1] + include asm/program_sshash_prefetch.inc + imul r8, qword ptr [r0_mul] + mov r9, qword ptr [r1_add] + xor r9, r8 + mov r10, qword ptr [r2_add] + xor r10, r8 + mov r11, qword ptr [r3_add] + xor r11, r8 + mov r12, qword ptr [r4_add] + xor r12, r8 + mov r13, qword ptr [r5_add] + xor r13, r8 + mov r14, qword ptr [r6_add] + xor r14, r8 + mov r15, qword ptr [r7_add] + xor r15, r8 + jmp rx_program_end +randomx_sshash_init ENDP + +ALIGN 64 + include asm/program_sshash_constants.inc + +ALIGN 64 +randomx_program_end PROC +rx_program_end:: + nop +randomx_program_end ENDP + +randomx_reciprocal_fast PROC + include asm/randomx_reciprocal.inc +randomx_reciprocal_fast ENDP + +_RANDOMX_JITX86_STATIC ENDS + +ENDIF + +END diff --git a/src/RandomX/src/jit_compiler_x86_static.hpp b/src/RandomX/src/jit_compiler_x86_static.hpp new file mode 100644 index 000000000..fe32a8b78 --- /dev/null +++ b/src/RandomX/src/jit_compiler_x86_static.hpp @@ -0,0 +1,50 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +extern "C" { + void randomx_prefetch_scratchpad(); + void randomx_prefetch_scratchpad_end(); + void randomx_program_prologue(); + void randomx_program_loop_begin(); + void randomx_program_loop_load(); + void randomx_program_start(); + void randomx_program_read_dataset(); + void randomx_program_read_dataset_sshash_init(); + void randomx_program_read_dataset_sshash_fin(); + void randomx_program_loop_store(); + void randomx_program_loop_end(); + void randomx_dataset_init(); + void randomx_program_epilogue(); + void randomx_sshash_load(); + void randomx_sshash_prefetch(); + void randomx_sshash_end(); + void randomx_sshash_init(); + void randomx_program_end(); +} diff --git a/src/RandomX/src/program.hpp b/src/RandomX/src/program.hpp new file mode 100644 index 000000000..d0f680523 --- /dev/null +++ b/src/RandomX/src/program.hpp @@ -0,0 +1,71 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include +#include "common.hpp" +#include "instruction.hpp" +#include "blake2/endian.h" + +namespace randomx { + + struct ProgramConfiguration { + uint64_t eMask[2]; + uint32_t readReg0, readReg1, readReg2, readReg3; + }; + + class Program { + public: + Instruction& operator()(int pc) { + return programBuffer[pc]; + } + friend std::ostream& operator<<(std::ostream& os, const Program& p) { + p.print(os); + return os; + } + uint64_t getEntropy(int i) { + return load64(&entropyBuffer[i]); + } + uint32_t getSize() { + return RANDOMX_PROGRAM_SIZE; + } + private: + void print(std::ostream& os) const { + for (int i = 0; i < RANDOMX_PROGRAM_SIZE; ++i) { + auto instr = programBuffer[i]; + os << instr; + } + } + uint64_t entropyBuffer[16]; + Instruction programBuffer[RANDOMX_PROGRAM_SIZE]; + }; + + static_assert(sizeof(Program) % 64 == 0, "Invalid size of class randomx::Program"); +} diff --git a/src/RandomX/src/randomx.cpp b/src/RandomX/src/randomx.cpp new file mode 100644 index 000000000..7d239f6fa --- /dev/null +++ b/src/RandomX/src/randomx.cpp @@ -0,0 +1,397 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "randomx.h" +#include "dataset.hpp" +#include "vm_interpreted.hpp" +#include "vm_interpreted_light.hpp" +#include "vm_compiled.hpp" +#include "vm_compiled_light.hpp" +#include "blake2/blake2.h" +#include "cpu.hpp" +#include +#include +#include + +extern "C" { + + randomx_flags randomx_get_flags() { + randomx_flags flags = RANDOMX_HAVE_COMPILER ? RANDOMX_FLAG_JIT : RANDOMX_FLAG_DEFAULT; + randomx::Cpu cpu; +#ifdef RANDOMX_FORCE_SECURE + if (flags == RANDOMX_FLAG_JIT) { + flags |= RANDOMX_FLAG_SECURE; + } +#endif + if (HAVE_AES && cpu.hasAes()) { + flags |= RANDOMX_FLAG_HARD_AES; + } + if (randomx_argon2_impl_avx2() != nullptr && cpu.hasAvx2()) { + flags |= RANDOMX_FLAG_ARGON2_AVX2; + } + if (randomx_argon2_impl_ssse3() != nullptr && cpu.hasSsse3()) { + flags |= RANDOMX_FLAG_ARGON2_SSSE3; + } + return flags; + } + + randomx_cache *randomx_alloc_cache(randomx_flags flags) { + randomx_cache *cache = nullptr; + auto impl = randomx::selectArgonImpl(flags); + if (impl == nullptr) { + return cache; + } + + try { + cache = new randomx_cache(); + cache->argonImpl = impl; + switch ((int)(flags & (RANDOMX_FLAG_JIT | RANDOMX_FLAG_LARGE_PAGES))) { + case RANDOMX_FLAG_DEFAULT: + cache->dealloc = &randomx::deallocCache; + cache->jit = nullptr; + cache->initialize = &randomx::initCache; + cache->datasetInit = &randomx::initDataset; + cache->memory = (uint8_t*)randomx::DefaultAllocator::allocMemory(randomx::CacheSize); + break; + + case RANDOMX_FLAG_JIT: + cache->dealloc = &randomx::deallocCache; + cache->jit = new randomx::JitCompiler(); + cache->initialize = &randomx::initCacheCompile; + cache->datasetInit = cache->jit->getDatasetInitFunc(); + cache->memory = (uint8_t*)randomx::DefaultAllocator::allocMemory(randomx::CacheSize); + break; + + case RANDOMX_FLAG_LARGE_PAGES: + cache->dealloc = &randomx::deallocCache; + cache->jit = nullptr; + cache->initialize = &randomx::initCache; + cache->datasetInit = &randomx::initDataset; + cache->memory = (uint8_t*)randomx::LargePageAllocator::allocMemory(randomx::CacheSize); + break; + + case RANDOMX_FLAG_JIT | RANDOMX_FLAG_LARGE_PAGES: + cache->dealloc = &randomx::deallocCache; + cache->jit = new randomx::JitCompiler(); + cache->initialize = &randomx::initCacheCompile; + cache->datasetInit = cache->jit->getDatasetInitFunc(); + cache->memory = (uint8_t*)randomx::LargePageAllocator::allocMemory(randomx::CacheSize); + break; + + default: + UNREACHABLE; + } + } + catch (std::exception &ex) { + if (cache != nullptr) { + randomx_release_cache(cache); + cache = nullptr; + } + } + + return cache; + } + + void randomx_init_cache(randomx_cache *cache, const void *key, size_t keySize) { + assert(cache != nullptr); + assert(keySize == 0 || key != nullptr); + std::string cacheKey; + cacheKey.assign((const char *)key, keySize); + if (cache->cacheKey != cacheKey || !cache->isInitialized()) { + cache->initialize(cache, key, keySize); + cache->cacheKey = cacheKey; + } + } + + void randomx_release_cache(randomx_cache* cache) { + assert(cache != nullptr); + if (cache->memory != nullptr) { + cache->dealloc(cache); + } + delete cache; + } + + randomx_dataset *randomx_alloc_dataset(randomx_flags flags) { + + //fail on 32-bit systems if DatasetSize is >= 4 GiB + if (randomx::DatasetSize > std::numeric_limits::max()) { + return nullptr; + } + + randomx_dataset *dataset = nullptr; + + try { + dataset = new randomx_dataset(); + if (flags & RANDOMX_FLAG_LARGE_PAGES) { + dataset->dealloc = &randomx::deallocDataset; + dataset->memory = (uint8_t*)randomx::LargePageAllocator::allocMemory(randomx::DatasetSize); + } + else { + dataset->dealloc = &randomx::deallocDataset; + dataset->memory = (uint8_t*)randomx::DefaultAllocator::allocMemory(randomx::DatasetSize); + } + } + catch (std::exception &ex) { + if (dataset != nullptr) { + randomx_release_dataset(dataset); + dataset = nullptr; + } + } + + return dataset; + } + + constexpr unsigned long DatasetItemCount = randomx::DatasetSize / RANDOMX_DATASET_ITEM_SIZE; + + unsigned long randomx_dataset_item_count() { + return DatasetItemCount; + } + + void randomx_init_dataset(randomx_dataset *dataset, randomx_cache *cache, unsigned long startItem, unsigned long itemCount) { + assert(dataset != nullptr); + assert(cache != nullptr); + assert(startItem < DatasetItemCount && itemCount <= DatasetItemCount); + assert(startItem + itemCount <= DatasetItemCount); + cache->datasetInit(cache, dataset->memory + startItem * randomx::CacheLineSize, startItem, startItem + itemCount); + } + + void *randomx_get_dataset_memory(randomx_dataset *dataset) { + assert(dataset != nullptr); + return dataset->memory; + } + + void randomx_release_dataset(randomx_dataset *dataset) { + assert(dataset != nullptr); + dataset->dealloc(dataset); + delete dataset; + } + + randomx_vm *randomx_create_vm(randomx_flags flags, randomx_cache *cache, randomx_dataset *dataset) { + assert(cache != nullptr || (flags & RANDOMX_FLAG_FULL_MEM)); + assert(cache == nullptr || cache->isInitialized()); + assert(dataset != nullptr || !(flags & RANDOMX_FLAG_FULL_MEM)); + + randomx_vm *vm = nullptr; + + try { + switch ((int)(flags & (RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT | RANDOMX_FLAG_HARD_AES | RANDOMX_FLAG_LARGE_PAGES))) { + case RANDOMX_FLAG_DEFAULT: + vm = new randomx::InterpretedLightVmDefault(); + break; + + case RANDOMX_FLAG_FULL_MEM: + vm = new randomx::InterpretedVmDefault(); + break; + + case RANDOMX_FLAG_JIT: + if (flags & RANDOMX_FLAG_SECURE) { + vm = new randomx::CompiledLightVmDefaultSecure(); + } + else { + vm = new randomx::CompiledLightVmDefault(); + } + break; + + case RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT: + if (flags & RANDOMX_FLAG_SECURE) { + vm = new randomx::CompiledVmDefaultSecure(); + } + else { + vm = new randomx::CompiledVmDefault(); + } + break; + + case RANDOMX_FLAG_HARD_AES: + vm = new randomx::InterpretedLightVmHardAes(); + break; + + case RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_HARD_AES: + vm = new randomx::InterpretedVmHardAes(); + break; + + case RANDOMX_FLAG_JIT | RANDOMX_FLAG_HARD_AES: + if (flags & RANDOMX_FLAG_SECURE) { + vm = new randomx::CompiledLightVmHardAesSecure(); + } + else { + vm = new randomx::CompiledLightVmHardAes(); + } + break; + + case RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT | RANDOMX_FLAG_HARD_AES: + if (flags & RANDOMX_FLAG_SECURE) { + vm = new randomx::CompiledVmHardAesSecure(); + } + else { + vm = new randomx::CompiledVmHardAes(); + } + break; + + case RANDOMX_FLAG_LARGE_PAGES: + vm = new randomx::InterpretedLightVmLargePage(); + break; + + case RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_LARGE_PAGES: + vm = new randomx::InterpretedVmLargePage(); + break; + + case RANDOMX_FLAG_JIT | RANDOMX_FLAG_LARGE_PAGES: + if (flags & RANDOMX_FLAG_SECURE) { + vm = new randomx::CompiledLightVmLargePageSecure(); + } + else { + vm = new randomx::CompiledLightVmLargePage(); + } + break; + + case RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT | RANDOMX_FLAG_LARGE_PAGES: + if (flags & RANDOMX_FLAG_SECURE) { + vm = new randomx::CompiledVmLargePageSecure(); + } + else { + vm = new randomx::CompiledVmLargePage(); + } + break; + + case RANDOMX_FLAG_HARD_AES | RANDOMX_FLAG_LARGE_PAGES: + vm = new randomx::InterpretedLightVmLargePageHardAes(); + break; + + case RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_HARD_AES | RANDOMX_FLAG_LARGE_PAGES: + vm = new randomx::InterpretedVmLargePageHardAes(); + break; + + case RANDOMX_FLAG_JIT | RANDOMX_FLAG_HARD_AES | RANDOMX_FLAG_LARGE_PAGES: + if (flags & RANDOMX_FLAG_SECURE) { + vm = new randomx::CompiledLightVmLargePageHardAesSecure(); + } + else { + vm = new randomx::CompiledLightVmLargePageHardAes(); + } + break; + + case RANDOMX_FLAG_FULL_MEM | RANDOMX_FLAG_JIT | RANDOMX_FLAG_HARD_AES | RANDOMX_FLAG_LARGE_PAGES: + if (flags & RANDOMX_FLAG_SECURE) { + vm = new randomx::CompiledVmLargePageHardAesSecure(); + } + else { + vm = new randomx::CompiledVmLargePageHardAes(); + } + break; + + default: + UNREACHABLE; + } + + if(cache != nullptr) { + vm->setCache(cache); + vm->cacheKey = cache->cacheKey; + } + + if(dataset != nullptr) + vm->setDataset(dataset); + + vm->allocate(); + } + catch (std::exception &ex) { + delete vm; + vm = nullptr; + } + + return vm; + } + + void randomx_vm_set_cache(randomx_vm *machine, randomx_cache* cache) { + assert(machine != nullptr); + assert(cache != nullptr && cache->isInitialized()); + if (machine->cacheKey != cache->cacheKey || machine->getMemory() != cache->memory) { + machine->setCache(cache); + machine->cacheKey = cache->cacheKey; + } + } + + void randomx_vm_set_dataset(randomx_vm *machine, randomx_dataset *dataset) { + assert(machine != nullptr); + assert(dataset != nullptr); + machine->setDataset(dataset); + } + + void randomx_destroy_vm(randomx_vm *machine) { + assert(machine != nullptr); + delete machine; + } + + void randomx_calculate_hash(randomx_vm *machine, const void *input, size_t inputSize, void *output) { + assert(machine != nullptr); + assert(inputSize == 0 || input != nullptr); + assert(output != nullptr); + fenv_t fpstate; + fegetenv(&fpstate); + alignas(16) uint64_t tempHash[8]; + int blakeResult = blake2b(tempHash, sizeof(tempHash), input, inputSize, nullptr, 0); + assert(blakeResult == 0); + machine->initScratchpad(&tempHash); + machine->resetRoundingMode(); + for (int chain = 0; chain < RANDOMX_PROGRAM_COUNT - 1; ++chain) { + machine->run(&tempHash); + blakeResult = blake2b(tempHash, sizeof(tempHash), machine->getRegisterFile(), sizeof(randomx::RegisterFile), nullptr, 0); + assert(blakeResult == 0); + } + machine->run(&tempHash); + machine->getFinalResult(output, RANDOMX_HASH_SIZE); + fesetenv(&fpstate); + } + + void randomx_calculate_hash_first(randomx_vm* machine, const void* input, size_t inputSize) { + blake2b(machine->tempHash, sizeof(machine->tempHash), input, inputSize, nullptr, 0); + machine->initScratchpad(machine->tempHash); + } + + void randomx_calculate_hash_next(randomx_vm* machine, const void* nextInput, size_t nextInputSize, void* output) { + machine->resetRoundingMode(); + for (uint32_t chain = 0; chain < RANDOMX_PROGRAM_COUNT - 1; ++chain) { + machine->run(machine->tempHash); + blake2b(machine->tempHash, sizeof(machine->tempHash), machine->getRegisterFile(), sizeof(randomx::RegisterFile), nullptr, 0); + } + machine->run(machine->tempHash); + + // Finish current hash and fill the scratchpad for the next hash at the same time + blake2b(machine->tempHash, sizeof(machine->tempHash), nextInput, nextInputSize, nullptr, 0); + machine->hashAndFill(output, RANDOMX_HASH_SIZE, machine->tempHash); + } + + void randomx_calculate_hash_last(randomx_vm* machine, void* output) { + machine->resetRoundingMode(); + for (int chain = 0; chain < RANDOMX_PROGRAM_COUNT - 1; ++chain) { + machine->run(machine->tempHash); + blake2b(machine->tempHash, sizeof(machine->tempHash), machine->getRegisterFile(), sizeof(randomx::RegisterFile), nullptr, 0); + } + machine->run(machine->tempHash); + machine->getFinalResult(output, RANDOMX_HASH_SIZE); + } +} diff --git a/src/RandomX/src/randomx.h b/src/RandomX/src/randomx.h new file mode 100644 index 000000000..64d18068b --- /dev/null +++ b/src/RandomX/src/randomx.h @@ -0,0 +1,267 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef RANDOMX_H +#define RANDOMX_H + +#include +#include + +#define RANDOMX_HASH_SIZE 32 +#define RANDOMX_DATASET_ITEM_SIZE 64 + +#ifndef RANDOMX_EXPORT +#define RANDOMX_EXPORT +#endif + +typedef enum { + RANDOMX_FLAG_DEFAULT = 0, + RANDOMX_FLAG_LARGE_PAGES = 1, + RANDOMX_FLAG_HARD_AES = 2, + RANDOMX_FLAG_FULL_MEM = 4, + RANDOMX_FLAG_JIT = 8, + RANDOMX_FLAG_SECURE = 16, + RANDOMX_FLAG_ARGON2_SSSE3 = 32, + RANDOMX_FLAG_ARGON2_AVX2 = 64, + RANDOMX_FLAG_ARGON2 = 96 +} randomx_flags; + +typedef struct randomx_dataset randomx_dataset; +typedef struct randomx_cache randomx_cache; +typedef struct randomx_vm randomx_vm; + + +#if defined(__cplusplus) + +#ifdef __cpp_constexpr +#define CONSTEXPR constexpr +#else +#define CONSTEXPR +#endif + +inline CONSTEXPR randomx_flags operator |(randomx_flags a, randomx_flags b) { + return static_cast(static_cast(a) | static_cast(b)); +} +inline CONSTEXPR randomx_flags operator &(randomx_flags a, randomx_flags b) { + return static_cast(static_cast(a) & static_cast(b)); +} +inline randomx_flags& operator |=(randomx_flags& a, randomx_flags b) { + return a = a | b; +} + +extern "C" { +#endif + +/** + * @return The recommended flags to be used on the current machine. + * Does not include: + * RANDOMX_FLAG_LARGE_PAGES + * RANDOMX_FLAG_FULL_MEM + * RANDOMX_FLAG_SECURE + * These flags must be added manually if desired. + * On OpenBSD RANDOMX_FLAG_SECURE is enabled by default in JIT mode as W^X is enforced by the OS. + */ +RANDOMX_EXPORT randomx_flags randomx_get_flags(void); + +/** + * Creates a randomx_cache structure and allocates memory for RandomX Cache. + * + * @param flags is any combination of these 2 flags (each flag can be set or not set): + * RANDOMX_FLAG_LARGE_PAGES - allocate memory in large pages + * RANDOMX_FLAG_JIT - create cache structure with JIT compilation support; this makes + * subsequent Dataset initialization faster + * Optionally, one of these two flags may be selected: + * RANDOMX_FLAG_ARGON2_SSSE3 - optimized Argon2 for CPUs with the SSSE3 instruction set + * makes subsequent cache initialization faster + * RANDOMX_FLAG_ARGON2_AVX2 - optimized Argon2 for CPUs with the AVX2 instruction set + * makes subsequent cache initialization faster + * + * @return Pointer to an allocated randomx_cache structure. + * Returns NULL if: + * (1) memory allocation fails + * (2) the RANDOMX_FLAG_JIT is set and JIT compilation is not supported on the current platform + * (3) an invalid or unsupported RANDOMX_FLAG_ARGON2 value is set + */ +RANDOMX_EXPORT randomx_cache *randomx_alloc_cache(randomx_flags flags); + +/** + * Initializes the cache memory and SuperscalarHash using the provided key value. + * Does nothing if called again with the same key value. + * + * @param cache is a pointer to a previously allocated randomx_cache structure. Must not be NULL. + * @param key is a pointer to memory which contains the key value. Must not be NULL. + * @param keySize is the number of bytes of the key. +*/ +RANDOMX_EXPORT void randomx_init_cache(randomx_cache *cache, const void *key, size_t keySize); + +/** + * Releases all memory occupied by the randomx_cache structure. + * + * @param cache is a pointer to a previously allocated randomx_cache structure. +*/ +RANDOMX_EXPORT void randomx_release_cache(randomx_cache* cache); + +/** + * Creates a randomx_dataset structure and allocates memory for RandomX Dataset. + * + * @param flags is the initialization flags. Only one flag is supported (can be set or not set): + * RANDOMX_FLAG_LARGE_PAGES - allocate memory in large pages + * + * @return Pointer to an allocated randomx_dataset structure. + * NULL is returned if memory allocation fails. + */ +RANDOMX_EXPORT randomx_dataset *randomx_alloc_dataset(randomx_flags flags); + +/** + * Gets the number of items contained in the dataset. + * + * @return the number of items contained in the dataset. +*/ +RANDOMX_EXPORT unsigned long randomx_dataset_item_count(void); + +/** + * Initializes dataset items. + * + * Note: In order to use the Dataset, all items from 0 to (randomx_dataset_item_count() - 1) must be initialized. + * This may be done by several calls to this function using non-overlapping item sequences. + * + * @param dataset is a pointer to a previously allocated randomx_dataset structure. Must not be NULL. + * @param cache is a pointer to a previously allocated and initialized randomx_cache structure. Must not be NULL. + * @param startItem is the item number where intialization should start. + * @param itemCount is the number of items that should be initialized. +*/ +RANDOMX_EXPORT void randomx_init_dataset(randomx_dataset *dataset, randomx_cache *cache, unsigned long startItem, unsigned long itemCount); + +/** + * Returns a pointer to the internal memory buffer of the dataset structure. The size + * of the internal memory buffer is randomx_dataset_item_count() * RANDOMX_DATASET_ITEM_SIZE. + * + * @param dataset is a pointer to a previously allocated randomx_dataset structure. Must not be NULL. + * + * @return Pointer to the internal memory buffer of the dataset structure. +*/ +RANDOMX_EXPORT void *randomx_get_dataset_memory(randomx_dataset *dataset); + +/** + * Releases all memory occupied by the randomx_dataset structure. + * + * @param dataset is a pointer to a previously allocated randomx_dataset structure. +*/ +RANDOMX_EXPORT void randomx_release_dataset(randomx_dataset *dataset); + +/** + * Creates and initializes a RandomX virtual machine. + * + * @param flags is any combination of these 5 flags (each flag can be set or not set): + * RANDOMX_FLAG_LARGE_PAGES - allocate scratchpad memory in large pages + * RANDOMX_FLAG_HARD_AES - virtual machine will use hardware accelerated AES + * RANDOMX_FLAG_FULL_MEM - virtual machine will use the full dataset + * RANDOMX_FLAG_JIT - virtual machine will use a JIT compiler + * RANDOMX_FLAG_SECURE - when combined with RANDOMX_FLAG_JIT, the JIT pages are never + * writable and executable at the same time (W^X policy) + * The numeric values of the first 4 flags are ordered so that a higher value will provide + * faster hash calculation and a lower numeric value will provide higher portability. + * Using RANDOMX_FLAG_DEFAULT (all flags not set) works on all platforms, but is the slowest. + * @param cache is a pointer to an initialized randomx_cache structure. Can be + * NULL if RANDOMX_FLAG_FULL_MEM is set. + * @param dataset is a pointer to a randomx_dataset structure. Can be NULL + * if RANDOMX_FLAG_FULL_MEM is not set. + * + * @return Pointer to an initialized randomx_vm structure. + * Returns NULL if: + * (1) Scratchpad memory allocation fails. + * (2) The requested initialization flags are not supported on the current platform. + * (3) cache parameter is NULL and RANDOMX_FLAG_FULL_MEM is not set + * (4) dataset parameter is NULL and RANDOMX_FLAG_FULL_MEM is set +*/ +RANDOMX_EXPORT randomx_vm *randomx_create_vm(randomx_flags flags, randomx_cache *cache, randomx_dataset *dataset); + +/** + * Reinitializes a virtual machine with a new Cache. This function should be called anytime + * the Cache is reinitialized with a new key. Does nothing if called with a Cache containing + * the same key value as already set. + * + * @param machine is a pointer to a randomx_vm structure that was initialized + * without RANDOMX_FLAG_FULL_MEM. Must not be NULL. + * @param cache is a pointer to an initialized randomx_cache structure. Must not be NULL. +*/ +RANDOMX_EXPORT void randomx_vm_set_cache(randomx_vm *machine, randomx_cache* cache); + +/** + * Reinitializes a virtual machine with a new Dataset. + * + * @param machine is a pointer to a randomx_vm structure that was initialized + * with RANDOMX_FLAG_FULL_MEM. Must not be NULL. + * @param dataset is a pointer to an initialized randomx_dataset structure. Must not be NULL. +*/ +RANDOMX_EXPORT void randomx_vm_set_dataset(randomx_vm *machine, randomx_dataset *dataset); + +/** + * Releases all memory occupied by the randomx_vm structure. + * + * @param machine is a pointer to a previously created randomx_vm structure. +*/ +RANDOMX_EXPORT void randomx_destroy_vm(randomx_vm *machine); + +/** + * Calculates a RandomX hash value. + * + * @param machine is a pointer to a randomx_vm structure. Must not be NULL. + * @param input is a pointer to memory to be hashed. Must not be NULL. + * @param inputSize is the number of bytes to be hashed. + * @param output is a pointer to memory where the hash will be stored. Must not + * be NULL and at least RANDOMX_HASH_SIZE bytes must be available for writing. +*/ +RANDOMX_EXPORT void randomx_calculate_hash(randomx_vm *machine, const void *input, size_t inputSize, void *output); + +/** + * Set of functions used to calculate multiple RandomX hashes more efficiently. + * randomx_calculate_hash_first will begin a hash calculation. + * randomx_calculate_hash_next will output the hash value of the previous input + * and begin the calculation of the next hash. + * randomx_calculate_hash_last will output the hash value of the previous input. + * + * WARNING: These functions may alter the floating point rounding mode of the calling thread. + * + * @param machine is a pointer to a randomx_vm structure. Must not be NULL. + * @param input is a pointer to memory to be hashed. Must not be NULL. + * @param inputSize is the number of bytes to be hashed. + * @param nextInput is a pointer to memory to be hashed for the next hash. Must not be NULL. + * @param nextInputSize is the number of bytes to be hashed for the next hash. + * @param output is a pointer to memory where the hash will be stored. Must not + * be NULL and at least RANDOMX_HASH_SIZE bytes must be available for writing. +*/ +RANDOMX_EXPORT void randomx_calculate_hash_first(randomx_vm* machine, const void* input, size_t inputSize); +RANDOMX_EXPORT void randomx_calculate_hash_next(randomx_vm* machine, const void* nextInput, size_t nextInputSize, void* output); +RANDOMX_EXPORT void randomx_calculate_hash_last(randomx_vm* machine, void* output); + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/src/RandomX/src/reciprocal.c b/src/RandomX/src/reciprocal.c new file mode 100644 index 000000000..22620f53a --- /dev/null +++ b/src/RandomX/src/reciprocal.c @@ -0,0 +1,80 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include "reciprocal.h" + +/* + Calculates rcp = 2**x / divisor for highest integer x such that rcp < 2**64. + divisor must not be 0 or a power of 2 + + Equivalent x86 assembly (divisor in rcx): + + mov edx, 1 + mov r8, rcx + xor eax, eax + bsr rcx, rcx + shl rdx, cl + div r8 + ret + +*/ +uint64_t randomx_reciprocal(uint64_t divisor) { + + assert(divisor != 0); + + const uint64_t p2exp63 = 1ULL << 63; + + uint64_t quotient = p2exp63 / divisor, remainder = p2exp63 % divisor; + + unsigned bsr = 0; //highest set bit in divisor + + for (uint64_t bit = divisor; bit > 0; bit >>= 1) + bsr++; + + for (unsigned shift = 0; shift < bsr; shift++) { + if (remainder >= divisor - remainder) { + quotient = quotient * 2 + 1; + remainder = remainder * 2 - divisor; + } + else { + quotient = quotient * 2; + remainder = remainder * 2; + } + } + + return quotient; +} + +#if !RANDOMX_HAVE_FAST_RECIPROCAL + +uint64_t randomx_reciprocal_fast(uint64_t divisor) { + return randomx_reciprocal(divisor); +} + +#endif diff --git a/src/RandomX/src/reciprocal.h b/src/RandomX/src/reciprocal.h new file mode 100644 index 000000000..8858df2b8 --- /dev/null +++ b/src/RandomX/src/reciprocal.h @@ -0,0 +1,48 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include + +#if defined(_M_X64) || defined(__x86_64__) +#define RANDOMX_HAVE_FAST_RECIPROCAL 1 +#else +#define RANDOMX_HAVE_FAST_RECIPROCAL 0 +#endif + +#if defined(__cplusplus) +extern "C" { +#endif + +uint64_t randomx_reciprocal(uint64_t); +uint64_t randomx_reciprocal_fast(uint64_t); + +#if defined(__cplusplus) +} +#endif diff --git a/src/RandomX/src/soft_aes.cpp b/src/RandomX/src/soft_aes.cpp new file mode 100644 index 000000000..3e82fa2ef --- /dev/null +++ b/src/RandomX/src/soft_aes.cpp @@ -0,0 +1,364 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "soft_aes.h" + +alignas(16) const uint8_t sbox[256] = { + 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, + 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, + 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, + 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, + 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, + 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, + 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, + 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, + 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, + 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, + 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, + 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, + 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, + 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, + 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, + 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16, +}; + +alignas(16) const uint32_t lutEnc0[256] = { + 0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6, 0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591, + 0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56, 0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec, + 0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa, 0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb, + 0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45, 0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b, + 0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c, 0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83, + 0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9, 0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a, + 0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d, 0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f, + 0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df, 0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea, + 0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34, 0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b, + 0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d, 0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413, + 0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1, 0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6, + 0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972, 0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85, + 0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed, 0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511, + 0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe, 0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b, + 0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05, 0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1, + 0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142, 0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf, + 0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3, 0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e, + 0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a, 0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6, + 0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3, 0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b, + 0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428, 0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad, + 0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14, 0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8, + 0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4, 0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2, + 0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda, 0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949, + 0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf, 0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810, + 0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c, 0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697, + 0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e, 0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f, + 0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc, 0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c, + 0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969, 0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27, + 0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122, 0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433, + 0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9, 0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5, + 0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a, 0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0, + 0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e, 0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c, +}; + +alignas(16) const uint32_t lutEnc1[256] = { + 0x6363c6a5, 0x7c7cf884, 0x7777ee99, 0x7b7bf68d, 0xf2f2ff0d, 0x6b6bd6bd, 0x6f6fdeb1, 0xc5c59154, + 0x30306050, 0x01010203, 0x6767cea9, 0x2b2b567d, 0xfefee719, 0xd7d7b562, 0xabab4de6, 0x7676ec9a, + 0xcaca8f45, 0x82821f9d, 0xc9c98940, 0x7d7dfa87, 0xfafaef15, 0x5959b2eb, 0x47478ec9, 0xf0f0fb0b, + 0xadad41ec, 0xd4d4b367, 0xa2a25ffd, 0xafaf45ea, 0x9c9c23bf, 0xa4a453f7, 0x7272e496, 0xc0c09b5b, + 0xb7b775c2, 0xfdfde11c, 0x93933dae, 0x26264c6a, 0x36366c5a, 0x3f3f7e41, 0xf7f7f502, 0xcccc834f, + 0x3434685c, 0xa5a551f4, 0xe5e5d134, 0xf1f1f908, 0x7171e293, 0xd8d8ab73, 0x31316253, 0x15152a3f, + 0x0404080c, 0xc7c79552, 0x23234665, 0xc3c39d5e, 0x18183028, 0x969637a1, 0x05050a0f, 0x9a9a2fb5, + 0x07070e09, 0x12122436, 0x80801b9b, 0xe2e2df3d, 0xebebcd26, 0x27274e69, 0xb2b27fcd, 0x7575ea9f, + 0x0909121b, 0x83831d9e, 0x2c2c5874, 0x1a1a342e, 0x1b1b362d, 0x6e6edcb2, 0x5a5ab4ee, 0xa0a05bfb, + 0x5252a4f6, 0x3b3b764d, 0xd6d6b761, 0xb3b37dce, 0x2929527b, 0xe3e3dd3e, 0x2f2f5e71, 0x84841397, + 0x5353a6f5, 0xd1d1b968, 0x00000000, 0xededc12c, 0x20204060, 0xfcfce31f, 0xb1b179c8, 0x5b5bb6ed, + 0x6a6ad4be, 0xcbcb8d46, 0xbebe67d9, 0x3939724b, 0x4a4a94de, 0x4c4c98d4, 0x5858b0e8, 0xcfcf854a, + 0xd0d0bb6b, 0xefefc52a, 0xaaaa4fe5, 0xfbfbed16, 0x434386c5, 0x4d4d9ad7, 0x33336655, 0x85851194, + 0x45458acf, 0xf9f9e910, 0x02020406, 0x7f7ffe81, 0x5050a0f0, 0x3c3c7844, 0x9f9f25ba, 0xa8a84be3, + 0x5151a2f3, 0xa3a35dfe, 0x404080c0, 0x8f8f058a, 0x92923fad, 0x9d9d21bc, 0x38387048, 0xf5f5f104, + 0xbcbc63df, 0xb6b677c1, 0xdadaaf75, 0x21214263, 0x10102030, 0xffffe51a, 0xf3f3fd0e, 0xd2d2bf6d, + 0xcdcd814c, 0x0c0c1814, 0x13132635, 0xececc32f, 0x5f5fbee1, 0x979735a2, 0x444488cc, 0x17172e39, + 0xc4c49357, 0xa7a755f2, 0x7e7efc82, 0x3d3d7a47, 0x6464c8ac, 0x5d5dbae7, 0x1919322b, 0x7373e695, + 0x6060c0a0, 0x81811998, 0x4f4f9ed1, 0xdcdca37f, 0x22224466, 0x2a2a547e, 0x90903bab, 0x88880b83, + 0x46468cca, 0xeeeec729, 0xb8b86bd3, 0x1414283c, 0xdedea779, 0x5e5ebce2, 0x0b0b161d, 0xdbdbad76, + 0xe0e0db3b, 0x32326456, 0x3a3a744e, 0x0a0a141e, 0x494992db, 0x06060c0a, 0x2424486c, 0x5c5cb8e4, + 0xc2c29f5d, 0xd3d3bd6e, 0xacac43ef, 0x6262c4a6, 0x919139a8, 0x959531a4, 0xe4e4d337, 0x7979f28b, + 0xe7e7d532, 0xc8c88b43, 0x37376e59, 0x6d6ddab7, 0x8d8d018c, 0xd5d5b164, 0x4e4e9cd2, 0xa9a949e0, + 0x6c6cd8b4, 0x5656acfa, 0xf4f4f307, 0xeaeacf25, 0x6565caaf, 0x7a7af48e, 0xaeae47e9, 0x08081018, + 0xbaba6fd5, 0x7878f088, 0x25254a6f, 0x2e2e5c72, 0x1c1c3824, 0xa6a657f1, 0xb4b473c7, 0xc6c69751, + 0xe8e8cb23, 0xdddda17c, 0x7474e89c, 0x1f1f3e21, 0x4b4b96dd, 0xbdbd61dc, 0x8b8b0d86, 0x8a8a0f85, + 0x7070e090, 0x3e3e7c42, 0xb5b571c4, 0x6666ccaa, 0x484890d8, 0x03030605, 0xf6f6f701, 0x0e0e1c12, + 0x6161c2a3, 0x35356a5f, 0x5757aef9, 0xb9b969d0, 0x86861791, 0xc1c19958, 0x1d1d3a27, 0x9e9e27b9, + 0xe1e1d938, 0xf8f8eb13, 0x98982bb3, 0x11112233, 0x6969d2bb, 0xd9d9a970, 0x8e8e0789, 0x949433a7, + 0x9b9b2db6, 0x1e1e3c22, 0x87871592, 0xe9e9c920, 0xcece8749, 0x5555aaff, 0x28285078, 0xdfdfa57a, + 0x8c8c038f, 0xa1a159f8, 0x89890980, 0x0d0d1a17, 0xbfbf65da, 0xe6e6d731, 0x424284c6, 0x6868d0b8, + 0x414182c3, 0x999929b0, 0x2d2d5a77, 0x0f0f1e11, 0xb0b07bcb, 0x5454a8fc, 0xbbbb6dd6, 0x16162c3a, +}; + +alignas(16) const uint32_t lutEnc2[256] = { + 0x63c6a563, 0x7cf8847c, 0x77ee9977, 0x7bf68d7b, 0xf2ff0df2, 0x6bd6bd6b, 0x6fdeb16f, 0xc59154c5, + 0x30605030, 0x01020301, 0x67cea967, 0x2b567d2b, 0xfee719fe, 0xd7b562d7, 0xab4de6ab, 0x76ec9a76, + 0xca8f45ca, 0x821f9d82, 0xc98940c9, 0x7dfa877d, 0xfaef15fa, 0x59b2eb59, 0x478ec947, 0xf0fb0bf0, + 0xad41ecad, 0xd4b367d4, 0xa25ffda2, 0xaf45eaaf, 0x9c23bf9c, 0xa453f7a4, 0x72e49672, 0xc09b5bc0, + 0xb775c2b7, 0xfde11cfd, 0x933dae93, 0x264c6a26, 0x366c5a36, 0x3f7e413f, 0xf7f502f7, 0xcc834fcc, + 0x34685c34, 0xa551f4a5, 0xe5d134e5, 0xf1f908f1, 0x71e29371, 0xd8ab73d8, 0x31625331, 0x152a3f15, + 0x04080c04, 0xc79552c7, 0x23466523, 0xc39d5ec3, 0x18302818, 0x9637a196, 0x050a0f05, 0x9a2fb59a, + 0x070e0907, 0x12243612, 0x801b9b80, 0xe2df3de2, 0xebcd26eb, 0x274e6927, 0xb27fcdb2, 0x75ea9f75, + 0x09121b09, 0x831d9e83, 0x2c58742c, 0x1a342e1a, 0x1b362d1b, 0x6edcb26e, 0x5ab4ee5a, 0xa05bfba0, + 0x52a4f652, 0x3b764d3b, 0xd6b761d6, 0xb37dceb3, 0x29527b29, 0xe3dd3ee3, 0x2f5e712f, 0x84139784, + 0x53a6f553, 0xd1b968d1, 0x00000000, 0xedc12ced, 0x20406020, 0xfce31ffc, 0xb179c8b1, 0x5bb6ed5b, + 0x6ad4be6a, 0xcb8d46cb, 0xbe67d9be, 0x39724b39, 0x4a94de4a, 0x4c98d44c, 0x58b0e858, 0xcf854acf, + 0xd0bb6bd0, 0xefc52aef, 0xaa4fe5aa, 0xfbed16fb, 0x4386c543, 0x4d9ad74d, 0x33665533, 0x85119485, + 0x458acf45, 0xf9e910f9, 0x02040602, 0x7ffe817f, 0x50a0f050, 0x3c78443c, 0x9f25ba9f, 0xa84be3a8, + 0x51a2f351, 0xa35dfea3, 0x4080c040, 0x8f058a8f, 0x923fad92, 0x9d21bc9d, 0x38704838, 0xf5f104f5, + 0xbc63dfbc, 0xb677c1b6, 0xdaaf75da, 0x21426321, 0x10203010, 0xffe51aff, 0xf3fd0ef3, 0xd2bf6dd2, + 0xcd814ccd, 0x0c18140c, 0x13263513, 0xecc32fec, 0x5fbee15f, 0x9735a297, 0x4488cc44, 0x172e3917, + 0xc49357c4, 0xa755f2a7, 0x7efc827e, 0x3d7a473d, 0x64c8ac64, 0x5dbae75d, 0x19322b19, 0x73e69573, + 0x60c0a060, 0x81199881, 0x4f9ed14f, 0xdca37fdc, 0x22446622, 0x2a547e2a, 0x903bab90, 0x880b8388, + 0x468cca46, 0xeec729ee, 0xb86bd3b8, 0x14283c14, 0xdea779de, 0x5ebce25e, 0x0b161d0b, 0xdbad76db, + 0xe0db3be0, 0x32645632, 0x3a744e3a, 0x0a141e0a, 0x4992db49, 0x060c0a06, 0x24486c24, 0x5cb8e45c, + 0xc29f5dc2, 0xd3bd6ed3, 0xac43efac, 0x62c4a662, 0x9139a891, 0x9531a495, 0xe4d337e4, 0x79f28b79, + 0xe7d532e7, 0xc88b43c8, 0x376e5937, 0x6ddab76d, 0x8d018c8d, 0xd5b164d5, 0x4e9cd24e, 0xa949e0a9, + 0x6cd8b46c, 0x56acfa56, 0xf4f307f4, 0xeacf25ea, 0x65caaf65, 0x7af48e7a, 0xae47e9ae, 0x08101808, + 0xba6fd5ba, 0x78f08878, 0x254a6f25, 0x2e5c722e, 0x1c38241c, 0xa657f1a6, 0xb473c7b4, 0xc69751c6, + 0xe8cb23e8, 0xdda17cdd, 0x74e89c74, 0x1f3e211f, 0x4b96dd4b, 0xbd61dcbd, 0x8b0d868b, 0x8a0f858a, + 0x70e09070, 0x3e7c423e, 0xb571c4b5, 0x66ccaa66, 0x4890d848, 0x03060503, 0xf6f701f6, 0x0e1c120e, + 0x61c2a361, 0x356a5f35, 0x57aef957, 0xb969d0b9, 0x86179186, 0xc19958c1, 0x1d3a271d, 0x9e27b99e, + 0xe1d938e1, 0xf8eb13f8, 0x982bb398, 0x11223311, 0x69d2bb69, 0xd9a970d9, 0x8e07898e, 0x9433a794, + 0x9b2db69b, 0x1e3c221e, 0x87159287, 0xe9c920e9, 0xce8749ce, 0x55aaff55, 0x28507828, 0xdfa57adf, + 0x8c038f8c, 0xa159f8a1, 0x89098089, 0x0d1a170d, 0xbf65dabf, 0xe6d731e6, 0x4284c642, 0x68d0b868, + 0x4182c341, 0x9929b099, 0x2d5a772d, 0x0f1e110f, 0xb07bcbb0, 0x54a8fc54, 0xbb6dd6bb, 0x162c3a16, +}; + +alignas(16) const uint32_t lutEnc3[256] = { + 0xc6a56363, 0xf8847c7c, 0xee997777, 0xf68d7b7b, 0xff0df2f2, 0xd6bd6b6b, 0xdeb16f6f, 0x9154c5c5, + 0x60503030, 0x02030101, 0xcea96767, 0x567d2b2b, 0xe719fefe, 0xb562d7d7, 0x4de6abab, 0xec9a7676, + 0x8f45caca, 0x1f9d8282, 0x8940c9c9, 0xfa877d7d, 0xef15fafa, 0xb2eb5959, 0x8ec94747, 0xfb0bf0f0, + 0x41ecadad, 0xb367d4d4, 0x5ffda2a2, 0x45eaafaf, 0x23bf9c9c, 0x53f7a4a4, 0xe4967272, 0x9b5bc0c0, + 0x75c2b7b7, 0xe11cfdfd, 0x3dae9393, 0x4c6a2626, 0x6c5a3636, 0x7e413f3f, 0xf502f7f7, 0x834fcccc, + 0x685c3434, 0x51f4a5a5, 0xd134e5e5, 0xf908f1f1, 0xe2937171, 0xab73d8d8, 0x62533131, 0x2a3f1515, + 0x080c0404, 0x9552c7c7, 0x46652323, 0x9d5ec3c3, 0x30281818, 0x37a19696, 0x0a0f0505, 0x2fb59a9a, + 0x0e090707, 0x24361212, 0x1b9b8080, 0xdf3de2e2, 0xcd26ebeb, 0x4e692727, 0x7fcdb2b2, 0xea9f7575, + 0x121b0909, 0x1d9e8383, 0x58742c2c, 0x342e1a1a, 0x362d1b1b, 0xdcb26e6e, 0xb4ee5a5a, 0x5bfba0a0, + 0xa4f65252, 0x764d3b3b, 0xb761d6d6, 0x7dceb3b3, 0x527b2929, 0xdd3ee3e3, 0x5e712f2f, 0x13978484, + 0xa6f55353, 0xb968d1d1, 0x00000000, 0xc12ceded, 0x40602020, 0xe31ffcfc, 0x79c8b1b1, 0xb6ed5b5b, + 0xd4be6a6a, 0x8d46cbcb, 0x67d9bebe, 0x724b3939, 0x94de4a4a, 0x98d44c4c, 0xb0e85858, 0x854acfcf, + 0xbb6bd0d0, 0xc52aefef, 0x4fe5aaaa, 0xed16fbfb, 0x86c54343, 0x9ad74d4d, 0x66553333, 0x11948585, + 0x8acf4545, 0xe910f9f9, 0x04060202, 0xfe817f7f, 0xa0f05050, 0x78443c3c, 0x25ba9f9f, 0x4be3a8a8, + 0xa2f35151, 0x5dfea3a3, 0x80c04040, 0x058a8f8f, 0x3fad9292, 0x21bc9d9d, 0x70483838, 0xf104f5f5, + 0x63dfbcbc, 0x77c1b6b6, 0xaf75dada, 0x42632121, 0x20301010, 0xe51affff, 0xfd0ef3f3, 0xbf6dd2d2, + 0x814ccdcd, 0x18140c0c, 0x26351313, 0xc32fecec, 0xbee15f5f, 0x35a29797, 0x88cc4444, 0x2e391717, + 0x9357c4c4, 0x55f2a7a7, 0xfc827e7e, 0x7a473d3d, 0xc8ac6464, 0xbae75d5d, 0x322b1919, 0xe6957373, + 0xc0a06060, 0x19988181, 0x9ed14f4f, 0xa37fdcdc, 0x44662222, 0x547e2a2a, 0x3bab9090, 0x0b838888, + 0x8cca4646, 0xc729eeee, 0x6bd3b8b8, 0x283c1414, 0xa779dede, 0xbce25e5e, 0x161d0b0b, 0xad76dbdb, + 0xdb3be0e0, 0x64563232, 0x744e3a3a, 0x141e0a0a, 0x92db4949, 0x0c0a0606, 0x486c2424, 0xb8e45c5c, + 0x9f5dc2c2, 0xbd6ed3d3, 0x43efacac, 0xc4a66262, 0x39a89191, 0x31a49595, 0xd337e4e4, 0xf28b7979, + 0xd532e7e7, 0x8b43c8c8, 0x6e593737, 0xdab76d6d, 0x018c8d8d, 0xb164d5d5, 0x9cd24e4e, 0x49e0a9a9, + 0xd8b46c6c, 0xacfa5656, 0xf307f4f4, 0xcf25eaea, 0xcaaf6565, 0xf48e7a7a, 0x47e9aeae, 0x10180808, + 0x6fd5baba, 0xf0887878, 0x4a6f2525, 0x5c722e2e, 0x38241c1c, 0x57f1a6a6, 0x73c7b4b4, 0x9751c6c6, + 0xcb23e8e8, 0xa17cdddd, 0xe89c7474, 0x3e211f1f, 0x96dd4b4b, 0x61dcbdbd, 0x0d868b8b, 0x0f858a8a, + 0xe0907070, 0x7c423e3e, 0x71c4b5b5, 0xccaa6666, 0x90d84848, 0x06050303, 0xf701f6f6, 0x1c120e0e, + 0xc2a36161, 0x6a5f3535, 0xaef95757, 0x69d0b9b9, 0x17918686, 0x9958c1c1, 0x3a271d1d, 0x27b99e9e, + 0xd938e1e1, 0xeb13f8f8, 0x2bb39898, 0x22331111, 0xd2bb6969, 0xa970d9d9, 0x07898e8e, 0x33a79494, + 0x2db69b9b, 0x3c221e1e, 0x15928787, 0xc920e9e9, 0x8749cece, 0xaaff5555, 0x50782828, 0xa57adfdf, + 0x038f8c8c, 0x59f8a1a1, 0x09808989, 0x1a170d0d, 0x65dabfbf, 0xd731e6e6, 0x84c64242, 0xd0b86868, + 0x82c34141, 0x29b09999, 0x5a772d2d, 0x1e110f0f, 0x7bcbb0b0, 0xa8fc5454, 0x6dd6bbbb, 0x2c3a1616, +}; + +alignas(16) const uint32_t lutDec0[256] = { + 0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a, 0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b, + 0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5, 0xfcd7e54f, 0xd7cb2ac5, 0x80443526, 0x8fa362b5, + 0x495ab1de, 0x671bba25, 0x980eea45, 0xe1c0fe5d, 0x02752fc3, 0x12f04c81, 0xa397468d, 0xc6f9d36b, + 0xe75f8f03, 0x959c9215, 0xeb7a6dbf, 0xda595295, 0x2d83bed4, 0xd3217458, 0x2969e049, 0x44c8c98e, + 0x6a89c275, 0x78798ef4, 0x6b3e5899, 0xdd71b927, 0xb64fe1be, 0x17ad88f0, 0x66ac20c9, 0xb43ace7d, + 0x184adf63, 0x82311ae5, 0x60335197, 0x457f5362, 0xe07764b1, 0x84ae6bbb, 0x1ca081fe, 0x942b08f9, + 0x58684870, 0x19fd458f, 0x876cde94, 0xb7f87b52, 0x23d373ab, 0xe2024b72, 0x578f1fe3, 0x2aab5566, + 0x0728ebb2, 0x03c2b52f, 0x9a7bc586, 0xa50837d3, 0xf2872830, 0xb2a5bf23, 0xba6a0302, 0x5c8216ed, + 0x2b1ccf8a, 0x92b479a7, 0xf0f207f3, 0xa1e2694e, 0xcdf4da65, 0xd5be0506, 0x1f6234d1, 0x8afea6c4, + 0x9d532e34, 0xa055f3a2, 0x32e18a05, 0x75ebf6a4, 0x39ec830b, 0xaaef6040, 0x069f715e, 0x51106ebd, + 0xf98a213e, 0x3d06dd96, 0xae053edd, 0x46bde64d, 0xb58d5491, 0x055dc471, 0x6fd40604, 0xff155060, + 0x24fb9819, 0x97e9bdd6, 0xcc434089, 0x779ed967, 0xbd42e8b0, 0x888b8907, 0x385b19e7, 0xdbeec879, + 0x470a7ca1, 0xe90f427c, 0xc91e84f8, 0x00000000, 0x83868009, 0x48ed2b32, 0xac70111e, 0x4e725a6c, + 0xfbff0efd, 0x5638850f, 0x1ed5ae3d, 0x27392d36, 0x64d90f0a, 0x21a65c68, 0xd1545b9b, 0x3a2e3624, + 0xb1670a0c, 0x0fe75793, 0xd296eeb4, 0x9e919b1b, 0x4fc5c080, 0xa220dc61, 0x694b775a, 0x161a121c, + 0x0aba93e2, 0xe52aa0c0, 0x43e0223c, 0x1d171b12, 0x0b0d090e, 0xadc78bf2, 0xb9a8b62d, 0xc8a91e14, + 0x8519f157, 0x4c0775af, 0xbbdd99ee, 0xfd607fa3, 0x9f2601f7, 0xbcf5725c, 0xc53b6644, 0x347efb5b, + 0x7629438b, 0xdcc623cb, 0x68fcedb6, 0x63f1e4b8, 0xcadc31d7, 0x10856342, 0x40229713, 0x2011c684, + 0x7d244a85, 0xf83dbbd2, 0x1132f9ae, 0x6da129c7, 0x4b2f9e1d, 0xf330b2dc, 0xec52860d, 0xd0e3c177, + 0x6c16b32b, 0x99b970a9, 0xfa489411, 0x2264e947, 0xc48cfca8, 0x1a3ff0a0, 0xd82c7d56, 0xef903322, + 0xc74e4987, 0xc1d138d9, 0xfea2ca8c, 0x360bd498, 0xcf81f5a6, 0x28de7aa5, 0x268eb7da, 0xa4bfad3f, + 0xe49d3a2c, 0x0d927850, 0x9bcc5f6a, 0x62467e54, 0xc2138df6, 0xe8b8d890, 0x5ef7392e, 0xf5afc382, + 0xbe805d9f, 0x7c93d069, 0xa92dd56f, 0xb31225cf, 0x3b99acc8, 0xa77d1810, 0x6e639ce8, 0x7bbb3bdb, + 0x097826cd, 0xf418596e, 0x01b79aec, 0xa89a4f83, 0x656e95e6, 0x7ee6ffaa, 0x08cfbc21, 0xe6e815ef, + 0xd99be7ba, 0xce366f4a, 0xd4099fea, 0xd67cb029, 0xafb2a431, 0x31233f2a, 0x3094a5c6, 0xc066a235, + 0x37bc4e74, 0xa6ca82fc, 0xb0d090e0, 0x15d8a733, 0x4a9804f1, 0xf7daec41, 0x0e50cd7f, 0x2ff69117, + 0x8dd64d76, 0x4db0ef43, 0x544daacc, 0xdf0496e4, 0xe3b5d19e, 0x1b886a4c, 0xb81f2cc1, 0x7f516546, + 0x04ea5e9d, 0x5d358c01, 0x737487fa, 0x2e410bfb, 0x5a1d67b3, 0x52d2db92, 0x335610e9, 0x1347d66d, + 0x8c61d79a, 0x7a0ca137, 0x8e14f859, 0x893c13eb, 0xee27a9ce, 0x35c961b7, 0xede51ce1, 0x3cb1477a, + 0x59dfd29c, 0x3f73f255, 0x79ce1418, 0xbf37c773, 0xeacdf753, 0x5baafd5f, 0x146f3ddf, 0x86db4478, + 0x81f3afca, 0x3ec468b9, 0x2c342438, 0x5f40a3c2, 0x72c31d16, 0x0c25e2bc, 0x8b493c28, 0x41950dff, + 0x7101a839, 0xdeb30c08, 0x9ce4b4d8, 0x90c15664, 0x6184cb7b, 0x70b632d5, 0x745c6c48, 0x4257b8d0, +}; + +alignas(16) const uint32_t lutDec1[256] = { + 0xa7f45150, 0x65417e53, 0xa4171ac3, 0x5e273a96, 0x6bab3bcb, 0x459d1ff1, 0x58faacab, 0x03e34b93, + 0xfa302055, 0x6d76adf6, 0x76cc8891, 0x4c02f525, 0xd7e54ffc, 0xcb2ac5d7, 0x44352680, 0xa362b58f, + 0x5ab1de49, 0x1bba2567, 0x0eea4598, 0xc0fe5de1, 0x752fc302, 0xf04c8112, 0x97468da3, 0xf9d36bc6, + 0x5f8f03e7, 0x9c921595, 0x7a6dbfeb, 0x595295da, 0x83bed42d, 0x217458d3, 0x69e04929, 0xc8c98e44, + 0x89c2756a, 0x798ef478, 0x3e58996b, 0x71b927dd, 0x4fe1beb6, 0xad88f017, 0xac20c966, 0x3ace7db4, + 0x4adf6318, 0x311ae582, 0x33519760, 0x7f536245, 0x7764b1e0, 0xae6bbb84, 0xa081fe1c, 0x2b08f994, + 0x68487058, 0xfd458f19, 0x6cde9487, 0xf87b52b7, 0xd373ab23, 0x024b72e2, 0x8f1fe357, 0xab55662a, + 0x28ebb207, 0xc2b52f03, 0x7bc5869a, 0x0837d3a5, 0x872830f2, 0xa5bf23b2, 0x6a0302ba, 0x8216ed5c, + 0x1ccf8a2b, 0xb479a792, 0xf207f3f0, 0xe2694ea1, 0xf4da65cd, 0xbe0506d5, 0x6234d11f, 0xfea6c48a, + 0x532e349d, 0x55f3a2a0, 0xe18a0532, 0xebf6a475, 0xec830b39, 0xef6040aa, 0x9f715e06, 0x106ebd51, + 0x8a213ef9, 0x06dd963d, 0x053eddae, 0xbde64d46, 0x8d5491b5, 0x5dc47105, 0xd406046f, 0x155060ff, + 0xfb981924, 0xe9bdd697, 0x434089cc, 0x9ed96777, 0x42e8b0bd, 0x8b890788, 0x5b19e738, 0xeec879db, + 0x0a7ca147, 0x0f427ce9, 0x1e84f8c9, 0x00000000, 0x86800983, 0xed2b3248, 0x70111eac, 0x725a6c4e, + 0xff0efdfb, 0x38850f56, 0xd5ae3d1e, 0x392d3627, 0xd90f0a64, 0xa65c6821, 0x545b9bd1, 0x2e36243a, + 0x670a0cb1, 0xe757930f, 0x96eeb4d2, 0x919b1b9e, 0xc5c0804f, 0x20dc61a2, 0x4b775a69, 0x1a121c16, + 0xba93e20a, 0x2aa0c0e5, 0xe0223c43, 0x171b121d, 0x0d090e0b, 0xc78bf2ad, 0xa8b62db9, 0xa91e14c8, + 0x19f15785, 0x0775af4c, 0xdd99eebb, 0x607fa3fd, 0x2601f79f, 0xf5725cbc, 0x3b6644c5, 0x7efb5b34, + 0x29438b76, 0xc623cbdc, 0xfcedb668, 0xf1e4b863, 0xdc31d7ca, 0x85634210, 0x22971340, 0x11c68420, + 0x244a857d, 0x3dbbd2f8, 0x32f9ae11, 0xa129c76d, 0x2f9e1d4b, 0x30b2dcf3, 0x52860dec, 0xe3c177d0, + 0x16b32b6c, 0xb970a999, 0x489411fa, 0x64e94722, 0x8cfca8c4, 0x3ff0a01a, 0x2c7d56d8, 0x903322ef, + 0x4e4987c7, 0xd138d9c1, 0xa2ca8cfe, 0x0bd49836, 0x81f5a6cf, 0xde7aa528, 0x8eb7da26, 0xbfad3fa4, + 0x9d3a2ce4, 0x9278500d, 0xcc5f6a9b, 0x467e5462, 0x138df6c2, 0xb8d890e8, 0xf7392e5e, 0xafc382f5, + 0x805d9fbe, 0x93d0697c, 0x2dd56fa9, 0x1225cfb3, 0x99acc83b, 0x7d1810a7, 0x639ce86e, 0xbb3bdb7b, + 0x7826cd09, 0x18596ef4, 0xb79aec01, 0x9a4f83a8, 0x6e95e665, 0xe6ffaa7e, 0xcfbc2108, 0xe815efe6, + 0x9be7bad9, 0x366f4ace, 0x099fead4, 0x7cb029d6, 0xb2a431af, 0x233f2a31, 0x94a5c630, 0x66a235c0, + 0xbc4e7437, 0xca82fca6, 0xd090e0b0, 0xd8a73315, 0x9804f14a, 0xdaec41f7, 0x50cd7f0e, 0xf691172f, + 0xd64d768d, 0xb0ef434d, 0x4daacc54, 0x0496e4df, 0xb5d19ee3, 0x886a4c1b, 0x1f2cc1b8, 0x5165467f, + 0xea5e9d04, 0x358c015d, 0x7487fa73, 0x410bfb2e, 0x1d67b35a, 0xd2db9252, 0x5610e933, 0x47d66d13, + 0x61d79a8c, 0x0ca1377a, 0x14f8598e, 0x3c13eb89, 0x27a9ceee, 0xc961b735, 0xe51ce1ed, 0xb1477a3c, + 0xdfd29c59, 0x73f2553f, 0xce141879, 0x37c773bf, 0xcdf753ea, 0xaafd5f5b, 0x6f3ddf14, 0xdb447886, + 0xf3afca81, 0xc468b93e, 0x3424382c, 0x40a3c25f, 0xc31d1672, 0x25e2bc0c, 0x493c288b, 0x950dff41, + 0x01a83971, 0xb30c08de, 0xe4b4d89c, 0xc1566490, 0x84cb7b61, 0xb632d570, 0x5c6c4874, 0x57b8d042, +}; + +alignas(16) const uint32_t lutDec2[256] = { + 0xf45150a7, 0x417e5365, 0x171ac3a4, 0x273a965e, 0xab3bcb6b, 0x9d1ff145, 0xfaacab58, 0xe34b9303, + 0x302055fa, 0x76adf66d, 0xcc889176, 0x02f5254c, 0xe54ffcd7, 0x2ac5d7cb, 0x35268044, 0x62b58fa3, + 0xb1de495a, 0xba25671b, 0xea45980e, 0xfe5de1c0, 0x2fc30275, 0x4c8112f0, 0x468da397, 0xd36bc6f9, + 0x8f03e75f, 0x9215959c, 0x6dbfeb7a, 0x5295da59, 0xbed42d83, 0x7458d321, 0xe0492969, 0xc98e44c8, + 0xc2756a89, 0x8ef47879, 0x58996b3e, 0xb927dd71, 0xe1beb64f, 0x88f017ad, 0x20c966ac, 0xce7db43a, + 0xdf63184a, 0x1ae58231, 0x51976033, 0x5362457f, 0x64b1e077, 0x6bbb84ae, 0x81fe1ca0, 0x08f9942b, + 0x48705868, 0x458f19fd, 0xde94876c, 0x7b52b7f8, 0x73ab23d3, 0x4b72e202, 0x1fe3578f, 0x55662aab, + 0xebb20728, 0xb52f03c2, 0xc5869a7b, 0x37d3a508, 0x2830f287, 0xbf23b2a5, 0x0302ba6a, 0x16ed5c82, + 0xcf8a2b1c, 0x79a792b4, 0x07f3f0f2, 0x694ea1e2, 0xda65cdf4, 0x0506d5be, 0x34d11f62, 0xa6c48afe, + 0x2e349d53, 0xf3a2a055, 0x8a0532e1, 0xf6a475eb, 0x830b39ec, 0x6040aaef, 0x715e069f, 0x6ebd5110, + 0x213ef98a, 0xdd963d06, 0x3eddae05, 0xe64d46bd, 0x5491b58d, 0xc471055d, 0x06046fd4, 0x5060ff15, + 0x981924fb, 0xbdd697e9, 0x4089cc43, 0xd967779e, 0xe8b0bd42, 0x8907888b, 0x19e7385b, 0xc879dbee, + 0x7ca1470a, 0x427ce90f, 0x84f8c91e, 0x00000000, 0x80098386, 0x2b3248ed, 0x111eac70, 0x5a6c4e72, + 0x0efdfbff, 0x850f5638, 0xae3d1ed5, 0x2d362739, 0x0f0a64d9, 0x5c6821a6, 0x5b9bd154, 0x36243a2e, + 0x0a0cb167, 0x57930fe7, 0xeeb4d296, 0x9b1b9e91, 0xc0804fc5, 0xdc61a220, 0x775a694b, 0x121c161a, + 0x93e20aba, 0xa0c0e52a, 0x223c43e0, 0x1b121d17, 0x090e0b0d, 0x8bf2adc7, 0xb62db9a8, 0x1e14c8a9, + 0xf1578519, 0x75af4c07, 0x99eebbdd, 0x7fa3fd60, 0x01f79f26, 0x725cbcf5, 0x6644c53b, 0xfb5b347e, + 0x438b7629, 0x23cbdcc6, 0xedb668fc, 0xe4b863f1, 0x31d7cadc, 0x63421085, 0x97134022, 0xc6842011, + 0x4a857d24, 0xbbd2f83d, 0xf9ae1132, 0x29c76da1, 0x9e1d4b2f, 0xb2dcf330, 0x860dec52, 0xc177d0e3, + 0xb32b6c16, 0x70a999b9, 0x9411fa48, 0xe9472264, 0xfca8c48c, 0xf0a01a3f, 0x7d56d82c, 0x3322ef90, + 0x4987c74e, 0x38d9c1d1, 0xca8cfea2, 0xd498360b, 0xf5a6cf81, 0x7aa528de, 0xb7da268e, 0xad3fa4bf, + 0x3a2ce49d, 0x78500d92, 0x5f6a9bcc, 0x7e546246, 0x8df6c213, 0xd890e8b8, 0x392e5ef7, 0xc382f5af, + 0x5d9fbe80, 0xd0697c93, 0xd56fa92d, 0x25cfb312, 0xacc83b99, 0x1810a77d, 0x9ce86e63, 0x3bdb7bbb, + 0x26cd0978, 0x596ef418, 0x9aec01b7, 0x4f83a89a, 0x95e6656e, 0xffaa7ee6, 0xbc2108cf, 0x15efe6e8, + 0xe7bad99b, 0x6f4ace36, 0x9fead409, 0xb029d67c, 0xa431afb2, 0x3f2a3123, 0xa5c63094, 0xa235c066, + 0x4e7437bc, 0x82fca6ca, 0x90e0b0d0, 0xa73315d8, 0x04f14a98, 0xec41f7da, 0xcd7f0e50, 0x91172ff6, + 0x4d768dd6, 0xef434db0, 0xaacc544d, 0x96e4df04, 0xd19ee3b5, 0x6a4c1b88, 0x2cc1b81f, 0x65467f51, + 0x5e9d04ea, 0x8c015d35, 0x87fa7374, 0x0bfb2e41, 0x67b35a1d, 0xdb9252d2, 0x10e93356, 0xd66d1347, + 0xd79a8c61, 0xa1377a0c, 0xf8598e14, 0x13eb893c, 0xa9ceee27, 0x61b735c9, 0x1ce1ede5, 0x477a3cb1, + 0xd29c59df, 0xf2553f73, 0x141879ce, 0xc773bf37, 0xf753eacd, 0xfd5f5baa, 0x3ddf146f, 0x447886db, + 0xafca81f3, 0x68b93ec4, 0x24382c34, 0xa3c25f40, 0x1d1672c3, 0xe2bc0c25, 0x3c288b49, 0x0dff4195, + 0xa8397101, 0x0c08deb3, 0xb4d89ce4, 0x566490c1, 0xcb7b6184, 0x32d570b6, 0x6c48745c, 0xb8d04257, +}; + +alignas(16) const uint32_t lutDec3[256] = { + 0x5150a7f4, 0x7e536541, 0x1ac3a417, 0x3a965e27, 0x3bcb6bab, 0x1ff1459d, 0xacab58fa, 0x4b9303e3, + 0x2055fa30, 0xadf66d76, 0x889176cc, 0xf5254c02, 0x4ffcd7e5, 0xc5d7cb2a, 0x26804435, 0xb58fa362, + 0xde495ab1, 0x25671bba, 0x45980eea, 0x5de1c0fe, 0xc302752f, 0x8112f04c, 0x8da39746, 0x6bc6f9d3, + 0x03e75f8f, 0x15959c92, 0xbfeb7a6d, 0x95da5952, 0xd42d83be, 0x58d32174, 0x492969e0, 0x8e44c8c9, + 0x756a89c2, 0xf478798e, 0x996b3e58, 0x27dd71b9, 0xbeb64fe1, 0xf017ad88, 0xc966ac20, 0x7db43ace, + 0x63184adf, 0xe582311a, 0x97603351, 0x62457f53, 0xb1e07764, 0xbb84ae6b, 0xfe1ca081, 0xf9942b08, + 0x70586848, 0x8f19fd45, 0x94876cde, 0x52b7f87b, 0xab23d373, 0x72e2024b, 0xe3578f1f, 0x662aab55, + 0xb20728eb, 0x2f03c2b5, 0x869a7bc5, 0xd3a50837, 0x30f28728, 0x23b2a5bf, 0x02ba6a03, 0xed5c8216, + 0x8a2b1ccf, 0xa792b479, 0xf3f0f207, 0x4ea1e269, 0x65cdf4da, 0x06d5be05, 0xd11f6234, 0xc48afea6, + 0x349d532e, 0xa2a055f3, 0x0532e18a, 0xa475ebf6, 0x0b39ec83, 0x40aaef60, 0x5e069f71, 0xbd51106e, + 0x3ef98a21, 0x963d06dd, 0xddae053e, 0x4d46bde6, 0x91b58d54, 0x71055dc4, 0x046fd406, 0x60ff1550, + 0x1924fb98, 0xd697e9bd, 0x89cc4340, 0x67779ed9, 0xb0bd42e8, 0x07888b89, 0xe7385b19, 0x79dbeec8, + 0xa1470a7c, 0x7ce90f42, 0xf8c91e84, 0x00000000, 0x09838680, 0x3248ed2b, 0x1eac7011, 0x6c4e725a, + 0xfdfbff0e, 0x0f563885, 0x3d1ed5ae, 0x3627392d, 0x0a64d90f, 0x6821a65c, 0x9bd1545b, 0x243a2e36, + 0x0cb1670a, 0x930fe757, 0xb4d296ee, 0x1b9e919b, 0x804fc5c0, 0x61a220dc, 0x5a694b77, 0x1c161a12, + 0xe20aba93, 0xc0e52aa0, 0x3c43e022, 0x121d171b, 0x0e0b0d09, 0xf2adc78b, 0x2db9a8b6, 0x14c8a91e, + 0x578519f1, 0xaf4c0775, 0xeebbdd99, 0xa3fd607f, 0xf79f2601, 0x5cbcf572, 0x44c53b66, 0x5b347efb, + 0x8b762943, 0xcbdcc623, 0xb668fced, 0xb863f1e4, 0xd7cadc31, 0x42108563, 0x13402297, 0x842011c6, + 0x857d244a, 0xd2f83dbb, 0xae1132f9, 0xc76da129, 0x1d4b2f9e, 0xdcf330b2, 0x0dec5286, 0x77d0e3c1, + 0x2b6c16b3, 0xa999b970, 0x11fa4894, 0x472264e9, 0xa8c48cfc, 0xa01a3ff0, 0x56d82c7d, 0x22ef9033, + 0x87c74e49, 0xd9c1d138, 0x8cfea2ca, 0x98360bd4, 0xa6cf81f5, 0xa528de7a, 0xda268eb7, 0x3fa4bfad, + 0x2ce49d3a, 0x500d9278, 0x6a9bcc5f, 0x5462467e, 0xf6c2138d, 0x90e8b8d8, 0x2e5ef739, 0x82f5afc3, + 0x9fbe805d, 0x697c93d0, 0x6fa92dd5, 0xcfb31225, 0xc83b99ac, 0x10a77d18, 0xe86e639c, 0xdb7bbb3b, + 0xcd097826, 0x6ef41859, 0xec01b79a, 0x83a89a4f, 0xe6656e95, 0xaa7ee6ff, 0x2108cfbc, 0xefe6e815, + 0xbad99be7, 0x4ace366f, 0xead4099f, 0x29d67cb0, 0x31afb2a4, 0x2a31233f, 0xc63094a5, 0x35c066a2, + 0x7437bc4e, 0xfca6ca82, 0xe0b0d090, 0x3315d8a7, 0xf14a9804, 0x41f7daec, 0x7f0e50cd, 0x172ff691, + 0x768dd64d, 0x434db0ef, 0xcc544daa, 0xe4df0496, 0x9ee3b5d1, 0x4c1b886a, 0xc1b81f2c, 0x467f5165, + 0x9d04ea5e, 0x015d358c, 0xfa737487, 0xfb2e410b, 0xb35a1d67, 0x9252d2db, 0xe9335610, 0x6d1347d6, + 0x9a8c61d7, 0x377a0ca1, 0x598e14f8, 0xeb893c13, 0xceee27a9, 0xb735c961, 0xe1ede51c, 0x7a3cb147, + 0x9c59dfd2, 0x553f73f2, 0x1879ce14, 0x73bf37c7, 0x53eacdf7, 0x5f5baafd, 0xdf146f3d, 0x7886db44, + 0xca81f3af, 0xb93ec468, 0x382c3424, 0xc25f40a3, 0x1672c31d, 0xbc0c25e2, 0x288b493c, 0xff41950d, + 0x397101a8, 0x08deb30c, 0xd89ce4b4, 0x6490c156, 0x7b6184cb, 0xd570b632, 0x48745c6c, 0xd04257b8, +}; + +rx_vec_i128 soft_aesenc(rx_vec_i128 in, rx_vec_i128 key) { + uint32_t s0, s1, s2, s3; + + s0 = rx_vec_i128_w(in); + s1 = rx_vec_i128_z(in); + s2 = rx_vec_i128_y(in); + s3 = rx_vec_i128_x(in); + + rx_vec_i128 out = rx_set_int_vec_i128( + (lutEnc0[s0 & 0xff] ^ lutEnc1[(s3 >> 8) & 0xff] ^ lutEnc2[(s2 >> 16) & 0xff] ^ lutEnc3[s1 >> 24]), + (lutEnc0[s1 & 0xff] ^ lutEnc1[(s0 >> 8) & 0xff] ^ lutEnc2[(s3 >> 16) & 0xff] ^ lutEnc3[s2 >> 24]), + (lutEnc0[s2 & 0xff] ^ lutEnc1[(s1 >> 8) & 0xff] ^ lutEnc2[(s0 >> 16) & 0xff] ^ lutEnc3[s3 >> 24]), + (lutEnc0[s3 & 0xff] ^ lutEnc1[(s2 >> 8) & 0xff] ^ lutEnc2[(s1 >> 16) & 0xff] ^ lutEnc3[s0 >> 24]) + ); + + return rx_xor_vec_i128(out, key); +} + +rx_vec_i128 soft_aesdec(rx_vec_i128 in, rx_vec_i128 key) { + uint32_t s0, s1, s2, s3; + + s0 = rx_vec_i128_w(in); + s1 = rx_vec_i128_z(in); + s2 = rx_vec_i128_y(in); + s3 = rx_vec_i128_x(in); + + rx_vec_i128 out = rx_set_int_vec_i128( + (lutDec0[s0 & 0xff] ^ lutDec1[(s1 >> 8) & 0xff] ^ lutDec2[(s2 >> 16) & 0xff] ^ lutDec3[s3 >> 24]), + (lutDec0[s1 & 0xff] ^ lutDec1[(s2 >> 8) & 0xff] ^ lutDec2[(s3 >> 16) & 0xff] ^ lutDec3[s0 >> 24]), + (lutDec0[s2 & 0xff] ^ lutDec1[(s3 >> 8) & 0xff] ^ lutDec2[(s0 >> 16) & 0xff] ^ lutDec3[s1 >> 24]), + (lutDec0[s3 & 0xff] ^ lutDec1[(s0 >> 8) & 0xff] ^ lutDec2[(s1 >> 16) & 0xff] ^ lutDec3[s2 >> 24]) + ); + + return rx_xor_vec_i128(out, key); +} diff --git a/src/RandomX/src/soft_aes.h b/src/RandomX/src/soft_aes.h new file mode 100644 index 000000000..254f8d630 --- /dev/null +++ b/src/RandomX/src/soft_aes.h @@ -0,0 +1,46 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include "intrin_portable.h" + +rx_vec_i128 soft_aesenc(rx_vec_i128 in, rx_vec_i128 key); + +rx_vec_i128 soft_aesdec(rx_vec_i128 in, rx_vec_i128 key); + +template +inline rx_vec_i128 aesenc(rx_vec_i128 in, rx_vec_i128 key) { + return soft ? soft_aesenc(in, key) : rx_aesenc_vec_i128(in, key); +} + +template +inline rx_vec_i128 aesdec(rx_vec_i128 in, rx_vec_i128 key) { + return soft ? soft_aesdec(in, key) : rx_aesdec_vec_i128(in, key); +} \ No newline at end of file diff --git a/src/RandomX/src/superscalar.cpp b/src/RandomX/src/superscalar.cpp new file mode 100644 index 000000000..4e9fd78d3 --- /dev/null +++ b/src/RandomX/src/superscalar.cpp @@ -0,0 +1,903 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "configuration.h" +#include "program.hpp" +#include "blake2/endian.h" +#include +#include +#include +#include +#include +#include "superscalar.hpp" +#include "intrin_portable.h" +#include "reciprocal.h" +#include "common.hpp" + +namespace randomx { + + static bool isMultiplication(SuperscalarInstructionType type) { + return type == SuperscalarInstructionType::IMUL_R || type == SuperscalarInstructionType::IMULH_R || type == SuperscalarInstructionType::ISMULH_R || type == SuperscalarInstructionType::IMUL_RCP; + } + + //uOPs (micro-ops) are represented only by the execution port they can go to + namespace ExecutionPort { + using type = int; + constexpr type Null = 0; + constexpr type P0 = 1; + constexpr type P1 = 2; + constexpr type P5 = 4; + constexpr type P01 = P0 | P1; + constexpr type P05 = P0 | P5; + constexpr type P015 = P0 | P1 | P5; + } + + //Macro-operation as output of the x86 decoder + //Usually one macro-op = one x86 instruction, but 2 instructions are sometimes fused into 1 macro-op + //Macro-op can consist of 1 or 2 uOPs. + class MacroOp { + public: + MacroOp(const char* name, int size) + : name_(name), size_(size), latency_(0), uop1_(ExecutionPort::Null), uop2_(ExecutionPort::Null) {} + MacroOp(const char* name, int size, int latency, ExecutionPort::type uop) + : name_(name), size_(size), latency_(latency), uop1_(uop), uop2_(ExecutionPort::Null) {} + MacroOp(const char* name, int size, int latency, ExecutionPort::type uop1, ExecutionPort::type uop2) + : name_(name), size_(size), latency_(latency), uop1_(uop1), uop2_(uop2) {} + MacroOp(const MacroOp& parent, bool dependent) + : name_(parent.name_), size_(parent.size_), latency_(parent.latency_), uop1_(parent.uop1_), uop2_(parent.uop2_), dependent_(dependent) {} + const char* getName() const { + return name_; + } + int getSize() const { + return size_; + } + int getLatency() const { + return latency_; + } + ExecutionPort::type getUop1() const { + return uop1_; + } + ExecutionPort::type getUop2() const { + return uop2_; + } + bool isSimple() const { + return uop2_ == ExecutionPort::Null; + } + bool isEliminated() const { + return uop1_ == ExecutionPort::Null; + } + bool isDependent() const { + return dependent_; + } + static const MacroOp Add_rr; + static const MacroOp Add_ri; + static const MacroOp Lea_sib; + static const MacroOp Sub_rr; + static const MacroOp Imul_rr; + static const MacroOp Imul_r; + static const MacroOp Mul_r; + static const MacroOp Mov_rr; + static const MacroOp Mov_ri64; + static const MacroOp Xor_rr; + static const MacroOp Xor_ri; + static const MacroOp Ror_rcl; + static const MacroOp Ror_ri; + static const MacroOp TestJz_fused; + static const MacroOp Xor_self; + static const MacroOp Cmp_ri; + static const MacroOp Setcc_r; + private: + const char* name_; + int size_; + int latency_; + ExecutionPort::type uop1_; + ExecutionPort::type uop2_; + bool dependent_ = false; + }; + + //Size: 3 bytes + const MacroOp MacroOp::Add_rr = MacroOp("add r,r", 3, 1, ExecutionPort::P015); + const MacroOp MacroOp::Sub_rr = MacroOp("sub r,r", 3, 1, ExecutionPort::P015); + const MacroOp MacroOp::Xor_rr = MacroOp("xor r,r", 3, 1, ExecutionPort::P015); + const MacroOp MacroOp::Imul_r = MacroOp("imul r", 3, 4, ExecutionPort::P1, ExecutionPort::P5); + const MacroOp MacroOp::Mul_r = MacroOp("mul r", 3, 4, ExecutionPort::P1, ExecutionPort::P5); + const MacroOp MacroOp::Mov_rr = MacroOp("mov r,r", 3); + + //Size: 4 bytes + const MacroOp MacroOp::Lea_sib = MacroOp("lea r,r+r*s", 4, 1, ExecutionPort::P01); + const MacroOp MacroOp::Imul_rr = MacroOp("imul r,r", 4, 3, ExecutionPort::P1); + const MacroOp MacroOp::Ror_ri = MacroOp("ror r,i", 4, 1, ExecutionPort::P05); + + //Size: 7 bytes (can be optionally padded with nop to 8 or 9 bytes) + const MacroOp MacroOp::Add_ri = MacroOp("add r,i", 7, 1, ExecutionPort::P015); + const MacroOp MacroOp::Xor_ri = MacroOp("xor r,i", 7, 1, ExecutionPort::P015); + + //Size: 10 bytes + const MacroOp MacroOp::Mov_ri64 = MacroOp("mov rax,i64", 10, 1, ExecutionPort::P015); + + //Unused: + const MacroOp MacroOp::Ror_rcl = MacroOp("ror r,cl", 3, 1, ExecutionPort::P0, ExecutionPort::P5); + const MacroOp MacroOp::Xor_self = MacroOp("xor rcx,rcx", 3); + const MacroOp MacroOp::Cmp_ri = MacroOp("cmp r,i", 7, 1, ExecutionPort::P015); + const MacroOp MacroOp::Setcc_r = MacroOp("setcc cl", 3, 1, ExecutionPort::P05); + const MacroOp MacroOp::TestJz_fused = MacroOp("testjz r,i", 13, 0, ExecutionPort::P5); + + const MacroOp IMULH_R_ops_array[] = { MacroOp::Mov_rr, MacroOp::Mul_r, MacroOp::Mov_rr }; + const MacroOp ISMULH_R_ops_array[] = { MacroOp::Mov_rr, MacroOp::Imul_r, MacroOp::Mov_rr }; + const MacroOp IMUL_RCP_ops_array[] = { MacroOp::Mov_ri64, MacroOp(MacroOp::Imul_rr, true) }; + + class SuperscalarInstructionInfo { + public: + const char* getName() const { + return name_; + } + int getSize() const { + return ops_.size(); + } + bool isSimple() const { + return getSize() == 1; + } + int getLatency() const { + return latency_; + } + const MacroOp& getOp(int index) const { + return ops_[index]; + } + SuperscalarInstructionType getType() const { + return type_; + } + int getResultOp() const { + return resultOp_; + } + int getDstOp() const { + return dstOp_; + } + int getSrcOp() const { + return srcOp_; + } + static const SuperscalarInstructionInfo ISUB_R; + static const SuperscalarInstructionInfo IXOR_R; + static const SuperscalarInstructionInfo IADD_RS; + static const SuperscalarInstructionInfo IMUL_R; + static const SuperscalarInstructionInfo IROR_C; + static const SuperscalarInstructionInfo IADD_C7; + static const SuperscalarInstructionInfo IXOR_C7; + static const SuperscalarInstructionInfo IADD_C8; + static const SuperscalarInstructionInfo IXOR_C8; + static const SuperscalarInstructionInfo IADD_C9; + static const SuperscalarInstructionInfo IXOR_C9; + static const SuperscalarInstructionInfo IMULH_R; + static const SuperscalarInstructionInfo ISMULH_R; + static const SuperscalarInstructionInfo IMUL_RCP; + static const SuperscalarInstructionInfo NOP; + private: + const char* name_; + SuperscalarInstructionType type_; + std::vector ops_; + int latency_; + int resultOp_ = 0; + int dstOp_ = 0; + int srcOp_; + + SuperscalarInstructionInfo(const char* name) + : name_(name), type_(SuperscalarInstructionType::INVALID), latency_(0) {} + SuperscalarInstructionInfo(const char* name, SuperscalarInstructionType type, const MacroOp& op, int srcOp) + : name_(name), type_(type), latency_(op.getLatency()), srcOp_(srcOp) { + ops_.push_back(MacroOp(op)); + } + template + SuperscalarInstructionInfo(const char* name, SuperscalarInstructionType type, const MacroOp(&arr)[N], int resultOp, int dstOp, int srcOp) + : name_(name), type_(type), latency_(0), resultOp_(resultOp), dstOp_(dstOp), srcOp_(srcOp) { + for (unsigned i = 0; i < N; ++i) { + ops_.push_back(MacroOp(arr[i])); + latency_ += ops_.back().getLatency(); + } + static_assert(N > 1, "Invalid array size"); + } + }; + + const SuperscalarInstructionInfo SuperscalarInstructionInfo::ISUB_R = SuperscalarInstructionInfo("ISUB_R", SuperscalarInstructionType::ISUB_R, MacroOp::Sub_rr, 0); + const SuperscalarInstructionInfo SuperscalarInstructionInfo::IXOR_R = SuperscalarInstructionInfo("IXOR_R", SuperscalarInstructionType::IXOR_R, MacroOp::Xor_rr, 0); + const SuperscalarInstructionInfo SuperscalarInstructionInfo::IADD_RS = SuperscalarInstructionInfo("IADD_RS", SuperscalarInstructionType::IADD_RS, MacroOp::Lea_sib, 0); + const SuperscalarInstructionInfo SuperscalarInstructionInfo::IMUL_R = SuperscalarInstructionInfo("IMUL_R", SuperscalarInstructionType::IMUL_R, MacroOp::Imul_rr, 0); + const SuperscalarInstructionInfo SuperscalarInstructionInfo::IROR_C = SuperscalarInstructionInfo("IROR_C", SuperscalarInstructionType::IROR_C, MacroOp::Ror_ri, -1); + + const SuperscalarInstructionInfo SuperscalarInstructionInfo::IADD_C7 = SuperscalarInstructionInfo("IADD_C7", SuperscalarInstructionType::IADD_C7, MacroOp::Add_ri, -1); + const SuperscalarInstructionInfo SuperscalarInstructionInfo::IXOR_C7 = SuperscalarInstructionInfo("IXOR_C7", SuperscalarInstructionType::IXOR_C7, MacroOp::Xor_ri, -1); + const SuperscalarInstructionInfo SuperscalarInstructionInfo::IADD_C8 = SuperscalarInstructionInfo("IADD_C8", SuperscalarInstructionType::IADD_C8, MacroOp::Add_ri, -1); + const SuperscalarInstructionInfo SuperscalarInstructionInfo::IXOR_C8 = SuperscalarInstructionInfo("IXOR_C8", SuperscalarInstructionType::IXOR_C8, MacroOp::Xor_ri, -1); + const SuperscalarInstructionInfo SuperscalarInstructionInfo::IADD_C9 = SuperscalarInstructionInfo("IADD_C9", SuperscalarInstructionType::IADD_C9, MacroOp::Add_ri, -1); + const SuperscalarInstructionInfo SuperscalarInstructionInfo::IXOR_C9 = SuperscalarInstructionInfo("IXOR_C9", SuperscalarInstructionType::IXOR_C9, MacroOp::Xor_ri, -1); + + const SuperscalarInstructionInfo SuperscalarInstructionInfo::IMULH_R = SuperscalarInstructionInfo("IMULH_R", SuperscalarInstructionType::IMULH_R, IMULH_R_ops_array, 1, 0, 1); + const SuperscalarInstructionInfo SuperscalarInstructionInfo::ISMULH_R = SuperscalarInstructionInfo("ISMULH_R", SuperscalarInstructionType::ISMULH_R, ISMULH_R_ops_array, 1, 0, 1); + const SuperscalarInstructionInfo SuperscalarInstructionInfo::IMUL_RCP = SuperscalarInstructionInfo("IMUL_RCP", SuperscalarInstructionType::IMUL_RCP, IMUL_RCP_ops_array, 1, 1, -1); + + const SuperscalarInstructionInfo SuperscalarInstructionInfo::NOP = SuperscalarInstructionInfo("NOP"); + + //these are some of the options how to split a 16-byte window into 3 or 4 x86 instructions. + //RandomX uses instructions with a native size of 3 (sub, xor, mul, mov), 4 (lea, mul), 7 (xor, add immediate) or 10 bytes (mov 64-bit immediate). + //Slots with sizes of 8 or 9 bytes need to be padded with a nop instruction. + const int buffer0[] = { 4, 8, 4 }; + const int buffer1[] = { 7, 3, 3, 3 }; + const int buffer2[] = { 3, 7, 3, 3 }; + const int buffer3[] = { 4, 9, 3 }; + const int buffer4[] = { 4, 4, 4, 4 }; + const int buffer5[] = { 3, 3, 10 }; + + class DecoderBuffer { + public: + static const DecoderBuffer Default; + template + DecoderBuffer(const char* name, int index, const int(&arr)[N]) + : name_(name), index_(index), counts_(arr), opsCount_(N) {} + const int* getCounts() const { + return counts_; + } + int getSize() const { + return opsCount_; + } + int getIndex() const { + return index_; + } + const char* getName() const { + return name_; + } + const DecoderBuffer* fetchNext(SuperscalarInstructionType instrType, int cycle, int mulCount, Blake2Generator& gen) const { + //If the current RandomX instruction is "IMULH", the next fetch configuration must be 3-3-10 + //because the full 128-bit multiplication instruction is 3 bytes long and decodes to 2 uOPs on Intel CPUs. + //Intel CPUs can decode at most 4 uOPs per cycle, so this requires a 2-1-1 configuration for a total of 3 macro ops. + if (instrType == SuperscalarInstructionType::IMULH_R || instrType == SuperscalarInstructionType::ISMULH_R) + return &decodeBuffer3310; + + //To make sure that the multiplication port is saturated, a 4-4-4-4 configuration is generated if the number of multiplications + //is lower than the number of cycles. + if (mulCount < cycle + 1) + return &decodeBuffer4444; + + //If the current RandomX instruction is "IMUL_RCP", the next buffer must begin with a 4-byte slot for multiplication. + if(instrType == SuperscalarInstructionType::IMUL_RCP) + return (gen.getByte() & 1) ? &decodeBuffer484 : &decodeBuffer493; + + //Default: select a random fetch configuration. + return fetchNextDefault(gen); + } + private: + const char* name_; + int index_; + const int* counts_; + int opsCount_; + DecoderBuffer() : index_(-1) {} + static const DecoderBuffer decodeBuffer484; + static const DecoderBuffer decodeBuffer7333; + static const DecoderBuffer decodeBuffer3733; + static const DecoderBuffer decodeBuffer493; + static const DecoderBuffer decodeBuffer4444; + static const DecoderBuffer decodeBuffer3310; + static const DecoderBuffer* decodeBuffers[4]; + const DecoderBuffer* fetchNextDefault(Blake2Generator& gen) const { + return decodeBuffers[gen.getByte() & 3]; + } + }; + + const DecoderBuffer DecoderBuffer::decodeBuffer484 = DecoderBuffer("4,8,4", 0, buffer0); + const DecoderBuffer DecoderBuffer::decodeBuffer7333 = DecoderBuffer("7,3,3,3", 1, buffer1); + const DecoderBuffer DecoderBuffer::decodeBuffer3733 = DecoderBuffer("3,7,3,3", 2, buffer2); + const DecoderBuffer DecoderBuffer::decodeBuffer493 = DecoderBuffer("4,9,3", 3, buffer3); + const DecoderBuffer DecoderBuffer::decodeBuffer4444 = DecoderBuffer("4,4,4,4", 4, buffer4); + const DecoderBuffer DecoderBuffer::decodeBuffer3310 = DecoderBuffer("3,3,10", 5, buffer5); + + const DecoderBuffer* DecoderBuffer::decodeBuffers[4] = { + &DecoderBuffer::decodeBuffer484, + &DecoderBuffer::decodeBuffer7333, + &DecoderBuffer::decodeBuffer3733, + &DecoderBuffer::decodeBuffer493, + }; + + const DecoderBuffer DecoderBuffer::Default = DecoderBuffer(); + + const SuperscalarInstructionInfo* slot_3[] = { &SuperscalarInstructionInfo::ISUB_R, &SuperscalarInstructionInfo::IXOR_R }; + const SuperscalarInstructionInfo* slot_3L[] = { &SuperscalarInstructionInfo::ISUB_R, &SuperscalarInstructionInfo::IXOR_R, &SuperscalarInstructionInfo::IMULH_R, &SuperscalarInstructionInfo::ISMULH_R }; + const SuperscalarInstructionInfo* slot_4[] = { &SuperscalarInstructionInfo::IROR_C, &SuperscalarInstructionInfo::IADD_RS }; + const SuperscalarInstructionInfo* slot_7[] = { &SuperscalarInstructionInfo::IXOR_C7, &SuperscalarInstructionInfo::IADD_C7 }; + const SuperscalarInstructionInfo* slot_8[] = { &SuperscalarInstructionInfo::IXOR_C8, &SuperscalarInstructionInfo::IADD_C8 }; + const SuperscalarInstructionInfo* slot_9[] = { &SuperscalarInstructionInfo::IXOR_C9, &SuperscalarInstructionInfo::IADD_C9 }; + const SuperscalarInstructionInfo* slot_10 = &SuperscalarInstructionInfo::IMUL_RCP; + + static bool selectRegister(std::vector& availableRegisters, Blake2Generator& gen, int& reg) { + int index; + if (availableRegisters.size() == 0) + return false; + + if (availableRegisters.size() > 1) { + index = gen.getUInt32() % availableRegisters.size(); + } + else { + index = 0; + } + reg = availableRegisters[index]; + return true; + } + + class RegisterInfo { + public: + RegisterInfo() : latency(0), lastOpGroup(SuperscalarInstructionType::INVALID), lastOpPar(-1), value(0) {} + int latency; + SuperscalarInstructionType lastOpGroup; + int lastOpPar; + int value; + }; + + //"SuperscalarInstruction" consists of one or more macro-ops + class SuperscalarInstruction { + public: + void toInstr(Instruction& instr) { //translate to a RandomX instruction format + instr.opcode = (int)getType(); + instr.dst = dst_; + instr.src = src_ >= 0 ? src_ : dst_; + instr.setMod(mod_); + instr.setImm32(imm32_); + } + + void createForSlot(Blake2Generator& gen, int slotSize, int fetchType, bool isLast, bool isFirst) { + switch (slotSize) + { + case 3: + //if this is the last slot, we can also select "IMULH" instructions + if (isLast) { + create(slot_3L[gen.getByte() & 3], gen); + } + else { + create(slot_3[gen.getByte() & 1], gen); + } + break; + case 4: + //if this is the 4-4-4-4 buffer, issue multiplications as the first 3 instructions + if (fetchType == 4 && !isLast) { + create(&SuperscalarInstructionInfo::IMUL_R, gen); + } + else { + create(slot_4[gen.getByte() & 1], gen); + } + break; + case 7: + create(slot_7[gen.getByte() & 1], gen); + break; + case 8: + create(slot_8[gen.getByte() & 1], gen); + break; + case 9: + create(slot_9[gen.getByte() & 1], gen); + break; + case 10: + create(slot_10, gen); + break; + default: + UNREACHABLE; + } + } + + void create(const SuperscalarInstructionInfo* info, Blake2Generator& gen) { + info_ = info; + reset(); + switch (info->getType()) + { + case SuperscalarInstructionType::ISUB_R: { + mod_ = 0; + imm32_ = 0; + opGroup_ = SuperscalarInstructionType::IADD_RS; + groupParIsSource_ = true; + } break; + + case SuperscalarInstructionType::IXOR_R: { + mod_ = 0; + imm32_ = 0; + opGroup_ = SuperscalarInstructionType::IXOR_R; + groupParIsSource_ = true; + } break; + + case SuperscalarInstructionType::IADD_RS: { + mod_ = gen.getByte(); + imm32_ = 0; + opGroup_ = SuperscalarInstructionType::IADD_RS; + groupParIsSource_ = true; + } break; + + case SuperscalarInstructionType::IMUL_R: { + mod_ = 0; + imm32_ = 0; + opGroup_ = SuperscalarInstructionType::IMUL_R; + groupParIsSource_ = true; + } break; + + case SuperscalarInstructionType::IROR_C: { + mod_ = 0; + do { + imm32_ = gen.getByte() & 63; + } while (imm32_ == 0); + opGroup_ = SuperscalarInstructionType::IROR_C; + opGroupPar_ = -1; + } break; + + case SuperscalarInstructionType::IADD_C7: + case SuperscalarInstructionType::IADD_C8: + case SuperscalarInstructionType::IADD_C9: { + mod_ = 0; + imm32_ = gen.getUInt32(); + opGroup_ = SuperscalarInstructionType::IADD_C7; + opGroupPar_ = -1; + } break; + + case SuperscalarInstructionType::IXOR_C7: + case SuperscalarInstructionType::IXOR_C8: + case SuperscalarInstructionType::IXOR_C9: { + mod_ = 0; + imm32_ = gen.getUInt32(); + opGroup_ = SuperscalarInstructionType::IXOR_C7; + opGroupPar_ = -1; + } break; + + case SuperscalarInstructionType::IMULH_R: { + canReuse_ = true; + mod_ = 0; + imm32_ = 0; + opGroup_ = SuperscalarInstructionType::IMULH_R; + opGroupPar_ = gen.getUInt32(); + } break; + + case SuperscalarInstructionType::ISMULH_R: { + canReuse_ = true; + mod_ = 0; + imm32_ = 0; + opGroup_ = SuperscalarInstructionType::ISMULH_R; + opGroupPar_ = gen.getUInt32(); + } break; + + case SuperscalarInstructionType::IMUL_RCP: { + mod_ = 0; + do { + imm32_ = gen.getUInt32(); + } while (isZeroOrPowerOf2(imm32_)); + opGroup_ = SuperscalarInstructionType::IMUL_RCP; + opGroupPar_ = -1; + } break; + + default: + break; + } + } + + bool selectDestination(int cycle, bool allowChainedMul, RegisterInfo (®isters)[8], Blake2Generator& gen) { + /*if (allowChainedMultiplication && opGroup_ == SuperscalarInstructionType::IMUL_R) + std::cout << "Selecting destination with chained MUL enabled" << std::endl;*/ + std::vector availableRegisters; + //Conditions for the destination register: + // * value must be ready at the required cycle + // * cannot be the same as the source register unless the instruction allows it + // - this avoids optimizable instructions such as "xor r, r" or "sub r, r" + // * register cannot be multiplied twice in a row unless allowChainedMul is true + // - this avoids accumulation of trailing zeroes in registers due to excessive multiplication + // - allowChainedMul is set to true if an attempt to find source/destination registers failed (this is quite rare, but prevents a catastrophic failure of the generator) + // * either the last instruction applied to the register or its source must be different than this instruction + // - this avoids optimizable instruction sequences such as "xor r1, r2; xor r1, r2" or "ror r, C1; ror r, C2" or "add r, C1; add r, C2" + // * register r5 cannot be the destination of the IADD_RS instruction (limitation of the x86 lea instruction) + for (unsigned i = 0; i < 8; ++i) { + if (registers[i].latency <= cycle && (canReuse_ || i != src_) && (allowChainedMul || opGroup_ != SuperscalarInstructionType::IMUL_R || registers[i].lastOpGroup != SuperscalarInstructionType::IMUL_R) && (registers[i].lastOpGroup != opGroup_ || registers[i].lastOpPar != opGroupPar_) && (info_->getType() != SuperscalarInstructionType::IADD_RS || i != RegisterNeedsDisplacement)) + availableRegisters.push_back(i); + } + return selectRegister(availableRegisters, gen, dst_); + } + + bool selectSource(int cycle, RegisterInfo(®isters)[8], Blake2Generator& gen) { + std::vector availableRegisters; + //all registers that are ready at the cycle + for (unsigned i = 0; i < 8; ++i) { + if (registers[i].latency <= cycle) + availableRegisters.push_back(i); + } + //if there are only 2 available registers for IADD_RS and one of them is r5, select it as the source because it cannot be the destination + if (availableRegisters.size() == 2 && info_->getType() == SuperscalarInstructionType::IADD_RS) { + if (availableRegisters[0] == RegisterNeedsDisplacement || availableRegisters[1] == RegisterNeedsDisplacement) { + opGroupPar_ = src_ = RegisterNeedsDisplacement; + return true; + } + } + if (selectRegister(availableRegisters, gen, src_)) { + if (groupParIsSource_) + opGroupPar_ = src_; + return true; + } + return false; + } + + SuperscalarInstructionType getType() { + return info_->getType(); + } + int getSource() { + return src_; + } + int getDestination() { + return dst_; + } + SuperscalarInstructionType getGroup() { + return opGroup_; + } + int getGroupPar() { + return opGroupPar_; + } + + const SuperscalarInstructionInfo& getInfo() const { + return *info_; + } + + static const SuperscalarInstruction Null; + + private: + const SuperscalarInstructionInfo* info_; + int src_ = -1; + int dst_ = -1; + int mod_; + uint32_t imm32_; + SuperscalarInstructionType opGroup_; + int opGroupPar_; + bool canReuse_ = false; + bool groupParIsSource_ = false; + + void reset() { + src_ = dst_ = -1; + canReuse_ = groupParIsSource_ = false; + } + + SuperscalarInstruction(const SuperscalarInstructionInfo* info) : info_(info) { + } + }; + + const SuperscalarInstruction SuperscalarInstruction::Null = SuperscalarInstruction(&SuperscalarInstructionInfo::NOP); + + constexpr int CYCLE_MAP_SIZE = RANDOMX_SUPERSCALAR_LATENCY + 4; + constexpr int LOOK_FORWARD_CYCLES = 4; + constexpr int MAX_THROWAWAY_COUNT = 256; + + template + static int scheduleUop(ExecutionPort::type uop, ExecutionPort::type(&portBusy)[CYCLE_MAP_SIZE][3], int cycle) { + //The scheduling here is done optimistically by checking port availability in order P5 -> P0 -> P1 to not overload + //port P1 (multiplication) by instructions that can go to any port. + for (; cycle < CYCLE_MAP_SIZE; ++cycle) { + if ((uop & ExecutionPort::P5) != 0 && !portBusy[cycle][2]) { + if (commit) { + if (trace) std::cout << "; P5 at cycle " << cycle << std::endl; + portBusy[cycle][2] = uop; + } + return cycle; + } + if ((uop & ExecutionPort::P0) != 0 && !portBusy[cycle][0]) { + if (commit) { + if (trace) std::cout << "; P0 at cycle " << cycle << std::endl; + portBusy[cycle][0] = uop; + } + return cycle; + } + if ((uop & ExecutionPort::P1) != 0 && !portBusy[cycle][1]) { + if (commit) { + if (trace) std::cout << "; P1 at cycle " << cycle << std::endl; + portBusy[cycle][1] = uop; + } + return cycle; + } + } + return -1; + } + + template + static int scheduleMop(const MacroOp& mop, ExecutionPort::type(&portBusy)[CYCLE_MAP_SIZE][3], int cycle, int depCycle) { + //if this macro-op depends on the previous one, increase the starting cycle if needed + //this handles an explicit dependency chain in IMUL_RCP + if (mop.isDependent()) { + cycle = std::max(cycle, depCycle); + } + //move instructions are eliminated and don't need an execution unit + if (mop.isEliminated()) { + if (commit) + if (trace) std::cout << "; (eliminated)" << std::endl; + return cycle; + } + else if (mop.isSimple()) { + //this macro-op has only one uOP + return scheduleUop(mop.getUop1(), portBusy, cycle); + } + else { + //macro-ops with 2 uOPs are scheduled conservatively by requiring both uOPs to execute in the same cycle + for (; cycle < CYCLE_MAP_SIZE; ++cycle) { + + int cycle1 = scheduleUop(mop.getUop1(), portBusy, cycle); + int cycle2 = scheduleUop(mop.getUop2(), portBusy, cycle); + + if (cycle1 >= 0 && cycle1 == cycle2) { + if (commit) { + scheduleUop(mop.getUop1(), portBusy, cycle1); + scheduleUop(mop.getUop2(), portBusy, cycle2); + } + return cycle1; + } + } + } + + return -1; + } + + void generateSuperscalar(SuperscalarProgram& prog, Blake2Generator& gen) { + + ExecutionPort::type portBusy[CYCLE_MAP_SIZE][3]; + memset(portBusy, 0, sizeof(portBusy)); + RegisterInfo registers[8]; + + const DecoderBuffer* decodeBuffer = &DecoderBuffer::Default; + SuperscalarInstruction currentInstruction = SuperscalarInstruction::Null; + int macroOpIndex = 0; + int codeSize = 0; + int macroOpCount = 0; + int cycle = 0; + int depCycle = 0; + int retireCycle = 0; + bool portsSaturated = false; + int programSize = 0; + int mulCount = 0; + int decodeCycle; + int throwAwayCount = 0; + + //decode instructions for RANDOMX_SUPERSCALAR_LATENCY cycles or until an execution port is saturated. + //Each decode cycle decodes 16 bytes of x86 code. + //Since a decode cycle produces on average 3.45 macro-ops and there are only 3 ALU ports, execution ports are always + //saturated first. The cycle limit is present only to guarantee loop termination. + //Program size is limited to SuperscalarMaxSize instructions. + for (decodeCycle = 0; decodeCycle < RANDOMX_SUPERSCALAR_LATENCY && !portsSaturated && programSize < SuperscalarMaxSize; ++decodeCycle) { + + //select a decode configuration + decodeBuffer = decodeBuffer->fetchNext(currentInstruction.getType(), decodeCycle, mulCount, gen); + if (trace) std::cout << "; ------------- fetch cycle " << cycle << " (" << decodeBuffer->getName() << ")" << std::endl; + + int bufferIndex = 0; + + //fill all instruction slots in the current decode buffer + while (bufferIndex < decodeBuffer->getSize()) { + int topCycle = cycle; + + //if we have issued all macro-ops for the current RandomX instruction, create a new instruction + if (macroOpIndex >= currentInstruction.getInfo().getSize()) { + if (portsSaturated || programSize >= SuperscalarMaxSize) + break; + //select an instruction so that the first macro-op fits into the current slot + currentInstruction.createForSlot(gen, decodeBuffer->getCounts()[bufferIndex], decodeBuffer->getIndex(), decodeBuffer->getSize() == bufferIndex + 1, bufferIndex == 0); + macroOpIndex = 0; + if (trace) std::cout << "; " << currentInstruction.getInfo().getName() << std::endl; + } + const MacroOp& mop = currentInstruction.getInfo().getOp(macroOpIndex); + if (trace) std::cout << mop.getName() << " "; + + //calculate the earliest cycle when this macro-op (all of its uOPs) can be scheduled for execution + int scheduleCycle = scheduleMop(mop, portBusy, cycle, depCycle); + if (scheduleCycle < 0) { + if (trace) std::cout << "Unable to map operation '" << mop.getName() << "' to execution port (cycle " << cycle << ")" << std::endl; + //__debugbreak(); + portsSaturated = true; + break; + } + + //find a source register (if applicable) that will be ready when this instruction executes + if (macroOpIndex == currentInstruction.getInfo().getSrcOp()) { + int forward; + //if no suitable operand is ready, look up to LOOK_FORWARD_CYCLES forward + for (forward = 0; forward < LOOK_FORWARD_CYCLES && !currentInstruction.selectSource(scheduleCycle, registers, gen); ++forward) { + if (trace) std::cout << "; src STALL at cycle " << cycle << std::endl; + ++scheduleCycle; + ++cycle; + } + //if no register was found, throw the instruction away and try another one + if (forward == LOOK_FORWARD_CYCLES) { + if (throwAwayCount < MAX_THROWAWAY_COUNT) { + throwAwayCount++; + macroOpIndex = currentInstruction.getInfo().getSize(); + if (trace) std::cout << "; THROW away " << currentInstruction.getInfo().getName() << std::endl; + //cycle = topCycle; + continue; + } + //abort this decode buffer + if (trace) std::cout << "Aborting at cycle " << cycle << " with decode buffer " << decodeBuffer->getName() << " - source registers not available for operation " << currentInstruction.getInfo().getName() << std::endl; + currentInstruction = SuperscalarInstruction::Null; + break; + } + if (trace) std::cout << "; src = r" << currentInstruction.getSource() << std::endl; + } + //find a destination register that will be ready when this instruction executes + if (macroOpIndex == currentInstruction.getInfo().getDstOp()) { + int forward; + for (forward = 0; forward < LOOK_FORWARD_CYCLES && !currentInstruction.selectDestination(scheduleCycle, throwAwayCount > 0, registers, gen); ++forward) { + if (trace) std::cout << "; dst STALL at cycle " << cycle << std::endl; + ++scheduleCycle; + ++cycle; + } + if (forward == LOOK_FORWARD_CYCLES) { //throw instruction away + if (throwAwayCount < MAX_THROWAWAY_COUNT) { + throwAwayCount++; + macroOpIndex = currentInstruction.getInfo().getSize(); + if (trace) std::cout << "; THROW away " << currentInstruction.getInfo().getName() << std::endl; + //cycle = topCycle; + continue; + } + //abort this decode buffer + if (trace) std::cout << "Aborting at cycle " << cycle << " with decode buffer " << decodeBuffer->getName() << " - destination registers not available" << std::endl; + currentInstruction = SuperscalarInstruction::Null; + break; + } + if (trace) std::cout << "; dst = r" << currentInstruction.getDestination() << std::endl; + } + throwAwayCount = 0; + + //recalculate when the instruction can be scheduled for execution based on operand availability + scheduleCycle = scheduleMop(mop, portBusy, scheduleCycle, scheduleCycle); + + if (scheduleCycle < 0) { + if (trace) std::cout << "Unable to map operation '" << mop.getName() << "' to execution port (cycle " << scheduleCycle << ")" << std::endl; + portsSaturated = true; + break; + } + + //calculate when the result will be ready + depCycle = scheduleCycle + mop.getLatency(); + + //if this instruction writes the result, modify register information + // RegisterInfo.latency - which cycle the register will be ready + // RegisterInfo.lastOpGroup - the last operation that was applied to the register + // RegisterInfo.lastOpPar - the last operation source value (-1 = constant, 0-7 = register) + if (macroOpIndex == currentInstruction.getInfo().getResultOp()) { + int dst = currentInstruction.getDestination(); + RegisterInfo& ri = registers[dst]; + retireCycle = depCycle; + ri.latency = retireCycle; + ri.lastOpGroup = currentInstruction.getGroup(); + ri.lastOpPar = currentInstruction.getGroupPar(); + if (trace) std::cout << "; RETIRED at cycle " << retireCycle << std::endl; + } + codeSize += mop.getSize(); + bufferIndex++; + macroOpIndex++; + macroOpCount++; + + //terminating condition + if (scheduleCycle >= RANDOMX_SUPERSCALAR_LATENCY) { + portsSaturated = true; + } + cycle = topCycle; + + //when all macro-ops of the current instruction have been issued, add the instruction into the program + if (macroOpIndex >= currentInstruction.getInfo().getSize()) { + currentInstruction.toInstr(prog(programSize++)); + mulCount += isMultiplication(currentInstruction.getType()); + } + } + ++cycle; + } + + double ipc = (macroOpCount / (double)retireCycle); + + memset(prog.asicLatencies, 0, sizeof(prog.asicLatencies)); + + //Calculate ASIC latency: + //Assumes 1 cycle latency for all operations and unlimited parallelization. + for (int i = 0; i < programSize; ++i) { + Instruction& instr = prog(i); + int latDst = prog.asicLatencies[instr.dst] + 1; + int latSrc = instr.dst != instr.src ? prog.asicLatencies[instr.src] + 1 : 0; + prog.asicLatencies[instr.dst] = std::max(latDst, latSrc); + } + + //address register is the register with the highest ASIC latency + int asicLatencyMax = 0; + int addressReg = 0; + for (int i = 0; i < 8; ++i) { + if (prog.asicLatencies[i] > asicLatencyMax) { + asicLatencyMax = prog.asicLatencies[i]; + addressReg = i; + } + prog.cpuLatencies[i] = registers[i].latency; + } + + prog.setSize(programSize); + prog.setAddressRegister(addressReg); + + prog.cpuLatency = retireCycle; + prog.asicLatency = asicLatencyMax; + prog.codeSize = codeSize; + prog.macroOps = macroOpCount; + prog.decodeCycles = decodeCycle; + prog.ipc = ipc; + prog.mulCount = mulCount; + + + /*if(INFO) std::cout << "; ALU port utilization:" << std::endl; + if (INFO) std::cout << "; (* = in use, _ = idle)" << std::endl; + + int portCycles = 0; + for (int i = 0; i < CYCLE_MAP_SIZE; ++i) { + std::cout << "; " << std::setw(3) << i << " "; + for (int j = 0; j < 3; ++j) { + std::cout << (portBusy[i][j] ? '*' : '_'); + portCycles += !!portBusy[i][j]; + } + std::cout << std::endl; + }*/ + } + + void executeSuperscalar(int_reg_t(&r)[8], SuperscalarProgram& prog, std::vector *reciprocals) { + for (unsigned j = 0; j < prog.getSize(); ++j) { + Instruction& instr = prog(j); + switch ((SuperscalarInstructionType)instr.opcode) + { + case SuperscalarInstructionType::ISUB_R: + r[instr.dst] -= r[instr.src]; + break; + case SuperscalarInstructionType::IXOR_R: + r[instr.dst] ^= r[instr.src]; + break; + case SuperscalarInstructionType::IADD_RS: + r[instr.dst] += r[instr.src] << instr.getModShift(); + break; + case SuperscalarInstructionType::IMUL_R: + r[instr.dst] *= r[instr.src]; + break; + case SuperscalarInstructionType::IROR_C: + r[instr.dst] = rotr(r[instr.dst], instr.getImm32()); + break; + case SuperscalarInstructionType::IADD_C7: + case SuperscalarInstructionType::IADD_C8: + case SuperscalarInstructionType::IADD_C9: + r[instr.dst] += signExtend2sCompl(instr.getImm32()); + break; + case SuperscalarInstructionType::IXOR_C7: + case SuperscalarInstructionType::IXOR_C8: + case SuperscalarInstructionType::IXOR_C9: + r[instr.dst] ^= signExtend2sCompl(instr.getImm32()); + break; + case SuperscalarInstructionType::IMULH_R: + r[instr.dst] = mulh(r[instr.dst], r[instr.src]); + break; + case SuperscalarInstructionType::ISMULH_R: + r[instr.dst] = smulh(r[instr.dst], r[instr.src]); + break; + case SuperscalarInstructionType::IMUL_RCP: + if (reciprocals != nullptr) + r[instr.dst] *= (*reciprocals)[instr.getImm32()]; + else + r[instr.dst] *= randomx_reciprocal(instr.getImm32()); + break; + default: + UNREACHABLE; + } + } + } +} diff --git a/src/RandomX/src/superscalar.hpp b/src/RandomX/src/superscalar.hpp new file mode 100644 index 000000000..bc101c453 --- /dev/null +++ b/src/RandomX/src/superscalar.hpp @@ -0,0 +1,60 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include +#include "superscalar_program.hpp" +#include "blake2_generator.hpp" + +namespace randomx { + // Intel Ivy Bridge reference + enum class SuperscalarInstructionType { //uOPs (decode) execution ports latency code size + ISUB_R = 0, //1 p015 1 3 (sub) + IXOR_R = 1, //1 p015 1 3 (xor) + IADD_RS = 2, //1 p01 1 4 (lea) + IMUL_R = 3, //1 p1 3 4 (imul) + IROR_C = 4, //1 p05 1 4 (ror) + IADD_C7 = 5, //1 p015 1 7 (add) + IXOR_C7 = 6, //1 p015 1 7 (xor) + IADD_C8 = 7, //1+0 p015 1 7+1 (add+nop) + IXOR_C8 = 8, //1+0 p015 1 7+1 (xor+nop) + IADD_C9 = 9, //1+0 p015 1 7+2 (add+nop) + IXOR_C9 = 10, //1+0 p015 1 7+2 (xor+nop) + IMULH_R = 11, //1+2+1 0+(p1,p5)+0 3 3+3+3 (mov+mul+mov) + ISMULH_R = 12, //1+2+1 0+(p1,p5)+0 3 3+3+3 (mov+imul+mov) + IMUL_RCP = 13, //1+1 p015+p1 4 10+4 (mov+imul) + + COUNT = 14, + INVALID = -1 + }; + + void generateSuperscalar(SuperscalarProgram& prog, Blake2Generator& gen); + void executeSuperscalar(uint64_t(&r)[8], SuperscalarProgram& prog, std::vector *reciprocals = nullptr); +} \ No newline at end of file diff --git a/src/RandomX/src/superscalar_program.hpp b/src/RandomX/src/superscalar_program.hpp new file mode 100644 index 000000000..7bcd484ba --- /dev/null +++ b/src/RandomX/src/superscalar_program.hpp @@ -0,0 +1,84 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include "instruction.hpp" +#include "common.hpp" + +namespace randomx { + + class SuperscalarProgram { + public: + Instruction& operator()(int pc) { + return programBuffer[pc]; + } + friend std::ostream& operator<<(std::ostream& os, const SuperscalarProgram& p) { + p.print(os); + return os; + } + uint32_t getSize() { + return size; + } + void setSize(uint32_t val) { + size = val; + } + int getAddressRegister() { + return addrReg; + } + void setAddressRegister(int val) { + addrReg = val; + } + + Instruction programBuffer[SuperscalarMaxSize]; + uint32_t size +#ifndef NDEBUG + = 0 +#endif + ; + int addrReg; + double ipc; + int codeSize; + int macroOps; + int decodeCycles; + int cpuLatency; + int asicLatency; + int mulCount; + int cpuLatencies[8]; + int asicLatencies[8]; + private: + void print(std::ostream& os) const { + for (unsigned i = 0; i < size; ++i) { + auto instr = programBuffer[i]; + os << instr; + } + } + }; + +} \ No newline at end of file diff --git a/src/RandomX/src/tests/affinity.cpp b/src/RandomX/src/tests/affinity.cpp new file mode 100644 index 000000000..b090d4799 --- /dev/null +++ b/src/RandomX/src/tests/affinity.cpp @@ -0,0 +1,117 @@ +/* +Copyright (c) 2019, jtgrassie +Copyright (c) 2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +#if defined(_WIN32) || defined(__CYGWIN__) + #include +#else + #ifdef __APPLE__ + #include + #include + #endif + #include +#endif +#include "affinity.hpp" + +int +set_thread_affinity(const unsigned &cpuid) +{ + std::thread::native_handle_type thread; +#if defined(_WIN32) || defined(__CYGWIN__) + thread = reinterpret_cast(GetCurrentThread()); +#else + thread = static_cast(pthread_self()); +#endif + return set_thread_affinity(thread, cpuid); +} + +int +set_thread_affinity(std::thread::native_handle_type thread, + const unsigned &cpuid) +{ + int rc = -1; +#ifdef __APPLE__ + thread_port_t mach_thread; + thread_affinity_policy_data_t policy = { static_cast(cpuid) }; + mach_thread = pthread_mach_thread_np(thread); + rc = thread_policy_set(mach_thread, THREAD_AFFINITY_POLICY, + (thread_policy_t)&policy, 1); +#elif defined(_WIN32) || defined(__CYGWIN__) + rc = SetThreadAffinityMask(reinterpret_cast(thread), 1ULL << cpuid) == 0 ? -2 : 0; +#elif !defined(__OpenBSD__) && !defined(__FreeBSD__) && !defined(__ANDROID__) && !defined(__NetBSD__) + cpu_set_t cs; + CPU_ZERO(&cs); + CPU_SET(cpuid, &cs); + rc = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cs); +#endif + return rc; +} + +unsigned +cpuid_from_mask(uint64_t mask, const unsigned &thread_index) +{ + static unsigned lookup[64]; + static bool init = false; + if (init) + return lookup[thread_index]; + unsigned count_found = 0; + for (unsigned i=0; i<64; i++) + { + if (1ULL & mask) + { + lookup[count_found] = i; + count_found++; + } + mask >>= 1; + } + init = true; + return lookup[thread_index]; +} + +std::string +mask_to_string(uint64_t mask) +{ + std::ostringstream ss; + unsigned len = 0; + unsigned v = 0; + unsigned i = 64; + while (i--) + { + v = mask >> i; + if (1ULL & v) + { + if (len == 0) len = i + 1; + ss << '1'; + } + else + if (len > 0) ss << '0'; + } + return ss.str(); +} diff --git a/src/RandomX/src/tests/affinity.hpp b/src/RandomX/src/tests/affinity.hpp new file mode 100644 index 000000000..db9e9a972 --- /dev/null +++ b/src/RandomX/src/tests/affinity.hpp @@ -0,0 +1,39 @@ +/* +Copyright (c) 2019, jtgrassie + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include +#include + +int set_thread_affinity(const unsigned &cpuid); +int set_thread_affinity(std::thread::native_handle_type thread, + const unsigned &cpuid); +unsigned cpuid_from_mask(uint64_t mask, const unsigned &thread_index); +std::string mask_to_string(uint64_t mask); diff --git a/src/RandomX/src/tests/api-example1.c b/src/RandomX/src/tests/api-example1.c new file mode 100644 index 000000000..e5f85267f --- /dev/null +++ b/src/RandomX/src/tests/api-example1.c @@ -0,0 +1,25 @@ +#include "../randomx.h" +#include + +int main() { + const char myKey[] = "RandomX example key"; + const char myInput[] = "RandomX example input"; + char hash[RANDOMX_HASH_SIZE]; + + randomx_flags flags = randomx_get_flags(); + randomx_cache *myCache = randomx_alloc_cache(flags); + randomx_init_cache(myCache, &myKey, sizeof myKey); + randomx_vm *myMachine = randomx_create_vm(flags, myCache, NULL); + + randomx_calculate_hash(myMachine, &myInput, sizeof myInput, hash); + + randomx_destroy_vm(myMachine); + randomx_release_cache(myCache); + + for (unsigned i = 0; i < RANDOMX_HASH_SIZE; ++i) + printf("%02x", hash[i] & 0xff); + + printf("\n"); + + return 0; +} diff --git a/src/RandomX/src/tests/api-example2.cpp b/src/RandomX/src/tests/api-example2.cpp new file mode 100644 index 000000000..610aaa896 --- /dev/null +++ b/src/RandomX/src/tests/api-example2.cpp @@ -0,0 +1,51 @@ +#include "../randomx.h" +#include +#include +#include + +int main() { + const char myKey[] = "RandomX example key"; + const char myInput[] = "RandomX example input"; + char hash[RANDOMX_HASH_SIZE]; + + randomx_flags flags = randomx_get_flags(); + flags |= RANDOMX_FLAG_LARGE_PAGES; + flags |= RANDOMX_FLAG_FULL_MEM; + randomx_cache *myCache = randomx_alloc_cache(flags); + if (myCache == nullptr) { + std::cout << "Cache allocation failed" << std::endl; + return 1; + } + randomx_init_cache(myCache, myKey, sizeof myKey); + + randomx_dataset *myDataset = randomx_alloc_dataset(flags); + if (myDataset == nullptr) { + std::cout << "Dataset allocation failed" << std::endl; + return 1; + } + + auto datasetItemCount = randomx_dataset_item_count(); + std::thread t1(&randomx_init_dataset, myDataset, myCache, 0, datasetItemCount / 2); + std::thread t2(&randomx_init_dataset, myDataset, myCache, datasetItemCount / 2, datasetItemCount - datasetItemCount / 2); + t1.join(); + t2.join(); + randomx_release_cache(myCache); + + randomx_vm *myMachine = randomx_create_vm(flags, nullptr, myDataset); + if (myMachine == nullptr) { + std::cout << "Failed to create a virtual machine" << std::endl; + return 1; + } + + randomx_calculate_hash(myMachine, &myInput, sizeof myInput, hash); + + randomx_destroy_vm(myMachine); + randomx_release_dataset(myDataset); + + for (unsigned i = 0; i < RANDOMX_HASH_SIZE; ++i) + std::cout << std::hex << std::setw(2) << std::setfill('0') << ((int)hash[i] & 0xff); + + std::cout << std::endl; + + return 0; +} \ No newline at end of file diff --git a/src/RandomX/src/tests/benchmark.cpp b/src/RandomX/src/tests/benchmark.cpp new file mode 100644 index 000000000..36b0259b6 --- /dev/null +++ b/src/RandomX/src/tests/benchmark.cpp @@ -0,0 +1,407 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "stopwatch.hpp" +#include "utility.hpp" +#include "../randomx.h" +#include "../dataset.hpp" +#include "../blake2/endian.h" +#include "../common.hpp" +#include "../jit_compiler.hpp" +#ifdef _WIN32 +#include +#include +#endif +#include "affinity.hpp" + +const uint8_t blockTemplate_[] = { + 0x07, 0x07, 0xf7, 0xa4, 0xf0, 0xd6, 0x05, 0xb3, 0x03, 0x26, 0x08, 0x16, 0xba, 0x3f, 0x10, 0x90, 0x2e, 0x1a, 0x14, + 0x5a, 0xc5, 0xfa, 0xd3, 0xaa, 0x3a, 0xf6, 0xea, 0x44, 0xc1, 0x18, 0x69, 0xdc, 0x4f, 0x85, 0x3f, 0x00, 0x2b, 0x2e, + 0xea, 0x00, 0x00, 0x00, 0x00, 0x77, 0xb2, 0x06, 0xa0, 0x2c, 0xa5, 0xb1, 0xd4, 0xce, 0x6b, 0xbf, 0xdf, 0x0a, 0xca, + 0xc3, 0x8b, 0xde, 0xd3, 0x4d, 0x2d, 0xcd, 0xee, 0xf9, 0x5c, 0xd2, 0x0c, 0xef, 0xc1, 0x2f, 0x61, 0xd5, 0x61, 0x09 +}; + +class AtomicHash { +public: + AtomicHash() { + for (int i = 0; i < 4; ++i) + hash[i].store(0); + } + void xorWith(uint64_t update[4]) { + for (int i = 0; i < 4; ++i) + hash[i].fetch_xor(update[i]); + } + void print(std::ostream& os) { + for (int i = 0; i < 4; ++i) + print(hash[i], os); + os << std::endl; + } +private: + static void print(std::atomic& hash, std::ostream& os) { + auto h = hash.load(); + outputHex(std::cout, (char*)&h, sizeof(h)); + } + std::atomic hash[4]; +}; + +void printUsage(const char* executable) { + std::cout << "Usage: " << executable << " [OPTIONS]" << std::endl; + std::cout << "Supported options:" << std::endl; + std::cout << " --help shows this message" << std::endl; + std::cout << " --mine mining mode: 2080 MiB" << std::endl; + std::cout << " --verify verification mode: 256 MiB" << std::endl; + std::cout << " --jit JIT compiled mode (default: interpreter)" << std::endl; + std::cout << " --secure W^X policy for JIT pages (default: off)" << std::endl; + std::cout << " --largePages use large pages (default: small pages)" << std::endl; + std::cout << " --softAes use software AES (default: hardware AES)" << std::endl; + std::cout << " --threads T use T threads (default: 1)" << std::endl; + std::cout << " --affinity A thread affinity bitmask (default: 0)" << std::endl; + std::cout << " --init Q initialize dataset with Q threads (default: 1)" << std::endl; + std::cout << " --nonces N run N nonces (default: 1000)" << std::endl; + std::cout << " --seed S seed for cache initialization (default: 0)" << std::endl; + std::cout << " --ssse3 use optimized Argon2 for SSSE3 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 << " --noBatch calculate hashes one by one (default: batch)" << std::endl; +} + +struct MemoryException : public std::exception { +}; +struct CacheAllocException : public MemoryException { + const char * what() const throw () { + return "Cache allocation failed"; + } +}; +struct DatasetAllocException : public MemoryException { + const char * what() const throw () { + return "Dataset allocation failed"; + } +}; + +using MineFunc = void(randomx_vm * vm, std::atomic & atomicNonce, AtomicHash & result, uint32_t noncesCount, int thread, int cpuid); + +template +void mine(randomx_vm* vm, std::atomic& atomicNonce, AtomicHash& result, uint32_t noncesCount, int thread, int cpuid = -1) { + if (cpuid >= 0) { + int rc = set_thread_affinity(cpuid); + if (rc) { + std::cerr << "Failed to set thread affinity for thread " << thread << " (error=" << rc << ")" << std::endl; + } + } + uint64_t hash[RANDOMX_HASH_SIZE / sizeof(uint64_t)]; + uint8_t blockTemplate[sizeof(blockTemplate_)]; + memcpy(blockTemplate, blockTemplate_, sizeof(blockTemplate)); + void* noncePtr = blockTemplate + 39; + auto nonce = atomicNonce.fetch_add(1); + + if (batch) { + store32(noncePtr, nonce); + randomx_calculate_hash_first(vm, blockTemplate, sizeof(blockTemplate)); + } + + while (nonce < noncesCount) { + if (batch) { + nonce = atomicNonce.fetch_add(1); + } + store32(noncePtr, nonce); + (batch ? randomx_calculate_hash_next : randomx_calculate_hash)(vm, blockTemplate, sizeof(blockTemplate), &hash); + result.xorWith(hash); + if (!batch) { + nonce = atomicNonce.fetch_add(1); + } + } +} + +int main(int argc, char** argv) { + bool softAes, miningMode, verificationMode, help, largePages, jit, secure; + bool ssse3, avx2, autoFlags, noBatch; + int noncesCount, threadCount, initThreadCount; + uint64_t threadAffinity; + int32_t seedValue; + char seed[4]; + + readOption("--softAes", argc, argv, softAes); + readOption("--mine", argc, argv, miningMode); + readOption("--verify", argc, argv, verificationMode); + readIntOption("--threads", argc, argv, threadCount, 1); + readUInt64Option("--affinity", argc, argv, threadAffinity, 0); + readIntOption("--nonces", argc, argv, noncesCount, 1000); + readIntOption("--init", argc, argv, initThreadCount, 1); + readIntOption("--seed", argc, argv, seedValue, 0); + readOption("--largePages", argc, argv, largePages); + if (!largePages) { + readOption("--largepages", argc, argv, largePages); + } + readOption("--jit", argc, argv, jit); + readOption("--help", argc, argv, help); + readOption("--secure", argc, argv, secure); + readOption("--ssse3", argc, argv, ssse3); + readOption("--avx2", argc, argv, avx2); + readOption("--auto", argc, argv, autoFlags); + readOption("--noBatch", argc, argv, noBatch); + + store32(&seed, seedValue); + + std::cout << "RandomX benchmark v1.1.11" << std::endl; + + if (help) { + printUsage(argv[0]); + return 0; + } + + if (!miningMode && !verificationMode) { + std::cout << "Please select either the fast mode (--mine) or the slow mode (--verify)" << std::endl; + std::cout << "Run '" << argv[0] << " --help' to see all supported options" << std::endl; + return 0; + } + + std::atomic atomicNonce(0); + AtomicHash result; + std::vector vms; + std::vector threads; + randomx_dataset* dataset; + randomx_cache* cache; + randomx_flags flags; + + if (autoFlags) { + initThreadCount = std::thread::hardware_concurrency(); + flags = randomx_get_flags(); + } + else { + flags = RANDOMX_FLAG_DEFAULT; + if (ssse3) { + flags |= RANDOMX_FLAG_ARGON2_SSSE3; + } + if (avx2) { + flags |= RANDOMX_FLAG_ARGON2_AVX2; + } + if (!softAes) { + flags |= RANDOMX_FLAG_HARD_AES; + } + if (jit) { + flags |= RANDOMX_FLAG_JIT; +#ifdef RANDOMX_FORCE_SECURE + flags |= RANDOMX_FLAG_SECURE; +#endif + } + } + + if (largePages) { + flags |= RANDOMX_FLAG_LARGE_PAGES; + } + if (miningMode) { + flags |= RANDOMX_FLAG_FULL_MEM; + } +#ifndef RANDOMX_FORCE_SECURE + if (secure) { + flags |= RANDOMX_FLAG_SECURE; + } +#endif + + if (flags & RANDOMX_FLAG_ARGON2_AVX2) { + std::cout << " - Argon2 implementation: AVX2" << std::endl; + } + else if (flags & RANDOMX_FLAG_ARGON2_SSSE3) { + std::cout << " - Argon2 implementation: SSSE3" << std::endl; + } + else { + std::cout << " - Argon2 implementation: reference" << std::endl; + } + + if (flags & RANDOMX_FLAG_FULL_MEM) { + std::cout << " - full memory mode (2080 MiB)" << std::endl; + } + else { + std::cout << " - light memory mode (256 MiB)" << std::endl; + } + + if (flags & RANDOMX_FLAG_JIT) { + std::cout << " - JIT compiled mode "; + if (flags & RANDOMX_FLAG_SECURE) { + std::cout << "(secure)"; + } + std::cout << std::endl; + } + else { + std::cout << " - interpreted mode" << std::endl; + } + + if (flags & RANDOMX_FLAG_HARD_AES) { + std::cout << " - hardware AES mode" << std::endl; + } + else { + std::cout << " - software AES mode" << std::endl; + } + + if (flags & RANDOMX_FLAG_LARGE_PAGES) { + std::cout << " - large pages mode" << std::endl; + } + else { + std::cout << " - small pages mode" << std::endl; + } + + if (threadAffinity) { + std::cout << " - thread affinity (" << mask_to_string(threadAffinity) << ")" << std::endl; + } + + MineFunc* func; + + if (noBatch) { + func = &mine; + } + else { + func = &mine; + std::cout << " - batch mode" << std::endl; + } + + std::cout << "Initializing"; + if (miningMode) + std::cout << " (" << initThreadCount << " thread" << (initThreadCount > 1 ? "s)" : ")"); + std::cout << " ..." << std::endl; + + try { + if (nullptr == randomx::selectArgonImpl(flags)) { + throw std::runtime_error("Unsupported Argon2 implementation"); + } + if ((flags & RANDOMX_FLAG_JIT) && !RANDOMX_HAVE_COMPILER) { + throw std::runtime_error("JIT compilation is not supported on this platform. Try without --jit"); + } + if (!(flags & RANDOMX_FLAG_JIT) && RANDOMX_HAVE_COMPILER) { + std::cout << "WARNING: You are using the interpreter mode. Use --jit for optimal performance." << std::endl; + } + + Stopwatch sw(true); + cache = randomx_alloc_cache(flags); + if (cache == nullptr) { + throw CacheAllocException(); + } + randomx_init_cache(cache, &seed, sizeof(seed)); + if (miningMode) { + dataset = randomx_alloc_dataset(flags); + if (dataset == nullptr) { + throw DatasetAllocException(); + } + uint32_t datasetItemCount = randomx_dataset_item_count(); + if (initThreadCount > 1) { + auto perThread = datasetItemCount / initThreadCount; + auto remainder = datasetItemCount % initThreadCount; + uint32_t startItem = 0; + for (int i = 0; i < initThreadCount; ++i) { + auto count = perThread + (i == initThreadCount - 1 ? remainder : 0); + threads.push_back(std::thread(&randomx_init_dataset, dataset, cache, startItem, count)); + startItem += count; + } + for (unsigned i = 0; i < threads.size(); ++i) { + threads[i].join(); + } + } + else { + randomx_init_dataset(dataset, cache, 0, datasetItemCount); + } + randomx_release_cache(cache); + cache = nullptr; + threads.clear(); + } + std::cout << "Memory initialized in " << sw.getElapsed() << " s" << std::endl; + std::cout << "Initializing " << threadCount << " virtual machine(s) ..." << std::endl; + for (int i = 0; i < threadCount; ++i) { + randomx_vm *vm = randomx_create_vm(flags, cache, dataset); + if (vm == nullptr) { + if ((flags & RANDOMX_FLAG_HARD_AES)) { + throw std::runtime_error("Cannot create VM with the selected options. Try using --softAes"); + } + if (largePages) { + throw std::runtime_error("Cannot create VM with the selected options. Try without --largePages"); + } + throw std::runtime_error("Cannot create VM"); + } + vms.push_back(vm); + } + std::cout << "Running benchmark (" << noncesCount << " nonces) ..." << std::endl; + sw.restart(); + if (threadCount > 1) { + for (unsigned i = 0; i < vms.size(); ++i) { + int cpuid = -1; + if (threadAffinity) + cpuid = cpuid_from_mask(threadAffinity, i); + threads.push_back(std::thread(func, vms[i], std::ref(atomicNonce), std::ref(result), noncesCount, i, cpuid)); + } + for (unsigned i = 0; i < threads.size(); ++i) { + threads[i].join(); + } + } + else { + func(vms[0], std::ref(atomicNonce), std::ref(result), noncesCount, 0, -1); + } + + double elapsed = sw.getElapsed(); + for (unsigned i = 0; i < vms.size(); ++i) + randomx_destroy_vm(vms[i]); + if (miningMode) + randomx_release_dataset(dataset); + else + randomx_release_cache(cache); + std::cout << "Calculated result: "; + result.print(std::cout); + if (noncesCount == 1000 && seedValue == 0) + std::cout << "Reference result: 10b649a3f15c7c7f88277812f2e74b337a0f20ce909af09199cccb960771cfa1" << std::endl; + if (!miningMode) { + std::cout << "Performance: " << 1000 * elapsed / noncesCount << " ms per hash" << std::endl; + } + else { + std::cout << "Performance: " << noncesCount / elapsed << " hashes per second" << std::endl; + } + } + catch (MemoryException& e) { + std::cout << "ERROR: " << e.what() << std::endl; + if (largePages) { +#ifdef _WIN32 + std::cout << "To use large pages, please enable the \"Lock Pages in Memory\" policy and reboot." << std::endl; + if (!IsWindows8OrGreater()) { + std::cout << "Additionally, you have to run the benchmark from elevated command prompt." << std::endl; + } +#else + std::cout << "To use large pages, please run: sudo sysctl -w vm.nr_hugepages=1250" << std::endl; +#endif + } + return 1; + } + catch (std::exception& e) { + std::cout << "ERROR: " << e.what() << std::endl; + return 1; + } + return 0; +} diff --git a/src/RandomX/src/tests/code-generator.cpp b/src/RandomX/src/tests/code-generator.cpp new file mode 100644 index 000000000..79123208d --- /dev/null +++ b/src/RandomX/src/tests/code-generator.cpp @@ -0,0 +1,124 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "utility.hpp" +#include "../common.hpp" +#include "../assembly_generator_x86.hpp" +#include "../superscalar.hpp" +#include "../aes_hash.hpp" +#include "../blake2/blake2.h" +#include "../program.hpp" + +const uint8_t seed[32] = { 191, 182, 222, 175, 249, 89, 134, 104, 241, 68, 191, 62, 162, 166, 61, 64, 123, 191, 227, 193, 118, 60, 188, 53, 223, 133, 175, 24, 123, 230, 55, 74 }; + +const uint8_t blockTemplate_[] = { + 0x07, 0x07, 0xf7, 0xa4, 0xf0, 0xd6, 0x05, 0xb3, 0x03, 0x26, 0x08, 0x16, 0xba, 0x3f, 0x10, 0x90, 0x2e, 0x1a, 0x14, + 0x5a, 0xc5, 0xfa, 0xd3, 0xaa, 0x3a, 0xf6, 0xea, 0x44, 0xc1, 0x18, 0x69, 0xdc, 0x4f, 0x85, 0x3f, 0x00, 0x2b, 0x2e, + 0xea, 0x00, 0x00, 0x00, 0x00, 0x77, 0xb2, 0x06, 0xa0, 0x2c, 0xa5, 0xb1, 0xd4, 0xce, 0x6b, 0xbf, 0xdf, 0x0a, 0xca, + 0xc3, 0x8b, 0xde, 0xd3, 0x4d, 0x2d, 0xcd, 0xee, 0xf9, 0x5c, 0xd2, 0x0c, 0xef, 0xc1, 0x2f, 0x61, 0xd5, 0x61, 0x09 +}; + +template +void generateAsm(uint32_t nonce) { + alignas(16) uint64_t hash[8]; + uint8_t blockTemplate[sizeof(blockTemplate_)]; + memcpy(blockTemplate, blockTemplate_, sizeof(blockTemplate)); + store32(blockTemplate + 39, nonce); + blake2b(hash, sizeof(hash), blockTemplate, sizeof(blockTemplate), nullptr, 0); + uint8_t scratchpad[randomx::ScratchpadSize]; + fillAes1Rx4((void*)hash, randomx::ScratchpadSize, scratchpad); + randomx::AssemblyGeneratorX86 asmX86; + randomx::Program p; + fillAes4Rx4(hash, sizeof(p), &p); + asmX86.generateProgram(p); + asmX86.printCode(std::cout); +} + +template +void generateNative(uint32_t nonce) { + alignas(16) uint64_t hash[8]; + uint8_t blockTemplate[sizeof(blockTemplate_)]; + memcpy(blockTemplate, blockTemplate_, sizeof(blockTemplate)); + store32(blockTemplate + 39, nonce); + blake2b(hash, sizeof(hash), blockTemplate, sizeof(blockTemplate), nullptr, 0); + uint8_t scratchpad[randomx::ScratchpadSize]; + fillAes1Rx4((void*)hash, randomx::ScratchpadSize, scratchpad); + alignas(16) randomx::Program prog; + fillAes4Rx4((void*)hash, sizeof(prog), &prog); + std::cout << prog << std::endl; +} + +void printUsage(const char* executable) { + std::cout << "Usage: " << executable << " [OPTIONS]" << std::endl; + std::cout << "Supported options:" << std::endl; + std::cout << " --softAes use software AES (default: x86 AES-NI)" << std::endl; + std::cout << " --nonce N seed nonce (default: 1000)" << std::endl; + std::cout << " --genAsm generate x86-64 asm code for nonce N" << std::endl; + std::cout << " --genNative generate RandomX code for nonce N" << std::endl; + std::cout << " --genSuperscalar generate superscalar program for nonce N" << std::endl; +} + +int main(int argc, char** argv) { + bool softAes, genAsm, genNative, genSuperscalar; + int nonce; + + readOption("--softAes", argc, argv, softAes); + readOption("--genAsm", argc, argv, genAsm); + readIntOption("--nonce", argc, argv, nonce, 1000); + readOption("--genNative", argc, argv, genNative); + readOption("--genSuperscalar", argc, argv, genSuperscalar); + + if (genSuperscalar) { + randomx::SuperscalarProgram p; + randomx::Blake2Generator gen(seed, nonce); + randomx::generateSuperscalar(p, gen); + randomx::AssemblyGeneratorX86 asmX86; + asmX86.generateAsm(p); + asmX86.printCode(std::cout); + return 0; + } + + if (genAsm) { + if (softAes) + generateAsm(nonce); + else + generateAsm(nonce); + return 0; + } + + if (genNative) { + if (softAes) + generateNative(nonce); + else + generateNative(nonce); + return 0; + } + + printUsage(argv[0]); + return 0; +} \ No newline at end of file diff --git a/src/RandomX/src/tests/jit-performance.cpp b/src/RandomX/src/tests/jit-performance.cpp new file mode 100644 index 000000000..71c0169c4 --- /dev/null +++ b/src/RandomX/src/tests/jit-performance.cpp @@ -0,0 +1,44 @@ +#include "../aes_hash.hpp" +#include "../jit_compiler_x86.hpp" +#include "../program.hpp" +#include "utility.hpp" +#include "stopwatch.hpp" +#include "../blake2/blake2.h" +#include "../reciprocal.h" + +int main(int argc, char** argv) { + int count; + readInt(argc, argv, count, 1000000); + + const char seed[] = "JIT performance test seed"; + uint8_t hash[64]; + + blake2b(&hash, sizeof hash, &seed, sizeof seed, nullptr, 0); + + randomx::ProgramConfiguration config; + + randomx::Program program; + randomx::JitCompilerX86 jit; + + std::cout << "Compiling " << count << " programs..." << std::endl; + + Stopwatch sw(true); + + for (int i = 0; i < count; ++i) { + fillAes1Rx4(hash, sizeof(program), &program); + auto addressRegisters = program.getEntropy(12); + config.readReg0 = 0 + (addressRegisters & 1); + addressRegisters >>= 1; + config.readReg1 = 2 + (addressRegisters & 1); + addressRegisters >>= 1; + config.readReg2 = 4 + (addressRegisters & 1); + addressRegisters >>= 1; + config.readReg3 = 6 + (addressRegisters & 1); + jit.generateProgram(program, config); + } + + std::cout << "Elapsed: " << sw.getElapsed() << " s" << std::endl; + + dump((const char*)jit.getProgramFunc(), jit.getCodeSize(), "program.bin"); + return 0; +} \ No newline at end of file diff --git a/src/RandomX/src/tests/perf-simulation.cpp b/src/RandomX/src/tests/perf-simulation.cpp new file mode 100644 index 000000000..1068a40ef --- /dev/null +++ b/src/RandomX/src/tests/perf-simulation.cpp @@ -0,0 +1,662 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "utility.hpp" +#include "../common.hpp" +#include "../aes_hash.hpp" +#include "../program.hpp" +#include "../blake2/blake2.h" +#include +#include + +int analyze(randomx::Program& p); +int executeInOrder(randomx::Program& p, randomx::Program& original, bool print, int executionPorts, int memoryPorts, bool speculate, int pipeline); +int executeOutOfOrder(randomx::Program& p, randomx::Program& original, bool print, int executionPorts, int memoryPorts, bool speculate, int pipeline); + +constexpr uint32_t DST_NOP = 0; +constexpr uint32_t DST_INT = 1; +constexpr uint32_t DST_FLT = 2; +constexpr uint32_t DST_MEM = 3; +constexpr uint32_t MASK_DST = 3; + +constexpr uint32_t SRC_NOP = 0; +constexpr uint32_t SRC_INT = 4; +constexpr uint32_t SRC_FLT = 8; +constexpr uint32_t SRC_MEM = 12; +constexpr uint32_t MASK_SRC = 12; + +constexpr uint32_t OP_CFROUND = 16; +constexpr uint32_t OP_SWAP = 32; +constexpr uint32_t OP_BRANCH = 48; +constexpr uint32_t MASK_EXT = 48; + +constexpr uint32_t OP_FLOAT = 64; +constexpr uint32_t BRANCH_TARGET = 128; + +//template +void generate(randomx::Program& p, uint32_t nonce) { + alignas(16) uint64_t hash[8]; + blake2b(hash, sizeof(hash), &nonce, sizeof(nonce), nullptr, 0); + fillAes1Rx4((void*)hash, sizeof(p), &p); +} + +bool has(randomx::Instruction& instr, uint32_t mask, uint32_t prop) { + return (instr.opcode & mask) == prop; +} + +bool has(randomx::Instruction& instr, uint32_t prop) { + return (instr.opcode & prop) != 0; +} + +int main(int argc, char** argv) { + int nonces, seed, executionPorts, memoryPorts, pipeline; + bool print, reorder, speculate; + readOption("--print", argc, argv, print); + readOption("--reorder", argc, argv, reorder); + readOption("--speculate", argc, argv, speculate); + readIntOption("--nonces", argc, argv, nonces, 1); + readIntOption("--seed", argc, argv, seed, 0); + readIntOption("--executionPorts", argc, argv, executionPorts, 4); + readIntOption("--memoryPorts", argc, argv, memoryPorts, 2); + readIntOption("--pipeline", argc, argv, pipeline, 3); + randomx::Program p, original; + double totalCycles = 0.0; + double jumpCount = 0; + for (int i = 0; i < nonces; ++i) { + generate(original, i ^ seed); + memcpy(&p, &original, sizeof(p)); + jumpCount += analyze(p); + totalCycles += + reorder + ? + executeOutOfOrder(p, original, print, executionPorts, memoryPorts, speculate, pipeline) + : + executeInOrder(p, original, print, executionPorts, memoryPorts, speculate, pipeline); + } + totalCycles /= nonces; + jumpCount /= nonces; + std::cout << "Execution took " << totalCycles << " cycles per program" << std::endl; + //std::cout << "Jump count: " << jumpCount << std::endl; + return 0; +} + +int executeInOrder(randomx::Program& p, randomx::Program& original, bool print, int executionPorts, int memoryPorts, bool speculate, int pipeline) { + int cycle = pipeline - 1; + int index = 0; + int branchCount = 0; + int int_reg_ready[randomx::RegistersCount] = { 0 }; + int flt_reg_ready[randomx::RegistersCount] = { 0 }; + //each workgroup takes 1 or 2 cycles (2 cycles if any instruction has a memory operand) + while (index < RANDOMX_PROGRAM_SIZE) { + int memoryAccesses = 0; + bool hasRound = false; + int workers = 0; + //std::cout << "-----------" << std::endl; + for (; workers < executionPorts && memoryAccesses < memoryPorts && index < RANDOMX_PROGRAM_SIZE; ++workers) { + auto& instr = p(index); + auto& origi = original(index); + origi.dst %= randomx::RegistersCount; + origi.src %= randomx::RegistersCount; + + //check dependencies + if (has(instr, MASK_SRC, SRC_INT) && int_reg_ready[instr.src] > cycle) + break; + + if (has(instr, MASK_SRC, SRC_MEM) && int_reg_ready[instr.src] > cycle - 1) + break; + + if (has(instr, MASK_DST, DST_MEM) && int_reg_ready[instr.dst] > cycle - 1) + break; + + if (has(instr, MASK_DST, DST_FLT) && flt_reg_ready[instr.dst] > cycle) + break; + + if (has(instr, MASK_DST, DST_INT) && int_reg_ready[instr.dst] > cycle) + break; + + if (hasRound && has(instr, OP_FLOAT)) + break; + + //execute + index++; + + if (has(instr, MASK_EXT, OP_BRANCH)) { + branchCount++; + } + + if (has(instr, MASK_DST, DST_FLT)) + flt_reg_ready[instr.dst] = cycle + 1; + + if (has(instr, MASK_DST, DST_INT)) + int_reg_ready[instr.dst] = cycle + 1; + + if (has(instr, MASK_EXT, OP_SWAP)) { + int_reg_ready[instr.src] = cycle + 1; + } + + if (has(instr, MASK_EXT, OP_CFROUND)) + hasRound = true; + + if (has(instr, MASK_SRC, SRC_MEM) || has(instr, MASK_DST, DST_MEM)) { + memoryAccesses++; + } + + if (print) + std::cout << std::setw(2) << (cycle + 1) << ": " << origi; + + //non-speculative execution must stall after branch + if (!speculate && has(instr, MASK_EXT, OP_BRANCH)) { + cycle += pipeline - 1; + break; + } + } + //std::cout << " workers: " << workers << std::endl; + cycle++; + } + if (speculate) { + //account for mispredicted branches + int i = 0; + while (branchCount--) { + auto entropy = p.getEntropy(i / 8); + entropy >> (i % 8) * 8; + if ((entropy & 0xff) == 0) // 1/256 chance to flush the pipeline + cycle += pipeline - 1; + } + } + return cycle; +} + +int executeOutOfOrder(randomx::Program& p, randomx::Program& original, bool print, int executionPorts, int memoryPorts, bool speculate, int pipeline) { + int index = 0; + int busyExecutionPorts[2 * RANDOMX_PROGRAM_SIZE] = { 0 }; + int busyMemoryPorts[2 * RANDOMX_PROGRAM_SIZE] = { 0 }; + int int_reg_ready[randomx::RegistersCount] = { 0 }; + int flt_reg_ready[randomx::RegistersCount] = { 0 }; + int fprcReady = 0; + int lastBranch = 0; + int branchCount = 0; + for (; index < RANDOMX_PROGRAM_SIZE; ++index) { + auto& instr = p(index); + int retireCycle = pipeline - 1; + + //non-speculative execution cannot reorder across branches + if (!speculate && !has(instr, MASK_EXT, OP_BRANCH)) + retireCycle = std::max(lastBranch + pipeline - 1, retireCycle); + + //check dependencies + if (has(instr, MASK_SRC, SRC_INT)) { + retireCycle = std::max(retireCycle, int_reg_ready[instr.src]); + int_reg_ready[instr.src] = retireCycle; + } + + if (has(instr, MASK_SRC, SRC_MEM)) { + retireCycle = std::max(retireCycle, int_reg_ready[instr.src] + 1); + //find free memory port + while (busyMemoryPorts[retireCycle - 1] >= memoryPorts) { + retireCycle++; + } + busyMemoryPorts[retireCycle - 1]++; + } + + if (has(instr, MASK_DST, DST_FLT)) { + retireCycle = std::max(retireCycle, flt_reg_ready[instr.dst]); + } + + if (has(instr, MASK_DST, DST_INT)) { + retireCycle = std::max(retireCycle, int_reg_ready[instr.dst]); + } + + //floating point operations depend on the fprc register + if (has(instr, OP_FLOAT)) + retireCycle = std::max(retireCycle, fprcReady); + + //execute + if (has(instr, MASK_DST, DST_MEM)) { + retireCycle = std::max(retireCycle, int_reg_ready[instr.dst] + 1); + //find free memory port + while (busyMemoryPorts[retireCycle - 1] >= memoryPorts) { + retireCycle++; + } + busyMemoryPorts[retireCycle - 1]++; + retireCycle++; + } + + if (has(instr, MASK_DST, DST_FLT)) { + //find free execution port + do { + retireCycle++; + } while (busyExecutionPorts[retireCycle - 1] >= executionPorts); + busyExecutionPorts[retireCycle - 1]++; + flt_reg_ready[instr.dst] = retireCycle; + } + + if (has(instr, MASK_DST, DST_INT)) { + //find free execution port + do { + retireCycle++; + } while (busyExecutionPorts[retireCycle - 1] >= executionPorts); + busyExecutionPorts[retireCycle - 1]++; + int_reg_ready[instr.dst] = retireCycle; + } + + if (has(instr, MASK_EXT, OP_SWAP)) { + int_reg_ready[instr.src] = retireCycle; + } + + if (has(instr, MASK_EXT, OP_CFROUND)) { + do { + retireCycle++; + } while (busyExecutionPorts[retireCycle - 1] >= executionPorts); + busyExecutionPorts[retireCycle - 1]++; + fprcReady = retireCycle; + } + + if (has(instr, MASK_EXT, OP_BRANCH)) { + /*if (!speculate && instr.mod == 1) { //simulated predication + do { + retireCycle++; + } while (busyExecutionPorts[retireCycle - 1] >= executionPorts); + busyExecutionPorts[retireCycle - 1]++; + int_reg_ready[instr.dst] = retireCycle; + }*/ + //else { + lastBranch = std::max(lastBranch, retireCycle); + branchCount++; + //} + } + + //print + auto& origi = original(index); + origi.dst %= randomx::RegistersCount; + origi.src %= randomx::RegistersCount; + if (print) { + std::cout << std::setw(2) << retireCycle << ": " << origi; + if (has(instr, MASK_EXT, OP_BRANCH)) { + std::cout << " jump: " << (int)instr.mod << std::endl; + } + } + } + int cycle = 0; + for (int i = 0; i < randomx::RegistersCount; ++i) { + cycle = std::max(cycle, int_reg_ready[i]); + } + for (int i = 0; i < randomx::RegistersCount; ++i) { + cycle = std::max(cycle, flt_reg_ready[i]); + } + if (speculate) { + //account for mispredicted branches + int i = 0; + while (branchCount--) { + auto entropy = p.getEntropy(i / 8); + entropy >> (i % 8) * 8; + if ((entropy & 0xff) == 0) // 1/256 chance to flush the pipeline + cycle += pipeline - 1; + } + } + return cycle; +} + +#include "../bytecode_machine.hpp" + +//old register selection +struct RegisterUsage { + int32_t lastUsed; + int32_t count; +}; + +inline int getConditionRegister(RegisterUsage(®isterUsage)[randomx::RegistersCount]) { + int min = INT_MAX; + int minCount = 0; + int minIndex; + //prefer registers that have been used as a condition register fewer times + for (unsigned i = 0; i < randomx::RegistersCount; ++i) { + if (registerUsage[i].lastUsed < min || (registerUsage[i].lastUsed == min && registerUsage[i].count < minCount)) { + min = registerUsage[i].lastUsed; + minCount = registerUsage[i].count; + minIndex = i; + } + } + return minIndex; +} + +int analyze(randomx::Program& p) { + int jumpCount = 0; + RegisterUsage registerUsage[randomx::RegistersCount]; + for (unsigned i = 0; i < randomx::RegistersCount; ++i) { + registerUsage[i].lastUsed = -1; + registerUsage[i].count = 0; + } + for (unsigned i = 0; i < RANDOMX_PROGRAM_SIZE; ++i) { + auto& instr = p(i); + int opcode = instr.opcode; + instr.opcode = 0; + + if (opcode < randomx::ceil_IADD_RS) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= SRC_INT; + instr.opcode |= DST_INT; + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_IADD_M) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= SRC_MEM; + instr.opcode |= DST_INT; + if (instr.src != instr.dst) { + instr.imm32 = (instr.getModMem() ? randomx::ScratchpadL1Mask : randomx::ScratchpadL2Mask); + } + else { + instr.imm32 &= randomx::ScratchpadL3Mask; + } + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_ISUB_R) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= DST_INT; + instr.opcode |= SRC_INT; + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_ISUB_M) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= SRC_MEM; + instr.opcode |= DST_INT; + if (instr.src != instr.dst) { + instr.imm32 = (instr.getModMem() ? randomx::ScratchpadL1Mask : randomx::ScratchpadL2Mask); + } + else { + instr.imm32 &= randomx::ScratchpadL3Mask; + } + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_IMUL_R) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= DST_INT; + instr.opcode |= SRC_INT; + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_IMUL_M) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= SRC_MEM; + instr.opcode |= DST_INT; + if (instr.src != instr.dst) { + instr.imm32 = (instr.getModMem() ? randomx::ScratchpadL1Mask : randomx::ScratchpadL2Mask); + } + else { + instr.imm32 &= randomx::ScratchpadL3Mask; + } + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_IMULH_R) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= DST_INT; + instr.opcode |= SRC_INT; + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_IMULH_M) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= SRC_MEM; + instr.opcode |= DST_INT; + if (instr.src != instr.dst) { + instr.imm32 = (instr.getModMem() ? randomx::ScratchpadL1Mask : randomx::ScratchpadL2Mask); + } + else { + instr.imm32 &= randomx::ScratchpadL3Mask; + } + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_ISMULH_R) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= DST_INT; + instr.opcode |= SRC_INT; + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_ISMULH_M) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= SRC_MEM; + instr.opcode |= DST_INT; + if (instr.src != instr.dst) { + instr.imm32 = (instr.getModMem() ? randomx::ScratchpadL1Mask : randomx::ScratchpadL2Mask); + } + else { + instr.imm32 &= randomx::ScratchpadL3Mask; + } + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_IMUL_RCP) { + uint64_t divisor = instr.getImm32(); + if (!randomx::isZeroOrPowerOf2(divisor)) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.opcode |= DST_INT; + registerUsage[instr.dst].lastUsed = i; + } + continue; + } + + if (opcode < randomx::ceil_INEG_R) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.opcode |= DST_INT; + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_IXOR_R) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= DST_INT; + instr.opcode |= SRC_INT; + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_IXOR_M) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= SRC_MEM; + instr.opcode |= DST_INT; + if (instr.src != instr.dst) { + instr.imm32 = (instr.getModMem() ? randomx::ScratchpadL1Mask : randomx::ScratchpadL2Mask); + } + else { + instr.imm32 &= randomx::ScratchpadL3Mask; + } + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_IROR_R) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= DST_INT; + instr.opcode |= SRC_INT; + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_IROL_R) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= DST_INT; + instr.opcode |= SRC_INT; + registerUsage[instr.dst].lastUsed = i; + continue; + } + + if (opcode < randomx::ceil_ISWAP_R) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + if (instr.src != instr.dst) { + instr.opcode |= DST_INT; + instr.opcode |= SRC_INT; + instr.opcode |= OP_SWAP; + registerUsage[instr.dst].lastUsed = i; + registerUsage[instr.src].lastUsed = i; + } + continue; + } + + if (opcode < randomx::ceil_FSWAP_R) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.opcode |= DST_FLT; + continue; + } + + if (opcode < randomx::ceil_FADD_R) { + instr.dst = instr.dst % randomx::RegisterCountFlt; + instr.opcode |= DST_FLT; + instr.opcode |= OP_FLOAT; + continue; + } + + if (opcode < randomx::ceil_FADD_M) { + instr.dst = instr.dst % randomx::RegisterCountFlt; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= DST_FLT; + instr.opcode |= SRC_MEM; + instr.opcode |= OP_FLOAT; + instr.imm32 = (instr.getModMem() ? randomx::ScratchpadL1Mask : randomx::ScratchpadL2Mask); + continue; + } + + if (opcode < randomx::ceil_FSUB_R) { + instr.dst = instr.dst % randomx::RegisterCountFlt; + instr.opcode |= DST_FLT; + instr.opcode |= OP_FLOAT; + continue; + } + + if (opcode < randomx::ceil_FSUB_M) { + instr.dst = instr.dst % randomx::RegisterCountFlt; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= DST_FLT; + instr.opcode |= SRC_MEM; + instr.opcode |= OP_FLOAT; + instr.imm32 = (instr.getModMem() ? randomx::ScratchpadL1Mask : randomx::ScratchpadL2Mask); + continue; + } + + if (opcode < randomx::ceil_FSCAL_R) { + instr.dst = instr.dst % randomx::RegisterCountFlt; + instr.opcode |= DST_FLT; + continue; + } + + if (opcode < randomx::ceil_FMUL_R) { + instr.dst = 4 + instr.dst % randomx::RegisterCountFlt; + instr.opcode |= DST_FLT; + instr.opcode |= OP_FLOAT; + continue; + } + + if (opcode < randomx::ceil_FDIV_M) { + instr.dst = 4 + instr.dst % randomx::RegisterCountFlt; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= DST_FLT; + instr.opcode |= SRC_MEM; + instr.opcode |= OP_FLOAT; + instr.imm32 = (instr.getModMem() ? randomx::ScratchpadL1Mask : randomx::ScratchpadL2Mask); + continue; + } + + if (opcode < randomx::ceil_FSQRT_R) { + instr.dst = 4 + instr.dst % randomx::RegisterCountFlt; + instr.opcode |= DST_FLT; + instr.opcode |= OP_FLOAT; + continue; + } + + if (opcode < randomx::ceil_CBRANCH) { + instr.opcode |= OP_BRANCH; + instr.opcode |= DST_INT; + int reg = instr.dst % randomx::RegistersCount; + int target = registerUsage[reg].lastUsed; + int offset = (i - target); + instr.mod = offset; + jumpCount += offset; + p(target + 1).opcode |= BRANCH_TARGET; + registerUsage[reg].count++; + instr.dst = reg; + //mark all registers as used + for (unsigned j = 0; j < randomx::RegistersCount; ++j) { + registerUsage[j].lastUsed = i; + } + continue; + } + + if (opcode < randomx::ceil_CFROUND) { + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= SRC_INT; + instr.opcode |= OP_CFROUND; + continue; + } + + if (opcode < randomx::ceil_ISTORE) { + instr.dst = instr.dst % randomx::RegistersCount; + instr.src = instr.src % randomx::RegistersCount; + instr.opcode |= DST_MEM; + if (instr.getModCond() < randomx::StoreL3Condition) + instr.imm32 = (instr.getModMem() ? randomx::ScratchpadL1Mask : randomx::ScratchpadL2Mask); + else + instr.imm32 &= randomx::ScratchpadL3Mask; + continue; + } + + if (opcode < randomx::ceil_NOP) { + + } + } + return jumpCount; +} diff --git a/src/RandomX/src/tests/rng-tests.cpp b/src/RandomX/src/tests/rng-tests.cpp new file mode 100644 index 000000000..fed476144 --- /dev/null +++ b/src/RandomX/src/tests/rng-tests.cpp @@ -0,0 +1,93 @@ +/* + cd ~ + wget http://simul.iro.umontreal.ca/testu01/TestU01.zip + unzip TestU01.zip + mkdir TestU01 + cd TestU01-1.2.3 + ./configure --prefix=`pwd`/../TestU01 + make -j8 + make install + cd ~/RandomX + g++ -O3 src/tests/rng-tests.cpp -lm -I ~/TestU01/include -L ~/TestU01/lib -L bin/ -l:libtestu01.a -l:libmylib.a -l:libprobdist.a -lrandomx -o bin/rng-tests -DRANDOMX_GEN=4R -DRANDOMX_TESTU01=Crush + bin/rng-tests 0 +*/ + +extern "C" { + #include "unif01.h" + #include "bbattery.h" +} + +#include "../aes_hash.hpp" +#include "../blake2/blake2.h" +#include "utility.hpp" +#include + +#ifndef RANDOMX_GEN +#error Please define RANDOMX_GEN with a value of 1R or 4R +#endif + +#ifndef RANDOMX_TESTU01 +#error Please define RANDOMX_TESTU01 with a value of SmallCrush, Crush or BigCrush +#endif + +#define STR(x) #x +#define CONCAT(a,b,c) a ## b ## c +#define GEN_NAME(x) "AesGenerator" STR(x) +#define GEN_FUNC(x) CONCAT(fillAes, x, x4) +#define TEST_SUITE(x) CONCAT(bbattery_, x,) + +constexpr int GeneratorStateSize = 64; +constexpr int GeneratorCapacity = GeneratorStateSize / sizeof(uint32_t); + +static unsigned long aesGenBits(void *param, void *state) { + uint32_t* statePtr = (uint32_t*)state; + int* indexPtr = (int*)param; + int stateIndex = *indexPtr; + if(stateIndex >= GeneratorCapacity) { + GEN_FUNC(RANDOMX_GEN)(statePtr, GeneratorStateSize, statePtr); + stateIndex = 0; + } + uint32_t next = statePtr[stateIndex]; + *indexPtr = stateIndex + 1; + return next; +} + +static double aesGenDouble(void *param, void *state) { + return aesGenBits (param, state) / unif01_NORM32; +} + +static void aesWriteState(void* state) { + char* statePtr = (char*)state; + for(int i = 0; i < 4; ++i) { + std::cout << "state" << i << " = "; + outputHex(std::cout, statePtr + (i * 16), 16); + std::cout << std::endl; + } +} + +int main(int argc, char** argv) { + if (argc != 2) { + std::cout << argv[0] << " " << std::endl; + return 1; + } + uint32_t state[GeneratorCapacity] = { 0 }; + int stateIndex = GeneratorCapacity; + char name[] = GEN_NAME(RANDOMX_GEN); + uint64_t seed = strtoull(argv[1], nullptr, 0); + if(seed) { + blake2b(&state, sizeof(state), &seed, sizeof(seed), nullptr, 0); + } + unif01_Gen gen; + gen.state = &state; + gen.param = &stateIndex; + gen.Write = &aesWriteState; + gen.GetU01 = &aesGenDouble; + gen.GetBits = &aesGenBits; + gen.name = (char*)name; + + gen.Write(gen.state); + std::cout << std::endl; + + TEST_SUITE(RANDOMX_TESTU01)(&gen); + return 0; +} \ No newline at end of file diff --git a/src/RandomX/src/tests/runtime-distr.cpp b/src/RandomX/src/tests/runtime-distr.cpp new file mode 100644 index 000000000..b7663d07e --- /dev/null +++ b/src/RandomX/src/tests/runtime-distr.cpp @@ -0,0 +1,172 @@ + +#include +#include "utility.hpp" +#include "stopwatch.hpp" +#include "../dataset.hpp" +#include "../vm_compiled.hpp" +#include "../blake2/blake2.h" + +struct Outlier { + Outlier(int idx, double rtime) : index(idx), runtime(rtime) {} + int index; + double runtime; +}; + +int main(int argc, char** argv) { + constexpr int distributionSize = 100; + int distribution[distributionSize + 1] = { 0 }; + Stopwatch sw; + alignas(16) uint64_t hash[8]; + + uint64_t checksum = 0; + double totalRuntime = 0; + double maxRuntime = 0; + std::vector outliers; + outliers.reserve(25); + randomx_flags flags = RANDOMX_FLAG_DEFAULT; + + bool softAes, largePages, jit, verify; + int totalCount, initThreadCount; + double binSize, offset; + int32_t seed; + + readOption("--verify", argc, argv, verify); + readOption("--jit", argc, argv, jit); + readOption("--softAes", argc, argv, softAes); + readIntOption("--nonces", argc, argv, totalCount, 10000); + readIntOption("--init", argc, argv, initThreadCount, 1); + readFloatOption("--binSize", argc, argv, binSize, 1e-3); + readFloatOption("--offset", argc, argv, offset, 0); + readIntOption("--seed", argc, argv, seed, 0); + readOption("--largePages", argc, argv, largePages); + + if (!verify) { + flags = (randomx_flags)(flags | RANDOMX_FLAG_FULL_MEM); + std::cout << "Measure program runtime" << std::endl; + } + else { + std::cout << "Measure verification time" << std::endl; + } + + std::cout << " - histogram offset: " << offset << std::endl; + std::cout << " - histogram bin size: " << binSize << std::endl; + + if (jit) { + flags = (randomx_flags)(flags | RANDOMX_FLAG_JIT); + std::cout << " - JIT compiled mode" << std::endl; + } + else { + std::cout << " - interpreted mode" << std::endl; + } + + if (softAes) { + std::cout << " - software AES mode" << std::endl; + } + else { + flags = (randomx_flags)(flags | RANDOMX_FLAG_HARD_AES); + std::cout << " - hardware AES mode" << std::endl; + } + + if (largePages) { + flags = (randomx_flags)(flags | RANDOMX_FLAG_LARGE_PAGES); + std::cout << " - large pages mode" << std::endl; + } + else { + std::cout << " - small pages mode" << std::endl; + } + + std::cout << "Initializing..." << std::endl; + + randomx_cache *cache = randomx_alloc_cache(flags); + randomx_dataset *dataset = nullptr; + if (cache == nullptr) { + std::cout << "Cache allocation failed" << std::endl; + return 1; + } + randomx_init_cache(cache, &seed, sizeof seed); + + if (!verify) { + blake2b(&hash, sizeof hash, &seed, sizeof seed, nullptr, 0); + + dataset = randomx_alloc_dataset(flags); + if (dataset == nullptr) { + std::cout << "Dataset allocation failed" << std::endl; + return 1; + } + + std::vector threads; + uint32_t datasetItemCount = randomx_dataset_item_count(); + if (initThreadCount > 1) { + auto perThread = datasetItemCount / initThreadCount; + auto remainder = datasetItemCount % initThreadCount; + uint32_t startItem = 0; + for (int i = 0; i < initThreadCount; ++i) { + auto count = perThread + (i == initThreadCount - 1 ? remainder : 0); + threads.push_back(std::thread(&randomx_init_dataset, dataset, cache, startItem, count)); + startItem += count; + } + for (unsigned i = 0; i < threads.size(); ++i) { + threads[i].join(); + } + } + else { + randomx_init_dataset(dataset, cache, 0, datasetItemCount); + } + randomx_release_cache(cache); + cache = nullptr; + } + + std::cout << "Running " << totalCount << " programs..." << std::endl; + + randomx_vm* vm = randomx_create_vm(flags, cache, dataset); + + if (!verify) { + vm->initScratchpad(&hash); + vm->resetRoundingMode(); + } + + for (int i = 0; i < totalCount; ++i) { + sw.restart(); + if (verify) + randomx_calculate_hash(vm, &i, sizeof i, &hash); + else + vm->run(&hash); + double elapsed = sw.getElapsed(); + //std::cout << "Elapsed: " << elapsed << std::endl; + totalRuntime += elapsed; + if (elapsed > maxRuntime) + maxRuntime = elapsed; + int bin = (elapsed - offset) / binSize; + bool outlier = false; + if (bin < 0) { + bin = 0; + outlier = true; + } + if (bin > distributionSize) { + bin = distributionSize; + outlier = true; + } + if (outlier && outliers.size() < outliers.capacity()) + outliers.push_back(Outlier(i, elapsed)); + distribution[bin]++; + if(!verify) + blake2b(hash, sizeof(hash), vm->getRegisterFile(), sizeof(randomx::RegisterFile), nullptr, 0); + checksum ^= hash[0]; + } + + for (int i = 0; i < distributionSize + 1; ++i) { + std::cout << i << " " << distribution[i] << std::endl; + } + + std::cout << "Average runtime: " << totalRuntime / totalCount << std::endl; + std::cout << "Maximum runtime: " << maxRuntime << std::endl; + std::cout << "Checksum: " << checksum << std::endl; + + std::cout << "Outliers: " << std::endl; + + for (Outlier& ol : outliers) { + std::cout << " " << ol.index << ": " << ol.runtime << std::endl; + } + + return 0; +} \ No newline at end of file diff --git a/src/RandomX/src/tests/scratchpad-entropy.cpp b/src/RandomX/src/tests/scratchpad-entropy.cpp new file mode 100644 index 000000000..ecb3c7d6c --- /dev/null +++ b/src/RandomX/src/tests/scratchpad-entropy.cpp @@ -0,0 +1,50 @@ +#include +#include +#include "utility.hpp" +#include "../randomx.h" +#include "../virtual_machine.hpp" +#include "../blake2/endian.h" + +/* + Writes final scratchpads to disk as files with .spad extension, each file is 2048 KiB. + Command line parameters: + --count N number of files to generate (default = 1) + --seed S different seed will give different outputs (default = 0) + + Entropy can be estimated by compressing the files using 7zip in Ultra mode: + + 7z.exe a -t7z -m0=lzma2 -mx=9 scratchpads.7z *.spad +*/ + +int main(int argc, char** argv) { + int count, seedValue; + + readIntOption("--count", argc, argv, count, 1); + readIntOption("--seed", argc, argv, seedValue, 0); + + std::cout << "Generating " << count << " scratchpad(s) using seed " << seedValue << " ..." << std::endl; + + char seed[4]; + char input[4]; + char hash[RANDOMX_HASH_SIZE]; + + store32(&seed, seedValue); + + randomx_cache *cache = randomx_alloc_cache(RANDOMX_FLAG_DEFAULT); + randomx_init_cache(cache, &seed, sizeof seed); + randomx_vm *vm = randomx_create_vm(RANDOMX_FLAG_DEFAULT, cache, NULL); + + for (int i = 0; i < count; ++i) { + store32(&input, i); + randomx_calculate_hash(vm, &input, sizeof input, hash); + std::string filename("test-"); + filename += std::to_string(i); + filename += ".spad"; + dump((const char*)vm->getScratchpad(), randomx::ScratchpadSize, filename.c_str()); + } + + randomx_destroy_vm(vm); + randomx_release_cache(cache); + + return 0; +} diff --git a/src/RandomX/src/tests/stopwatch.hpp b/src/RandomX/src/tests/stopwatch.hpp new file mode 100644 index 000000000..d1e4912c5 --- /dev/null +++ b/src/RandomX/src/tests/stopwatch.hpp @@ -0,0 +1,84 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include + +class Stopwatch { +public: + Stopwatch(bool startNow = false) { + reset(); + if (startNow) { + start(); + } + } + void reset() { + isRunning = false; + elapsed = 0; + } + void start() { + if (!isRunning) { + startMark = std::chrono::high_resolution_clock::now(); + isRunning = true; + } + } + void restart() { + startMark = std::chrono::high_resolution_clock::now(); + isRunning = true; + elapsed = 0; + } + void stop() { + if (isRunning) { + chrono_t endMark = std::chrono::high_resolution_clock::now(); + uint64_t ns = std::chrono::duration_cast(endMark - startMark).count(); + elapsed += ns; + isRunning = false; + } + } + double getElapsed() const { + return getElapsedNanosec() / 1e+9; + } +private: + using chrono_t = std::chrono::high_resolution_clock::time_point; + using sw_unit = std::chrono::nanoseconds; + chrono_t startMark; + uint64_t elapsed; + bool isRunning; + + uint64_t getElapsedNanosec() const { + uint64_t elns = elapsed; + if (isRunning) { + chrono_t endMark = std::chrono::high_resolution_clock::now(); + uint64_t ns = std::chrono::duration_cast(endMark - startMark).count(); + elns += ns; + } + return elns; + } +}; \ No newline at end of file diff --git a/src/RandomX/src/tests/superscalar-avalanche.cpp b/src/RandomX/src/tests/superscalar-avalanche.cpp new file mode 100644 index 000000000..d9f916cdd --- /dev/null +++ b/src/RandomX/src/tests/superscalar-avalanche.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include "../superscalar.hpp" +#include "../intrin_portable.h" + +const uint8_t seed[32] = { 191, 182, 222, 175, 249, 89, 134, 104, 241, 68, 191, 62, 162, 166, 61, 64, 123, 191, 227, 193, 118, 60, 188, 53, 223, 133, 175, 24, 123, 230, 55, 74 }; + +int main() { + + int insensitiveProgCount[64] = { 0 }; + std::vector dummy; + for (int bit = 0; bit < 64; ++bit) { + for (int i = 0; i < 10000; ++i) { + uint64_t ra[8] = { + 6364136223846793005ULL, + 9298410992540426748ULL, + 12065312585734608966ULL, + 9306329213124610396ULL, + 5281919268842080866ULL, + 10536153434571861004ULL, + 3398623926847679864ULL, + 9549104520008361294ULL, + }; + uint64_t rb[8]; + memcpy(rb, ra, sizeof rb); + rb[0] ^= (1ULL << bit); + randomx::SuperscalarProgram p; + randomx::Blake2Generator gen(seed, sizeof seed, i); + randomx::generateSuperscalar(p, gen); + randomx::executeSuperscalar(ra, p, nullptr); + randomx::executeSuperscalar(rb, p, nullptr); + uint64_t diff = 0; + for (int j = 0; j < 8; ++j) { + diff += __popcnt64(ra[j] ^ rb[j]); + } + if (diff < 192 || diff > 320) { + std::cout << "Seed: " << i << " diff = " << diff << std::endl; + insensitiveProgCount[bit]++; + } + } + } + for (int bit = 0; bit < 64; ++bit) { + std::cout << bit << " " << insensitiveProgCount[bit] << std::endl; + } + + return 0; +} \ No newline at end of file diff --git a/src/RandomX/src/tests/superscalar-init.cpp b/src/RandomX/src/tests/superscalar-init.cpp new file mode 100644 index 000000000..15554bbd6 --- /dev/null +++ b/src/RandomX/src/tests/superscalar-init.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include "../superscalar.hpp" +#include "../common.hpp" + +int main() { + std::cout << "THIS PROGRAM REQUIRES MORE THAN 16 GB OF RAM TO COMPLETE" << std::endl; + std::vector dummy; + constexpr uint64_t superscalarMul0 = 6364136223846793005ULL; + constexpr uint64_t superscalarAdd1 = 0x810A978A59F5A1FC; //9298410992540426748ULL; //9298410992540426048ULL + constexpr uint64_t superscalarAdd2 = 12065312585734608966ULL; + constexpr uint64_t superscalarAdd3 = 0x8126B91CBF22495C; //9306329213124610396ULL; + constexpr uint64_t superscalarAdd4 = 5281919268842080866ULL; + constexpr uint64_t superscalarAdd5 = 10536153434571861004ULL; + constexpr uint64_t superscalarAdd6 = 3398623926847679864ULL; + constexpr uint64_t superscalarAdd7 = 9549104520008361294ULL; + constexpr uint32_t totalItems = randomx::DatasetSize / randomx::CacheLineSize; + std::unordered_set registerValues; + registerValues.reserve(totalItems); + registerValues.rehash(totalItems); + int collisionCount[9] = { 0 }; + for (uint32_t itemNumber = 0; itemNumber < totalItems; ++itemNumber) { + uint64_t rl[8]; + rl[0] = (itemNumber + 1) * superscalarMul0; + rl[1] = rl[0] ^ superscalarAdd1; + rl[2] = rl[0] ^ superscalarAdd2; + rl[3] = rl[0] ^ superscalarAdd3; + rl[4] = rl[0] ^ superscalarAdd4; + rl[5] = rl[0] ^ superscalarAdd5; + rl[6] = rl[0] ^ superscalarAdd6; + rl[7] = rl[0] ^ superscalarAdd7; + int blockCollisions = 0; + for (int i = 0; i < 8; ++i) { + uint64_t reducedValue = rl[i] & 0x3FFFFFFFFFFFF8; //bits 3-53 only + if (registerValues.find(reducedValue) != registerValues.end()) { + blockCollisions++; + std::cout << "Item " << itemNumber << ": collision of register r" << i << std::endl; + } + else { + registerValues.insert(reducedValue); + } + } + collisionCount[blockCollisions]++; + if ((itemNumber % (320 * 1024)) == 0) + std::cout << "Item " << itemNumber << " processed" << std::endl; + } + + for (int i = 0; i < 9; ++i) { + std::cout << i << " register(s) collide in " << collisionCount[i] << " items" << std::endl; + } + + return 0; +} \ No newline at end of file diff --git a/src/RandomX/src/tests/superscalar-stats.cpp b/src/RandomX/src/tests/superscalar-stats.cpp new file mode 100644 index 000000000..50924e5ba --- /dev/null +++ b/src/RandomX/src/tests/superscalar-stats.cpp @@ -0,0 +1,52 @@ +#include +#include +#include "../superscalar.hpp" +#include "../blake2_generator.hpp" + +const uint8_t seed[32] = { 191, 182, 222, 175, 249, 89, 134, 104, 241, 68, 191, 62, 162, 166, 61, 64, 123, 191, 227, 193, 118, 60, 188, 53, 223, 133, 175, 24, 123, 230, 55, 74 }; + +int main() { + + constexpr int count = 1000000; + int isnCounts[(int)randomx::SuperscalarInstructionType::COUNT] = { 0 }; + int64_t asicLatency = 0; + int64_t codesize = 0; + int64_t cpuLatency = 0; + int64_t macroOps = 0; + int64_t mulCount = 0; + int64_t size = 0; + for (int i = 0; i < count; ++i) { + randomx::SuperscalarProgram prog; + randomx::Blake2Generator gen(seed, sizeof(seed), i); + randomx::generateSuperscalar(prog, gen); + asicLatency += prog.asicLatency; + codesize += prog.codeSize; + cpuLatency += prog.cpuLatency; + macroOps += prog.macroOps; + mulCount += prog.mulCount; + size += prog.getSize(); + + for (unsigned j = 0; j < prog.getSize(); ++j) { + isnCounts[prog(j).opcode]++; + } + + if ((i + 1) % (count / 100) == 0) { + std::cout << "Completed " << ((i + 1) / (count / 100)) << "% ..." << std::endl; + } + } + + std::cout << "Avg. IPC: " << (macroOps / (double)cpuLatency) << std::endl; + std::cout << "Avg. ASIC latency: " << (asicLatency / (double)count) << std::endl; + std::cout << "Avg. CPU latency: " << (cpuLatency / (double)count) << std::endl; + std::cout << "Avg. code size: " << (codesize / (double)count) << std::endl; + std::cout << "Avg. x86 ops: " << (macroOps / (double)count) << std::endl; + std::cout << "Avg. mul. count: " << (mulCount / (double)count) << std::endl; + std::cout << "Avg. RandomX ops: " << (size / (double)count) << std::endl; + + std::cout << "Frequencies: " << std::endl; + for (unsigned j = 0; j < (int)randomx::SuperscalarInstructionType::COUNT; ++j) { + std::cout << j << " " << isnCounts[j] << " " << isnCounts[j] / (double)size << std::endl; + } + + return 0; +} \ No newline at end of file diff --git a/src/RandomX/src/tests/tests.cpp b/src/RandomX/src/tests/tests.cpp new file mode 100644 index 000000000..412585b1d --- /dev/null +++ b/src/RandomX/src/tests/tests.cpp @@ -0,0 +1,1096 @@ +#ifdef NDEBUG +#undef NDEBUG +#endif + +#include +#include +#include "utility.hpp" +#include "../bytecode_machine.hpp" +#include "../dataset.hpp" +#include "../blake2/endian.h" +#include "../blake2/blake2.h" +#include "../blake2_generator.hpp" +#include "../superscalar.hpp" +#include "../reciprocal.h" +#include "../intrin_portable.h" +#include "../jit_compiler.hpp" +#include "../aes_hash.hpp" + +randomx_cache* cache; +randomx_vm* vm = nullptr; + +template +void initCache(const char (&key)[N]) { + assert(cache != nullptr); + randomx_init_cache(cache, key, N - 1); + if (vm != nullptr) + randomx_vm_set_cache(vm, cache); +} + +template +void calcStringHash(const char(&key)[K], const char(&input)[H], void* output) { + initCache(key); + assert(vm != nullptr); + randomx_calculate_hash(vm, input, H - 1, output); +} + +template +void calcHexHash(const char(&key)[K], const char(&hex)[H], void* output) { + initCache(key); + assert(vm != nullptr); + char input[H / 2]; + hex2bin((char*)hex, H - 1, input); + randomx_calculate_hash(vm, input, sizeof(input), output); +} + +int testNo = 0; +int skipped = 0; + +template +void runTest(const char* name, bool condition, FUNC f) { + std::cout << "["; + std::cout.width(2); + std::cout << std::right << ++testNo << "] "; + std::cout.width(40); + std::cout << std::left << name << " ... "; + std::cout.flush(); + if (condition) { + f(); + std::cout << "PASSED" << std::endl; + } + else { + std::cout << "SKIPPED" << std::endl; + skipped++; + } +} + +int main() { + char testHash[32]; + + //std::cout << "Allocating randomx_cache..." << std::endl; + cache = randomx_alloc_cache(RANDOMX_FLAG_DEFAULT); + + runTest("Cache initialization", RANDOMX_ARGON_ITERATIONS == 3 && RANDOMX_ARGON_LANES == 1 && RANDOMX_ARGON_MEMORY == 262144 && stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), []() { + initCache("test key 000"); + uint64_t* cacheMemory = (uint64_t*)cache->memory; + assert(cacheMemory[0] == 0x191e0e1d23c02186); + assert(cacheMemory[1568413] == 0xf1b62fe6210bf8b1); + assert(cacheMemory[33554431] == 0x1f47f056d05cd99b); + }); + + runTest("SuperscalarHash generator", RANDOMX_SUPERSCALAR_LATENCY == 170, []() { + char sprogHash[32]; + randomx::SuperscalarProgram sprog; + const char key[] = "test key 000"; + constexpr size_t keySize = sizeof(key) - 1; + randomx::Blake2Generator gen(key, keySize); + + const char superscalarReferences[10][65] = { + "d3a4a6623738756f77e6104469102f082eff2a3e60be7ad696285ef7dfc72a61", + "f5e7e0bbc7e93c609003d6359208688070afb4a77165a552ff7be63b38dfbc86", + "85ed8b11734de5b3e9836641413a8f36e99e89694f419c8cd25c3f3f16c40c5a", + "5dd956292cf5d5704ad99e362d70098b2777b2a1730520be52f772ca48cd3bc0", + "6f14018ca7d519e9b48d91af094c0f2d7e12e93af0228782671a8640092af9e5", + "134be097c92e2c45a92f23208cacd89e4ce51f1009a0b900dbe83b38de11d791", + "268f9392c20c6e31371a5131f82bd7713d3910075f2f0468baafaa1abd2f3187", + "c668a05fd909714ed4a91e8d96d67b17e44329e88bc71e0672b529a3fc16be47", + "99739351315840963011e4c5d8e90ad0bfed3facdcb713fe8f7138fbf01c4c94", + "14ab53d61880471f66e80183968d97effd5492b406876060e595fcf9682f9295", + }; + + for (int i = 0; i < 10; ++i) { + randomx::generateSuperscalar(sprog, gen); + blake2b(sprogHash, sizeof(sprogHash), &sprog.programBuffer, sizeof(randomx::Instruction) * sprog.getSize(), nullptr, 0); + assert(equalsHex(sprogHash, superscalarReferences[i])); + } + }); + + runTest("randomx_reciprocal", true, []() { + assert(randomx_reciprocal(3) == 12297829382473034410U); + assert(randomx_reciprocal(13) == 11351842506898185609U); + assert(randomx_reciprocal(33) == 17887751829051686415U); + assert(randomx_reciprocal(65537) == 18446462603027742720U); + assert(randomx_reciprocal(15000001) == 10316166306300415204U); + assert(randomx_reciprocal(3845182035) == 10302264209224146340U); + assert(randomx_reciprocal(0xffffffff) == 9223372039002259456U); + }); + + runTest("randomx_reciprocal_fast", RANDOMX_HAVE_FAST_RECIPROCAL, []() { + assert(randomx_reciprocal_fast(3) == 12297829382473034410U); + assert(randomx_reciprocal_fast(13) == 11351842506898185609U); + assert(randomx_reciprocal_fast(33) == 17887751829051686415U); + assert(randomx_reciprocal_fast(65537) == 18446462603027742720U); + assert(randomx_reciprocal_fast(15000001) == 10316166306300415204U); + assert(randomx_reciprocal_fast(3845182035) == 10302264209224146340U); + assert(randomx_reciprocal_fast(0xffffffff) == 9223372039002259456U); + }); + + runTest("Dataset initialization (interpreter)", stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), []() { + initCache("test key 000"); + uint64_t datasetItem[8]; + randomx::initDatasetItem(cache, (uint8_t*)&datasetItem, 0); + assert(datasetItem[0] == 0x680588a85ae222db); + randomx::initDatasetItem(cache, (uint8_t*)&datasetItem, 10000000); + assert(datasetItem[0] == 0x7943a1f6186ffb72); + randomx::initDatasetItem(cache, (uint8_t*)&datasetItem, 20000000); + assert(datasetItem[0] == 0x9035244d718095e1); + randomx::initDatasetItem(cache, (uint8_t*)&datasetItem, 30000000); + assert(datasetItem[0] == 0x145a5091f7853099); + }); + + runTest("Dataset initialization (compiler)", RANDOMX_HAVE_COMPILER && stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), []() { + initCache("test key 000"); + randomx::JitCompiler jit; + jit.generateSuperscalarHash(cache->programs, cache->reciprocalCache); + jit.generateDatasetInitCode(); +#ifdef RANDOMX_FORCE_SECURE + jit.enableExecution(); +#else + jit.enableAll(); +#endif + uint64_t datasetItem[8]; + jit.getDatasetInitFunc()(cache, (uint8_t*)&datasetItem, 0, 1); + assert(datasetItem[0] == 0x680588a85ae222db); + jit.getDatasetInitFunc()(cache, (uint8_t*)&datasetItem, 10000000, 10000001); + assert(datasetItem[0] == 0x7943a1f6186ffb72); + jit.getDatasetInitFunc()(cache, (uint8_t*)&datasetItem, 20000000, 20000001); + assert(datasetItem[0] == 0x9035244d718095e1); + jit.getDatasetInitFunc()(cache, (uint8_t*)&datasetItem, 30000000, 30000001); + assert(datasetItem[0] == 0x145a5091f7853099); + }); + + runTest("AesGenerator1R", true, []() { + char state[64] = { 0 }; + hex2bin("6c19536eb2de31b6c0065f7f116e86f960d8af0c57210a6584c3237b9d064dc7", 64, state); + fillAes1Rx4(state, sizeof(state), state); + assert(equalsHex(state, "fa89397dd6ca422513aeadba3f124b5540324c4ad4b6db434394307a17c833ab")); + }); + + randomx::NativeRegisterFile reg; + randomx::BytecodeMachine decoder; + randomx::InstructionByteCode ibc; + alignas(16) randomx::ProgramConfiguration config; + constexpr int registerHigh = 192; + constexpr int registerDst = 0; + constexpr int registerSrc = 1; + int pc = 0; + constexpr uint32_t imm32 = 3234567890; + constexpr uint64_t imm64 = signExtend2sCompl(imm32); + + decoder.beginCompilation(reg); + + runTest("IADD_RS (decode)", RANDOMX_FREQ_IADD_RS > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IADD_RS - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.mod = UINT8_MAX; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IADD_RS); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + assert(ibc.shift == 3); + assert(ibc.imm == 0); + }); + + runTest("IADD_RS (execute)", RANDOMX_FREQ_IADD_RS > 0, [&] { + reg.r[registerDst] = 0x8000000000000000; + reg.r[registerSrc] = 0x1000000000000000; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(reg.r[registerDst] == 0); + }); + + runTest("IADD_RS with immediate (decode)", RANDOMX_FREQ_IADD_RS > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IADD_RS - 1; + instr.mod = 8; + instr.dst = registerHigh | randomx::RegisterNeedsDisplacement; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IADD_RS); + assert(ibc.idst == ®.r[randomx::RegisterNeedsDisplacement]); + assert(ibc.isrc == ®.r[registerSrc]); + assert(ibc.shift == 2); + assert(ibc.imm == imm64); + }); + + runTest("IADD_RS with immediate (decode)", RANDOMX_FREQ_IADD_RS > 0, [&] { + reg.r[randomx::RegisterNeedsDisplacement] = 0x8000000000000000; + reg.r[registerSrc] = 0x2000000000000000; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(reg.r[randomx::RegisterNeedsDisplacement] == imm64); + }); + + runTest("IADD_M (decode)", RANDOMX_FREQ_IADD_M > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IADD_M - 1; + instr.mod = 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IADD_M); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + assert(ibc.imm == imm64); + assert(ibc.memMask == randomx::ScratchpadL1Mask); + }); + + runTest("ISUB_R (decode)", RANDOMX_FREQ_ISUB_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_ISUB_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::ISUB_R); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + }); + + runTest("ISUB_R (execute)", RANDOMX_FREQ_ISUB_R > 0, [&] { + reg.r[registerDst] = 1; + reg.r[registerSrc] = 0xFFFFFFFF; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(reg.r[registerDst] == 0xFFFFFFFF00000002); + }); + + runTest("ISUB_R with immediate (decode)", RANDOMX_FREQ_ISUB_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_ISUB_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerDst; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::ISUB_R); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == &ibc.imm); + }); + + runTest("ISUB_R with immediate (decode)", RANDOMX_FREQ_ISUB_R > 0, [&] { + reg.r[registerDst] = 0; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(reg.r[registerDst] == (~imm64 + 1)); + }); + + runTest("ISUB_M (decode)", RANDOMX_FREQ_ISUB_M > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_ISUB_M - 1; + instr.mod = 0; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::ISUB_M); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + assert(ibc.imm == imm64); + assert(ibc.memMask == randomx::ScratchpadL2Mask); + }); + + runTest("IMUL_R (decode)", RANDOMX_FREQ_IMUL_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IMUL_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IMUL_R); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + }); + + runTest("IMUL_R (execute)", RANDOMX_FREQ_IMUL_R > 0, [&] { + reg.r[registerDst] = 0xBC550E96BA88A72B; + reg.r[registerSrc] = 0xF5391FA9F18D6273; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(reg.r[registerDst] == 0x28723424A9108E51); + }); + + runTest("IMUL_R with immediate (decode)", RANDOMX_FREQ_IMUL_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IMUL_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerDst; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IMUL_R); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == &ibc.imm); + }); + + runTest("IMUL_R with immediate (execute)", RANDOMX_FREQ_IMUL_R > 0, [&] { + reg.r[registerDst] = 1; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(reg.r[registerDst] == imm64); + }); + + runTest("IMUL_M (decode)", RANDOMX_FREQ_IMUL_M > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IMUL_M - 1; + instr.mod = 0; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerDst; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IMUL_M); + assert(ibc.idst == ®.r[registerDst]); + assert(*ibc.isrc == 0); + assert(ibc.imm == imm64); + assert(ibc.memMask == randomx::ScratchpadL3Mask); + }); + + runTest("IMULH_R (decode)", RANDOMX_FREQ_IMULH_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IMULH_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IMULH_R); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + }); + + runTest("IMULH_R (execute)", RANDOMX_FREQ_IMULH_R > 0, [&] { + reg.r[registerDst] = 0xBC550E96BA88A72B; + reg.r[registerSrc] = 0xF5391FA9F18D6273; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(reg.r[registerDst] == 0xB4676D31D2B34883); + }); + + runTest("IMULH_R squared (decode)", RANDOMX_FREQ_IMULH_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IMULH_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerDst; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IMULH_R); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerDst]); + }); + + runTest("IMULH_M (decode)", RANDOMX_FREQ_IMULH_M > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IMULH_M - 1; + instr.mod = 0; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IMULH_M); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + assert(ibc.imm == imm64); + assert(ibc.memMask == randomx::ScratchpadL2Mask); + }); + + runTest("ISMULH_R (decode)", RANDOMX_FREQ_ISMULH_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_ISMULH_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::ISMULH_R); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + }); + + runTest("ISMULH_R (execute)", RANDOMX_FREQ_ISMULH_R > 0, [&] { + reg.r[registerDst] = 0xBC550E96BA88A72B; + reg.r[registerSrc] = 0xF5391FA9F18D6273; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(reg.r[registerDst] == 0x02D93EF1269D3EE5); + }); + + runTest("ISMULH_R squared (decode)", RANDOMX_FREQ_ISMULH_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_ISMULH_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerDst; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::ISMULH_R); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerDst]); + }); + + runTest("ISMULH_M (decode)", RANDOMX_FREQ_ISMULH_M > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_ISMULH_M - 1; + instr.mod = 3; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::ISMULH_M); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + assert(ibc.imm == imm64); + assert(ibc.memMask == randomx::ScratchpadL1Mask); + }); + + runTest("IMUL_RCP (decode)", RANDOMX_FREQ_IMUL_RCP > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IMUL_RCP - 1; + instr.dst = registerHigh | registerDst; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IMUL_R); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == &ibc.imm); + assert(ibc.imm == randomx_reciprocal(imm32)); + }); + + runTest("IMUL_RCP zero imm32 (decode)", RANDOMX_FREQ_IMUL_RCP > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IMUL_RCP - 1; + instr.setImm32(0); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::NOP); + }); + + runTest("INEG_R (decode)", RANDOMX_FREQ_INEG_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_INEG_R - 1; + instr.dst = registerHigh | registerDst; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::INEG_R); + assert(ibc.idst == ®.r[registerDst]); + }); + + runTest("INEG_R (execute)", RANDOMX_FREQ_INEG_R > 0, [&] { + reg.r[registerDst] = 0xFFFFFFFFFFFFFFFF; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(reg.r[registerDst] == 1); + }); + + runTest("IXOR_R (decode)", RANDOMX_FREQ_IXOR_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IXOR_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IXOR_R); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + }); + + runTest("IXOR_R (execute)", RANDOMX_FREQ_IMUL_R > 0, [&] { + reg.r[registerDst] = 0x8888888888888888; + reg.r[registerSrc] = 0xAAAAAAAAAAAAAAAA; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(reg.r[registerDst] == 0x2222222222222222); + }); + + runTest("IXOR_R with immediate (decode)", RANDOMX_FREQ_IXOR_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IXOR_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerDst; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IXOR_R); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == &ibc.imm); + }); + + runTest("IXOR_R with immediate (execute)", RANDOMX_FREQ_IXOR_R > 0, [&] { + reg.r[registerDst] = 0xFFFFFFFFFFFFFFFF; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(reg.r[registerDst] == ~imm64); + }); + + runTest("IXOR_M (decode)", RANDOMX_FREQ_IXOR_M > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IXOR_M - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerDst; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IXOR_M); + assert(ibc.idst == ®.r[registerDst]); + assert(*ibc.isrc == 0); + assert(ibc.imm == imm64); + assert(ibc.memMask == randomx::ScratchpadL3Mask); + }); + + runTest("IROR_R (decode)", RANDOMX_FREQ_IROR_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IROR_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IROR_R); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + }); + + runTest("IROR_R (execute)", RANDOMX_FREQ_IROR_R > 0, [&] { + reg.r[registerDst] = 953360005391419562; + reg.r[registerSrc] = 4569451684712230561; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(reg.r[registerDst] == 0xD835C455069D81EF); + }); + + runTest("IROL_R (decode)", RANDOMX_FREQ_IROL_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_IROL_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::IROL_R); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + }); + + runTest("IROL_R (execute)", RANDOMX_FREQ_IROL_R > 0, [&] { + reg.r[registerDst] = 953360005391419562; + reg.r[registerSrc] = 4569451684712230561; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(reg.r[registerDst] == 6978065200552740799); + }); + + runTest("ISWAP_R (decode)", RANDOMX_FREQ_ISWAP_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_ISWAP_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::ISWAP_R); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + }); + + runTest("ISWAP_R (execute)", RANDOMX_FREQ_ISWAP_R > 0, [&] { + reg.r[registerDst] = 953360005391419562; + reg.r[registerSrc] = 4569451684712230561; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(reg.r[registerDst] == 4569451684712230561); + assert(reg.r[registerSrc] == 953360005391419562); + }); + + runTest("FSWAP_R (decode)", RANDOMX_FREQ_FSWAP_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_FSWAP_R - 1; + instr.dst = registerHigh | registerDst; + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::FSWAP_R); + assert(ibc.fdst == ®.f[registerDst]); + }); + + runTest("FSWAP_R (execute)", RANDOMX_FREQ_FSWAP_R > 0, [&] { + alignas(16) uint64_t vec[2]; + reg.f[registerDst] = rx_set_vec_f128(953360005391419562, 4569451684712230561); + decoder.executeInstruction(ibc, pc, nullptr, config); + rx_store_vec_f128((double*)&vec, reg.f[registerDst]); + assert(equalsHex((const char*)&vec, "aa886bb0df033b0da12e95e518f4693f")); + }); + + runTest("FADD_R (decode)", RANDOMX_FREQ_FADD_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_FADD_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::FADD_R); + assert(ibc.fdst == ®.f[registerDst]); + assert(ibc.fsrc == ®.a[registerSrc]); + }); + + runTest("FADD_R RoundToNearest (execute)", RANDOMX_FREQ_FADD_R > 0, [&] { + alignas(16) uint64_t vec[2]; + reg.f[registerDst] = rx_set_vec_f128(0x3ffd2c97cc4ef015, 0xc1ce30b3c4223576); + reg.a[registerSrc] = rx_set_vec_f128(0x402a26a86a60c8fb, 0x40b8f684057a59e1); + rx_set_rounding_mode(RoundToNearest); + decoder.executeInstruction(ibc, pc, nullptr, config); + rx_store_vec_f128((double*)&vec, reg.f[registerDst]); + assert(equalsHex(&vec, "b932e048a730cec1fea6ea633bcc2d40")); + }); + + runTest("FADD_R RoundDown (execute)", RANDOMX_FREQ_FADD_R > 0, [&] { + alignas(16) uint64_t vec[2]; + reg.f[registerDst] = rx_set_vec_f128(0x3ffd2c97cc4ef015, 0xc1ce30b3c4223576); + reg.a[registerSrc] = rx_set_vec_f128(0x402a26a86a60c8fb, 0x40b8f684057a59e1); + rx_set_rounding_mode(RoundDown); + decoder.executeInstruction(ibc, pc, nullptr, config); + rx_store_vec_f128((double*)&vec, reg.f[registerDst]); + assert(equalsHex(&vec, "b932e048a730cec1fda6ea633bcc2d40")); + }); + + runTest("FADD_R RoundUp (execute)", RANDOMX_FREQ_FADD_R > 0, [&] { + alignas(16) uint64_t vec[2]; + reg.f[registerDst] = rx_set_vec_f128(0x3ffd2c97cc4ef015, 0xc1ce30b3c4223576); + reg.a[registerSrc] = rx_set_vec_f128(0x402a26a86a60c8fb, 0x40b8f684057a59e1); + rx_set_rounding_mode(RoundUp); + decoder.executeInstruction(ibc, pc, nullptr, config); + rx_store_vec_f128((double*)&vec, reg.f[registerDst]); + assert(equalsHex(&vec, "b832e048a730cec1fea6ea633bcc2d40")); + }); + + runTest("FADD_R RoundToZero (execute)", RANDOMX_FREQ_FADD_R > 0, [&] { + alignas(16) uint64_t vec[2]; + reg.f[registerDst] = rx_set_vec_f128(0x3ffd2c97cc4ef015, 0xc1ce30b3c4223576); + reg.a[registerSrc] = rx_set_vec_f128(0x402a26a86a60c8fb, 0x40b8f684057a59e1); + rx_set_rounding_mode(RoundToZero); + decoder.executeInstruction(ibc, pc, nullptr, config); + rx_store_vec_f128((double*)&vec, reg.f[registerDst]); + assert(equalsHex(&vec, "b832e048a730cec1fda6ea633bcc2d40")); + }); + + runTest("FADD_M (decode)", RANDOMX_FREQ_FADD_M > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_FADD_M - 1; + instr.mod = 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::FADD_M); + assert(ibc.fdst == ®.f[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + assert(ibc.imm == imm64); + assert(ibc.memMask == randomx::ScratchpadL1Mask); + }); + + runTest("FADD_M (execute)", RANDOMX_FREQ_FADD_R > 0, [&] { + uint64_t mockScratchpad; + store64(&mockScratchpad, 0x1234567890abcdef); + alignas(16) uint64_t vec[2]; + reg.f[registerDst] = rx_set_vec_f128(0, 0); + reg.r[registerSrc] = 0xFFFFFFFFFFFFE930; + rx_set_rounding_mode(RoundToNearest); + decoder.executeInstruction(ibc, pc, (uint8_t*)&mockScratchpad, config); + rx_store_vec_f128((double*)&vec, reg.f[registerDst]); + assert(equalsHex(&vec, "000040840cd5dbc1000000785634b241")); + }); + + runTest("FSUB_R (decode)", RANDOMX_FREQ_FSUB_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_FSUB_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::FSUB_R); + assert(ibc.fdst == ®.f[registerDst]); + assert(ibc.fsrc == ®.a[registerSrc]); + }); + + runTest("FSUB_M (decode)", RANDOMX_FREQ_FSUB_M > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_FSUB_M - 1; + instr.mod = 2; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::FSUB_M); + assert(ibc.fdst == ®.f[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + assert(ibc.imm == imm64); + assert(ibc.memMask == randomx::ScratchpadL1Mask); + }); + + runTest("FSCAL_R (decode)", RANDOMX_FREQ_FSCAL_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_FSCAL_R - 1; + instr.dst = registerHigh | registerDst; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::FSCAL_R); + assert(ibc.fdst == ®.f[registerDst]); + }); + + runTest("FSCAL_R (execute)", RANDOMX_FREQ_FSCAL_R > 0, [&] { + alignas(16) uint64_t vec[2]; + reg.f[registerDst] = rx_set_vec_f128(0x41dbc35cef248783, 0x40fdfdabb6173d07); + decoder.executeInstruction(ibc, pc, nullptr, config); + rx_store_vec_f128((double*)&vec, reg.f[registerDst]); + assert(equalsHex((const char*)&vec, "073d17b6abfd0dc0838724ef5cc32bc1")); + }); + + runTest("FMUL_R (decode)", RANDOMX_FREQ_FMUL_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_FMUL_R - 1; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::FMUL_R); + assert(ibc.fdst == ®.e[registerDst]); + assert(ibc.fsrc == ®.a[registerSrc]); + }); + + runTest("FMUL_R RoundToNearest (execute)", RANDOMX_FREQ_FMUL_R > 0, [&] { + alignas(16) uint64_t vec[2]; + reg.e[registerDst] = rx_set_vec_f128(0x41dbc35cef248783, 0x40fdfdabb6173d07); + reg.a[registerSrc] = rx_set_vec_f128(0x40eba861aa31c7c0, 0x41c4561212ae2d50); + rx_set_rounding_mode(RoundToNearest); + decoder.executeInstruction(ibc, pc, nullptr, config); + rx_store_vec_f128((double*)&vec, reg.e[registerDst]); + assert(equalsHex(&vec, "69697aff350fd3422f1589cdecfed742")); + }); + + runTest("FMUL_R RoundDown/RoundToZero (execute)", RANDOMX_FREQ_FMUL_R > 0, [&] { + alignas(16) uint64_t vec[2]; + reg.e[registerDst] = rx_set_vec_f128(0x41dbc35cef248783, 0x40fdfdabb6173d07); + reg.a[registerSrc] = rx_set_vec_f128(0x40eba861aa31c7c0, 0x41c4561212ae2d50); + rx_set_rounding_mode(RoundDown); + decoder.executeInstruction(ibc, pc, nullptr, config); + rx_store_vec_f128((double*)&vec, reg.e[registerDst]); + assert(equalsHex(&vec, "69697aff350fd3422e1589cdecfed742")); + }); + + runTest("FMUL_R RoundUp (execute)", RANDOMX_FREQ_FMUL_R > 0, [&] { + alignas(16) uint64_t vec[2]; + reg.e[registerDst] = rx_set_vec_f128(0x41dbc35cef248783, 0x40fdfdabb6173d07); + reg.a[registerSrc] = rx_set_vec_f128(0x40eba861aa31c7c0, 0x41c4561212ae2d50); + rx_set_rounding_mode(RoundUp); + decoder.executeInstruction(ibc, pc, nullptr, config); + rx_store_vec_f128((double*)&vec, reg.e[registerDst]); + assert(equalsHex(&vec, "6a697aff350fd3422f1589cdecfed742")); + }); + + runTest("FDIV_M (decode)", RANDOMX_FREQ_FDIV_M > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_FDIV_M - 1; + instr.mod = 3; + instr.dst = registerHigh | registerDst; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::FDIV_M); + assert(ibc.fdst == ®.e[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + assert(ibc.imm == imm64); + assert(ibc.memMask == randomx::ScratchpadL1Mask); + }); + + runTest("FDIV_M RoundToNearest (execute)", RANDOMX_FREQ_FDIV_M > 0, [&] { + alignas(16) uint64_t vec[2]; + alignas(16) uint32_t mockScratchpad[2]; + store32(&mockScratchpad[0], 0xd350a1b6); + store32(&mockScratchpad[1], 0x8b2460d9); + store64(&config.eMask[0], 0x3a0000000005d11a); + store64(&config.eMask[1], 0x39000000001ba31e); + reg.e[registerDst] = rx_set_vec_f128(0x41937f76fede16ee, 0x411b414296ce93b6); + reg.r[registerSrc] = 0xFFFFFFFFFFFFE930; + rx_set_rounding_mode(RoundToNearest); + decoder.executeInstruction(ibc, pc, (uint8_t*)&mockScratchpad, config); + rx_store_vec_f128((double*)&vec, reg.e[registerDst]); + assert(equalsHex(&vec, "e7b269639484434632474a66635ba547")); + }); + + runTest("FDIV_M RoundDown/RoundToZero (execute)", RANDOMX_FREQ_FDIV_M > 0, [&] { + alignas(16) uint64_t vec[2]; + alignas(16) uint32_t mockScratchpad[2]; + store32(&mockScratchpad[0], 0xd350a1b6); + store32(&mockScratchpad[1], 0x8b2460d9); + store64(&config.eMask[0], 0x3a0000000005d11a); + store64(&config.eMask[1], 0x39000000001ba31e); + reg.e[registerDst] = rx_set_vec_f128(0x41937f76fede16ee, 0x411b414296ce93b6); + reg.r[registerSrc] = 0xFFFFFFFFFFFFE930; + rx_set_rounding_mode(RoundDown); + decoder.executeInstruction(ibc, pc, (uint8_t*)&mockScratchpad, config); + rx_store_vec_f128((double*)&vec, reg.e[registerDst]); + assert(equalsHex(&vec, "e6b269639484434632474a66635ba547")); + }); + + runTest("FDIV_M RoundUp (execute)", RANDOMX_FREQ_FDIV_M > 0, [&] { + alignas(16) uint64_t vec[2]; + alignas(16) uint32_t mockScratchpad[2]; + store32(&mockScratchpad[0], 0xd350a1b6); + store32(&mockScratchpad[1], 0x8b2460d9); + store64(&config.eMask[0], 0x3a0000000005d11a); + store64(&config.eMask[1], 0x39000000001ba31e); + reg.e[registerDst] = rx_set_vec_f128(0x41937f76fede16ee, 0x411b414296ce93b6); + reg.r[registerSrc] = 0xFFFFFFFFFFFFE930; + rx_set_rounding_mode(RoundUp); + decoder.executeInstruction(ibc, pc, (uint8_t*)&mockScratchpad, config); + rx_store_vec_f128((double*)&vec, reg.e[registerDst]); + assert(equalsHex(&vec, "e7b269639484434633474a66635ba547")); + }); + + runTest("FSQRT_R (decode)", RANDOMX_FREQ_FSQRT_R > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_FSQRT_R - 1; + instr.dst = registerHigh | registerDst; + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::FSQRT_R); + assert(ibc.fdst == ®.e[registerDst]); + }); + + runTest("FSQRT_R RoundToNearest (execute)", RANDOMX_FREQ_FSQRT_R > 0, [&] { + alignas(16) uint64_t vec[2]; + reg.e[registerDst] = rx_set_vec_f128(0x41b6b21c11affea7, 0x40526a7e778d9824); + rx_set_rounding_mode(RoundToNearest); + decoder.executeInstruction(ibc, pc, nullptr, config); + rx_store_vec_f128((double*)&vec, reg.e[registerDst]); + assert(equalsHex(&vec, "e81f300b612a21408dbaa33f570ed340")); + }); + + runTest("FSQRT_R RoundDown/RoundToZero (execute)", RANDOMX_FREQ_FSQRT_R > 0, [&] { + alignas(16) uint64_t vec[2]; + reg.e[registerDst] = rx_set_vec_f128(0x41b6b21c11affea7, 0x40526a7e778d9824); + rx_set_rounding_mode(RoundDown); + decoder.executeInstruction(ibc, pc, nullptr, config); + rx_store_vec_f128((double*)&vec, reg.e[registerDst]); + assert(equalsHex(&vec, "e81f300b612a21408cbaa33f570ed340")); + }); + + runTest("FSQRT_R RoundUp (execute)", RANDOMX_FREQ_FSQRT_R > 0, [&] { + alignas(16) uint64_t vec[2]; + reg.e[registerDst] = rx_set_vec_f128(0x41b6b21c11affea7, 0x40526a7e778d9824); + rx_set_rounding_mode(RoundUp); + decoder.executeInstruction(ibc, pc, nullptr, config); + rx_store_vec_f128((double*)&vec, reg.e[registerDst]); + assert(equalsHex(&vec, "e91f300b612a21408dbaa33f570ed340")); + }); + + runTest("CBRANCH (decode) 100", RANDOMX_FREQ_CBRANCH > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_CBRANCH - 1; + instr.dst = registerHigh | registerDst; + instr.setImm32(imm32); + instr.mod = 48; + decoder.compileInstruction(instr, 100, ibc); + assert(ibc.type == randomx::InstructionType::CBRANCH); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.imm == 0xFFFFFFFFC0CB9AD2); + assert(ibc.memMask == 0x7F800); + assert(ibc.target == pc); + }); + + runTest("CBRANCH (decode) 200", RANDOMX_FREQ_CBRANCH > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_CBRANCH - 1; + instr.dst = registerHigh | registerDst; + instr.setImm32(imm32); + instr.mod = 48; + decoder.compileInstruction(instr, pc = 200, ibc); + assert(ibc.type == randomx::InstructionType::CBRANCH); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.imm == 0xFFFFFFFFC0CB9AD2); + assert(ibc.memMask == 0x7F800); + assert(ibc.target == 100); + }); + + runTest("CBRANCH not taken (execute)", RANDOMX_FREQ_CBRANCH > 0, [&] { + reg.r[registerDst] = 0; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(pc == 200); + }); + + runTest("CBRANCH taken (execute)", RANDOMX_FREQ_CBRANCH > 0, [&] { + reg.r[registerDst] = 0xFFFFFFFFFFFC6800; + decoder.executeInstruction(ibc, pc, nullptr, config); + assert(pc == ibc.target); + }); + + runTest("CFROUND (decode)", RANDOMX_FREQ_CFROUND > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_CFROUND - 1; + instr.src = registerHigh | registerSrc; + instr.setImm32(imm32); + decoder.compileInstruction(instr, 100, ibc); + assert(ibc.type == randomx::InstructionType::CFROUND); + assert(ibc.isrc == ®.r[registerSrc]); + assert(ibc.imm == 18); + }); + + runTest("ISTORE L1 (decode)", RANDOMX_FREQ_ISTORE > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_ISTORE - 1; + instr.src = registerHigh | registerSrc; + instr.dst = registerHigh | registerDst; + instr.setImm32(imm32); + instr.mod = 1; + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::ISTORE); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + assert(ibc.imm == imm64); + assert(ibc.memMask == randomx::ScratchpadL1Mask); + }); + + runTest("ISTORE L2 (decode)", RANDOMX_FREQ_ISTORE > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_ISTORE - 1; + instr.src = registerHigh | registerSrc; + instr.dst = registerHigh | registerDst; + instr.setImm32(imm32); + instr.mod = 0; + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::ISTORE); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + assert(ibc.imm == imm64); + assert(ibc.memMask == randomx::ScratchpadL2Mask); + }); + + runTest("ISTORE L3 (decode)", RANDOMX_FREQ_ISTORE > 0, [&] { + randomx::Instruction instr; + instr.opcode = randomx::ceil_ISTORE - 1; + instr.src = registerHigh | registerSrc; + instr.dst = registerHigh | registerDst; + instr.setImm32(imm32); + instr.mod = 224; + decoder.compileInstruction(instr, pc, ibc); + assert(ibc.type == randomx::InstructionType::ISTORE); + assert(ibc.idst == ®.r[registerDst]); + assert(ibc.isrc == ®.r[registerSrc]); + assert(ibc.imm == imm64); + assert(ibc.memMask == randomx::ScratchpadL3Mask); + }); + +#ifdef RANDOMX_FORCE_SECURE + vm = randomx_create_vm(RANDOMX_FLAG_DEFAULT | RANDOMX_FLAG_SECURE, cache, nullptr); +#else + vm = randomx_create_vm(RANDOMX_FLAG_DEFAULT, cache, nullptr); +#endif + + auto test_a = [&] { + char hash[RANDOMX_HASH_SIZE]; + calcStringHash("test key 000", "This is a test", &hash); + assert(equalsHex(hash, "639183aae1bf4c9a35884cb46b09cad9175f04efd7684e7262a0ac1c2f0b4e3f")); + }; + + auto test_b = [&] { + char hash[RANDOMX_HASH_SIZE]; + calcStringHash("test key 000", "Lorem ipsum dolor sit amet", &hash); + assert(equalsHex(hash, "300a0adb47603dedb42228ccb2b211104f4da45af709cd7547cd049e9489c969")); + }; + + auto test_c = [&] { + char hash[RANDOMX_HASH_SIZE]; + calcStringHash("test key 000", "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua", &hash); + assert(equalsHex(hash, "c36d4ed4191e617309867ed66a443be4075014e2b061bcdaf9ce7b721d2b77a8")); + }; + + auto test_d = [&] { + char hash[RANDOMX_HASH_SIZE]; + calcStringHash("test key 001", "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua", &hash); + assert(equalsHex(hash, "e9ff4503201c0c2cca26d285c93ae883f9b1d30c9eb240b820756f2d5a7905fc")); + }; + + auto test_e = [&] { + char hash[RANDOMX_HASH_SIZE]; + calcHexHash("test key 001", "0b0b98bea7e805e0010a2126d287a2a0cc833d312cb786385a7c2f9de69d25537f584a9bc9977b00000000666fd8753bf61a8631f12984e3fd44f4014eca629276817b56f32e9b68bd82f416", &hash); + //std::cout << std::endl; + //outputHex(std::cout, (const char*)hash, sizeof(hash)); + //std::cout << std::endl; + assert(equalsHex(hash, "c56414121acda1713c2f2a819d8ae38aed7c80c35c2a769298d34f03833cd5f1")); + }; + + runTest("Hash test 1a (interpreter)", stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_a); + + runTest("Hash test 1b (interpreter)", stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_b); + + runTest("Hash test 1c (interpreter)", stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_c); + + runTest("Hash test 1d (interpreter)", stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_d); + + runTest("Hash test 1e (interpreter)", stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_e); + + if (RANDOMX_HAVE_COMPILER) { + randomx_release_cache(cache); + randomx_destroy_vm(vm); + vm = nullptr; + cache = randomx_alloc_cache(RANDOMX_FLAG_JIT); + initCache("test key 000"); +#ifdef RANDOMX_FORCE_SECURE + vm = randomx_create_vm(RANDOMX_FLAG_JIT | RANDOMX_FLAG_SECURE, cache, nullptr); +#else + vm = randomx_create_vm(RANDOMX_FLAG_JIT, cache, nullptr); +#endif + } + + runTest("Hash test 2a (compiler)", RANDOMX_HAVE_COMPILER && stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_a); + + runTest("Hash test 2b (compiler)", RANDOMX_HAVE_COMPILER && stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_b); + + runTest("Hash test 2c (compiler)", RANDOMX_HAVE_COMPILER && stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_c); + + runTest("Hash test 2d (compiler)", RANDOMX_HAVE_COMPILER && stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_d); + + runTest("Hash test 2e (compiler)", RANDOMX_HAVE_COMPILER && stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), test_e); + + auto flags = randomx_get_flags(); + + randomx_release_cache(cache); + cache = randomx_alloc_cache(RANDOMX_FLAG_ARGON2_SSSE3); + + runTest("Cache initialization: SSSE3", (flags & RANDOMX_FLAG_ARGON2_SSSE3) && RANDOMX_ARGON_ITERATIONS == 3 && RANDOMX_ARGON_LANES == 1 && RANDOMX_ARGON_MEMORY == 262144 && stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), []() { + initCache("test key 000"); + uint64_t* cacheMemory = (uint64_t*)cache->memory; + assert(cacheMemory[0] == 0x191e0e1d23c02186); + assert(cacheMemory[1568413] == 0xf1b62fe6210bf8b1); + assert(cacheMemory[33554431] == 0x1f47f056d05cd99b); + }); + + if (cache != nullptr) + randomx_release_cache(cache); + cache = randomx_alloc_cache(RANDOMX_FLAG_ARGON2_AVX2); + + runTest("Cache initialization: AVX2", (flags & RANDOMX_FLAG_ARGON2_AVX2) && RANDOMX_ARGON_ITERATIONS == 3 && RANDOMX_ARGON_LANES == 1 && RANDOMX_ARGON_MEMORY == 262144 && stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), []() { + initCache("test key 000"); + uint64_t* cacheMemory = (uint64_t*)cache->memory; + assert(cacheMemory[0] == 0x191e0e1d23c02186); + assert(cacheMemory[1568413] == 0xf1b62fe6210bf8b1); + assert(cacheMemory[33554431] == 0x1f47f056d05cd99b); + }); + + if (cache != nullptr) + randomx_release_cache(cache); + cache = randomx_alloc_cache(RANDOMX_FLAG_DEFAULT); + + runTest("Hash batch test", RANDOMX_HAVE_COMPILER && stringsEqual(RANDOMX_ARGON_SALT, "RandomX\x03"), []() { + char hash1[RANDOMX_HASH_SIZE]; + char hash2[RANDOMX_HASH_SIZE]; + char hash3[RANDOMX_HASH_SIZE]; + initCache("test key 000"); + char input1[] = "This is a test"; + char input2[] = "Lorem ipsum dolor sit amet"; + char input3[] = "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua"; + + randomx_calculate_hash_first(vm, input1, sizeof(input1) - 1); + randomx_calculate_hash_next(vm, input2, sizeof(input2) - 1, &hash1); + randomx_calculate_hash_next(vm, input3, sizeof(input3) - 1, &hash2); + randomx_calculate_hash_last(vm, &hash3); + + assert(equalsHex(hash1, "639183aae1bf4c9a35884cb46b09cad9175f04efd7684e7262a0ac1c2f0b4e3f")); + assert(equalsHex(hash2, "300a0adb47603dedb42228ccb2b211104f4da45af709cd7547cd049e9489c969")); + assert(equalsHex(hash3, "c36d4ed4191e617309867ed66a443be4075014e2b061bcdaf9ce7b721d2b77a8")); + }); + + runTest("Preserve rounding mode", RANDOMX_FREQ_CFROUND > 0, []() { + rx_set_rounding_mode(RoundToNearest); + char hash[RANDOMX_HASH_SIZE]; + calcStringHash("test key 000", "Lorem ipsum dolor sit amet", &hash); + assert(equalsHex(hash, "300a0adb47603dedb42228ccb2b211104f4da45af709cd7547cd049e9489c969")); + assert(rx_get_rounding_mode() == RoundToNearest); + }); + + randomx_destroy_vm(vm); + vm = nullptr; + + if (cache != nullptr) + randomx_release_cache(cache); + + std::cout << std::endl << "All tests PASSED" << std::endl; + + if (skipped) { + std::cout << skipped << " tests were SKIPPED due to incompatible configuration (see above)" << std::endl; + } +} diff --git a/src/RandomX/src/tests/utility.hpp b/src/RandomX/src/tests/utility.hpp new file mode 100644 index 000000000..92723b979 --- /dev/null +++ b/src/RandomX/src/tests/utility.hpp @@ -0,0 +1,124 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include +#include +#include + +constexpr char hexmap[] = "0123456789abcdef"; +inline void outputHex(std::ostream& os, const char* data, int length) { + for (int i = 0; i < length; ++i) { + os << hexmap[(data[i] & 0xF0) >> 4]; + os << hexmap[data[i] & 0x0F]; + } +} + +char parseNibble(char hex) { + hex &= ~0x20; + if (hex & 0x40) { + hex -= 'A' - 10; + } + else { + hex &= 0xf; + } + return hex; +} + +void hex2bin(const char *in, int length, char *out) { + for (int i = 0; i < length; i += 2) { + char nibble1 = parseNibble(*in++); + char nibble2 = parseNibble(*in++); + *out++ = nibble1 << 4 | nibble2; + } +} + +constexpr bool stringsEqual(char const * a, char const * b) { + return *a == *b && (*a == '\0' || stringsEqual(a + 1, b + 1)); +} + +template +bool equalsHex(const void* hash, const char (&hex)[N]) { + char reference[N / 2]; + hex2bin(hex, N - 1, reference); + return memcmp(hash, reference, sizeof(reference)) == 0; +} + +inline void dump(const char* buffer, uint64_t count, const char* name) { + std::ofstream fout(name, std::ios::out | std::ios::binary); + fout.write(buffer, count); + fout.close(); +} + +inline void readOption(const char* option, int argc, char** argv, bool& out) { + for (int i = 0; i < argc; ++i) { + if (strcmp(argv[i], option) == 0) { + out = true; + return; + } + } + out = false; +} + +inline void readIntOption(const char* option, int argc, char** argv, int& out, int defaultValue) { + for (int i = 0; i < argc - 1; ++i) { + if (strcmp(argv[i], option) == 0 && (out = atoi(argv[i + 1])) > 0) { + return; + } + } + out = defaultValue; +} + +inline void readUInt64Option(const char* option, int argc, char** argv, uint64_t& out, uint64_t defaultValue) { + for (int i = 0; i < argc - 1; ++i) { + if (strcmp(argv[i], option) == 0 && (out = std::strtoull(argv[i + 1], NULL, 0)) > 0) { + return; + } + } + out = defaultValue; +} + +inline void readFloatOption(const char* option, int argc, char** argv, double& out, double defaultValue) { + for (int i = 0; i < argc - 1; ++i) { + if (strcmp(argv[i], option) == 0 && (out = atof(argv[i + 1])) > 0) { + return; + } + } + out = defaultValue; +} + +inline void readInt(int argc, char** argv, int& out, int defaultValue) { + for (int i = 0; i < argc; ++i) { + if (*argv[i] != '-' && (out = atoi(argv[i])) > 0) { + return; + } + } + out = defaultValue; +} diff --git a/src/RandomX/src/virtual_machine.cpp b/src/RandomX/src/virtual_machine.cpp new file mode 100644 index 000000000..2d5d2bead --- /dev/null +++ b/src/RandomX/src/virtual_machine.cpp @@ -0,0 +1,143 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include +#include "virtual_machine.hpp" +#include "common.hpp" +#include "aes_hash.hpp" +#include "blake2/blake2.h" +#include "intrin_portable.h" +#include "allocator.hpp" + +randomx_vm::~randomx_vm() { + +} + +void randomx_vm::resetRoundingMode() { + rx_reset_float_state(); +} + +namespace randomx { + + static inline uint64_t getSmallPositiveFloatBits(uint64_t entropy) { + auto exponent = entropy >> 59; //0..31 + auto mantissa = entropy & mantissaMask; + exponent += exponentBias; + exponent &= exponentMask; + exponent <<= mantissaSize; + return exponent | mantissa; + } + + static inline uint64_t getStaticExponent(uint64_t entropy) { + auto exponent = constExponentBits; + exponent |= (entropy >> (64 - staticExponentBits)) << dynamicExponentBits; + exponent <<= mantissaSize; + return exponent; + } + + static inline uint64_t getFloatMask(uint64_t entropy) { + constexpr uint64_t mask22bit = (1ULL << 22) - 1; + return (entropy & mask22bit) | getStaticExponent(entropy); + } + +} + +void randomx_vm::initialize() { + store64(®.a[0].lo, randomx::getSmallPositiveFloatBits(program.getEntropy(0))); + store64(®.a[0].hi, randomx::getSmallPositiveFloatBits(program.getEntropy(1))); + store64(®.a[1].lo, randomx::getSmallPositiveFloatBits(program.getEntropy(2))); + store64(®.a[1].hi, randomx::getSmallPositiveFloatBits(program.getEntropy(3))); + store64(®.a[2].lo, randomx::getSmallPositiveFloatBits(program.getEntropy(4))); + store64(®.a[2].hi, randomx::getSmallPositiveFloatBits(program.getEntropy(5))); + store64(®.a[3].lo, randomx::getSmallPositiveFloatBits(program.getEntropy(6))); + store64(®.a[3].hi, randomx::getSmallPositiveFloatBits(program.getEntropy(7))); + mem.ma = program.getEntropy(8) & randomx::CacheLineAlignMask; + mem.mx = program.getEntropy(10); + auto addressRegisters = program.getEntropy(12); + config.readReg0 = 0 + (addressRegisters & 1); + addressRegisters >>= 1; + config.readReg1 = 2 + (addressRegisters & 1); + addressRegisters >>= 1; + config.readReg2 = 4 + (addressRegisters & 1); + addressRegisters >>= 1; + config.readReg3 = 6 + (addressRegisters & 1); + datasetOffset = (program.getEntropy(13) % (randomx::DatasetExtraItems + 1)) * randomx::CacheLineSize; + store64(&config.eMask[0], randomx::getFloatMask(program.getEntropy(14))); + store64(&config.eMask[1], randomx::getFloatMask(program.getEntropy(15))); +} + +namespace randomx { + + alignas(16) volatile static rx_vec_i128 aesDummy; + + template + VmBase::~VmBase() { + Allocator::freeMemory(scratchpad, ScratchpadSize); + } + + template + void VmBase::allocate() { + if (datasetPtr == nullptr) + throw std::invalid_argument("Cache/Dataset not set"); + if (!softAes) { //if hardware AES is not supported, it's better to fail now than to return a ticking bomb + rx_vec_i128 tmp = rx_load_vec_i128((const rx_vec_i128*)&aesDummy); + tmp = rx_aesenc_vec_i128(tmp, tmp); + rx_store_vec_i128((rx_vec_i128*)&aesDummy, tmp); + } + scratchpad = (uint8_t*)Allocator::allocMemory(ScratchpadSize); + } + + template + void VmBase::getFinalResult(void* out, size_t outSize) { + hashAes1Rx4(scratchpad, ScratchpadSize, ®.a); + blake2b(out, outSize, ®, sizeof(RegisterFile), nullptr, 0); + } + + template + void VmBase::hashAndFill(void* out, size_t outSize, uint64_t *fill_state) { + hashAndFillAes1Rx4((void*) getScratchpad(), ScratchpadSize, ®.a, fill_state); + blake2b(out, outSize, ®, sizeof(RegisterFile), nullptr, 0); + } + + template + void VmBase::initScratchpad(void* seed) { + fillAes1Rx4(seed, ScratchpadSize, scratchpad); + } + + template + void VmBase::generateProgram(void* seed) { + fillAes4Rx4(seed, sizeof(program), &program); + } + + template class VmBase, false>; + template class VmBase, true>; + template class VmBase; + template class VmBase; +} \ No newline at end of file diff --git a/src/RandomX/src/virtual_machine.hpp b/src/RandomX/src/virtual_machine.hpp new file mode 100644 index 000000000..02979a2cd --- /dev/null +++ b/src/RandomX/src/virtual_machine.hpp @@ -0,0 +1,91 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include "common.hpp" +#include "program.hpp" + +/* Global namespace for C binding */ +class randomx_vm { +public: + virtual ~randomx_vm() = 0; + virtual void allocate() = 0; + virtual void getFinalResult(void* out, size_t outSize) = 0; + virtual void hashAndFill(void* out, size_t outSize, uint64_t *fill_state) = 0; + virtual void setDataset(randomx_dataset* dataset) { } + virtual void setCache(randomx_cache* cache) { } + virtual void initScratchpad(void* seed) = 0; + virtual void run(void* seed) = 0; + void resetRoundingMode(); + randomx::RegisterFile *getRegisterFile() { + return ® + } + const void* getScratchpad() { + return scratchpad; + } + const randomx::Program& getProgram() + { + return program; + } + const uint8_t* getMemory() const { + return mem.memory; + } +protected: + void initialize(); + alignas(64) randomx::Program program; + alignas(64) randomx::RegisterFile reg; + alignas(16) randomx::ProgramConfiguration config; + randomx::MemoryRegisters mem; + uint8_t* scratchpad = nullptr; + union { + randomx_cache* cachePtr = nullptr; + randomx_dataset* datasetPtr; + }; + uint64_t datasetOffset; +public: + std::string cacheKey; + alignas(16) uint64_t tempHash[8]; //8 64-bit values used to store intermediate data +}; + +namespace randomx { + + template + class VmBase : public randomx_vm { + public: + ~VmBase() override; + void allocate() override; + void initScratchpad(void* seed) override; + void getFinalResult(void* out, size_t outSize) override; + void hashAndFill(void* out, size_t outSize, uint64_t *fill_state) override; + protected: + void generateProgram(void* seed); + }; + +} diff --git a/src/RandomX/src/virtual_memory.cpp b/src/RandomX/src/virtual_memory.cpp new file mode 100644 index 000000000..caf02922a --- /dev/null +++ b/src/RandomX/src/virtual_memory.cpp @@ -0,0 +1,203 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "virtual_memory.hpp" + +#include + +#if defined(_WIN32) || defined(__CYGWIN__) +#include +#else +#ifdef __APPLE__ +#include +#include +#include +# if TARGET_OS_OSX +# define USE_PTHREAD_JIT_WP 1 +# include +# endif +#endif +#include +#include +#ifndef MAP_ANONYMOUS +#define MAP_ANONYMOUS MAP_ANON +#endif +#define PAGE_READONLY PROT_READ +#define PAGE_READWRITE (PROT_READ | PROT_WRITE) +#define PAGE_EXECUTE_READ (PROT_READ | PROT_EXEC) +#define PAGE_EXECUTE_READWRITE (PROT_READ | PROT_WRITE | PROT_EXEC) +#endif + +#if defined(_WIN32) || defined(__CYGWIN__) +std::string getErrorMessage(const char* function) { + LPSTR messageBuffer = nullptr; + size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL); + std::string message(messageBuffer, size); + LocalFree(messageBuffer); + return std::string(function) + std::string(": ") + message; +} + +void setPrivilege(const char* pszPrivilege, BOOL bEnable) { + HANDLE hToken; + TOKEN_PRIVILEGES tp; + BOOL status; + DWORD error; + + if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) + throw std::runtime_error(getErrorMessage("OpenProcessToken")); + + if (!LookupPrivilegeValue(NULL, pszPrivilege, &tp.Privileges[0].Luid)) + throw std::runtime_error(getErrorMessage("LookupPrivilegeValue")); + + tp.PrivilegeCount = 1; + + if (bEnable) + tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; + else + tp.Privileges[0].Attributes = 0; + + status = AdjustTokenPrivileges(hToken, FALSE, &tp, 0, (PTOKEN_PRIVILEGES)NULL, 0); + + error = GetLastError(); + if (!status || (error != ERROR_SUCCESS)) + throw std::runtime_error(getErrorMessage("AdjustTokenPrivileges")); + + if (!CloseHandle(hToken)) + throw std::runtime_error(getErrorMessage("CloseHandle")); +} +#endif + +void* allocMemoryPages(std::size_t bytes) { + void* mem; +#if defined(_WIN32) || defined(__CYGWIN__) + mem = VirtualAlloc(nullptr, bytes, MEM_COMMIT, PAGE_READWRITE); + if (mem == nullptr) + throw std::runtime_error(getErrorMessage("allocMemoryPages - VirtualAlloc")); +#else + #if defined(__NetBSD__) + #define RESERVED_FLAGS PROT_MPROTECT(PROT_EXEC) + #else + #define RESERVED_FLAGS 0 + #endif + #ifdef USE_PTHREAD_JIT_WP + #define MEXTRA MAP_JIT + #define PEXTRA PROT_EXEC + #else + #define MEXTRA 0 + #define PEXTRA 0 + #endif + mem = mmap(nullptr, bytes, PAGE_READWRITE | RESERVED_FLAGS | PEXTRA, MAP_ANONYMOUS | MAP_PRIVATE | MEXTRA, -1, 0); + if (mem == MAP_FAILED) + throw std::runtime_error("allocMemoryPages - mmap failed"); +#if defined(USE_PTHREAD_JIT_WP) && defined(MAC_OS_VERSION_11_0) \ + && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0 + if (__builtin_available(macOS 11.0, *)) { + pthread_jit_write_protect_np(false); + } +#endif +#endif + return mem; +} + +static inline void pageProtect(void* ptr, std::size_t bytes, int rules) { +#if defined(_WIN32) || defined(__CYGWIN__) + DWORD oldp; + if (!VirtualProtect(ptr, bytes, (DWORD)rules, &oldp)) { + throw std::runtime_error(getErrorMessage("VirtualProtect")); + } +#else + if (-1 == mprotect(ptr, bytes, rules)) + throw std::runtime_error("mprotect failed"); +#endif +} + +void setPagesRW(void* ptr, std::size_t bytes) { +#if defined(USE_PTHREAD_JIT_WP) && defined(MAC_OS_VERSION_11_0) \ + && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0 + if (__builtin_available(macOS 11.0, *)) { + pthread_jit_write_protect_np(false); + } else { + pageProtect(ptr, bytes, PAGE_READWRITE); + } +#else + pageProtect(ptr, bytes, PAGE_READWRITE); +#endif +} + +void setPagesRX(void* ptr, std::size_t bytes) { +#if defined(USE_PTHREAD_JIT_WP) && defined(MAC_OS_VERSION_11_0) \ + && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_VERSION_11_0 + if (__builtin_available(macOS 11.0, *)) { + pthread_jit_write_protect_np(true); + } else { + pageProtect(ptr, bytes, PAGE_EXECUTE_READ); + } +#else + pageProtect(ptr, bytes, PAGE_EXECUTE_READ); +#endif +} + +void setPagesRWX(void* ptr, std::size_t bytes) { + pageProtect(ptr, bytes, PAGE_EXECUTE_READWRITE); +} + +void* allocLargePagesMemory(std::size_t bytes) { + void* mem; +#if defined(_WIN32) || defined(__CYGWIN__) + setPrivilege("SeLockMemoryPrivilege", 1); + auto pageMinimum = GetLargePageMinimum(); + if (pageMinimum > 0) + mem = VirtualAlloc(NULL, alignSize(bytes, pageMinimum), MEM_COMMIT | MEM_RESERVE | MEM_LARGE_PAGES, PAGE_READWRITE); + else + throw std::runtime_error("allocLargePagesMemory - Large pages are not supported"); + if (mem == nullptr) + throw std::runtime_error(getErrorMessage("allocLargePagesMemory - VirtualAlloc")); +#else +#ifdef __APPLE__ + mem = mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, VM_FLAGS_SUPERPAGE_SIZE_2MB, 0); +#elif defined(__FreeBSD__) + mem = mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_ALIGNED_SUPER, -1, 0); +#elif defined(__OpenBSD__) || defined(__NetBSD__) + mem = MAP_FAILED; // OpenBSD does not support huge pages +#else + mem = mmap(nullptr, bytes, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB | MAP_POPULATE, -1, 0); +#endif + if (mem == MAP_FAILED) + throw std::runtime_error("allocLargePagesMemory - mmap failed"); +#endif + return mem; +} + +void freePagedMemory(void* ptr, std::size_t bytes) { +#if defined(_WIN32) || defined(__CYGWIN__) + VirtualFree(ptr, 0, MEM_RELEASE); +#else + munmap(ptr, bytes); +#endif +} diff --git a/src/RandomX/src/virtual_memory.hpp b/src/RandomX/src/virtual_memory.hpp new file mode 100644 index 000000000..9e8bc29ab --- /dev/null +++ b/src/RandomX/src/virtual_memory.hpp @@ -0,0 +1,42 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include + +constexpr std::size_t alignSize(std::size_t pos, std::size_t align) { + return ((pos - 1) / align + 1) * align; +} + +void* allocMemoryPages(std::size_t); +void setPagesRW(void*, std::size_t); +void setPagesRX(void*, std::size_t); +void setPagesRWX(void*, std::size_t); +void* allocLargePagesMemory(std::size_t); +void freePagedMemory(void*, std::size_t); diff --git a/src/RandomX/src/vm_compiled.cpp b/src/RandomX/src/vm_compiled.cpp new file mode 100644 index 000000000..060abec33 --- /dev/null +++ b/src/RandomX/src/vm_compiled.cpp @@ -0,0 +1,80 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "vm_compiled.hpp" +#include "common.hpp" + +namespace randomx { + + static_assert(sizeof(MemoryRegisters) == 2 * sizeof(addr_t) + sizeof(uintptr_t), "Invalid alignment of struct randomx::MemoryRegisters"); + static_assert(sizeof(RegisterFile) == 256, "Invalid alignment of struct randomx::RegisterFile"); + + template + CompiledVm::CompiledVm() { + if (!secureJit) { + compiler.enableAll(); //make JIT buffer both writable and executable + } + } + + template + void CompiledVm::setDataset(randomx_dataset* dataset) { + datasetPtr = dataset; + } + + template + void CompiledVm::run(void* seed) { + VmBase::generateProgram(seed); + randomx_vm::initialize(); + if (secureJit) { + compiler.enableWriting(); + } + compiler.generateProgram(program, config); + if (secureJit) { + compiler.enableExecution(); + } + mem.memory = datasetPtr->memory + datasetOffset; + execute(); + } + + template + void CompiledVm::execute() { +#ifdef __aarch64__ + memcpy(reg.f, config.eMask, sizeof(config.eMask)); +#endif + compiler.getProgramFunc()(reg, mem, scratchpad, RANDOMX_PROGRAM_ITERATIONS); + } + + template class CompiledVm, false, false>; + template class CompiledVm, true, false>; + template class CompiledVm; + template class CompiledVm; + template class CompiledVm, false, true>; + template class CompiledVm, true, true>; + template class CompiledVm; + template class CompiledVm; +} \ No newline at end of file diff --git a/src/RandomX/src/vm_compiled.hpp b/src/RandomX/src/vm_compiled.hpp new file mode 100644 index 000000000..f7ceb0a62 --- /dev/null +++ b/src/RandomX/src/vm_compiled.hpp @@ -0,0 +1,77 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include +#include "virtual_machine.hpp" +#include "jit_compiler.hpp" +#include "allocator.hpp" +#include "dataset.hpp" + +namespace randomx { + + template + class CompiledVm : public VmBase { + public: + void* operator new(size_t size) { + void* ptr = AlignedAllocator::allocMemory(size); + if (ptr == nullptr) + throw std::bad_alloc(); + return ptr; + } + void operator delete(void* ptr) { + AlignedAllocator::freeMemory(ptr, sizeof(CompiledVm)); + } + CompiledVm(); + void setDataset(randomx_dataset* dataset) override; + void run(void* seed) override; + + using VmBase::mem; + using VmBase::program; + using VmBase::config; + using VmBase::reg; + using VmBase::scratchpad; + using VmBase::datasetPtr; + using VmBase::datasetOffset; + protected: + void execute(); + + JitCompiler compiler; + }; + + using CompiledVmDefault = CompiledVm, true, false>; + using CompiledVmHardAes = CompiledVm, false, false>; + using CompiledVmLargePage = CompiledVm; + using CompiledVmLargePageHardAes = CompiledVm; + using CompiledVmDefaultSecure = CompiledVm, true, true>; + using CompiledVmHardAesSecure = CompiledVm, false, true>; + using CompiledVmLargePageSecure = CompiledVm; + using CompiledVmLargePageHardAesSecure = CompiledVm; +} diff --git a/src/RandomX/src/vm_compiled_light.cpp b/src/RandomX/src/vm_compiled_light.cpp new file mode 100644 index 000000000..98dff34ca --- /dev/null +++ b/src/RandomX/src/vm_compiled_light.cpp @@ -0,0 +1,70 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "vm_compiled_light.hpp" +#include "common.hpp" +#include + +namespace randomx { + + template + void CompiledLightVm::setCache(randomx_cache* cache) { + cachePtr = cache; + mem.memory = cache->memory; + if (secureJit) { + compiler.enableWriting(); + } + compiler.generateSuperscalarHash(cache->programs, cache->reciprocalCache); + if (secureJit) { + compiler.enableExecution(); + } + } + + template + void CompiledLightVm::run(void* seed) { + VmBase::generateProgram(seed); + randomx_vm::initialize(); + if (secureJit) { + compiler.enableWriting(); + } + compiler.generateProgramLight(program, config, datasetOffset); + if (secureJit) { + compiler.enableExecution(); + } + CompiledVm::execute(); + } + + template class CompiledLightVm, false, false>; + template class CompiledLightVm, true, false>; + template class CompiledLightVm; + template class CompiledLightVm; + template class CompiledLightVm, false, true>; + template class CompiledLightVm, true, true>; + template class CompiledLightVm; + template class CompiledLightVm; +} \ No newline at end of file diff --git a/src/RandomX/src/vm_compiled_light.hpp b/src/RandomX/src/vm_compiled_light.hpp new file mode 100644 index 000000000..bed4ce144 --- /dev/null +++ b/src/RandomX/src/vm_compiled_light.hpp @@ -0,0 +1,68 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include "vm_compiled.hpp" + +namespace randomx { + + template + class CompiledLightVm : public CompiledVm { + public: + void* operator new(size_t size) { + void* ptr = AlignedAllocator::allocMemory(size); + if (ptr == nullptr) + throw std::bad_alloc(); + return ptr; + } + void operator delete(void* ptr) { + AlignedAllocator::freeMemory(ptr, sizeof(CompiledLightVm)); + } + void setCache(randomx_cache* cache) override; + void setDataset(randomx_dataset* dataset) override { } + void run(void* seed) override; + + using CompiledVm::mem; + using CompiledVm::compiler; + using CompiledVm::program; + using CompiledVm::config; + using CompiledVm::cachePtr; + using CompiledVm::datasetOffset; + }; + + using CompiledLightVmDefault = CompiledLightVm, true, false>; + using CompiledLightVmHardAes = CompiledLightVm, false, false>; + using CompiledLightVmLargePage = CompiledLightVm; + using CompiledLightVmLargePageHardAes = CompiledLightVm; + using CompiledLightVmDefaultSecure = CompiledLightVm, true, true>; + using CompiledLightVmHardAesSecure = CompiledLightVm, false, true>; + using CompiledLightVmLargePageSecure = CompiledLightVm; + using CompiledLightVmLargePageHardAesSecure = CompiledLightVm; +} \ No newline at end of file diff --git a/src/RandomX/src/vm_interpreted.cpp b/src/RandomX/src/vm_interpreted.cpp new file mode 100644 index 000000000..64243c3ec --- /dev/null +++ b/src/RandomX/src/vm_interpreted.cpp @@ -0,0 +1,131 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include +#include +#include +#include +#include +#include +#include "vm_interpreted.hpp" +#include "dataset.hpp" +#include "intrin_portable.h" +#include "reciprocal.h" + +namespace randomx { + + template + void InterpretedVm::setDataset(randomx_dataset* dataset) { + datasetPtr = dataset; + mem.memory = dataset->memory; + } + + template + void InterpretedVm::run(void* seed) { + VmBase::generateProgram(seed); + randomx_vm::initialize(); + execute(); + } + + template + void InterpretedVm::execute() { + + NativeRegisterFile nreg; + + for(unsigned i = 0; i < RegisterCountFlt; ++i) + nreg.a[i] = rx_load_vec_f128(®.a[i].lo); + + compileProgram(program, bytecode, nreg); + + uint32_t spAddr0 = mem.mx; + uint32_t spAddr1 = mem.ma; + + for(unsigned ic = 0; ic < RANDOMX_PROGRAM_ITERATIONS; ++ic) { + uint64_t spMix = nreg.r[config.readReg0] ^ nreg.r[config.readReg1]; + spAddr0 ^= spMix; + spAddr0 &= ScratchpadL3Mask64; + spAddr1 ^= spMix >> 32; + spAddr1 &= ScratchpadL3Mask64; + + for (unsigned i = 0; i < RegistersCount; ++i) + nreg.r[i] ^= load64(scratchpad + spAddr0 + 8 * i); + + for (unsigned i = 0; i < RegisterCountFlt; ++i) + nreg.f[i] = rx_cvt_packed_int_vec_f128(scratchpad + spAddr1 + 8 * i); + + for (unsigned i = 0; i < RegisterCountFlt; ++i) + nreg.e[i] = maskRegisterExponentMantissa(config, rx_cvt_packed_int_vec_f128(scratchpad + spAddr1 + 8 * (RegisterCountFlt + i))); + + executeBytecode(bytecode, scratchpad, config); + + mem.mx ^= nreg.r[config.readReg2] ^ nreg.r[config.readReg3]; + mem.mx &= CacheLineAlignMask; + datasetPrefetch(datasetOffset + mem.mx); + datasetRead(datasetOffset + mem.ma, nreg.r); + std::swap(mem.mx, mem.ma); + + for (unsigned i = 0; i < RegistersCount; ++i) + store64(scratchpad + spAddr1 + 8 * i, nreg.r[i]); + + for (unsigned i = 0; i < RegisterCountFlt; ++i) + nreg.f[i] = rx_xor_vec_f128(nreg.f[i], nreg.e[i]); + + for (unsigned i = 0; i < RegisterCountFlt; ++i) + rx_store_vec_f128((double*)(scratchpad + spAddr0 + 16 * i), nreg.f[i]); + + spAddr0 = 0; + spAddr1 = 0; + } + + for (unsigned i = 0; i < RegistersCount; ++i) + store64(®.r[i], nreg.r[i]); + + for (unsigned i = 0; i < RegisterCountFlt; ++i) + rx_store_vec_f128(®.f[i].lo, nreg.f[i]); + + for (unsigned i = 0; i < RegisterCountFlt; ++i) + rx_store_vec_f128(®.e[i].lo, nreg.e[i]); + } + + template + void InterpretedVm::datasetRead(uint64_t address, int_reg_t(&r)[RegistersCount]) { + uint64_t* datasetLine = (uint64_t*)(mem.memory + address); + for (int i = 0; i < RegistersCount; ++i) + r[i] ^= datasetLine[i]; + } + + template + void InterpretedVm::datasetPrefetch(uint64_t address) { + rx_prefetch_nta(mem.memory + address); + } + + template class InterpretedVm, false>; + template class InterpretedVm, true>; + template class InterpretedVm; + template class InterpretedVm; +} \ No newline at end of file diff --git a/src/RandomX/src/vm_interpreted.hpp b/src/RandomX/src/vm_interpreted.hpp new file mode 100644 index 000000000..2fac2eddb --- /dev/null +++ b/src/RandomX/src/vm_interpreted.hpp @@ -0,0 +1,75 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include +#include "common.hpp" +#include "virtual_machine.hpp" +#include "bytecode_machine.hpp" +#include "intrin_portable.h" +#include "allocator.hpp" + +namespace randomx { + + template + class InterpretedVm : public VmBase, public BytecodeMachine { + public: + using VmBase::mem; + using VmBase::scratchpad; + using VmBase::program; + using VmBase::config; + using VmBase::reg; + using VmBase::datasetPtr; + using VmBase::datasetOffset; + void* operator new(size_t size) { + void* ptr = AlignedAllocator::allocMemory(size); + if (ptr == nullptr) + throw std::bad_alloc(); + return ptr; + } + void operator delete(void* ptr) { + AlignedAllocator::freeMemory(ptr, sizeof(InterpretedVm)); + } + void run(void* seed) override; + void setDataset(randomx_dataset* dataset) override; + protected: + virtual void datasetRead(uint64_t blockNumber, int_reg_t(&r)[RegistersCount]); + virtual void datasetPrefetch(uint64_t blockNumber); + private: + void execute(); + + InstructionByteCode bytecode[RANDOMX_PROGRAM_SIZE]; + }; + + using InterpretedVmDefault = InterpretedVm, true>; + using InterpretedVmHardAes = InterpretedVm, false>; + using InterpretedVmLargePage = InterpretedVm; + using InterpretedVmLargePageHardAes = InterpretedVm; +} \ No newline at end of file diff --git a/src/RandomX/src/vm_interpreted_light.cpp b/src/RandomX/src/vm_interpreted_light.cpp new file mode 100644 index 000000000..c54b32f64 --- /dev/null +++ b/src/RandomX/src/vm_interpreted_light.cpp @@ -0,0 +1,55 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include "vm_interpreted_light.hpp" +#include "dataset.hpp" + +namespace randomx { + + template + void InterpretedLightVm::setCache(randomx_cache* cache) { + cachePtr = cache; + mem.memory = cache->memory; + } + + template + void InterpretedLightVm::datasetRead(uint64_t address, int_reg_t(&r)[8]) { + uint32_t itemNumber = address / CacheLineSize; + int_reg_t rl[8]; + + initDatasetItem(cachePtr, (uint8_t*)rl, itemNumber); + + for (unsigned q = 0; q < 8; ++q) + r[q] ^= rl[q]; + } + + template class InterpretedLightVm, false>; + template class InterpretedLightVm, true>; + template class InterpretedLightVm; + template class InterpretedLightVm; +} diff --git a/src/RandomX/src/vm_interpreted_light.hpp b/src/RandomX/src/vm_interpreted_light.hpp new file mode 100644 index 000000000..02d678f6e --- /dev/null +++ b/src/RandomX/src/vm_interpreted_light.hpp @@ -0,0 +1,61 @@ +/* +Copyright (c) 2018-2019, tevador + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + * Neither the name of the copyright holder nor the + names of its contributors may be used to endorse or promote products + derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#pragma once + +#include +#include "vm_interpreted.hpp" + +namespace randomx { + + template + class InterpretedLightVm : public InterpretedVm { + public: + using VmBase::mem; + using VmBase::cachePtr; + void* operator new(size_t size) { + void* ptr = AlignedAllocator::allocMemory(size); + if (ptr == nullptr) + throw std::bad_alloc(); + return ptr; + } + void operator delete(void* ptr) { + AlignedAllocator::freeMemory(ptr, sizeof(InterpretedLightVm)); + } + void setDataset(randomx_dataset* dataset) override { } + void setCache(randomx_cache* cache) override; + protected: + void datasetRead(uint64_t address, int_reg_t(&r)[8]) override; + void datasetPrefetch(uint64_t address) override { } + }; + + using InterpretedLightVmDefault = InterpretedLightVm, true>; + using InterpretedLightVmHardAes = InterpretedLightVm, false>; + using InterpretedLightVmLargePage = InterpretedLightVm; + using InterpretedLightVmLargePageHardAes = InterpretedLightVm; +} diff --git a/src/RandomX/vcxproj/api-example1.vcxproj b/src/RandomX/vcxproj/api-example1.vcxproj new file mode 100644 index 000000000..0cb1fc92e --- /dev/null +++ b/src/RandomX/vcxproj/api-example1.vcxproj @@ -0,0 +1,131 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {83EA3E54-5D91-4E01-8EF6-C1E718334F83} + apiexample1 + 10.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + {3346a4ad-c438-4324-8b77-47a16452954b} + + + + + + + + + + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/api-example1.vcxproj.filters b/src/RandomX/vcxproj/api-example1.vcxproj.filters new file mode 100644 index 000000000..6cd41c29d --- /dev/null +++ b/src/RandomX/vcxproj/api-example1.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/api-example2.vcxproj b/src/RandomX/vcxproj/api-example2.vcxproj new file mode 100644 index 000000000..ab1962713 --- /dev/null +++ b/src/RandomX/vcxproj/api-example2.vcxproj @@ -0,0 +1,128 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {44947B9C-E6B1-4C06-BD01-F8EF43B59223} + apiexample2 + 10.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + false + true + + + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + {3346a4ad-c438-4324-8b77-47a16452954b} + + + + + + + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/api-example2.vcxproj.filters b/src/RandomX/vcxproj/api-example2.vcxproj.filters new file mode 100644 index 000000000..c52d1e8b5 --- /dev/null +++ b/src/RandomX/vcxproj/api-example2.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/benchmark.vcxproj b/src/RandomX/vcxproj/benchmark.vcxproj new file mode 100644 index 000000000..9f53488fc --- /dev/null +++ b/src/RandomX/vcxproj/benchmark.vcxproj @@ -0,0 +1,132 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {1E8A2E2F-9F9F-43AA-BB19-9107FEC64A70} + benchmark + 10.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + false + true + + + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + false + true + + + + + Level3 + MaxSpeed + true + true + false + true + + + true + true + + + + + + + + + {3346a4ad-c438-4324-8b77-47a16452954b} + + + + + + + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/benchmark.vcxproj.filters b/src/RandomX/vcxproj/benchmark.vcxproj.filters new file mode 100644 index 000000000..ea182de56 --- /dev/null +++ b/src/RandomX/vcxproj/benchmark.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/code-generator.vcxproj b/src/RandomX/vcxproj/code-generator.vcxproj new file mode 100644 index 000000000..3cfb3f869 --- /dev/null +++ b/src/RandomX/vcxproj/code-generator.vcxproj @@ -0,0 +1,129 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {3E490DEC-1874-43AA-92DA-1AC57C217EAC} + codegenerator + 10.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + 4194304 + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + + + {3346a4ad-c438-4324-8b77-47a16452954b} + + + + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/code-generator.vcxproj.filters b/src/RandomX/vcxproj/code-generator.vcxproj.filters new file mode 100644 index 000000000..7578ae661 --- /dev/null +++ b/src/RandomX/vcxproj/code-generator.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/h2inc.ps1 b/src/RandomX/vcxproj/h2inc.ps1 new file mode 100644 index 000000000..ded47b80f --- /dev/null +++ b/src/RandomX/vcxproj/h2inc.ps1 @@ -0,0 +1,90 @@ +# The MIT License (MIT) +# +# Copyright (c) .NET Foundation and Contributors +# +# All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# C to MASM include file translator +# This is replacement for the deprecated h2inc tool that used to be part of VS. + +# +# The use of [console]::WriteLine (instead of Write-Output) is intentional. +# PowerShell 2.0 (installed by default on Windows 7) wraps lines written with +# Write-Output at whatever column width is being used by the current terminal, +# even when output is being redirected to a file. We can't have this behavior +# because it will cause the generated file to be malformed. +# + +Function ProcessFile($filePath) { + + [console]::WriteLine("; File start: $filePath") + + Get-Content $filePath | ForEach-Object { + + if ($_ -match "^\s*#\spragma") { + # Ignore pragmas + return + } + + if ($_ -match "^\s*#\s*include\s*`"(.*)`"") + { + # Expand includes. + ProcessFile(Join-Path (Split-Path -Parent $filePath) $Matches[1]) + return + } + + if ($_ -match "^\s*#define\s+(\S+)\s*(.*)") + { + # Augment #defines with their MASM equivalent + $name = $Matches[1] + $value = $Matches[2] + + # Note that we do not handle multiline constants + + # Strip comments from value + $value = $value -replace "//.*", "" + $value = $value -replace "/\*.*\*/", "" + + # Strip whitespaces from value + $value = $value -replace "\s+$", "" + + # ignore #defines with arguments + if ($name -notmatch "\(") { + $HEX_NUMBER_PATTERN = "\b0x(\w+)\b" + $DECIMAL_NUMBER_PATTERN = "(-?\b\d+\b)" + + if ($value -match $HEX_NUMBER_PATTERN -or $value -match $DECIMAL_NUMBER_PATTERN) { + $value = $value -replace $HEX_NUMBER_PATTERN, "0`$1h" # Convert hex constants + $value = $value -replace $DECIMAL_NUMBER_PATTERN, "`$1t" # Convert dec constants + [console]::WriteLine("$name EQU $value") + } else { + [console]::WriteLine("$name TEXTEQU <$value>") + } + } + } + + # [console]::WriteLine("$_") + } + + [console]::WriteLine("; File end: $filePath") +} + +ProcessFile $args[0] diff --git a/src/RandomX/vcxproj/jit-performance.vcxproj b/src/RandomX/vcxproj/jit-performance.vcxproj new file mode 100644 index 000000000..3b8329e3f --- /dev/null +++ b/src/RandomX/vcxproj/jit-performance.vcxproj @@ -0,0 +1,128 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {535F2111-FA81-4C76-A354-EDD2F9AA00E3} + jitperformance + 10.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + + + {3346a4ad-c438-4324-8b77-47a16452954b} + + + + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/jit-performance.vcxproj.filters b/src/RandomX/vcxproj/jit-performance.vcxproj.filters new file mode 100644 index 000000000..46a0be068 --- /dev/null +++ b/src/RandomX/vcxproj/jit-performance.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/perf-simulation.vcxproj b/src/RandomX/vcxproj/perf-simulation.vcxproj new file mode 100644 index 000000000..e779c7294 --- /dev/null +++ b/src/RandomX/vcxproj/perf-simulation.vcxproj @@ -0,0 +1,128 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {F1FC7AC0-2773-4A57-AFA7-56BB07216AA2} + perfsimulation + 10.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + + + {3346a4ad-c438-4324-8b77-47a16452954b} + + + + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/perf-simulation.vcxproj.filters b/src/RandomX/vcxproj/perf-simulation.vcxproj.filters new file mode 100644 index 000000000..5870291d5 --- /dev/null +++ b/src/RandomX/vcxproj/perf-simulation.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/randomx-dll.vcxproj b/src/RandomX/vcxproj/randomx-dll.vcxproj new file mode 100644 index 000000000..8b8ea8c08 --- /dev/null +++ b/src/RandomX/vcxproj/randomx-dll.vcxproj @@ -0,0 +1,217 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AdvancedVectorExtensions2 + + + + + + + + + + + + + + + + + + + + + + + + + + 15.0 + {59560AD8-18E3-463E-A941-BBD808EC7C83} + Win32Proj + randomxdll + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + false + + + true + + + true + + + false + randomx + + + + Use + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;RANDOMXDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + true + true + + + + + Use + Level3 + Disabled + true + WIN32;_DEBUG;RANDOMXDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + Use + Level3 + Disabled + true + _DEBUG;RANDOMXDLL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + + + Windows + true + + + + + NotUsing + Level3 + MaxSpeed + true + true + false + NDEBUG;RANDOMXDLL_EXPORTS;_WINDOWS;_USRDLL;RANDOMX_EXPORT=__declspec(dllexport) + true + + + Windows + true + true + true + + + + + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/randomx-dll.vcxproj.filters b/src/RandomX/vcxproj/randomx-dll.vcxproj.filters new file mode 100644 index 000000000..68e1b8559 --- /dev/null +++ b/src/RandomX/vcxproj/randomx-dll.vcxproj.filters @@ -0,0 +1,185 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/randomx.vcxproj b/src/RandomX/vcxproj/randomx.vcxproj new file mode 100644 index 000000000..e0625c88b --- /dev/null +++ b/src/RandomX/vcxproj/randomx.vcxproj @@ -0,0 +1,207 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {3346A4AD-C438-4324-8B77-47A16452954B} + randomx + 10.0 + + + + StaticLibrary + true + v143 + MultiByte + + + StaticLibrary + false + v143 + true + MultiByte + + + StaticLibrary + true + v143 + MultiByte + + + StaticLibrary + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + false + true + + + + + Level4 + Disabled + false + true + + + + + Level3 + MaxSpeed + true + true + false + true + NoExtensions + + + true + true + UseLinkTimeCodeGeneration + false + + + + + Level4 + MaxSpeed + true + true + false + true + AssemblyCode + _MBCS;NDEBUG;%(PreprocessorDefinitions) + + + true + true + UseLinkTimeCodeGeneration + false + + + 4194304 + + + powershell -ExecutionPolicy Bypass -File .\h2inc.ps1 ..\src\configuration.h > ..\src\asm\configuration.asm +SET ERRORLEVEL = 0 + + + + + + AdvancedVectorExtensions2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/randomx.vcxproj.filters b/src/RandomX/vcxproj/randomx.vcxproj.filters new file mode 100644 index 000000000..eb4462a59 --- /dev/null +++ b/src/RandomX/vcxproj/randomx.vcxproj.filters @@ -0,0 +1,212 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/runtime-distr.vcxproj b/src/RandomX/vcxproj/runtime-distr.vcxproj new file mode 100644 index 000000000..bf2e097e8 --- /dev/null +++ b/src/RandomX/vcxproj/runtime-distr.vcxproj @@ -0,0 +1,128 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {F207EC8C-C55F-46C0-8851-887A71574F54} + runtimedistr + 10.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + + + {3346a4ad-c438-4324-8b77-47a16452954b} + + + + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/runtime-distr.vcxproj.filters b/src/RandomX/vcxproj/runtime-distr.vcxproj.filters new file mode 100644 index 000000000..bb53c1b1c --- /dev/null +++ b/src/RandomX/vcxproj/runtime-distr.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/scratchpad-entropy.vcxproj b/src/RandomX/vcxproj/scratchpad-entropy.vcxproj new file mode 100644 index 000000000..436cba364 --- /dev/null +++ b/src/RandomX/vcxproj/scratchpad-entropy.vcxproj @@ -0,0 +1,128 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {FF8BD408-AFD8-43C6-BE98-4D03B37E840B} + scratchpadentropy + 10.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + + + {3346a4ad-c438-4324-8b77-47a16452954b} + + + + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/scratchpad-entropy.vcxproj.filters b/src/RandomX/vcxproj/scratchpad-entropy.vcxproj.filters new file mode 100644 index 000000000..a215bfab0 --- /dev/null +++ b/src/RandomX/vcxproj/scratchpad-entropy.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/superscalar-avalanche.vcxproj b/src/RandomX/vcxproj/superscalar-avalanche.vcxproj new file mode 100644 index 000000000..9251693fb --- /dev/null +++ b/src/RandomX/vcxproj/superscalar-avalanche.vcxproj @@ -0,0 +1,130 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {CF34A7EF-7DC9-4077-94A5-76F5425EA938} + superscalaravalanche + 10.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + false + true + + + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + + + {3346a4ad-c438-4324-8b77-47a16452954b} + + + + + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/superscalar-avalanche.vcxproj.filters b/src/RandomX/vcxproj/superscalar-avalanche.vcxproj.filters new file mode 100644 index 000000000..6f33fce4f --- /dev/null +++ b/src/RandomX/vcxproj/superscalar-avalanche.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/superscalar-init.vcxproj b/src/RandomX/vcxproj/superscalar-init.vcxproj new file mode 100644 index 000000000..49585ab27 --- /dev/null +++ b/src/RandomX/vcxproj/superscalar-init.vcxproj @@ -0,0 +1,130 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {E59DC709-9B12-4A53-BAF3-79398821C376} + superscalarinit + 10.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + false + true + + + true + true + + + + + Level3 + Disabled + false + true + + + + + Level3 + Disabled + false + true + + + + + Level3 + MaxSpeed + true + true + false + true + + + true + true + + + + + + + + {3346a4ad-c438-4324-8b77-47a16452954b} + + + + + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/superscalar-init.vcxproj.filters b/src/RandomX/vcxproj/superscalar-init.vcxproj.filters new file mode 100644 index 000000000..d78d2810f --- /dev/null +++ b/src/RandomX/vcxproj/superscalar-init.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/superscalar-stats.vcxproj b/src/RandomX/vcxproj/superscalar-stats.vcxproj new file mode 100644 index 000000000..bd681f3f0 --- /dev/null +++ b/src/RandomX/vcxproj/superscalar-stats.vcxproj @@ -0,0 +1,128 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {0173D560-8C12-46B3-B467-0C6E7573AA0B} + superscalarstats + 10.0 + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + false + true + + + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + + + + {3346a4ad-c438-4324-8b77-47a16452954b} + + + + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/superscalar-stats.vcxproj.filters b/src/RandomX/vcxproj/superscalar-stats.vcxproj.filters new file mode 100644 index 000000000..6d5129c3b --- /dev/null +++ b/src/RandomX/vcxproj/superscalar-stats.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/tests.vcxproj b/src/RandomX/vcxproj/tests.vcxproj new file mode 100644 index 000000000..62ccbd1c6 --- /dev/null +++ b/src/RandomX/vcxproj/tests.vcxproj @@ -0,0 +1,133 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {41F3F4DF-8113-4029-9915-FDDC44C43D49} + tests + 10.0 + tests + + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + Application + true + v143 + MultiByte + + + Application + false + v143 + true + MultiByte + + + + + + + + + + + + + + + + + + + + + + + Level3 + MaxSpeed + true + true + true + true + + + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + Disabled + true + true + + + + + Level3 + MaxSpeed + true + true + true + true + NoExtensions + + + true + true + + + + + + + + {3346a4ad-c438-4324-8b77-47a16452954b} + + + + + + + + + \ No newline at end of file diff --git a/src/RandomX/vcxproj/tests.vcxproj.filters b/src/RandomX/vcxproj/tests.vcxproj.filters new file mode 100644 index 000000000..d04c81562 --- /dev/null +++ b/src/RandomX/vcxproj/tests.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + + + Source Files + + + \ No newline at end of file From e6e5b3a352e0085c78eb83baa193895301dcaa6a Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 22 Jan 2022 23:57:42 -0500 Subject: [PATCH 004/255] Include randomx.h header in miner code --- src/miner.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/miner.cpp b/src/miner.cpp index 79f791159..894195c05 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -31,6 +31,7 @@ #include "consensus/validation.h" #ifdef ENABLE_MINING #include "crypto/equihash.h" +#include "RandomX/src/randomx.h" #endif #include "hash.h" #include "key_io.h" From a7a67a4668a78aeefc074a03840944cbf1e5f84a Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 22 Jan 2022 23:58:10 -0500 Subject: [PATCH 005/255] remove dead code --- src/miner.cpp | 45 --------------------------------------------- 1 file changed, 45 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 894195c05..c0d80fdee 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -763,53 +763,8 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 return pblocktemplate.release(); } -/* - #ifdef ENABLE_WALLET - boost::optional GetMinerScriptPubKey(CReserveKey& reservekey) - #else - boost::optional GetMinerScriptPubKey() - #endif - { - CKeyID keyID; - CBitcoinAddress addr; - if (addr.SetString(GetArg("-mineraddress", ""))) { - addr.GetKeyID(keyID); - } else { - #ifdef ENABLE_WALLET - CPubKey pubkey; - if (!reservekey.GetReservedKey(pubkey)) { - return boost::optional(); - } - keyID = pubkey.GetID(); - #else - return boost::optional(); - #endif - } - CScript scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG; - return scriptPubKey; - } - - #ifdef ENABLE_WALLET - CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey) - { - boost::optional scriptPubKey = GetMinerScriptPubKey(reservekey); - #else - CBlockTemplate* CreateNewBlockWithKey() - { - boost::optional scriptPubKey = GetMinerScriptPubKey(); - #endif - - if (!scriptPubKey) { - return NULL; - } - return CreateNewBlock(*scriptPubKey); - }*/ - -////////////////////////////////////////////////////////////////////////////// -// // Internal miner -// #ifdef ENABLE_MINING From 35dde25d98e661f00cddde23f48680c662bc1624 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 23 Jan 2022 00:32:01 -0500 Subject: [PATCH 006/255] Fill out some RandomXMiner code, which is BitcoinMiner without all the extraneous junk --- src/miner.cpp | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index c0d80fdee..da19909c8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -985,6 +985,176 @@ CBlockIndex *get_chainactive(int32_t height) int32_t gotinvalid; +#ifdef ENABLE_WALLET +void static RandomXMiner(CWallet *pwallet) +#else +void static RandomXMiner() +#endif +{ + LogPrintf("HushRandomXMiner started\n"); + SetThreadPriority(THREAD_PRIORITY_LOWEST); + RenameThread("hush-randomx"); + const CChainParams& chainparams = Params(); + +#ifdef ENABLE_WALLET + // Each thread has its own key + CReserveKey reservekey(pwallet); +#endif + // Each thread has its own counter + unsigned int nExtraNonce = 0; + + uint8_t *script; uint64_t total; int32_t i,j,gpucount=HUSH_MAXGPUCOUNT,notaryid = -1; + while ( (ASSETCHAIN_INIT == 0 || HUSH_INITDONE == 0) ) + { + sleep(1); + if ( hush_baseid(SMART_CHAIN_SYMBOL) < 0 ) + break; + } + + if ( notaryid != My_notaryid ) + My_notaryid = notaryid; + + std::mutex m_cs; + bool cancelSolver = false; + boost::signals2::connection c = uiInterface.NotifyBlockTip.connect( + [&m_cs, &cancelSolver](const uint256& hashNewTip) mutable { + std::lock_guard lock{m_cs}; + cancelSolver = true; + } + ); + miningTimer.start(); + + try { + if ( SMART_CHAIN_SYMBOL[0] != 0 ) + fprintf(stderr,"try %s Mining with %s\n",SMART_CHAIN_SYMBOL,solver.c_str()); + while (true) + { + if (chainparams.MiningRequiresPeers()) { + //if ( ASSETCHAINS_SEED != 0 && chainActive.LastTip()->GetHeight() < 100 ) + // break; + // Busy-wait for the network to come online so we don't waste time mining + // on an obsolete chain. In regtest mode we expect to fly solo. + miningTimer.stop(); + do { + bool fvNodesEmpty; + { + //LOCK(cs_vNodes); + fvNodesEmpty = vNodes.empty(); + } + if (!fvNodesEmpty )//&& !IsInitialBlockDownload()) + break; + MilliSleep(15000); + //fprintf(stderr,"fvNodesEmpty %d IsInitialBlockDownload(%s) %d\n",(int32_t)fvNodesEmpty,SMART_CHAIN_SYMBOL,(int32_t)IsInitialBlockDownload()); + + } while (true); + //fprintf(stderr,"%s Found peers\n",SMART_CHAIN_SYMBOL); + miningTimer.start(); + } + // + // Create new block + // + unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); + CBlockIndex* pindexPrev = chainActive.LastTip(); + if ( Mining_height != pindexPrev->GetHeight()+1 ) + { + Mining_height = pindexPrev->GetHeight()+1; + Mining_start = (uint32_t)time(NULL); + } +#ifdef ENABLE_WALLET + CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, 0); +#else + CBlockTemplate *ptr = CreateNewBlockWithKey(); +#endif + if ( ptr == 0 ) + { + if ( !GetBoolArg("-gen",false)) + { + miningTimer.stop(); + c.disconnect(); + LogPrintf("HushMiner terminated\n"); + return; + } + static uint32_t counter; + if ( counter++ < 10 && ASSETCHAINS_STAKED == 0 ) + fprintf(stderr,"created illegal blockB, retry\n"); + sleep(1); + continue; + } + //fprintf(stderr,"get template\n"); + unique_ptr pblocktemplate(ptr); + if (!pblocktemplate.get()) + { + if (GetArg("-mineraddress", "").empty()) { + LogPrintf("Error in HushMiner: Keypool ran out, please call keypoolrefill before restarting the mining thread\n"); + } else { + // Should never reach here, because -mineraddress validity is checked in init.cpp + LogPrintf("Error in HushMiner: Invalid -mineraddress\n"); + } + return; + } + CBlock *pblock = &pblocktemplate->block; + if ( SMART_CHAIN_SYMBOL[0] != 0 ) + { + if ( ASSETCHAINS_REWARD[0] == 0 && !ASSETCHAINS_LASTERA ) + { + if ( pblock->vtx.size() == 1 && pblock->vtx[0].vout.size() == 1 && Mining_height > ASSETCHAINS_MINHEIGHT ) + { + static uint32_t counter; + if ( counter++ < 10 ) + fprintf(stderr,"skip generating %s on-demand block, no tx avail\n",SMART_CHAIN_SYMBOL); + sleep(10); + continue; + } else fprintf(stderr,"%s vouts.%d mining.%d vs %d\n",SMART_CHAIN_SYMBOL,(int32_t)pblock->vtx[0].vout.size(),Mining_height,ASSETCHAINS_MINHEIGHT); + } + } + IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); + //fprintf(stderr,"Running HushMiner.%s with %u transactions in block\n",solver.c_str(),(int32_t)pblock->vtx.size()); + LogPrintf("Running HushRandomXMiner with %u transactions in block (%u bytes)\n",,pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); + + // Search + uint8_t pubkeys[66][33]; arith_uint256 bnMaxPoSdiff; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); + pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); + savebits = pblock->nBits; + HASHTarget = arith_uint256().SetCompact(savebits); + roundrobin_delay = ROUNDROBIN_DELAY; + + // HASHTarget_POW = hush_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); + gotinvalid = 0; + while (true) + { + //fprintf(stderr,"gotinvalid.%d\n",gotinvalid); + if ( gotinvalid != 0 ) + break; + hush_longestchain(); + + LogPrint("pow", "Running RandomX solver with nNonce = %s\n",pblock->nNonce.ToString()); + arith_uint256 hashTarget; + hashTarget = HASHTarget; + + // TODO: RandomX solver code + + } + + } + } + catch (const boost::thread_interrupted&) + { + miningTimer.stop(); + c.disconnect(); + LogPrintf("HushRandomXMiner terminated\n"); + throw; + } + catch (const std::runtime_error &e) + { + miningTimer.stop(); + c.disconnect(); + LogPrintf("HushRandomXMiner runtime error: %s\n", e.what()); + return; + } + miningTimer.stop(); + c.disconnect(); +} + #ifdef ENABLE_WALLET void static BitcoinMiner(CWallet *pwallet) #else From 0b7f57af449dad68e2463c05482f2abe269e761d Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 23 Jan 2022 01:10:57 -0500 Subject: [PATCH 007/255] Document possible values of -ac_algo --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 2aaa490a0..b262ee45d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -596,7 +596,7 @@ std::string HelpMessage(HelpMessageMode mode) // "ac" stands for "affects consensus" strUsage += HelpMessageGroup(_("Hush Smart Chain options:")); - strUsage += HelpMessageOpt("-ac_algo", _("Choose PoW mining algorithm, default is Equihash (200,9)")); + strUsage += HelpMessageOpt("-ac_algo", _("Choose PoW mining algorithm, either 'equihash' or 'randomx'. default is Equihash (200,9)")); strUsage += HelpMessageOpt("-ac_blocktime", _("Block time in seconds, default is 60")); strUsage += HelpMessageOpt("-ac_cc", _("Cryptoconditions, default 0")); strUsage += HelpMessageOpt("-ac_beam", _("BEAM integration")); From dba86be534d65fe6a7b634a85b85c6aba923035a Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 23 Jan 2022 23:15:12 -0500 Subject: [PATCH 008/255] Update randomx argon salt to make it unique --- src/RandomX/src/configuration.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RandomX/src/configuration.h b/src/RandomX/src/configuration.h index 84400ddce..da3367db5 100644 --- a/src/RandomX/src/configuration.h +++ b/src/RandomX/src/configuration.h @@ -38,7 +38,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define RANDOMX_ARGON_LANES 1 //Argon2d salt -#define RANDOMX_ARGON_SALT "RandomX\x03" +#define RANDOMX_ARGON_SALT "RandomXHUSH\x03" //Number of random Cache accesses per Dataset item. Minimum is 2. #define RANDOMX_CACHE_ACCESSES 8 From 000dc1dc34300431a6a7fb4a9803e469fdf870e7 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 24 Jan 2022 00:57:00 -0500 Subject: [PATCH 009/255] change some randomx config params after reading thru the spec+audits --- src/RandomX/src/configuration.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/RandomX/src/configuration.h b/src/RandomX/src/configuration.h index da3367db5..f74a74a4c 100644 --- a/src/RandomX/src/configuration.h +++ b/src/RandomX/src/configuration.h @@ -32,7 +32,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define RANDOMX_ARGON_MEMORY 262144 //Number of Argon2d iterations for Cache initialization. -#define RANDOMX_ARGON_ITERATIONS 3 +#define RANDOMX_ARGON_ITERATIONS 5 //Number of parallel lanes for Cache initialization. #define RANDOMX_ARGON_LANES 1 @@ -53,13 +53,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define RANDOMX_DATASET_EXTRA_SIZE 33554368 //Number of instructions in a RandomX program. Must be divisible by 8. -#define RANDOMX_PROGRAM_SIZE 256 +#define RANDOMX_PROGRAM_SIZE 512 //Number of iterations during VM execution. -#define RANDOMX_PROGRAM_ITERATIONS 2048 +#define RANDOMX_PROGRAM_ITERATIONS 4096 //Number of chained VM executions per hash. -#define RANDOMX_PROGRAM_COUNT 8 +#define RANDOMX_PROGRAM_COUNT 16 //Scratchpad L3 size in bytes. Must be a power of 2. #define RANDOMX_SCRATCHPAD_L3 2097152 From 15ca83b817ab15ca1d24f78d1b1cad77462f4716 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 24 Jan 2022 09:56:12 -0500 Subject: [PATCH 010/255] Add randomx to build.sh --- zcutil/build.sh | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/zcutil/build.sh b/zcutil/build.sh index 012b4d3f1..a5ecda2ca 100755 --- a/zcutil/build.sh +++ b/zcutil/build.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html @@ -108,12 +108,24 @@ HOST="$HOST" BUILD="$BUILD" "$MAKE" "$@" -C ./depends/ V=1 CONFIG_SITE="$PWD/depends/$HOST/share/config.site" ./configure "$HARDENING_ARG" "$LCOV_ARG" "$TEST_ARG" "$MINING_ARG" $CONFIGURE_FLAGS CXXFLAGS='-g' -#BUILD CCLIB - +# Build CryptoConditions stuff WD=$PWD cd src/cc echo $PWD ./makecustom cd $WD +# Build RandomX +cd src/RandomX +if [ -d "build" ] +then + ls -la build/librandomx* +else + mkdir build && cd build + cmake -DARCH=native .. + make +fi + +cd $WD + "$MAKE" "$@" V=1 From 6f707342eab06f45444a4b647f2f376f34e092d3 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 25 Jan 2022 23:09:15 -0500 Subject: [PATCH 011/255] Work even if build/ dir doesn't exist --- contrib/devtools/gen-linux-binary-release.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/contrib/devtools/gen-linux-binary-release.sh b/contrib/devtools/gen-linux-binary-release.sh index bcd34e7f3..cd4cec2b7 100755 --- a/contrib/devtools/gen-linux-binary-release.sh +++ b/contrib/devtools/gen-linux-binary-release.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 set -e @@ -11,8 +11,13 @@ VERSION=$(./src/hushd --version|grep version|cut -d' ' -f4|cut -d- -f1|sed 's/v/ FILE="hush-$VERSION-linux-amd64.tar" TIME=$(perl -e 'print time') -mv build build.$TIME +if [ -d "build" ] +then + mv build build.$TIME + echo "Moved existing build/ dir to build.$TIME" +fi mkdir build +echo "Created new build/ dir" cp contrib/asmap/asmap.dat build/ cp sapling*.params build/ cd src From 371e1baeb1845008aa4479c6fa0b89497468d039 Mon Sep 17 00:00:00 2001 From: onryo Date: Thu, 27 Jan 2022 14:01:28 +0000 Subject: [PATCH 012/255] Update 'src/hush_utils.h' --- src/hush_utils.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hush_utils.h b/src/hush_utils.h index 81030a268..d4d92bc1a 100644 --- a/src/hush_utils.h +++ b/src/hush_utils.h @@ -1810,7 +1810,7 @@ void hush_args(char *argv0) vector HUSH_nodes= {"node1.hush.is","node2.hush.is","node3.hush.is", "node4.hush.is","node5.hush.is","node6.hush.is", - "node7.hush.is","node8.hush.is","node1.hush.land", "node2.hush.land"}; + "node7.hush.is","node8.hush.is","node1.hush.land", "node2.hush.land", "node3.hush.land", "node4.hush.land", "node5.hush.land"}; vector more_nodes = mapMultiArgs["-addnode"]; if (more_nodes.size() > 0) { fprintf(stderr,"%s: Adding %lu more nodes via custom -addnode arguments\n", __func__, more_nodes.size() ); From bc3316165dd9c5ab96b8d2856fd2a6ca27ca1e8f Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 4 Feb 2022 14:55:44 +0000 Subject: [PATCH 013/255] Update 'INSTALL.md' --- INSTALL.md | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index eba94faa0..37e930058 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -26,11 +26,12 @@ sudo swapon /swapfile sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib \ autoconf libtool ncurses-dev unzip git python zlib1g-dev wget \ bsdmainutils automake curl unzip nano libsodium-dev -# pull +# clone git repo git clone https://git.hush.is/hush/hush3 cd hush3 # Build -./build.sh -j$(nproc) +# This uses 3 build processes, you need 2GB of RAM for each. +./build.sh -j3 ``` ### Building On Ubuntu 16.04 and older systems @@ -45,6 +46,23 @@ apt-get install -y gcc-7 g++-7 && \ update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 60 ``` +### Build on mac + +These instructions are a work in progress. Please report issues to https://hush.is/tg_support + +``` +sudo port update +sudo port upgrade outdated +sudo port install qt5 + +# clone git repo +git clone https://git.hush.is/hush/hush3 +cd hush3 +# Build +# This uses 3 build processes, you need 2GB of RAM for each. +./build.sh -j3 +``` + ## Run a HUSH Node After you have compiled Hush, then you can run it with the following command: From 32ea1efda4f8afd587734289f45b74c6ec518b1a Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 4 Feb 2022 14:59:39 +0000 Subject: [PATCH 014/255] Update 'INSTALL.md' --- INSTALL.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 37e930058..114ef1775 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -98,5 +98,5 @@ Currently, any ARMv7 machine will not be able to build this repo, because the underlying tech (zcash and the zksnark library) do not support that instruction set. -This also means that RaspberryPi devices will not work, unless they have a -newer ARMv8-based Raspberry Pi. +This also means that old RaspberryPi devices will not work, unless they have a +newer ARMv8-based Raspberry Pi. Raspberry Pi 4 and newer are known to work. From 6154e216b2fb81b3691af12587b00e2ae3763836 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 5 Feb 2022 22:37:02 -0500 Subject: [PATCH 015/255] updated manpage copyright to 2022 --- doc/man/hush-cli.1 | 2 +- doc/man/hush-tx.1 | 2 +- doc/man/hushd.1 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/man/hush-cli.1 b/doc/man/hush-cli.1 index 6179f7d95..35482a8fe 100644 --- a/doc/man/hush-cli.1 +++ b/doc/man/hush-cli.1 @@ -75,7 +75,7 @@ Read extra arguments from standard input, one per line until EOF/Ctrl\-D In order to ensure you are adequately protecting your privacy when using Hush, please see . -Copyright (C) 2016-2021 Duke Leto and The Hush Developers +Copyright (C) 2016-2022 Duke Leto and The Hush Developers Copyright (C) 2016-2020 jl777 and SuperNET developers Copyright (C) 2016-2018 The Zcash developers Copyright (C) 2009-2014 The Bitcoin Core developers diff --git a/doc/man/hush-tx.1 b/doc/man/hush-tx.1 index 54149df40..ec0004e1d 100644 --- a/doc/man/hush-tx.1 +++ b/doc/man/hush-tx.1 @@ -88,7 +88,7 @@ Set register NAME to given JSON\-STRING In order to ensure you are adequately protecting your privacy when using Hush, please see . -Copyright (C) 2016-2021 Duke Leto and The Hush Developers +Copyright (C) 2016-2022 Duke Leto and The Hush Developers Copyright (C) 2016-2020 jl777 and SuperNET developers Copyright (C) 2016-2018 The Zcash developers Copyright (C) 2009-2014 The Bitcoin Core developers diff --git a/doc/man/hushd.1 b/doc/man/hushd.1 index f5c1dd68e..73baab69f 100644 --- a/doc/man/hushd.1 +++ b/doc/man/hushd.1 @@ -712,7 +712,7 @@ Enforce transaction\-rate limit, default 0 In order to ensure you are adequately protecting your privacy when using Hush, please see . -Copyright (C) 2016-2021 Duke Leto and The Hush Developers +Copyright (C) 2016-2022 Duke Leto and The Hush Developers Copyright (C) 2016-2020 jl777 and SuperNET developers Copyright (C) 2016-2018 The Zcash developers Copyright (C) 2009-2014 The Bitcoin Core developers From 4e803c60552e0d65f1dae6091f141d1be6b36767 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Mon, 7 Feb 2022 00:49:02 -0500 Subject: [PATCH 016/255] reverted back to upstream --- doc/man/hush-cli.1 | 2 +- doc/man/hush-tx.1 | 2 +- doc/man/hushd.1 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/man/hush-cli.1 b/doc/man/hush-cli.1 index 35482a8fe..6179f7d95 100644 --- a/doc/man/hush-cli.1 +++ b/doc/man/hush-cli.1 @@ -75,7 +75,7 @@ Read extra arguments from standard input, one per line until EOF/Ctrl\-D In order to ensure you are adequately protecting your privacy when using Hush, please see . -Copyright (C) 2016-2022 Duke Leto and The Hush Developers +Copyright (C) 2016-2021 Duke Leto and The Hush Developers Copyright (C) 2016-2020 jl777 and SuperNET developers Copyright (C) 2016-2018 The Zcash developers Copyright (C) 2009-2014 The Bitcoin Core developers diff --git a/doc/man/hush-tx.1 b/doc/man/hush-tx.1 index ec0004e1d..54149df40 100644 --- a/doc/man/hush-tx.1 +++ b/doc/man/hush-tx.1 @@ -88,7 +88,7 @@ Set register NAME to given JSON\-STRING In order to ensure you are adequately protecting your privacy when using Hush, please see . -Copyright (C) 2016-2022 Duke Leto and The Hush Developers +Copyright (C) 2016-2021 Duke Leto and The Hush Developers Copyright (C) 2016-2020 jl777 and SuperNET developers Copyright (C) 2016-2018 The Zcash developers Copyright (C) 2009-2014 The Bitcoin Core developers diff --git a/doc/man/hushd.1 b/doc/man/hushd.1 index 73baab69f..f5c1dd68e 100644 --- a/doc/man/hushd.1 +++ b/doc/man/hushd.1 @@ -712,7 +712,7 @@ Enforce transaction\-rate limit, default 0 In order to ensure you are adequately protecting your privacy when using Hush, please see . -Copyright (C) 2016-2022 Duke Leto and The Hush Developers +Copyright (C) 2016-2021 Duke Leto and The Hush Developers Copyright (C) 2016-2020 jl777 and SuperNET developers Copyright (C) 2016-2018 The Zcash developers Copyright (C) 2009-2014 The Bitcoin Core developers From 026c23ee208cb879b97ee76db42fc33a73e01728 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Mon, 7 Feb 2022 02:14:58 -0500 Subject: [PATCH 017/255] ARM deb creation script --- contrib/debian/control | 2 +- zcutil/build-debian-package-ARM.sh | 115 +++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+), 1 deletion(-) create mode 100755 zcutil/build-debian-package-ARM.sh diff --git a/contrib/debian/control b/contrib/debian/control index 4b542452a..8526dd6b4 100644 --- a/contrib/debian/control +++ b/contrib/debian/control @@ -11,6 +11,6 @@ Vcs-Git: https://git.hush.is/hush/hush3.git Vcs-Browser: https://git.hush.is/hush/hush3 Package: hush -Architecture: amd64 +Architecture: amd64 arm64 Depends: ${shlibs:Depends} Description: Hush cryptocoin full node. Speak And Transact Freely. Hush inherits from Bitcoin Protocol and Zcash Protocol and is focused on private communications. diff --git a/zcutil/build-debian-package-ARM.sh b/zcutil/build-debian-package-ARM.sh new file mode 100755 index 000000000..a2f9629cf --- /dev/null +++ b/zcutil/build-debian-package-ARM.sh @@ -0,0 +1,115 @@ +#!/usr/bin/env bash +# Copyright (c) 2016-2022 The Hush developers +# Distributed under the GPLv3 software license, see the accompanying +# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html +# +# Remix for SBC (Single Board Computer) like PineBook, Rock64, Raspberry Pi, etc. +## Usage: ./zcutil/build-debian-package-ARM.sh + +# Pre-requisite checks +# Check if lintian is installed and exit if it is not +if ! [ -x "$(command -v lintian)" ]; then + echo 'Error: lintian is not installed yet. Consult your Linux version package manager...' >&2 + echo 'On Debian/Ubuntu, try "sudo apt install lintian"' + echo "" + exit 1 +fi +# Check if fakeroot is installed and exit if it is not +if ! [ -x "$(command -v fakeroot)" ]; then + echo 'Error: fakeroot is not installed yet. Consult your Linux version package manager...' >&2 + echo 'On Debian/Ubuntu, try "sudo apt install fakeroot"' + echo "" + exit 1 +fi + +echo "Let There Be Hush Debian ARM Packages" +echo "" +echo " ______" +echo " |\_______________ (_____\\______________" +echo "HH======#H###############H#######################" +echo ' ~"""""""""""""""`##(_))#H\"""""Y########' +echo " )) \#H\ ##Y###" +echo 'dew " }#H)' +echo "" + +set -e +set -x + +BUILD_PATH="/tmp/hush-debian-$$" +PACKAGE_NAME="hush" +SRC_PATH=`pwd` +SRC_DEB=$SRC_PATH/contrib/debian +SRC_DOC=$SRC_PATH/doc +ARCH="aarch64" + +umask 022 + +if [ ! -d $BUILD_PATH ]; then + mkdir $BUILD_PATH +fi + +PACKAGE_VERSION=$($SRC_PATH/src/hushd --version|grep version|cut -d' ' -f4|cut -d- -f1|sed 's/v//g') +DEBVERSION=$(echo $PACKAGE_VERSION | sed 's/-beta/~beta/' | sed 's/-rc/~rc/' | sed 's/-/+/') +BUILD_DIR="$BUILD_PATH/$PACKAGE_NAME-$PACKAGE_VERSION-$ARCH" + +if [ -d $BUILD_DIR ]; then + rm -R $BUILD_DIR +fi + +DEB_BIN=$BUILD_DIR/usr/bin +DEB_CMP=$BUILD_DIR/usr/share/bash-completion/completions +DEB_DOC=$BUILD_DIR/usr/share/doc/$PACKAGE_NAME +DEB_MAN=$BUILD_DIR/usr/share/man/man1 +DEB_SHR=$BUILD_DIR/usr/share/hush +mkdir -p $BUILD_DIR/DEBIAN $DEB_CMP $DEB_BIN $DEB_DOC $DEB_MAN $DEB_SHR +chmod 0755 -R $BUILD_DIR/* + +# Package maintainer scripts (currently empty) +#cp $SRC_DEB/postinst $BUILD_DIR/DEBIAN +#cp $SRC_DEB/postrm $BUILD_DIR/DEBIAN +#cp $SRC_DEB/preinst $BUILD_DIR/DEBIAN +#cp $SRC_DEB/prerm $BUILD_DIR/DEBIAN + +cp $SRC_PATH/contrib/asmap/asmap.dat $DEB_SHR +cp $SRC_PATH/sapling-spend.params $DEB_SHR +cp $SRC_PATH/sapling-output.params $DEB_SHR +cp $SRC_PATH/src/hushd $DEB_BIN +strip $DEB_BIN/hushd +cp $SRC_PATH/src/hush-cli $DEB_BIN +strip $DEB_BIN/hush-cli +cp $SRC_PATH/src/hush-tx $DEB_BIN +strip $DEB_BIN/hush-tx +cp $SRC_PATH/src/hush-smart-chain $DEB_BIN +#cp $SRC_DEB/changelog $DEB_DOC/changelog.Debian +cp $SRC_DEB/copyright $DEB_DOC +cp -r $SRC_DEB/examples $DEB_DOC +# Copy manpages +cp $SRC_DOC/man/hushd.1 $DEB_MAN/hushd.1 +cp $SRC_DOC/man/hush-cli.1 $DEB_MAN/hush-cli.1 +cp $SRC_DOC/man/hush-tx.1 $DEB_MAN/hush-tx.1 + +# Copy bash completion files +cp $SRC_PATH/contrib/hushd.bash-completion $DEB_CMP/hushd +cp $SRC_PATH/contrib/hush-cli.bash-completion $DEB_CMP/hush-cli +cp $SRC_PATH/contrib/hush-tx.bash-completion $DEB_CMP/hush-tx +# Gzip files +#gzip --best -n $DEB_DOC/changelog +#gzip --best -n $DEB_DOC/changelog.Debian +gzip --best -n $DEB_MAN/hushd.1 +gzip --best -n $DEB_MAN/hush-cli.1 +gzip --best -n $DEB_MAN/hush-tx.1 + +cd $SRC_PATH/contrib + +# Create the control file +dpkg-shlibdeps $DEB_BIN/hushd $DEB_BIN/hush-cli $DEB_BIN/hush-tx +dpkg-gencontrol -P$BUILD_DIR -v$DEBVERSION +#dpkg-gencontrol -P$BUILD_DIR + +# Create the Debian package +fakeroot dpkg-deb --build $BUILD_DIR +cp $BUILD_PATH/$PACKAGE_NAME-$PACKAGE_VERSION-$ARCH.deb $SRC_PATH +shasum -a 256 $SRC_PATH/$PACKAGE_NAME-$PACKAGE_VERSION-$ARCH.deb +# Analyze with Lintian, reporting bugs and policy violations +lintian -i $SRC_PATH/$PACKAGE_NAME-$PACKAGE_VERSION-$ARCH.deb +exit 0 From a157a5c6a1933cf6e2bf3e5998a226317aaad118 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 14 Feb 2022 14:10:08 -0500 Subject: [PATCH 018/255] update --- src/Makefile.test-hush.include | 4 ++-- src/cc/CC_made_easy.md | 4 ++-- src/cc/betprotocol.cpp | 4 ++-- src/cc/betprotocol.h | 4 ++-- src/cc/channels.cpp | 8 +++---- src/cc/eval.cpp | 12 +++++------ src/cc/eval.h | 4 ++-- src/cc/gateways.cpp | 18 ++++++++-------- src/cc/importgateway.cpp | 14 ++++++------ src/cc/importpayout.cpp | 4 ++-- src/hush.h | 14 ++++++------ src/hush_bitcoind.h | 26 +++++++++++------------ src/main.cpp | 2 +- src/notarizationdb.h | 6 +++--- src/test-hush/test_eval_bet.cpp | 6 +++--- src/test-hush/test_parse_notarization.cpp | 2 +- 16 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/Makefile.test-hush.include b/src/Makefile.test-hush.include index f638ebe59..9d6379ea0 100644 --- a/src/Makefile.test-hush.include +++ b/src/Makefile.test-hush.include @@ -12,8 +12,8 @@ hush_test_SOURCES = test-hush/main.cpp # test-hush/test_cryptoconditions.cpp \ # test-hush/test_coinimport.cpp \ # test-hush/test_eval_bet.cpp \ -# test-hush/test_eval_notarisation.cpp \ -# test-hush/test_parse_notarisation.cpp \ +# test-hush/test_eval_notarization.cpp \ +# test-hush/test_parse_notarization.cpp \ # test-hush/test_addrman.cpp \ # test-hush/test_netbase_tests.cpp diff --git a/src/cc/CC_made_easy.md b/src/cc/CC_made_easy.md index 149c5321c..79655dcbc 100644 --- a/src/cc/CC_made_easy.md +++ b/src/cc/CC_made_easy.md @@ -496,13 +496,13 @@ channelsopen: Used to open channel between two pub keys (sender and receiver). Parameters: destination_pubkey, total_number_of_payments, payment_denomination. Example - channelsopen 03a8fe537de2ace0d9c210b0ff945085c9192c9abf56ea22f22ce7998f289bb7bb 10 10000000 channelspayment: - Sending payment to receiver. Condition is that the channel open tx is confirmed/notarised. Parameters: open_tx_id, payment_amount, [secret] (optional, used when receiver needs to make a payment which secret has already been revealed by sender). + Sending payment to receiver. Condition is that the channel open tx is confirmed/notarized. Parameters: open_tx_id, payment_amount, [secret] (optional, used when receiver needs to make a payment which secret has already been revealed by sender). Example - channelspayment b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 20000000 channelsclose: Marking channel as closed. This RPC only creates a tx which says that the channel is closed and will be used in refund RPC to withdraw funds from closed channel. This also notifies receiver that channel fund could be withdrawn, but the payment RPC is still available until all funds are withdrawn. Parameters: open_tx_id. Example - channelsclose b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 channelsrefund: - Withdrawing funds back to senders address. Refund can be issued only when channel close tx is confirmed/notarised. Parameters: open_tx_id, close_tx_id + Withdrawing funds back to senders address. Refund can be issued only when channel close tx is confirmed/notarized. Parameters: open_tx_id, close_tx_id Example - channelsrefund b9c141facc8cb71306d0de8e525b3de1450e93e17fc8799c8fda5ed52fd14440 bb0ea34f846247642684c7c541c435b06ee79e47893640e5d2e51023841677fd channelsinfo: Getting info about channels in which the issuer is involved, either as sender or receiver. Call without parameters give the list of available channels. Parameters: [open_tx_id] (optional - used to get info about specific channel) diff --git a/src/cc/betprotocol.cpp b/src/cc/betprotocol.cpp index d8e904287..c6b76bb2c 100644 --- a/src/cc/betprotocol.cpp +++ b/src/cc/betprotocol.cpp @@ -164,7 +164,7 @@ bool GetOpReturnHash(CScript script, uint256 &hash) /* * Crypto-Condition EVAL method that verifies a payout against a transaction - * notarised on another chain. + * notarized on another chain. * * IN: params - condition params * IN: importTx - Payout transaction on value chain (HUSH) @@ -219,7 +219,7 @@ bool Eval::ImportPayout(const std::vector params, const CTransaction &i // Check disputeTx solves momproof from vout[0] { NotarizationData data(0); - if (!GetNotarizationData(proof.notarisationHash, data)) + if (!GetNotarizationData(proof.notarizationHash, data)) return Invalid("coudnt-load-mom"); if (data.MoM != proof.branch.Exec(disputeTx.GetHash())) diff --git a/src/cc/betprotocol.h b/src/cc/betprotocol.h index 6694cb331..5dd920aba 100644 --- a/src/cc/betprotocol.h +++ b/src/cc/betprotocol.h @@ -29,12 +29,12 @@ class MoMProof { public: MerkleBranch branch; - uint256 notarisationHash; + uint256 notarizationHash; ADD_SERIALIZE_METHODS; template inline void SerializationOp(Stream& s, Operation ser_action) { READWRITE(branch); - READWRITE(notarisationHash); + READWRITE(notarizationHash); } }; diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 135d0dc9d..389de64d8 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -250,7 +250,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else if ( ConstrainVout(channelOpenTx.vout[2],1,destmarker,CC_MARKER_VALUE)==0 ) return eval->Invalid("vout.2 is CC marker to destpub or invalid amount for channelopen!"); else if (hush_txnotarizedconfirmed(opentxid) == 0) - return eval->Invalid("channelopen is not yet confirmed(notarised)!"); + return eval->Invalid("channelopen is not yet confirmed(notarized)!"); else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for channelpayment!"); else if ( IsCCInput(tx.vin[tx.vin.size()-2].scriptSig) == 0 ) @@ -311,7 +311,7 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else if ( ConstrainVout(channelOpenTx.vout[2],1,destmarker,CC_MARKER_VALUE)==0 ) return eval->Invalid("vout.2 is CC marker to destpub or invalid amount for channelopen!"); else if (hush_txnotarizedconfirmed(opentxid) == 0) - return eval->Invalid("channelopen is not yet confirmed(notarised)!"); + return eval->Invalid("channelopen is not yet confirmed(notarized)!"); else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for channelclose!"); else if ( IsCCInput(tx.vin[tx.vin.size()-2].scriptSig) == 0 ) @@ -352,9 +352,9 @@ bool ChannelsValidate(struct CCcontract_info *cp,Eval* eval,const CTransaction & else if ( ConstrainVout(channelOpenTx.vout[2],1,destmarker,CC_MARKER_VALUE)==0 ) return eval->Invalid("vout.2 is CC marker to destpub or invalid amount for channelopen!"); else if (hush_txnotarizedconfirmed(opentxid) == 0) - return eval->Invalid("channelopen is not yet confirmed(notarised)!"); + return eval->Invalid("channelopen is not yet confirmed(notarized)!"); else if (hush_txnotarizedconfirmed(param3) == 0) - return eval->Invalid("channelClose is not yet confirmed(notarised)!"); + return eval->Invalid("channelClose is not yet confirmed(notarized)!"); else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for channelrefund!"); else if ( IsCCInput(tx.vin[tx.vin.size()-2].scriptSig) == 0 ) diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index 9f362db6c..c99160a3b 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -180,14 +180,14 @@ bool Eval::CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t t return CheckTxAuthority(tx, auth); } -// Get MoM from a notarisation tx hash (on HUSH) +// Get MoM from a notarization tx hash (on HUSH) bool Eval::GetNotarizationData(const uint256 notaryHash, NotarizationData &data) const { - CTransaction notarisationTx; + CTransaction notarizationTx; CBlockIndex block; - if (!GetTxConfirmed(notaryHash, notarisationTx, block)) return false; - if (!CheckNotaryInputs(notarisationTx, block.GetHeight(), block.nTime)) return false; - if (!ParseNotarizationOpReturn(notarisationTx, data)) return false; + if (!GetTxConfirmed(notaryHash, notarizationTx, block)) return false; + if (!CheckNotaryInputs(notarizationTx, block.GetHeight(), block.nTime)) return false; + if (!ParseNotarizationOpReturn(notarizationTx, data)) return false; return true; } @@ -205,7 +205,7 @@ std::string Eval::GetAssetchainsSymbol() const /* - * Notarization data, ie, OP_RETURN payload in notarisation transactions + * Notarization data, ie, OP_RETURN payload in notarization transactions */ bool ParseNotarizationOpReturn(const CTransaction &tx, NotarizationData &data) { diff --git a/src/cc/eval.h b/src/cc/eval.h index d4581e8ef..5c6784086 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -110,7 +110,7 @@ public: virtual bool GetSpendsConfirmed(uint256 hash, std::vector &spends) const; virtual bool GetBlock(uint256 hash, CBlockIndex& blockIdx) const; virtual int32_t GetNotaries(uint8_t pubkeys[64][33], int32_t height, uint32_t timestamp) const; - virtual bool GetNotarizationData(uint256 notarisationHash, NotarizationData &data) const; + virtual bool GetNotarizationData(uint256 notarizationHash, NotarizationData &data) const; virtual bool CheckNotaryInputs(const CTransaction &tx, uint32_t height, uint32_t timestamp) const; virtual uint32_t GetAssetchainsCC() const; virtual std::string GetAssetchainsSymbol() const; @@ -158,7 +158,7 @@ extern char SMART_CHAIN_SYMBOL[65]; /* - * Data from notarisation OP_RETURN from chain being notarised + * Data from notarization OP_RETURN from chain being notarized */ class NotarizationData { diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index c8036e5f2..4a38c9daf 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -613,7 +613,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & return eval->Invalid(validationError); } else if (hush_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!"); else if (myGetTransaction(deposittxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysdeposittxid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysDepositOpRet(tmptx.vout[numvouts-1].scriptPubKey,tmptxid,tmprefcoin,tmppublishers,txids,height,cointxid,claimvout,hex,proof,tmppubkey,tmpamount) != 'D') @@ -631,7 +631,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmpamount>totalsupply) return eval->Invalid("deposit amount greater then bind total supply"); else if (hush_txnotarizedconfirmed(deposittxid) == false) - return eval->Invalid("gatewaysdeposit tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysdeposit tx is not yet confirmed(notarized)!"); else if (tx.vin.size()>0) { i=0; @@ -705,7 +705,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if ( ConstrainVout(tmptx.vout[1],1,gatewaystokensaddr,amount)==0) return eval->Invalid("invalid tokens to gateways vout for gatewaysWithdraw!"); else if (hush_txnotarizedconfirmed(withdrawtxid) == false) - return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!"); else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysbind txid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') @@ -715,7 +715,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmptokenid!=tokenid) return eval->Invalid("tokenid does not match tokenid from gatewaysbind"); else if (hush_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!"); else if (IsCCInput(tx.vin[0].scriptSig) != 0) return eval->Invalid("vin.0 is normal for gatewayspartialsign!"); else if ((*cp->ismyvin)(tx.vin[tx.vin.size()-1].scriptSig) == 0 || myGetTransaction(tx.vin[tx.vin.size()-1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[tx.vin.size()-1].prevout.n].nValue!=CC_MARKER_VALUE) @@ -747,7 +747,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmptx.vout[1].nValue!=amount) return eval->Invalid("amount in opret not matching tx tokens amount!"); else if (hush_txnotarizedconfirmed(withdrawtxid) == false) - return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!"); else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysbind txid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') @@ -757,7 +757,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmptokenid!=tokenid) return eval->Invalid("tokenid does not match tokenid from gatewaysbind"); else if (hush_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!"); else if (IsCCInput(tx.vin[0].scriptSig) != 0) return eval->Invalid("vin.0 is normal for gatewayscompletesigning!"); else if ((*cp->ismyvin)(tx.vin[tx.vin.size()-1].scriptSig) == 0 || myGetTransaction(tx.vin[tx.vin.size()-1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[tx.vin.size()-1].prevout.n].nValue!=CC_MARKER_VALUE) @@ -778,7 +778,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if ((numvouts=tmptx.vout.size()) > 0 && DecodeGatewaysCompleteSigningOpRet(tmptx.vout[numvouts-1].scriptPubKey,withdrawtxid,tmprefcoin,K,hex)!='S') return eval->Invalid("invalid gatewayscompletesigning OP_RETURN data!"); else if (hush_txnotarizedconfirmed(completetxid) == false) - return eval->Invalid("gatewayscompletesigning tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayscompletesigning tx is not yet confirmed(notarized)!"); else if (myGetTransaction(withdrawtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid withdraw txid!"); else if ((numvouts=tmptx.vout.size()) > 0 && DecodeGatewaysWithdrawOpRet(tmptx.vout[numvouts-1].scriptPubKey,tmptokenid,bindtxid,tmprefcoin,pubkey,amount)!='W') @@ -786,7 +786,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmprefcoin!=refcoin) return eval->Invalid("refcoin different than in bind tx"); else if (hush_txnotarizedconfirmed(withdrawtxid) == false) - return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!"); else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysbind txid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeGatewaysBindOpRet(depositaddr,tmptx.vout[numvouts-1].scriptPubKey,tokenid,tmprefcoin,totalsupply,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') @@ -796,7 +796,7 @@ bool GatewaysValidate(struct CCcontract_info *cp,Eval *eval,const CTransaction & else if (tmptokenid!=tokenid) return eval->Invalid("tokenid does not match tokenid from gatewaysbind"); else if (hush_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!"); else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for gatewaysmarkdone!"); else if ((*cp->ismyvin)(tx.vin[tx.vin.size()-1].scriptSig) == 0 || myGetTransaction(tx.vin[tx.vin.size()-1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[tx.vin.size()-1].prevout.n].nValue!=CC_MARKER_VALUE) diff --git a/src/cc/importgateway.cpp b/src/cc/importgateway.cpp index 1afaeec94..12ab0f90e 100644 --- a/src/cc/importgateway.cpp +++ b/src/cc/importgateway.cpp @@ -361,7 +361,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact else if (tmptx.vout[1].nValue!=amount) return eval->Invalid("amount in opret not matching tx tokens amount!"); else if (hush_txnotarizedconfirmed(withdrawtxid) == false) - return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!"); else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysbind txid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeImportGatewayBindOpRet(burnaddr,tmptx.vout[numvouts-1].scriptPubKey,tmprefcoin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') @@ -369,7 +369,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact else if (tmprefcoin!=refcoin) return eval->Invalid("refcoin different than in bind tx"); else if (hush_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!"); else if (IsCCInput(tx.vin[0].scriptSig) != 0) return eval->Invalid("vin.0 is normal for gatewayspartialsign!"); else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE) @@ -403,7 +403,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact else if (tmptx.vout[1].nValue!=amount) return eval->Invalid("amount in opret not matching tx tokens amount!"); else if (hush_txnotarizedconfirmed(withdrawtxid) == false) - return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!"); else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysbind txid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeImportGatewayBindOpRet(burnaddr,tmptx.vout[numvouts-1].scriptPubKey,tmprefcoin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') @@ -411,7 +411,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact else if (tmprefcoin!=refcoin) return eval->Invalid("refcoin different than in bind tx"); else if (hush_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!"); else if (IsCCInput(tx.vin[0].scriptSig) != 0) return eval->Invalid("vin.0 is normal for gatewayscompletesigning!"); else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE) @@ -432,7 +432,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact else if ((numvouts=tmptx.vout.size()) > 0 && DecodeImportGatewayCompleteSigningOpRet(tmptx.vout[numvouts-1].scriptPubKey,withdrawtxid,tmprefcoin,K,hex)!='S') return eval->Invalid("invalid gatewayscompletesigning OP_RETURN data!"); else if (hush_txnotarizedconfirmed(completetxid) == false) - return eval->Invalid("gatewayscompletesigning tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayscompletesigning tx is not yet confirmed(notarized)!"); else if (myGetTransaction(withdrawtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid withdraw txid!"); else if ((numvouts=tmptx.vout.size()) > 0 && DecodeImportGatewayWithdrawOpRet(tmptx.vout[numvouts-1].scriptPubKey,bindtxid,tmprefcoin,pubkey,amount)!='W') @@ -440,7 +440,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact else if (tmprefcoin!=refcoin) return eval->Invalid("refcoin different than in bind tx"); else if (hush_txnotarizedconfirmed(withdrawtxid) == false) - return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewayswithdraw tx is not yet confirmed(notarized)!"); else if (myGetTransaction(bindtxid,tmptx,hashblock) == 0) return eval->Invalid("invalid gatewaysbind txid!"); else if ((numvouts=tmptx.vout.size()) < 1 || DecodeImportGatewayBindOpRet(burnaddr,tmptx.vout[numvouts-1].scriptPubKey,tmprefcoin,oracletxid,M,N,pubkeys,taddr,prefix,prefix2,wiftype) != 'B') @@ -448,7 +448,7 @@ bool ImportGatewayValidate(struct CCcontract_info *cp,Eval *eval,const CTransact else if (tmprefcoin!=refcoin) return eval->Invalid("refcoin different than in bind tx"); else if (hush_txnotarizedconfirmed(bindtxid) == false) - return eval->Invalid("gatewaysbind tx is not yet confirmed(notarised)!"); + return eval->Invalid("gatewaysbind tx is not yet confirmed(notarized)!"); else if ( IsCCInput(tx.vin[0].scriptSig) != 0 ) return eval->Invalid("vin.0 is normal for gatewaysmarkdone!"); else if ((*cp->ismyvin)(tx.vin[1].scriptSig) == 0 || myGetTransaction(tx.vin[1].prevout.hash,tmptx,hashblock)==0 || tmptx.vout[tx.vin[1].prevout.n].nValue!=CC_MARKER_VALUE) diff --git a/src/cc/importpayout.cpp b/src/cc/importpayout.cpp index a3fd90394..481e846f0 100644 --- a/src/cc/importpayout.cpp +++ b/src/cc/importpayout.cpp @@ -28,7 +28,7 @@ /* * Crypto-Condition EVAL method that verifies a payout against a transaction - * notarised on another chain. + * notarized on another chain. * * IN: params - condition params * IN: importTx - Payout transaction on value chain (HUSH) @@ -83,7 +83,7 @@ bool Eval::ImportPayout(const std::vector params, const CTransaction &i // Check disputeTx solves momproof from vout[0] { NotarizationData data; - if (!GetNotarizationData(proof.notarisationHash, data)) + if (!GetNotarizationData(proof.notarizationHash, data)) return Invalid("coudnt-load-mom"); if (data.MoM != proof.Exec(disputeTx.GetHash())) diff --git a/src/hush.h b/src/hush.h index ee9f608f2..68a5051ca 100644 --- a/src/hush.h +++ b/src/hush.h @@ -704,7 +704,7 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi printf("[%s] ht.%d NOTARIZED.%d %s.%s %sTXID.%s lens.(%d %d) MoM.%s %d\n",SMART_CHAIN_SYMBOL,height,sp->NOTARIZED_HEIGHT,SMART_CHAIN_SYMBOL,srchash.ToString().c_str(),"HUSH",desttxid.ToString().c_str(),opretlen,len,sp->MoM.ToString().c_str(),sp->MoMdepth); } //else if ( fJustCheck ) - // return (-3); // if the notarisation is only invalid because its out of order it cannot be mined in a block with a valid one! + // return (-3); // if the notarization is only invalid because its out of order it cannot be mined in a block with a valid one! } else if ( opretlen != 149 && height > 600000 && matched != 0 ) printf("%s validated.%d notarized.%d %llx reject ht.%d NOTARIZED.%d prev.%d %s.%s DESTTXID.%s len.%d opretlen.%d\n",ccdata.symbol,validated,notarized,(long long)signedmask,height,*notarizedheightp,sp->NOTARIZED_HEIGHT,SMART_CHAIN_SYMBOL,srchash.ToString().c_str(),desttxid.ToString().c_str(),len,opretlen); } @@ -764,7 +764,7 @@ int32_t hush_notarycmp(uint8_t *scriptPubKey,int32_t scriptlen,uint8_t pubkeys[6 int32_t hush_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) { static int32_t hwmheight; - std::vector notarisations; + std::vector notarizations; uint64_t signedmask,voutmask; char symbol[HUSH_SMART_CHAIN_MAXLEN],dest[HUSH_SMART_CHAIN_MAXLEN]; struct hush_state *sp; uint8_t scriptbuf[10001],pubkeys[64][33],rmd160[20],scriptPubKey[35]; uint256 zero,btctxid,txhash; int32_t i,j,k,numnotaries,notarized,scriptlen,isratification,nid,numvalid,specialtx,notarizedheight,notaryid,len,numvouts,numvins,height,txn_count; @@ -897,8 +897,8 @@ int32_t hush_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) notaryid = hush_voutupdate(fJustCheck,&isratification,notaryid,scriptbuf,len,height,txhash,i,j,&voutmask,&specialtx,¬arizedheight,(uint64_t)block.vtx[i].vout[j].nValue,notarized,signedmask,(uint32_t)chainActive.LastTip()->GetBlockTime()); if ( fJustCheck && notaryid == -2 ) { - // We see a valid notarisation here, save its location. - notarisations.push_back(i); + // We see a valid notarization here, save its location. + notarizations.push_back(i); } if ( 0 && i > 0 ) { @@ -961,11 +961,11 @@ int32_t hush_connectblock(bool fJustCheck, CBlockIndex *pindex,CBlock& block) //fprintf(stderr,"%s end connect.%d\n",SMART_CHAIN_SYMBOL,pindex->GetHeight()); if (fJustCheck) { - if ( notarisations.size() == 0 ) + if ( notarizations.size() == 0 ) return(0); - if ( notarisations.size() == 1 && notarisations[0] == 1 ) + if ( notarizations.size() == 1 && notarizations[0] == 1 ) return(1); - if ( notarisations.size() > 1 || (notarisations.size() == 1 && notarisations[0] != 1) ) + if ( notarizations.size() > 1 || (notarizations.size() == 1 && notarizations[0] != 1) ) return(-1); fprintf(stderr,"hush_connectblock: unxexpected behaviour when fJustCheck == true, report bug plz ! \n"); diff --git a/src/hush_bitcoind.h b/src/hush_bitcoind.h index 0aefbcccf..d690cc8a2 100644 --- a/src/hush_bitcoind.h +++ b/src/hush_bitcoind.h @@ -1375,7 +1375,7 @@ uint64_t hush_notarypayamount(int32_t nHeight, int64_t notarycount) int32_t hush_getnotarizedheight(uint32_t timestamp,int32_t height, uint8_t *script, int32_t len) { - // Check the notarisation is valid, and extract notarised height. + // Check the notarization is valid, and extract notarized height. uint64_t voutmask; uint8_t scriptbuf[10001]; int32_t isratification,specialtx,notarizedheight; @@ -1403,7 +1403,7 @@ uint64_t hush_notarypay(CMutableTransaction &txNew, std::vector &Notariz if ( notarypubkeys[0][0] == 0 ) return(0); - // Check the notarisation is valid. + // Check the notarization is valid. int32_t notarizedheight = hush_getnotarizedheight(timestamp, height, script, len); if ( notarizedheight == 0 ) return(0); @@ -1416,7 +1416,7 @@ uint64_t hush_notarypay(CMutableTransaction &txNew, std::vector &Notariz if ( AmountToPay == 0 ) return(0); - // loop over notarisation vins and add transaction to coinbase. + // loop over notarization vins and add transaction to coinbase. // Commented prints here can be used to verify manually the pubkeys match. for (int8_t n = 0; n < NotarizationNotaries.size(); n++) { @@ -1468,10 +1468,10 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height) if ( !GetNotarizationNotaries(notarypubkeys, numSN, pblock->vtx[1].vin, NotarizationNotaries) ) return(0); - // check a notary didnt sign twice (this would be an invalid notarisation later on and cause problems) + // check a notary didnt sign twice (this would be an invalid notarization later on and cause problems) std::set checkdupes( NotarizationNotaries.begin(), NotarizationNotaries.end() ); if ( checkdupes.size() != NotarizationNotaries.size() ) { - fprintf(stderr, "Possible notarisation is signed multiple times by same notary. It is invalid.\n"); + fprintf(stderr, "Possible notarization is signed multiple times by same notary. It is invalid.\n"); return(0); } const CChainParams& chainparams = Params(); @@ -1480,7 +1480,7 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height) CMutableTransaction txNew = CreateNewContextualCMutableTransaction(consensusParams, height); if ( pblock->vtx[1].vout.size() == 2 && pblock->vtx[1].vout[1].nValue == 0 ) { - // Get the OP_RETURN for the notarisation + // Get the OP_RETURN for the notarization uint8_t *script = (uint8_t *)&pblock->vtx[1].vout[1].scriptPubKey[0]; int32_t scriptlen = (int32_t)pblock->vtx[1].vout[1].scriptPubKey.size(); if ( script[0] == OP_RETURN ) @@ -1491,13 +1491,13 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height) } else { - fprintf(stderr, "vout 2 of notarisation is not OP_RETURN scriptlen.%i\n", scriptlen); + fprintf(stderr, "vout 2 of notarization is not OP_RETURN scriptlen.%i\n", scriptlen); return(0); } } else return(0); - // if notarypay fails, because the notarisation is not valid, exit now as txNew was not created. - // This should never happen, as the notarisation is checked before this function is called. + // if notarypay fails, because the notarization is not valid, exit now as txNew was not created. + // This should never happen, as the notarization is checked before this function is called. if ( totalsats == 0 ) { fprintf(stderr, "notary pay returned 0!\n"); @@ -1519,7 +1519,7 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height) n++; continue; } - // Check the pubkeys match the pubkeys in the notarisation. + // Check the pubkeys match the pubkeys in the notarization. script = (uint8_t *)&txout.scriptPubKey[0]; scriptlen = (int32_t)txout.scriptPubKey.size(); if ( scriptlen == 35 && script[0] == 33 && script[34] == OP_CHECKSIG && memcmp(script+1,notarypubkeys[NotarizationNotaries[n-1]],33) == 0 ) @@ -1537,7 +1537,7 @@ uint64_t hush_checknotarypay(CBlock *pblock,int32_t height) } if ( matches != 0 && matches == NotarizationNotaries.size() && totalsats == total ) { - //fprintf(stderr, "Validated coinbase matches notarisation in tx position 1.\n" ); + //fprintf(stderr, "Validated coinbase matches notarization in tx position 1.\n" ); return(totalsats); } return(0); @@ -1757,10 +1757,10 @@ int32_t hush_checkPOW(int32_t slowflag,CBlock *pblock,int32_t height) // We check the full validation in ConnectBlock directly to get the amount for coinbase. So just approx here. if ( slowflag == 0 && pblock->vtx[0].vout.size() > 1 ) { - // Check the notarisation tx is to the crypto address. + // Check the notarization tx is to the crypto address. if ( !hush_is_notarytx(pblock->vtx[1]) == 1 ) { - fprintf(stderr, "notarisation is not to crypto address ht.%i\n",height); + fprintf(stderr, "notarization is not to crypto address ht.%i\n",height); return(-1); } // Check min sigs. diff --git a/src/main.cpp b/src/main.cpp index 4e6fc678f..7eba3e7a3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5600,7 +5600,7 @@ bool PruneOneBlockFile(bool tempfile, const int fileNumber) } else { - // Block is not in main chain and is older than last notarised block so its safe for removal. + // Block is not in main chain and is older than last notarized block so its safe for removal. fprintf(stderr, "Block [%i] in tempfile.%i We can clear this block!\n",pindex->GetHeight(),fileNumber); // Add index to list and remove after loop? } diff --git a/src/notarizationdb.h b/src/notarizationdb.h index 53d4f7318..b6e3f7684 100644 --- a/src/notarizationdb.h +++ b/src/notarizationdb.h @@ -20,9 +20,9 @@ typedef std::vector NotarizationsInBlock; NotarizationsInBlock ScanBlockNotarizations(const CBlock &block, int nHeight); bool GetBlockNotarizations(uint256 blockHash, NotarizationsInBlock &nibs); -bool GetBackNotarization(uint256 notarisationHash, Notarization &n); -void WriteBackNotarizations(const NotarizationsInBlock notarisations, CDBBatch &batch); -void EraseBackNotarizations(const NotarizationsInBlock notarisations, CDBBatch &batch); +bool GetBackNotarization(uint256 notarizationHash, Notarization &n); +void WriteBackNotarizations(const NotarizationsInBlock notarizations, CDBBatch &batch); +void EraseBackNotarizations(const NotarizationsInBlock notarizations, CDBBatch &batch); int ScanNotarizationsDB(int height, std::string symbol, int scanLimitBlocks, Notarization& out); #endif /* HUSH_NOTARISATIONDB_H */ diff --git a/src/test-hush/test_eval_bet.cpp b/src/test-hush/test_eval_bet.cpp index 5ff210393..51c9eda42 100644 --- a/src/test-hush/test_eval_bet.cpp +++ b/src/test-hush/test_eval_bet.cpp @@ -123,9 +123,9 @@ public: return true; } - bool GetNotarizationData(uint256 notarisationHash, NotarizationData &data) const + bool GetNotarizationData(uint256 notarizationHash, NotarizationData &data) const { - if (notarisationHash == NotarizationHash()) { + if (notarizationHash == NotarizationHash()) { data.MoM = MoM; return true; } @@ -567,7 +567,7 @@ TEST_F(TestBet, testImportPayoutInvalidNotarizationHash) EvalMock eval = ebet.SetEvalMock(12); MoMProof proof = ebet.GetMoMProof(); - proof.notarisationHash = uint256(); + proof.notarizationHash = uint256(); CMutableTransaction importTx = ebet.bet.MakeImportPayoutTx( ebet.Payouts(Player2), ebet.DisputeTx(Player2), uint256(), proof); diff --git a/src/test-hush/test_parse_notarization.cpp b/src/test-hush/test_parse_notarization.cpp index 655c6d5b6..0ee04a817 100644 --- a/src/test-hush/test_parse_notarization.cpp +++ b/src/test-hush/test_parse_notarization.cpp @@ -49,6 +49,6 @@ TEST(TestParseNotarization, test__b) -// for l in `g 'parse notarisation' ~/.hush/HUSH3/debug.log | pyline 'l.split()[8]'`; do hoek decodeTx '{"hex":"'`src/hush-cli getrawtransaction "$l"`'"}' | jq '.outputs[1].script.op_return' | pyline 'import base64; print base64.b64decode(l).encode("hex")'; done +// for l in `g 'parse notarization' ~/.hush/HUSH3/debug.log | pyline 'l.split()[8]'`; do hoek decodeTx '{"hex":"'`src/hush-cli getrawtransaction "$l"`'"}' | jq '.outputs[1].script.op_return' | pyline 'import base64; print base64.b64decode(l).encode("hex")'; done } From c8430665f714db7aff020cc2fc3af61ecadca870 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 15 Feb 2022 11:26:50 -0500 Subject: [PATCH 019/255] WIP RPC that doesn't quite work yet --- src/rpc/blockchain.cpp | 36 +++++++++++++++++++++++++++++ src/rpc/client.cpp | 1 + src/zcash/IncrementalMerkleTree.hpp | 2 +- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 5f3a54d2f..24412762a 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -856,6 +856,41 @@ UniValue gettxoutsetinfo(const UniValue& params, bool fHelp, const CPubKey& mypk return ret; } +UniValue getblockmerkletree(const UniValue& params, bool fHelp, const CPubKey& mypk) +{ + if (fHelp || params.size() != 1 ) + throw runtime_error( + "getblockmerkletree height\n" + "\nGet full merkletree for a given Hush or HSC block height.\n" + "\nArguments:\n" + "1. height (int, required) block height\n" + "\nResult:\n" + "\"hex\" (string) the merkle tree hex encoded\n" + + HelpExampleCli("getblockmerkletree", "290000") + + HelpExampleRpc("getblockmerkletree", "290000") + ); + + CBlockIndex* phushblockindex; + uint256 blockRoot; + SaplingMerkleTree tree; + + int nHeight = params[0].get_int(); + if ( (nHeight < 1) || (nHeight > chainActive.LastTip()->GetHeight()) ) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid Hush or HSC block height parameter"); + } + + phushblockindex = chainActive[nHeight]; + blockRoot = phushblockindex->pprev->hashFinalSaplingRoot; + if( pcoinsTip->GetSaplingAnchorAt(blockRoot, tree) ) { + CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); + ss << tree.path(); + std::vector merklepath(ss.begin(), ss.end()); + //TODO: this returns the same, wrong data for all heights + return HexStr(merklepath); + } else { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Could not find merkletree"); + } +} UniValue kvsearch(const UniValue& params, bool fHelp, const CPubKey& mypk) { @@ -1877,6 +1912,7 @@ static const CRPCCommand commands[] = { "blockchain", "getblockcount", &getblockcount, true }, { "blockchain", "getblock", &getblock, true }, { "blockchain", "getblockhash", &getblockhash, true }, + { "blockchain", "getblockmerkletree", &getblockmerkletree, true }, { "blockchain", "getblockheader", &getblockheader, true }, { "blockchain", "getchaintips", &getchaintips, true }, { "blockchain", "getchaintxstats", &getchaintxstats, true }, diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 916273043..e427ec3ff 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -63,6 +63,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "getbalance", 1 }, { "getbalance", 2 }, { "getblockhash", 0 }, + { "getblockmerkletree", 0 }, { "move", 2 }, { "move", 3 }, { "sendfrom", 2 }, diff --git a/src/zcash/IncrementalMerkleTree.hpp b/src/zcash/IncrementalMerkleTree.hpp index 03fa51fda..e0a05f6c6 100644 --- a/src/zcash/IncrementalMerkleTree.hpp +++ b/src/zcash/IncrementalMerkleTree.hpp @@ -108,6 +108,7 @@ public: IncrementalWitness witness() const { return IncrementalWitness(*this); } + MerklePath path(std::deque filler_hashes = std::deque()) const; ADD_SERIALIZE_METHODS; @@ -135,7 +136,6 @@ private: // Collapsed "left" subtrees ordered toward the root of the tree. std::vector> parents; - MerklePath path(std::deque filler_hashes = std::deque()) const; Hash root(size_t depth, std::deque filler_hashes = std::deque()) const; bool is_complete(size_t depth = Depth) const; size_t next_depth(size_t skip) const; From ce5c8a54e458def4b698b95f810e088e1e508d7d Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 16 Feb 2022 09:10:11 -0500 Subject: [PATCH 020/255] Make it work correctly --- src/rpc/blockchain.cpp | 8 +++----- src/zcash/IncrementalMerkleTree.hpp | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 24412762a..90b8e7201 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -880,13 +880,11 @@ UniValue getblockmerkletree(const UniValue& params, bool fHelp, const CPubKey& m } phushblockindex = chainActive[nHeight]; - blockRoot = phushblockindex->pprev->hashFinalSaplingRoot; + blockRoot = phushblockindex->hashFinalSaplingRoot; if( pcoinsTip->GetSaplingAnchorAt(blockRoot, tree) ) { CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); - ss << tree.path(); - std::vector merklepath(ss.begin(), ss.end()); - //TODO: this returns the same, wrong data for all heights - return HexStr(merklepath); + ss << tree; + return HexStr(ss.begin(), ss.end()); } else { throw JSONRPCError(RPC_INVALID_PARAMETER, "Could not find merkletree"); } diff --git a/src/zcash/IncrementalMerkleTree.hpp b/src/zcash/IncrementalMerkleTree.hpp index e0a05f6c6..03fa51fda 100644 --- a/src/zcash/IncrementalMerkleTree.hpp +++ b/src/zcash/IncrementalMerkleTree.hpp @@ -108,7 +108,6 @@ public: IncrementalWitness witness() const { return IncrementalWitness(*this); } - MerklePath path(std::deque filler_hashes = std::deque()) const; ADD_SERIALIZE_METHODS; @@ -136,6 +135,7 @@ private: // Collapsed "left" subtrees ordered toward the root of the tree. std::vector> parents; + MerklePath path(std::deque filler_hashes = std::deque()) const; Hash root(size_t depth, std::deque filler_hashes = std::deque()) const; bool is_complete(size_t depth = Depth) const; size_t next_depth(size_t skip) const; From c3623047f7eba7b6bd63ea4a21f4f74ea27d71f5 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 16 Feb 2022 10:57:52 -0500 Subject: [PATCH 021/255] Script to generate SDL checkpoint data via getblockmerkletree --- contrib/sdl_checkpoints.pl | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 contrib/sdl_checkpoints.pl diff --git a/contrib/sdl_checkpoints.pl b/contrib/sdl_checkpoints.pl new file mode 100755 index 000000000..e140fb0ec --- /dev/null +++ b/contrib/sdl_checkpoints.pl @@ -0,0 +1,44 @@ +#!/usr/bin/perl +# Copyright (c) 2016-2022 The Hush developers +# Distributed under the GPLv3 software license, see the accompanying +# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html + +# This script is used to generate the data used by the silentdragonlite-cli checkpoints.rs file +# https://git.hush.is/hush/silentdragonlite-cli/src/branch/master/lib/src/lightclient/checkpoints.rs#L24 + +use warnings; +use strict; +my $hush = "./src/hush-cli"; +my $gethash = "$hush getblockhash"; +my $gettree = "$hush getblockmerkletree"; +my $start = shift || 300000; +my $end = shift || 840000; +my $stride = shift || 10000; + +my $blocks = qx{$hush getblockcount}; +if($?) { + print "ERROR, is hushd running? exiting...\n"; + exit 1; +} + +if ($end > $blocks) { + print "The block $end is beyond how many blocks this node knows about, exiting...\n"; + exit 1; +} + +if ($start < 1) { + print "Invalid start block $start, exiting...\n"; + exit 1; +} + +my $block = $start; +while (1) { + last if $block > $end; + my $blockhash = qx{$gethash $block}; + my $merkle = qx{$gettree $block}; + chomp $merkle; + chomp $blockhash; + print qq{($block,"$blockhash",\n\t"$merkle"\n),\n}; + + $block += $stride; +} From 35f6314123d3de99a734e718b42a88100c0ae839 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 20 Feb 2022 11:32:09 -0500 Subject: [PATCH 022/255] Correctly link against librandomx in build --- src/Makefile.am | 10 +++++++--- src/miner.cpp | 8 +++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 3232cabdb..5d73c049f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -53,6 +53,7 @@ LIBCRYPTOCONDITIONS=cryptoconditions/libcryptoconditions_core.la LIBUNIVALUE=univalue/libunivalue.la LIBZCASH=libzcash.a LIBHUSH=libhush.a +LIBRANDOMX=RandomX/build/librandomx.a if ENABLE_ZMQ LIBBITCOIN_ZMQ=libbitcoin_zmq.a @@ -505,7 +506,8 @@ hushd_LDADD = \ $(LIBLEVELDB) \ $(LIBMEMENV) \ $(LIBSECP256K1) \ - $(LIBCRYPTOCONDITIONS) + $(LIBCRYPTOCONDITIONS) \ + $(LIBRANDOMX) if ENABLE_WALLET hushd_LDADD += $(LIBBITCOIN_WALLET) @@ -583,7 +585,8 @@ wallet_utility_LDADD = \ $(CRYPTO_LIBS) \ $(LIBZCASH) \ $(LIBZCASH_LIBS)\ - $(LIBCRYPTOCONDITIONS) + $(LIBCRYPTOCONDITIONS) \ + $(LIBRANDOMX) endif # hush-tx binary # @@ -605,7 +608,8 @@ hush_tx_LDADD = \ $(LIBHUSH) \ $(LIBBITCOIN_CRYPTO) \ $(LIBZCASH_LIBS) \ - $(LIBCRYPTOCONDITIONS) + $(LIBCRYPTOCONDITIONS) \ + $(LIBRANDOMX) hush_tx_LDADD += $(BOOST_LIBS) $(CRYPTO_LIBS) diff --git a/src/miner.cpp b/src/miner.cpp index da19909c8..50480e821 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -116,6 +116,7 @@ public: }; extern int8_t ASSETCHAINS_ADAPTIVEPOW; +extern uint32_t ASSETCHAINS_RANDOMX; void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) { @@ -1025,8 +1026,9 @@ void static RandomXMiner() miningTimer.start(); try { - if ( SMART_CHAIN_SYMBOL[0] != 0 ) - fprintf(stderr,"try %s Mining with %s\n",SMART_CHAIN_SYMBOL,solver.c_str()); + if ( SMART_CHAIN_SYMBOL[0] != 0 ) { + fprintf(stderr,"trying %s Mining with randomx\n",SMART_CHAIN_SYMBOL); + } while (true) { if (chainparams.MiningRequiresPeers()) { @@ -1109,7 +1111,7 @@ void static RandomXMiner() } IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); //fprintf(stderr,"Running HushMiner.%s with %u transactions in block\n",solver.c_str(),(int32_t)pblock->vtx.size()); - LogPrintf("Running HushRandomXMiner with %u transactions in block (%u bytes)\n",,pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); + LogPrintf("Running HushRandomXMiner with %u transactions in block (%u bytes)\n",pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); // Search uint8_t pubkeys[66][33]; arith_uint256 bnMaxPoSdiff; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); From f78479b34ee6237ecd368a162e18dfc90c9353d2 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 20 Feb 2022 12:57:08 -0500 Subject: [PATCH 023/255] Get randomx flags and allocate cache --- src/miner.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index 50480e821..aabc50627 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1134,6 +1134,8 @@ void static RandomXMiner() hashTarget = HASHTarget; // TODO: RandomX solver code + randomx_flags flags = randomx_get_flags(); + randomx_cache *myCache = randomx_alloc_cache(flags); } From 583b0fdeff20a7fbd15fd4bb5a6a5f90f28f5250 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 20 Feb 2022 14:46:42 -0500 Subject: [PATCH 024/255] Calculate randomx hashes --- src/miner.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index aabc50627..da4af7a66 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1133,9 +1133,33 @@ void static RandomXMiner() arith_uint256 hashTarget; hashTarget = HASHTarget; - // TODO: RandomX solver code - randomx_flags flags = randomx_get_flags(); - randomx_cache *myCache = randomx_alloc_cache(flags); + char randomxHash[RANDOMX_HASH_SIZE]; + // TODO: decide on real RandomX key and input + const char randomxKey[] = "HUSH RandomX testing key"; + const char randomxInput[] = "HUSH RandomX testing input"; + randomx_flags flags = randomx_get_flags(); + randomx_cache *randomxCache = randomx_alloc_cache(flags); + + if (randomxCache == NULL) { + LogPrintf("RandomX cache is null, something is wrong, cannot mine!\n"); + return; + } + + randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey); + randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL); + + randomx_calculate_hash(myVM, &randomxInput, sizeof randomxInput, randomxHash); + + randomx_destroy_vm(myVM); + randomx_release_cache(randomxCache); + + printf("RandomX Hash: "); + for (unsigned i = 0; i < RANDOMX_HASH_SIZE; ++i) { + printf("%02x", randomxHash[i] & 0xff); + } + + printf("\n"); + // TODO: use randomx hash to build a block } From ad754cf2f059d9323e0f5d8d3f26a40c2bdc496f Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 20 Feb 2022 21:55:34 -0500 Subject: [PATCH 025/255] Use chain magic as a unique starting value for randomx key --- src/miner.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index da4af7a66..f1920f7c5 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1135,11 +1135,31 @@ void static RandomXMiner() char randomxHash[RANDOMX_HASH_SIZE]; // TODO: decide on real RandomX key and input - const char randomxKey[] = "HUSH RandomX testing key"; - const char randomxInput[] = "HUSH RandomX testing input"; + char randomxKey[5]; + randomxKey[0] = ASSETCHAINS_MAGIC & 0xff; + randomxKey[1] = (ASSETCHAINS_MAGIC >> 8) & 0xff; + randomxKey[2] = (ASSETCHAINS_MAGIC >> 16) & 0xff; + randomxKey[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff; + randomxKey[4] = SMART_CHAIN_SYMBOL[0]; + + // crypto_generichash_blake2b_state state; + // CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); + // ss << randomxKey; + // ss << SMART_CHAIN_SYMBOL; + // crypto_generichash_blake2b_update(&state, (unsigned char*)&ss[0], ss.size()); + // char blakehash[32]; + // crypto_generichash_blake2b_final(&state, blakehash, 32); + + const char randomxInput[] = "testing"; // blakehash[32]; randomx_flags flags = randomx_get_flags(); randomx_cache *randomxCache = randomx_alloc_cache(flags); + if(Mining_height > 1) { + // use blockchain data to set a new key+input for a group of blocks + // randomxKey = ... + // randomxInput = ... + } + if (randomxCache == NULL) { LogPrintf("RandomX cache is null, something is wrong, cannot mine!\n"); return; From c9aaf341aeaf82fcbb5926c2f6477e6b0455fac9 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 20 Feb 2022 23:20:15 -0500 Subject: [PATCH 026/255] Use randomxInput = blake2b(randomXkey || ac_name) --- src/miner.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index f1920f7c5..3b0335a2b 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1134,7 +1134,7 @@ void static RandomXMiner() hashTarget = HASHTarget; char randomxHash[RANDOMX_HASH_SIZE]; - // TODO: decide on real RandomX key and input + // Initial randomx key is chain magic + first letter of chain name which is 2^40 bits of entropy char randomxKey[5]; randomxKey[0] = ASSETCHAINS_MAGIC & 0xff; randomxKey[1] = (ASSETCHAINS_MAGIC >> 8) & 0xff; @@ -1142,19 +1142,18 @@ void static RandomXMiner() randomxKey[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff; randomxKey[4] = SMART_CHAIN_SYMBOL[0]; - // crypto_generichash_blake2b_state state; - // CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); - // ss << randomxKey; - // ss << SMART_CHAIN_SYMBOL; - // crypto_generichash_blake2b_update(&state, (unsigned char*)&ss[0], ss.size()); - // char blakehash[32]; - // crypto_generichash_blake2b_final(&state, blakehash, 32); + crypto_generichash_blake2b_state state; + // Hash = blake2b( key || ac_name) + crypto_generichash_blake2b_update(&state, (unsigned char*)&randomxKey[0], 5); + crypto_generichash_blake2b_update(&state, (unsigned char*)&SMART_CHAIN_SYMBOL[0], strlen(SMART_CHAIN_SYMBOL)); + uchar randomxInput[32]; + crypto_generichash_blake2b_final(&state, randomxInput, 32); - const char randomxInput[] = "testing"; // blakehash[32]; randomx_flags flags = randomx_get_flags(); randomx_cache *randomxCache = randomx_alloc_cache(flags); - if(Mining_height > 1) { + if(Mining_height > 1024 && (Mining_height % 1024 == 64)) { + // At block height 1024*N+64 we should use the blockhash of block 1024*N as key // use blockchain data to set a new key+input for a group of blocks // randomxKey = ... // randomxInput = ... From 8eab796800eeaf84d5ed8e6c5dc89afb392f77f0 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 20 Feb 2022 23:46:37 -0500 Subject: [PATCH 027/255] WIP to change rx key+input for groups of blocks; use full ac_name in rx key --- src/miner.cpp | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 3b0335a2b..8b5941dd9 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1134,36 +1134,45 @@ void static RandomXMiner() hashTarget = HASHTarget; char randomxHash[RANDOMX_HASH_SIZE]; - // Initial randomx key is chain magic + first letter of chain name which is 2^40 bits of entropy - char randomxKey[5]; + // Initial randomx key is chain magic || ac_name which is >= 2^40 bits of entropy assuming strlen(ac_name) >= 1 + // For ac_name=DRAGONX we have 4 + 7 = 11 bytes or 2^88 bits of entropy + char randomxKey[4 + strlen(SMART_CHAIN_SYMBOL)]; randomxKey[0] = ASSETCHAINS_MAGIC & 0xff; randomxKey[1] = (ASSETCHAINS_MAGIC >> 8) & 0xff; randomxKey[2] = (ASSETCHAINS_MAGIC >> 16) & 0xff; randomxKey[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff; - randomxKey[4] = SMART_CHAIN_SYMBOL[0]; + + for(int i=0; i++; i 1024 && (Mining_height % 1024 == 64)) { - // At block height 1024*N+64 we should use the blockhash of block 1024*N as key - // use blockchain data to set a new key+input for a group of blocks - // randomxKey = ... - // randomxInput = ... - } - if (randomxCache == NULL) { LogPrintf("RandomX cache is null, something is wrong, cannot mine!\n"); return; } + + // TODO: use same block key for groups of blocks + if(Mining_height > 1024 && (Mining_height % 1024 == 64)) { + // At block height 1024*N+64 we should use the blockhash of block 1024*N as randomx key + // use blockchain data to set a new key+input for a group of blocks + uint256 randomxBlockKey; + randomxBlockKey = chainActive[Mining_height - 64]->GetBlockHash(); + crypto_generichash_blake2b_state new_state; + crypto_generichash_blake2b_update(&state, (unsigned char*)&randomxBlockKey, 32); + crypto_generichash_blake2b_final(&state, randomxInput, 32); + } + + // TODO: use correct variables randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey); randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL); From c5743d59854397d2acc2c8a8a8e7e89830c42eed Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 21 Feb 2022 09:41:08 -0500 Subject: [PATCH 028/255] Error checking for randomx vm creation --- src/miner.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index 8b5941dd9..e25d53c34 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1175,6 +1175,10 @@ void static RandomXMiner() // TODO: use correct variables randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey); randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL); + if(myVM == NULL) { + LogPrintf("Cannot create RandomX VM, aborting!\n"); + return; + } randomx_calculate_hash(myVM, &randomxInput, sizeof randomxInput, randomxHash); From e4abb51fcd376b7abf0dbe4efd56a8a44d808f55 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 9 Mar 2022 08:53:37 -0500 Subject: [PATCH 029/255] update copyright years --- src/miner.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/miner.cpp b/src/miner.cpp index e25d53c34..6434ab872 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** From 224b5b144cfdb14a6946f98397940fb6337e2e12 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 9 Mar 2022 10:18:06 -0500 Subject: [PATCH 030/255] Set a rolling randomx block key --- src/miner.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 6434ab872..42c7fc3f2 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1161,19 +1161,30 @@ void static RandomXMiner() } - // TODO: use same block key for groups of blocks - if(Mining_height > 1024 && (Mining_height % 1024 == 64)) { - // At block height 1024*N+64 we should use the blockhash of block 1024*N as randomx key - // use blockchain data to set a new key+input for a group of blocks - uint256 randomxBlockKey; - randomxBlockKey = chainActive[Mining_height - 64]->GetBlockHash(); + // TODO: we may want to tweak these params to more closely match the 2.8 days and ~2 hrs + // which is what they work out to on XMR + // The key block will change every ~21.3 hours with a 75s block time + // and every ~17 hours with the default 60s block time for HSCs + int randomxInterval = 1024; + // This lag is 80 mins for 75s blocktime and 64 mins for 60s (default) blocktime for HSCs + int randomxBlockLag = 64; + + // Use the initial key at the start of the chain + if( (Mining_height-randomxBlockLag) < randomxInterval) { + LogPrintf("RandomX using initial key\n"); + randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey); + } else { + // At heights between intervals, we use the same block key and wait randomxBlockLag blocks until changing + int keyHeight = ((Mining_height - randomxBlockLag) / randomxInterval) * randomxInterval; + LogPrintf("RandomX key height=%d\n", keyHeight); + uint256 randomxBlockKey = chainActive[keyHeight]->GetBlockHash(); crypto_generichash_blake2b_state new_state; - crypto_generichash_blake2b_update(&state, (unsigned char*)&randomxBlockKey, 32); + crypto_generichash_blake2b_update(&state, (unsigned char *)&randomxBlockKey, 32); crypto_generichash_blake2b_final(&state, randomxInput, 32); + + randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxKey); } - // TODO: use correct variables - randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey); randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL); if(myVM == NULL) { LogPrintf("Cannot create RandomX VM, aborting!\n"); From a2954c4576a73fc6363468c00db7d28ec55ce18c Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 10 Mar 2022 01:09:42 -0500 Subject: [PATCH 031/255] Fill in more randomx miner code --- src/miner.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 79 insertions(+), 16 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 42c7fc3f2..6037be939 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1012,9 +1012,6 @@ void static RandomXMiner() break; } - if ( notaryid != My_notaryid ) - My_notaryid = notaryid; - std::mutex m_cs; bool cancelSolver = false; boost::signals2::connection c = uiInterface.NotifyBlockTip.connect( @@ -1026,9 +1023,8 @@ void static RandomXMiner() miningTimer.start(); try { - if ( SMART_CHAIN_SYMBOL[0] != 0 ) { - fprintf(stderr,"trying %s Mining with randomx\n",SMART_CHAIN_SYMBOL); - } + fprintf(stderr,"trying %s Mining with randomx\n",SMART_CHAIN_SYMBOL); + while (true) { if (chainparams.MiningRequiresPeers()) { @@ -1073,7 +1069,7 @@ void static RandomXMiner() { miningTimer.stop(); c.disconnect(); - LogPrintf("HushMiner terminated\n"); + LogPrintf("HushRandomXMiner terminated\n"); return; } static uint32_t counter; @@ -1087,10 +1083,10 @@ void static RandomXMiner() if (!pblocktemplate.get()) { if (GetArg("-mineraddress", "").empty()) { - LogPrintf("Error in HushMiner: Keypool ran out, please call keypoolrefill before restarting the mining thread\n"); + LogPrintf("Error in HushRandomXMiner: Keypool ran out, please call keypoolrefill before restarting the mining thread\n"); } else { // Should never reach here, because -mineraddress validity is checked in init.cpp - LogPrintf("Error in HushMiner: Invalid -mineraddress\n"); + LogPrintf("Error in HushRandomXMiner: Invalid -mineraddress\n"); } return; } @@ -1119,12 +1115,12 @@ void static RandomXMiner() savebits = pblock->nBits; HASHTarget = arith_uint256().SetCompact(savebits); roundrobin_delay = ROUNDROBIN_DELAY; + Mining_start = 0; - // HASHTarget_POW = hush_adaptivepow_target(Mining_height,HASHTarget,pblock->nTime); gotinvalid = 0; while (true) { - //fprintf(stderr,"gotinvalid.%d\n",gotinvalid); + fprintf(stderr,"gotinvalid.%d\n",gotinvalid); if ( gotinvalid != 0 ) break; hush_longestchain(); @@ -1160,9 +1156,6 @@ void static RandomXMiner() return; } - - // TODO: we may want to tweak these params to more closely match the 2.8 days and ~2 hrs - // which is what they work out to on XMR // The key block will change every ~21.3 hours with a 75s block time // and every ~17 hours with the default 60s block time for HSCs int randomxInterval = 1024; @@ -1204,9 +1197,79 @@ void static RandomXMiner() printf("\n"); // TODO: use randomx hash to build a block - } + std::function)> validBlock = +#ifdef ENABLE_WALLET + [&pblock, &hashTarget, &pwallet, &reservekey, &m_cs, &cancelSolver, &chainparams] +#else + [&pblock, &hashTarget, &m_cs, &cancelSolver, &chainparams] +#endif + (std::vector soln) { + int32_t z; arith_uint256 h; CBlock B; + // Write the solution to the hash and compute the result. + LogPrint("pow", "- Checking solution against target\n"); + pblock->nSolution = soln; + solutionTargetChecks.increment(); + B = *pblock; + h = UintToArith256(B.GetHash()); + if ( h > hashTarget ) + { + return false; + } - } + CValidationState state; + if ( !TestBlockValidity(state,B, chainActive.LastTip(), true, false)) + { + h = UintToArith256(B.GetHash()); + //for (z=31; z>=0; z--) + // fprintf(stderr,"%02x",((uint8_t *)&h)[z]); + fprintf(stderr," Invalid block mined, try again\n"); + gotinvalid = 1; + return(false); + } + SetThreadPriority(THREAD_PRIORITY_NORMAL); + LogPrintf("HushRandomXMiner:\n"); + LogPrintf("proof-of-work found \n hash: %s \ntarget: %s\n", B.GetHash().GetHex(), HASHTarget.GetHex()); +#ifdef ENABLE_WALLET + if (ProcessBlockFound(&B, *pwallet, reservekey)) { +#else + if (ProcessBlockFound(&B)) { +#endif + // Ignore chain updates caused by us + std::lock_guard lock{m_cs}; + cancelSolver = false; + } + SetThreadPriority(THREAD_PRIORITY_LOWEST); + // In regression test mode, stop mining after a block is found. + if (chainparams.MineBlocksOnDemand()) { + // Increment here because throwing skips the call below + // TODO: equivalent of ehSolverRuns.increment(); + throw boost::thread_interrupted(); + } + return true; + }; + // TODO: solver specific stuff + // TODO: Convert solution indices to byte array (decompress) and pass it to validBlock method. + + boost::this_thread::interruption_point(); + + if (vNodes.empty() && chainparams.MiningRequiresPeers()) + { + if ( Mining_height > ASSETCHAINS_MINHEIGHT ) + { + fprintf(stderr,"no nodes, break\n"); + break; + } + } + if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff) + { + fprintf(stderr,"nonce & 0xffff == 0xffff, break\n"); + break; + } + // Update nNonce and nTime + pblock->nNonce = ArithToUint256(UintToArith256(pblock->nNonce) + 1); + pblock->nBits = savebits; + } + } } catch (const boost::thread_interrupted&) { From fc214e9644a87d04fabf6120131db5f4169b9f09 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 16 Mar 2022 11:57:33 -0400 Subject: [PATCH 032/255] Get closer to deciding if a block is valid in randomx solver --- src/miner.cpp | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 6037be939..10f2ed944 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -986,6 +986,19 @@ CBlockIndex *get_chainactive(int32_t height) int32_t gotinvalid; +class RandomXSolverCanceledException : public std::exception +{ + virtual const char* what() const throw() { + return "RandomX solver was canceled"; + } +}; + +enum RandomXSolverCancelCheck +{ + Reason1, + Reason2 +}; + #ifdef ENABLE_WALLET void static RandomXMiner(CWallet *pwallet) #else @@ -1222,7 +1235,7 @@ void static RandomXMiner() h = UintToArith256(B.GetHash()); //for (z=31; z>=0; z--) // fprintf(stderr,"%02x",((uint8_t *)&h)[z]); - fprintf(stderr," Invalid block mined, try again\n"); + fprintf(stderr,"Invalid randomx block mined, try again\n"); gotinvalid = 1; return(false); } @@ -1247,8 +1260,28 @@ void static RandomXMiner() } return true; }; + std::function cancelled = [&m_cs, &cancelSolver](RandomXSolverCancelCheck pos) { + std::lock_guard lock{m_cs}; + return cancelSolver; + }; // TODO: solver specific stuff - // TODO: Convert solution indices to byte array (decompress) and pass it to validBlock method. + try { + // TODO: Convert solution to byte array (decompress) and pass it to validBlock method. + std::vector sol_char; // = GetMinimalFromIndices(index_vector, DIGITBITS); + bool found = validBlock(sol_char); + if (found) { + LogPrintf("HushRandomXMiner found solution!\n"); + // If we find a POW solution, do not try other solutions + // because they become invalid as we created a new block in blockchain. + break; + } else { + fprintf(stderr,"HushRandomXMiner solution not found, validBlock=false"); + } + } catch (RandomXSolverCanceledException&) { + LogPrintf("HushRandomXMiner solver canceled\n"); + std::lock_guard lock{m_cs}; + cancelSolver = false; + } boost::this_thread::interruption_point(); From 04911ae966963b4240d23970f8d0e8de08cc28fb Mon Sep 17 00:00:00 2001 From: jahway603 Date: Fri, 18 Mar 2022 12:12:40 -0400 Subject: [PATCH 033/255] Mention z_viewtransaction in gettransaction and getrawtransaction RPC calls --- src/rpc/rawtransaction.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 69e614f3b..a48df8e44 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -353,7 +353,7 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp, const CPubKey& my "\nNOTE: By default this function only works sometimes. This is when the tx is in the mempool\n" "or there is an unspent output in the utxo for this transaction. To make it always work,\n" "you need to maintain a transaction index, using the -txindex command line option.\n" - "\nReturn the raw transaction data.\n" + "\nReturn the raw transaction data. Also see z_viewtransaction for ztx details.\n" "\nIf verbose=0, returns a string that is serialized, hex-encoded data for 'txid'.\n" "If verbose is non-zero, returns an Object with information about 'txid'.\n" diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e3f5e5064..c4dd9c7fc 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2257,7 +2257,7 @@ UniValue gettransaction(const UniValue& params, bool fHelp, const CPubKey& mypk) if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "gettransaction \"txid\" ( includeWatchonly )\n" - "\nGet detailed information about in-wallet transaction . Also see z_viewtransaction for ztx details\n" + "\nGet detailed information about in-wallet transaction . Also see z_viewtransaction for ztx details.\n" "\nArguments:\n" "1. \"txid\" (string, required) The transaction id\n" "2. \"includeWatchonly\" (bool, optional, default=false) Whether to include watchonly addresses in balance calculation and details[]\n" From 214a7418d7bcd8b9d725914323c50d65255c6745 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Fri, 18 Mar 2022 12:54:48 -0400 Subject: [PATCH 034/255] Document that '~' cannot be used in -datadir --- src/bitcoin-cli.cpp | 2 +- src/init.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index e9623f9bd..79e7701fc 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -48,7 +48,7 @@ std::string HelpMessageCli() strUsage += HelpMessageGroup(_("Options:")); strUsage += HelpMessageOpt("-?", _("This help message")); strUsage += HelpMessageOpt("-conf=", strprintf(_("Specify configuration file (default: %s)"), "HUSH3.conf")); - strUsage += HelpMessageOpt("-datadir=", _("Specify data directory")); + strUsage += HelpMessageOpt("-datadir=", _("Specify data directory (this path cannot use '~')")); strUsage += HelpMessageOpt("-testnet", _("Use the test network")); strUsage += HelpMessageOpt("-regtest", _("Enter regression test mode, which uses a special chain in which blocks can be " "solved instantly. This is intended for regression testing tools and app development.")); diff --git a/src/init.cpp b/src/init.cpp index 2aaa490a0..90cad3b02 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -389,7 +389,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-daemon", _("Run in the background as a daemon and accept commands")); #endif } - strUsage += HelpMessageOpt("-datadir=", _("Specify data directory")); + strUsage += HelpMessageOpt("-datadir=", _("Specify data directory (this path cannot use '~')")); strUsage += HelpMessageOpt("-exportdir=", _("Specify directory to be used when exporting data")); strUsage += HelpMessageOpt("-dbcache=", strprintf(_("Set database cache size in megabytes (%d to %d, default: %d)"), nMinDbCache, nMaxDbCache, nDefaultDbCache)); strUsage += HelpMessageOpt("-loadblock=", _("Imports blocks from external blk000??.dat file") + " " + _("on startup")); From fab401343f1b0ccb4f83d81dac66a1e200abcd7a Mon Sep 17 00:00:00 2001 From: jahway603 Date: Fri, 18 Mar 2022 14:43:14 -0400 Subject: [PATCH 035/255] updated AUTHORS file --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index d2d49e2e0..20bd581e2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -2,6 +2,7 @@ Duke Leto https://git.hush.is/duke https://github.com/leto Miodrag https://github.com/miodragpop +jahway603 https://git.hush.is/jahway603 https://github.com/jahway603 # The SuperNET Developers From ccfd17b3b2f1a1e92f64a05fe351e7ee52218c35 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sun, 27 Mar 2022 00:40:46 -0400 Subject: [PATCH 036/255] minor change --- src/hush/tlsmanager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hush/tlsmanager.cpp b/src/hush/tlsmanager.cpp index c0c280a42..51e2ea064 100644 --- a/src/hush/tlsmanager.cpp +++ b/src/hush/tlsmanager.cpp @@ -619,7 +619,7 @@ int TLSManager::threadSocketHandler(CNode* pnode, fd_set& fdsetRecv, fd_set& fds if (nRet != WOLFSSL_ERROR_WANT_READ && nRet != WOLFSSL_ERROR_WANT_WRITE) { if (!pnode->fDisconnect) - LogPrintf("TSL: ERROR: SSL_read %s\n", ERR_error_string(nRet, NULL)); + LogPrintf("TLS: ERROR: SSL_read %s\n", ERR_error_string(nRet, NULL)); pnode->CloseSocketDisconnect(); unsigned long error = ERR_get_error(); @@ -634,7 +634,7 @@ int TLSManager::threadSocketHandler(CNode* pnode, fd_set& fdsetRecv, fd_set& fds } else { if (nRet != WSAEWOULDBLOCK && nRet != WSAEMSGSIZE && nRet != WSAEINTR && nRet != WSAEINPROGRESS) { if (!pnode->fDisconnect) - LogPrintf("TSL: ERROR: socket recv %s\n", NetworkErrorString(nRet)); + LogPrintf("TLS: ERROR: socket recv %s\n", NetworkErrorString(nRet)); pnode->CloseSocketDisconnect(); } } From 90bb8c7cf4eb69d0d7f8744bb90582caf36ec30e Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 29 Mar 2022 10:29:54 -0400 Subject: [PATCH 037/255] Fix incorrect comment --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 7eba3e7a3..8266ccdce 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1452,7 +1452,7 @@ bool CheckTransaction(uint32_t tiptime,const CTransaction& tx, CValidationState return true; } -// This is used only in RPC currently but hush_notaries()/gethushseason/getacseason is consensus +// This is and hush_notaries()/gethushseason/getacseason are all consensus code int32_t hush_isnotaryvout(char *coinaddr,uint32_t tiptime) { bool ishush3 = strncmp(SMART_CHAIN_SYMBOL, "HUSH3",5) == 0 ? true : false; bool istush = strncmp(SMART_CHAIN_SYMBOL, "TUSH",4) == 0 ? true : false; From 79a6f51c2d048fbbfa209b5ab3f1ed5771ac4fd5 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 30 Mar 2022 00:21:38 -0400 Subject: [PATCH 038/255] Update some comments and docs --- src/wallet/rpcwallet.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c4dd9c7fc..80064f6b2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -64,7 +64,7 @@ const std::string ADDR_TYPE_AMNESIA = "amnesia"; extern int32_t HUSH_INSYNC; uint32_t hush_segid32(char *coinaddr); int32_t hush_dpowconfs(int32_t height,int32_t numconfs); -int32_t hush_isnotaryvout(char *coinaddr,uint32_t tiptime); // from ac_private chains only +int32_t hush_isnotaryvout(char *coinaddr,uint32_t tiptime); // needed for ac_private=1 chains only CBlockIndex *hush_getblockindex(uint256 hash); extern string randomSietchZaddr(); extern CAmount fConsolidationTxFee; @@ -559,9 +559,9 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp, const CPubKey& mypk) "\"transactionid\" (string) The transaction id.\n" "\nExamples:\n" + HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1") - + HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1 \"donation\" \"seans outpost\"") + + HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1 \"donation\" \"Hush Puppy Freedom Fund\"") + HelpExampleCli("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\" 0.1 \"\" \"\" true") - + HelpExampleRpc("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 0.1, \"donation\", \"seans outpost\"") + + HelpExampleRpc("sendtoaddress", "\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPV\", 0.1, \"donation\", \"Hush Puppy Freedom Fund\"") ); if ( ASSETCHAINS_PRIVATE != 0 && AmountFromValue(params[1]) > 0 ) @@ -4929,6 +4929,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk) if (fromTaddr) { txsize += CTXIN_SPEND_DUST_SIZE; //TODO: On HUSH since block 340k there can no longer be taddr change, + // (except for notary addresses) // so we can likely make a better estimation of max txsize txsize += CTXOUT_REGULAR_SIZE; // There will probably be taddr change } From 689a360b607095274ce960b3078c8524455531df Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 18 Apr 2022 00:32:11 -0400 Subject: [PATCH 039/255] Allow notary addresses in sendmany, fixes #126 --- src/wallet/rpcwallet.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 80064f6b2..edfb608e7 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1502,8 +1502,6 @@ UniValue sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk) "\nAs a json rpc call\n" + HelpExampleRpc("sendmany", "\"\", {\"RD6GgnrMpPaTSMn8vai6yiGA7mN4QGPVMY\":0.01,\"RRyyejME7LRTuvdziWsXkAbSW1fdiohGwK\":0.02}, 6, \"testing\"") ); - if ( ASSETCHAINS_PRIVATE != 0 ) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "cant use transparent addresses in private chain"); LOCK2(cs_main, pwalletMain->cs_wallet); @@ -1528,6 +1526,17 @@ UniValue sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk) std::vector keys = sendTo.getKeys(); int32_t i = 0; for (const std::string& name_ : keys) { + // Allow transparent notary addresses and throw an error for anything else + // This is also a consensus check but we want to prevent it from going into the mempool + // and give an error as early as possible + if ( ASSETCHAINS_PRIVATE != 0 ) + { + if ( hush_isnotaryvout((char *)name_.c_str(),chainActive.LastTip()->nTime) == 0 ) + { + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transparent " + strprintf("%s",hush_chainname()) + " address not allowed on private chain"); + } + } + CTxDestination dest = DecodeDestination(name_); if (!IsValidDestination(dest)) { CScript tmpspk; From 69cd4f79901d7d8594f76676d490da0518c59383 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 20 Apr 2022 10:51:12 -0400 Subject: [PATCH 040/255] data key (OP_RETURN) is optional in createrawtransaction --- src/rpc/rawtransaction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index a48df8e44..2619d309b 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -647,7 +647,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp, const CPubKey& "2. \"outputs\" (object, required) a json object with outputs\n" " {\n" " \"address\": x.xxx, (numeric or string, required) The key is the HUSH address or script (in hex), the numeric value (can be string) is the " + CURRENCY_UNIT + " amount\n" - " \"data\": \"hex\" (string, required) The key is \"data\", the value is hex encoded data\n" + " \"data\": \"hex\" (string, optional) The key is \"data\", the value is hex encoded data\n" " ,...\n" " }\n" "3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n" From 193a1b2a97c7d669bf03bd23d6c18793286ac09d Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 20 Apr 2022 10:52:12 -0400 Subject: [PATCH 041/255] Clarify that it is OP_RETURN data --- src/rpc/rawtransaction.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 2619d309b..6c115cb67 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -647,7 +647,7 @@ UniValue createrawtransaction(const UniValue& params, bool fHelp, const CPubKey& "2. \"outputs\" (object, required) a json object with outputs\n" " {\n" " \"address\": x.xxx, (numeric or string, required) The key is the HUSH address or script (in hex), the numeric value (can be string) is the " + CURRENCY_UNIT + " amount\n" - " \"data\": \"hex\" (string, optional) The key is \"data\", the value is hex encoded data\n" + " \"data\": \"hex\" (string, optional) The key is \"data\", the value is hex encoded OP_RETURN data\n" " ,...\n" " }\n" "3. locktime (numeric, optional, default=0) Raw locktime. Non-0 value also locktime-activates inputs\n" From afe1cf153c337e49739fd6b57850e9e80fdae047 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 21 Apr 2022 22:35:21 -0400 Subject: [PATCH 042/255] Uncomment some dpow debugging --- src/hush.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hush.h b/src/hush.h index 68a5051ca..187638372 100644 --- a/src/hush.h +++ b/src/hush.h @@ -635,7 +635,7 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi ccdata.MoMdata.notarized_height = *notarizedheightp; ccdata.MoMdata.height = height; ccdata.MoMdata.txi = i; - //printf("nameoffset.%d len.%d + 36 %d opoffset.%d vs opretlen.%d\n",nameoffset,len,len+36,opoffset,opretlen); + printf("nameoffset.%d len.%d + 36 %d opoffset.%d vs opretlen.%d\n",nameoffset,len,len+36,opoffset,opretlen); if ( len+36-opoffset <= opretlen ) { len += dragon_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&MoM); @@ -645,8 +645,8 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi if ( len+sizeof(ccdata.CCid)-opoffset <= opretlen ) { len += dragon_rwnum(0,&scriptbuf[len],sizeof(ccdata.CCid),(uint8_t *)&ccdata.CCid); - //if ( ((MoMdepth>>16) & 0xffff) != (ccdata.CCid & 0xffff) ) - // fprintf(stderr,"%s CCid mismatch %u != %u\n",SMART_CHAIN_SYMBOL,((MoMdepth>>16) & 0xffff),(ccdata.CCid & 0xffff)); + if ( ((MoMdepth>>16) & 0xffff) != (ccdata.CCid & 0xffff) ) + fprintf(stderr,"%s CCid mismatch %u != %u\n",SMART_CHAIN_SYMBOL,((MoMdepth>>16) & 0xffff),(ccdata.CCid & 0xffff)); ccdata.len = sizeof(ccdata.CCid); if ( SMART_CHAIN_SYMBOL[0] != 0 ) { From 7859fdf7eb32f95a47eeef6cceaf1a9f9837d2a4 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 23 Apr 2022 10:00:35 -0400 Subject: [PATCH 043/255] More debug --- src/hush.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hush.h b/src/hush.h index 187638372..cf72b05f1 100644 --- a/src/hush.h +++ b/src/hush.h @@ -612,7 +612,7 @@ int32_t hush_voutupdate(bool fJustCheck,int32_t *isratificationp,int32_t notaryi notarized = 1; if ( strcmp("DPOW",ccdata.symbol) == 0 || strncmp("ZPOW",ccdata.symbol,5) == 0 || strcmp("TUSH",ccdata.symbol) == 0) notarized = 1; - if ( 0 && opretlen != 149 ) + if ( opretlen != 149 ) printf("[%s].%d (%s) matched.%d i.%d j.%d notarized.%d %llx opretlen.%d len.%d offset.%d opoffset.%d\n",SMART_CHAIN_SYMBOL,height,ccdata.symbol,matched,i,j,notarized,(long long)signedmask,opretlen,len,offset,opoffset); len += dragon_rwbignum(0,&scriptbuf[len],32,(uint8_t *)&srchash); len += dragon_rwnum(0,&scriptbuf[len],sizeof(*notarizedheightp),(uint8_t *)notarizedheightp); From 3325c946c4ec443741afea9b3c72fe0aed6994f6 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sun, 15 May 2022 19:54:10 -0400 Subject: [PATCH 044/255] updated libgmp to pull direct from FSF --- depends/packages/libgmp.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/packages/libgmp.mk b/depends/packages/libgmp.mk index 8e830eaff..fece8f822 100644 --- a/depends/packages/libgmp.mk +++ b/depends/packages/libgmp.mk @@ -18,7 +18,7 @@ $(package)_dependencies= $(package)_config_opts=--enable-cxx --disable-shared else $(package)_version=6.1.1 -$(package)_download_path=https://github.com/MyHush/libgmp/releases/download/v6.1.1 +$(package)_download_path=https://ftp.gnu.org/gnu/gmp $(package)_file_name=gmp-$($(package)_version).tar.bz2 $(package)_sha256_hash=a8109865f2893f1373b0a8ed5ff7429de8db696fc451b1036bd7bdf95bbeffd6 $(package)_dependencies= From 58d3d212859431fadc828d7f2cd4af9b1787d80e Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sun, 15 May 2022 22:22:00 -0400 Subject: [PATCH 045/255] migrated more from mcro --- depends/packages/boost.mk | 2 +- depends/packages/utfcpp.mk | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/depends/packages/boost.mk b/depends/packages/boost.mk index 3112ca7be..c925e52ef 100644 --- a/depends/packages/boost.mk +++ b/depends/packages/boost.mk @@ -1,7 +1,7 @@ package=boost $(package)_version=1_72_0 -$(package)_download_path=https://github.com/MyHush/boost/releases/download/v1.72.0/ +$(package)_download_path=https://boostorg.jfrog.io/artifactory/main/release/$(subst _,.,$($(package)_version))/source/ $(package)_sha256_hash=59c9b274bc451cf91a9ba1dd2c7fdcaf5d60b1b3aa83f2c9fa143417cc660722 $(package)_file_name=$(package)_$($(package)_version).tar.bz2 diff --git a/depends/packages/utfcpp.mk b/depends/packages/utfcpp.mk index fb7ca044e..623f6a592 100644 --- a/depends/packages/utfcpp.mk +++ b/depends/packages/utfcpp.mk @@ -1,8 +1,8 @@ $(package)_version=3.1 -$(package)_download_path=https://github.com/MyHush/$(package)/archive/ +$(package)_download_path=https://git.hush.is/jahway603/$(package)/archive $(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_download_file=v$($(package)_version).tar.gz -$(package)_sha256_hash=ab531c3fd5d275150430bfaca01d7d15e017a188183be932322f2f651506b096 +$(package)_sha256_hash=eb4d5b9843a8411a20da8d011983e5351bf6c5893814f6756de8a31392185a98 define $(package)_stage_cmds cp -a ./source $($(package)_staging_dir)$(host_prefix)/include From 421edc8979a3fb27e421ba92eef99f1ae324ecfb Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 2 Jun 2022 21:43:10 -0400 Subject: [PATCH 046/255] Log txid for double spends and missing anchors This makes debugging failed transactions much easier. --- src/coins.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coins.cpp b/src/coins.cpp index a83731e35..0c3af3863 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -578,13 +578,13 @@ bool CCoinsViewCache::HaveShieldedRequirements(const CTransaction& tx) const { for (const SpendDescription &spendDescription : tx.vShieldedSpend) { if (GetNullifier(spendDescription.nullifier, SAPLING)) { // Prevent double spends - LogPrintf("%s: sapling nullifier %s exists, preventing double spend\n", __FUNCTION__, spendDescription.nullifier.GetHex().c_str()); + LogPrintf("%s: sapling nullifier %s exists, preventing double spend in tx %s\n", __FUNCTION__, spendDescription.nullifier.GetHex().c_str(), tx.GetHash().GetHex().c_str()); return false; } SaplingMerkleTree tree; if (!GetSaplingAnchorAt(spendDescription.anchor, tree)) { - LogPrintf("%s: missing sapling anchor: %s \n", __FUNCTION__, spendDescription.anchor.GetHex().c_str()); + LogPrintf("%s: missing sapling anchor: %s in tx %s \n", __FUNCTION__, spendDescription.anchor.GetHex().c_str(), tx.GetHash().GetHex().c_str()); return false; } } From 09b5ce78e26b6caf5393b5a97674a5e9e2097c3c Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 15:47:34 +0000 Subject: [PATCH 047/255] Update 'doc/files.md' --- doc/files.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/files.md b/doc/files.md index f1a56bcb9..902431376 100644 --- a/doc/files.md +++ b/doc/files.md @@ -12,5 +12,6 @@ * fee_estimates.dat: stores statistics used to estimate minimum transaction fees and priorities required for confirmation * peers.dat: peer IP address database (custom format) * wallet.dat: personal wallet (BDB) with keys and transactions +* zindex.dat: Optional file that stores anonset (shielded pool) stats. Only created if `zindex=1` in HUSH3.conf or `hushd -zindex` is used * .cookie: session RPC authentication cookie (written at start when cookie authentication is used, deleted on shutdown): since 0.12.0 * onion_private_key: cached Tor hidden service private key for `-listenonion`: since 0.12.0 From 90bb4ccc3b5056a9aabb652510025a119a09bc83 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 15:48:31 +0000 Subject: [PATCH 048/255] Get rid of old IP's in HUSH3.conf example --- doc/beefy-HUSH3.conf | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/doc/beefy-HUSH3.conf b/doc/beefy-HUSH3.conf index 455f1ee3f..ee1daff63 100644 --- a/doc/beefy-HUSH3.conf +++ b/doc/beefy-HUSH3.conf @@ -3,10 +3,5 @@ rpcpassword=dontuseweakpasswordoryougetrobbed txindex=1 server=1 rpcworkqueue=64 -addnode=5.9.102.210 -addnode=78.47.196.146 -addnode=178.63.69.164 -addnode=88.198.65.74 -addnode=5.9.122.241 -addnode=144.76.94.38 -addnode=89.248.166.91 \ No newline at end of file +addnode=1.2.3.4 +addnode=5.6.7.8 From 59fdc549b67d1aa5f38ff5706f49d924861b2575 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 15:49:39 +0000 Subject: [PATCH 049/255] Add 'doc/config.md' --- doc/config.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 doc/config.md diff --git a/doc/config.md b/doc/config.md new file mode 100644 index 000000000..85edc3d0e --- /dev/null +++ b/doc/config.md @@ -0,0 +1,3 @@ +# HUSH3.conf config options + +This document explains all options that can be used in HUSH3.conf \ No newline at end of file From bd41b3c848ccff98cbd81c2c518efc4a051954d2 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 15:53:05 +0000 Subject: [PATCH 050/255] Update 'doc/config.md' --- doc/config.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/config.md b/doc/config.md index 85edc3d0e..b6b041a7e 100644 --- a/doc/config.md +++ b/doc/config.md @@ -1,3 +1,15 @@ # HUSH3.conf config options -This document explains all options that can be used in HUSH3.conf \ No newline at end of file +This document explains all options that can be used in HUSH3.conf + +# Basics + +Options can either be put in HUSH3.conf or given on the `hushd` commandline when starting. If you think you will want to continually use a feature, it's better to put it in HUSH3.conf. If you don't, and start `hushd` without an option on accident, it cause a downtime from a long rescan, that you didn't want to do anyway. + +# txindex=1 + +This is a default option that should not be changed or things will not work correctly. + +# zindex=1 + +This option enables the "shielded index" which also calculates the "anonset" (anonymity set) also known as the "shielded pool". This data is avaailable in the getchaintxstats RPC, if zindex is enabled. \ No newline at end of file From 057bbdd0365ce7e7677be899877070e9d20a29ac Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 15:54:00 +0000 Subject: [PATCH 051/255] Update 'config.md' --- doc/config.md => config.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename doc/config.md => config.md (58%) diff --git a/doc/config.md b/config.md similarity index 58% rename from doc/config.md rename to config.md index b6b041a7e..0e2998758 100644 --- a/doc/config.md +++ b/config.md @@ -8,8 +8,8 @@ Options can either be put in HUSH3.conf or given on the `hushd` commandline when # txindex=1 -This is a default option that should not be changed or things will not work correctly. +Defaults to 1. This is a default option that should not be changed or things will not work correctly. # zindex=1 -This option enables the "shielded index" which also calculates the "anonset" (anonymity set) also known as the "shielded pool". This data is avaailable in the getchaintxstats RPC, if zindex is enabled. \ No newline at end of file +Defaults to 0. This option enables the "shielded index" which also calculates the "anonset" (anonymity set) also known as the "shielded pool". This data is avaailable in the getchaintxstats RPC, if zindex is enabled. \ No newline at end of file From ae10d0a02f9d9f71e5dc4b9587ae648c159e950a Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 15:55:25 +0000 Subject: [PATCH 052/255] Update 'config.md' --- config.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config.md b/config.md index 0e2998758..530407c73 100644 --- a/config.md +++ b/config.md @@ -6,6 +6,11 @@ This document explains all options that can be used in HUSH3.conf Options can either be put in HUSH3.conf or given on the `hushd` commandline when starting. If you think you will want to continually use a feature, it's better to put it in HUSH3.conf. If you don't, and start `hushd` without an option on accident, it cause a downtime from a long rescan, that you didn't want to do anyway. + +# rescan=1 + +Defaults to 0. Performs a full rescan of all of chain history. Can take a very long time. Speed this up with `rescanheight=123` to only rescan from a certain block height. Also speed this up with `keepnotewitnesscache=1` to not rebuild the zaddr witness cache. + # txindex=1 Defaults to 1. This is a default option that should not be changed or things will not work correctly. From 481ba5c6fe290c042c1f4ae554c1855dc1c589a2 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 15:56:52 +0000 Subject: [PATCH 053/255] Add 'doc/config.md' --- doc/config.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 doc/config.md diff --git a/doc/config.md b/doc/config.md new file mode 100644 index 000000000..530407c73 --- /dev/null +++ b/doc/config.md @@ -0,0 +1,20 @@ +# HUSH3.conf config options + +This document explains all options that can be used in HUSH3.conf + +# Basics + +Options can either be put in HUSH3.conf or given on the `hushd` commandline when starting. If you think you will want to continually use a feature, it's better to put it in HUSH3.conf. If you don't, and start `hushd` without an option on accident, it cause a downtime from a long rescan, that you didn't want to do anyway. + + +# rescan=1 + +Defaults to 0. Performs a full rescan of all of chain history. Can take a very long time. Speed this up with `rescanheight=123` to only rescan from a certain block height. Also speed this up with `keepnotewitnesscache=1` to not rebuild the zaddr witness cache. + +# txindex=1 + +Defaults to 1. This is a default option that should not be changed or things will not work correctly. + +# zindex=1 + +Defaults to 0. This option enables the "shielded index" which also calculates the "anonset" (anonymity set) also known as the "shielded pool". This data is avaailable in the getchaintxstats RPC, if zindex is enabled. \ No newline at end of file From 394a7ba620ffad0f60c68dff6f57084dc944dbaa Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 15:57:49 +0000 Subject: [PATCH 054/255] Delete 'config.md' --- config.md | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 config.md diff --git a/config.md b/config.md deleted file mode 100644 index 530407c73..000000000 --- a/config.md +++ /dev/null @@ -1,20 +0,0 @@ -# HUSH3.conf config options - -This document explains all options that can be used in HUSH3.conf - -# Basics - -Options can either be put in HUSH3.conf or given on the `hushd` commandline when starting. If you think you will want to continually use a feature, it's better to put it in HUSH3.conf. If you don't, and start `hushd` without an option on accident, it cause a downtime from a long rescan, that you didn't want to do anyway. - - -# rescan=1 - -Defaults to 0. Performs a full rescan of all of chain history. Can take a very long time. Speed this up with `rescanheight=123` to only rescan from a certain block height. Also speed this up with `keepnotewitnesscache=1` to not rebuild the zaddr witness cache. - -# txindex=1 - -Defaults to 1. This is a default option that should not be changed or things will not work correctly. - -# zindex=1 - -Defaults to 0. This option enables the "shielded index" which also calculates the "anonset" (anonymity set) also known as the "shielded pool". This data is avaailable in the getchaintxstats RPC, if zindex is enabled. \ No newline at end of file From 3fd094b07f56a6995545d49fe255c567389f72da Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 16:00:33 +0000 Subject: [PATCH 055/255] Update 'doc/config.md' --- doc/config.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/config.md b/doc/config.md index 530407c73..073a661cc 100644 --- a/doc/config.md +++ b/doc/config.md @@ -11,6 +11,14 @@ Options can either be put in HUSH3.conf or given on the `hushd` commandline when Defaults to 0. Performs a full rescan of all of chain history. Can take a very long time. Speed this up with `rescanheight=123` to only rescan from a certain block height. Also speed this up with `keepnotewitnesscache=1` to not rebuild the zaddr witness cache. +# rpcuser=hushpuppy + +No default. This option sets the RPC username and should only be used in HUSH3.conf, because setting it from the command-line makes it show up in `ps` output. + +# rpcpassword=TOOMANYSECRETS + +No default. This option sets the RPC password and should only be used in HUSH3.conf, because setting it from the command-line makes it show up in `ps` output. + # txindex=1 Defaults to 1. This is a default option that should not be changed or things will not work correctly. From 3431cee99e5ab315336b480901cf2b83ebad53ee Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 16:10:20 +0000 Subject: [PATCH 056/255] Update 'doc/config.md' --- doc/config.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/config.md b/doc/config.md index 073a661cc..266f50f6f 100644 --- a/doc/config.md +++ b/doc/config.md @@ -7,7 +7,9 @@ This document explains all options that can be used in HUSH3.conf Options can either be put in HUSH3.conf or given on the `hushd` commandline when starting. If you think you will want to continually use a feature, it's better to put it in HUSH3.conf. If you don't, and start `hushd` without an option on accident, it cause a downtime from a long rescan, that you didn't want to do anyway. -# rescan=1 +## Common Options + +### rescan=1 Defaults to 0. Performs a full rescan of all of chain history. Can take a very long time. Speed this up with `rescanheight=123` to only rescan from a certain block height. Also speed this up with `keepnotewitnesscache=1` to not rebuild the zaddr witness cache. From 70eb3c39b9a9540a0863f773c91f9ce9302eb8fa Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 16:10:35 +0000 Subject: [PATCH 057/255] Update 'doc/config.md' --- doc/config.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/config.md b/doc/config.md index 266f50f6f..24981a8ff 100644 --- a/doc/config.md +++ b/doc/config.md @@ -9,11 +9,11 @@ Options can either be put in HUSH3.conf or given on the `hushd` commandline when ## Common Options -### rescan=1 +## rescan=1 Defaults to 0. Performs a full rescan of all of chain history. Can take a very long time. Speed this up with `rescanheight=123` to only rescan from a certain block height. Also speed this up with `keepnotewitnesscache=1` to not rebuild the zaddr witness cache. -# rpcuser=hushpuppy +## rpcuser=hushpuppy No default. This option sets the RPC username and should only be used in HUSH3.conf, because setting it from the command-line makes it show up in `ps` output. From 157bd7a38ba594b5d7182f2e4ecf88e86e93ea8a Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 16:11:46 +0000 Subject: [PATCH 058/255] Update 'doc/config.md' --- doc/config.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/doc/config.md b/doc/config.md index 24981a8ff..b1464a1e2 100644 --- a/doc/config.md +++ b/doc/config.md @@ -17,14 +17,22 @@ Defaults to 0. Performs a full rescan of all of chain history. Can take a very l No default. This option sets the RPC username and should only be used in HUSH3.conf, because setting it from the command-line makes it show up in `ps` output. -# rpcpassword=TOOMANYSECRETS +## rpcpassword=TOOMANYSECRETS No default. This option sets the RPC password and should only be used in HUSH3.conf, because setting it from the command-line makes it show up in `ps` output. -# txindex=1 +## txindex=1 Defaults to 1. This is a default option that should not be changed or things will not work correctly. -# zindex=1 +## zindex=1 -Defaults to 0. This option enables the "shielded index" which also calculates the "anonset" (anonymity set) also known as the "shielded pool". This data is avaailable in the getchaintxstats RPC, if zindex is enabled. \ No newline at end of file +Defaults to 0. This option enables the "shielded index" which also calculates the "anonset" (anonymity set) also known as the "shielded pool". This data is avaailable in the getchaintxstats RPC, if zindex is enabled. + +# Mining options + +These options are only of interest to solo miners and mining pool operators.... + +# Other options + +These options are not commonly used and likely on for advanced users and/or developers... \ No newline at end of file From 37d8f0b8602d9dc771a677273dd83e4ea4b32e8e Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 16:13:16 +0000 Subject: [PATCH 059/255] Update 'doc/config.md' --- doc/config.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/config.md b/doc/config.md index b1464a1e2..bc40520d0 100644 --- a/doc/config.md +++ b/doc/config.md @@ -9,6 +9,10 @@ Options can either be put in HUSH3.conf or given on the `hushd` commandline when ## Common Options +## addnode=1.2.3.4 + +Tells your node to connect to another node, by IP address or hostname. + ## rescan=1 Defaults to 0. Performs a full rescan of all of chain history. Can take a very long time. Speed this up with `rescanheight=123` to only rescan from a certain block height. Also speed this up with `keepnotewitnesscache=1` to not rebuild the zaddr witness cache. From 609d59b3ad5ef800607fbe8b6c3243b98dd63e26 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 16:15:46 +0000 Subject: [PATCH 060/255] Update 'doc/config.md' --- doc/config.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/config.md b/doc/config.md index bc40520d0..d15856597 100644 --- a/doc/config.md +++ b/doc/config.md @@ -39,4 +39,16 @@ These options are only of interest to solo miners and mining pool operators.... # Other options -These options are not commonly used and likely on for advanced users and/or developers... \ No newline at end of file +These options are not commonly used and likely on for advanced users and/or developers... + +## addressindex=1 + +Defaults to 0 in hushd, defaults to 1 in some GUI wallets. Maintain a full address index, used to query for the balance, txids and unspent outputs for addresses + +## timestampindex=1 + +Defaults to 0 in hushd, defaults to 1 in some GUI wallets. Maintain a timestamp index for block hashes, used to query blocks hashes by a range of timestamps + +## spentindex=1 + +Defaults to 0 in hushd, defaults to 1 in some GUI wallets. Maintain a full spent index, used to query the spending txid and input index for an outpoint \ No newline at end of file From db180a5b42903e49e031eca18e8096e8e516c083 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 16:17:03 +0000 Subject: [PATCH 061/255] Update 'doc/config.md' --- doc/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/config.md b/doc/config.md index d15856597..e8a9d8626 100644 --- a/doc/config.md +++ b/doc/config.md @@ -4,7 +4,7 @@ This document explains all options that can be used in HUSH3.conf # Basics -Options can either be put in HUSH3.conf or given on the `hushd` commandline when starting. If you think you will want to continually use a feature, it's better to put it in HUSH3.conf. If you don't, and start `hushd` without an option on accident, it cause a downtime from a long rescan, that you didn't want to do anyway. +Options can either be put in HUSH3.conf or given on the `hushd` commandline when starting. If you think you will want to continually use a feature, it's better to put it in HUSH3.conf. If you don't, and start `hushd` without an option on accident, it can cause downtime from a long rescan, that you didn't want to do anyway. ## Common Options From 8af089e5e781efc47818b6a45764a5e16c28408e Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 16:17:55 +0000 Subject: [PATCH 062/255] Update 'doc/config.md' --- doc/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/config.md b/doc/config.md index e8a9d8626..526ebbf20 100644 --- a/doc/config.md +++ b/doc/config.md @@ -31,7 +31,7 @@ Defaults to 1. This is a default option that should not be changed or things wil ## zindex=1 -Defaults to 0. This option enables the "shielded index" which also calculates the "anonset" (anonymity set) also known as the "shielded pool". This data is avaailable in the getchaintxstats RPC, if zindex is enabled. +Defaults to 0. This option enables the "shielded index" which also calculates the "anonset" (anonymity set) also known as the "shielded pool". This data is avaailable in the getchaintxstats RPC, if zindex is enabled. Enabling this feature requires a full rescan or full sync from scratch, which is not done by default. If you don't do one of those things, your zindex stats will be incorrect. # Mining options From c683edf4f1d10461d7ee380b087087c2ac912844 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 18:20:56 +0000 Subject: [PATCH 063/255] Update 'doc/config.md' --- doc/config.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/config.md b/doc/config.md index 526ebbf20..d2af57e94 100644 --- a/doc/config.md +++ b/doc/config.md @@ -13,6 +13,11 @@ Options can either be put in HUSH3.conf or given on the `hushd` commandline when Tells your node to connect to another node, by IP address or hostname. +## consolidation=1 + +Defaults to 0 in CLI hushd, defaults to 1 in SilentDragon. This option consolidates many unspent shielded UTXOs (zutxos) into one zutxo, which makes spending them in the future faster and potentially cost less in fees. It also helps prevent +certain kinds of metadata leakages and spam attacks. + ## rescan=1 Defaults to 0. Performs a full rescan of all of chain history. Can take a very long time. Speed this up with `rescanheight=123` to only rescan from a certain block height. Also speed this up with `keepnotewitnesscache=1` to not rebuild the zaddr witness cache. From 064f850705d4ff2ffa658b96f2ed31355cdb1d5d Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 6 Jun 2022 18:22:57 +0000 Subject: [PATCH 064/255] Update 'doc/config.md' --- doc/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/config.md b/doc/config.md index d2af57e94..44df5ece3 100644 --- a/doc/config.md +++ b/doc/config.md @@ -16,7 +16,7 @@ Tells your node to connect to another node, by IP address or hostname. ## consolidation=1 Defaults to 0 in CLI hushd, defaults to 1 in SilentDragon. This option consolidates many unspent shielded UTXOs (zutxos) into one zutxo, which makes spending them in the future faster and potentially cost less in fees. It also helps prevent -certain kinds of metadata leakages and spam attacks. +certain kinds of metadata leakages and spam attacks. It is not recommended for very large wallets (wallet.dat files with thousands of transactions) for performance reasons. This is why it defaults to OFF for CLI full nodes but ON for GUI wallets that use an embedded hushd. ## rescan=1 From bdde67c35989f64db3e55cfed79ea7a66773cdd4 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 7 Jun 2022 20:05:49 -0700 Subject: [PATCH 065/255] Initial implementation of anonsettxdelta + z_anonsetblockdelta --- src/wallet/rpcwallet.cpp | 88 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index edfb608e7..06dc0ded2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3652,6 +3652,92 @@ UniValue z_listsentbyaddress(const UniValue& params, bool fHelp,const CPubKey&) return ret; } +UniValue z_anonsetblockdelta(const UniValue& params, bool fHelp, const CPubKey& mypk) +{ + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() != 1) + throw runtime_error( + "z_anonsetblockdelta\n" + "\nReturns delta (difference) in the anonset for a given block height.\n" + "\nArguments:\n" + "1. \"height\" (number, required) The block height\n" + "\nResult:\n" + "\"delta\" (integer) An integer number.\n" + "\nExamples:\n" + + HelpExampleCli("z_anonsetblockdelta 123", "456") + + HelpExampleRpc("z_anonsetblockdelta 123", "456") + ); + + LOCK2(cs_main, pwalletMain->cs_wallet); + std::string strHeight = params[0].get_str(); + int nHeight = -1; + try { + nHeight = std::stoi(strHeight); + } catch (const std::exception &e) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block height parameter"); + } + + if (nHeight < 0 || nHeight > chainActive.Height()) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); + } + strHash = chainActive[nHeight]->GetBlockHash().GetHex(); + uint256 hash(uint256S(strHash)); + + if (mapBlockIndex.count(hash) == 0) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); + + CBlock block; + CBlockIndex* pblockindex = mapBlockIndex[hash]; + + if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0) + throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)"); + + if(!ReadBlockFromDisk(block, pblockindex,1)) + throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); + + int delta = 0; + BOOST_FOREACH(const CTransaction&tx, block.vtx) + { + // delta = shielded outputs - shielded inputs + delta += tx.vShieldedOutput.size() - tx.vShieldedSpend.size(); + } + return delta; +} + +UniValue z_anonsettxdelta(const UniValue& params, bool fHelp, const CPubKey& mypk) +{ + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() != 1) + throw runtime_error( + "z_anonsettxdelta\n" + "\nReturns delta (difference) in the anonset for a given txid.\n" + "\nArguments:\n" + "1. \"txid\" (string, required) The transaction id\n" + "\nResult:\n" + "\"delta\" (integer) An integer number.\n" + "\nExamples:\n" + + HelpExampleCli("z_anonsettxdelta txid", "123") + + HelpExampleRpc("z_anonsettxdelta txid", "123") + ); + + LOCK2(cs_main, pwalletMain->cs_wallet); + + uint256 txid; + txid.SetHex(params[0].get_str()); + + if (!pwalletMain->mapWallet.count(hash)) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id!"); + const CWalletTx& wtx = pwalletMain->mapWallet[hash]; + + // delta = shielded outputs - shielded inputs + int delta = wtx.vShieldedSpend.size() - wtx.vShieldedOutput.size(); + return delta; +} + UniValue z_getbalances(const UniValue& params, bool fHelp, const CPubKey& mypk) { if (!EnsureWalletIsAvailable(fHelp)) @@ -8352,6 +8438,8 @@ static const CRPCCommand commands[] = { "wallet", "z_listunspent", &z_listunspent, false }, { "wallet", "z_getbalance", &z_getbalance, false }, { "wallet", "z_getbalances", &z_getbalances, false }, + { "wallet", "z_anonsettxdelta", &z_anonsettxdelta, true }, + { "wallet", "z_anonsetblockdelta", &z_anonsetblockdelta, true }, { "wallet", "z_gettotalbalance", &z_gettotalbalance, false }, { "wallet", "z_mergetoaddress", &z_mergetoaddress, false }, { "wallet", "z_sendmany", &z_sendmany, false }, From c218cf1c09587acadafeb61538cb18975ecd4674 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 7 Jun 2022 23:19:06 -0400 Subject: [PATCH 066/255] Fix compile errors --- src/wallet/rpcwallet.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 06dc0ded2..28c987fb1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3682,7 +3682,7 @@ UniValue z_anonsetblockdelta(const UniValue& params, bool fHelp, const CPubKey& if (nHeight < 0 || nHeight > chainActive.Height()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); } - strHash = chainActive[nHeight]->GetBlockHash().GetHex(); + auto strHash = chainActive[nHeight]->GetBlockHash().GetHex(); uint256 hash(uint256S(strHash)); if (mapBlockIndex.count(hash) == 0) @@ -3729,9 +3729,9 @@ UniValue z_anonsettxdelta(const UniValue& params, bool fHelp, const CPubKey& myp uint256 txid; txid.SetHex(params[0].get_str()); - if (!pwalletMain->mapWallet.count(hash)) + if (!pwalletMain->mapWallet.count(txid)) throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id!"); - const CWalletTx& wtx = pwalletMain->mapWallet[hash]; + const CWalletTx& wtx = pwalletMain->mapWallet[txid]; // delta = shielded outputs - shielded inputs int delta = wtx.vShieldedSpend.size() - wtx.vShieldedOutput.size(); From cc61b19930f3337d3058f6f97105e664c6c00adc Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 7 Jun 2022 23:56:25 -0400 Subject: [PATCH 067/255] Make z_anonsettxdelta work on a tx that is not in our wallet and fix calculation --- src/wallet/rpcwallet.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 28c987fb1..189d668f3 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3724,17 +3724,17 @@ UniValue z_anonsettxdelta(const UniValue& params, bool fHelp, const CPubKey& myp + HelpExampleRpc("z_anonsettxdelta txid", "123") ); - LOCK2(cs_main, pwalletMain->cs_wallet); - uint256 txid; + uint256 txid,hashBlock; + CTransaction tx; txid.SetHex(params[0].get_str()); - if (!pwalletMain->mapWallet.count(txid)) - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id!"); - const CWalletTx& wtx = pwalletMain->mapWallet[txid]; + LOCK(cs_main); + if (!GetTransaction(txid, tx, hashBlock, true)) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available about transaction"); // delta = shielded outputs - shielded inputs - int delta = wtx.vShieldedSpend.size() - wtx.vShieldedOutput.size(); + int delta = tx.vShieldedOutput.size() - tx.vShieldedSpend.size(); return delta; } From e0d22ee170f8af9542f2c7dcb5d1eb0c28c1e72c Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 9 Jun 2022 03:00:50 -0700 Subject: [PATCH 068/255] Enable z_anonsetblockdelta to calculate a delta for a block range; ignore coinbase txs as optimization --- src/wallet/rpcwallet.cpp | 63 +++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 189d668f3..3a5498f19 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3657,12 +3657,15 @@ UniValue z_anonsetblockdelta(const UniValue& params, bool fHelp, const CPubKey& if (!EnsureWalletIsAvailable(fHelp)) return NullUniValue; - if (fHelp || params.size() != 1) + if (fHelp || params.size() < 1 || params.size() > 2) throw runtime_error( "z_anonsetblockdelta\n" - "\nReturns delta (difference) in the anonset for a given block height.\n" + "\nReturns delta (difference) in the anonset for a given block height. A delta > 0 increases the anonset,\n" + "\na delta < 0 reduces the anonset and a delta=0 leaves the anonset the same. Given a single block height\n" + "\nwe calculate the delta for that block. Given two block heights, we calculate the delta for that range of blocks.\n" "\nArguments:\n" "1. \"height\" (number, required) The block height\n" + "1. \"end_height\" (number, optional) The ending block height\n" "\nResult:\n" "\"delta\" (integer) An integer number.\n" "\nExamples:\n" @@ -3698,10 +3701,55 @@ UniValue z_anonsetblockdelta(const UniValue& params, bool fHelp, const CPubKey& throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); int delta = 0; - BOOST_FOREACH(const CTransaction&tx, block.vtx) - { - // delta = shielded outputs - shielded inputs - delta += tx.vShieldedOutput.size() - tx.vShieldedSpend.size(); + + // given a single block height, we calculate delta for that height + if (params.size() == 1) { + BOOST_FOREACH(const CTransaction&tx, block.vtx) + { + // delta = shielded outputs - shielded inputs + if(!tx.IsCoinBase()) { + delta += tx.vShieldedOutput.size() - tx.vShieldedSpend.size(); + } + } + } else { + // given two blocks, we calculate delta for that range + std::string strHeight2 = params[1].get_str(); + int nHeight2 = -1; + try { + nHeight = std::stoi(strHeight2); + } catch (const std::exception &e) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid ending block height parameter"); + } + + if (nHeight2 < 0 || nHeight2 > chainActive.Height()) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Ending block height out of range"); + } + + // get the delta for every block in the range + for(int currentHeight = nHeight; currentHeight <= nHeight2; currentHeight++) { + auto strHash = chainActive[currentHeight]->GetBlockHash().GetHex(); + uint256 hash(uint256S(strHash)); + + if (mapBlockIndex.count(hash) == 0) + throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); + + CBlock block; + CBlockIndex* pblockindex = mapBlockIndex[hash]; + + if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0) + throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)"); + + if(!ReadBlockFromDisk(block, pblockindex,1)) + throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk"); + + BOOST_FOREACH(const CTransaction&tx, block.vtx) + { + // delta = shielded outputs - shielded inputs + if(!tx.IsCoinBase()) { + delta += tx.vShieldedOutput.size() - tx.vShieldedSpend.size(); + } + } + } } return delta; } @@ -3714,7 +3762,8 @@ UniValue z_anonsettxdelta(const UniValue& params, bool fHelp, const CPubKey& myp if (fHelp || params.size() != 1) throw runtime_error( "z_anonsettxdelta\n" - "\nReturns delta (difference) in the anonset for a given txid.\n" + "\nReturns delta (difference) in the anonset for a given txid. A delta > 0 increases the anonset,\n" + "\na delta < 0 reduces the anonset and a delta=0 leaves the anonset the same.\n" "\nArguments:\n" "1. \"txid\" (string, required) The transaction id\n" "\nResult:\n" From 2b336dccc0c51edbaac802a94b5c0f7e3d2cf502 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 9 Jun 2022 06:41:09 -0400 Subject: [PATCH 069/255] Fix ending height bug and check that ending height is larger than starting height --- src/wallet/rpcwallet.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 3a5498f19..8e6d8b128 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3716,11 +3716,15 @@ UniValue z_anonsetblockdelta(const UniValue& params, bool fHelp, const CPubKey& std::string strHeight2 = params[1].get_str(); int nHeight2 = -1; try { - nHeight = std::stoi(strHeight2); + nHeight2 = std::stoi(strHeight2); } catch (const std::exception &e) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid ending block height parameter"); } + if (nHeight2 <= nHeight) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Ending block height must be larger than starting height"); + } + if (nHeight2 < 0 || nHeight2 > chainActive.Height()) { throw JSONRPCError(RPC_INVALID_PARAMETER, "Ending block height out of range"); } From 0a9abedc5dba747fa40d4ebfcbe2ab3ab4adae65 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 26 Jun 2022 04:40:06 -0700 Subject: [PATCH 070/255] Return size in bytes of a tx from getrawtransaction --- src/rpc/rawtransaction.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 6c115cb67..2e82c061a 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -367,6 +367,7 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp, const CPubKey& my "\nResult (if verbose > 0):\n" "{\n" " \"hex\" : \"data\", (string) The serialized, hex-encoded data for 'txid'\n" + " \"size\" : n, (numeric) The length in bytes\n" " \"txid\" : \"id\", (string) The transaction id (same as provided)\n" " \"version\" : n, (numeric) The version\n" " \"locktime\" : ttt, (numeric) The lock time\n" @@ -453,6 +454,7 @@ UniValue getrawtransaction(const UniValue& params, bool fHelp, const CPubKey& my UniValue result(UniValue::VOBJ); result.push_back(Pair("hex", strHex)); + result.push_back(Pair("size", GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION) )); TxToJSONExpanded(tx, hashBlock, result, nHeight, nConfirmations, nBlockTime); return result; } From 0ee1d068c1302e945ce457bb65c12f1d4aa82b0d Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 26 Jun 2022 17:21:33 -0700 Subject: [PATCH 071/255] These haven't existed for a long time --- src/rpc/server.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/rpc/server.h b/src/rpc/server.h index 4e301ea8c..b6a20b559 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -479,8 +479,6 @@ extern UniValue z_listoperationids(const UniValue& params, bool fHelp, const CPu extern UniValue opreturn_burn(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue rescan(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue z_validateaddress(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcmisc.cpp -extern UniValue z_getpaymentdisclosure(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcdisclosure.cpp -extern UniValue z_validatepaymentdisclosure(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcdisclosure.cpp extern UniValue MoMoMdata(const UniValue& params, bool fHelp, const CPubKey& mypk); extern UniValue calc_MoM(const UniValue& params, bool fHelp, const CPubKey& mypk); From abaa623526945150f0bd1606327a7343fd8d9923 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 26 Jun 2022 17:23:10 -0700 Subject: [PATCH 072/255] This file no longer exists --- src/Makefile.gtest.include | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include index 457ef6bdf..368666e58 100644 --- a/src/Makefile.gtest.include +++ b/src/Makefile.gtest.include @@ -41,7 +41,6 @@ zcash_gtest_SOURCES += \ gtest/test_txid.cpp \ gtest/test_libzcash_utils.cpp \ gtest/test_proofs.cpp \ - gtest/test_paymentdisclosure.cpp \ gtest/test_pedersen_hash.cpp \ gtest/test_checkblock.cpp \ gtest/test_zip32.cpp From 97dea10b2b2da03eeaaa4358aa7a8b3f02e38017 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 29 Jun 2022 22:18:05 -0400 Subject: [PATCH 073/255] more randomx debug --- src/miner.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 10f2ed944..9b5ad0392 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1119,7 +1119,7 @@ void static RandomXMiner() } } IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); - //fprintf(stderr,"Running HushMiner.%s with %u transactions in block\n",solver.c_str(),(int32_t)pblock->vtx.size()); + fprintf(stderr,"Running HushRandomXMiner with %u transactions in block\n",(int32_t)pblock->vtx.size()); LogPrintf("Running HushRandomXMiner with %u transactions in block (%u bytes)\n",pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); // Search @@ -1143,9 +1143,11 @@ void static RandomXMiner() hashTarget = HASHTarget; char randomxHash[RANDOMX_HASH_SIZE]; + fprintf(stderr,"RandomXMiner: created randomxHash of size %d\n", RANDOMX_HASH_SIZE); // Initial randomx key is chain magic || ac_name which is >= 2^40 bits of entropy assuming strlen(ac_name) >= 1 // For ac_name=DRAGONX we have 4 + 7 = 11 bytes or 2^88 bits of entropy char randomxKey[4 + strlen(SMART_CHAIN_SYMBOL)]; + fprintf(stderr,"RandomXMiner: creating randomxKey of size %d\n", 4 + strlen(SMART_CHAIN_SYMBOL)); randomxKey[0] = ASSETCHAINS_MAGIC & 0xff; randomxKey[1] = (ASSETCHAINS_MAGIC >> 8) & 0xff; randomxKey[2] = (ASSETCHAINS_MAGIC >> 16) & 0xff; @@ -1154,6 +1156,7 @@ void static RandomXMiner() for(int i=0; i++; i Date: Wed, 29 Jun 2022 23:20:25 -0400 Subject: [PATCH 074/255] avoid coredump by hardcoding some things --- src/miner.cpp | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 9b5ad0392..a4c8c2e14 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1146,24 +1146,31 @@ void static RandomXMiner() fprintf(stderr,"RandomXMiner: created randomxHash of size %d\n", RANDOMX_HASH_SIZE); // Initial randomx key is chain magic || ac_name which is >= 2^40 bits of entropy assuming strlen(ac_name) >= 1 // For ac_name=DRAGONX we have 4 + 7 = 11 bytes or 2^88 bits of entropy - char randomxKey[4 + strlen(SMART_CHAIN_SYMBOL)]; - fprintf(stderr,"RandomXMiner: creating randomxKey of size %d\n", 4 + strlen(SMART_CHAIN_SYMBOL)); + //int randomxKeySize = sizeof(randomxKey); // 4 + strlen(SMART_CHAIN_SYMBOL)]; + char randomxKey[] = "RANDOMX"; + //fprintf(stderr,"RandomXMiner: creating randomxKey of size %d\n", randomxKeySize); + /* randomxKey[0] = ASSETCHAINS_MAGIC & 0xff; randomxKey[1] = (ASSETCHAINS_MAGIC >> 8) & 0xff; randomxKey[2] = (ASSETCHAINS_MAGIC >> 16) & 0xff; randomxKey[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff; - + for(int i=0; i++; iGetBlockHash(); crypto_generichash_blake2b_state new_state; crypto_generichash_blake2b_update(&state, (unsigned char *)&randomxBlockKey, 32); crypto_generichash_blake2b_final(&state, randomxInput, 32); randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxKey); + fprintf(stderr,"RandomXMiner: initialized cache\n"); } randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL); @@ -1200,10 +1210,13 @@ void static RandomXMiner() LogPrintf("Cannot create RandomX VM, aborting!\n"); return; } + fprintf(stderr,"RandomXMiner: created VM\n"); randomx_calculate_hash(myVM, &randomxInput, sizeof randomxInput, randomxHash); + fprintf(stderr,"RandomXMiner: calculated randomx hash\n"); randomx_destroy_vm(myVM); + fprintf(stderr,"RandomXMiner: destroyed VM\n"); randomx_release_cache(randomxCache); printf("RandomX Hash: "); From b99772e6228e1f57b093b17909a13d064003fd44 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 30 Jun 2022 09:05:20 -0400 Subject: [PATCH 075/255] more debug --- src/miner.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index a4c8c2e14..9b5e1648d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1119,7 +1119,7 @@ void static RandomXMiner() } } IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); - fprintf(stderr,"Running HushRandomXMiner with %u transactions in block\n",(int32_t)pblock->vtx.size()); + fprintf(stderr,"RandomXMiner: %u transactions in block\n",(int32_t)pblock->vtx.size()); LogPrintf("Running HushRandomXMiner with %u transactions in block (%u bytes)\n",pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); // Search @@ -1138,7 +1138,7 @@ void static RandomXMiner() break; hush_longestchain(); - LogPrint("pow", "Running RandomX solver with nNonce = %s\n",pblock->nNonce.ToString()); + fprintf(stderr,"RandomXMiner: solving with nNonce = %s\n",pblock->nNonce.ToString().c_str()); arith_uint256 hashTarget; hashTarget = HASHTarget; @@ -1236,13 +1236,20 @@ void static RandomXMiner() (std::vector soln) { int32_t z; arith_uint256 h; CBlock B; // Write the solution to the hash and compute the result. - LogPrint("pow", "- Checking solution against target\n"); + fprintf(stderr,"RandomXMiner: Checking solution against target\n"); pblock->nSolution = soln; solutionTargetChecks.increment(); B = *pblock; h = UintToArith256(B.GetHash()); if ( h > hashTarget ) { + fprintf(stderr,"RandomXMiner: h > hashTarget h="); + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&h)[z]); + fprintf(stderr," , hashTarget="); + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); + fprintf(stderr,"\n"); return false; } @@ -1250,10 +1257,11 @@ void static RandomXMiner() if ( !TestBlockValidity(state,B, chainActive.LastTip(), true, false)) { h = UintToArith256(B.GetHash()); - //for (z=31; z>=0; z--) - // fprintf(stderr,"%02x",((uint8_t *)&h)[z]); - fprintf(stderr,"Invalid randomx block mined, try again\n"); + fprintf(stderr,"RandomXMiner: Invalid randomx block mined, try again "); + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&h)[z]); gotinvalid = 1; + fprintf(stderr,"\n"); return(false); } SetThreadPriority(THREAD_PRIORITY_NORMAL); @@ -1284,7 +1292,7 @@ void static RandomXMiner() // TODO: solver specific stuff try { // TODO: Convert solution to byte array (decompress) and pass it to validBlock method. - std::vector sol_char; // = GetMinimalFromIndices(index_vector, DIGITBITS); + std::vector sol_char(randomxHash, randomxHash+32); // = GetMinimalFromIndices(index_vector, DIGITBITS); bool found = validBlock(sol_char); if (found) { LogPrintf("HushRandomXMiner found solution!\n"); @@ -1292,7 +1300,7 @@ void static RandomXMiner() // because they become invalid as we created a new block in blockchain. break; } else { - fprintf(stderr,"HushRandomXMiner solution not found, validBlock=false"); + fprintf(stderr,"HushRandomXMiner: solution not found, validBlock=false\n"); } } catch (RandomXSolverCanceledException&) { LogPrintf("HushRandomXMiner solver canceled\n"); From 2353f1a4337a3049d5ccdc3fffaeb53b2461d8b2 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 30 Jun 2022 09:18:58 -0400 Subject: [PATCH 076/255] even more debug --- src/miner.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 9b5e1648d..ea987e9b1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1036,7 +1036,7 @@ void static RandomXMiner() miningTimer.start(); try { - fprintf(stderr,"trying %s Mining with randomx\n",SMART_CHAIN_SYMBOL); + fprintf(stderr,"RandomXMiner: mining %s with randomx\n",SMART_CHAIN_SYMBOL); while (true) { @@ -1241,15 +1241,18 @@ void static RandomXMiner() solutionTargetChecks.increment(); B = *pblock; h = UintToArith256(B.GetHash()); + + fprintf(stderr,"RandomXMiner: h="); + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&h)[z]); + fprintf(stderr," , hashTarget="); + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); + fprintf(stderr,"\n"); + if ( h > hashTarget ) { - fprintf(stderr,"RandomXMiner: h > hashTarget h="); - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&h)[z]); - fprintf(stderr," , hashTarget="); - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); - fprintf(stderr,"\n"); + fprintf(stderr,"RandomXMiner: h > hashTarget"); return false; } @@ -1295,7 +1298,7 @@ void static RandomXMiner() std::vector sol_char(randomxHash, randomxHash+32); // = GetMinimalFromIndices(index_vector, DIGITBITS); bool found = validBlock(sol_char); if (found) { - LogPrintf("HushRandomXMiner found solution!\n"); + fprintf(stderr,"RandomXMiner: found solution!\n"); // If we find a POW solution, do not try other solutions // because they become invalid as we created a new block in blockchain. break; From 4988ce6f2e3611b4feb7536635127b0cf9b03276 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 1 Jul 2022 12:20:51 -0400 Subject: [PATCH 077/255] much debug such wow --- src/hush.h | 2 ++ src/main.cpp | 18 +++++++++-------- src/miner.cpp | 54 +++++++++++++++++++++++++++++---------------------- 3 files changed, 43 insertions(+), 31 deletions(-) diff --git a/src/hush.h b/src/hush.h index ee9f608f2..915c18096 100644 --- a/src/hush.h +++ b/src/hush.h @@ -504,11 +504,13 @@ void hush_stateupdate(int32_t height,uint8_t notarypubs[][33],uint8_t numnotarie int32_t hush_validate_chain(uint256 srchash,int32_t notarized_height) { + fprintf(stderr,"%s\n", __func__); static int32_t last_rewind; int32_t rewindtarget; CBlockIndex *pindex; struct hush_state *sp; char symbol[HUSH_SMART_CHAIN_MAXLEN],dest[HUSH_SMART_CHAIN_MAXLEN]; if ( (sp= hush_stateptr(symbol,dest)) == 0 ) return(0); if ( IsInitialBlockDownload() == 0 && ((pindex= hush_getblockindex(srchash)) == 0 || pindex->GetHeight() != notarized_height) ) { + fprintf(stderr,"%s: Not in IBD, height=%d\n", __func__, pindex->GetHeight() ); if ( sp->NOTARIZED_HEIGHT > 0 && sp->NOTARIZED_HEIGHT < notarized_height ) rewindtarget = sp->NOTARIZED_HEIGHT - 1; else if ( notarized_height > 101 ) diff --git a/src/main.cpp b/src/main.cpp index 4e6fc678f..0c89f526a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2403,7 +2403,9 @@ bool IsInitialBlockDownload() { LogPrintf("Leaving InitialBlockDownload (latching to false)\n"); latchToFalse.store(true, std::memory_order_relaxed); - } // else fprintf(stderr,"state.%d ht.%d vs %d, t.%u\n",state,(int32_t)chainActive.Height(),(uint32_t)ptr->GetHeight(),(int32_t)ptr->GetBlockTime()); + } else { + fprintf(stderr,"%s: state.%d ht.%d vs %d, t.%u\n",__func__, state,(int32_t)chainActive.Height(),(uint32_t)ptr->GetHeight(),(int32_t)ptr->GetBlockTime()); + } return state; } @@ -2446,12 +2448,14 @@ static CBlockIndex *pindexBestForkBase = NULL; void CheckForkWarningConditions() { + fprintf(stderr,"%s checking for IBD\n", __func__); AssertLockHeld(cs_main); // Before we get past initial download, we cannot reliably alert about forks // (we assume we don't get stuck on a fork before finishing our initial sync) if (IsInitialBlockDownload()) return; + fprintf(stderr,"%s not in IBD\n", __func__); // If our best fork is no longer within 288 blocks (+/- 12 hours if no one mines it) // of our head, drop it if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->GetHeight() >= 288) @@ -2479,9 +2483,7 @@ void CheckForkWarningConditions() CAlert::Notify(warning, true); fLargeWorkInvalidChainFound = true; } - } - else - { + } else { fLargeWorkForkFound = false; fLargeWorkInvalidChainFound = false; } @@ -5537,23 +5539,23 @@ bool TestBlockValidity(CValidationState &state, const CBlock& block, CBlockIndex // NOTE: CheckBlockHeader is called by CheckBlock if (!ContextualCheckBlockHeader(block, state, pindexPrev)) { - //fprintf(stderr,"TestBlockValidity failure A checkPOW.%d\n",fCheckPOW); + fprintf(stderr,"%s: failure A checkPOW=%d\n",__func__,fCheckPOW); return false; } int32_t futureblock; if (!CheckBlock(&futureblock,indexDummy.GetHeight(),0,block, state, verifier, fCheckPOW, fCheckMerkleRoot)) { - //fprintf(stderr,"TestBlockValidity failure B checkPOW.%d\n",fCheckPOW); + fprintf(stderr,"%s: failure B checkPOW=%d\n",__func__, fCheckPOW); return false; } if (!ContextualCheckBlock(0,block, state, pindexPrev)) { - //fprintf(stderr,"TestBlockValidity failure C checkPOW.%d\n",fCheckPOW); + fprintf(stderr,"%s: failure C checkPOW=%d\n",__func__, fCheckPOW); return false; } if (!ConnectBlock(block, state, &indexDummy, viewNew, true,fCheckPOW)) { - //fprintf(stderr,"TestBlockValidity failure D checkPOW.%d\n",fCheckPOW); + fprintf(stderr,"%s: failure D checkPOW=%d\n",__func__,fCheckPOW); return false; } assert(state.IsValid()); diff --git a/src/miner.cpp b/src/miner.cpp index ea987e9b1..fd81ec143 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -154,6 +154,7 @@ bool hush_appendACscriptpub(); CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { + fprintf(stderr,"%s\n", __func__); CScript scriptPubKeyIn(_scriptPubKeyIn); CPubKey pk; @@ -172,14 +173,14 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 uint64_t deposits,voutsum=0; int32_t isrealtime,hushheight; uint32_t blocktime; const CChainParams& chainparams = Params(); bool fNotarizationBlock = false; std::vector NotarizationNotaries; - //fprintf(stderr,"create new block\n"); + fprintf(stderr,"%s: create new block with pubkey=%s\n", __func__, HexStr(pk).c_str()); // Create new block if ( gpucount < 0 ) gpucount = HUSH_MAXGPUCOUNT; std::unique_ptr pblocktemplate(new CBlockTemplate()); if(!pblocktemplate.get()) { - fprintf(stderr,"pblocktemplate.get() failure\n"); + fprintf(stderr,"%s: pblocktemplate.get() failure\n", __func__); return NULL; } CBlock *pblock = &pblocktemplate->block; // pointer for convenience @@ -505,8 +506,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 //fprintf(stderr,"fee rate skip\n"); continue; } - // Prioritise by fee once past the priority size or we run out of high-priority - // transactions: + // Prioritize by fee once past the priority size or we run out of high-priority transactions if (!fSortedByFee && ((nBlockSize + nTxSize >= nBlockPrioritySize) || !AllowFree(dPriority))) { @@ -595,7 +595,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout.resize(1); txNew.vout[0].scriptPubKey = scriptPubKeyIn; txNew.vout[0].nValue = GetBlockSubsidy(nHeight,consensusParams) + nFees; - fprintf(stderr,"mine ht.%d with %.8f\n",nHeight,(double)txNew.vout[0].nValue/COIN); + fprintf(stderr,"%s: mine ht.%d with %.8f\n",__func__,nHeight,(double)txNew.vout[0].nValue/COIN); txNew.nExpiryHeight = 0; if ( ASSETCHAINS_ADAPTIVEPOW <= 0 ) txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetTime()); @@ -741,7 +741,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 else if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && ASSETCHAINS_STAKED == 0 && (SMART_CHAIN_SYMBOL[0] != 0 || IS_HUSH_NOTARY == 0 || My_notaryid < 0) ) { CValidationState state; - //fprintf(stderr,"check validity\n"); + fprintf(stderr,"%s: check validity\n", __func__); if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) // invokes CC checks { if ( SMART_CHAIN_SYMBOL[0] == 0 || (SMART_CHAIN_SYMBOL[0] != 0 && !isStake) ) @@ -749,6 +749,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 LEAVE_CRITICAL_SECTION(cs_main); LEAVE_CRITICAL_SECTION(mempool.cs); } + fprintf(stderr,"%s: TestBlockValidity failed!\n", __func__); //throw std::runtime_error("CreateNewBlock(): TestBlockValidity failed"); // crashes the node, moved to GetBlockTemplate and issue return. return(0); } @@ -760,7 +761,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 LEAVE_CRITICAL_SECTION(cs_main); LEAVE_CRITICAL_SECTION(mempool.cs); } - //fprintf(stderr,"done new block\n"); + fprintf(stderr,"%s: done\n", __func__); return pblocktemplate.release(); } @@ -771,6 +772,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce) { + fprintf(stderr,"RandomXMiner: %s with nExtraNonce=%u\n", __func__, nExtraNonce); // Update nExtraNonce static uint256 hashPrevBlock; if (hashPrevBlock != pblock->hashPrevBlock) @@ -794,12 +796,14 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, int32_t gpucount, bool isStake) { CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i,len; + fprintf(stderr,"%s: with nHeight=%d\n", __func__, nHeight); if ( nHeight == 1 && ASSETCHAINS_COMMISSION != 0 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()] != 49 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()-1] != 51 ) { if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { pubkey = ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY); scriptPubKey = CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG; + fprintf(stderr,"%s: with pubkey=%s\n", __func__, HexStr(pubkey).c_str() ); } else { len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); len >>= 1; @@ -823,16 +827,20 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, } else { // wallet disabled CTxDestination dest = DecodeDestination(GetArg("-mineraddress", "")); + char destaddr[65]; if (IsValidDestination(dest)) { // CKeyID keyID = boost::get(dest); // scriptPubKey = CScript() << OP_DUP << OP_HASH160 << ToByteVector(keyID) << OP_EQUALVERIFY << OP_CHECKSIG; scriptPubKey = GetScriptForDestination(dest); + Getscriptaddress(destaddr,scriptPubKey); + fprintf(stderr,"%s: wallet disabled with mineraddress=%s\n", __func__, destaddr); } else { return NULL; } } } } + fprintf(stderr,"%s: calling CreateNewBlock\n", __func__); return CreateNewBlock(pubkey, scriptPubKey, gpucount, isStake); } @@ -1040,6 +1048,7 @@ void static RandomXMiner() while (true) { + fprintf(stderr,"RandomXMiner: beginning mining loop on %s with nExtraNonce=%u\n",SMART_CHAIN_SYMBOL, nExtraNonce); if (chainparams.MiningRequiresPeers()) { //if ( ASSETCHAINS_SEED != 0 && chainActive.LastTip()->GetHeight() < 100 ) // break; @@ -1061,9 +1070,8 @@ void static RandomXMiner() //fprintf(stderr,"%s Found peers\n",SMART_CHAIN_SYMBOL); miningTimer.start(); } - // + // Create new block - // unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); CBlockIndex* pindexPrev = chainActive.LastTip(); if ( Mining_height != pindexPrev->GetHeight()+1 ) @@ -1071,11 +1079,14 @@ void static RandomXMiner() Mining_height = pindexPrev->GetHeight()+1; Mining_start = (uint32_t)time(NULL); } + fprintf(stderr,"RandomXMiner: Mining_start=%u\n", Mining_start); #ifdef ENABLE_WALLET CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif + + fprintf(stderr,"RandomXMiner: created new block\n"); if ( ptr == 0 ) { if ( !GetBoolArg("-gen",false)) @@ -1087,11 +1098,11 @@ void static RandomXMiner() } static uint32_t counter; if ( counter++ < 10 && ASSETCHAINS_STAKED == 0 ) - fprintf(stderr,"created illegal blockB, retry\n"); + fprintf(stderr,"RandomXMiner: created illegal blockB, retry with counter=%u\n", counter); sleep(1); continue; } - //fprintf(stderr,"get template\n"); + fprintf(stderr,"RandomXMiner: getting block template\n"); unique_ptr pblocktemplate(ptr); if (!pblocktemplate.get()) { @@ -1133,7 +1144,7 @@ void static RandomXMiner() gotinvalid = 0; while (true) { - fprintf(stderr,"gotinvalid.%d\n",gotinvalid); + fprintf(stderr,"RandomXMiner: gotinvalid=%d\n",gotinvalid); if ( gotinvalid != 0 ) break; hush_longestchain(); @@ -1186,13 +1197,14 @@ void static RandomXMiner() // This lag is 80 mins for 75s blocktime and 64 mins for 60s (default) blocktime for HSCs int randomxBlockLag = 64; - fprintf(stderr,"RandomX using initial key with interval=%d and lag=%d\n", randomxInterval, randomxBlockLag); + fprintf(stderr,"RandomXMiner: using initial key with interval=%d and lag=%d\n", randomxInterval, randomxBlockLag); fprintf(stderr,"RandomXMiner: Mining_height=%u\n", Mining_height); // Use the initial key at the start of the chain if( (Mining_height) < randomxInterval + randomxBlockLag) { randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey); fprintf(stderr,"RandomXMiner: initialized cache with initial key\n"); } else { + fprintf(stderr,"RandomXMiner: calculating keyHeight with randomxInterval=%d\n", randomxInterval); // At heights between intervals, we use the same block key and wait randomxBlockLag blocks until changing int keyHeight = ((Mining_height - randomxBlockLag) / randomxInterval) * randomxInterval; fprintf(stderr,"RandomXMiner: key height=%d\n", keyHeight); @@ -1202,12 +1214,12 @@ void static RandomXMiner() crypto_generichash_blake2b_final(&state, randomxInput, 32); randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxKey); - fprintf(stderr,"RandomXMiner: initialized cache\n"); + fprintf(stderr,"RandomXMiner: initialized cache with randomxBlockKey=%s\n", randomxBlockKey.ToString().c_str()); } randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL); if(myVM == NULL) { - LogPrintf("Cannot create RandomX VM, aborting!\n"); + fprintf(stderr,"RandomXMiner: Cannot create RandomX VM, aborting!\n"); return; } fprintf(stderr,"RandomXMiner: created VM\n"); @@ -1303,7 +1315,7 @@ void static RandomXMiner() // because they become invalid as we created a new block in blockchain. break; } else { - fprintf(stderr,"HushRandomXMiner: solution not found, validBlock=false\n"); + fprintf(stderr,"RandomXMiner: solution not found, validBlock=false\n"); } } catch (RandomXSolverCanceledException&) { LogPrintf("HushRandomXMiner solver canceled\n"); @@ -1331,19 +1343,15 @@ void static RandomXMiner() pblock->nBits = savebits; } } - } - catch (const boost::thread_interrupted&) - { + } catch (const boost::thread_interrupted&) { miningTimer.stop(); c.disconnect(); LogPrintf("HushRandomXMiner terminated\n"); throw; - } - catch (const std::runtime_error &e) - { + } catch (const std::runtime_error &e) { miningTimer.stop(); c.disconnect(); - LogPrintf("HushRandomXMiner runtime error: %s\n", e.what()); + fprintf(stderr,"RandomXMiner: runtime error: %s\n", e.what()); return; } miningTimer.stop(); From a45150eac452a31441728de0bf810ccaf1991ced Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 1 Jul 2022 13:10:30 -0400 Subject: [PATCH 078/255] yet more debug --- src/hush_utils.h | 16 ++++++++++++---- src/main.cpp | 1 + src/miner.cpp | 21 +++++++++++++++++---- 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/hush_utils.h b/src/hush_utils.h index 81030a268..19deeeadb 100644 --- a/src/hush_utils.h +++ b/src/hush_utils.h @@ -1622,13 +1622,13 @@ uint64_t hush_block_subsidy(int height) // wrapper for more general supply curves of Hush Smart Chains uint64_t hush_sc_block_subsidy(int nHeight) { - //fprintf(stderr,"%s: ht.%d\n", __func__, nHeight); // Find current era, start from beginning reward, and determine current subsidy int64_t numerator, denominator, subsidy = 0; int64_t subsidyDifference; int32_t numhalvings = 0, curEra = 0, sign = 1; static uint64_t cached_subsidy; static int32_t cached_numhalvings; static int cached_era; bool ishush3 = strncmp(SMART_CHAIN_SYMBOL, "HUSH3",5) == 0 ? true : false; + fprintf(stderr,"%s: ht=%d ishush3=%d\n", __func__, nHeight, ishush3); // check for backwards compat, older chains with no explicit rewards had 0.0001 block reward if ( ASSETCHAINS_ENDSUBSIDY[0] == 0 && ASSETCHAINS_REWARD[0] == 0 ) { @@ -1649,11 +1649,12 @@ uint64_t hush_sc_block_subsidy(int nHeight) { int64_t nStart = curEra ? ASSETCHAINS_ENDSUBSIDY[curEra - 1] : 0; subsidy = (int64_t)ASSETCHAINS_REWARD[curEra]; - if(fDebug) + //if(fDebug) fprintf(stderr,"%s: nStart.%ld subsidy.%ld curEra.%d\n",__func__,nStart,subsidy,curEra); if ( subsidy || (curEra != ASSETCHAINS_LASTERA && ASSETCHAINS_REWARD[curEra + 1] != 0) ) { + fprintf(stderr,"%s: subsidy=%ld at height=%d with ASSETCHAINS_HALVING[curEra]=%lu\n",__func__,subsidy,nHeight, ASSETCHAINS_HALVING[curEra]); if ( ASSETCHAINS_HALVING[curEra] != 0 ) { if (ishush3) { @@ -1680,7 +1681,14 @@ uint64_t hush_sc_block_subsidy(int nHeight) } denominator = ASSETCHAINS_ENDSUBSIDY[curEra] - nStart; numerator = denominator - ((ASSETCHAINS_ENDSUBSIDY[curEra] - nHeight) + ((nHeight - nStart) % ASSETCHAINS_HALVING[curEra])); - subsidy = subsidy - sign * ((subsidyDifference * numerator) / denominator); + fprintf(stderr,"%s: numerator=%ld , denominator=%ld at height=%d\n",__func__,numerator, denominator,nHeight); + if( denominator ) { + subsidy = subsidy - sign * ((subsidyDifference * numerator) / denominator); + } else { + fprintf(stderr,"%s: invalid denominator=%ld !\n", __func__, denominator); + fprintf(stderr,"%s: defaulting to 0.0001 subsidy\n",__func__); + subsidy = 10000; + } } else { if ( cached_subsidy > 0 && cached_era == curEra && cached_numhalvings == numhalvings ) { subsidy = cached_subsidy; @@ -1715,7 +1723,7 @@ uint64_t hush_sc_block_subsidy(int nHeight) else subsidy += ASSETCHAINS_SUPPLY * SATOSHIDEN + magicExtra; } - if(fDebug) + //if(fDebug) fprintf(stderr,"%s: ht.%d curEra.%d lastEra.%lu subsidy.%ld magicExtra.%u\n",__func__,nHeight,curEra,ASSETCHAINS_LASTERA,subsidy,magicExtra); return(subsidy); } diff --git a/src/main.cpp b/src/main.cpp index 0c89f526a..7e665a562 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2359,6 +2359,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW) CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { + fprintf(stderr,"%s: nHeight=%d\n", __func__, nHeight); return hush_sc_block_subsidy(nHeight); } diff --git a/src/miner.cpp b/src/miner.cpp index fd81ec143..ea6a298d9 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -178,6 +178,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if ( gpucount < 0 ) gpucount = HUSH_MAXGPUCOUNT; std::unique_ptr pblocktemplate(new CBlockTemplate()); + fprintf(stderr,"%s: created new block template\n", __func__); if(!pblocktemplate.get()) { fprintf(stderr,"%s: pblocktemplate.get() failure\n", __func__); @@ -193,6 +194,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 pblock->vtx.push_back(CTransaction()); pblocktemplate->vTxFees.push_back(-1); // updated at end pblocktemplate->vTxSigOps.push_back(-1); // updated at end + fprintf(stderr,"%s: added dummy coinbase\n", __func__); // Largest block you're willing to create: unsigned int nBlockMaxSize = GetArg("-blockmaxsize", MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1)); @@ -208,6 +210,8 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 // until there are no more or the block reaches this size: unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE); nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize); + fprintf(stderr,"%s: nBlockMaxSize=%u, nBlockPrioritySize=%u, nBlockMinSize=%u\n", __func__, nBlockMaxSize, nBlockPrioritySize, nBlockMinSize); + // Collect memory pool transactions into the block CAmount nFees = 0; @@ -230,7 +234,11 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); uint32_t proposedTime = GetTime(); + + fprintf(stderr,"%s: nHeight=%d, consensusBranchId=%u, proposedTime=%u\n", __func__, nHeight, consensusBranchId, proposedTime); + voutsum = GetBlockSubsidy(nHeight,consensusParams) + 10000*COIN; // approx fees + fprintf(stderr,"%s: voutsum=%lu\n", __func__, voutsum); if (proposedTime == nMedianTimePast) { @@ -267,6 +275,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 vector vecPriority; vecPriority.reserve(mempool.mapTx.size() + 1); + fprintf(stderr,"%s: going to add txs from mempool\n", __func__); // now add transactions from the mem pool int32_t Notarizations = 0; uint64_t txvalue; for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin(); @@ -280,7 +289,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if (tx.IsCoinBase() || !IsFinalTx(tx, nHeight, nLockTimeCutoff) || IsExpiredTx(tx, nHeight)) { - //fprintf(stderr,"coinbase.%d finaltx.%d expired.%d\n",tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); + fprintf(stderr,"%s: coinbase.%d finaltx.%d expired.%d\n",__func__, tx.IsCoinBase(),IsFinalTx(tx, nHeight, nLockTimeCutoff),IsExpiredTx(tx, nHeight)); continue; } txvalue = tx.GetValueOut(); @@ -449,6 +458,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 // Size limits unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); + fprintf(stderr,"%s: nTxSize = %u\n", __func__, nTxSize); // Opret spam limits if (mapArgs.count("-opretmintxfee")) @@ -485,7 +495,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 if (nBlockSize + nTxSize >= nBlockMaxSize-512) // room for extra autotx { - //fprintf(stderr,"nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",(int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); + fprintf(stderr,"%s: nBlockSize %d + %d nTxSize >= %d nBlockMaxSize\n",__func__, (int32_t)nBlockSize,(int32_t)nTxSize,(int32_t)nBlockMaxSize); continue; } @@ -496,6 +506,9 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 //fprintf(stderr,"A nBlockSigOps %d + %d nTxSigOps >= %d MAX_BLOCK_SIGOPS-1\n",(int32_t)nBlockSigOps,(int32_t)nTxSigOps,(int32_t)MAX_BLOCK_SIGOPS); continue; } + + fprintf(stderr,"%s: looking to see if we need to skip any fee=0 txs\n", __func__); + // Skip free transactions if we're past the minimum block size: const uint256& hash = tx.GetHash(); double dPriorityDelta = 0; @@ -503,7 +516,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 mempool.ApplyDeltas(hash, dPriorityDelta, nFeeDelta); if (fSortedByFee && (dPriorityDelta <= 0) && (nFeeDelta <= 0) && (feeRate < ::minRelayTxFee) && (nBlockSize + nTxSize >= nBlockMinSize)) { - //fprintf(stderr,"fee rate skip\n"); + fprintf(stderr,"%s: fee rate skip\n", __func__); continue; } // Prioritize by fee once past the priority size or we run out of high-priority transactions @@ -535,7 +548,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 PrecomputedTransactionData txdata(tx); if (!ContextualCheckInputs(tx, state, view, true, MANDATORY_SCRIPT_VERIFY_FLAGS, true, txdata, Params().GetConsensus(), consensusBranchId)) { - //fprintf(stderr,"context failure\n"); + fprintf(stderr,"%s: ContextualCheckInputs failure\n",__func__); continue; } UpdateCoins(tx, view, nHeight); From 05cbc86a009a8ebcf6a5ab7b74ee2465cfea89f0 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 1 Jul 2022 13:43:51 -0400 Subject: [PATCH 079/255] Fix bug where GetNextWorkRequired did not know about randomx --- src/hush_defs.h | 2 +- src/miner.cpp | 10 ++++++++++ src/pow.cpp | 7 +++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/hush_defs.h b/src/hush_defs.h index 4d8bd62b8..c4a0b5425 100644 --- a/src/hush_defs.h +++ b/src/hush_defs.h @@ -568,7 +568,7 @@ extern int32_t ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, ASSETCHAINS_OVERWINTER, extern uint64_t ASSETCHAINS_SUPPLY, ASSETCHAINS_FOUNDERS_REWARD; extern int32_t ASSETCHAINS_LWMAPOS, ASSETCHAINS_SAPLING, ASSETCHAINS_OVERWINTER,ASSETCHAINS_BLOCKTIME; extern uint64_t ASSETCHAINS_TIMELOCKGTE; -extern uint32_t ASSETCHAINS_ALGO,ASSETCHAINS_EQUIHASH,HUSH_INITDONE; +extern uint32_t ASSETCHAINS_ALGO,ASSETCHAINS_EQUIHASH,ASSETCHAINS_RANDOMX, HUSH_INITDONE; extern int32_t HUSH_MININGTHREADS,HUSH_LONGESTCHAIN,ASSETCHAINS_SEED,IS_HUSH_NOTARY,USE_EXTERNAL_PUBKEY,HUSH_CHOSEN_ONE,HUSH_ON_DEMAND,HUSH_PASSPORT_INITDONE,ASSETCHAINS_STAKED,HUSH_NSPV; extern uint64_t ASSETCHAINS_COMMISSION, ASSETCHAINS_LASTERA,ASSETCHAINS_CBOPRET; extern uint64_t ASSETCHAINS_REWARD[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_NOTARY_PAY[ASSETCHAINS_MAX_ERAS+1], ASSETCHAINS_TIMELOCKGTE, ASSETCHAINS_NONCEMASK[],ASSETCHAINS_NK[2]; diff --git a/src/miner.cpp b/src/miner.cpp index ea6a298d9..392d9aaa4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -391,6 +391,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 // Priority is sum(valuein * age) / modified_txsize unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); + fprintf(stderr,"%s: computing priority with nTxSize=%u\n", __func__, nTxSize); dPriority = tx.ComputePriority(dPriority, nTxSize); uint256 hash = tx.GetHash(); @@ -436,6 +437,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx()))); } } + fprintf(stderr,"%s: done adding txs from mempool\n", __func__); // Collect transactions into block int64_t interest; @@ -447,13 +449,18 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 TxPriorityCompare comparer(fSortedByFee); std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); + fprintf(stderr,"%s: compared txs with fSortedByFee=%d\n", __func__, fSortedByFee); + while (!vecPriority.empty()) { // Take highest priority transaction off the priority queue: double dPriority = vecPriority.front().get<0>(); CFeeRate feeRate = vecPriority.front().get<1>(); const CTransaction& tx = *(vecPriority.front().get<2>()); + fprintf(stderr,"%s: grabbed first tx from priority queue\n", __func__); + std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); + fprintf(stderr,"%s: compared first tx from priority queue\n", __func__); vecPriority.pop_back(); // Size limits @@ -591,10 +598,13 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; + fprintf(stderr,"%s: nLastBlockTx=%lu , nLastBlockSize=%lu\n", __func__, nLastBlockTx, nLastBlockSize); + if ( ASSETCHAINS_ADAPTIVEPOW <= 0 ) blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetTime()); else blocktime = 1 + std::max((int64_t)(pindexPrev->nTime+1), GetTime()); //pblock->nTime = blocktime + 1; + fprintf(stderr,"%s: calling GetNextWorkRequired\n", __func__); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); diff --git a/src/pow.cpp b/src/pow.cpp index 143ee71c0..757929a19 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -297,8 +297,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead if (pindexLast->GetHeight() == 340000) { LogPrintf("%s: Using blocktime=%d\n",__func__,ASSETCHAINS_BLOCKTIME); } - if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH && ASSETCHAINS_STAKED == 0) + //if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH && ASSETCHAINS_STAKED == 0) + if (ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH && ASSETCHAINS_ALGO != ASSETCHAINS_RANDOMX) { + fprintf(stderr,"%s: using lwma for next work\n",__func__); return lwmaGetNextWorkRequired(pindexLast, pblock, params); + } arith_uint256 bnLimit; if (ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH) @@ -500,7 +503,7 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, const CBlockHead nbits = bnTarget.GetCompact(); nbits = (nbits & 0xfffffffc) | zawyflag; } - if(fDebug) + //if(fDebug) fprintf(stderr,"%s: nbits=%d\n", __func__, nbits); return(nbits); } From 26129a6339ebd961ec519129e91f44d18bac55cf Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 1 Jul 2022 17:47:03 -0400 Subject: [PATCH 080/255] Give the randomx block interval and block lag CLI options --- src/miner.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 392d9aaa4..6893b8d4f 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1214,11 +1214,12 @@ void static RandomXMiner() } fprintf(stderr,"RandomXMiner: created randomx flags + cache\n"); - // The key block will change every ~21.3 hours with a 75s block time + // With the defaults of 1024 and 64 + // the key block will change every ~21.3 hours with a 75s block time // and every ~17 hours with the default 60s block time for HSCs - int randomxInterval = 1024; + int randomxInterval = GetArg("-ac_randomx_interval",1024); // This lag is 80 mins for 75s blocktime and 64 mins for 60s (default) blocktime for HSCs - int randomxBlockLag = 64; + int randomxBlockLag = GetArg("-ac_randomx_lag", 64); fprintf(stderr,"RandomXMiner: using initial key with interval=%d and lag=%d\n", randomxInterval, randomxBlockLag); fprintf(stderr,"RandomXMiner: Mining_height=%u\n", Mining_height); From 1864b83e998f1db174b9501c0947a841152cace1 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 1 Jul 2022 18:04:04 -0400 Subject: [PATCH 081/255] oops, looks like I never added this test script --- test_randomx | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 test_randomx diff --git a/test_randomx b/test_randomx new file mode 100755 index 000000000..46ea5ffaf --- /dev/null +++ b/test_randomx @@ -0,0 +1,7 @@ +#!/bin/bash + + ./src/hushd -ac_randomx_interval=20 -ac_randomx_lag=5 -ac_halving=30 -ac_algo=randomx -ac_name=RANDOMX2 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 + +# to run via the debugger +# type "run" when gdb prompt appears +#gdb --args ./src/hushd -- -ac_algo=randomx -ac_name=RANDOMX -ac_private=1 -ac_blocktime=30 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 From 71a72c9c6011b4fa689aa21e088f949cb3ab8cdb Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 1 Jul 2022 18:37:59 -0400 Subject: [PATCH 082/255] Prevent coredump when randomxBlockKey changes --- src/miner.cpp | 6 +++--- test_randomx | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 6893b8d4f..e59bfa831 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1233,9 +1233,9 @@ void static RandomXMiner() int keyHeight = ((Mining_height - randomxBlockLag) / randomxInterval) * randomxInterval; fprintf(stderr,"RandomXMiner: key height=%d\n", keyHeight); uint256 randomxBlockKey = chainActive[keyHeight]->GetBlockHash(); - crypto_generichash_blake2b_state new_state; - crypto_generichash_blake2b_update(&state, (unsigned char *)&randomxBlockKey, 32); - crypto_generichash_blake2b_final(&state, randomxInput, 32); + //crypto_generichash_blake2b_state new_state; + //crypto_generichash_blake2b_update(&new_state, (unsigned char *)&randomxBlockKey, 32); + //crypto_generichash_blake2b_final(&new_state, randomxInput, 32); randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxKey); fprintf(stderr,"RandomXMiner: initialized cache with randomxBlockKey=%s\n", randomxBlockKey.ToString().c_str()); diff --git a/test_randomx b/test_randomx index 46ea5ffaf..780db691d 100755 --- a/test_randomx +++ b/test_randomx @@ -1,6 +1,6 @@ #!/bin/bash - ./src/hushd -ac_randomx_interval=20 -ac_randomx_lag=5 -ac_halving=30 -ac_algo=randomx -ac_name=RANDOMX2 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 + ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX3 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 # to run via the debugger # type "run" when gdb prompt appears From 15d254af104ad4af0b48d9b79fa394bfc4520641 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 1 Jul 2022 21:40:39 -0400 Subject: [PATCH 083/255] Ignore chain sync verification and relaying when -testnode=1 --- src/net.cpp | 8 +++++++- src/wallet/rpcwallet.cpp | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index ae61ea51b..ef029025b 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -43,6 +43,7 @@ #include #include using namespace hush; +extern int32_t HUSH_TESTNODE; // Dump addresses to peers.dat every 5 minutes (300s) // Satoshi originally used 10 seconds(!), did they know something Peter Wuille didn't? @@ -2120,7 +2121,12 @@ void RelayTransaction(const CTransaction& tx, const CDataStream& ss) random_shuffle( vRelayNodes.begin(), vRelayNodes.end(), GetRandInt ); vRelayNodes.resize(newSize); - fprintf(stderr, "%s: Relaying to %lu of %lu peers\n", __func__, newSize, vNodes.size() ); + if (HUSH_TESTNODE==1 && vNodes.size() == 0) { + fprintf(stderr, "%s: -testnode=1, no peers, not relaying\n", __func__ ); + return; + } else { + fprintf(stderr, "%s: Relaying to %lu of %lu peers\n", __func__, newSize, vNodes.size() ); + } // Only relay to randomly chosen 50% of peers BOOST_FOREACH(CNode* pnode, vRelayNodes) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e3f5e5064..c1755cf07 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -83,7 +83,7 @@ UniValue z_getoperationstatus_IMPL(const UniValue&, bool); #define PLAN_NAME_MAX 8 #define VALID_PLAN_NAME(x) (strlen(x) <= PLAN_NAME_MAX) -#define THROW_IF_SYNCING(INSYNC) if (INSYNC == 0) { throw runtime_error(strprintf("%s: Extreme Privacy! Chain still syncing at height %d, aborting to prevent linkability analysis. Please wait until FULLY SYNCED and try again.",__FUNCTION__,chainActive.Tip()->GetHeight())); } +#define THROW_IF_SYNCING(INSYNC) if (HUSH_TESTNODE == 0 && INSYNC == 0) { throw runtime_error(strprintf("%s: Extreme Privacy! Chain still syncing at height %d, aborting to prevent linkability analysis. Please wait until FULLY SYNCED and try again.",__FUNCTION__,chainActive.Tip()->GetHeight())); } int tx_height( const uint256 &hash ); From 212f98445977007d0a6a1cba3fa7f5cf5203fc30 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 2 Jul 2022 01:03:05 -0400 Subject: [PATCH 084/255] Use -ac_name for initial randomx key and ASSETCHAINS_MAGIC for randomx input --- src/miner.cpp | 30 ++++++++++-------------------- test_randomx | 2 +- 2 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index e59bfa831..6d7a5aba4 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1178,23 +1178,10 @@ void static RandomXMiner() char randomxHash[RANDOMX_HASH_SIZE]; fprintf(stderr,"RandomXMiner: created randomxHash of size %d\n", RANDOMX_HASH_SIZE); - // Initial randomx key is chain magic || ac_name which is >= 2^40 bits of entropy assuming strlen(ac_name) >= 1 - // For ac_name=DRAGONX we have 4 + 7 = 11 bytes or 2^88 bits of entropy - //int randomxKeySize = sizeof(randomxKey); // 4 + strlen(SMART_CHAIN_SYMBOL)]; - char randomxKey[] = "RANDOMX"; - //fprintf(stderr,"RandomXMiner: creating randomxKey of size %d\n", randomxKeySize); - /* - randomxKey[0] = ASSETCHAINS_MAGIC & 0xff; - randomxKey[1] = (ASSETCHAINS_MAGIC >> 8) & 0xff; - randomxKey[2] = (ASSETCHAINS_MAGIC >> 16) & 0xff; - randomxKey[3] = (ASSETCHAINS_MAGIC >> 24) & 0xff; - - for(int i=0; i++; i= 2^40 bits of entropy assuming strlen(ac_name) >= 5 + // For ac_name=DRAGONX we have 7 bytes or 2^56 bits of entropy + char randomxKey[65]; // randomx spec says keysize of >60 bytes is implementation-specific + strncpy(randomxKey, SMART_CHAIN_SYMBOL, 65); crypto_generichash_blake2b_state state; // Hash = blake2b( key || ac_name) @@ -1203,8 +1190,11 @@ void static RandomXMiner() //crypto_generichash_blake2b_update(&state, (unsigned char*)&SMART_CHAIN_SYMBOL[0], sizeof(SMART_CHAIN_SYMBOL)); //uchar randomxInput[32]; //crypto_generichash_blake2b_final(&state, randomxInput, 32); - unsigned char randomxInput[] = "RANDOMX"; - fprintf(stderr,"RandomXMiner: created randomxInput\n"); + //unsigned char randomxInput[] = "RANDOMX"; + char randomxInput[80]; + sprintf(randomxInput, "%08x", ASSETCHAINS_MAGIC); + + fprintf(stderr,"RandomXMiner: created randomxInput=%s\n", randomxInput); randomx_flags flags = randomx_get_flags(); randomx_cache *randomxCache = randomx_alloc_cache(flags); @@ -1237,7 +1227,7 @@ void static RandomXMiner() //crypto_generichash_blake2b_update(&new_state, (unsigned char *)&randomxBlockKey, 32); //crypto_generichash_blake2b_final(&new_state, randomxInput, 32); - randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxKey); + randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxBlockKey); fprintf(stderr,"RandomXMiner: initialized cache with randomxBlockKey=%s\n", randomxBlockKey.ToString().c_str()); } diff --git a/test_randomx b/test_randomx index 780db691d..90543998b 100755 --- a/test_randomx +++ b/test_randomx @@ -1,6 +1,6 @@ #!/bin/bash - ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX3 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 + ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX5 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 # to run via the debugger # type "run" when gdb prompt appears From 42f75bd5775715c694d9bd5880ce842dcd0719c0 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 2 Jul 2022 01:52:49 -0400 Subject: [PATCH 085/255] Make our randomx input longer with a variable prefix and suffix --- src/miner.cpp | 10 +--------- test_randomx | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 6d7a5aba4..212b3c984 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1183,16 +1183,8 @@ void static RandomXMiner() char randomxKey[65]; // randomx spec says keysize of >60 bytes is implementation-specific strncpy(randomxKey, SMART_CHAIN_SYMBOL, 65); - crypto_generichash_blake2b_state state; - // Hash = blake2b( key || ac_name) - //crypto_generichash_blake2b_update(&state, (unsigned char*)&randomxKey[0], sizeof(randomxKey)); - //crypto_generichash_blake2b_update(&state, (unsigned char*)&randomxKey[0], 4 + strlen(SMART_CHAIN_SYMBOL) + 1); - //crypto_generichash_blake2b_update(&state, (unsigned char*)&SMART_CHAIN_SYMBOL[0], sizeof(SMART_CHAIN_SYMBOL)); - //uchar randomxInput[32]; - //crypto_generichash_blake2b_final(&state, randomxInput, 32); - //unsigned char randomxInput[] = "RANDOMX"; char randomxInput[80]; - sprintf(randomxInput, "%08x", ASSETCHAINS_MAGIC); + sprintf(randomxInput, "%08x Extreme Privacy Hush Smart Chain %08x", ASSETCHAINS_MAGIC, ASSETCHAINS_MAGIC); fprintf(stderr,"RandomXMiner: created randomxInput=%s\n", randomxInput); diff --git a/test_randomx b/test_randomx index 90543998b..0c90c9ecb 100755 --- a/test_randomx +++ b/test_randomx @@ -1,6 +1,6 @@ #!/bin/bash - ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX5 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 + ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX6 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 # to run via the debugger # type "run" when gdb prompt appears From 5a742dfc9d17769a30db33f6fb8b20268d2b1464 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 2 Jul 2022 10:57:01 -0400 Subject: [PATCH 086/255] Make our initial randomx key longer, at least 9 bytes of entropy --- src/miner.cpp | 19 ++++++++++--------- test_randomx | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 212b3c984..6c65e4728 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1167,9 +1167,10 @@ void static RandomXMiner() gotinvalid = 0; while (true) { - fprintf(stderr,"RandomXMiner: gotinvalid=%d\n",gotinvalid); - if ( gotinvalid != 0 ) + if ( gotinvalid != 0 ) { + fprintf(stderr,"RandomXMiner: gotinvalid=%d\n",gotinvalid); break; + } hush_longestchain(); fprintf(stderr,"RandomXMiner: solving with nNonce = %s\n",pblock->nNonce.ToString().c_str()); @@ -1177,16 +1178,16 @@ void static RandomXMiner() hashTarget = HASHTarget; char randomxHash[RANDOMX_HASH_SIZE]; - fprintf(stderr,"RandomXMiner: created randomxHash of size %d\n", RANDOMX_HASH_SIZE); - // Initial randomx key is ac_name which is >= 2^40 bits of entropy assuming strlen(ac_name) >= 5 - // For ac_name=DRAGONX we have 7 bytes or 2^56 bits of entropy - char randomxKey[65]; // randomx spec says keysize of >60 bytes is implementation-specific - strncpy(randomxKey, SMART_CHAIN_SYMBOL, 65); + //fprintf(stderr,"RandomXMiner: created randomxHash of size %d\n", RANDOMX_HASH_SIZE); + char randomxKey[82]; // randomx spec says keysize of >60 bytes is implementation-specific + // initial randomx key is unique to every Hush Smart Chain, and has at least 9 bytes (2^128 bits) of entropy + // since magic is 4 bytes, rpc port is 4 bytes and smart chain symbol must be at least 1 character long + snprintf(randomxKey, 81, "%08x%s%08x", ASSETCHAINS_MAGIC, SMART_CHAIN_SYMBOL, ASSETCHAINS_RPCPORT); char randomxInput[80]; sprintf(randomxInput, "%08x Extreme Privacy Hush Smart Chain %08x", ASSETCHAINS_MAGIC, ASSETCHAINS_MAGIC); - fprintf(stderr,"RandomXMiner: created randomxInput=%s\n", randomxInput); + fprintf(stderr,"RandomXMiner: created randomxKey=%s , randomxInput=%s\n", randomxKey, randomxInput); randomx_flags flags = randomx_get_flags(); randomx_cache *randomxCache = randomx_alloc_cache(flags); @@ -1194,7 +1195,7 @@ void static RandomXMiner() LogPrintf("RandomX cache is null, something is wrong, cannot mine!\n"); return; } - fprintf(stderr,"RandomXMiner: created randomx flags + cache\n"); + // fprintf(stderr,"RandomXMiner: created randomx flags + cache\n"); // With the defaults of 1024 and 64 // the key block will change every ~21.3 hours with a 75s block time diff --git a/test_randomx b/test_randomx index 0c90c9ecb..e525bbb01 100755 --- a/test_randomx +++ b/test_randomx @@ -1,6 +1,6 @@ #!/bin/bash - ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX6 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 + ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX8 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 # to run via the debugger # type "run" when gdb prompt appears From d078eed3cf02d709e0f5c6bcb8dd5694bb9e6bd6 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 2 Jul 2022 11:04:28 -0400 Subject: [PATCH 087/255] reduce some debugging in non-randomx code --- src/main.cpp | 4 ++-- src/miner.cpp | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7e665a562..a387f2248 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2449,14 +2449,14 @@ static CBlockIndex *pindexBestForkBase = NULL; void CheckForkWarningConditions() { - fprintf(stderr,"%s checking for IBD\n", __func__); + //fprintf(stderr,"%s checking for IBD\n", __func__); AssertLockHeld(cs_main); // Before we get past initial download, we cannot reliably alert about forks // (we assume we don't get stuck on a fork before finishing our initial sync) if (IsInitialBlockDownload()) return; - fprintf(stderr,"%s not in IBD\n", __func__); + //fprintf(stderr,"%s not in IBD\n", __func__); // If our best fork is no longer within 288 blocks (+/- 12 hours if no one mines it) // of our head, drop it if (pindexBestForkTip && chainActive.Height() - pindexBestForkTip->GetHeight() >= 288) diff --git a/src/miner.cpp b/src/miner.cpp index 6c65e4728..db9426270 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -154,7 +154,7 @@ bool hush_appendACscriptpub(); CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32_t gpucount, bool isStake) { - fprintf(stderr,"%s\n", __func__); + //fprintf(stderr,"%s\n", __func__); CScript scriptPubKeyIn(_scriptPubKeyIn); CPubKey pk; @@ -173,12 +173,12 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 uint64_t deposits,voutsum=0; int32_t isrealtime,hushheight; uint32_t blocktime; const CChainParams& chainparams = Params(); bool fNotarizationBlock = false; std::vector NotarizationNotaries; - fprintf(stderr,"%s: create new block with pubkey=%s\n", __func__, HexStr(pk).c_str()); + //fprintf(stderr,"%s: create new block with pubkey=%s\n", __func__, HexStr(pk).c_str()); // Create new block if ( gpucount < 0 ) gpucount = HUSH_MAXGPUCOUNT; std::unique_ptr pblocktemplate(new CBlockTemplate()); - fprintf(stderr,"%s: created new block template\n", __func__); + //fprintf(stderr,"%s: created new block template\n", __func__); if(!pblocktemplate.get()) { fprintf(stderr,"%s: pblocktemplate.get() failure\n", __func__); @@ -194,7 +194,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 pblock->vtx.push_back(CTransaction()); pblocktemplate->vTxFees.push_back(-1); // updated at end pblocktemplate->vTxSigOps.push_back(-1); // updated at end - fprintf(stderr,"%s: added dummy coinbase\n", __func__); + //fprintf(stderr,"%s: added dummy coinbase\n", __func__); // Largest block you're willing to create: unsigned int nBlockMaxSize = GetArg("-blockmaxsize", MAX_BLOCK_SIZE(chainActive.LastTip()->GetHeight()+1)); @@ -210,7 +210,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 // until there are no more or the block reaches this size: unsigned int nBlockMinSize = GetArg("-blockminsize", DEFAULT_BLOCK_MIN_SIZE); nBlockMinSize = std::min(nBlockMaxSize, nBlockMinSize); - fprintf(stderr,"%s: nBlockMaxSize=%u, nBlockPrioritySize=%u, nBlockMinSize=%u\n", __func__, nBlockMaxSize, nBlockPrioritySize, nBlockMinSize); + //fprintf(stderr,"%s: nBlockMaxSize=%u, nBlockPrioritySize=%u, nBlockMinSize=%u\n", __func__, nBlockMaxSize, nBlockPrioritySize, nBlockMinSize); // Collect memory pool transactions into the block @@ -235,10 +235,10 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 const int64_t nMedianTimePast = pindexPrev->GetMedianTimePast(); uint32_t proposedTime = GetTime(); - fprintf(stderr,"%s: nHeight=%d, consensusBranchId=%u, proposedTime=%u\n", __func__, nHeight, consensusBranchId, proposedTime); + //fprintf(stderr,"%s: nHeight=%d, consensusBranchId=%u, proposedTime=%u\n", __func__, nHeight, consensusBranchId, proposedTime); voutsum = GetBlockSubsidy(nHeight,consensusParams) + 10000*COIN; // approx fees - fprintf(stderr,"%s: voutsum=%lu\n", __func__, voutsum); + //fprintf(stderr,"%s: voutsum=%lu\n", __func__, voutsum); if (proposedTime == nMedianTimePast) { @@ -275,7 +275,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 vector vecPriority; vecPriority.reserve(mempool.mapTx.size() + 1); - fprintf(stderr,"%s: going to add txs from mempool\n", __func__); + //fprintf(stderr,"%s: going to add txs from mempool\n", __func__); // now add transactions from the mem pool int32_t Notarizations = 0; uint64_t txvalue; for (CTxMemPool::indexed_transaction_set::iterator mi = mempool.mapTx.begin(); @@ -391,7 +391,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 // Priority is sum(valuein * age) / modified_txsize unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); - fprintf(stderr,"%s: computing priority with nTxSize=%u\n", __func__, nTxSize); + // fprintf(stderr,"%s: computing priority with nTxSize=%u\n", __func__, nTxSize); dPriority = tx.ComputePriority(dPriority, nTxSize); uint256 hash = tx.GetHash(); @@ -437,7 +437,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 vecPriority.push_back(TxPriority(dPriority, feeRate, &(mi->GetTx()))); } } - fprintf(stderr,"%s: done adding txs from mempool\n", __func__); + // fprintf(stderr,"%s: done adding txs from mempool\n", __func__); // Collect transactions into block int64_t interest; @@ -449,7 +449,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 TxPriorityCompare comparer(fSortedByFee); std::make_heap(vecPriority.begin(), vecPriority.end(), comparer); - fprintf(stderr,"%s: compared txs with fSortedByFee=%d\n", __func__, fSortedByFee); + // fprintf(stderr,"%s: compared txs with fSortedByFee=%d\n", __func__, fSortedByFee); while (!vecPriority.empty()) { // Take highest priority transaction off the priority queue: @@ -457,15 +457,15 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 CFeeRate feeRate = vecPriority.front().get<1>(); const CTransaction& tx = *(vecPriority.front().get<2>()); - fprintf(stderr,"%s: grabbed first tx from priority queue\n", __func__); + // fprintf(stderr,"%s: grabbed first tx from priority queue\n", __func__); std::pop_heap(vecPriority.begin(), vecPriority.end(), comparer); - fprintf(stderr,"%s: compared first tx from priority queue\n", __func__); + // fprintf(stderr,"%s: compared first tx from priority queue\n", __func__); vecPriority.pop_back(); // Size limits unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION); - fprintf(stderr,"%s: nTxSize = %u\n", __func__, nTxSize); + // fprintf(stderr,"%s: nTxSize = %u\n", __func__, nTxSize); // Opret spam limits if (mapArgs.count("-opretmintxfee")) @@ -514,7 +514,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 continue; } - fprintf(stderr,"%s: looking to see if we need to skip any fee=0 txs\n", __func__); + // fprintf(stderr,"%s: looking to see if we need to skip any fee=0 txs\n", __func__); // Skip free transactions if we're past the minimum block size: const uint256& hash = tx.GetHash(); @@ -598,7 +598,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 nLastBlockTx = nBlockTx; nLastBlockSize = nBlockSize; - fprintf(stderr,"%s: nLastBlockTx=%lu , nLastBlockSize=%lu\n", __func__, nLastBlockTx, nLastBlockSize); + // fprintf(stderr,"%s: nLastBlockTx=%lu , nLastBlockSize=%lu\n", __func__, nLastBlockTx, nLastBlockSize); if ( ASSETCHAINS_ADAPTIVEPOW <= 0 ) blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetTime()); @@ -784,7 +784,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 LEAVE_CRITICAL_SECTION(cs_main); LEAVE_CRITICAL_SECTION(mempool.cs); } - fprintf(stderr,"%s: done\n", __func__); + // fprintf(stderr,"%s: done\n", __func__); return pblocktemplate.release(); } From e0651983bc722748437db3767b3dd895b027fa3f Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 2 Jul 2022 11:11:51 -0400 Subject: [PATCH 088/255] less debug --- src/hush_utils.h | 8 ++++---- test_randomx | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hush_utils.h b/src/hush_utils.h index 19deeeadb..b2e3e4903 100644 --- a/src/hush_utils.h +++ b/src/hush_utils.h @@ -1628,7 +1628,7 @@ uint64_t hush_sc_block_subsidy(int nHeight) int32_t numhalvings = 0, curEra = 0, sign = 1; static uint64_t cached_subsidy; static int32_t cached_numhalvings; static int cached_era; bool ishush3 = strncmp(SMART_CHAIN_SYMBOL, "HUSH3",5) == 0 ? true : false; - fprintf(stderr,"%s: ht=%d ishush3=%d\n", __func__, nHeight, ishush3); + // fprintf(stderr,"%s: ht=%d ishush3=%d\n", __func__, nHeight, ishush3); // check for backwards compat, older chains with no explicit rewards had 0.0001 block reward if ( ASSETCHAINS_ENDSUBSIDY[0] == 0 && ASSETCHAINS_REWARD[0] == 0 ) { @@ -1649,7 +1649,7 @@ uint64_t hush_sc_block_subsidy(int nHeight) { int64_t nStart = curEra ? ASSETCHAINS_ENDSUBSIDY[curEra - 1] : 0; subsidy = (int64_t)ASSETCHAINS_REWARD[curEra]; - //if(fDebug) + if(fDebug) fprintf(stderr,"%s: nStart.%ld subsidy.%ld curEra.%d\n",__func__,nStart,subsidy,curEra); if ( subsidy || (curEra != ASSETCHAINS_LASTERA && ASSETCHAINS_REWARD[curEra + 1] != 0) ) @@ -1665,7 +1665,7 @@ uint64_t hush_sc_block_subsidy(int nHeight) // The code below is not compatible with HUSH3 mainnet if ( ASSETCHAINS_DECAY[curEra] == 0 ) { subsidy >>= numhalvings; - fprintf(stderr,"%s: no decay, numhalvings.%d curEra.%d subsidy.%ld nStart.%ld\n",__func__, numhalvings, curEra, subsidy, nStart); + // fprintf(stderr,"%s: no decay, numhalvings.%d curEra.%d subsidy.%ld nStart.%ld\n",__func__, numhalvings, curEra, subsidy, nStart); } else if ( ASSETCHAINS_DECAY[curEra] == 100000000 && ASSETCHAINS_ENDSUBSIDY[curEra] != 0 ) { if ( curEra == ASSETCHAINS_LASTERA ) { @@ -1723,7 +1723,7 @@ uint64_t hush_sc_block_subsidy(int nHeight) else subsidy += ASSETCHAINS_SUPPLY * SATOSHIDEN + magicExtra; } - //if(fDebug) + if(fDebug) fprintf(stderr,"%s: ht.%d curEra.%d lastEra.%lu subsidy.%ld magicExtra.%u\n",__func__,nHeight,curEra,ASSETCHAINS_LASTERA,subsidy,magicExtra); return(subsidy); } diff --git a/test_randomx b/test_randomx index e525bbb01..4d783f4c4 100755 --- a/test_randomx +++ b/test_randomx @@ -1,6 +1,6 @@ #!/bin/bash - ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX8 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 + ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX9 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 # to run via the debugger # type "run" when gdb prompt appears From 22f353cb61cef5f48daa607beed4d159fa3fa21a Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 3 Jul 2022 13:20:13 -0400 Subject: [PATCH 089/255] Use the current block template as randomxInput --- src/miner.cpp | 28 ++++++++++++++++++---------- test_randomx | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index db9426270..86d9cc4f2 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1157,8 +1157,10 @@ void static RandomXMiner() LogPrintf("Running HushRandomXMiner with %u transactions in block (%u bytes)\n",pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); // Search - uint8_t pubkeys[66][33]; arith_uint256 bnMaxPoSdiff; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; uint32_t savebits; int64_t nStart = GetTime(); - pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); + uint8_t pubkeys[66][33]; arith_uint256 bnMaxPoSdiff; uint32_t blocktimes[66]; int mids[256],nonzpkeys,i,j,externalflag; + uint32_t savebits; + int64_t nStart = GetTime(); + pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); savebits = pblock->nBits; HASHTarget = arith_uint256().SetCompact(savebits); roundrobin_delay = ROUNDROBIN_DELAY; @@ -1184,10 +1186,16 @@ void static RandomXMiner() // since magic is 4 bytes, rpc port is 4 bytes and smart chain symbol must be at least 1 character long snprintf(randomxKey, 81, "%08x%s%08x", ASSETCHAINS_MAGIC, SMART_CHAIN_SYMBOL, ASSETCHAINS_RPCPORT); - char randomxInput[80]; - sprintf(randomxInput, "%08x Extreme Privacy Hush Smart Chain %08x", ASSETCHAINS_MAGIC, ASSETCHAINS_MAGIC); + //char randomxInput[80]; + //std::string randomxInput; + //sprintf(randomxInput, "%08x Extreme Privacy Hush Smart Chain %08x", ASSETCHAINS_MAGIC, ASSETCHAINS_MAGIC); - fprintf(stderr,"RandomXMiner: created randomxKey=%s , randomxInput=%s\n", randomxKey, randomxInput); + CDataStream randomxInput(SER_NETWORK, PROTOCOL_VERSION); + // Use the current block as randomx input + randomxInput << pblocktemplate->block; + + std::cerr << "RandomXMiner: randomxInput=" << HexStr(randomxInput) << "\n"; + fprintf(stderr,"RandomXMiner: created randomxKey=%s , randomxInput.size=%lu\n", randomxKey, randomxInput.size() ); //randomxInput); randomx_flags flags = randomx_get_flags(); randomx_cache *randomxCache = randomx_alloc_cache(flags); @@ -1206,7 +1214,7 @@ void static RandomXMiner() fprintf(stderr,"RandomXMiner: using initial key with interval=%d and lag=%d\n", randomxInterval, randomxBlockLag); fprintf(stderr,"RandomXMiner: Mining_height=%u\n", Mining_height); - // Use the initial key at the start of the chain + // Use the initial key at the start of the chain, until the first key block if( (Mining_height) < randomxInterval + randomxBlockLag) { randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey); fprintf(stderr,"RandomXMiner: initialized cache with initial key\n"); @@ -1229,22 +1237,22 @@ void static RandomXMiner() fprintf(stderr,"RandomXMiner: Cannot create RandomX VM, aborting!\n"); return; } - fprintf(stderr,"RandomXMiner: created VM\n"); + // fprintf(stderr,"RandomXMiner: created VM\n"); randomx_calculate_hash(myVM, &randomxInput, sizeof randomxInput, randomxHash); fprintf(stderr,"RandomXMiner: calculated randomx hash\n"); randomx_destroy_vm(myVM); - fprintf(stderr,"RandomXMiner: destroyed VM\n"); + // fprintf(stderr,"RandomXMiner: destroyed VM\n"); randomx_release_cache(randomxCache); - printf("RandomX Hash: "); + printf("RandomXMiner: randomxHash="); for (unsigned i = 0; i < RANDOMX_HASH_SIZE; ++i) { printf("%02x", randomxHash[i] & 0xff); } printf("\n"); - // TODO: use randomx hash to build a block + // Use randomx hash to build a valid block std::function)> validBlock = #ifdef ENABLE_WALLET diff --git a/test_randomx b/test_randomx index 4d783f4c4..bba394f6b 100755 --- a/test_randomx +++ b/test_randomx @@ -1,6 +1,6 @@ #!/bin/bash - ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX9 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 + ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX10 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 # to run via the debugger # type "run" when gdb prompt appears From 7dfa3f9475d61c5916881976a4b9d834ec53b086 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 4 Jul 2022 01:08:45 -0400 Subject: [PATCH 090/255] cleanup --- src/miner.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 86d9cc4f2..c50b813d8 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1186,10 +1186,6 @@ void static RandomXMiner() // since magic is 4 bytes, rpc port is 4 bytes and smart chain symbol must be at least 1 character long snprintf(randomxKey, 81, "%08x%s%08x", ASSETCHAINS_MAGIC, SMART_CHAIN_SYMBOL, ASSETCHAINS_RPCPORT); - //char randomxInput[80]; - //std::string randomxInput; - //sprintf(randomxInput, "%08x Extreme Privacy Hush Smart Chain %08x", ASSETCHAINS_MAGIC, ASSETCHAINS_MAGIC); - CDataStream randomxInput(SER_NETWORK, PROTOCOL_VERSION); // Use the current block as randomx input randomxInput << pblocktemplate->block; @@ -1224,9 +1220,6 @@ void static RandomXMiner() int keyHeight = ((Mining_height - randomxBlockLag) / randomxInterval) * randomxInterval; fprintf(stderr,"RandomXMiner: key height=%d\n", keyHeight); uint256 randomxBlockKey = chainActive[keyHeight]->GetBlockHash(); - //crypto_generichash_blake2b_state new_state; - //crypto_generichash_blake2b_update(&new_state, (unsigned char *)&randomxBlockKey, 32); - //crypto_generichash_blake2b_final(&new_state, randomxInput, 32); randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxBlockKey); fprintf(stderr,"RandomXMiner: initialized cache with randomxBlockKey=%s\n", randomxBlockKey.ToString().c_str()); From 8ca330dc686b7ed2d6c6a6df820e30ee4032bea2 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 4 Jul 2022 01:45:05 -0400 Subject: [PATCH 091/255] cleanup --- src/miner.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index c50b813d8..827618a1c 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1312,10 +1312,10 @@ void static RandomXMiner() std::lock_guard lock{m_cs}; return cancelSolver; }; - // TODO: solver specific stuff + try { - // TODO: Convert solution to byte array (decompress) and pass it to validBlock method. - std::vector sol_char(randomxHash, randomxHash+32); // = GetMinimalFromIndices(index_vector, DIGITBITS); + // Use the randomX hash as the block solution + std::vector sol_char(randomxHash, randomxHash+32); bool found = validBlock(sol_char); if (found) { fprintf(stderr,"RandomXMiner: found solution!\n"); @@ -1327,8 +1327,8 @@ void static RandomXMiner() } } catch (RandomXSolverCanceledException&) { LogPrintf("HushRandomXMiner solver canceled\n"); - std::lock_guard lock{m_cs}; - cancelSolver = false; + std::lock_guard lock{m_cs}; + cancelSolver = false; } boost::this_thread::interruption_point(); @@ -1337,13 +1337,13 @@ void static RandomXMiner() { if ( Mining_height > ASSETCHAINS_MINHEIGHT ) { - fprintf(stderr,"no nodes, break\n"); + fprintf(stderr,"%s: no nodes, break\n", __func__); break; } } if ((UintToArith256(pblock->nNonce) & 0xffff) == 0xffff) { - fprintf(stderr,"nonce & 0xffff == 0xffff, break\n"); + fprintf(stderr,"%s: nonce & 0xffff == 0xffff, break\n", __func__); break; } // Update nNonce and nTime From 642ac9bda1f7c5efb2eac45bb00aa3919b26905a Mon Sep 17 00:00:00 2001 From: jahway603 Date: Wed, 6 Jul 2022 00:12:13 -0400 Subject: [PATCH 092/255] algo all day long --- src/rpc/misc.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 2933d7393..7a394dc89 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -295,7 +295,7 @@ UniValue getinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC())); obj.push_back(Pair("relayfee", ValueFromAmount(::minRelayTxFee.GetFeePerK()))); obj.push_back(Pair("errors", GetWarnings("statusbar"))); - if ( NOTARY_PUBKEY33[0] != 0 ) { + if ( NOTARY_PUBKEY33[0] != 0 ) { char pubkeystr[65]; int32_t notaryid; std::string notaryname; if( (notaryid= hush_whoami(pubkeystr,(int32_t)chainActive.LastTip()->GetHeight(),hush_chainactive_timestamp())) >= 0 ) { obj.push_back(Pair("notaryid", notaryid)); @@ -347,8 +347,8 @@ UniValue getinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) if ( ASSETCHAINS_COMMISSION != 0 ) obj.push_back(Pair("commission", ASSETCHAINS_COMMISSION)); - if ( ASSETCHAINS_ALGO != ASSETCHAINS_EQUIHASH ) - obj.push_back(Pair("algo",ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO])); + + obj.push_back(Pair("algo",ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO])); } return obj; } From dfc3056ede5033e8370a22809004689d8a22c8e3 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Wed, 6 Jul 2022 01:08:55 -0400 Subject: [PATCH 093/255] algo twerking --- src/rpc/misc.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 7a394dc89..83b15a92f 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -347,8 +347,9 @@ UniValue getinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) if ( ASSETCHAINS_COMMISSION != 0 ) obj.push_back(Pair("commission", ASSETCHAINS_COMMISSION)); - - obj.push_back(Pair("algo",ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO])); + if ( ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) + obj.push_back(Pair("algo",ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO])); + else obj.push_back(Pair("algo",ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO])); } return obj; } From e6ec40190c702c4bb9f2c6c4cd6972a5cef731c6 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Wed, 6 Jul 2022 11:50:39 -0400 Subject: [PATCH 094/255] algo now reflects N & K if equihash --- src/rpc/misc.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 83b15a92f..50dd62090 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** @@ -348,7 +348,15 @@ UniValue getinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) if ( ASSETCHAINS_COMMISSION != 0 ) obj.push_back(Pair("commission", ASSETCHAINS_COMMISSION)); if ( ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) + { obj.push_back(Pair("algo",ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO])); + if ( ASSETCHAINS_NK[0] == 0 ) // display default for Hush + obj.push_back(Pair("algo N",200)); + else obj.push_back(Pair("algo N",ASSETCHAINS_NK[0])); + if ( ASSETCHAINS_NK[1] == 0 ) // display default for Hush + obj.push_back(Pair("algo K",9)); + else obj.push_back(Pair("algo K",ASSETCHAINS_NK[1])); + } else obj.push_back(Pair("algo",ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO])); } return obj; From 4768d302fd73888d27902361207ea77f5fd71eb7 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Wed, 6 Jul 2022 11:56:10 -0400 Subject: [PATCH 095/255] added jahway603 to AUTHORS --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index d2d49e2e0..20bd581e2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -2,6 +2,7 @@ Duke Leto https://git.hush.is/duke https://github.com/leto Miodrag https://github.com/miodragpop +jahway603 https://git.hush.is/jahway603 https://github.com/jahway603 # The SuperNET Developers From 66e9bd835a8b2d85513db404b9c716ffbe00b572 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 8 Jul 2022 09:42:54 -0400 Subject: [PATCH 096/255] less debug --- src/hush_utils.h | 6 ++++-- src/main.cpp | 2 +- src/miner.cpp | 20 +++++++++----------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/hush_utils.h b/src/hush_utils.h index b2e3e4903..597dddfac 100644 --- a/src/hush_utils.h +++ b/src/hush_utils.h @@ -1654,7 +1654,9 @@ uint64_t hush_sc_block_subsidy(int nHeight) if ( subsidy || (curEra != ASSETCHAINS_LASTERA && ASSETCHAINS_REWARD[curEra + 1] != 0) ) { - fprintf(stderr,"%s: subsidy=%ld at height=%d with ASSETCHAINS_HALVING[curEra]=%lu\n",__func__,subsidy,nHeight, ASSETCHAINS_HALVING[curEra]); + if(fDebug) { + fprintf(stderr,"%s: subsidy=%ld at height=%d with ASSETCHAINS_HALVING[curEra]=%lu\n",__func__,subsidy,nHeight, ASSETCHAINS_HALVING[curEra]); + } if ( ASSETCHAINS_HALVING[curEra] != 0 ) { if (ishush3) { @@ -1681,7 +1683,7 @@ uint64_t hush_sc_block_subsidy(int nHeight) } denominator = ASSETCHAINS_ENDSUBSIDY[curEra] - nStart; numerator = denominator - ((ASSETCHAINS_ENDSUBSIDY[curEra] - nHeight) + ((nHeight - nStart) % ASSETCHAINS_HALVING[curEra])); - fprintf(stderr,"%s: numerator=%ld , denominator=%ld at height=%d\n",__func__,numerator, denominator,nHeight); + // fprintf(stderr,"%s: numerator=%ld , denominator=%ld at height=%d\n",__func__,numerator, denominator,nHeight); if( denominator ) { subsidy = subsidy - sign * ((subsidyDifference * numerator) / denominator); } else { diff --git a/src/main.cpp b/src/main.cpp index a387f2248..68d156983 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2359,7 +2359,7 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex,bool checkPOW) CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams) { - fprintf(stderr,"%s: nHeight=%d\n", __func__, nHeight); + // fprintf(stderr,"%s: nHeight=%d\n", __func__, nHeight); return hush_sc_block_subsidy(nHeight); } diff --git a/src/miner.cpp b/src/miner.cpp index 827618a1c..9f2a4eab0 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -411,7 +411,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 Notarizations++; if ( Notarizations > 1 ) { - fprintf(stderr, "skipping notarization.%d\n",Notarizations); + fprintf(stderr, "%s: skipping notarization.%d\n",__func__, Notarizations); // Any attempted notarization needs to be in its own block! continue; } @@ -604,7 +604,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 blocktime = 1 + std::max(pindexPrev->GetMedianTimePast()+1, GetTime()); else blocktime = 1 + std::max((int64_t)(pindexPrev->nTime+1), GetTime()); //pblock->nTime = blocktime + 1; - fprintf(stderr,"%s: calling GetNextWorkRequired\n", __func__); + // fprintf(stderr,"%s: calling GetNextWorkRequired\n", __func__); pblock->nBits = GetNextWorkRequired(pindexPrev, pblock, Params().GetConsensus()); LogPrintf("CreateNewBlock(): total size %u blocktime.%u nBits.%08x\n", nBlockSize,blocktime,pblock->nBits); @@ -618,7 +618,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 txNew.vout.resize(1); txNew.vout[0].scriptPubKey = scriptPubKeyIn; txNew.vout[0].nValue = GetBlockSubsidy(nHeight,consensusParams) + nFees; - fprintf(stderr,"%s: mine ht.%d with %.8f\n",__func__,nHeight,(double)txNew.vout[0].nValue/COIN); + // fprintf(stderr,"%s: mine ht.%d with %.8f\n",__func__,nHeight,(double)txNew.vout[0].nValue/COIN); txNew.nExpiryHeight = 0; if ( ASSETCHAINS_ADAPTIVEPOW <= 0 ) txNew.nLockTime = std::max(pindexPrev->GetMedianTimePast()+1, GetTime()); @@ -701,7 +701,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 // if not staking, setup nonce, otherwise, leave it alone if (!isStake || ASSETCHAINS_LWMAPOS == 0) { - // Randomise nonce + // Randomize nonce arith_uint256 nonce = UintToArith256(GetRandHash()); // Clear the top 16 and bottom 16 or 24 bits (for local use as thread flags and counters) @@ -749,9 +749,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 pblocktemplate->vTxFees[0] = -nFees; //*(uint64_t *)(&pblock->vtx[0].vout[0].nValue) += txfees; //fprintf(stderr,"added notaryvin\n"); - } - else - { + } else { fprintf(stderr,"error adding notaryvin, need to create 0.0001 utxos\n"); if ( SMART_CHAIN_SYMBOL[0] == 0 || (SMART_CHAIN_SYMBOL[0] != 0 && !isStake) ) { @@ -764,7 +762,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 else if ( ASSETCHAINS_CC == 0 && pindexPrev != 0 && ASSETCHAINS_STAKED == 0 && (SMART_CHAIN_SYMBOL[0] != 0 || IS_HUSH_NOTARY == 0 || My_notaryid < 0) ) { CValidationState state; - fprintf(stderr,"%s: check validity\n", __func__); + //fprintf(stderr,"%s: check validity\n", __func__); if ( !TestBlockValidity(state, *pblock, pindexPrev, false, false)) // invokes CC checks { if ( SMART_CHAIN_SYMBOL[0] == 0 || (SMART_CHAIN_SYMBOL[0] != 0 && !isStake) ) @@ -819,14 +817,14 @@ void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, int32_t gpucount, bool isStake) { CPubKey pubkey; CScript scriptPubKey; uint8_t *script,*ptr; int32_t i,len; - fprintf(stderr,"%s: with nHeight=%d\n", __func__, nHeight); + // fprintf(stderr,"%s: with nHeight=%d\n", __func__, nHeight); if ( nHeight == 1 && ASSETCHAINS_COMMISSION != 0 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()] != 49 && ASSETCHAINS_SCRIPTPUB[ASSETCHAINS_SCRIPTPUB.back()-1] != 51 ) { if ( ASSETCHAINS_OVERRIDE_PUBKEY33[0] != 0 ) { pubkey = ParseHex(ASSETCHAINS_OVERRIDE_PUBKEY); scriptPubKey = CScript() << ParseHex(HexStr(pubkey)) << OP_CHECKSIG; - fprintf(stderr,"%s: with pubkey=%s\n", __func__, HexStr(pubkey).c_str() ); + // fprintf(stderr,"%s: with pubkey=%s\n", __func__, HexStr(pubkey).c_str() ); } else { len = strlen(ASSETCHAINS_SCRIPTPUB.c_str()); len >>= 1; @@ -863,7 +861,7 @@ CBlockTemplate* CreateNewBlockWithKey(CReserveKey& reservekey, int32_t nHeight, } } } - fprintf(stderr,"%s: calling CreateNewBlock\n", __func__); + // fprintf(stderr,"%s: calling CreateNewBlock\n", __func__); return CreateNewBlock(pubkey, scriptPubKey, gpucount, isStake); } From a70897966a6fdb933547084228ef571518558f12 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 11 Jul 2022 18:33:10 -0400 Subject: [PATCH 097/255] Only print out randomx debug stuff when -debug=randomx --- src/init.cpp | 6 +++- src/miner.cpp | 84 ++++++++++++++++++++++++++++++--------------------- src/util.cpp | 1 + src/util.h | 1 + test_randomx | 4 ++- 5 files changed, 59 insertions(+), 37 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index b262ee45d..e0b942158 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -512,7 +512,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", 0)); strUsage += HelpMessageOpt("-nuparams=hexBranchId:activationHeight", "Use given activation height for specified network upgrade (regtest-only)"); } - string debugCategories = "addrman, alert, bench, coindb, db, deletetx, estimatefee, http, libevent, lock, mempool, net, tls, partitioncheck, pow, proxy, prune, rand, reindex, rpc, selectcoins, stratum, tor, zmq, zrpc, zrpcunsafe (implies zrpc)"; // Don't translate these + string debugCategories = "addrman, alert, bench, coindb, db, deletetx, estimatefee, http, libevent, lock, mempool, net, tls, partitioncheck, pow, proxy, prune, rand, randomx, reindex, rpc, selectcoins, stratum, tor, zmq, zrpc, zrpcunsafe (implies zrpc)"; // Don't translate these strUsage += HelpMessageOpt("-debug=", strprintf(_("Output debugging information (default: %u, supplying is optional)"), 0) + ". " + _("If is not supplied or if = 1, output all debugging information.") + " " + _(" can be:") + " " + debugCategories + "."); strUsage += HelpMessageOpt("-experimentalfeatures", _("Enable use of experimental features")); @@ -1249,6 +1249,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) v.push_back("zrpc"); } } + if (find(categories.begin(), categories.end(), string("randomx")) != categories.end()) { + fRandomXDebug = true; + fprintf(stderr,"%s: enabled randomx debug\n", __func__); + } //fprintf(stderr,"%s tik5\n", __FUNCTION__); // Check for -debugnet diff --git a/src/miner.cpp b/src/miner.cpp index 9f2a4eab0..71ce266ce 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -58,6 +58,8 @@ #endif #include +#define rxdebug(format, ...) if(fRandomXDebug) { fprintf(stderr, format, __func__, ## __VA_ARGS__ ); } + using namespace std; ////////////////////////////////////////////////////////////////////////////// @@ -117,6 +119,7 @@ public: extern int8_t ASSETCHAINS_ADAPTIVEPOW; extern uint32_t ASSETCHAINS_RANDOMX; +extern bool fRandomXDebug; void UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParams, const CBlockIndex* pindexPrev) { @@ -793,7 +796,7 @@ CBlockTemplate* CreateNewBlock(CPubKey _pk,const CScript& _scriptPubKeyIn, int32 void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce) { - fprintf(stderr,"RandomXMiner: %s with nExtraNonce=%u\n", __func__, nExtraNonce); + //fprintf(stderr,"RandomXMiner: %s with nExtraNonce=%u\n", __func__, nExtraNonce); // Update nExtraNonce static uint256 hashPrevBlock; if (hashPrevBlock != pblock->hashPrevBlock) @@ -1065,11 +1068,15 @@ void static RandomXMiner() miningTimer.start(); try { - fprintf(stderr,"RandomXMiner: mining %s with randomx\n",SMART_CHAIN_SYMBOL); + // fprintf(stderr,"RandomXMiner: mining %s with randomx\n",SMART_CHAIN_SYMBOL); + + rxdebug("%s: mining %s with randomx\n", SMART_CHAIN_SYMBOL); while (true) { - fprintf(stderr,"RandomXMiner: beginning mining loop on %s with nExtraNonce=%u\n",SMART_CHAIN_SYMBOL, nExtraNonce); + // fprintf(stderr,"RandomXMiner: beginning mining loop on %s with nExtraNonce=%u\n",SMART_CHAIN_SYMBOL, nExtraNonce); + rxdebug("%s: start mining loop on %s with nExtraNonce=%u\n", SMART_CHAIN_SYMBOL, nExtraNonce); + if (chainparams.MiningRequiresPeers()) { //if ( ASSETCHAINS_SEED != 0 && chainActive.LastTip()->GetHeight() < 100 ) // break; @@ -1100,14 +1107,15 @@ void static RandomXMiner() Mining_height = pindexPrev->GetHeight()+1; Mining_start = (uint32_t)time(NULL); } - fprintf(stderr,"RandomXMiner: Mining_start=%u\n", Mining_start); + //fprintf(stderr,"RandomXMiner: Mining_start=%u\n", Mining_start); #ifdef ENABLE_WALLET CBlockTemplate *ptr = CreateNewBlockWithKey(reservekey, pindexPrev->GetHeight()+1, gpucount, 0); #else CBlockTemplate *ptr = CreateNewBlockWithKey(); #endif - fprintf(stderr,"RandomXMiner: created new block\n"); + // fprintf(stderr,"RandomXMiner: created new block with Mining_start=%u\n",Mining_start); + rxdebug("%s: created new block with Mining_start=%u\n",Mining_start); if ( ptr == 0 ) { if ( !GetBoolArg("-gen",false)) @@ -1123,7 +1131,9 @@ void static RandomXMiner() sleep(1); continue; } - fprintf(stderr,"RandomXMiner: getting block template\n"); + // fprintf(stderr,"RandomXMiner: getting block template\n"); + rxdebug("%s: getting block template\n"); + unique_ptr pblocktemplate(ptr); if (!pblocktemplate.get()) { @@ -1151,7 +1161,7 @@ void static RandomXMiner() } } IncrementExtraNonce(pblock, pindexPrev, nExtraNonce); - fprintf(stderr,"RandomXMiner: %u transactions in block\n",(int32_t)pblock->vtx.size()); + // fprintf(stderr,"RandomXMiner: %u transactions in block\n",(int32_t)pblock->vtx.size()); LogPrintf("Running HushRandomXMiner with %u transactions in block (%u bytes)\n",pblock->vtx.size(),::GetSerializeSize(*pblock,SER_NETWORK,PROTOCOL_VERSION)); // Search @@ -1173,7 +1183,8 @@ void static RandomXMiner() } hush_longestchain(); - fprintf(stderr,"RandomXMiner: solving with nNonce = %s\n",pblock->nNonce.ToString().c_str()); + // fprintf(stderr,"RandomXMiner: solving with nNonce = %s\n",pblock->nNonce.ToString().c_str()); + rxdebug("%s: solving with nNonce = %s\n",pblock->nNonce.ToString().c_str()); arith_uint256 hashTarget; hashTarget = HASHTarget; @@ -1188,8 +1199,9 @@ void static RandomXMiner() // Use the current block as randomx input randomxInput << pblocktemplate->block; - std::cerr << "RandomXMiner: randomxInput=" << HexStr(randomxInput) << "\n"; - fprintf(stderr,"RandomXMiner: created randomxKey=%s , randomxInput.size=%lu\n", randomxKey, randomxInput.size() ); //randomxInput); + // std::cerr << "RandomXMiner: randomxInput=" << HexStr(randomxInput) << "\n"; + // fprintf(stderr,"RandomXMiner: created randomxKey=%s , randomxInput.size=%lu\n", randomxKey, randomxInput.size() ); //randomxInput); + rxdebug("%s: randomxKey=%s randomxInput=%s", randomxKey, HexStr(randomxInput).c_str()); randomx_flags flags = randomx_get_flags(); randomx_cache *randomxCache = randomx_alloc_cache(flags); @@ -1206,43 +1218,43 @@ void static RandomXMiner() // This lag is 80 mins for 75s blocktime and 64 mins for 60s (default) blocktime for HSCs int randomxBlockLag = GetArg("-ac_randomx_lag", 64); - fprintf(stderr,"RandomXMiner: using initial key with interval=%d and lag=%d\n", randomxInterval, randomxBlockLag); - fprintf(stderr,"RandomXMiner: Mining_height=%u\n", Mining_height); + // fprintf(stderr,"RandomXMiner: using initial key with interval=%d and lag=%d\n", randomxInterval, randomxBlockLag); + rxdebug("%s: using initial key, interval=%d, lag=%d, Mining_height=%u\n", randomxInterval, randomxBlockLag, Mining_height); // Use the initial key at the start of the chain, until the first key block if( (Mining_height) < randomxInterval + randomxBlockLag) { randomx_init_cache(randomxCache, &randomxKey, sizeof randomxKey); - fprintf(stderr,"RandomXMiner: initialized cache with initial key\n"); + rxdebug("%s: initialized cache with initial key\n"); } else { - fprintf(stderr,"RandomXMiner: calculating keyHeight with randomxInterval=%d\n", randomxInterval); + rxdebug("%s: calculating keyHeight with randomxInterval=%d\n", randomxInterval); // At heights between intervals, we use the same block key and wait randomxBlockLag blocks until changing int keyHeight = ((Mining_height - randomxBlockLag) / randomxInterval) * randomxInterval; - fprintf(stderr,"RandomXMiner: key height=%d\n", keyHeight); uint256 randomxBlockKey = chainActive[keyHeight]->GetBlockHash(); randomx_init_cache(randomxCache, &randomxBlockKey, sizeof randomxBlockKey); - fprintf(stderr,"RandomXMiner: initialized cache with randomxBlockKey=%s\n", randomxBlockKey.ToString().c_str()); + rxdebug("%s: initialized cache with keyHeight=%d, randomxBlockKey=%s\n", keyHeight, randomxBlockKey.ToString().c_str()); } randomx_vm *myVM = randomx_create_vm(flags, randomxCache, NULL); if(myVM == NULL) { - fprintf(stderr,"RandomXMiner: Cannot create RandomX VM, aborting!\n"); + LogPrintf("RandomXMiner: Cannot create RandomX VM, aborting!\n"); return; } - // fprintf(stderr,"RandomXMiner: created VM\n"); randomx_calculate_hash(myVM, &randomxInput, sizeof randomxInput, randomxHash); - fprintf(stderr,"RandomXMiner: calculated randomx hash\n"); + // rxdebug("calculated randomx hash\n"); randomx_destroy_vm(myVM); // fprintf(stderr,"RandomXMiner: destroyed VM\n"); randomx_release_cache(randomxCache); - printf("RandomXMiner: randomxHash="); - for (unsigned i = 0; i < RANDOMX_HASH_SIZE; ++i) { - printf("%02x", randomxHash[i] & 0xff); - } + rxdebug("%s: randomxHash="); + if (fRandomXDebug) { + for (unsigned i = 0; i < RANDOMX_HASH_SIZE; ++i) { + printf("%02x", randomxHash[i] & 0xff); + } - printf("\n"); + printf("\n"); + } // Use randomx hash to build a valid block std::function)> validBlock = @@ -1254,23 +1266,25 @@ void static RandomXMiner() (std::vector soln) { int32_t z; arith_uint256 h; CBlock B; // Write the solution to the hash and compute the result. - fprintf(stderr,"RandomXMiner: Checking solution against target\n"); + rxdebug("%s: Checking solution against target\n"); pblock->nSolution = soln; solutionTargetChecks.increment(); B = *pblock; h = UintToArith256(B.GetHash()); - fprintf(stderr,"RandomXMiner: h="); - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&h)[z]); - fprintf(stderr," , hashTarget="); - for (z=31; z>=0; z--) - fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); - fprintf(stderr,"\n"); + rxdebug("%s: h="); + if (fRandomXDebug) { + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&h)[z]); + fprintf(stderr," , hashTarget="); + for (z=31; z>=0; z--) + fprintf(stderr,"%02x",((uint8_t *)&hashTarget)[z]); + fprintf(stderr,"\n"); + } if ( h > hashTarget ) { - fprintf(stderr,"RandomXMiner: h > hashTarget"); + rxdebug("%s: h > hashTarget"); return false; } @@ -1316,12 +1330,12 @@ void static RandomXMiner() std::vector sol_char(randomxHash, randomxHash+32); bool found = validBlock(sol_char); if (found) { - fprintf(stderr,"RandomXMiner: found solution!\n"); + rxdebug("%s: found solution!\n"); // If we find a POW solution, do not try other solutions // because they become invalid as we created a new block in blockchain. break; } else { - fprintf(stderr,"RandomXMiner: solution not found, validBlock=false\n"); + rxdebug("%s: solution not found, validBlock=false\n"); } } catch (RandomXSolverCanceledException&) { LogPrintf("HushRandomXMiner solver canceled\n"); diff --git a/src/util.cpp b/src/util.cpp index a2de3bb7d..ed894a37f 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -119,6 +119,7 @@ using namespace std; map mapArgs; map > mapMultiArgs; bool fDebug = false; +bool fRandomXDebug = false; bool fZdebug = false; bool fPrintToConsole = false; bool fPrintToDebugLog = true; diff --git a/src/util.h b/src/util.h index 7dd63b5bb..c7898c179 100644 --- a/src/util.h +++ b/src/util.h @@ -58,6 +58,7 @@ public: extern std::map mapArgs; extern std::map > mapMultiArgs; extern bool fDebug; +extern bool fRandomXDebug; extern bool fZdebug; extern bool fPrintToConsole; extern bool fPrintToDebugLog; diff --git a/test_randomx b/test_randomx index bba394f6b..df45890d8 100755 --- a/test_randomx +++ b/test_randomx @@ -1,6 +1,8 @@ #!/bin/bash - ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX10 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 +# any CLI args given to this script will be passed along +# example: ./test_randomx -debug=randomx + ./src/hushd -ac_randomx_interval=10 -ac_randomx_lag=3 -ac_halving=20 -ac_algo=randomx -ac_name=RANDOMX10 -ac_private=1 -ac_blocktime=20 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 $@ # to run via the debugger # type "run" when gdb prompt appears From b956945509be09917a34816ad22b1f221dc19887 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Tue, 12 Jul 2022 16:29:30 -0400 Subject: [PATCH 098/255] fixed utfcpp to use Hush gitea copy --- depends/packages/utfcpp.mk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/depends/packages/utfcpp.mk b/depends/packages/utfcpp.mk index 623f6a592..df000166c 100644 --- a/depends/packages/utfcpp.mk +++ b/depends/packages/utfcpp.mk @@ -1,8 +1,8 @@ $(package)_version=3.1 -$(package)_download_path=https://git.hush.is/jahway603/$(package)/archive +$(package)_download_path=https://git.hush.is/hush/$(package)/archive $(package)_file_name=$(package)-$($(package)_version).tar.gz $(package)_download_file=v$($(package)_version).tar.gz -$(package)_sha256_hash=eb4d5b9843a8411a20da8d011983e5351bf6c5893814f6756de8a31392185a98 +$(package)_sha256_hash=ab531c3fd5d275150430bfaca01d7d15e017a188183be932322f2f651506b096 define $(package)_stage_cmds cp -a ./source $($(package)_staging_dir)$(host_prefix)/include From f55b77f65282a50e42922eff7c27daa4f10d28bd Mon Sep 17 00:00:00 2001 From: jahway603 Date: Tue, 12 Jul 2022 17:19:00 -0400 Subject: [PATCH 099/255] changed algo N & K to equihash N & K --- src/rpc/misc.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 50dd62090..5d01384fb 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -349,15 +349,15 @@ UniValue getinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) obj.push_back(Pair("commission", ASSETCHAINS_COMMISSION)); if ( ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) { - obj.push_back(Pair("algo",ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO])); + obj.push_back(Pair("algo", ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO])); if ( ASSETCHAINS_NK[0] == 0 ) // display default for Hush - obj.push_back(Pair("algo N",200)); - else obj.push_back(Pair("algo N",ASSETCHAINS_NK[0])); + obj.push_back(Pair("equihash N", 200)); + else obj.push_back(Pair("equihash N", ASSETCHAINS_NK[0])); if ( ASSETCHAINS_NK[1] == 0 ) // display default for Hush - obj.push_back(Pair("algo K",9)); - else obj.push_back(Pair("algo K",ASSETCHAINS_NK[1])); + obj.push_back(Pair("equihash K", 9)); + else obj.push_back(Pair("equihash K", ASSETCHAINS_NK[1])); } - else obj.push_back(Pair("algo",ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO])); + else obj.push_back(Pair("algo", ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO])); } return obj; } From 398db65c0e00cc637c7c3ede6e714f23ec5aec2a Mon Sep 17 00:00:00 2001 From: jahway603 Date: Tue, 12 Jul 2022 18:26:05 -0400 Subject: [PATCH 100/255] NOW using special gitea file --- depends/packages/utfcpp.mk | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/depends/packages/utfcpp.mk b/depends/packages/utfcpp.mk index df000166c..f031b46a5 100644 --- a/depends/packages/utfcpp.mk +++ b/depends/packages/utfcpp.mk @@ -1,7 +1,7 @@ $(package)_version=3.1 -$(package)_download_path=https://git.hush.is/hush/$(package)/archive -$(package)_file_name=$(package)-$($(package)_version).tar.gz -$(package)_download_file=v$($(package)_version).tar.gz +$(package)_download_path=https://git.hush.is/attachments +$(package)_file_name=11822fe4-3846-4ce4-9c84-ba0877a7b186 +$(package)_download_file=11822fe4-3846-4ce4-9c84-ba0877a7b186 $(package)_sha256_hash=ab531c3fd5d275150430bfaca01d7d15e017a188183be932322f2f651506b096 define $(package)_stage_cmds From 9bd41875d7240a733359254b422f393f5b03f596 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 12 Jul 2022 23:20:57 -0400 Subject: [PATCH 101/255] Return getinfo algo as a single key --- src/rpc/misc.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 5d01384fb..cd8ee74b2 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -347,17 +347,14 @@ UniValue getinfo(const UniValue& params, bool fHelp, const CPubKey& mypk) if ( ASSETCHAINS_COMMISSION != 0 ) obj.push_back(Pair("commission", ASSETCHAINS_COMMISSION)); - if ( ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) - { + if ( ASSETCHAINS_ALGO == ASSETCHAINS_EQUIHASH ) { + uint64_t N = ASSETCHAINS_NK[0] ? ASSETCHAINS_NK[0] : 200; + uint64_t K = ASSETCHAINS_NK[1] ? ASSETCHAINS_NK[1] : 9; + std::string equihash_algo = "equihash (" + std::to_string(N) + "," + std::to_string(K) + ")"; + obj.push_back(Pair("algo",equihash_algo)); + } else { obj.push_back(Pair("algo", ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO])); - if ( ASSETCHAINS_NK[0] == 0 ) // display default for Hush - obj.push_back(Pair("equihash N", 200)); - else obj.push_back(Pair("equihash N", ASSETCHAINS_NK[0])); - if ( ASSETCHAINS_NK[1] == 0 ) // display default for Hush - obj.push_back(Pair("equihash K", 9)); - else obj.push_back(Pair("equihash K", ASSETCHAINS_NK[1])); - } - else obj.push_back(Pair("algo", ASSETCHAINS_ALGORITHMS[ASSETCHAINS_ALGO])); + } } return obj; } From a3258de21769939d34b241fb6fe6ae97f53de06c Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 12 Jul 2022 23:29:36 -0400 Subject: [PATCH 102/255] less debug by default from IsInitialBlockDownload --- src/main.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 627a99f90..b8e64dc27 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2405,7 +2405,9 @@ bool IsInitialBlockDownload() LogPrintf("Leaving InitialBlockDownload (latching to false)\n"); latchToFalse.store(true, std::memory_order_relaxed); } else { - fprintf(stderr,"%s: state.%d ht.%d vs %d, t.%u\n",__func__, state,(int32_t)chainActive.Height(),(uint32_t)ptr->GetHeight(),(int32_t)ptr->GetBlockTime()); + if (fDebug) { + fprintf(stderr,"%s: state.%d ht.%d vs %d, t.%u\n",__func__, state,(int32_t)chainActive.Height(),(uint32_t)ptr->GetHeight(),(int32_t)ptr->GetBlockTime()); + } } return state; } From 9806119366b0f6cf8940d531014a601d9bef19c0 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Wed, 13 Jul 2022 01:04:03 -0400 Subject: [PATCH 103/255] optimized IsBanned() --- src/net.cpp | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/net.cpp b/src/net.cpp index ef029025b..db47d5ec7 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -547,35 +547,29 @@ void CNode::ClearBanned() bool CNode::IsBanned(CNetAddr ip) { - bool fResult = false; + LOCK(cs_setBanned); + for (std::map::iterator it = setBanned.begin(); it != setBanned.end(); it++) { - LOCK(cs_setBanned); - for (std::map::iterator it = setBanned.begin(); it != setBanned.end(); it++) - { - CSubNet subNet = (*it).first; - int64_t t = (*it).second; + CSubNet subNet = (*it).first; + int64_t t = (*it).second; - if(subNet.Match(ip) && GetTime() < t) - fResult = true; - } + if(subNet.Match(ip) && GetTime() < t) + return true; } - return fResult; + return false; } bool CNode::IsBanned(CSubNet subnet) { - bool fResult = false; + LOCK(cs_setBanned); + std::map::iterator i = setBanned.find(subnet); + if (i != setBanned.end()) { - LOCK(cs_setBanned); - std::map::iterator i = setBanned.find(subnet); - if (i != setBanned.end()) - { - int64_t t = (*i).second; - if (GetTime() < t) - fResult = true; - } + int64_t t = (*i).second; + if (GetTime() < t) + return true; } - return fResult; + return false; } void CNode::Ban(const CNetAddr& addr, int64_t bantimeoffset, bool sinceUnixEpoch) { From ff37b7a1ecd58b83190d68ff1ea2ee64e2f1e539 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Fri, 15 Jul 2022 11:43:05 -0400 Subject: [PATCH 104/255] update build.sh and CONTRIBUTING.md --- CONTRIBUTING.md | 4 ++-- INSTALL.md | 2 +- zcutil/build.sh | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3a2b1e08a..5866ab2e3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -37,7 +37,7 @@ Before we get started, here are a few things we expect from you (and that you sh ## How to contribute -If you'd like to contribute, start by searching through the [issues](https://github.com/MyHush/hush3/issues) and [pull requests](https://github.com/MyHush/hush3/pulls) to see whether someone else has raised a similar idea or question. +If you'd like to contribute, start by searching through the [issues](https://git.hush.is/hush/hush3/issues) and [pull requests](https://git.hush.is/hush/hush3/pulls) to see whether someone else has raised a similar idea or question. If you don't see your idea listed, and you think it can contribute to Hush, do one of the following: * **If your contribution is minor,** such as a fixing a typo, open a pull request. @@ -49,7 +49,7 @@ Don't write shitty code. Do not emulate "jl777 code style" from Komodo, we consi ## Setting up your environment -The Hush Core (hushd) is mainly written in C++ with specific modules written in C. Follow the [Install](https://github.com/MyHush/hush3/blob/master/INSTALL.md) instructions to build hushd from sources. For more informations about the Hush Platform and a full API documentation please visit the official [Hush Developer documentation](https://gilardh.github.io/dev-website/developers/) +The Hush Core (hushd) is mainly written in C++ with specific modules written in C. Follow the [Install](https://git.hush.is/hush/hush3/src/branch/master/INSTALL.md) instructions to build hushd from sources. For more informations about the Hush Platform and a full API documentation please visit the official [Hush Developer documentation](https://faq.hush.is/rpc/) Other Hush software is written in Rust or Go. We avoid Javascript at all costs. diff --git a/INSTALL.md b/INSTALL.md index 114ef1775..ad81f40b9 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -25,7 +25,7 @@ sudo swapon /swapfile # install build dependencies sudo apt-get install build-essential pkg-config libc6-dev m4 g++-multilib \ autoconf libtool ncurses-dev unzip git python zlib1g-dev wget \ - bsdmainutils automake curl unzip nano libsodium-dev + bsdmainutils automake curl unzip nano libsodium-dev cmake # clone git repo git clone https://git.hush.is/hush/hush3 cd hush3 diff --git a/zcutil/build.sh b/zcutil/build.sh index a5ecda2ca..42f4196b3 100755 --- a/zcutil/build.sh +++ b/zcutil/build.sh @@ -5,6 +5,12 @@ set -eu -o pipefail +# Check if cmake, a new dependency for randomx support, is installed on system and exits if it is not +if ! [ -x "$(command -v cmake)" ]; then + echo 'Error: cmake is not installed. Install cmake and try again.' >&2 + exit 1 +fi + function cmd_pref() { if type -p "$2" > /dev/null; then eval "$1=$2" From b6ee6ba57e4c1ad9961cedade9cff38adbb4f16c Mon Sep 17 00:00:00 2001 From: jahway603 Date: Fri, 15 Jul 2022 12:58:29 -0400 Subject: [PATCH 105/255] changed libsodium to gitea hosted version --- depends/packages/libsodium.mk | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/depends/packages/libsodium.mk b/depends/packages/libsodium.mk index 0be8e1676..2d930c4ae 100644 --- a/depends/packages/libsodium.mk +++ b/depends/packages/libsodium.mk @@ -1,7 +1,8 @@ package=libsodium $(package)_version=1.0.18 -$(package)_download_path=https://github.com/MyHush/libsodium/releases/download/$($(package)_version)/ -$(package)_file_name=$(package)-$($(package)_version).tar.gz +$(package)_download_path=https://git.hush.is/attachments +$(package)_file_name=0d9f589e-a9f9-4ddb-acaa-0f1b423b32eb +$(package)_download_file=0d9f589e-a9f9-4ddb-acaa-0f1b423b32eb $(package)_sha256_hash=6f504490b342a4f8a4c4a02fc9b866cbef8622d5df4e5452b46be121e46636c1 $(package)_dependencies= $(package)_config_opts= From 2efa9652e2d35f5bb2d1c6fe20d0f61e86715504 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Fri, 15 Jul 2022 22:21:41 -0400 Subject: [PATCH 106/255] fixed spacing in manpages --- doc/man/hush-cli.1 | 3 +++ doc/man/hush-tx.1 | 3 +++ doc/man/hushd.1 | 3 +++ 3 files changed, 9 insertions(+) diff --git a/doc/man/hush-cli.1 b/doc/man/hush-cli.1 index 6179f7d95..8f7861dbf 100644 --- a/doc/man/hush-cli.1 +++ b/doc/man/hush-cli.1 @@ -76,8 +76,11 @@ In order to ensure you are adequately protecting your privacy when using Hush, please see . Copyright (C) 2016-2021 Duke Leto and The Hush Developers + Copyright (C) 2016-2020 jl777 and SuperNET developers + Copyright (C) 2016-2018 The Zcash developers + Copyright (C) 2009-2014 The Bitcoin Core developers This is experimental Free Software! Fuck Yeah!!!!! diff --git a/doc/man/hush-tx.1 b/doc/man/hush-tx.1 index 54149df40..7b1124b70 100644 --- a/doc/man/hush-tx.1 +++ b/doc/man/hush-tx.1 @@ -89,8 +89,11 @@ In order to ensure you are adequately protecting your privacy when using Hush, please see . Copyright (C) 2016-2021 Duke Leto and The Hush Developers + Copyright (C) 2016-2020 jl777 and SuperNET developers + Copyright (C) 2016-2018 The Zcash developers + Copyright (C) 2009-2014 The Bitcoin Core developers This is experimental Free Software! Fuck Yeah!!!!! diff --git a/doc/man/hushd.1 b/doc/man/hushd.1 index f5c1dd68e..539f544be 100644 --- a/doc/man/hushd.1 +++ b/doc/man/hushd.1 @@ -713,8 +713,11 @@ In order to ensure you are adequately protecting your privacy when using Hush, please see . Copyright (C) 2016-2021 Duke Leto and The Hush Developers + Copyright (C) 2016-2020 jl777 and SuperNET developers + Copyright (C) 2016-2018 The Zcash developers + Copyright (C) 2009-2014 The Bitcoin Core developers This is experimental Free Software! Fuck Yeah!!!!! From afd3f93e2ead442a43818508bdd4cbdcbefc3e4d Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 18 Jul 2022 10:43:22 -0400 Subject: [PATCH 107/255] Throw error in wallet if ReadBlockFromDisk fails --- src/wallet/wallet.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8d12d903a..bda0140f0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1032,7 +1032,10 @@ int CWallet::VerifyAndSetInitialWitness(const CBlockIndex* pindex, bool witnessO //Cycle through blocks and transactions building sapling tree until the commitment needed is reached const CBlock* pblock; CBlock block; - ReadBlockFromDisk(block, pblockindex, 1); + if (!ReadBlockFromDisk(block, pblockindex, 1)) { + throw std::runtime_error( + strprintf("Cannot read block height %d (%s) from disk", pindex->GetHeight(), pindex->GetBlockHash().GetHex())); + } pblock = █ for (const CTransaction& tx : block.vtx) { @@ -1102,7 +1105,10 @@ void CWallet::BuildWitnessCache(const CBlockIndex* pindex, bool witnessOnly) //Cycle through blocks and transactions building sapling tree until the commitment needed is reached CBlock block; - ReadBlockFromDisk(block, pblockindex, 1); + if (!ReadBlockFromDisk(block, pblockindex, 1)) { + throw std::runtime_error( + strprintf("Cannot read block height %d (%s) from disk", pindex->GetHeight(), pindex->GetBlockHash().GetHex())); + } for (std::pair& wtxItem : mapWallet) { @@ -2721,7 +2727,11 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) CBlock block; bool involvesMe = false; - ReadBlockFromDisk(block, pindex,1); + if (!ReadBlockFromDisk(block, pindex,1)) { + throw std::runtime_error( + strprintf("Cannot read block height %d (%s) from disk", pindex->GetHeight(), pindex->GetBlockHash().GetHex())); + } + BOOST_FOREACH(CTransaction& tx, block.vtx) { if (AddToWalletIfInvolvingMe(tx, &block, fUpdate)) { From c6e5b07a5906893bcf996ab4032e96a8882ac6c7 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 24 Aug 2022 23:38:19 -0400 Subject: [PATCH 108/255] You might be a king or a little street zsweeper, but sooner or later you will dance with the reaper --- src/Makefile.am | 2 + src/base58.cpp | 1 + src/compressor.cpp | 1 + src/consensus/upgrades.h | 7 ++- src/consensus/validation.h | 1 + src/core_read.cpp | 1 + src/core_write.cpp | 1 + src/fs.cpp | 1 + src/importcoin.cpp | 3 + src/init.cpp | 58 +++++++++++++++++++ src/key.cpp | 1 + src/merkleblock.cpp | 1 + src/noui.cpp | 1 + src/scheduler.cpp | 1 + src/transaction_builder.cpp | 5 ++ src/transaction_builder.h | 1 + src/uint256.cpp | 3 +- src/utilstrencodings.cpp | 1 + src/utiltime.cpp | 1 + ...asyncrpcoperation_saplingconsolidation.cpp | 4 +- src/wallet/wallet.cpp | 47 ++++++++++++++- src/wallet/wallet.h | 13 ++++- 22 files changed, 146 insertions(+), 9 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 5d73c049f..76f99f00c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -231,6 +231,7 @@ BITCOIN_CORE_H = \ version.h \ wallet/asyncrpcoperation_mergetoaddress.h \ wallet/asyncrpcoperation_saplingconsolidation.h \ + wallet/asyncrpcoperation_sweep.h \ wallet/asyncrpcoperation_sendmany.h \ wallet/asyncrpcoperation_shieldcoinbase.h \ wallet/crypter.h \ @@ -344,6 +345,7 @@ libbitcoin_wallet_a_SOURCES = \ zcbenchmarks.h \ wallet/asyncrpcoperation_mergetoaddress.cpp \ wallet/asyncrpcoperation_saplingconsolidation.cpp \ + wallet/asyncrpcoperation_sweep.cpp \ wallet/asyncrpcoperation_sendmany.cpp \ wallet/asyncrpcoperation_shieldcoinbase.cpp \ wallet/crypter.cpp \ diff --git a/src/base58.cpp b/src/base58.cpp index d46894ea0..f1ca396ab 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2021 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/compressor.cpp b/src/compressor.cpp index ae7fe02ba..b55313486 100644 --- a/src/compressor.cpp +++ b/src/compressor.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2021 The Hush developers // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/consensus/upgrades.h b/src/consensus/upgrades.h index 7a72e798b..278c3e462 100644 --- a/src/consensus/upgrades.h +++ b/src/consensus/upgrades.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2018 The Zcash developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html @@ -17,8 +18,8 @@ * * ******************************************************************************/ -#ifndef ZCASH_CONSENSUS_UPGRADES_H -#define ZCASH_CONSENSUS_UPGRADES_H +#ifndef HUSH_CONSENSUS_UPGRADES_H +#define HUSH_CONSENSUS_UPGRADES_H #include "consensus/params.h" @@ -114,4 +115,4 @@ boost::optional NextActivationHeight( int nHeight, const Consensus::Params& params); -#endif // ZCASH_CONSENSUS_UPGRADES_H +#endif // HUSH_CONSENSUS_UPGRADES_H diff --git a/src/consensus/validation.h b/src/consensus/validation.h index edf38e294..848018728 100644 --- a/src/consensus/validation.h +++ b/src/consensus/validation.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/core_read.cpp b/src/core_read.cpp index 679d221f4..d092f6624 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2021 The Hush developers // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/core_write.cpp b/src/core_write.cpp index bb996c700..67953e2fa 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2021 The Hush developers // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/fs.cpp b/src/fs.cpp index a5e12f1cf..0c6a60014 100644 --- a/src/fs.cpp +++ b/src/fs.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2021 The Hush developers #include "fs.h" namespace fsbridge { diff --git a/src/importcoin.cpp b/src/importcoin.cpp index 16a8d3c64..f6da631c7 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -1,3 +1,6 @@ +// Copyright (c) 2016-2021 The Hush developers +// Distributed under the GPLv3 software license, see the accompanying +// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * diff --git a/src/init.cpp b/src/init.cpp index e057282be..dd6666710 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -59,6 +59,7 @@ #include "wallet/wallet.h" #include "wallet/walletdb.h" #include "wallet/asyncrpcoperation_saplingconsolidation.h" +#include "wallet/asyncrpcoperation_sweep.h" #endif #include #include @@ -461,6 +462,16 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-consolidation", _("Enable auto Sapling note consolidation (default: false)")); strUsage += HelpMessageOpt("-consolidatesaplingaddress=", _("Specify Sapling Address to Consolidate. (default: all)")); strUsage += HelpMessageOpt("-consolidationtxfee", strprintf(_("Fee amount in Puposhis used send consolidation transactions. (default %i)"), DEFAULT_CONSOLIDATION_FEE)); + + strUsage += HelpMessageOpt("-zsweep", _("Enable zaddr sweeping, automatically move all shielded funds to a one address once per X blocks")); + strUsage += HelpMessageOpt("-zsweepaddress=", _("Specify the shielded address where swept funds will be sent)")); + strUsage += HelpMessageOpt("-zsweepfee", strprintf(_("Fee amount in puposhis used send sweep transactions. (default %i)"), DEFAULT_SWEEP_FEE)); + strUsage += HelpMessageOpt("-zsweepinterval", strprintf(_("Sweep shielded funds every X blocks (default %i)"), 5)); + strUsage += HelpMessageOpt("-zsweepmaxinputs", strprintf(_("Maximum number of shielded inputs to sweep per transaction (default %i)"), 8)); + // By default we only allow sweeping to the current wallet which must have the spending key of the sweep zaddr + // This hopefully will make it harder for people to accidentally sweep funds to a wrong zaddr and lose funds + strUsage += HelpMessageOpt("-zsweepexternal", _("Enable sweeping to an external wallet (default false)")); + strUsage += HelpMessageOpt("-deletetx", _("Enable Old Transaction Deletion")); strUsage += HelpMessageOpt("-deleteinterval", strprintf(_("Delete transaction every blocks during inital block download (default: %i)"), DEFAULT_TX_DELETE_INTERVAL)); strUsage += HelpMessageOpt("-keeptxnum", strprintf(_("Keep the last transactions (default: %i)"), DEFAULT_TX_RETENTION_LASTTX)); @@ -2054,6 +2065,53 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) } } + //Set Sweep + pwalletMain->fSweepEnabled = GetBoolArg("-zsweep", false); + + if (pwalletMain->fSweepEnabled) { + fSweepTxFee = GetArg("-zsweepfee", DEFAULT_SWEEP_FEE); + fSweepMapUsed = !mapMultiArgs["-zsweepaddress"].empty(); + + //Validate Sapling Addresses + vector& vSweep = mapMultiArgs["-zsweepaddress"]; + if (vSweep.size() != 1) { + return InitError("A single zsweep address must be specified."); + } + + for (int i = 0; i < vSweep.size(); i++) { + // LogPrintf("Sweep Address: %s\n", vSweep[i]); + auto zSweep = DecodePaymentAddress(vSweep[i]); + if (!IsValidPaymentAddress(zSweep)) { + return InitError("Invalid zsweep address"); + } + auto hasSpendingKey = boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), zSweep); + auto allowSweepToExternalWallet = GetArg("-zsweepexternal", false); + + if (!hasSpendingKey) { + if (allowSweepToExternalWallet) { + LogPrintf("%s: sweeping funds to a zaddr in an external wallet\n", __func__); + } else { + return InitError("Wallet must have the spending key of zsweep address"); + } + } + } + + if (pwalletMain->fSaplingConsolidationEnabled) { + //Validate 1 Consolidation address only that matches the sweep address + vector& vaddresses = mapMultiArgs["-consolidatesaplingaddress"]; + if (vaddresses.size() == 0) { + fConsolidationMapUsed = true; + mapMultiArgs["-consolidatesaplingaddress"] = vSweep; + } else { + for (int i = 0; i < vaddresses.size(); i++) { + if (vSweep[0] != vaddresses[i]) { + return InitError("Consolidation can only be used on the sweep address when sweep is enabled."); + } + } + } + } + } + //Set Transaction Deletion Options fTxDeleteEnabled = GetBoolArg("-deletetx", false); fTxConflictDeleteEnabled = GetBoolArg("-deleteconflicttx", true); diff --git a/src/key.cpp b/src/key.cpp index 70ade77fb..83f831ada 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2021 The Hush developers // Copyright (c) 2009-2014 The Bitcoin Core developers // Copyright (c) 2017 The Zcash developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/merkleblock.cpp b/src/merkleblock.cpp index c12552f78..86df55cac 100644 --- a/src/merkleblock.cpp +++ b/src/merkleblock.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2021 The Hush developers // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/noui.cpp b/src/noui.cpp index 7a838d0bd..e0bd76e4d 100644 --- a/src/noui.cpp +++ b/src/noui.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2021 The Hush developers // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/scheduler.cpp b/src/scheduler.cpp index c243ca308..9c4ebf334 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2021 The Hush developers // Copyright (c) 2015 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/transaction_builder.cpp b/src/transaction_builder.cpp index 3ff6269b2..0dfd5a299 100644 --- a/src/transaction_builder.cpp +++ b/src/transaction_builder.cpp @@ -104,6 +104,11 @@ bool TransactionBuilder::AddOpRetLast() return true; } +void TransactionBuilder::SetExpiryHeight(int nHeight) +{ + this->mtx.nExpiryHeight = nHeight; +} + void TransactionBuilder::AddOpRet(CScript &s) { opReturn.emplace(CScript(s)); diff --git a/src/transaction_builder.h b/src/transaction_builder.h index 89a8d6580..6c4d20302 100644 --- a/src/transaction_builder.h +++ b/src/transaction_builder.h @@ -77,6 +77,7 @@ public: TransactionBuilder(const Consensus::Params& consensusParams, int nHeight, CKeyStore* keyStore = nullptr); void SetFee(CAmount fee); + void SetExpiryHeight(int nHeight); // Returns false if the anchor does not match the anchor used by // previously-added Sapling spends. diff --git a/src/uint256.cpp b/src/uint256.cpp index 4883ac50b..97c0cb007 100644 --- a/src/uint256.cpp +++ b/src/uint256.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2021 The Hush developers // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying @@ -19,9 +20,7 @@ ******************************************************************************/ #include "uint256.h" - #include "utilstrencodings.h" - #include #include diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp index 665f9bead..4a2815968 100644 --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2021 The Hush developers // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/utiltime.cpp b/src/utiltime.cpp index aba3823ca..bc5e3d69c 100644 --- a/src/utiltime.cpp +++ b/src/utiltime.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2021 The Hush developers // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index 2594fb4ce..361d04390 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -159,7 +159,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { amountConsolidated += amountToSend; auto builder = TransactionBuilder(consensusParams, targetHeight_, pwalletMain); - //builder.SetExpiryHeight(targetHeight_ + CONSOLIDATION_EXPIRY_DELTA); + builder.SetExpiryHeight(targetHeight_ + CONSOLIDATION_EXPIRY_DELTA); auto actualAmountToSend = amountToSend < fConsolidationTxFee ? 0 : amountToSend - fConsolidationTxFee; LogPrintf("%s: %s Beginning to create transaction with Sapling output amount=%s\n", __func__, opid, FormatMoney(actualAmountToSend)); @@ -235,7 +235,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { break; } - if(pwalletMain->CommitConsolidationTx(tx)) { + if(pwalletMain->CommitAutomatedTx(tx)) { LogPrint("zrpcunsafe", "%s: Committed consolidation transaction with txid=%s\n",opid, tx.GetHash().ToString()); amountConsolidated += actualAmountToSend; consolidationTxIds.push_back(tx.GetHash().ToString()); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index bda0140f0..83f95cbb3 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -38,6 +38,7 @@ #include "crypter.h" #include "coins.h" #include "wallet/asyncrpcoperation_saplingconsolidation.h" +#include "wallet/asyncrpcoperation_sweep.h" #include "zcash/zip32.h" #include "cc/CCinclude.h" #include @@ -483,6 +484,9 @@ void CWallet::ChainTip(const CBlockIndex *pindex, if (fSaplingConsolidationEnabled) { RunSaplingConsolidation(pindex->GetHeight()); } + if (fSweepEnabled) { + RunSaplingSweep(pindex->GetHeight()); + } if (fTxDeleteEnabled) { DeleteWalletTransactions(pindex); } @@ -501,6 +505,43 @@ void CWallet::ChainTip(const CBlockIndex *pindex, } } +void CWallet::RunSaplingSweep(int blockHeight) { + // Sapling is always active since height=1 of HUSH+HSCs + // if (!NetworkUpgradeActive(blockHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) { + // return; + // } + AssertLockHeld(cs_wallet); + if (!fSweepEnabled) { + return; + } + + if (nextSweep > blockHeight) { + return; + } + + //Don't Run if consolidation will run soon. + if (fSaplingConsolidationEnabled && nextConsolidation - 15 <= blockHeight) { + return; + } + + //Don't Run While consolidation is running. + if (fConsolidationRunning) { + return; + } + + fSweepRunning = true; + + std::shared_ptr q = getAsyncRPCQueue(); + std::shared_ptr lastOperation = q->getOperationForId(saplingSweepOperationId); + if (lastOperation != nullptr) { + lastOperation->cancel(); + } + pendingSaplingSweepTxs.clear(); + std::shared_ptr operation(new AsyncRPCOperation_sweep(blockHeight + 5)); + saplingSweepOperationId = operation->getId(); + q->addOperation(operation); +} + void CWallet::RunSaplingConsolidation(int blockHeight) { if (!NetworkUpgradeActive(blockHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) { return; @@ -512,6 +553,10 @@ void CWallet::RunSaplingConsolidation(int blockHeight) { return; } + if (fSweepRunning) { + return; + } + int consolidateInterval = rand() % 5 + 5; if(fZdebug) @@ -530,7 +575,7 @@ void CWallet::RunSaplingConsolidation(int blockHeight) { } } -bool CWallet::CommitConsolidationTx(const CTransaction& tx) { +bool CWallet::CommitAutomatedTx(const CTransaction& tx) { CWalletTx wtx(this, tx); CReserveKey reservekey(pwalletMain); fprintf(stderr,"%s: %s\n",__func__,tx.ToString().c_str()); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 15be2072d..f633f2564 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -785,6 +785,9 @@ private: std::vector pendingSaplingConsolidationTxs; AsyncRPCOperationId saplingConsolidationOperationId; + std::vector pendingSaplingSweepTxs; + AsyncRPCOperationId saplingSweepOperationId; + void AddToTransparentSpends(const COutPoint& outpoint, const uint256& wtxid); void AddToSaplingSpends(const uint256& nullifier, const uint256& wtxid); void AddToSpends(const uint256& wtxid); @@ -797,7 +800,13 @@ public: */ int64_t nWitnessCacheSize; bool needsRescan = false; + int nextConsolidation = 0; + bool fSaplingConsolidationEnabled = false; + bool fConsolidationRunning = false; + bool fSweepEnabled = false; + bool fSweepRunning = false; + int nextSweep = 0; void ClearNoteWitnessCache(); @@ -1181,12 +1190,14 @@ public: CAmount GetCredit(const CTransaction& tx, int32_t voutNum, const isminefilter& filter) const; CAmount GetCredit(const CTransaction& tx, const isminefilter& filter) const; CAmount GetChange(const CTransaction& tx) const; + void RunSaplingSweep(int blockHeight); + void ChainTip( const CBlockIndex *pindex, const CBlock *pblock, boost::optional> added); void RunSaplingConsolidation(int blockHeight); - bool CommitConsolidationTx(const CTransaction& tx); + bool CommitAutomatedTx(const CTransaction& tx); /** Saves witness caches and best block locator to disk. */ void SetBestChain(const CBlockLocator& loc); std::set> GetNullifiersForAddresses(const std::set & addresses); From 02ef7149011d9b221f58585dd00747661b9cdf09 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 25 Aug 2022 09:26:10 -0400 Subject: [PATCH 109/255] Commit forgotten files --- src/wallet/asyncrpcoperation_sweep.cpp | 313 +++++++++++++++++++++++++ src/wallet/asyncrpcoperation_sweep.h | 42 ++++ 2 files changed, 355 insertions(+) create mode 100644 src/wallet/asyncrpcoperation_sweep.cpp create mode 100644 src/wallet/asyncrpcoperation_sweep.h diff --git a/src/wallet/asyncrpcoperation_sweep.cpp b/src/wallet/asyncrpcoperation_sweep.cpp new file mode 100644 index 000000000..140c9902a --- /dev/null +++ b/src/wallet/asyncrpcoperation_sweep.cpp @@ -0,0 +1,313 @@ +// Copyright (c) 2016-2022 The Hush developers +// Distributed under the GPLv3 software license, see the accompanying +// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html +#include "assert.h" +#include "boost/variant/static_visitor.hpp" +#include "asyncrpcoperation_sweep.h" +#include "init.h" +#include "key_io.h" +#include "rpc/protocol.h" +#include "random.h" +#include "sync.h" +#include "tinyformat.h" +#include "transaction_builder.h" +#include "util.h" +#include "utilmoneystr.h" +#include "wallet.h" + +extern string randomSietchZaddr(); + +CAmount fSweepTxFee = DEFAULT_SWEEP_FEE; +bool fSweepMapUsed = false; +const int SWEEP_EXPIRY_DELTA = 15; +boost::optional rpcSweepAddress; + +AsyncRPCOperation_sweep::AsyncRPCOperation_sweep(int targetHeight, bool fromRpc) : targetHeight_(targetHeight), fromRPC_(fromRpc){} + +AsyncRPCOperation_sweep::~AsyncRPCOperation_sweep() {} + +void AsyncRPCOperation_sweep::main() { + if (isCancelled()) + return; + + set_state(OperationStatus::EXECUTING); + start_execution_clock(); + + bool success = false; + + try { + success = main_impl(); + } catch (const UniValue& objError) { + int code = find_value(objError, "code").get_int(); + std::string message = find_value(objError, "message").get_str(); + set_error_code(code); + set_error_message(message); + } catch (const runtime_error& e) { + set_error_code(-1); + set_error_message("runtime error: " + string(e.what())); + } catch (const logic_error& e) { + set_error_code(-1); + set_error_message("logic error: " + string(e.what())); + } catch (const exception& e) { + set_error_code(-1); + set_error_message("general exception: " + string(e.what())); + } catch (...) { + set_error_code(-2); + set_error_message("unknown error"); + } + + stop_execution_clock(); + + if (success) { + set_state(OperationStatus::SUCCESS); + } else { + set_state(OperationStatus::FAILED); + } + + std::string s = strprintf("%s: Sapling Sweep transaction created. (status=%s", getId(), getStateAsString()); + if (success) { + s += strprintf(", success)\n"); + } else { + s += strprintf(", error=%s)\n", getErrorMessage()); + } + + LogPrintf("%s", s); +} + +bool AsyncRPCOperation_sweep::main_impl() { + LogPrint("zrpcunsafe", "%s: Beginning asyncrpcoperation_sweep.\n", getId()); + auto consensusParams = Params().GetConsensus(); + auto nextActivationHeight = NextActivationHeight(targetHeight_, consensusParams); + if (nextActivationHeight && targetHeight_ + SWEEP_EXPIRY_DELTA >= nextActivationHeight.get()) { + LogPrint("zrpcunsafe", "%s: Sweep txs would be created before a NU activation but may expire after. Skipping this round.\n", getId()); + setSweepResult(0, 0, std::vector()); + return true; + } + + std::vector saplingEntries; + libzcash::SaplingPaymentAddress sweepAddress; + std::map> mapAddresses; + + { + LOCK2(cs_main, pwalletMain->cs_wallet); + pwalletMain->GetFilteredNotes(saplingEntries, "", 11); + if (!fromRPC_) { + if (fSweepMapUsed) { + const vector& v = mapMultiArgs["-zsweepaddress"]; + for(int i = 0; i < v.size(); i++) { + auto zAddress = DecodePaymentAddress(v[i]); + if (boost::get(&zAddress) != nullptr) { + sweepAddress = boost::get(zAddress); + } + } + } else { + return false; + } + } else { + if (boost::get(&rpcSweepAddress) != nullptr) { + sweepAddress = boost::get(rpcSweepAddress); + } else { + return false; + } + } + + for (auto & entry : saplingEntries) { + //Map all notes by address + if (sweepAddress == entry.address) { + continue; + } else { + std::map>::iterator it; + it = mapAddresses.find(entry.address); + if (it != mapAddresses.end()) { + it->second.push_back(entry); + } else { + std::vector entries; + entries.push_back(entry); + mapAddresses[entry.address] = entries; + } + } + } + } + + int numTxCreated = 0; + std::vector sweepTxIds; + CAmount amountSwept = 0; + CCoinsViewCache coinsView(pcoinsTip); + bool sweepComplete = true; + + for (std::map>::iterator it = mapAddresses.begin(); it != mapAddresses.end(); it++) { + auto addr = (*it).first; + auto saplingEntries = (*it).second; + + libzcash::SaplingExtendedSpendingKey extsk; + if (pwalletMain->GetSaplingExtendedSpendingKey(addr, extsk)) { + + std::vector fromNotes; + CAmount amountToSend = 0; + int maxInputs = GetArg("-zsweepmaxinputs", 8); + if( maxInputs > 100 || maxInputs < 5) { + fprintf(stderr,"%s: Invalid zsweep maxinputs=%d is >100 and <5, setting to default of 8\n", __func__, maxInputs); + maxInputs = 8; + } + + //Count Notes availiable for this address + int targetCount = 0; + int noteCount = 0; + for (const SaplingNoteEntry& saplingEntry : saplingEntries) { + + libzcash::SaplingIncomingViewingKey ivk; + pwalletMain->GetSaplingIncomingViewingKey(boost::get(saplingEntry.address), ivk); + + if (ivk == extsk.expsk.full_viewing_key().in_viewing_key() && saplingEntry.address == addr) { + noteCount++; + } + } + + //Don't sweep if under the threshold + if (noteCount <= targetCount){ + continue; + } + + //if we make it here then we need to sweep and the routine is considered incomplete + sweepComplete = false; + + for (const SaplingNoteEntry& saplingEntry : saplingEntries) { + + libzcash::SaplingIncomingViewingKey ivk; + pwalletMain->GetSaplingIncomingViewingKey(boost::get(saplingEntry.address), ivk); + + //Select Notes from that same address we will be sending to. + if (ivk == extsk.expsk.full_viewing_key().in_viewing_key() && saplingEntry.address == addr) { + amountToSend += CAmount(saplingEntry.note.value()); + fromNotes.push_back(saplingEntry); + } + + if (fromNotes.size() >= maxInputs) + break; + + } + + int minQuantity = 1; + if (fromNotes.size() < minQuantity) + continue; + + CAmount fee = fSweepTxFee; + if (amountToSend <= fSweepTxFee) { + fee = 0; + } + amountSwept += amountToSend; + auto builder = TransactionBuilder(consensusParams, targetHeight_, pwalletMain); + { + LOCK2(cs_main, pwalletMain->cs_wallet); + builder.SetExpiryHeight(chainActive.Tip()->GetHeight()+ SWEEP_EXPIRY_DELTA); + } + LogPrint("zrpcunsafe", "%s: Beginning creating transaction with Sapling output amount=%s\n", getId(), FormatMoney(amountToSend - fee)); + + // Select Sapling notes + std::vector ops; + std::vector notes; + for (auto fromNote : fromNotes) { + ops.push_back(fromNote.op); + notes.push_back(fromNote.note); + } + + // Fetch Sapling anchor and witnesses + uint256 anchor; + std::vector> witnesses; + { + LOCK2(cs_main, pwalletMain->cs_wallet); + pwalletMain->GetSaplingNoteWitnesses(ops, witnesses, anchor); + } + + // Add Sapling spends + for (size_t i = 0; i < notes.size(); i++) { + if (!witnesses[i]) { + LogPrint("zrpcunsafe", "%s: Missing Witnesses. Stopping.\n", getId()); + break; + } + builder.AddSaplingSpend(extsk.expsk, notes[i], anchor, witnesses[i].get()); + } + + builder.SetFee(fee); + builder.AddSaplingOutput(extsk.expsk.ovk, sweepAddress, amountToSend - fee); + + // Add sietch zouts + int ZOUTS = 7; + for(size_t i = 0; i < ZOUTS; i++) { + // In Privacy Zdust We Trust -- Duke + string zdust = randomSietchZaddr(); + auto zaddr = DecodePaymentAddress(zdust); + if (IsValidPaymentAddress(zaddr)) { + CAmount amount=0; + auto sietchZoutput = boost::get(zaddr); + LogPrint("zrpcunsafe", "%s: Adding Sietch zdust output %d\n", __func__, i); // %d %s amount=%li\n", __func__, i, zaddr, amount); + + builder.AddSaplingOutput(extsk.expsk.ovk, sietchZoutput, amount); + } else { + LogPrint("zrpcunsafe", "%s: Invalid payment address %s! Stopping.\n", __func__, zdust); + // status = false; + break; + } + } + LogPrint("zrpcunsafe", "%s: Done adding %d sietch zouts\n", __func__, ZOUTS); + + auto maybe_tx = builder.Build(); + if (!maybe_tx) { + LogPrint("zrpcunsafe", "%s: Failed to build transaction %s.\n",__func__, getId()); + // status=false; + break; + } + CTransaction tx = maybe_tx.get(); + + if (isCancelled()) { + LogPrint("zrpcunsafe", "%s: Canceled. Stopping.\n", getId()); + break; + } + + pwalletMain->CommitAutomatedTx(tx); + LogPrint("zrpcunsafe", "%s: Committed sweep transaction with txid=%s\n", getId(), tx.GetHash().ToString()); + amountSwept += amountToSend - fee; + sweepTxIds.push_back(tx.GetHash().ToString()); + + } + } + + if (sweepComplete) { + int sweepInterval = GetArg("-zsweepinterval", 5); + if (sweepInterval < 1) { + fprintf(stderr,"%s: Invalid sweep interval of %d, setting to default of 5\n", __func__, sweepInterval); + sweepInterval = 5; + } + pwalletMain->nextSweep = sweepInterval + chainActive.Tip()->GetHeight(); + pwalletMain->fSweepRunning = false; + } + + LogPrint("zrpcunsafe", "%s: Created %d transactions with total Sapling output amount=%s\n", getId(), numTxCreated, FormatMoney(amountSwept)); + setSweepResult(numTxCreated, amountSwept, sweepTxIds); + return true; + +} + +void AsyncRPCOperation_sweep::setSweepResult(int numTxCreated, const CAmount& amountSwept, const std::vector& sweepTxIds) { + UniValue res(UniValue::VOBJ); + res.push_back(Pair("num_tx_created", numTxCreated)); + res.push_back(Pair("amount_swept", FormatMoney(amountSwept))); + UniValue txIds(UniValue::VARR); + for (const std::string& txId : sweepTxIds) { + txIds.push_back(txId); + } + res.push_back(Pair("sweep_txids", txIds)); + set_result(res); +} + +void AsyncRPCOperation_sweep::cancel() { + set_state(OperationStatus::CANCELLED); +} + +UniValue AsyncRPCOperation_sweep::getStatus() const { + UniValue v = AsyncRPCOperation::getStatus(); + UniValue obj = v.get_obj(); + obj.push_back(Pair("method", "sweep")); + obj.push_back(Pair("target_height", targetHeight_)); + return obj; +} diff --git a/src/wallet/asyncrpcoperation_sweep.h b/src/wallet/asyncrpcoperation_sweep.h new file mode 100644 index 000000000..8927bf8a3 --- /dev/null +++ b/src/wallet/asyncrpcoperation_sweep.h @@ -0,0 +1,42 @@ +// Copyright (c) 2016-2022 The Hush developers +// Distributed under the GPLv3 software license, see the accompanying +// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html +#include "amount.h" +#include "asyncrpcoperation.h" +#include "univalue.h" +#include "zcash/Address.hpp" +#include "zcash/zip32.h" + +//Default fee used for sweep transactions +static const CAmount DEFAULT_SWEEP_FEE = 10000; +extern CAmount fSweepTxFee; +extern bool fSweepMapUsed; +extern boost::optional rpcSweepAddress; + +class AsyncRPCOperation_sweep : public AsyncRPCOperation +{ +public: + AsyncRPCOperation_sweep(int targetHeight, bool fromRpc = false); + virtual ~AsyncRPCOperation_sweep(); + + // We don't want to be copied or moved around + AsyncRPCOperation_sweep(AsyncRPCOperation_sweep const&) = delete; // Copy construct + AsyncRPCOperation_sweep(AsyncRPCOperation_sweep&&) = delete; // Move construct + AsyncRPCOperation_sweep& operator=(AsyncRPCOperation_sweep const&) = delete; // Copy assign + AsyncRPCOperation_sweep& operator=(AsyncRPCOperation_sweep&&) = delete; // Move assign + + virtual void main(); + + virtual void cancel(); + + virtual UniValue getStatus() const; + +private: + int targetHeight_; + bool fromRPC_; + + bool main_impl(); + + void setSweepResult(int numTxCreated, const CAmount& amountSwept, const std::vector& sweepTxIds); + +}; From 4aedeb557bcd83c8a3f36c49dfa7144500631f2f Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 27 Aug 2022 10:35:08 -0700 Subject: [PATCH 110/255] Add z_sweepstatus RPC --- src/init.cpp | 1 + src/rpc/server.h | 1 + src/wallet/asyncrpcoperation_sweep.cpp | 2 +- src/wallet/rpcwallet.cpp | 42 ++++++++++++++++++++++++++ src/wallet/wallet.h | 6 +++- 5 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index dd6666710..2827a2bb9 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2086,6 +2086,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) } auto hasSpendingKey = boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), zSweep); auto allowSweepToExternalWallet = GetArg("-zsweepexternal", false); + pwalletMain->sweepAddress = vSweep[i]; if (!hasSpendingKey) { if (allowSweepToExternalWallet) { diff --git a/src/rpc/server.h b/src/rpc/server.h index b6a20b559..b2c361765 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -472,6 +472,7 @@ extern UniValue z_getbalance(const UniValue& params, bool fHelp, const CPubKey& extern UniValue z_gettotalbalance(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue z_mergetoaddress(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp +extern UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue z_shieldcoinbase(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue z_getoperationstatus(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue z_getoperationresult(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp diff --git a/src/wallet/asyncrpcoperation_sweep.cpp b/src/wallet/asyncrpcoperation_sweep.cpp index 140c9902a..a2b6a19c3 100644 --- a/src/wallet/asyncrpcoperation_sweep.cpp +++ b/src/wallet/asyncrpcoperation_sweep.cpp @@ -64,7 +64,7 @@ void AsyncRPCOperation_sweep::main() { set_state(OperationStatus::FAILED); } - std::string s = strprintf("%s: Sapling Sweep transaction created. (status=%s", getId(), getStateAsString()); + std::string s = strprintf("%s: Sweep transaction created. (status=%s", getId(), getStateAsString()); if (success) { s += strprintf(", success)\n"); } else { diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 42a145b94..e596ed03f 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3315,6 +3315,48 @@ UniValue getalldata(const UniValue& params, bool fHelp,const CPubKey&) return returnObj; } +UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk) +{ + + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() > 0) + throw runtime_error( + "z_sweepstatus\n" + "\nGive details about zsweep operations since the node was started." + "}\n" + "\nExamples:\n" + + HelpExampleCli("z_sweepstatus", "") + + HelpExampleRpc("z_sweepstatus", "") + ); + + LOCK2(cs_main, pwalletMain->cs_wallet); + + UniValue ret(UniValue::VOBJ); + auto amount_swept; + ret.push_back(Pair("zsweep", pwalletMain->fSweepEnabled)); + ret.push_back(Pair("running", pwalletMain->fSweepRunning)); + ret.push_back(Pair("amount_swept", amount_swept)); + + if (pwalletMain->fConsolidationRunning) { + ret.push_back(Pair("next_zsweep", pwalletMain->sweepInterval + chainActive.Tip()->GetHeight())); + } else { + if (pwalletMain->nextConsolidation == 0) { + ret.push_back(Pair("next_zsweep", chainActive.Tip()->GetHeight() + 1)); + } else { + ret.push_back(Pair("next_zsweep", pwalletMain->nextSweep)); + } + } + ret.push_back(Pair("zsweepinterval", pwalletMain->sweepInterval)); + ret.push_back(Pair("zsweepaddress", pwalletMain->sweepAddress)); + ret.push_back(Pair("zsweepmaxinputs", pwalletMain->sweepMaxInputs)); + ret.push_back(Pair("zsweepfee", pwalletMain->sweepFee)); + ret.push_back(Pair("zsweepexternal", pwalletMain->fSweepExternalEnabled)); + + return ret; +} + UniValue z_listreceivedaddress(const UniValue& params, bool fHelp,const CPubKey&) { if (!EnsureWalletIsAvailable(fHelp)) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f633f2564..ada169c73 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -805,8 +805,12 @@ public: bool fSaplingConsolidationEnabled = false; bool fConsolidationRunning = false; bool fSweepEnabled = false; + bool fSweepExternalEnabled = false; bool fSweepRunning = false; - int nextSweep = 0; + int nextSweep = 0; + int sweepInterval = 20; + int sweepMaxInputs = 200; + std::string sweepAddress = ""; void ClearNoteWitnessCache(); From 4eec81b1916302a895ed32aef93b9915f742b1cb Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 27 Aug 2022 13:57:00 -0400 Subject: [PATCH 111/255] Fix some issues in z_sweepstatus --- src/wallet/rpcwallet.cpp | 3 +-- src/wallet/wallet.h | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index e596ed03f..c977e2764 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3334,10 +3334,9 @@ UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk) LOCK2(cs_main, pwalletMain->cs_wallet); UniValue ret(UniValue::VOBJ); - auto amount_swept; ret.push_back(Pair("zsweep", pwalletMain->fSweepEnabled)); ret.push_back(Pair("running", pwalletMain->fSweepRunning)); - ret.push_back(Pair("amount_swept", amount_swept)); + ret.push_back(Pair("amount_swept", pwalletMain->amountSwept)); if (pwalletMain->fConsolidationRunning) { ret.push_back(Pair("next_zsweep", pwalletMain->sweepInterval + chainActive.Tip()->GetHeight())); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index ada169c73..4ae4716cb 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -808,7 +808,9 @@ public: bool fSweepExternalEnabled = false; bool fSweepRunning = false; int nextSweep = 0; + int amountSwept = 0; int sweepInterval = 20; + int sweepFee = 10000; int sweepMaxInputs = 200; std::string sweepAddress = ""; From 37301759713fce42d434f2e38d3694fa200d9267 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 27 Aug 2022 14:04:53 -0400 Subject: [PATCH 112/255] Add some logging when skipping sweep/consolidation --- src/wallet/wallet.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 83f95cbb3..8c6e82586 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -520,12 +520,14 @@ void CWallet::RunSaplingSweep(int blockHeight) { } //Don't Run if consolidation will run soon. - if (fSaplingConsolidationEnabled && nextConsolidation - 15 <= blockHeight) { + if (fSaplingConsolidationEnabled && nextConsolidation - 5 <= blockHeight) { + LogPrintf("%s: not consolidating since next sweep is within 5 blocks\n", __func__); return; } //Don't Run While consolidation is running. if (fConsolidationRunning) { + LogPrintf("%s: not sweeping since consolidation is currently running\n", __func__); return; } From 0e3889c96ae3fab105acc524b87450477ef7d744 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 27 Aug 2022 15:03:11 -0400 Subject: [PATCH 113/255] List z_sweepstatus in RPC list --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c977e2764..00d120f54 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -8536,6 +8536,7 @@ static const CRPCCommand commands[] = { "wallet", "z_anonsetblockdelta", &z_anonsetblockdelta, true }, { "wallet", "z_gettotalbalance", &z_gettotalbalance, false }, { "wallet", "z_mergetoaddress", &z_mergetoaddress, false }, + { "wallet", "z_sweepstatus", &z_sweepstatus, true }, { "wallet", "z_sendmany", &z_sendmany, false }, { "wallet", "z_shieldcoinbase", &z_shieldcoinbase, false }, { "wallet", "z_getoperationstatus", &z_getoperationstatus, true }, From 1748f0f2a30da57129d3e01bcab029498f1744b8 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 27 Aug 2022 22:31:40 -0400 Subject: [PATCH 114/255] Improved logging and error checking in consolidation and sweeping --- ...asyncrpcoperation_saplingconsolidation.cpp | 22 +++++------ src/wallet/asyncrpcoperation_sweep.cpp | 38 +++++++++++-------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index 361d04390..25c1f54ac 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -82,7 +82,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { auto consensusParams = Params().GetConsensus(); auto nextActivationHeight = NextActivationHeight(targetHeight_, consensusParams); if (nextActivationHeight && targetHeight_ + CONSOLIDATION_EXPIRY_DELTA >= nextActivationHeight.get()) { - LogPrint("zrpcunsafe", "%s: Consolidation txs would be created before a NU activation but may expire after. Skipping this round.\n",opid); + LogPrintf("%s: Consolidation txs would be created before a NU activation but may expire after. Skipping this round.\n",opid); setConsolidationResult(0, 0, std::vector()); return status; } @@ -97,7 +97,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { pwalletMain->GetFilteredNotes(saplingEntries, "", 11); if(saplingEntries.size() == 0) { - LogPrint("zrpcunsafe", "%s: Nothing to consolidate, done.\n",opid); + LogPrintf("%s: Nothing to consolidate, done.\n",opid); return true; } @@ -109,7 +109,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { libzcash::SaplingPaymentAddress saplingAddress = boost::get(zAddress); addresses.insert(saplingAddress); } else { - LogPrint("zrpcunsafe", "%s: Invalid zaddr, exiting\n", opid); + LogPrintf("%s: Invalid zaddr, exiting\n", opid); return false; } } @@ -176,14 +176,14 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { std::vector> witnesses; { LOCK2(cs_main, pwalletMain->cs_wallet); - LogPrint("zrpcunsafe", "%s: Fetching note witnesses\n", opid); + // LogPrint("zrpcunsafe", "%s: Fetching note witnesses\n", opid); pwalletMain->GetSaplingNoteWitnesses(ops, witnesses, anchor); } // Add Sapling spends for (size_t i = 0; i < notes.size(); i++) { if (!witnesses[i]) { - LogPrint("zrpcunsafe", "%s: Missing Witnesses. Stopping.\n", opid); + LogPrintf("%s: Missing Witnesses! Stopping.\n", opid); status=false; break; } @@ -213,7 +213,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { // actually add our sietch zoutput, the new way builder.AddSaplingOutput(extsk.expsk.ovk, sietchZoutput, amount); } else { - LogPrint("zrpcunsafe", "%s: Invalid payment address %s! Stopping.\n", opid, zdust); + LogPrintf("%s: Invalid payment address %s! Stopping.\n", opid, zdust); status = false; break; } @@ -223,25 +223,25 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { auto maybe_tx = builder.Build(); if (!maybe_tx) { - LogPrint("zrpcunsafe", "%s: Failed to build transaction.\n",opid); + LogPrintf("%s: Failed to build transaction.\n",opid); status=false; break; } CTransaction tx = maybe_tx.get(); if (isCancelled()) { - LogPrint("zrpcunsafe", "%s: Canceled. Stopping.\n", opid); + LogPrintf("%s: Canceled. Stopping.\n", opid); status=false; break; } if(pwalletMain->CommitAutomatedTx(tx)) { - LogPrint("zrpcunsafe", "%s: Committed consolidation transaction with txid=%s\n",opid, tx.GetHash().ToString()); + LogPrintf("%s: Committed consolidation transaction with txid=%s\n",opid, tx.GetHash().ToString()); amountConsolidated += actualAmountToSend; consolidationTxIds.push_back(tx.GetHash().ToString()); numTxCreated++; } else { - LogPrint("zrpcunsafe", "%s: Consolidation transaction FAILED in CommitTransaction, txid=%s\n",opid , tx.GetHash().ToString()); + LogPrintf("%s: Consolidation transaction FAILED in CommitTransaction, txid=%s\n",opid , tx.GetHash().ToString()); setConsolidationResult(numTxCreated, amountConsolidated, consolidationTxIds); status = false; break; @@ -249,7 +249,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { } } - LogPrint("zrpcunsafe", "%s: Created %d transactions with total Sapling output amount=%s,status=%d\n",opid , numTxCreated, FormatMoney(amountConsolidated), (int)status); + LogPrintf("%s: Created %d transactions with total Sapling output amount=%s,status=%d\n",opid , numTxCreated, FormatMoney(amountConsolidated), (int)status); setConsolidationResult(numTxCreated, amountConsolidated, consolidationTxIds); return status; } diff --git a/src/wallet/asyncrpcoperation_sweep.cpp b/src/wallet/asyncrpcoperation_sweep.cpp index a2b6a19c3..60132bb38 100644 --- a/src/wallet/asyncrpcoperation_sweep.cpp +++ b/src/wallet/asyncrpcoperation_sweep.cpp @@ -75,11 +75,13 @@ void AsyncRPCOperation_sweep::main() { } bool AsyncRPCOperation_sweep::main_impl() { - LogPrint("zrpcunsafe", "%s: Beginning asyncrpcoperation_sweep.\n", getId()); + bool status=true; + auto opid=getId(); + LogPrintf("%s: Beginning asyncrpcoperation_sweep.\n", getId()); auto consensusParams = Params().GetConsensus(); auto nextActivationHeight = NextActivationHeight(targetHeight_, consensusParams); if (nextActivationHeight && targetHeight_ + SWEEP_EXPIRY_DELTA >= nextActivationHeight.get()) { - LogPrint("zrpcunsafe", "%s: Sweep txs would be created before a NU activation but may expire after. Skipping this round.\n", getId()); + LogPrintf("%s: Sweep txs would be created before a NU activation but may expire after. Skipping this round.\n", getId()); setSweepResult(0, 0, std::vector()); return true; } @@ -201,7 +203,7 @@ bool AsyncRPCOperation_sweep::main_impl() { LOCK2(cs_main, pwalletMain->cs_wallet); builder.SetExpiryHeight(chainActive.Tip()->GetHeight()+ SWEEP_EXPIRY_DELTA); } - LogPrint("zrpcunsafe", "%s: Beginning creating transaction with Sapling output amount=%s\n", getId(), FormatMoney(amountToSend - fee)); + LogPrintf("%s: Beginning creating transaction with Sapling output amount=%s\n", getId(), FormatMoney(amountToSend - fee)); // Select Sapling notes std::vector ops; @@ -222,7 +224,7 @@ bool AsyncRPCOperation_sweep::main_impl() { // Add Sapling spends for (size_t i = 0; i < notes.size(); i++) { if (!witnesses[i]) { - LogPrint("zrpcunsafe", "%s: Missing Witnesses. Stopping.\n", getId()); + LogPrintf("%s: Missing Witnesses! Stopping.\n", getId()); break; } builder.AddSaplingSpend(extsk.expsk, notes[i], anchor, witnesses[i].get()); @@ -244,8 +246,8 @@ bool AsyncRPCOperation_sweep::main_impl() { builder.AddSaplingOutput(extsk.expsk.ovk, sietchZoutput, amount); } else { - LogPrint("zrpcunsafe", "%s: Invalid payment address %s! Stopping.\n", __func__, zdust); - // status = false; + LogPrintf("%s: Invalid payment address %s! Stopping.\n", __func__, zdust); + status = false; break; } } @@ -253,22 +255,28 @@ bool AsyncRPCOperation_sweep::main_impl() { auto maybe_tx = builder.Build(); if (!maybe_tx) { - LogPrint("zrpcunsafe", "%s: Failed to build transaction %s.\n",__func__, getId()); - // status=false; + LogPrintf("%s: Failed to build transaction %s.\n",__func__, getId()); + status=false; break; } CTransaction tx = maybe_tx.get(); if (isCancelled()) { - LogPrint("zrpcunsafe", "%s: Canceled. Stopping.\n", getId()); + LogPrintf("%s: Canceled. Stopping.\n", getId()); break; } - pwalletMain->CommitAutomatedTx(tx); - LogPrint("zrpcunsafe", "%s: Committed sweep transaction with txid=%s\n", getId(), tx.GetHash().ToString()); - amountSwept += amountToSend - fee; - sweepTxIds.push_back(tx.GetHash().ToString()); - + if (pwalletMain->CommitAutomatedTx(tx)) { + LogPrintf("%s: Committed sweep transaction with txid=%s\n", getId(), tx.GetHash().ToString()); + amountSwept += amountToSend - fee; + sweepTxIds.push_back(tx.GetHash().ToString()); + numTxCreated++; + } else { + LogPrintf("%s: Sweep transaction FAILED in CommitTransaction, txid=%s\n",opid , tx.GetHash().ToString()); + setSweepResult(numTxCreated, amountSwept, sweepTxIds); + status = false; + break; + } } } @@ -282,7 +290,7 @@ bool AsyncRPCOperation_sweep::main_impl() { pwalletMain->fSweepRunning = false; } - LogPrint("zrpcunsafe", "%s: Created %d transactions with total Sapling output amount=%s\n", getId(), numTxCreated, FormatMoney(amountSwept)); + LogPrintf("%s: Created %d transactions with total output amount=%s\n", getId(), numTxCreated, FormatMoney(amountSwept)); setSweepResult(numTxCreated, amountSwept, sweepTxIds); return true; From 702c2163cd13137e71778beca613ab4b7f792dda Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 30 Aug 2022 21:05:09 -0400 Subject: [PATCH 115/255] Log if we have no zsweepaddress or an invalid zsweepaddress --- src/wallet/asyncrpcoperation_sweep.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/asyncrpcoperation_sweep.cpp b/src/wallet/asyncrpcoperation_sweep.cpp index 60132bb38..b76915e92 100644 --- a/src/wallet/asyncrpcoperation_sweep.cpp +++ b/src/wallet/asyncrpcoperation_sweep.cpp @@ -103,12 +103,14 @@ bool AsyncRPCOperation_sweep::main_impl() { } } } else { + LogPrintf("%s: No zsweepaddress configured, exiting\n", opid); return false; } } else { if (boost::get(&rpcSweepAddress) != nullptr) { sweepAddress = boost::get(rpcSweepAddress); } else { + LogPrintf("%s: Invalid zsweepaddress, exiting\n", opid); return false; } } From b4b6988eb03cfc90332fbc82dec4e7e5d64b48be Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 30 Aug 2022 21:05:27 -0400 Subject: [PATCH 116/255] Log when we use fee=0 for small inputs --- src/wallet/asyncrpcoperation_sweep.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/asyncrpcoperation_sweep.cpp b/src/wallet/asyncrpcoperation_sweep.cpp index b76915e92..721309385 100644 --- a/src/wallet/asyncrpcoperation_sweep.cpp +++ b/src/wallet/asyncrpcoperation_sweep.cpp @@ -197,9 +197,10 @@ bool AsyncRPCOperation_sweep::main_impl() { CAmount fee = fSweepTxFee; if (amountToSend <= fSweepTxFee) { - fee = 0; + LogPrintf("%s: Amount to send %s is <= fee, using fee=0", getId(), FormatMoney(amountToSend)); + fee = 0; } - amountSwept += amountToSend; + auto builder = TransactionBuilder(consensusParams, targetHeight_, pwalletMain); { LOCK2(cs_main, pwalletMain->cs_wallet); From b50c51f797c3b146ffb4bc81fa668e97e9d619cb Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 30 Aug 2022 21:05:57 -0400 Subject: [PATCH 117/255] Log value of status and correctly return status value instead of always returning success, derp --- src/wallet/asyncrpcoperation_sweep.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/wallet/asyncrpcoperation_sweep.cpp b/src/wallet/asyncrpcoperation_sweep.cpp index 721309385..780ddfa29 100644 --- a/src/wallet/asyncrpcoperation_sweep.cpp +++ b/src/wallet/asyncrpcoperation_sweep.cpp @@ -293,10 +293,9 @@ bool AsyncRPCOperation_sweep::main_impl() { pwalletMain->fSweepRunning = false; } - LogPrintf("%s: Created %d transactions with total output amount=%s\n", getId(), numTxCreated, FormatMoney(amountSwept)); + LogPrintf("%s: Created %d transactions with total output amount=%s, status=%d\n", getId(), numTxCreated, FormatMoney(amountSwept), (int)status); setSweepResult(numTxCreated, amountSwept, sweepTxIds); - return true; - + return status; } void AsyncRPCOperation_sweep::setSweepResult(int numTxCreated, const CAmount& amountSwept, const std::vector& sweepTxIds) { From 57baf25b0257c30636484b6ac8e8191b2f2ab320 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 30 Aug 2022 22:05:41 -0400 Subject: [PATCH 118/255] Do not add to amountConsolidated until we successfully create the tx and only do it once --- src/wallet/asyncrpcoperation_saplingconsolidation.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index 25c1f54ac..f9f2ebe1e 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -157,7 +157,6 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { if (fromNotes.size() < minQuantity) continue; - amountConsolidated += amountToSend; auto builder = TransactionBuilder(consensusParams, targetHeight_, pwalletMain); builder.SetExpiryHeight(targetHeight_ + CONSOLIDATION_EXPIRY_DELTA); auto actualAmountToSend = amountToSend < fConsolidationTxFee ? 0 : amountToSend - fConsolidationTxFee; @@ -219,8 +218,6 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { } } LogPrint("zrpcunsafe", "%s: Done adding %d sietch zouts\n", opid, MIN_ZOUTS); - //CTransaction tx = builder.Build(); - auto maybe_tx = builder.Build(); if (!maybe_tx) { LogPrintf("%s: Failed to build transaction.\n",opid); From 88263995c81c5c62f367bf3c2bb3bf7eb8ce2d7f Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 30 Aug 2022 22:27:34 -0400 Subject: [PATCH 119/255] Do not coredump if pnode=NULL in RelayTransaction --- src/net.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/net.cpp b/src/net.cpp index db47d5ec7..7df4f5e90 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2125,6 +2125,10 @@ void RelayTransaction(const CTransaction& tx, const CDataStream& ss) // Only relay to randomly chosen 50% of peers BOOST_FOREACH(CNode* pnode, vRelayNodes) { + //TODO: correct fix is to correctly LOCK vRelayNodes + if(!pnode) + continue; + if(!pnode->fRelayTxes) continue; LOCK(pnode->cs_filter); From 26fd16cb523abddfc2ee38f7b1766ddef20d9434 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 31 Aug 2022 11:09:18 -0700 Subject: [PATCH 120/255] Avoid relaying expired transactions which causes other nodes to ban us --- src/wallet/wallet.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8c6e82586..1db729e2f 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3121,6 +3121,13 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) if (wtx.nTimeReceived > nTime) continue; + // Do not relay expired transactions, to avoid other nodes banning us + if (wtx.nExpiryHeight > 0 && wtx.nExpiryHeight < chainActive.LastTip->GetHeight()) { + fprintf(stderr,"%s: ignoring expired tx %s\n", wtx.GetHash().ToString().c_str() ); + // TODO: should we call EraseFromWallet(wtx) right here? + continue; + } + if ( (wtx.nLockTime >= LOCKTIME_THRESHOLD && wtx.nLockTime < now-HUSH_MAXMEMPOOLTIME) ) { if(fDebug) { From 4573a8336f84fb63e5d0641be520561aafe80ff8 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 31 Aug 2022 14:10:40 -0400 Subject: [PATCH 121/255] Fix compile error --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1db729e2f..d7b818723 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3122,7 +3122,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) continue; // Do not relay expired transactions, to avoid other nodes banning us - if (wtx.nExpiryHeight > 0 && wtx.nExpiryHeight < chainActive.LastTip->GetHeight()) { + if (wtx.nExpiryHeight > 0 && wtx.nExpiryHeight < chainActive.LastTip()->GetHeight()) { fprintf(stderr,"%s: ignoring expired tx %s\n", wtx.GetHash().ToString().c_str() ); // TODO: should we call EraseFromWallet(wtx) right here? continue; From 63f9e2230818ee817c595b3ac5254d0904bbd103 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 31 Aug 2022 14:15:38 -0400 Subject: [PATCH 122/255] log the function name correctly --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index d7b818723..229f49275 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3123,7 +3123,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) // Do not relay expired transactions, to avoid other nodes banning us if (wtx.nExpiryHeight > 0 && wtx.nExpiryHeight < chainActive.LastTip()->GetHeight()) { - fprintf(stderr,"%s: ignoring expired tx %s\n", wtx.GetHash().ToString().c_str() ); + fprintf(stderr,"%s: ignoring expired tx %s\n", __func__, wtx.GetHash().ToString().c_str() ); // TODO: should we call EraseFromWallet(wtx) right here? continue; } From 0c2487c4271eaf80286478cb21ad8754ec281f0a Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 18 Jul 2022 10:43:22 -0400 Subject: [PATCH 123/255] Throw error in wallet if ReadBlockFromDisk fails --- src/wallet/wallet.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8d12d903a..bda0140f0 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1032,7 +1032,10 @@ int CWallet::VerifyAndSetInitialWitness(const CBlockIndex* pindex, bool witnessO //Cycle through blocks and transactions building sapling tree until the commitment needed is reached const CBlock* pblock; CBlock block; - ReadBlockFromDisk(block, pblockindex, 1); + if (!ReadBlockFromDisk(block, pblockindex, 1)) { + throw std::runtime_error( + strprintf("Cannot read block height %d (%s) from disk", pindex->GetHeight(), pindex->GetBlockHash().GetHex())); + } pblock = █ for (const CTransaction& tx : block.vtx) { @@ -1102,7 +1105,10 @@ void CWallet::BuildWitnessCache(const CBlockIndex* pindex, bool witnessOnly) //Cycle through blocks and transactions building sapling tree until the commitment needed is reached CBlock block; - ReadBlockFromDisk(block, pblockindex, 1); + if (!ReadBlockFromDisk(block, pblockindex, 1)) { + throw std::runtime_error( + strprintf("Cannot read block height %d (%s) from disk", pindex->GetHeight(), pindex->GetBlockHash().GetHex())); + } for (std::pair& wtxItem : mapWallet) { @@ -2721,7 +2727,11 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate) CBlock block; bool involvesMe = false; - ReadBlockFromDisk(block, pindex,1); + if (!ReadBlockFromDisk(block, pindex,1)) { + throw std::runtime_error( + strprintf("Cannot read block height %d (%s) from disk", pindex->GetHeight(), pindex->GetBlockHash().GetHex())); + } + BOOST_FOREACH(CTransaction& tx, block.vtx) { if (AddToWalletIfInvolvingMe(tx, &block, fUpdate)) { From 43e0ec186b50b596008496ed8d044f0a2a79b485 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 09:13:19 -0400 Subject: [PATCH 124/255] Get rid of CLIENT_DATE --- src/clientversion.cpp | 9 --------- src/clientversion.h | 1 - src/init.cpp | 2 +- src/wallet/rpcdump.cpp | 2 +- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/clientversion.cpp b/src/clientversion.cpp index 5702fbb95..cd6126eb1 100644 --- a/src/clientversion.cpp +++ b/src/clientversion.cpp @@ -104,16 +104,7 @@ const std::string CLIENT_NAME = GetArg("-clientname", "GoldenSandtrout"); #endif #endif -#ifndef BUILD_DATE -#ifdef GIT_COMMIT_DATE -#define BUILD_DATE GIT_COMMIT_DATE -#else -#define BUILD_DATE __DATE__ ", " __TIME__ -#endif -#endif - const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX); -const std::string CLIENT_DATE(BUILD_DATE); std::string FormatVersion(int nVersion) { diff --git a/src/clientversion.h b/src/clientversion.h index 1b2802b35..03657120e 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -73,7 +73,6 @@ static const int CLIENT_VERSION = extern const std::string CLIENT_NAME; extern const std::string CLIENT_BUILD; -extern const std::string CLIENT_DATE; std::string FormatVersion(int nVersion); diff --git a/src/init.cpp b/src/init.cpp index e057282be..6c0b81b75 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1063,7 +1063,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - LogPrintf("Hush version %s (%s)\n", FormatFullVersion(), CLIENT_DATE); + LogPrintf("Hush version %s (%s)\n", FormatFullVersion()); // when specifying an explicit binding address, you want to listen on it // even when -connect or -proxy is specified diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index db2727923..8b3b932c1 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -677,7 +677,7 @@ UniValue dumpwallet_impl(const UniValue& params, bool fHelp, bool fDumpZKeys) std::sort(vKeyBirth.begin(), vKeyBirth.end()); // produce output - file << strprintf("# Wallet dump created by Hush %s (%s)\n", CLIENT_BUILD, CLIENT_DATE); + file << strprintf("# Wallet dump created by Hush %s (%s)\n", CLIENT_BUILD); file << strprintf("# * Created on %s\n", EncodeDumpTime(GetTime())); file << strprintf("# * Best block at time of backup was %i (%s),\n", chainActive.Height(), chainActive.Tip()->GetBlockHash().ToString()); file << strprintf("# mined on %s\n", EncodeDumpTime(chainActive.Tip()->GetBlockTime())); From b9101e67ab7703b064006f7e018463fe7a49684d Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 09:20:09 -0400 Subject: [PATCH 125/255] removed unused file --- share/genbuild.sh | 51 ----------------------------------------------- 1 file changed, 51 deletions(-) delete mode 100755 share/genbuild.sh diff --git a/share/genbuild.sh b/share/genbuild.sh deleted file mode 100755 index a15cb34e4..000000000 --- a/share/genbuild.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh -if [ $# -gt 1 ]; then - cd "$2" -fi -if [ $# -gt 0 ]; then - FILE="$1" - shift - if [ -f "$FILE" ]; then - INFO="$(head -n 1 "$FILE")" - fi -else - echo "Usage: $0 " - exit 1 -fi - -DESC="" -SUFFIX="" -LAST_COMMIT_DATE="" -if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then - # clean 'dirty' status of touched files that haven't been modified - git diff >/dev/null 2>/dev/null - - # if latest commit is tagged and not dirty, then override using the tag name - RAWDESC=$(git describe --abbrev=0 2>/dev/null) - if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then - git diff-index --quiet HEAD -- && DESC=$RAWDESC - fi - - # otherwise generate suffix from git, i.e. string like "59887e8-dirty" - SUFFIX=$(git rev-parse --short HEAD) - git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty" - - # get a string like "2012-04-10 16:27:19 +0200" - LAST_COMMIT_DATE="$(git log -n 1 --format="%ci")" -fi - -if [ -n "$DESC" ]; then - NEWINFO="#define BUILD_DESC \"$DESC\"" -elif [ -n "$SUFFIX" ]; then - NEWINFO="#define BUILD_SUFFIX $SUFFIX" -else - NEWINFO="// No build information available" -fi - -# only update build.h if necessary -if [ "$INFO" != "$NEWINFO" ]; then - echo "$NEWINFO" >"$FILE" - if [ -n "$LAST_COMMIT_DATE" ]; then - echo "#define BUILD_DATE \"$LAST_COMMIT_DATE\"" >> "$FILE" - fi -fi From 8ea5438a1615dfd135481519ab48ca9a5a37a813 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 09:26:55 -0400 Subject: [PATCH 126/255] updated .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index b2010491e..9fc50df80 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,6 @@ libtool src/config/bitcoin-config.h src/config/bitcoin-config.h.in src/config/stamp-h1 -share/setup.nsi cache/ venv-mnf/ From 658160ce6cf73367020fb63e184e745a29ae5ac3 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 09:44:59 -0400 Subject: [PATCH 127/255] still removing CLIENT_DATE --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 6c0b81b75..e9adae1f4 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1501,7 +1501,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) //fprintf(stderr,"%s tik12\n", __FUNCTION__); LogPrintf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); - LogPrintf("Hush version %s (%s)\n", FormatFullVersion(), CLIENT_DATE); + LogPrintf("Hush version %s\n", FormatFullVersion()); if (fPrintToDebugLog) OpenDebugLog(); From 1085d15a2df6efd0b875e007ce4e68925b9da904 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 09:51:59 -0400 Subject: [PATCH 128/255] Revert "removed unused file" This reverts commit b9101e67ab7703b064006f7e018463fe7a49684d. --- share/genbuild.sh | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 share/genbuild.sh diff --git a/share/genbuild.sh b/share/genbuild.sh new file mode 100755 index 000000000..a15cb34e4 --- /dev/null +++ b/share/genbuild.sh @@ -0,0 +1,51 @@ +#!/bin/sh +if [ $# -gt 1 ]; then + cd "$2" +fi +if [ $# -gt 0 ]; then + FILE="$1" + shift + if [ -f "$FILE" ]; then + INFO="$(head -n 1 "$FILE")" + fi +else + echo "Usage: $0 " + exit 1 +fi + +DESC="" +SUFFIX="" +LAST_COMMIT_DATE="" +if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then + # clean 'dirty' status of touched files that haven't been modified + git diff >/dev/null 2>/dev/null + + # if latest commit is tagged and not dirty, then override using the tag name + RAWDESC=$(git describe --abbrev=0 2>/dev/null) + if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then + git diff-index --quiet HEAD -- && DESC=$RAWDESC + fi + + # otherwise generate suffix from git, i.e. string like "59887e8-dirty" + SUFFIX=$(git rev-parse --short HEAD) + git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty" + + # get a string like "2012-04-10 16:27:19 +0200" + LAST_COMMIT_DATE="$(git log -n 1 --format="%ci")" +fi + +if [ -n "$DESC" ]; then + NEWINFO="#define BUILD_DESC \"$DESC\"" +elif [ -n "$SUFFIX" ]; then + NEWINFO="#define BUILD_SUFFIX $SUFFIX" +else + NEWINFO="// No build information available" +fi + +# only update build.h if necessary +if [ "$INFO" != "$NEWINFO" ]; then + echo "$NEWINFO" >"$FILE" + if [ -n "$LAST_COMMIT_DATE" ]; then + echo "#define BUILD_DATE \"$LAST_COMMIT_DATE\"" >> "$FILE" + fi +fi From 7fc594d220830226777799400b59a17999b02ba1 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 09:56:55 -0400 Subject: [PATCH 129/255] edits to genbuild.sh --- share/genbuild.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/share/genbuild.sh b/share/genbuild.sh index a15cb34e4..efe083f05 100755 --- a/share/genbuild.sh +++ b/share/genbuild.sh @@ -15,7 +15,6 @@ fi DESC="" SUFFIX="" -LAST_COMMIT_DATE="" if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then # clean 'dirty' status of touched files that haven't been modified git diff >/dev/null 2>/dev/null @@ -30,8 +29,6 @@ if [ -e "$(which git 2>/dev/null)" -a "$(git rev-parse --is-inside-work-tree 2>/ SUFFIX=$(git rev-parse --short HEAD) git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty" - # get a string like "2012-04-10 16:27:19 +0200" - LAST_COMMIT_DATE="$(git log -n 1 --format="%ci")" fi if [ -n "$DESC" ]; then @@ -45,7 +42,4 @@ fi # only update build.h if necessary if [ "$INFO" != "$NEWINFO" ]; then echo "$NEWINFO" >"$FILE" - if [ -n "$LAST_COMMIT_DATE" ]; then - echo "#define BUILD_DATE \"$LAST_COMMIT_DATE\"" >> "$FILE" - fi fi From bf51d37e5dc20687f2bb820c0c95c6b6a7907032 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 10:09:46 -0400 Subject: [PATCH 130/255] added copyright to genbuild.sh --- share/genbuild.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/share/genbuild.sh b/share/genbuild.sh index efe083f05..d4dc35ed4 100755 --- a/share/genbuild.sh +++ b/share/genbuild.sh @@ -1,4 +1,7 @@ #!/bin/sh +# Copyright (c) 2018-2022 The Hush developers +# Distributed under the GPLv3 software license, see the accompanying +# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html if [ $# -gt 1 ]; then cd "$2" fi From 325dcec0ac790cae2dc2ed931f4ad73fab30483c Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sat, 3 Sep 2022 10:22:00 -0400 Subject: [PATCH 131/255] remove unused function GetKeyID_NoCheck --- src/base58.cpp | 8 -------- src/base58.h | 2 -- 2 files changed, 10 deletions(-) diff --git a/src/base58.cpp b/src/base58.cpp index d46894ea0..831a4842e 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -323,14 +323,6 @@ bool CBitcoinAddress::GetKeyID(CKeyID& keyID) const return true; } -bool CBitcoinAddress::GetKeyID_NoCheck(CKeyID& keyID) const -{ - uint160 id; - memcpy(&id, &vchData[0], 20); - keyID = CKeyID(id); - return true; -} - bool CBitcoinAddress::IsScript() const { return IsValid() && vchVersion == Params().Base58Prefix(CChainParams::SCRIPT_ADDRESS); diff --git a/src/base58.h b/src/base58.h index 6fa3f457f..1032a4f00 100644 --- a/src/base58.h +++ b/src/base58.h @@ -146,7 +146,6 @@ public: CTxDestination Get() const; bool GetKeyID(CKeyID &keyID) const; - bool GetKeyID_NoCheck(CKeyID& keyID) const; bool GetIndexKey(uint160& hashBytes, int& type, bool ccflag) const; bool IsScript() const; }; @@ -171,7 +170,6 @@ public: CTxDestination Get() const; bool GetKeyID(CKeyID &keyID) const; - bool GetKeyID_NoCheck(CKeyID& keyID) const; bool GetIndexKey(uint160& hashBytes, int& type, bool ccflag) const; bool IsScript() const; }; From 3327b25a288d5792a58c4723cfedcbf8578d40ea Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sat, 3 Sep 2022 16:22:43 -0700 Subject: [PATCH 132/255] fix logging bug --- src/wallet/wallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1db729e2f..453b486d8 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3123,7 +3123,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) // Do not relay expired transactions, to avoid other nodes banning us if (wtx.nExpiryHeight > 0 && wtx.nExpiryHeight < chainActive.LastTip->GetHeight()) { - fprintf(stderr,"%s: ignoring expired tx %s\n", wtx.GetHash().ToString().c_str() ); + fprintf(stderr,"%s: ignoring expired tx %s\n", __func__, wtx.GetHash().ToString().c_str() ); // TODO: should we call EraseFromWallet(wtx) right here? continue; } From 5c8c7507ec30c6ccab5d3367634e25a74c0a2daa Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 6 Sep 2022 05:55:03 -0700 Subject: [PATCH 133/255] Add z_consolidationstatus RPC --- src/rpc/server.h | 1 + ...asyncrpcoperation_saplingconsolidation.cpp | 1 + src/wallet/rpcwallet.cpp | 40 +++++++++++++++++++ src/wallet/wallet.h | 1 + 4 files changed, 43 insertions(+) diff --git a/src/rpc/server.h b/src/rpc/server.h index b2c361765..3b3e11c6a 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -473,6 +473,7 @@ extern UniValue z_gettotalbalance(const UniValue& params, bool fHelp, const CPub extern UniValue z_mergetoaddress(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp +extern UniValue z_consolidationstatus(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue z_shieldcoinbase(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue z_getoperationstatus(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp extern UniValue z_getoperationresult(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index f9f2ebe1e..5422e1715 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -108,6 +108,7 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { if (boost::get(&zAddress) != nullptr) { libzcash::SaplingPaymentAddress saplingAddress = boost::get(zAddress); addresses.insert(saplingAddress); + consolidationAddress = zAddress; } else { LogPrintf("%s: Invalid zaddr, exiting\n", opid); return false; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 00d120f54..749576178 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3315,6 +3315,45 @@ UniValue getalldata(const UniValue& params, bool fHelp,const CPubKey&) return returnObj; } +UniValue z_consolidationstatus(const UniValue& params, bool fHelp, const CPubKey& mypk) +{ + + if (!EnsureWalletIsAvailable(fHelp)) + return NullUniValue; + + if (fHelp || params.size() > 0) + throw runtime_error( + "z_consolidationstatus\n" + "\nGive details about consolidation operations since the node was started." + "}\n" + "\nExamples:\n" + + HelpExampleCli("z_consolidationstatus", "") + + HelpExampleRpc("z_consolidationstatus", "") + ); + + LOCK2(cs_main, pwalletMain->cs_wallet); + + UniValue ret(UniValue::VOBJ); + ret.push_back(Pair("consolidation", pwalletMain->fConsolidationEnabled)); + ret.push_back(Pair("running", pwalletMain->fConsolidationRunning)); + ret.push_back(Pair("amount_consolidated", pwalletMain->amountConsolidated)); + + if (pwalletMain->fConsolidationRunning) { + ret.push_back(Pair("next_consolidation", pwalletMain->consolidationInterval + chainActive.Tip()->GetHeight())); + } else { + if (pwalletMain->nextConsolidation == 0) { + ret.push_back(Pair("next_consolidation", chainActive.Tip()->GetHeight() + 1)); + } else { + ret.push_back(Pair("next_consolidation", pwalletMain->nextConsolidation)); + } + } + ret.push_back(Pair("consolidationinterval", pwalletMain->consolidationInterval)); + ret.push_back(Pair("consolidationaddress", pwalletMain->consolidationAddress)); + ret.push_back(Pair("consolidationtxfee",(int)fConsolidationTxFee)); + + return ret; +} + UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk) { @@ -8537,6 +8576,7 @@ static const CRPCCommand commands[] = { "wallet", "z_gettotalbalance", &z_gettotalbalance, false }, { "wallet", "z_mergetoaddress", &z_mergetoaddress, false }, { "wallet", "z_sweepstatus", &z_sweepstatus, true }, + { "wallet", "z_consolidationstatus", &z_consolidationstatus, true }, { "wallet", "z_sendmany", &z_sendmany, false }, { "wallet", "z_shieldcoinbase", &z_shieldcoinbase, false }, { "wallet", "z_getoperationstatus", &z_getoperationstatus, true }, diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 4ae4716cb..7bf0d446a 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -813,6 +813,7 @@ public: int sweepFee = 10000; int sweepMaxInputs = 200; std::string sweepAddress = ""; + std::string consolidationAddress = ""; void ClearNoteWitnessCache(); From 9c5e5c550ccc803ff71b6c841c61c023e1961ef9 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 6 Sep 2022 09:20:53 -0400 Subject: [PATCH 134/255] Fix compile issues in z_consolidationstatus --- src/init.cpp | 1 + src/wallet/asyncrpcoperation_saplingconsolidation.cpp | 1 - src/wallet/rpcwallet.cpp | 7 ++++--- src/wallet/wallet.h | 1 + 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 2827a2bb9..ce03bd7fb 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2100,6 +2100,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if (pwalletMain->fSaplingConsolidationEnabled) { //Validate 1 Consolidation address only that matches the sweep address vector& vaddresses = mapMultiArgs["-consolidatesaplingaddress"]; + pwalletMain->consolidationAddress = vaddresses[0]; if (vaddresses.size() == 0) { fConsolidationMapUsed = true; mapMultiArgs["-consolidatesaplingaddress"] = vSweep; diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index 5422e1715..f9f2ebe1e 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -108,7 +108,6 @@ bool AsyncRPCOperation_saplingconsolidation::main_impl() { if (boost::get(&zAddress) != nullptr) { libzcash::SaplingPaymentAddress saplingAddress = boost::get(zAddress); addresses.insert(saplingAddress); - consolidationAddress = zAddress; } else { LogPrintf("%s: Invalid zaddr, exiting\n", opid); return false; diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 749576178..745dc3ce4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3334,12 +3334,13 @@ UniValue z_consolidationstatus(const UniValue& params, bool fHelp, const CPubKey LOCK2(cs_main, pwalletMain->cs_wallet); UniValue ret(UniValue::VOBJ); - ret.push_back(Pair("consolidation", pwalletMain->fConsolidationEnabled)); + ret.push_back(Pair("consolidation", pwalletMain->fSaplingConsolidationEnabled)); ret.push_back(Pair("running", pwalletMain->fConsolidationRunning)); ret.push_back(Pair("amount_consolidated", pwalletMain->amountConsolidated)); if (pwalletMain->fConsolidationRunning) { - ret.push_back(Pair("next_consolidation", pwalletMain->consolidationInterval + chainActive.Tip()->GetHeight())); + // TODO: set a static consolidationInterval instead of it being non-deterministic + // ret.push_back(Pair("next_consolidation", pwalletMain->consolidationInterval + chainActive.Tip()->GetHeight())); } else { if (pwalletMain->nextConsolidation == 0) { ret.push_back(Pair("next_consolidation", chainActive.Tip()->GetHeight() + 1)); @@ -3347,7 +3348,7 @@ UniValue z_consolidationstatus(const UniValue& params, bool fHelp, const CPubKey ret.push_back(Pair("next_consolidation", pwalletMain->nextConsolidation)); } } - ret.push_back(Pair("consolidationinterval", pwalletMain->consolidationInterval)); + // ret.push_back(Pair("consolidationinterval", pwalletMain->consolidationInterval)); ret.push_back(Pair("consolidationaddress", pwalletMain->consolidationAddress)); ret.push_back(Pair("consolidationtxfee",(int)fConsolidationTxFee)); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 7bf0d446a..fdaee018b 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -809,6 +809,7 @@ public: bool fSweepRunning = false; int nextSweep = 0; int amountSwept = 0; + int amountConsolidated = 0; int sweepInterval = 20; int sweepFee = 10000; int sweepMaxInputs = 200; From 55703fdb95cf6300325341abb04d669e024797c0 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 6 Sep 2022 10:03:47 -0400 Subject: [PATCH 135/255] Do not ban nodes which relay expired transactions --- src/main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b8e64dc27..4e466ba45 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1304,10 +1304,12 @@ bool ContextualCheckTransaction(int32_t slowflag,const CBlock *block, CBlockInde // Check that all transactions are unexpired if (IsExpiredTx(tx, nHeight)) { // Don't increase banscore if the transaction only just expired - int expiredDosLevel = IsExpiredTx(tx, nHeight - 1) ? (dosLevel > 10 ? dosLevel : 10) : 0; + //int expiredDosLevel = IsExpiredTx(tx, nHeight - 1) ? (dosLevel > 10 ? dosLevel : 10) : 0; //string strHex = EncodeHexTx(tx); - //fprintf(stderr, "transaction exipred.%s\n",strHex.c_str()); - return state.DoS(expiredDosLevel, error("ContextualCheckTransaction(): transaction %s is expired, expiry block %i vs current block %i\n",tx.GetHash().ToString(),tx.nExpiryHeight,nHeight), REJECT_INVALID, "tx-overwinter-expired"); + //fprintf(stderr, "transaction expired.%s\n",strHex.c_str()); + + // Do not ban nodes which relay expired tx's, it's a bug not an attack + return state.DoS(0, error("ContextualCheckTransaction(): transaction %s is expired, expiry block %i vs current block %i\n",tx.GetHash().ToString(),tx.nExpiryHeight,nHeight), REJECT_INVALID, "tx-overwinter-expired"); } } From 456cf77b652c5afb63a00b079b5b9d46ffd0108b Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 6 Sep 2022 10:08:24 -0400 Subject: [PATCH 136/255] Exit RelayTransaction early if we have no nodes to relay to --- src/net.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/net.cpp b/src/net.cpp index 7df4f5e90..40e5070de 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2109,6 +2109,12 @@ void RelayTransaction(const CTransaction& tx, const CDataStream& ss) auto vRelayNodes = vNodes; + // If we have no nodes to relay to, there is nothing to do + if(vNodes.size() == 0) { + fprintf(stderr, "%s: No nodes to relay to!\n", __func__ ); + return; + } + // We always round down, except when we have only 1 connection auto newSize = (vNodes.size() / 2) == 0 ? 1 : (vNodes.size() / 2); From 85810121633dd38fd21d5723bd91ad8896028be8 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 6 Sep 2022 11:19:16 -0400 Subject: [PATCH 137/255] Sweep operations might not create any txs, so make logging more precise --- src/wallet/asyncrpcoperation_sweep.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/asyncrpcoperation_sweep.cpp b/src/wallet/asyncrpcoperation_sweep.cpp index 780ddfa29..fcf4769bb 100644 --- a/src/wallet/asyncrpcoperation_sweep.cpp +++ b/src/wallet/asyncrpcoperation_sweep.cpp @@ -64,7 +64,7 @@ void AsyncRPCOperation_sweep::main() { set_state(OperationStatus::FAILED); } - std::string s = strprintf("%s: Sweep transaction created. (status=%s", getId(), getStateAsString()); + std::string s = strprintf("%s: Sweep operation finished. (status=%s", getId(), getStateAsString()); if (success) { s += strprintf(", success)\n"); } else { From 8d8f988a1928ec6ff7d7dbce1649b6919aeeb499 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 6 Sep 2022 11:19:46 -0400 Subject: [PATCH 138/255] Delete expired txs from the wallet, since they can never be included in a block --- src/wallet/wallet.cpp | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 229f49275..e024d826c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1715,9 +1715,9 @@ void CWallet::EraseFromWallet(const uint256 &hash) if (mapWallet.erase(hash)) CWalletDB(strWalletFile).EraseTx(hash); } - if(fDebug) { - LogPrintf("%s: erased txid %s\n", __func__, hash.ToString().c_str() ); - } + + LogPrintf("%s: erased txid %s\n", __func__, hash.ToString().c_str() ); + return; } @@ -3111,6 +3111,8 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) // Sort them in chronological order multimap mapSorted; uint32_t now = (uint32_t)time(NULL); + + // vector of wallet transactions to delete std::vector vwtxh; uint32_t erased = 0, skipped = 0; @@ -3122,9 +3124,11 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) continue; // Do not relay expired transactions, to avoid other nodes banning us + // Current code will not ban nodes relaying expired txs but older nodes will if (wtx.nExpiryHeight > 0 && wtx.nExpiryHeight < chainActive.LastTip()->GetHeight()) { fprintf(stderr,"%s: ignoring expired tx %s\n", __func__, wtx.GetHash().ToString().c_str() ); - // TODO: should we call EraseFromWallet(wtx) right here? + // append to list of txs to delete + vwtxh.push_back(wtx.GetHash()); continue; } @@ -3134,6 +3138,7 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) LogPrintf("%s: skip Relaying wtx %s nLockTime %u vs now.%u\n", __func__, wtx.GetHash().ToString(),(uint32_t)wtx.nLockTime,now); } skipped++; + // TODO: this does not seem to handle rescanning+finding old coinbase txs correctly //vwtxh.push_back(wtx.GetHash()); continue; } @@ -3150,10 +3155,13 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) } } - // TODO: this does not seem to handle rescanning+finding old coinbase txs correctly - // Unless we remove these unconfirmed txs from the wallet, they will + // Unless we remove these unconfirmed and/or expired txs from the wallet, they will // persist there forever. They are too old to be accepted by network // consensus rules, so we erase them. + // Expired txs are always unconfirmed, but unconfirmed tx's could be expired or not, + // i.e. expired txs are a subset of unconfirmed tx's. Expired tx's can never be included + // in a block because they are against consensus rules. Unconfirmed tx's might still be + // included in a future block. for (auto hash : vwtxh) { EraseFromWallet(hash); @@ -3174,6 +3182,7 @@ void CWallet::ResendWalletTransactions(int64_t nBestBlockTime) if (GetTime() < nNextResend || !fBroadcastTransactions) return; bool fFirst = (nNextResend == 0); + // TODO: BTC Core changed this to be every 12 hours instead of every 30 mins nNextResend = GetTime() + GetRand(30 * 60); if (fFirst) return; From 61ecffd07460beac9d8c71fe52fb2afb307289e9 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 6 Sep 2022 14:30:06 -0400 Subject: [PATCH 139/255] Change default sweep interval to 10 and consolidation to be deterministic every 45 blocks --- src/wallet/asyncrpcoperation_sweep.cpp | 8 ++++---- src/wallet/wallet.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/wallet/asyncrpcoperation_sweep.cpp b/src/wallet/asyncrpcoperation_sweep.cpp index fcf4769bb..6045cf46f 100644 --- a/src/wallet/asyncrpcoperation_sweep.cpp +++ b/src/wallet/asyncrpcoperation_sweep.cpp @@ -284,10 +284,10 @@ bool AsyncRPCOperation_sweep::main_impl() { } if (sweepComplete) { - int sweepInterval = GetArg("-zsweepinterval", 5); - if (sweepInterval < 1) { - fprintf(stderr,"%s: Invalid sweep interval of %d, setting to default of 5\n", __func__, sweepInterval); - sweepInterval = 5; + int sweepInterval = GetArg("-zsweepinterval", 10); + if (sweepInterval < 5) { + fprintf(stderr,"%s: Invalid sweep interval of %d, setting to default of 10\n", __func__, sweepInterval); + sweepInterval = 10; } pwalletMain->nextSweep = sweepInterval + chainActive.Tip()->GetHeight(); pwalletMain->fSweepRunning = false; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e024d826c..8cee74ed2 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -559,7 +559,7 @@ void CWallet::RunSaplingConsolidation(int blockHeight) { return; } - int consolidateInterval = rand() % 5 + 5; + int consolidateInterval = 45; if(fZdebug) fprintf(stderr,"%s: height=%d interval=%d\n", __func__, blockHeight, consolidateInterval); From 3e75a2be225b7f3bdfc5394a53658725af8c7971 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Wed, 7 Sep 2022 00:35:08 -0400 Subject: [PATCH 140/255] delete unused zcbenchmarks --- src/Makefile.am | 2 - src/wallet/rpcwallet.cpp | 1 - src/zcbenchmarks.cpp | 405 --------------------------------------- src/zcbenchmarks.h | 27 --- 4 files changed, 435 deletions(-) delete mode 100644 src/zcbenchmarks.cpp delete mode 100644 src/zcbenchmarks.h diff --git a/src/Makefile.am b/src/Makefile.am index 5d73c049f..5364a6366 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -340,8 +340,6 @@ endif libbitcoin_wallet_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) libbitcoin_wallet_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) libbitcoin_wallet_a_SOURCES = \ - zcbenchmarks.cpp \ - zcbenchmarks.h \ wallet/asyncrpcoperation_mergetoaddress.cpp \ wallet/asyncrpcoperation_saplingconsolidation.cpp \ wallet/asyncrpcoperation_sendmany.cpp \ diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 42a145b94..c4827df02 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -33,7 +33,6 @@ #include "wallet.h" #include "walletdb.h" #include "primitives/transaction.h" -#include "zcbenchmarks.h" #include "script/interpreter.h" #include "zcash/zip32.h" #include "zcash/Note.hpp" diff --git a/src/zcbenchmarks.cpp b/src/zcbenchmarks.cpp deleted file mode 100644 index 3476918e6..000000000 --- a/src/zcbenchmarks.cpp +++ /dev/null @@ -1,405 +0,0 @@ -// Copyright (c) 2016-2021 The Hush developers -// Distributed under the GPLv3 software license, see the accompanying -// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - -#include -#include -#include -#include -#include -#include -#include "coins.h" -#include "util.h" -#include "init.h" -#include "primitives/transaction.h" -#include "base58.h" -#include "crypto/equihash.h" -#include "chain.h" -#include "chainparams.h" -#include "consensus/upgrades.h" -#include "consensus/validation.h" -#include "main.h" -#include "miner.h" -#include "pow.h" -#include "rpc/server.h" -#include "script/sign.h" -#include "sodium.h" -#include "streams.h" -#include "txdb.h" -#include "wallet/wallet.h" -#include "zcbenchmarks.h" -#include "zcash/Zcash.h" -#include "zcash/IncrementalMerkleTree.hpp" -#include "zcash/Note.hpp" -#include "librustzcash.h" - -using namespace libzcash; -// This method is based on Shutdown from init.cpp -void pre_wallet_load() -{ - LogPrintf("%s: In progress...\n", __func__); - if (ShutdownRequested()) - throw new std::runtime_error("The Hush node is shutting down"); - - if (pwalletMain) - pwalletMain->Flush(false); -#ifdef ENABLE_MINING - GenerateBitcoins(false, NULL, 0); -#endif - UnregisterNodeSignals(GetNodeSignals()); - if (pwalletMain) - pwalletMain->Flush(true); - - UnregisterValidationInterface(pwalletMain); - delete pwalletMain; - pwalletMain = NULL; - bitdb.Reset(); - RegisterNodeSignals(GetNodeSignals()); - LogPrintf("%s: done\n", __func__); -} - -void post_wallet_load(){ - RegisterValidationInterface(pwalletMain); -#ifdef ENABLE_MINING - // Generate coins in the background - if (pwalletMain || !GetArg("-mineraddress", "").empty()) - GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", 1)); -#endif -} - - -void timer_start(timeval &tv_start) -{ - gettimeofday(&tv_start, 0); -} - -double timer_stop(timeval &tv_start) -{ - double elapsed; - struct timeval tv_end; - gettimeofday(&tv_end, 0); - elapsed = double(tv_end.tv_sec-tv_start.tv_sec) + - (tv_end.tv_usec-tv_start.tv_usec)/double(1000000); - return elapsed; -} - -double benchmark_sleep() -{ - struct timeval tv_start; - timer_start(tv_start); - sleep(1); - return timer_stop(tv_start); -} - -#ifdef ENABLE_MINING -double benchmark_solve_equihash() -{ - CBlock pblock; - CEquihashInput I{pblock}; - CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); - ss << I; - - unsigned int n = Params(CBaseChainParams::MAIN).EquihashN(); - unsigned int k = Params(CBaseChainParams::MAIN).EquihashK(); - crypto_generichash_blake2b_state eh_state; - EhInitialiseState(n, k, eh_state); - crypto_generichash_blake2b_update(&eh_state, (unsigned char*)&ss[0], ss.size()); - - uint256 nonce; - randombytes_buf(nonce.begin(), 32); - crypto_generichash_blake2b_update(&eh_state, - nonce.begin(), - nonce.size()); - - struct timeval tv_start; - timer_start(tv_start); - std::set> solns; - EhOptimisedSolveUncancellable(n, k, eh_state, - [](std::vector soln) { return false; }); - return timer_stop(tv_start); -} - -std::vector benchmark_solve_equihash_threaded(int nThreads) -{ - std::vector ret; - std::vector> tasks; - std::vector threads; - for (int i = 0; i < nThreads; i++) { - std::packaged_task task(&benchmark_solve_equihash); - tasks.emplace_back(task.get_future()); - threads.emplace_back(std::move(task)); - } - std::future_status status; - for (auto it = tasks.begin(); it != tasks.end(); it++) { - it->wait(); - ret.push_back(it->get()); - } - for (auto it = threads.begin(); it != threads.end(); it++) { - it->join(); - } - return ret; -} -#endif // ENABLE_MINING - -double benchmark_verify_equihash() -{ - CChainParams params = Params(CBaseChainParams::MAIN); - CBlock genesis = Params(CBaseChainParams::MAIN).GenesisBlock(); - CBlockHeader genesis_header = genesis.GetBlockHeader(); - struct timeval tv_start; - timer_start(tv_start); - CheckEquihashSolution(&genesis_header, params); - return timer_stop(tv_start); -} - -double benchmark_large_tx(size_t nInputs) -{ - // Create priv/pub key - CKey priv; - priv.MakeNewKey(false); - auto pub = priv.GetPubKey(); - CBasicKeyStore tempKeystore; - tempKeystore.AddKey(priv); - - // The "original" transaction that the spending transaction will spend - // from. - CMutableTransaction m_orig_tx; - m_orig_tx.vout.resize(1); - m_orig_tx.vout[0].nValue = 1000000; - CScript prevPubKey = GetScriptForDestination(pub.GetID()); - m_orig_tx.vout[0].scriptPubKey = prevPubKey; - - auto orig_tx = CTransaction(m_orig_tx); - - CMutableTransaction spending_tx; - spending_tx.fOverwintered = true; - spending_tx.nVersionGroupId = SAPLING_VERSION_GROUP_ID; - spending_tx.nVersion = SAPLING_TX_VERSION; - - auto input_hash = orig_tx.GetHash(); - // Add nInputs inputs - for (size_t i = 0; i < nInputs; i++) { - spending_tx.vin.emplace_back(input_hash, 0); - } - - // Sign for all the inputs - auto consensusBranchId = NetworkUpgradeInfo[Consensus::UPGRADE_SAPLING].nBranchId; - for (size_t i = 0; i < nInputs; i++) { - SignSignature(tempKeystore, prevPubKey, spending_tx, i, 1000000, SIGHASH_ALL, consensusBranchId); - } - - // Spending tx has all its inputs signed and does not need to be mutated anymore - CTransaction final_spending_tx(spending_tx); - - // Benchmark signature verification costs: - struct timeval tv_start; - timer_start(tv_start); - PrecomputedTransactionData txdata(final_spending_tx); - for (size_t i = 0; i < nInputs; i++) { - ScriptError serror = SCRIPT_ERR_OK; - assert(VerifyScript(final_spending_tx.vin[i].scriptSig, - prevPubKey, - STANDARD_SCRIPT_VERIFY_FLAGS, - TransactionSignatureChecker(&final_spending_tx, i, 1000000, txdata), - consensusBranchId, - &serror)); - } - return timer_stop(tv_start); -} - -extern UniValue getnewaddress(const UniValue& params, bool fHelp, const CPubKey& mypk); // in rpcwallet.cpp -extern UniValue sendtoaddress(const UniValue& params, bool fHelp, const CPubKey& mypk); - -double benchmark_sendtoaddress(CAmount amount) -{ - UniValue params(UniValue::VARR); - auto addr = getnewaddress(params, false, CPubKey()); - - params.push_back(addr); - params.push_back(ValueFromAmount(amount)); - - struct timeval tv_start; - timer_start(tv_start); - auto txid = sendtoaddress(params, false, CPubKey()); - return timer_stop(tv_start); -} - -double benchmark_loadwallet() -{ - pre_wallet_load(); - struct timeval tv_start; - bool fFirstRunRet=true; - timer_start(tv_start); - pwalletMain = new CWallet("wallet.dat"); - DBErrors nLoadWalletRet = pwalletMain->LoadWallet(fFirstRunRet); - auto res = timer_stop(tv_start); - post_wallet_load(); - return res; -} - -extern UniValue listunspent(const UniValue& params, bool fHelp, const CPubKey& mypk); - -double benchmark_listunspent() -{ - UniValue params(UniValue::VARR); - struct timeval tv_start; - timer_start(tv_start); - auto unspent = listunspent(params, false, CPubKey()); - return timer_stop(tv_start); -} - -double benchmark_create_sapling_spend() -{ - auto sk = libzcash::SaplingSpendingKey::random(); - auto expsk = sk.expanded_spending_key(); - auto address = sk.default_address(); - SaplingNote note(address, GetRand(MAX_MONEY)); - SaplingMerkleTree tree; - auto maybe_cm = note.cm(); - tree.append(maybe_cm.get()); - auto anchor = tree.root(); - auto witness = tree.witness(); - auto maybe_nf = note.nullifier(expsk.full_viewing_key(), witness.position()); - if (!(maybe_cm && maybe_nf)) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "Could not create note commitment and nullifier"); - } - - CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); - ss << witness.path(); - std::vector witnessChars(ss.begin(), ss.end()); - - uint256 alpha; - librustzcash_sapling_generate_r(alpha.begin()); - - auto ctx = librustzcash_sapling_proving_ctx_init(); - - struct timeval tv_start; - timer_start(tv_start); - - SpendDescription sdesc; - bool result = librustzcash_sapling_spend_proof( - ctx, - expsk.full_viewing_key().ak.begin(), - expsk.nsk.begin(), - note.d.data(), - note.r.begin(), - alpha.begin(), - note.value(), - anchor.begin(), - witnessChars.data(), - sdesc.cv.begin(), - sdesc.rk.begin(), - sdesc.zkproof.data()); - - double t = timer_stop(tv_start); - librustzcash_sapling_proving_ctx_free(ctx); - if (!result) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "librustzcash_sapling_spend_proof() should return true"); - } - return t; -} - -double benchmark_create_sapling_output() -{ - auto sk = libzcash::SaplingSpendingKey::random(); - auto address = sk.default_address(); - - std::array memo; - SaplingNote note(address, GetRand(MAX_MONEY)); - - libzcash::SaplingNotePlaintext notePlaintext(note, memo); - auto res = notePlaintext.encrypt(note.pk_d); - if (!res) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "SaplingNotePlaintext::encrypt() failed"); - } - - auto enc = res.get(); - auto encryptor = enc.second; - - auto ctx = librustzcash_sapling_proving_ctx_init(); - - struct timeval tv_start; - timer_start(tv_start); - - OutputDescription odesc; - bool result = librustzcash_sapling_output_proof( - ctx, - encryptor.get_esk().begin(), - note.d.data(), - note.pk_d.begin(), - note.r.begin(), - note.value(), - odesc.cv.begin(), - odesc.zkproof.begin()); - - double t = timer_stop(tv_start); - librustzcash_sapling_proving_ctx_free(ctx); - if (!result) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "librustzcash_sapling_output_proof() should return true"); - } - return t; -} - -// Verify Sapling spend from testnet -// txid: abbd823cbd3d4e3b52023599d81a96b74817e95ce5bb58354f979156bd22ecc8 -// position: 0 -double benchmark_verify_sapling_spend() -{ - SpendDescription spend; - CDataStream ss(ParseHex("8c6cf86bbb83bf0d075e5bd9bb4b5cd56141577be69f032880b11e26aa32aa5ef09fd00899e4b469fb11f38e9d09dc0379f0b11c23b5fe541765f76695120a03f0261d32af5d2a2b1e5c9a04200cd87d574dc42349de9790012ce560406a8a876a1e54cfcdc0eb74998abec2a9778330eeb2a0ac0e41d0c9ed5824fbd0dbf7da930ab299966ce333fd7bc1321dada0817aac5444e02c754069e218746bf879d5f2a20a8b028324fb2c73171e63336686aa5ec2e6e9a08eb18b87c14758c572f4531ccf6b55d09f44beb8b47563be4eff7a52598d80959dd9c9fee5ac4783d8370cb7d55d460053d3e067b5f9fe75ff2722623fb1825fcba5e9593d4205b38d1f502ff03035463043bd393a5ee039ce75a5d54f21b395255df6627ef96751566326f7d4a77d828aa21b1827282829fcbc42aad59cdb521e1a3aaa08b99ea8fe7fff0a04da31a52260fc6daeccd79bb877bdd8506614282258e15b3fe74bf71a93f4be3b770119edf99a317b205eea7d5ab800362b97384273888106c77d633600"), SER_NETWORK, PROTOCOL_VERSION); - ss >> spend; - uint256 dataToBeSigned = uint256S("0x2dbf83fe7b88a7cbd80fac0c719483906bb9a0c4fc69071e4780d5f2c76e592c"); - - auto ctx = librustzcash_sapling_verification_ctx_init(); - - struct timeval tv_start; - timer_start(tv_start); - - bool result = librustzcash_sapling_check_spend( - ctx, - spend.cv.begin(), - spend.anchor.begin(), - spend.nullifier.begin(), - spend.rk.begin(), - spend.zkproof.begin(), - spend.spendAuthSig.begin(), - dataToBeSigned.begin() - ); - - double t = timer_stop(tv_start); - librustzcash_sapling_verification_ctx_free(ctx); - if (!result) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "librustzcash_sapling_check_spend() should return true"); - } - return t; -} - -// Verify Sapling output from testnet -// txid: abbd823cbd3d4e3b52023599d81a96b74817e95ce5bb58354f979156bd22ecc8 -// position: 0 -double benchmark_verify_sapling_output() -{ - OutputDescription output; - CDataStream ss(ParseHex("edd742af18857e5ec2d71d346a7fe2ac97c137339bd5268eea86d32e0ff4f38f76213fa8cfed3347ac4e8572dd88aff395c0c10a59f8b3f49d2bc539ed6c726667e29d4763f914ddd0abf1cdfa84e44de87c233434c7e69b8b5b8f4623c8aa444163425bae5cef842972fed66046c1c6ce65c866ad894d02e6e6dcaae7a962d9f2ef95757a09c486928e61f0f7aed90ad0a542b0d3dc5fe140dfa7626b9315c77e03b055f19cbacd21a866e46f06c00e0c7792b2a590a611439b510a9aaffcf1073bad23e712a9268b36888e3727033eee2ab4d869f54a843f93b36ef489fb177bf74b41a9644e5d2a0a417c6ac1c8869bc9b83273d453f878ed6fd96b82a5939903f7b64ecaf68ea16e255a7fb7cc0b6d8b5608a1c6b0ed3024cc62c2f0f9c5cfc7b431ae6e9d40815557aa1d010523f9e1960de77b2274cb6710d229d475c87ae900183206ba90cb5bbc8ec0df98341b82726c705e0308ca5dc08db4db609993a1046dfb43dfd8c760be506c0bed799bb2205fc29dc2e654dce731034a23b0aaf6da0199248702ee0523c159f41f4cbfff6c35ace4dd9ae834e44e09c76a0cbdda1d3f6a2c75ad71212daf9575ab5f09ca148718e667f29ddf18c8a330a86ace18a86e89454653902aa393c84c6b694f27d0d42e24e7ac9fe34733de5ec15f5066081ce912c62c1a804a2bb4dedcef7cc80274f6bb9e89e2fce91dc50d6a73c8aefb9872f1cf3524a92626a0b8f39bbf7bf7d96ca2f770fc04d7f457021c536a506a187a93b2245471ddbfb254a71bc4a0d72c8d639a31c7b1920087ffca05c24214157e2e7b28184e91989ef0b14f9b34c3dc3cc0ac64226b9e337095870cb0885737992e120346e630a416a9b217679ce5a778fb15779c136bcecca5efe79012013d77d90b4e99dd22c8f35bc77121716e160d05bd30d288ee8886390ee436f85bdc9029df888a3a3326d9d4ddba5cb5318b3274928829d662e96fea1d601f7a306251ed8c6cc4e5a3a7a98c35a3650482a0eee08f3b4c2da9b22947c96138f1505c2f081f8972d429f3871f32bef4aaa51aa6945df8e9c9760531ac6f627d17c1518202818a91ca304fb4037875c666060597976144fcbbc48a776a2c61beb9515fa8f3ae6d3a041d320a38a8ac75cb47bb9c866ee497fc3cd13299970c4b369c1c2ceb4220af082fbecdd8114492a8e4d713b5a73396fd224b36c1185bd5e20d683e6c8db35346c47ae7401988255da7cfffdced5801067d4d296688ee8fe424b4a8a69309ce257eefb9345ebfda3f6de46bb11ec94133e1f72cd7ac54934d6cf17b3440800e70b80ebc7c7bfc6fb0fc2c"), SER_NETWORK, PROTOCOL_VERSION); - ss >> output; - - auto ctx = librustzcash_sapling_verification_ctx_init(); - - struct timeval tv_start; - timer_start(tv_start); - - bool result = librustzcash_sapling_check_output( - ctx, - output.cv.begin(), - output.cm.begin(), - output.ephemeralKey.begin(), - output.zkproof.begin() - ); - - double t = timer_stop(tv_start); - librustzcash_sapling_verification_ctx_free(ctx); - if (!result) { - throw JSONRPCError(RPC_INTERNAL_ERROR, "librustzcash_sapling_check_output() should return true"); - } - return timer_stop(tv_start); -} diff --git a/src/zcbenchmarks.h b/src/zcbenchmarks.h deleted file mode 100644 index c79081bc2..000000000 --- a/src/zcbenchmarks.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2016-2021 The Hush developers -#ifndef BENCHMARKS_H -#define BENCHMARKS_H - -#include -#include - -extern double benchmark_sleep(); -extern double benchmark_create_joinsplit(); -extern std::vector benchmark_create_joinsplit_threaded(int nThreads); -extern double benchmark_solve_equihash(); -extern std::vector benchmark_solve_equihash_threaded(int nThreads); -extern double benchmark_verify_joinsplit(const JSDescription &joinsplit); -extern double benchmark_verify_equihash(); -extern double benchmark_large_tx(size_t nInputs); -extern double benchmark_try_decrypt_notes(size_t nAddrs); -extern double benchmark_increment_note_witnesses(size_t nTxs); -extern double benchmark_connectblock_slow(); -extern double benchmark_sendtoaddress(CAmount amount); -extern double benchmark_loadwallet(); -extern double benchmark_listunspent(); -extern double benchmark_create_sapling_spend(); -extern double benchmark_create_sapling_output(); -extern double benchmark_verify_sapling_spend(); -extern double benchmark_verify_sapling_output(); - -#endif From b2987b43f01ef04bcfc6c67557b4a1db904944d3 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Wed, 7 Sep 2022 01:10:53 -0400 Subject: [PATCH 141/255] miner: fix MAXSOLS --- src/miner.cpp | 2 +- src/test/miner_tests.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/miner.cpp b/src/miner.cpp index 71ce266ce..16c18146b 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1732,7 +1732,7 @@ void static BitcoinMiner() ehSolverRuns.increment(); // Convert solution indices to byte array (decompress) and pass it to validBlock method. - for (size_t s = 0; s < eq.nsols; s++) { + for (size_t s = 0; s < std::min(MAXSOLS, eq.nsols); s++) { LogPrint("pow", "Checking solution %d\n", s+1); std::vector index_vector(PROOFSIZE); for (size_t i = 0; i < PROOFSIZE; i++) { diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index ed2777c6d..52f0a0211 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -225,7 +225,7 @@ BOOST_AUTO_TEST_CASE(CreateNewBlock_validity) // Convert solution indices to byte array (decompress) and pass it to validBlock method. std::set> solns; - for (size_t s = 0; s < eq.nsols; s++) { + for (size_t s = 0; s < std::min(MAXSOLS, eq.nsols); s++) { LogPrint("pow", "Checking solution %d\n", s+1); std::vector index_vector(PROOFSIZE); for (size_t i = 0; i < PROOFSIZE; i++) { From 8770fb7035f098cdd54f9c6eba9fe48b9197b893 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Thu, 8 Sep 2022 18:11:10 -0700 Subject: [PATCH 142/255] Hopefully avoid a coredump when consolidation=1 and consolidatesaplingaddress is not specified --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index ce03bd7fb..31073cf16 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2100,11 +2100,11 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if (pwalletMain->fSaplingConsolidationEnabled) { //Validate 1 Consolidation address only that matches the sweep address vector& vaddresses = mapMultiArgs["-consolidatesaplingaddress"]; - pwalletMain->consolidationAddress = vaddresses[0]; if (vaddresses.size() == 0) { fConsolidationMapUsed = true; mapMultiArgs["-consolidatesaplingaddress"] = vSweep; } else { + pwalletMain->consolidationAddress = vaddresses[0]; for (int i = 0; i < vaddresses.size(); i++) { if (vSweep[0] != vaddresses[i]) { return InitError("Consolidation can only be used on the sweep address when sweep is enabled."); From 4647bc85257033732a19c985f8fbe64f3328b15c Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 9 Sep 2022 06:30:06 -0700 Subject: [PATCH 143/255] Try to generate a stacktrace for runtime errors in consolidation --- src/wallet/asyncrpcoperation_saplingconsolidation.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index f9f2ebe1e..d75100be4 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -16,6 +16,7 @@ #include "util.h" #include "utilmoneystr.h" #include "wallet.h" +#include CAmount fConsolidationTxFee = DEFAULT_CONSOLIDATION_FEE; bool fConsolidationMapUsed = false; @@ -44,6 +45,11 @@ void AsyncRPCOperation_saplingconsolidation::main() { set_error_code(code); set_error_message(message); } catch (const runtime_error& e) { + const boost::stacktrace::stacktrace* st = boost::get_error_info(e); + if (st) { + std::cerr << *st << '\n'; + } + set_error_code(-1); set_error_code(-1); set_error_message("runtime error: " + string(e.what())); } catch (const logic_error& e) { From 8f49549a1d4fc3ae3808b47bfdeeb9e672308a94 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 9 Sep 2022 09:37:16 -0400 Subject: [PATCH 144/255] Fix stacktrace --- src/wallet/asyncrpcoperation_saplingconsolidation.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index d75100be4..e578958bc 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -45,10 +45,7 @@ void AsyncRPCOperation_saplingconsolidation::main() { set_error_code(code); set_error_message(message); } catch (const runtime_error& e) { - const boost::stacktrace::stacktrace* st = boost::get_error_info(e); - if (st) { - std::cerr << *st << '\n'; - } + std::cerr << boost::stacktrace::stacktrace() << '\n'; set_error_code(-1); set_error_code(-1); set_error_message("runtime error: " + string(e.what())); From 85f7ac4c8c22600443e354c488829910abe40bc9 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 9 Sep 2022 15:14:01 -0700 Subject: [PATCH 145/255] Enable function names and line numbers in backtraces --- src/wallet/asyncrpcoperation_saplingconsolidation.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index e578958bc..79a0342a0 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -17,6 +17,11 @@ #include "utilmoneystr.h" #include "wallet.h" #include +#include + +// enable function names and line numbers in backtraces +#define BOOST_STACKTRACE_LINK +#define BOOST_STACKTRACE_USE_ADDR2LINE CAmount fConsolidationTxFee = DEFAULT_CONSOLIDATION_FEE; bool fConsolidationMapUsed = false; From 1259dd512dfe36cd0a8fe1a9bfd5b49a538bd00c Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 10 Sep 2022 19:37:34 -0400 Subject: [PATCH 146/255] Fix 'not enough conversion params' bug --- src/wallet/asyncrpcoperation_saplingconsolidation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index 79a0342a0..0d5fa35aa 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -86,7 +86,7 @@ void AsyncRPCOperation_saplingconsolidation::main() { bool AsyncRPCOperation_saplingconsolidation::main_impl() { bool status=true; auto opid=getId(); - LogPrintf("%s: Beginning AsyncRPCOperation_saplingconsolidation.\n", __func__, opid); + LogPrintf("%s: Beginning AsyncRPCOperation_saplingconsolidation\n", opid); auto consensusParams = Params().GetConsensus(); auto nextActivationHeight = NextActivationHeight(targetHeight_, consensusParams); if (nextActivationHeight && targetHeight_ + CONSOLIDATION_EXPIRY_DELTA >= nextActivationHeight.get()) { From 772160af6d940889608e6494ddf9f77a2d93eda1 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 10 Sep 2022 19:38:08 -0400 Subject: [PATCH 147/255] Add more logging for consolidation + sweeping --- .../asyncrpcoperation_saplingconsolidation.cpp | 4 ++-- src/wallet/wallet.cpp | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index 0d5fa35aa..6eb20d2e6 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -50,7 +50,7 @@ void AsyncRPCOperation_saplingconsolidation::main() { set_error_code(code); set_error_message(message); } catch (const runtime_error& e) { - std::cerr << boost::stacktrace::stacktrace() << '\n'; + std::cerr << "Consolidation stacktrace:" << '\n' << boost::stacktrace::stacktrace() << '\n'; set_error_code(-1); set_error_code(-1); set_error_message("runtime error: " + string(e.what())); @@ -73,7 +73,7 @@ void AsyncRPCOperation_saplingconsolidation::main() { set_state(OperationStatus::FAILED); } - std::string s = strprintf("%s: Sapling Consolidation transaction created. (status=%s", getId(), getStateAsString()); + std::string s = strprintf("%s: Sapling Consolidation operation complete. (status=%s", getId(), getStateAsString()); if (success) { s += strprintf(", success)\n"); } else { diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 8cee74ed2..e8434afcf 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -515,13 +515,14 @@ void CWallet::RunSaplingSweep(int blockHeight) { return; } + LogPrintf("%s: Sweep enabled at blockHeight=%d nextSweep=%d\n", __func__, blockHeight, nextSweep); if (nextSweep > blockHeight) { return; } //Don't Run if consolidation will run soon. if (fSaplingConsolidationEnabled && nextConsolidation - 5 <= blockHeight) { - LogPrintf("%s: not consolidating since next sweep is within 5 blocks\n", __func__); + LogPrintf("%s: not sweeping since next consolidation is within 5 blocks, nextConsolidation=%d , blockHeight=%d\n", __func__, nextConsolidation, blockHeight); return; } @@ -545,9 +546,10 @@ void CWallet::RunSaplingSweep(int blockHeight) { } void CWallet::RunSaplingConsolidation(int blockHeight) { - if (!NetworkUpgradeActive(blockHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) { - return; - } + // Sapling is always active on HUSH+HSCs + //if (!NetworkUpgradeActive(blockHeight, Params().GetConsensus(), Consensus::UPGRADE_SAPLING)) { + // return; + //} LOCK(cs_wallet); @@ -555,6 +557,8 @@ void CWallet::RunSaplingConsolidation(int blockHeight) { return; } + LogPrintf("%s: consolidation enabled at blockHeight=%d fSweepRunning=%d\n", __func__, blockHeight, fSweepRunning ); + if (fSweepRunning) { return; } @@ -565,6 +569,7 @@ void CWallet::RunSaplingConsolidation(int blockHeight) { fprintf(stderr,"%s: height=%d interval=%d\n", __func__, blockHeight, consolidateInterval); if (blockHeight % consolidateInterval == 0) { + LogPrintf("%s: creating consolidation operation at blockHeight=%d\n", __func__, blockHeight); std::shared_ptr q = getAsyncRPCQueue(); std::shared_ptr lastOperation = q->getOperationForId(saplingConsolidationOperationId); if (lastOperation != nullptr) { From b06c3788510556b99cc61a829cb7e3874d52323a Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sun, 11 Sep 2022 18:01:11 -0400 Subject: [PATCH 148/255] removed unused function mta_find_output --- .../asyncrpcoperation_mergetoaddress.cpp | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.cpp b/src/wallet/asyncrpcoperation_mergetoaddress.cpp index ac462f5b8..d1f207571 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.cpp +++ b/src/wallet/asyncrpcoperation_mergetoaddress.cpp @@ -52,24 +52,6 @@ using namespace libzcash; extern UniValue sendrawtransaction(const UniValue& params, bool fHelp, const CPubKey& mypk); -int mta_find_output(UniValue obj, int n) -{ - UniValue outputMapValue = find_value(obj, "outputmap"); - if (!outputMapValue.isArray()) { - throw JSONRPCError(RPC_WALLET_ERROR, "Missing outputmap for JoinSplit operation"); - } - - UniValue outputMap = outputMapValue.get_array(); - assert(outputMap.size() == HUSH_NUM_JS_OUTPUTS); - for (size_t i = 0; i < outputMap.size(); i++) { - if (outputMap[i].get_int() == n) { - return i; - } - } - - throw std::logic_error("n is not present in outputmap"); -} - AsyncRPCOperation_mergetoaddress::AsyncRPCOperation_mergetoaddress( boost::optional builder, CMutableTransaction contextualTx, From 2a1cad1e5fbdf8081869a53b4399ef38c057ff87 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 11 Sep 2022 20:10:28 -0400 Subject: [PATCH 149/255] Fix bug in z_sweepstatus --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 745dc3ce4..ced9b19b2 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3381,7 +3381,7 @@ UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk) if (pwalletMain->fConsolidationRunning) { ret.push_back(Pair("next_zsweep", pwalletMain->sweepInterval + chainActive.Tip()->GetHeight())); } else { - if (pwalletMain->nextConsolidation == 0) { + if (pwalletMain->nextSweep == 0) { ret.push_back(Pair("next_zsweep", chainActive.Tip()->GetHeight() + 1)); } else { ret.push_back(Pair("next_zsweep", pwalletMain->nextSweep)); From 9347b1fa12215ce7291222656895d1bdb0bceb5a Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 11 Sep 2022 20:18:01 -0400 Subject: [PATCH 150/255] Sweep Interval should be 10 to match other defaults --- src/wallet/wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index fdaee018b..147ed6dbc 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -810,7 +810,7 @@ public: int nextSweep = 0; int amountSwept = 0; int amountConsolidated = 0; - int sweepInterval = 20; + int sweepInterval = 10; int sweepFee = 10000; int sweepMaxInputs = 200; std::string sweepAddress = ""; From 5b15d790f9cd09779b7c842ce4eb01cadeafa4a1 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 11 Sep 2022 21:56:21 -0400 Subject: [PATCH 151/255] Parse sweep+consolidation intervals on startup, add consolidationinterval config option, change consolidation interval default to 25, only validate consolidatesaplingaddress if consolidation is enabled --- src/init.cpp | 38 ++++++++++++++++++------ src/wallet/asyncrpcoperation_sweep.cpp | 7 +---- src/wallet/rpcwallet.cpp | 25 ++-------------- src/wallet/wallet.cpp | 40 +++++++++++++------------- src/wallet/wallet.h | 1 + 5 files changed, 54 insertions(+), 57 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 31073cf16..f71423e2a 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2052,16 +2052,28 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) //Set Sapling Consolidation pwalletMain->fSaplingConsolidationEnabled = GetBoolArg("-consolidation", false); - fConsolidationTxFee = GetArg("-consolidationtxfee", DEFAULT_CONSOLIDATION_FEE); - fConsolidationMapUsed = !mapMultiArgs["-consolidatesaplingaddress"].empty(); + if(pwalletMain->fSaplingConsolidationEnabled) { + fConsolidationTxFee = GetArg("-consolidationtxfee", DEFAULT_CONSOLIDATION_FEE); + fConsolidationMapUsed = !mapMultiArgs["-consolidatesaplingaddress"].empty(); - //Validate Sapling Addresses - vector& vaddresses = mapMultiArgs["-consolidatesaplingaddress"]; - for (int i = 0; i < vaddresses.size(); i++) { - LogPrintf("Consolidating Sapling Address: %s\n", vaddresses[i]); - auto zAddress = DecodePaymentAddress(vaddresses[i]); - if (!IsValidPaymentAddress(zAddress)) { - return InitError("Invalid consolidation address"); + int consolidationInterval = GetArg("-consolidationinterval", 25); + if (consolidationInterval < 5) { + fprintf(stderr,"%s: Invalid consolidation interval of %d < 5, setting to default of 25\n", __func__, consolidationInterval); + consolidationInterval = 25; + } + + pwalletMain->consolidationInterval = consolidationInterval; + pwalletMain->nextConsolidation = pwalletMain->consolidationInterval + chainActive.Tip()->GetHeight(); + LogPrintf("%s: set nextConsolidation=%d\n", __func__, pwalletMain->nextConsolidation ); + + //Validate Sapling Addresses + vector& vaddresses = mapMultiArgs["-consolidatesaplingaddress"]; + for (int i = 0; i < vaddresses.size(); i++) { + LogPrintf("Consolidating Sapling Address: %s\n", vaddresses[i]); + auto zAddress = DecodePaymentAddress(vaddresses[i]); + if (!IsValidPaymentAddress(zAddress)) { + return InitError("Invalid consolidation address"); + } } } @@ -2069,6 +2081,14 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) pwalletMain->fSweepEnabled = GetBoolArg("-zsweep", false); if (pwalletMain->fSweepEnabled) { + int sweepInterval = GetArg("-zsweepinterval", 10); + if (sweepInterval < 5) { + fprintf(stderr,"%s: Invalid sweep interval of %d, setting to default of 10\n", __func__, sweepInterval); + sweepInterval = 10; + } + pwalletMain->sweepInterval = sweepInterval; + pwalletMain->nextSweep = pwalletMain->sweepInterval + chainActive.Tip()->GetHeight(); + LogPrintf("%s: set nextSweep=%d with sweepInterval=%d\n", __func__, pwalletMain->nextSweep, pwalletMain->sweepInterval ); fSweepTxFee = GetArg("-zsweepfee", DEFAULT_SWEEP_FEE); fSweepMapUsed = !mapMultiArgs["-zsweepaddress"].empty(); diff --git a/src/wallet/asyncrpcoperation_sweep.cpp b/src/wallet/asyncrpcoperation_sweep.cpp index 6045cf46f..1e7d324af 100644 --- a/src/wallet/asyncrpcoperation_sweep.cpp +++ b/src/wallet/asyncrpcoperation_sweep.cpp @@ -284,12 +284,7 @@ bool AsyncRPCOperation_sweep::main_impl() { } if (sweepComplete) { - int sweepInterval = GetArg("-zsweepinterval", 10); - if (sweepInterval < 5) { - fprintf(stderr,"%s: Invalid sweep interval of %d, setting to default of 10\n", __func__, sweepInterval); - sweepInterval = 10; - } - pwalletMain->nextSweep = sweepInterval + chainActive.Tip()->GetHeight(); + pwalletMain->nextSweep = pwalletMain->sweepInterval + chainActive.Tip()->GetHeight(); pwalletMain->fSweepRunning = false; } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index ced9b19b2..eaa9e436a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3337,18 +3337,8 @@ UniValue z_consolidationstatus(const UniValue& params, bool fHelp, const CPubKey ret.push_back(Pair("consolidation", pwalletMain->fSaplingConsolidationEnabled)); ret.push_back(Pair("running", pwalletMain->fConsolidationRunning)); ret.push_back(Pair("amount_consolidated", pwalletMain->amountConsolidated)); - - if (pwalletMain->fConsolidationRunning) { - // TODO: set a static consolidationInterval instead of it being non-deterministic - // ret.push_back(Pair("next_consolidation", pwalletMain->consolidationInterval + chainActive.Tip()->GetHeight())); - } else { - if (pwalletMain->nextConsolidation == 0) { - ret.push_back(Pair("next_consolidation", chainActive.Tip()->GetHeight() + 1)); - } else { - ret.push_back(Pair("next_consolidation", pwalletMain->nextConsolidation)); - } - } - // ret.push_back(Pair("consolidationinterval", pwalletMain->consolidationInterval)); + ret.push_back(Pair("next_consolidation", pwalletMain->nextConsolidation)); + ret.push_back(Pair("consolidationinterval", pwalletMain->consolidationInterval)); ret.push_back(Pair("consolidationaddress", pwalletMain->consolidationAddress)); ret.push_back(Pair("consolidationtxfee",(int)fConsolidationTxFee)); @@ -3377,16 +3367,7 @@ UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk) ret.push_back(Pair("zsweep", pwalletMain->fSweepEnabled)); ret.push_back(Pair("running", pwalletMain->fSweepRunning)); ret.push_back(Pair("amount_swept", pwalletMain->amountSwept)); - - if (pwalletMain->fConsolidationRunning) { - ret.push_back(Pair("next_zsweep", pwalletMain->sweepInterval + chainActive.Tip()->GetHeight())); - } else { - if (pwalletMain->nextSweep == 0) { - ret.push_back(Pair("next_zsweep", chainActive.Tip()->GetHeight() + 1)); - } else { - ret.push_back(Pair("next_zsweep", pwalletMain->nextSweep)); - } - } + ret.push_back(Pair("next_zsweep", pwalletMain->nextSweep)); ret.push_back(Pair("zsweepinterval", pwalletMain->sweepInterval)); ret.push_back(Pair("zsweepaddress", pwalletMain->sweepAddress)); ret.push_back(Pair("zsweepmaxinputs", pwalletMain->sweepMaxInputs)); diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e8434afcf..85faac38b 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -515,10 +515,11 @@ void CWallet::RunSaplingSweep(int blockHeight) { return; } - LogPrintf("%s: Sweep enabled at blockHeight=%d nextSweep=%d\n", __func__, blockHeight, nextSweep); if (nextSweep > blockHeight) { + LogPrintf("%s: Not time to sweep yet at blockHeight=%d nextSweep=%d\n", __func__, blockHeight, nextSweep); return; } + LogPrintf("%s: Sweep enabled at blockHeight=%d nextSweep=%d\n", __func__, blockHeight, nextSweep); //Don't Run if consolidation will run soon. if (fSaplingConsolidationEnabled && nextConsolidation - 5 <= blockHeight) { @@ -528,7 +529,7 @@ void CWallet::RunSaplingSweep(int blockHeight) { //Don't Run While consolidation is running. if (fConsolidationRunning) { - LogPrintf("%s: not sweeping since consolidation is currently running\n", __func__); + LogPrintf("%s: not sweeping since consolidation is currently running at height=%d\n", __func__, blockHeight); return; } @@ -557,29 +558,28 @@ void CWallet::RunSaplingConsolidation(int blockHeight) { return; } - LogPrintf("%s: consolidation enabled at blockHeight=%d fSweepRunning=%d\n", __func__, blockHeight, fSweepRunning ); - - if (fSweepRunning) { + if (nextConsolidation > blockHeight) { + LogPrintf("%s: Not time to consolidate yet at blockHeight=%d nextConsolidation=%d\n", __func__, blockHeight, nextConsolidation); return; } - int consolidateInterval = 45; + LogPrintf("%s: consolidation enabled at blockHeight=%d fSweepRunning=%d\n", __func__, blockHeight, fSweepRunning ); - if(fZdebug) - fprintf(stderr,"%s: height=%d interval=%d\n", __func__, blockHeight, consolidateInterval); - - if (blockHeight % consolidateInterval == 0) { - LogPrintf("%s: creating consolidation operation at blockHeight=%d\n", __func__, blockHeight); - std::shared_ptr q = getAsyncRPCQueue(); - std::shared_ptr lastOperation = q->getOperationForId(saplingConsolidationOperationId); - if (lastOperation != nullptr) { - lastOperation->cancel(); - } - pendingSaplingConsolidationTxs.clear(); - std::shared_ptr operation(new AsyncRPCOperation_saplingconsolidation(blockHeight + 5)); - saplingConsolidationOperationId = operation->getId(); - q->addOperation(operation); + if (fSweepRunning) { + LogPrintf("%s: not consolidating since sweep is currently running at height=%d\n", __func__, blockHeight); + return; } + + LogPrintf("%s: creating consolidation operation at blockHeight=%d\n", __func__, blockHeight); + std::shared_ptr q = getAsyncRPCQueue(); + std::shared_ptr lastOperation = q->getOperationForId(saplingConsolidationOperationId); + if (lastOperation != nullptr) { + lastOperation->cancel(); + } + pendingSaplingConsolidationTxs.clear(); + std::shared_ptr operation(new AsyncRPCOperation_saplingconsolidation(blockHeight + 5)); + saplingConsolidationOperationId = operation->getId(); + q->addOperation(operation); } bool CWallet::CommitAutomatedTx(const CTransaction& tx) { diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 147ed6dbc..f5e07e9da 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -811,6 +811,7 @@ public: int amountSwept = 0; int amountConsolidated = 0; int sweepInterval = 10; + int consolidationInterval = 25; int sweepFee = 10000; int sweepMaxInputs = 200; std::string sweepAddress = ""; From bd9006623c2ae9e1489111d64c87f5a3e7d29a94 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 11 Sep 2022 22:41:03 -0400 Subject: [PATCH 152/255] Avoid coredumps in ReacceptWalletTransactions and log the situation, which is possibly caused by corrupt wallet tx data --- src/wallet/wallet.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 85faac38b..e9450161f 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -2847,7 +2847,12 @@ void CWallet::ReacceptWalletTransactions() { const uint256& wtxid = item.first; CWalletTx& wtx = item.second; - assert(wtx.GetHash() == wtxid); + if(wtx.GetHash() != wtxid) { + LogPrintf("%s: Something funky going on, skipping this tx. wtx.GetHash() != wtxid (%s != %s)\n", __func__, wtx.GetHash().ToString().c_str(), wtxid.ToString().c_str() ); + continue; + } + // Crashing the node because of this is lame + // assert(wtx.GetHash() == wtxid); int nDepth = wtx.GetDepthInMainChain(); From 0edc5927e9da3f746093a0b1a2e201eba2717eeb Mon Sep 17 00:00:00 2001 From: jahway603 Date: Mon, 12 Sep 2022 00:50:50 -0400 Subject: [PATCH 153/255] depends: Add FreeBSD to hosts and builders --- depends/Makefile | 2 ++ depends/builders/freebsd.mk | 4 ++++ depends/hosts/freebsd.mk | 31 +++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 depends/builders/freebsd.mk create mode 100644 depends/hosts/freebsd.mk diff --git a/depends/Makefile b/depends/Makefile index 82acde0ac..05abb94db 100644 --- a/depends/Makefile +++ b/depends/Makefile @@ -39,6 +39,7 @@ build_vendor=$(word 2,$(subst -, ,$(build))) full_build_os:=$(subst $(build_arch)-$(build_vendor)-,,$(build)) build_os:=$(findstring linux,$(full_build_os)) build_os+=$(findstring darwin,$(full_build_os)) +build_os+=$(findstring freebsd,$(full_build_os)) build_os:=$(strip $(build_os)) ifeq ($(build_os),) build_os=$(full_build_os) @@ -49,6 +50,7 @@ host_vendor=$(word 2,$(subst -, ,$(canonical_host))) full_host_os:=$(subst $(host_arch)-$(host_vendor)-,,$(canonical_host)) host_os:=$(findstring linux,$(full_host_os)) host_os+=$(findstring darwin,$(full_host_os)) +host_os+=$(findstring freebsd,$(full_host_os)) host_os+=$(findstring mingw32,$(full_host_os)) host_os:=$(strip $(host_os)) ifeq ($(host_os),) diff --git a/depends/builders/freebsd.mk b/depends/builders/freebsd.mk new file mode 100644 index 000000000..7a61043e9 --- /dev/null +++ b/depends/builders/freebsd.mk @@ -0,0 +1,4 @@ +build_freebsd_CC = clang +build_freebsd_CXX = clang++ +build_freebsd_SHA256SUM = shasum -a 256 +build_freebsd_DOWNLOAD = curl --location --fail --connect-timeout $(DOWNLOAD_CONNECT_TIMEOUT) --retry $(DOWNLOAD_RETRIES) -o diff --git a/depends/hosts/freebsd.mk b/depends/hosts/freebsd.mk new file mode 100644 index 000000000..07436aef8 --- /dev/null +++ b/depends/hosts/freebsd.mk @@ -0,0 +1,31 @@ +freebsd_CFLAGS=-pipe +freebsd_CXXFLAGS=$(freebsd_CFLAGS) + +freebsd_release_CFLAGS=-O1 +freebsd_release_CXXFLAGS=$(freebsd_release_CFLAGS) + +freebsd_debug_CFLAGS=-O1 +freebsd_debug_CXXFLAGS=$(freebsd_debug_CFLAGS) + +freebsd_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC + +ifeq (86,$(findstring 86,$(build_arch))) +i686_freebsd_CC=gcc -m32 +i686_freebsd_CXX=g++ -m32 +i686_freebsd_AR=ar +i686_freebsd_RANLIB=ranlib +i686_freebsd_NM=nm +i686_freebsd_STRIP=strip + +x86_64_freebsd_CC=gcc -m64 +x86_64_freebsd_CXX=g++ -m64 +x86_64_freebsd_AR=ar +x86_64_freebsd_RANLIB=ranlib +x86_64_freebsd_NM=nm +x86_64_freebsd_STRIP=strip +else +i686_freebsd_CC=$(default_host_CC) -m32 +i686_freebsd_CXX=$(default_host_CXX) -m32 +x86_64_freebsd_CC=$(default_host_CC) -m64 +x86_64_freebsd_CXX=$(default_host_CXX) -m64 +endif From 1799c6c9bf15c38bbb9ffeea82404a4585241cae Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 12 Sep 2022 19:35:27 -0400 Subject: [PATCH 154/255] Remove zeromq support --- configure.ac | 40 ------ contrib/debian/copyright | 42 ------ contrib/zmq/zmq_sub.py | 45 ------ depends/packages/packages.mk | 2 +- depends/packages/zeromq.mk | 53 ------- doc/zmq.md | 107 -------------- qa/pull-tester/tests-config.sh.in | 1 - qa/rpc-tests/zmq_test.py | 93 ------------ src/Makefile.am | 23 +-- src/Makefile.gtest.include | 3 - src/Makefile.test.include | 4 - src/init.cpp | 35 +---- src/zmq/zmqabstractnotifier.cpp | 27 ---- src/zmq/zmqabstractnotifier.h | 45 ------ src/zmq/zmqconfig.h | 24 ---- src/zmq/zmqnotificationinterface.cpp | 181 ------------------------ src/zmq/zmqnotificationinterface.h | 39 ----- src/zmq/zmqpublishnotifier.cpp | 203 --------------------------- src/zmq/zmqpublishnotifier.h | 61 -------- 19 files changed, 3 insertions(+), 1025 deletions(-) delete mode 100755 contrib/zmq/zmq_sub.py delete mode 100644 depends/packages/zeromq.mk delete mode 100644 doc/zmq.md delete mode 100755 qa/rpc-tests/zmq_test.py delete mode 100644 src/zmq/zmqabstractnotifier.cpp delete mode 100644 src/zmq/zmqabstractnotifier.h delete mode 100644 src/zmq/zmqconfig.h delete mode 100644 src/zmq/zmqnotificationinterface.cpp delete mode 100644 src/zmq/zmqnotificationinterface.h delete mode 100644 src/zmq/zmqpublishnotifier.cpp delete mode 100644 src/zmq/zmqpublishnotifier.h diff --git a/configure.ac b/configure.ac index 794c486c0..801d7be75 100644 --- a/configure.ac +++ b/configure.ac @@ -151,12 +151,6 @@ AC_ARG_ENABLE([glibc-back-compat], [use_glibc_compat=$enableval], [use_glibc_compat=no]) -AC_ARG_ENABLE([zmq], - [AS_HELP_STRING([--disable-zmq], - [disable ZMQ notifications])], - [use_zmq=$enableval], - [use_zmq=yes]) - AC_ARG_ENABLE([experimental-asm], [AS_HELP_STRING([--enable-experimental-asm], [Enable experimental assembly routines (default is no)])], @@ -673,15 +667,6 @@ if test x$use_pkgconfig = xyes; then fi fi - if test "x$use_zmq" = "xyes"; then - PKG_CHECK_MODULES([ZMQ],[libzmq >= 4], - [AC_DEFINE([ENABLE_ZMQ],[1],[Define to 1 to enable ZMQ functions])], - [AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions]) - AC_MSG_WARN([libzmq version 4.x or greater not found, disabling]) - use_zmq=no]) - else - AC_DEFINE_UNQUOTED([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions]) - fi ] ) else @@ -718,28 +703,7 @@ fi #AC_CHECK_HEADER([gmpxx.h],,AC_MSG_ERROR(libgmpxx headers missing)) #AC_CHECK_LIB([gmpxx],[main],GMPXX_LIBS=-lgmpxx, [AC_MSG_ERROR(libgmpxx missing)]) - if test "x$use_zmq" = "xyes"; then - AC_CHECK_HEADER([zmq.h], - [AC_DEFINE([ENABLE_ZMQ],[1],[Define to 1 to enable ZMQ functions])], - [AC_MSG_WARN([zmq.h not found, disabling zmq support]) - use_zmq=no - AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])]) - AC_CHECK_LIB([zmq],[zmq_ctx_shutdown],ZMQ_LIBS=-lzmq, - [AC_MSG_WARN([libzmq >= 4.0 not found, disabling zmq support]) - use_zmq=no - AC_DEFINE([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions])]) - else - AC_DEFINE_UNQUOTED([ENABLE_ZMQ],[0],[Define to 1 to enable ZMQ functions]) - fi - if test "x$use_zmq" = "xyes"; then - dnl Assume libzmq was built for static linking - case $host in - *mingw*) - ZMQ_CFLAGS="$ZMQ_CFLAGS -DZMQ_STATIC" - ;; - esac - fi fi # These packages don't provide pkgconfig config files across all @@ -824,8 +788,6 @@ else AC_MSG_RESULT(no) fi -AM_CONDITIONAL([ENABLE_ZMQ], [test "x$use_zmq" = "xyes"]) - AC_MSG_CHECKING([whether to build test_bitcoin]) if test x$use_tests = xyes; then AC_MSG_RESULT([yes]) @@ -894,7 +856,6 @@ AC_SUBST(CRYPTO_LIBS) AC_SUBST(SSL_LIBS) AC_SUBST(EVENT_LIBS) AC_SUBST(EVENT_PTHREADS_LIBS) -AC_SUBST(ZMQ_LIBS) AC_SUBST(GMP_LIBS) AC_SUBST(GMPXX_LIBS) AC_SUBST(LIBZCASH_LIBS) @@ -944,7 +905,6 @@ esac echo echo "Options used to compile and link:" echo " with wallet = $enable_wallet" -echo " with zmq = $use_zmq" echo " with test = $use_tests" echo " debug enabled = $enable_debug" echo " werror = $enable_werror" diff --git a/contrib/debian/copyright b/contrib/debian/copyright index f2d71c287..7bf3a707c 100644 --- a/contrib/debian/copyright +++ b/contrib/debian/copyright @@ -23,19 +23,6 @@ Copyright: 1990, 2016 Oracle and/or its affiliates; 2000-2005 INRIA, France Telecom License: BDB -Files: depends/sources/zeromq-*.tar.gz -Copyright: - 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. - 2007-2014 iMatix Corporation - 2009-2011 250bpm s.r.o. - 2010-2011 Miru Limited - 2011 VMware, Inc. - 2012 Spotify AB - 2013 Ericsson AB - 2014 AppDynamics Inc. - 2015-2016 Brocade Communications Systems Inc. -License: LGPL-with-ZeroMQ-exception - Files: depends/sources/google*.tar.gz Copyright: 2008 Google Inc. License: BSD-3clause-Google @@ -1056,35 +1043,6 @@ Comment: You should have received a copy of the GNU General Public License along with this program. If not, see . -License: LGPL-with-ZeroMQ-exception - GNU LESSER GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - . - On Debian systems the GNU Lesser General Public License (LGPL) is - located in '/usr/share/common-licenses/LGPL'. - . - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - -------------------------------------------------------------------------------- - SPECIAL EXCEPTION GRANTED BY COPYRIGHT HOLDERS - . - As a special exception, copyright holders give you permission to link this - library with independent modules to produce an executable, regardless of - the license terms of these independent modules, and to copy and distribute - the resulting executable under terms of your choice, provided that you also - meet, for each linked independent module, the terms and conditions of - the license of that module. An independent module is a module which is not - derived from or based on this library. If you modify this library, you must - extend this exception to your version of the library. - - Note: this exception relieves you of any obligations under sections 4 and 5 - of this license, and section 6 of the GNU General Public License. -Comment: - You should have received a copy of the GNU General Public License - along with this program. If not, see . - License: GNU-All-permissive-License Copying and distribution of this file, with or without modification, are permitted in any medium without royalty provided the copyright notice diff --git a/contrib/zmq/zmq_sub.py b/contrib/zmq/zmq_sub.py deleted file mode 100755 index 902fc73c5..000000000 --- a/contrib/zmq/zmq_sub.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/env python2 -# Copyright (c) 2014-2016 The Bitcoin Core developers -# Copyright (c) 2016-2021 The Hush developers -# Distributed under the GPLv3 software license, see the accompanying -# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - -import array -import binascii -import zmq -import struct - -port = 28332 - -zmqContext = zmq.Context() -zmqSubSocket = zmqContext.socket(zmq.SUB) -zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "hashblock") -zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "hashtx") -zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "rawblock") -zmqSubSocket.setsockopt(zmq.SUBSCRIBE, "rawtx") -zmqSubSocket.connect("tcp://127.0.0.1:%i" % port) - -try: - while True: - msg = zmqSubSocket.recv_multipart() - topic = str(msg[0]) - body = msg[1] - sequence = "Unknown"; - if len(msg[-1]) == 4: - msgSequence = struct.unpack(' #include #include - -#if ENABLE_ZMQ -#include "zmq/zmqnotificationinterface.h" -#endif - #include "librustzcash.h" using namespace std; @@ -103,10 +98,6 @@ CWallet* pwalletMain = NULL; #endif bool fFeeEstimatesInitialized = false; -#if ENABLE_ZMQ -static CZMQNotificationInterface* pzmqNotificationInterface = NULL; -#endif - #ifdef WIN32 // Win32 LevelDB doesn't use file descriptors, and the ones used for // accessing block files don't count towards the fd_set size limit @@ -269,14 +260,6 @@ void Shutdown() pwalletMain->Flush(true); #endif -#if ENABLE_ZMQ - if (pzmqNotificationInterface) { - UnregisterValidationInterface(pzmqNotificationInterface); - delete pzmqNotificationInterface; - pzmqNotificationInterface = NULL; - } -#endif - #ifndef WIN32 try { boost::filesystem::remove(GetPidFile()); @@ -491,14 +474,6 @@ std::string HelpMessage(HelpMessageMode mode) " " + _("(1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data)")); #endif -#if ENABLE_ZMQ - strUsage += HelpMessageGroup(_("ZeroMQ notification options:")); - strUsage += HelpMessageOpt("-zmqpubhashblock=
", _("Enable publish hash block in
")); - strUsage += HelpMessageOpt("-zmqpubhashtx=
", _("Enable publish hash transaction in
")); - strUsage += HelpMessageOpt("-zmqpubrawblock=
", _("Enable publish raw block in
")); - strUsage += HelpMessageOpt("-zmqpubrawtx=
", _("Enable publish raw transaction in
")); -#endif - strUsage += HelpMessageGroup(_("Debugging/Testing options:")); if (showDebug) { @@ -512,7 +487,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-stopafterblockimport", strprintf("Stop running after importing blocks from disk (default: %u)", 0)); strUsage += HelpMessageOpt("-nuparams=hexBranchId:activationHeight", "Use given activation height for specified network upgrade (regtest-only)"); } - string debugCategories = "addrman, alert, bench, coindb, db, deletetx, estimatefee, http, libevent, lock, mempool, net, tls, partitioncheck, pow, proxy, prune, rand, randomx, reindex, rpc, selectcoins, stratum, tor, zmq, zrpc, zrpcunsafe (implies zrpc)"; // Don't translate these + string debugCategories = "addrman, alert, bench, coindb, db, deletetx, estimatefee, http, libevent, lock, mempool, net, tls, partitioncheck, pow, proxy, prune, rand, randomx, reindex, rpc, selectcoins, stratum, tor, zrpc, zrpcunsafe (implies zrpc)"; // Don't translate these strUsage += HelpMessageOpt("-debug=", strprintf(_("Output debugging information (default: %u, supplying is optional)"), 0) + ". " + _("If is not supplied or if = 1, output all debugging information.") + " " + _(" can be:") + " " + debugCategories + "."); strUsage += HelpMessageOpt("-experimentalfeatures", _("Enable use of experimental features")); @@ -1728,14 +1703,6 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) return InitError(strprintf(_("Cannot find trusted certificates directory: '%s'"), pathTLSTrustredDir.string())); } -#if ENABLE_ZMQ - pzmqNotificationInterface = CZMQNotificationInterface::CreateWithArguments(mapArgs); - - if (pzmqNotificationInterface) { - RegisterValidationInterface(pzmqNotificationInterface); - } -#endif - if ( HUSH_NSPV_SUPERLITE ) { std::vector vImportFiles; diff --git a/src/zmq/zmqabstractnotifier.cpp b/src/zmq/zmqabstractnotifier.cpp deleted file mode 100644 index b2f1d0833..000000000 --- a/src/zmq/zmqabstractnotifier.cpp +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2015 The Bitcoin Core developers -// Distributed under the GPLv3 software license, see the accompanying -// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - -#include "zmqabstractnotifier.h" -#include "util.h" - - -CZMQAbstractNotifier::~CZMQAbstractNotifier() -{ - assert(!psocket); -} - -bool CZMQAbstractNotifier::NotifyBlock(const CBlockIndex * /*CBlockIndex*/) -{ - return true; -} - -bool CZMQAbstractNotifier::NotifyBlock(const CBlock &) -{ - return true; -} - -bool CZMQAbstractNotifier::NotifyTransaction(const CTransaction &/*transaction*/) -{ - return true; -} diff --git a/src/zmq/zmqabstractnotifier.h b/src/zmq/zmqabstractnotifier.h deleted file mode 100644 index d9d3cb0de..000000000 --- a/src/zmq/zmqabstractnotifier.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2015 The Bitcoin Core developers -// Distributed under the GPLv3 software license, see the accompanying -// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - -#ifndef HUSH_ZMQ_ZMQABSTRACTNOTIFIER_H -#define HUSH_ZMQ_ZMQABSTRACTNOTIFIER_H - -#include "zmqconfig.h" - -class CBlockIndex; -class CZMQAbstractNotifier; - -typedef CZMQAbstractNotifier* (*CZMQNotifierFactory)(); - -class CZMQAbstractNotifier -{ -public: - CZMQAbstractNotifier() : psocket(0) { } - virtual ~CZMQAbstractNotifier(); - - template - static CZMQAbstractNotifier* Create() - { - return new T(); - } - - std::string GetType() const { return type; } - void SetType(const std::string &t) { type = t; } - std::string GetAddress() const { return address; } - void SetAddress(const std::string &a) { address = a; } - - virtual bool Initialize(void *pcontext) = 0; - virtual void Shutdown() = 0; - - virtual bool NotifyBlock(const CBlockIndex *pindex); - virtual bool NotifyBlock(const CBlock& pblock); - virtual bool NotifyTransaction(const CTransaction &transaction); - -protected: - void *psocket; - std::string type; - std::string address; -}; - -#endif // HUSH_ZMQ_ZMQABSTRACTNOTIFIER_H diff --git a/src/zmq/zmqconfig.h b/src/zmq/zmqconfig.h deleted file mode 100644 index e561b0e7b..000000000 --- a/src/zmq/zmqconfig.h +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2015 The Bitcoin Core developers -// Distributed under the GPLv3 software license, see the accompanying -// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - -#ifndef HUSH_ZMQ_ZMQCONFIG_H -#define HUSH_ZMQ_ZMQCONFIG_H - -#if defined(HAVE_CONFIG_H) -#include "config/bitcoin-config.h" -#endif - -#include -#include - -#if ENABLE_ZMQ -#include -#endif - -#include "primitives/block.h" -#include "primitives/transaction.h" - -void zmqError(const char *str); - -#endif // HUSH_ZMQ_ZMQCONFIG_H diff --git a/src/zmq/zmqnotificationinterface.cpp b/src/zmq/zmqnotificationinterface.cpp deleted file mode 100644 index 50838c9c9..000000000 --- a/src/zmq/zmqnotificationinterface.cpp +++ /dev/null @@ -1,181 +0,0 @@ -// Copyright (c) 2015 The Bitcoin Core developers -// Distributed under the GPLv3 software license, see the accompanying -// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - -#include "zmqnotificationinterface.h" -#include "zmqpublishnotifier.h" - -#include "version.h" -#include "main.h" -#include "streams.h" -#include "util.h" - -void zmqError(const char *str) -{ - LogPrint("zmq", "zmq: Error: %s, errno=%s\n", str, zmq_strerror(errno)); -} - -CZMQNotificationInterface::CZMQNotificationInterface() : pcontext(NULL) -{ -} - -CZMQNotificationInterface::~CZMQNotificationInterface() -{ - Shutdown(); - - for (std::list::iterator i=notifiers.begin(); i!=notifiers.end(); ++i) - { - delete *i; - } -} - -CZMQNotificationInterface* CZMQNotificationInterface::CreateWithArguments(const std::map &args) -{ - CZMQNotificationInterface* notificationInterface = NULL; - std::map factories; - std::list notifiers; - - factories["pubhashblock"] = CZMQAbstractNotifier::Create; - factories["pubhashtx"] = CZMQAbstractNotifier::Create; - factories["pubrawblock"] = CZMQAbstractNotifier::Create; - factories["pubrawtx"] = CZMQAbstractNotifier::Create; - factories["pubcheckedblock"] = CZMQAbstractNotifier::Create; - - for (std::map::const_iterator i=factories.begin(); i!=factories.end(); ++i) - { - std::map::const_iterator j = args.find("-zmq" + i->first); - if (j!=args.end()) - { - CZMQNotifierFactory factory = i->second; - std::string address = j->second; - CZMQAbstractNotifier *notifier = factory(); - notifier->SetType(i->first); - notifier->SetAddress(address); - notifiers.push_back(notifier); - } - } - - if (!notifiers.empty()) - { - notificationInterface = new CZMQNotificationInterface(); - notificationInterface->notifiers = notifiers; - - if (!notificationInterface->Initialize()) - { - delete notificationInterface; - notificationInterface = NULL; - } - } - - return notificationInterface; -} - -// Called at startup to conditionally set up ZMQ socket(s) -bool CZMQNotificationInterface::Initialize() -{ - LogPrint("zmq", "zmq: Initialize notification interface\n"); - assert(!pcontext); - - pcontext = zmq_init(1); - - if (!pcontext) - { - zmqError("Unable to initialize context"); - return false; - } - - std::list::iterator i=notifiers.begin(); - for (; i!=notifiers.end(); ++i) - { - CZMQAbstractNotifier *notifier = *i; - if (notifier->Initialize(pcontext)) - { - LogPrint("zmq", " Notifier %s ready (address = %s)\n", notifier->GetType(), notifier->GetAddress()); - } - else - { - LogPrint("zmq", " Notifier %s failed (address = %s)\n", notifier->GetType(), notifier->GetAddress()); - break; - } - } - - if (i!=notifiers.end()) - { - return false; - } - - return true; -} - -// Called during shutdown sequence -void CZMQNotificationInterface::Shutdown() -{ - LogPrint("zmq", "zmq: Shutdown notification interface\n"); - if (pcontext) - { - for (std::list::iterator i=notifiers.begin(); i!=notifiers.end(); ++i) - { - CZMQAbstractNotifier *notifier = *i; - LogPrint("zmq", " Shutdown notifier %s at %s\n", notifier->GetType(), notifier->GetAddress()); - notifier->Shutdown(); - } - zmq_ctx_destroy(pcontext); - - pcontext = 0; - } -} - -void CZMQNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindex) -{ - for (std::list::iterator i = notifiers.begin(); i!=notifiers.end(); ) - { - CZMQAbstractNotifier *notifier = *i; - if (notifier->NotifyBlock(pindex)) - { - i++; - } - else - { - notifier->Shutdown(); - i = notifiers.erase(i); - } - } -} - -void CZMQNotificationInterface::BlockChecked(const CBlock& block, const CValidationState& state) -{ - if (state.IsInvalid()) { - return; - } - - for (std::list::iterator i = notifiers.begin(); i!=notifiers.end(); ) - { - CZMQAbstractNotifier *notifier = *i; - if (notifier->NotifyBlock(block)) - { - i++; - } - else - { - notifier->Shutdown(); - i = notifiers.erase(i); - } - } -} - -void CZMQNotificationInterface::SyncTransaction(const CTransaction &tx, const CBlock *pblock) -{ - for (std::list::iterator i = notifiers.begin(); i!=notifiers.end(); ) - { - CZMQAbstractNotifier *notifier = *i; - if (notifier->NotifyTransaction(tx)) - { - i++; - } - else - { - notifier->Shutdown(); - i = notifiers.erase(i); - } - } -} diff --git a/src/zmq/zmqnotificationinterface.h b/src/zmq/zmqnotificationinterface.h deleted file mode 100644 index 14542a983..000000000 --- a/src/zmq/zmqnotificationinterface.h +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) 2015 The Bitcoin Core developers -// Distributed under the GPLv3 software license, see the accompanying -// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - -#ifndef HUSH_ZMQ_ZMQNOTIFICATIONINTERFACE_H -#define HUSH_ZMQ_ZMQNOTIFICATIONINTERFACE_H - -#include "validationinterface.h" -#include "consensus/validation.h" -#include -#include - -class CBlockIndex; -class CZMQAbstractNotifier; - -class CZMQNotificationInterface : public CValidationInterface -{ -public: - virtual ~CZMQNotificationInterface(); - - static CZMQNotificationInterface* CreateWithArguments(const std::map &args); - -protected: - bool Initialize(); - void Shutdown(); - - // CValidationInterface - void SyncTransaction(const CTransaction &tx, const CBlock *pblock); - void UpdatedBlockTip(const CBlockIndex *pindex); - void BlockChecked(const CBlock& block, const CValidationState& state); - -private: - CZMQNotificationInterface(); - - void *pcontext; - std::list notifiers; -}; - -#endif // HUSH_ZMQ_ZMQNOTIFICATIONINTERFACE_H diff --git a/src/zmq/zmqpublishnotifier.cpp b/src/zmq/zmqpublishnotifier.cpp deleted file mode 100644 index a712bce8a..000000000 --- a/src/zmq/zmqpublishnotifier.cpp +++ /dev/null @@ -1,203 +0,0 @@ -// Copyright (c) 2015 The Bitcoin Core developers -// Distributed under the GPLv3 software license, see the accompanying -// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - -#include "zmqpublishnotifier.h" -#include "main.h" -#include "util.h" - -static std::multimap mapPublishNotifiers; - -static const char *MSG_HASHBLOCK = "hashblock"; -static const char *MSG_HASHTX = "hashtx"; -static const char *MSG_RAWBLOCK = "rawblock"; -static const char *MSG_RAWTX = "rawtx"; -static const char *MSG_CHECKEDBLOCK = "checkedblock"; - -// Internal function to send multipart message -static int zmq_send_multipart(void *sock, const void* data, size_t size, ...) -{ - va_list args; - va_start(args, size); - - while (1) - { - zmq_msg_t msg; - - int rc = zmq_msg_init_size(&msg, size); - if (rc != 0) - { - zmqError("Unable to initialize ZMQ msg"); - return -1; - } - - void *buf = zmq_msg_data(&msg); - memcpy(buf, data, size); - - data = va_arg(args, const void*); - - rc = zmq_msg_send(&msg, sock, data ? ZMQ_SNDMORE : 0); - if (rc == -1) - { - zmqError("Unable to send ZMQ msg"); - zmq_msg_close(&msg); - return -1; - } - - zmq_msg_close(&msg); - - if (!data) - break; - - size = va_arg(args, size_t); - } - return 0; -} - -bool CZMQAbstractPublishNotifier::Initialize(void *pcontext) -{ - assert(!psocket); - - // check if address is being used by other publish notifier - std::multimap::iterator i = mapPublishNotifiers.find(address); - - if (i==mapPublishNotifiers.end()) - { - psocket = zmq_socket(pcontext, ZMQ_PUB); - if (!psocket) - { - zmqError("Failed to create socket"); - return false; - } - - int rc = zmq_bind(psocket, address.c_str()); - if (rc!=0) - { - zmqError("Failed to bind address"); - zmq_close(psocket); - return false; - } - - // register this notifier for the address, so it can be reused for other publish notifier - mapPublishNotifiers.insert(std::make_pair(address, this)); - return true; - } - else - { - LogPrint("zmq", "zmq: Reusing socket for address %s\n", address); - - psocket = i->second->psocket; - mapPublishNotifiers.insert(std::make_pair(address, this)); - - return true; - } -} - -void CZMQAbstractPublishNotifier::Shutdown() -{ - assert(psocket); - - int count = mapPublishNotifiers.count(address); - - // remove this notifier from the list of publishers using this address - typedef std::multimap::iterator iterator; - std::pair iterpair = mapPublishNotifiers.equal_range(address); - - for (iterator it = iterpair.first; it != iterpair.second; ++it) - { - if (it->second==this) - { - mapPublishNotifiers.erase(it); - break; - } - } - - if (count == 1) - { - LogPrint("zmq", "Close socket at address %s\n", address); - int linger = 0; - zmq_setsockopt(psocket, ZMQ_LINGER, &linger, sizeof(linger)); - zmq_close(psocket); - } - - psocket = 0; -} - -bool CZMQAbstractPublishNotifier::SendMessage(const char *command, const void* data, size_t size) -{ - assert(psocket); - - /* send three parts, command & data & a LE 4byte sequence number */ - unsigned char msgseq[sizeof(uint32_t)]; - WriteLE32(&msgseq[0], nSequence); - int rc = zmq_send_multipart(psocket, command, strlen(command), data, size, msgseq, (size_t)sizeof(uint32_t), (void*)0); - if (rc == -1) - return false; - - /* increment memory only sequence number after sending */ - nSequence++; - - return true; -} - -bool CZMQPublishHashBlockNotifier::NotifyBlock(const CBlockIndex *pindex) -{ - uint256 hash = pindex->GetBlockHash(); - LogPrint("zmq", "zmq: Publish hashblock %s\n", hash.GetHex()); - char data[32]; - for (unsigned int i = 0; i < 32; i++) - data[31 - i] = hash.begin()[i]; - return SendMessage(MSG_HASHBLOCK, data, 32); -} - -bool CZMQPublishHashTransactionNotifier::NotifyTransaction(const CTransaction &transaction) -{ - uint256 hash = transaction.GetHash(); - LogPrint("zmq", "zmq: Publish hashtx %s\n", hash.GetHex()); - char data[32]; - for (unsigned int i = 0; i < 32; i++) - data[31 - i] = hash.begin()[i]; - return SendMessage(MSG_HASHTX, data, 32); -} - -bool CZMQPublishRawBlockNotifier::NotifyBlock(const CBlockIndex *pindex) -{ - LogPrint("zmq", "zmq: Publish rawblock %s\n", pindex->GetBlockHash().GetHex()); - - CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); - { - LOCK(cs_main); - CBlock block; - if(!ReadBlockFromDisk(block, pindex,1)) - { - zmqError("Can't read block from disk"); - return false; - } - - ss << block; - } - - return SendMessage(MSG_RAWBLOCK, &(*ss.begin()), ss.size()); -} - -bool CZMQPublishCheckedBlockNotifier::NotifyBlock(const CBlock& block) -{ - LogPrint("zmq", "zmq: Publish checkedblock %s\n", block.GetHash().GetHex()); - - CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); - { - LOCK(cs_main); - ss << block; - } - - return SendMessage(MSG_CHECKEDBLOCK, &(*ss.begin()), ss.size()); -} - -bool CZMQPublishRawTransactionNotifier::NotifyTransaction(const CTransaction &transaction) -{ - uint256 hash = transaction.GetHash(); - LogPrint("zmq", "zmq: Publish rawtx %s\n", hash.GetHex()); - CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); - ss << transaction; - return SendMessage(MSG_RAWTX, &(*ss.begin()), ss.size()); -} diff --git a/src/zmq/zmqpublishnotifier.h b/src/zmq/zmqpublishnotifier.h deleted file mode 100644 index d60276187..000000000 --- a/src/zmq/zmqpublishnotifier.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2015 The Bitcoin Core developers -// Distributed under the GPLv3 software license, see the accompanying -// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html - -#ifndef HUSH_ZMQ_ZMQPUBLISHNOTIFIER_H -#define HUSH_ZMQ_ZMQPUBLISHNOTIFIER_H - -#include "zmqabstractnotifier.h" - -class CBlockIndex; - -class CZMQAbstractPublishNotifier : public CZMQAbstractNotifier -{ -private: - uint32_t nSequence; //! upcounting per message sequence number - -public: - - /* send zmq multipart message - parts: - * command - * data - * message sequence number - */ - bool SendMessage(const char *command, const void* data, size_t size); - - bool Initialize(void *pcontext); - void Shutdown(); -}; - -class CZMQPublishHashBlockNotifier : public CZMQAbstractPublishNotifier -{ -public: - bool NotifyBlock(const CBlockIndex *pindex); -}; - -class CZMQPublishHashTransactionNotifier : public CZMQAbstractPublishNotifier -{ -public: - bool NotifyTransaction(const CTransaction &transaction); -}; - -class CZMQPublishRawBlockNotifier : public CZMQAbstractPublishNotifier -{ -public: - bool NotifyBlock(const CBlockIndex *pindex); -}; - -class CZMQPublishRawTransactionNotifier : public CZMQAbstractPublishNotifier -{ -public: - bool NotifyTransaction(const CTransaction &transaction); -}; - -class CZMQPublishCheckedBlockNotifier : public CZMQAbstractPublishNotifier -{ -public: - bool NotifyBlock(const CBlock &block); -}; - -#endif // HUSH_ZMQ_ZMQPUBLISHNOTIFIER_H From f11d50d17ebae03a26734fee422a9c7781e66275 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 12 Sep 2022 19:54:32 -0400 Subject: [PATCH 155/255] Update manpages to remove zmq options --- doc/man/hush-cli.1 | 9 +++------ doc/man/hush-tx.1 | 7 ++----- doc/man/hushd.1 | 34 +++++++--------------------------- 3 files changed, 12 insertions(+), 38 deletions(-) diff --git a/doc/man/hush-cli.1 b/doc/man/hush-cli.1 index 8f7861dbf..51f26c6a4 100644 --- a/doc/man/hush-cli.1 +++ b/doc/man/hush-cli.1 @@ -1,9 +1,9 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.13. -.TH HUSH-CLI "1" "January 2022" "hush-cli v3.9.1" "User Commands" +.TH HUSH-CLI "1" "September 2022" "hush-cli v3.9.1" "User Commands" .SH NAME hush-cli \- manual page for hush-cli v3.9.1 .SH DESCRIPTION -Hush RPC client version v3.9.1\-804a4abbe\-dirty +Hush RPC client version v3.9.1\-1799c6c9b .PP In order to ensure you are adequately protecting your privacy when using Hush, please see . @@ -29,7 +29,7 @@ Specify configuration file (default: HUSH3.conf) .HP \fB\-datadir=\fR .IP -Specify data directory +Specify data directory (this path cannot use '~') .HP \fB\-testnet\fR .IP @@ -76,11 +76,8 @@ In order to ensure you are adequately protecting your privacy when using Hush, please see . Copyright (C) 2016-2021 Duke Leto and The Hush Developers - Copyright (C) 2016-2020 jl777 and SuperNET developers - Copyright (C) 2016-2018 The Zcash developers - Copyright (C) 2009-2014 The Bitcoin Core developers This is experimental Free Software! Fuck Yeah!!!!! diff --git a/doc/man/hush-tx.1 b/doc/man/hush-tx.1 index 7b1124b70..8318b2aa2 100644 --- a/doc/man/hush-tx.1 +++ b/doc/man/hush-tx.1 @@ -1,9 +1,9 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.13. -.TH HUSH-TX "1" "January 2022" "hush-tx v3.9.1" "User Commands" +.TH HUSH-TX "1" "September 2022" "hush-tx v3.9.1" "User Commands" .SH NAME hush-tx \- manual page for hush-tx v3.9.1 .SH DESCRIPTION -hush\-tx utility version v3.9.1\-804a4abbe\-dirty +hush\-tx utility version v3.9.1\-1799c6c9b .SS "Usage:" .TP hush\-tx [options] [commands] @@ -89,11 +89,8 @@ In order to ensure you are adequately protecting your privacy when using Hush, please see . Copyright (C) 2016-2021 Duke Leto and The Hush Developers - Copyright (C) 2016-2020 jl777 and SuperNET developers - Copyright (C) 2016-2018 The Zcash developers - Copyright (C) 2009-2014 The Bitcoin Core developers This is experimental Free Software! Fuck Yeah!!!!! diff --git a/doc/man/hushd.1 b/doc/man/hushd.1 index 539f544be..eebf51b5b 100644 --- a/doc/man/hushd.1 +++ b/doc/man/hushd.1 @@ -1,9 +1,9 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.13. -.TH HUSHD "1" "January 2022" "hushd v3.9.1" "User Commands" +.TH HUSHD "1" "September 2022" "hushd v3.9.1" "User Commands" .SH NAME hushd \- manual page for hushd v3.9.1 .SH DESCRIPTION -Hush Daemon version v3.9.1\-804a4abbe\-dirty +Hush Daemon version v3.9.1\-1799c6c9b .PP In order to ensure you are adequately protecting your privacy when using Hush, please see . @@ -49,7 +49,7 @@ Run in the background as a daemon and accept commands .HP \fB\-datadir=\fR .IP -Specify data directory +Specify data directory (this path cannot use '~') .HP \fB\-exportdir=\fR .IP @@ -414,24 +414,6 @@ Delete all wallet transactions and only recover those parts of the blockchain through \fB\-rescan\fR on startup (1 = keep tx meta data e.g. account owner and payment request information, 2 = drop tx meta data) .PP -ZeroMQ notification options: -.HP -\fB\-zmqpubhashblock=\fR
-.IP -Enable publish hash block in
-.HP -\fB\-zmqpubhashtx=\fR
-.IP -Enable publish hash transaction in
-.HP -\fB\-zmqpubrawblock=\fR
-.IP -Enable publish raw block in
-.HP -\fB\-zmqpubrawtx=\fR
-.IP -Enable publish raw transaction in
-.PP Debugging/Testing options: .HP \fB\-debug=\fR @@ -440,8 +422,8 @@ Output debugging information (default: 0, supplying is optional). If is not supplied or if = 1, output all debugging information. can be: addrman, alert, bench, coindb, db, deletetx, estimatefee, http, libevent, lock, mempool, net, -tls, partitioncheck, pow, proxy, prune, rand, reindex, rpc, selectcoins, -stratum, tor, zmq, zrpc, zrpcunsafe (implies zrpc). +tls, partitioncheck, pow, proxy, prune, rand, randomx, reindex, rpc, +selectcoins, stratum, tor, zrpc, zrpcunsafe (implies zrpc). .HP \fB\-experimentalfeatures\fR .IP @@ -614,7 +596,8 @@ Hush Smart Chain options: .HP \fB\-ac_algo\fR .IP -Choose PoW mining algorithm, default is Equihash (200,9) +Choose PoW mining algorithm, either 'equihash' or 'randomx'. default is +Equihash (200,9) .HP \fB\-ac_blocktime\fR .IP @@ -713,11 +696,8 @@ In order to ensure you are adequately protecting your privacy when using Hush, please see . Copyright (C) 2016-2021 Duke Leto and The Hush Developers - Copyright (C) 2016-2020 jl777 and SuperNET developers - Copyright (C) 2016-2018 The Zcash developers - Copyright (C) 2009-2014 The Bitcoin Core developers This is experimental Free Software! Fuck Yeah!!!!! From 19b65600c2fec3973b2cf7f7d0fe29efe6800119 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 12 Sep 2022 20:07:16 -0400 Subject: [PATCH 156/255] Delete a zmq dingleberry --- qa/pull-tester/rpc-tests.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index 8b8169a2f..153f7b4a6 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -92,10 +92,6 @@ testScriptsExt=( 'p2p-acceptblock.py' ); -if [ "x$ENABLE_ZMQ" = "x1" ]; then - testScripts+=('zmq_test.py') -fi - extArg="-extended" passOn=${@#$extArg} From fb45331b79b11391946b74d56f0212b8e016dd4f Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 12 Sep 2022 17:56:01 -0700 Subject: [PATCH 157/255] Be better about finding bash --- build.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 864a20548..908ee2e15 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,5 @@ -#!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +#!/usr/bin/env bash +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html From c6e278154f7b19decde9b10fce7bc906a6e46adc Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 12 Sep 2022 18:03:36 -0700 Subject: [PATCH 158/255] Find bash on FreeBSD better --- src/hush-smart-chain | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hush-smart-chain b/src/hush-smart-chain index c5543b221..2a33f0ba0 100755 --- a/src/hush-smart-chain +++ b/src/hush-smart-chain @@ -1,5 +1,5 @@ -#!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +#!/usr/bin/env bash +# Copyright (c) 2016-2022 The Hush developers # set working directory to the location of this script # readlink -f does not always exist DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" From 7cbf9bf61bd38955cdc80c1d3381e4cfe35a698a Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 12 Sep 2022 18:38:03 -0700 Subject: [PATCH 159/255] desprout --- src/test/test_bitcoin.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/test/test_bitcoin.h b/src/test/test_bitcoin.h index d80ab5165..bba2ce335 100644 --- a/src/test/test_bitcoin.h +++ b/src/test/test_bitcoin.h @@ -1,3 +1,6 @@ +// Copyright (c) 2016-2021 The Hush developers +// Distributed under the GPLv3 software license, see the accompanying +// file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #ifndef HUSH_TEST_TEST_HUSH_H #define HUSH_TEST_TEST_HUSH_H @@ -18,17 +21,11 @@ struct BasicTestingSetup { ~BasicTestingSetup(); }; -// Setup w.r.t. zk-SNARK API -struct JoinSplitTestingSetup: public BasicTestingSetup { - JoinSplitTestingSetup(); - ~JoinSplitTestingSetup(); -}; - /** Testing setup that configures a complete environment. * Included are data directory, coins database, script check threads * and wallet (if enabled) setup. */ -struct TestingSetup: public JoinSplitTestingSetup { +struct TestingSetup { CCoinsViewDB *pcoinsdbview; boost::filesystem::path pathTemp; boost::thread_group threadGroup; From 78f5021cc2db4079f0ada8eb97250e81ac438919 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Mon, 12 Sep 2022 22:38:53 -0400 Subject: [PATCH 160/255] starting to support zsweepexclude functionality --- src/init.cpp | 16 ++++++++++++++++ src/wallet/wallet.h | 1 + 2 files changed, 17 insertions(+) diff --git a/src/init.cpp b/src/init.cpp index 98f773b0f..3b0bc6bcd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -471,6 +471,7 @@ std::string HelpMessage(HelpMessageMode mode) // By default we only allow sweeping to the current wallet which must have the spending key of the sweep zaddr // This hopefully will make it harder for people to accidentally sweep funds to a wrong zaddr and lose funds strUsage += HelpMessageOpt("-zsweepexternal", _("Enable sweeping to an external wallet (default false)")); + strUsage += HelpMessageOpt("-zsweepexclude", _("Addresses to exclude from sweeping (default none)")); strUsage += HelpMessageOpt("-deletetx", _("Enable Old Transaction Deletion")); strUsage += HelpMessageOpt("-deleteinterval", strprintf(_("Delete transaction every blocks during inital block download (default: %i)"), DEFAULT_TX_DELETE_INTERVAL)); @@ -2094,6 +2095,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) //Validate Sapling Addresses vector& vSweep = mapMultiArgs["-zsweepaddress"]; + vector& vSweepExclude = mapMultiArgs["-zsweepexclude"]; if (vSweep.size() != 1) { return InitError("A single zsweep address must be specified."); } @@ -2117,6 +2119,20 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) } } + for (int i = 0; i < vSweepExclude.size(); i++) { + // LogPrintf("Sweep Excluded Address: %s\n", vSweepExclude[i]); + auto zSweepExcluded = DecodePaymentAddress(vSweepExclude[i]); + if (!IsValidPaymentAddress(zSweepExcluded)) { + return InitError("Invalid zsweep address"); + } + auto hasSpendingKey = boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), zSweepExcluded); + pwalletMain->sweepExcludeAddress = vSweepExclude[i]; + + if (!hasSpendingKey) { + return InitError("Wallet must have the spending key of zsweepexclude address"); + } + } + if (pwalletMain->fSaplingConsolidationEnabled) { //Validate 1 Consolidation address only that matches the sweep address vector& vaddresses = mapMultiArgs["-consolidatesaplingaddress"]; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index f5e07e9da..2dfb9e6b1 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -815,6 +815,7 @@ public: int sweepFee = 10000; int sweepMaxInputs = 200; std::string sweepAddress = ""; + std::string sweepExcludeAddress = ""; std::string consolidationAddress = ""; void ClearNoteWitnessCache(); From ca3bb90e0c2a5ccd852c75c4511557280aef680a Mon Sep 17 00:00:00 2001 From: jahway603 Date: Mon, 12 Sep 2022 23:30:59 -0400 Subject: [PATCH 161/255] skip excluded address from zsweep --- src/wallet/asyncrpcoperation_sweep.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/wallet/asyncrpcoperation_sweep.cpp b/src/wallet/asyncrpcoperation_sweep.cpp index 1e7d324af..82dc1a40c 100644 --- a/src/wallet/asyncrpcoperation_sweep.cpp +++ b/src/wallet/asyncrpcoperation_sweep.cpp @@ -88,12 +88,18 @@ bool AsyncRPCOperation_sweep::main_impl() { std::vector saplingEntries; libzcash::SaplingPaymentAddress sweepAddress; + libzcash::SaplingPaymentAddress sweepExcludeAddress; std::map> mapAddresses; { LOCK2(cs_main, pwalletMain->cs_wallet); pwalletMain->GetFilteredNotes(saplingEntries, "", 11); + if (!fromRPC_) { + auto zAddressExclude = DecodePaymentAddress(pwalletMain->sweepExcludeAddress); + if (boost::get(&zAddressExclude) != nullptr) { + sweepExcludeAddress = boost::get(zAddressExclude); + } if (fSweepMapUsed) { const vector& v = mapMultiArgs["-zsweepaddress"]; for(int i = 0; i < v.size(); i++) { @@ -115,8 +121,11 @@ bool AsyncRPCOperation_sweep::main_impl() { } } + // Map all notes by address for (auto & entry : saplingEntries) { - //Map all notes by address + // do not need to sweep Excluded Address + if (sweepExcludeAddress == entry.address) { continue; } + // do not need to sweep the sweepAddress as that is the destination if (sweepAddress == entry.address) { continue; } else { From 0c22e263585e6b73414776db5135871ec7a7dc38 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Mon, 12 Sep 2022 23:47:49 -0400 Subject: [PATCH 162/255] updated z_sweepstatus --- src/wallet/rpcwallet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 2f64df677..cc569baf4 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3369,6 +3369,7 @@ UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk) ret.push_back(Pair("next_zsweep", pwalletMain->nextSweep)); ret.push_back(Pair("zsweepinterval", pwalletMain->sweepInterval)); ret.push_back(Pair("zsweepaddress", pwalletMain->sweepAddress)); + ret.push_back(Pair("zsweepexcludeaddress", pwalletMain->sweepExcludeAddress)); ret.push_back(Pair("zsweepmaxinputs", pwalletMain->sweepMaxInputs)); ret.push_back(Pair("zsweepfee", pwalletMain->sweepFee)); ret.push_back(Pair("zsweepexternal", pwalletMain->fSweepExternalEnabled)); From 88d3f116647356d367478e76b36ba850c4409170 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 13 Sep 2022 00:18:44 -0400 Subject: [PATCH 163/255] Save excluded address to be used later --- src/init.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/init.cpp b/src/init.cpp index 3b0bc6bcd..025d448e9 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2121,6 +2121,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) for (int i = 0; i < vSweepExclude.size(); i++) { // LogPrintf("Sweep Excluded Address: %s\n", vSweepExclude[i]); + pwalletMain->sweepExcludeAddress = vSweepExclude[i]; auto zSweepExcluded = DecodePaymentAddress(vSweepExclude[i]); if (!IsValidPaymentAddress(zSweepExcluded)) { return InitError("Invalid zsweep address"); From b687d5f76ef8a0641431b6c80d49e92d72305dc4 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Tue, 13 Sep 2022 00:22:13 -0400 Subject: [PATCH 164/255] debug --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 025d448e9..727a4e946 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2120,7 +2120,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) } for (int i = 0; i < vSweepExclude.size(); i++) { - // LogPrintf("Sweep Excluded Address: %s\n", vSweepExclude[i]); + LogPrintf("Sweep Excluded Address: %s\n", vSweepExclude[i]); pwalletMain->sweepExcludeAddress = vSweepExclude[i]; auto zSweepExcluded = DecodePaymentAddress(vSweepExclude[i]); if (!IsValidPaymentAddress(zSweepExcluded)) { From 908240d07fd433d0f1dd375b38fa53347b96d890 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Tue, 13 Sep 2022 01:00:56 -0400 Subject: [PATCH 165/255] Make z_sweepstatus match up with config option name --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index cc569baf4..59be0f5bd 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3369,7 +3369,7 @@ UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk) ret.push_back(Pair("next_zsweep", pwalletMain->nextSweep)); ret.push_back(Pair("zsweepinterval", pwalletMain->sweepInterval)); ret.push_back(Pair("zsweepaddress", pwalletMain->sweepAddress)); - ret.push_back(Pair("zsweepexcludeaddress", pwalletMain->sweepExcludeAddress)); + ret.push_back(Pair("zsweepexclude", pwalletMain->sweepExcludeAddress)); ret.push_back(Pair("zsweepmaxinputs", pwalletMain->sweepMaxInputs)); ret.push_back(Pair("zsweepfee", pwalletMain->sweepFee)); ret.push_back(Pair("zsweepexternal", pwalletMain->fSweepExternalEnabled)); From f90715192efb5377deb49ef04899cb56ce0b4c10 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 15 Sep 2022 09:38:48 -0400 Subject: [PATCH 166/255] Do not delete expired txs for now, it doesn't work correctly, and log more info about them --- src/wallet/wallet.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index e9450161f..3a84f267e 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -3136,9 +3136,10 @@ std::vector CWallet::ResendWalletTransactionsBefore(int64_t nTime) // Do not relay expired transactions, to avoid other nodes banning us // Current code will not ban nodes relaying expired txs but older nodes will if (wtx.nExpiryHeight > 0 && wtx.nExpiryHeight < chainActive.LastTip()->GetHeight()) { - fprintf(stderr,"%s: ignoring expired tx %s\n", __func__, wtx.GetHash().ToString().c_str() ); + fprintf(stderr,"%s: ignoring expired tx %s with expiry %d at height %d\n", __func__, wtx.GetHash().ToString().c_str(), wtx.nExpiryHeight, chainActive.LastTip()->GetHeight() ); + // TODO: expired detection doesn't seem to work right // append to list of txs to delete - vwtxh.push_back(wtx.GetHash()); + // vwtxh.push_back(wtx.GetHash()); continue; } From b07f9db06dc348faf1fe0a2da8207aaec5b948e1 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 15 Sep 2022 19:39:57 -0400 Subject: [PATCH 167/255] Update for 75s blocks --- contrib/block_time.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/block_time.pl b/contrib/block_time.pl index 1b8c13351..e91f22d19 100755 --- a/contrib/block_time.pl +++ b/contrib/block_time.pl @@ -19,7 +19,7 @@ if ($block <= $blockcount) { die "That block has already happened!"; } else { my $diff = $block - $blockcount; - my $minutes = $diff*2.5; + my $minutes = $diff*1.25; # 75s in minutes my $seconds = $minutes*60; my $now = time; my $then = $now + $seconds; From 2ddf539185ab9ffe1a5714ead8574e2f30c932f4 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 15 Sep 2022 19:41:28 -0400 Subject: [PATCH 168/255] Check if hush-cli binary exists before using it --- contrib/block_time.pl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/contrib/block_time.pl b/contrib/block_time.pl index e91f22d19..0366aa8f9 100755 --- a/contrib/block_time.pl +++ b/contrib/block_time.pl @@ -8,6 +8,9 @@ use strict; # Given a block time, estimate when it will happen my $block = shift || die "Usage: $0 123"; my $hush = "./src/hush-cli"; +unless (-e $hush) { + die "$hush does not exist, aborting"; +} my $blockcount = qx{$hush getblockcount}; unless ($blockcount = int($blockcount)) { From 88c2ddbb9f6914c41c9120d0de8d1c883e639641 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 16 Sep 2022 11:12:46 +0000 Subject: [PATCH 169/255] Update 'contrib/debian/copyright' --- contrib/debian/copyright | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/debian/copyright b/contrib/debian/copyright index 7bf3a707c..6231c2023 100644 --- a/contrib/debian/copyright +++ b/contrib/debian/copyright @@ -2,7 +2,7 @@ Files: * Copyright: 2016-2020, The Hush developers 2009-2016, Bitcoin Core developers License: GPLv3 -Comment: https://hush.is/developers +Comment: https://hush.is Files: depends/sources/libsodium-*.tar.gz Copyright: 2013-2016 Frank Denis From 77d7aaba969a2b642d2f606535626bd356d33e51 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 16 Sep 2022 05:47:35 -0700 Subject: [PATCH 170/255] Return an array of addresses to exclude from zsweep in zsweep_status --- src/wallet/rpcwallet.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 59be0f5bd..246615a5a 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3369,7 +3369,12 @@ UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk) ret.push_back(Pair("next_zsweep", pwalletMain->nextSweep)); ret.push_back(Pair("zsweepinterval", pwalletMain->sweepInterval)); ret.push_back(Pair("zsweepaddress", pwalletMain->sweepAddress)); - ret.push_back(Pair("zsweepexclude", pwalletMain->sweepExcludeAddress)); + UniValue excludes(UniValue::VARR); + // BOOST_FOREACH(const std::string& exclude, pwalletMain->sweepExcludeAddresses ) { + // excludes.push_back(exclude); + // } + excludes.push_back( pwalletMain->sweepExcludeAddress ); + ret.push_back(Pair("zsweepexclude", excludes)); ret.push_back(Pair("zsweepmaxinputs", pwalletMain->sweepMaxInputs)); ret.push_back(Pair("zsweepfee", pwalletMain->sweepFee)); ret.push_back(Pair("zsweepexternal", pwalletMain->fSweepExternalEnabled)); From f796d5d14eb57b21d6bb30559dd4329facf9aa14 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 16 Sep 2022 10:08:53 -0700 Subject: [PATCH 171/255] Support multiple zsweepexclude zaddrs --- src/init.cpp | 4 +-- src/wallet/asyncrpcoperation_sweep.cpp | 37 ++++++++++++++++++++------ src/wallet/wallet.h | 2 +- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 727a4e946..cec462cf5 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2121,17 +2121,17 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) for (int i = 0; i < vSweepExclude.size(); i++) { LogPrintf("Sweep Excluded Address: %s\n", vSweepExclude[i]); - pwalletMain->sweepExcludeAddress = vSweepExclude[i]; auto zSweepExcluded = DecodePaymentAddress(vSweepExclude[i]); if (!IsValidPaymentAddress(zSweepExcluded)) { return InitError("Invalid zsweep address"); } auto hasSpendingKey = boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), zSweepExcluded); - pwalletMain->sweepExcludeAddress = vSweepExclude[i]; if (!hasSpendingKey) { return InitError("Wallet must have the spending key of zsweepexclude address"); } + // Add this validated zaddr to the list of excluded sweep zaddrs + pwalletMain->sweepExcludeAddresses.push_back( vSweepExclude[i] ); } if (pwalletMain->fSaplingConsolidationEnabled) { diff --git a/src/wallet/asyncrpcoperation_sweep.cpp b/src/wallet/asyncrpcoperation_sweep.cpp index 82dc1a40c..46962564d 100644 --- a/src/wallet/asyncrpcoperation_sweep.cpp +++ b/src/wallet/asyncrpcoperation_sweep.cpp @@ -74,6 +74,26 @@ void AsyncRPCOperation_sweep::main() { LogPrintf("%s", s); } +// Is this zaddr excluded from zsweep ? +bool IsExcludedAddress(libzcash::SaplingPaymentAddress zaddr) { + for( auto & sweepExcludeAddress : pwalletMain->sweepExcludeAddresses ) { + auto zAddressExclude = DecodePaymentAddress(sweepExcludeAddress); + + if (boost::get(&zAddressExclude) != nullptr) { + sweepExcludeAddress = boost::get(zAddressExclude); + } else { + // This is an invalid sapling zaddr + LogPrintf("%s: Invalid zsweepexclude zaddr %s, ignoring\n", opid, sweepExcludeAddress); + } + + if (sweepExcludeAddress == entry.address) { + return true; + } + } + + return false; +} + bool AsyncRPCOperation_sweep::main_impl() { bool status=true; auto opid=getId(); @@ -88,7 +108,6 @@ bool AsyncRPCOperation_sweep::main_impl() { std::vector saplingEntries; libzcash::SaplingPaymentAddress sweepAddress; - libzcash::SaplingPaymentAddress sweepExcludeAddress; std::map> mapAddresses; { @@ -96,16 +115,15 @@ bool AsyncRPCOperation_sweep::main_impl() { pwalletMain->GetFilteredNotes(saplingEntries, "", 11); if (!fromRPC_) { - auto zAddressExclude = DecodePaymentAddress(pwalletMain->sweepExcludeAddress); - if (boost::get(&zAddressExclude) != nullptr) { - sweepExcludeAddress = boost::get(zAddressExclude); - } if (fSweepMapUsed) { const vector& v = mapMultiArgs["-zsweepaddress"]; for(int i = 0; i < v.size(); i++) { auto zAddress = DecodePaymentAddress(v[i]); if (boost::get(&zAddress) != nullptr) { sweepAddress = boost::get(zAddress); + } else { + LogPrintf("%s: Invalid zsweepaddress configured, exiting\n", opid); + return false; } } } else { @@ -121,10 +139,13 @@ bool AsyncRPCOperation_sweep::main_impl() { } } - // Map all notes by address + // Map all notes (zutxos) by address for (auto & entry : saplingEntries) { - // do not need to sweep Excluded Address - if (sweepExcludeAddress == entry.address) { continue; } + // do not need to sweep Excluded Addresses + if(IsExcludedAddress(entry.address) { + continue; + } + // do not need to sweep the sweepAddress as that is the destination if (sweepAddress == entry.address) { continue; diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 2dfb9e6b1..3b932c4f5 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -815,7 +815,7 @@ public: int sweepFee = 10000; int sweepMaxInputs = 200; std::string sweepAddress = ""; - std::string sweepExcludeAddress = ""; + std::vector sweepExcludeAddresses = ""; std::string consolidationAddress = ""; void ClearNoteWitnessCache(); From 12fa3013cedfc9ee9a14a7593221934433f4b0f9 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 16 Sep 2022 13:11:32 -0400 Subject: [PATCH 172/255] Fix definition of sweepExcludeAddresses --- src/wallet/wallet.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 3b932c4f5..ec2937a1d 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -815,7 +815,7 @@ public: int sweepFee = 10000; int sweepMaxInputs = 200; std::string sweepAddress = ""; - std::vector sweepExcludeAddresses = ""; + std::vector sweepExcludeAddresses; std::string consolidationAddress = ""; void ClearNoteWitnessCache(); From 35f376c8b5bcbd3d3550cbbc78b40a3d78648e75 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 16 Sep 2022 14:28:51 -0400 Subject: [PATCH 173/255] Fix bugs in excluding multiple zsweep zaddrs and report all excluded zsweep zaddrs in z_sweepstatus --- src/wallet/asyncrpcoperation_sweep.cpp | 13 +++++++------ src/wallet/rpcwallet.cpp | 7 +++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/wallet/asyncrpcoperation_sweep.cpp b/src/wallet/asyncrpcoperation_sweep.cpp index 46962564d..237af4cd3 100644 --- a/src/wallet/asyncrpcoperation_sweep.cpp +++ b/src/wallet/asyncrpcoperation_sweep.cpp @@ -80,15 +80,16 @@ bool IsExcludedAddress(libzcash::SaplingPaymentAddress zaddr) { auto zAddressExclude = DecodePaymentAddress(sweepExcludeAddress); if (boost::get(&zAddressExclude) != nullptr) { - sweepExcludeAddress = boost::get(zAddressExclude); + auto excludeAddress = boost::get(zAddressExclude); + if (excludeAddress == zaddr) { + return true; + } } else { // This is an invalid sapling zaddr - LogPrintf("%s: Invalid zsweepexclude zaddr %s, ignoring\n", opid, sweepExcludeAddress); + LogPrintf("%s: Invalid zsweepexclude zaddr %s, ignoring\n", sweepExcludeAddress); + continue; } - if (sweepExcludeAddress == entry.address) { - return true; - } } return false; @@ -142,7 +143,7 @@ bool AsyncRPCOperation_sweep::main_impl() { // Map all notes (zutxos) by address for (auto & entry : saplingEntries) { // do not need to sweep Excluded Addresses - if(IsExcludedAddress(entry.address) { + if(IsExcludedAddress(entry.address)) { continue; } diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 246615a5a..a09f33e79 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -3370,10 +3370,9 @@ UniValue z_sweepstatus(const UniValue& params, bool fHelp, const CPubKey& mypk) ret.push_back(Pair("zsweepinterval", pwalletMain->sweepInterval)); ret.push_back(Pair("zsweepaddress", pwalletMain->sweepAddress)); UniValue excludes(UniValue::VARR); - // BOOST_FOREACH(const std::string& exclude, pwalletMain->sweepExcludeAddresses ) { - // excludes.push_back(exclude); - // } - excludes.push_back( pwalletMain->sweepExcludeAddress ); + BOOST_FOREACH(const std::string& exclude, pwalletMain->sweepExcludeAddresses ) { + excludes.push_back(exclude); + } ret.push_back(Pair("zsweepexclude", excludes)); ret.push_back(Pair("zsweepmaxinputs", pwalletMain->sweepMaxInputs)); ret.push_back(Pair("zsweepfee", pwalletMain->sweepFee)); From 62c9bce6f7d29ce4ed84547777b79011d1176351 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 16 Sep 2022 14:33:37 -0400 Subject: [PATCH 174/255] Correct error messsage about invalid zsweepexclude address --- src/init.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index cec462cf5..63a8d9c8e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2123,7 +2123,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) LogPrintf("Sweep Excluded Address: %s\n", vSweepExclude[i]); auto zSweepExcluded = DecodePaymentAddress(vSweepExclude[i]); if (!IsValidPaymentAddress(zSweepExcluded)) { - return InitError("Invalid zsweep address"); + return InitError("Invalid zsweepexclude address"); } auto hasSpendingKey = boost::apply_visitor(HaveSpendingKeyForPaymentAddress(pwalletMain), zSweepExcluded); From 0938bd6b7b7e48ba226d1df5688bc2d294a57b29 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Fri, 16 Sep 2022 19:23:25 -0700 Subject: [PATCH 175/255] Log outpoint for failed Sapling witness lookup --- src/wallet/asyncrpcoperation_sendmany.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index 762d50021..5d5067772 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -435,7 +435,9 @@ bool AsyncRPCOperation_sendmany::main_impl() { // Add Sapling spends for (size_t i = 0; i < notes.size(); i++) { if (!witnesses[i]) { - throw JSONRPCError(RPC_WALLET_ERROR, "Missing witness for Sapling note"); + throw JSONRPCError(RPC_WALLET_ERROR, + strprintf( "Missing witness for Sapling note at outpoint %s", notes[i].op.ToString()) + ); } assert(builder_.AddSaplingSpend(expsk, notes[i], anchor, witnesses[i].get())); } From e1590836fd952a83e2e4187e4797b482300355c6 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 16 Sep 2022 23:17:08 -0400 Subject: [PATCH 176/255] Use the correct variable for missing witness error --- src/wallet/asyncrpcoperation_sendmany.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index 5d5067772..28fad9c60 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -436,7 +436,7 @@ bool AsyncRPCOperation_sendmany::main_impl() { for (size_t i = 0; i < notes.size(); i++) { if (!witnesses[i]) { throw JSONRPCError(RPC_WALLET_ERROR, - strprintf( "Missing witness for Sapling note at outpoint %s", notes[i].op.ToString()) + strprintf( "Missing witness for Sapling note at outpoint %s", z_sapling_inputs_[i].op.ToString()) ); } assert(builder_.AddSaplingSpend(expsk, notes[i], anchor, witnesses[i].get())); From cd999f60be3c49275e87b3a1051adbc106942c2b Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 17 Sep 2022 14:18:14 +0000 Subject: [PATCH 177/255] Update 'doc/release-process.md' --- doc/release-process.md | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/doc/release-process.md b/doc/release-process.md index b5dee897d..643d5f953 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -1,10 +1,39 @@ # Hush Release Process -## Pre-release +## High-Level Philosophy + +Beware of making high-risk changes (such as consensus changes, p2p layer changes and wallet/transaction changes) too close to a new release, because they will not get as much testing as they should. Don't merge large branches which haven't undergone lots of testing just before a release. + +## Check for changes on master that should be on dev + +Often there are trivial changes made directly on master, such as documentation changes. In theory, no code changes should happen on master without being on dev first, but it's better to be safe than sorry. We want the dev branch which undergoes testing to be as close as possible to what the master branch will become, so we don't want to merge dev into master and just assume everything works. So it's best to merge the master branch into dev just before merging the dev branch into master. + +To check if the master branch has any changes that the dev branch does not: + +``` +# this assumes you are working with https://git.hush.is/hush/hush3 as your remote +git checkout dev +git pull # make sure dev is up to date +git checkout master +git pull # make sure master is up to date +git diff dev...master # look at the set of changes which exist in master but not dev +``` + +If the last command has no output, congrats, there is nothing to do. If the last command has output, then you should merge master into dev: + +``` +git checkout dev +git merge --no-ff master # using the default commit message is fine +git push +``` + +The `--no-ff` flag above makes sure to make a merge commit, no matter what, even if a "fast forward" could be done. For those in the future looking back, it's much better to see evidence of when branches were merged. + + ### Git Issues -Look for Git issues that should be fixed in the next release. +Look for Git issues that should be fixed in the next release. Especially low-risk and simple things, like documentation changes, improvements to error messages and RPC help output. ### Pre-release checklist: * Is this release changing consensus rules? From 233b14d14bec59ce619514f3abbafd6a12f87009 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 17 Sep 2022 14:21:42 +0000 Subject: [PATCH 178/255] Update 'doc/release-process.md' --- doc/release-process.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/doc/release-process.md b/doc/release-process.md index 643d5f953..6c4977fd1 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -30,17 +30,17 @@ git push The `--no-ff` flag above makes sure to make a merge commit, no matter what, even if a "fast forward" could be done. For those in the future looking back, it's much better to see evidence of when branches were merged. - ### Git Issues Look for Git issues that should be fixed in the next release. Especially low-risk and simple things, like documentation changes, improvements to error messages and RPC help output. ### Pre-release checklist: - * Is this release changing consensus rules? + * Is this release changing consensus rules? Definitely update protocol version. ### Protocol Safety Checks: * Does MIN_PROTO_VERSION need to change? + * If it does, new nodes will not be able to talk to nodes with a version less than MIN_PROTO_VERSION ## Release dependencies @@ -50,4 +50,9 @@ Install deps on Linux: ## Release process -... + - Update checkpoints + - Update man pages + - Update copyright years (if applicable) with replace.pl + - Do a fresh clone and fresh sync with new checkpoints + - Stop node, wait 20 minutes, and then do a partial sync with new checkpoints + From 9dd4dcc7f9274643b43a393a28b201af9f280c3d Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 17 Sep 2022 23:17:35 -0400 Subject: [PATCH 179/255] Update release docs --- doc/developer-notes.md | 7 +------ doc/release-process.md | 5 +++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/developer-notes.md b/doc/developer-notes.md index 87d2be84a..77233221c 100644 --- a/doc/developer-notes.md +++ b/doc/developer-notes.md @@ -45,12 +45,7 @@ The jq manual can be found here: https://stedolan.github.io/jq/manual/ # Making a new release of Hush - * Update version in configure.ac and src/clientversion.h - * Run ./contrib/devtools/gen-manpages.sh, commit + push results - * Update checkpoints - * Update protocol version in src/version.h if necessary - * Make Gitea release - * Make Git Tag (Gitea can do this) +See doc/release-process.md for details. # Testing a Branch diff --git a/doc/release-process.md b/doc/release-process.md index 6c4977fd1..e781cc75b 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -50,9 +50,14 @@ Install deps on Linux: ## Release process + - Update version in configure.ac and src/clientversion.h + - Update checkpoints + - Run ./contrib/devtools/gen-manpages.sh, commit + push results - Update checkpoints - Update man pages - Update copyright years (if applicable) with replace.pl - Do a fresh clone and fresh sync with new checkpoints - Stop node, wait 20 minutes, and then do a partial sync with new checkpoints + - Make Gitea release + - Make Git Tag (Gitea can do this) From 95f6a14ac36851a4cb6a5ee181311c57c831e776 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 17 Sep 2022 23:31:47 -0400 Subject: [PATCH 180/255] Document updating hushd version --- doc/release-process.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/release-process.md b/doc/release-process.md index e781cc75b..bb8c5b67a 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -50,7 +50,12 @@ Install deps on Linux: ## Release process - - Update version in configure.ac and src/clientversion.h + - Update version in configure.ac and src/clientversion.h to update the hushd version + - In src/clientversion.h you update `CLIENT_VERSION_*` variables. Usually you will just update `CLIENT_VERSION_REVISION` + - If there is a consensus change, it may be a good idea to update `CLIENT_VERSION_MINOR` or `CLIENT_VERSION_MAJOR` + - To make a pre-release "beta" you can modify `CLIENT_VERSION_BUILD` but that is rarely done in Hush world. + - A `CLIENT_VERSION_BUILD` of 50 means "actual non-beta release" + - Make sure to keep the values in configure.ac and src/clientversion.h the same. The variables are prefixed wth an underscore in configure.ac - Update checkpoints - Run ./contrib/devtools/gen-manpages.sh, commit + push results - Update checkpoints From 5a145acd46fb8e89f33fc93f1373194ab9f38895 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 17 Sep 2022 23:35:27 -0400 Subject: [PATCH 181/255] Add script to automate string replaces --- contrib/devtools/replace.pl | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 contrib/devtools/replace.pl diff --git a/contrib/devtools/replace.pl b/contrib/devtools/replace.pl new file mode 100755 index 000000000..601c781aa --- /dev/null +++ b/contrib/devtools/replace.pl @@ -0,0 +1,42 @@ +#!/usr/bin/perl +# Copyright (c) 2016-2022 The Hush developers +# Distributed under the GPLv3 software license, see the accompanying +# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html + +use strict; +use warnings; +use autodie; +use Data::Dumper; +my ($find,$replace,@files) = @ARGV; + +usage() unless $find && defined $replace; +unless( @files ) { + printf "No files to replace stuff!"; + exit 0; +} + +my $fh; +print "Going to replace $find with $replace in " . scalar(@files) . " files\n"; + +for my $file (@files) { + if (-d $file) { + printf "Skipping directory $file\n"; + next; + } + unless ( -e $file ) { + printf "$file does not exist!\n"; + next; + } + open $fh, '<', $file; + my $content = join('',<$fh>); + $content =~ s/\Q$find\E/$replace/g; + close $fh; + + open $fh, '>', $file; + print $fh $content; + close $fh; +} + +sub usage { + die "$0 stringtofind stringtoreplace file [more files...]\n"; +} From 73789ba26b22d76477b9111692d6f8ea3daf892e Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sat, 17 Sep 2022 23:38:49 -0400 Subject: [PATCH 182/255] Yep --- doc/release-process.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/release-process.md b/doc/release-process.md index bb8c5b67a..ca4bd1b3d 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -60,7 +60,7 @@ Install deps on Linux: - Run ./contrib/devtools/gen-manpages.sh, commit + push results - Update checkpoints - Update man pages - - Update copyright years (if applicable) with replace.pl + - Update copyright years (if applicable) with contrib/devtools/replace.pl - Do a fresh clone and fresh sync with new checkpoints - Stop node, wait 20 minutes, and then do a partial sync with new checkpoints - Make Gitea release From 711cd8e2343bc589e3954b8837185560305d7967 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 18 Sep 2022 00:05:27 -0400 Subject: [PATCH 183/255] Explain protocol version stuff --- doc/release-process.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/release-process.md b/doc/release-process.md index ca4bd1b3d..26c172a2b 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -39,8 +39,13 @@ Look for Git issues that should be fixed in the next release. Especially low-ris ### Protocol Safety Checks: - * Does MIN_PROTO_VERSION need to change? - * If it does, new nodes will not be able to talk to nodes with a version less than MIN_PROTO_VERSION + * Does `PROTOCOL_VERSION` in src/version.h need to be increased? + * All releases with a consensus change should increase the value by 1 + * This identifies a nodes protocol version to all other peers it connects to. + * Does `MIN_PEER_PROTO_VERSION` in src/version.h need to change? + * If it does, new nodes will not be able to talk to nodes with a version less than `MIN_PROTO_VERSION` + * The main use of these is for newer nodes that know they do not want to talk to older nodes to prevent connecting to older nodes efficiently + * For instance, when a new release has different consensus rules than older nodes, `MIN_PROTO_VERSION` prevents wasting lots of network bandwidth talking to incompatible nodes which will eventually be banned for disagreeing on consensus rules ## Release dependencies From 9b1b6fdc2e40d4e82a9131952ee43394c673dde2 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 18 Sep 2022 00:24:10 -0400 Subject: [PATCH 184/255] Document checkpoints better --- doc/release-process.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/release-process.md b/doc/release-process.md index 26c172a2b..8f1412b61 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -63,7 +63,8 @@ Install deps on Linux: - Make sure to keep the values in configure.ac and src/clientversion.h the same. The variables are prefixed wth an underscore in configure.ac - Update checkpoints - Run ./contrib/devtools/gen-manpages.sh, commit + push results - - Update checkpoints + - Update checkpoints in src/chainparams.cpp via contrib/checkpoints.pl + - checkpoints.pl will just generate the data you need, it must be manually copied into the correct place - Update man pages - Update copyright years (if applicable) with contrib/devtools/replace.pl - Do a fresh clone and fresh sync with new checkpoints From 8e1ba0658d10a620b0d1e382ebc751170eb23f34 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 18 Sep 2022 10:27:48 -0400 Subject: [PATCH 185/255] Ensure pindexPrev is not null before mining against it in both BitcoinMiner and RandomXMiner --- src/miner.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/miner.cpp b/src/miner.cpp index 16c18146b..72d6d04df 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1102,6 +1102,14 @@ void static RandomXMiner() // Create new block unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); CBlockIndex* pindexPrev = chainActive.LastTip(); + + // If we don't have a valid chain tip to work from, wait and try again. + if (pindexPrev == nullptr) { + fprintf(stderr,"%s: null pindexPrev, trying again...\n",__func__); + MilliSleep(1000); + continue; + } + if ( Mining_height != pindexPrev->GetHeight()+1 ) { Mining_height = pindexPrev->GetHeight()+1; @@ -1460,6 +1468,14 @@ void static BitcoinMiner() // unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated(); CBlockIndex* pindexPrev = chainActive.LastTip(); + + // If we don't have a valid chain tip to work from, wait and try again. + if (pindexPrev == nullptr) { + fprintf(stderr,"%s: null pindexPrev, trying again...\n",__func__); + MilliSleep(1000); + continue; + } + if ( Mining_height != pindexPrev->GetHeight()+1 ) { Mining_height = pindexPrev->GetHeight()+1; From 703697404255a70451f756d1cc68ebebaecca9ea Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 18 Sep 2022 10:53:47 -0400 Subject: [PATCH 186/255] Explain checkpoints a bit --- doc/release-process.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/release-process.md b/doc/release-process.md index 8f1412b61..c46f54b9a 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -61,10 +61,12 @@ Install deps on Linux: - To make a pre-release "beta" you can modify `CLIENT_VERSION_BUILD` but that is rarely done in Hush world. - A `CLIENT_VERSION_BUILD` of 50 means "actual non-beta release" - Make sure to keep the values in configure.ac and src/clientversion.h the same. The variables are prefixed wth an underscore in configure.ac - - Update checkpoints - Run ./contrib/devtools/gen-manpages.sh, commit + push results - Update checkpoints in src/chainparams.cpp via contrib/checkpoints.pl - checkpoints.pl will just generate the data you need, it must be manually copied into the correct place + - Checkpoint are a list of block heights and block hashes that tell a full node the correct block history of the blockchain + - Checkpoints make block verification a bit faster, because nodes can say "is this block a descendant of a checkpoint block" instead of doing full consensus checks, which take more time + - Checkpoints also provide a bit of security against some attacks that would create malicious chainforks - Update man pages - Update copyright years (if applicable) with contrib/devtools/replace.pl - Do a fresh clone and fresh sync with new checkpoints From 7e53907bdc78d94d8111099def744e4bfce89883 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 18 Sep 2022 11:08:09 -0400 Subject: [PATCH 187/255] Update version to 3.9.2 --- configure.ac | 2 +- src/clientversion.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 801d7be75..e863c6384 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N) AC_PREREQ([2.60]) define(_CLIENT_VERSION_MAJOR, 3) define(_CLIENT_VERSION_MINOR, 9) -define(_CLIENT_VERSION_REVISION, 1) +define(_CLIENT_VERSION_REVISION, 2) define(_CLIENT_VERSION_BUILD, 50) define(_ZC_BUILD_VAL, m4_if(m4_eval(_CLIENT_VERSION_BUILD < 25), 1, m4_incr(_CLIENT_VERSION_BUILD), m4_eval(_CLIENT_VERSION_BUILD < 50), 1, m4_eval(_CLIENT_VERSION_BUILD - 24), m4_eval(_CLIENT_VERSION_BUILD == 50), 1, , m4_eval(_CLIENT_VERSION_BUILD - 50))) define(_CLIENT_VERSION_SUFFIX, m4_if(m4_eval(_CLIENT_VERSION_BUILD < 25), 1, _CLIENT_VERSION_REVISION-beta$1, m4_eval(_CLIENT_VERSION_BUILD < 50), 1, _CLIENT_VERSION_REVISION-rc$1, m4_eval(_CLIENT_VERSION_BUILD == 50), 1, _CLIENT_VERSION_REVISION, _CLIENT_VERSION_REVISION-$1))) diff --git a/src/clientversion.h b/src/clientversion.h index 03657120e..461c4c197 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -30,7 +30,7 @@ // Must be kept in sync with configure.ac , ugh! #define CLIENT_VERSION_MAJOR 3 #define CLIENT_VERSION_MINOR 9 -#define CLIENT_VERSION_REVISION 1 +#define CLIENT_VERSION_REVISION 2 #define CLIENT_VERSION_BUILD 50 //! Set to true for release, false for prerelease or test build From ad4600fb9fada48beed6073d29765272ca5f6946 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sun, 18 Sep 2022 14:50:57 -0400 Subject: [PATCH 188/255] renamed to util --- Dockerfile | 4 ++-- Makefile.am | 2 +- build.sh | 2 +- {zcutil => util}/afl/afl-build.sh | 0 {zcutil => util}/afl/afl-get.sh | 0 {zcutil => util}/afl/afl-getbuildrun.sh | 0 {zcutil => util}/afl/afl-run.sh | 0 {zcutil => util}/afl/hush-wrapper | 0 {zcutil => util}/afl/hush-wrapper-g++ | 0 {zcutil => util}/afl/hush-wrapper-gcc | 0 {zcutil => util}/build-arm.sh | 0 {zcutil => util}/build-debian-package-ARM.sh | 0 {zcutil => util}/build-debian-package.sh | 0 {zcutil => util}/build-mac.sh | 0 {zcutil => util}/build-win.sh | 0 {zcutil => util}/build.sh | 0 {zcutil => util}/docker-entrypoint.sh | 0 {zcutil => util}/docker-hush-cli.sh | 0 {zcutil => util}/dragon.txt | 0 19 files changed, 4 insertions(+), 4 deletions(-) rename {zcutil => util}/afl/afl-build.sh (100%) rename {zcutil => util}/afl/afl-get.sh (100%) rename {zcutil => util}/afl/afl-getbuildrun.sh (100%) rename {zcutil => util}/afl/afl-run.sh (100%) rename {zcutil => util}/afl/hush-wrapper (100%) rename {zcutil => util}/afl/hush-wrapper-g++ (100%) rename {zcutil => util}/afl/hush-wrapper-gcc (100%) rename {zcutil => util}/build-arm.sh (100%) rename {zcutil => util}/build-debian-package-ARM.sh (100%) rename {zcutil => util}/build-debian-package.sh (100%) rename {zcutil => util}/build-mac.sh (100%) rename {zcutil => util}/build-win.sh (100%) rename {zcutil => util}/build.sh (100%) rename {zcutil => util}/docker-entrypoint.sh (100%) rename {zcutil => util}/docker-hush-cli.sh (100%) rename {zcutil => util}/dragon.txt (100%) diff --git a/Dockerfile b/Dockerfile index e1323ec2f..b89a159a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ RUN ln -sf /hush/src/hushd /usr/bin/hushd && \ ln -sf /hush/src/hush-tx /usr/bin/hush-tx && \ ln -sf /hush/src/wallet-utility /usr/bin/hush-wallet-utility && \ ln -sf /hush/src/hush-smart-chain /usr/bin/hush-smart-chain && \ - ln -sf /hush/zcutil/docker-entrypoint.sh /usr/bin/entrypoint && \ - ln -sf /hush/zcutil/docker-hush-cli.sh /usr/bin/hush-cli + ln -sf /hush/util/docker-entrypoint.sh /usr/bin/entrypoint && \ + ln -sf /hush/util/docker-hush-cli.sh /usr/bin/hush-cli CMD ["entrypoint"] diff --git a/Makefile.am b/Makefile.am index bc04a0cdd..de977adfc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -233,7 +233,7 @@ endif endif dist_bin_SCRIPTS = -dist_noinst_SCRIPTS = autogen.sh zcutil/build-debian-package.sh zcutil/build.sh +dist_noinst_SCRIPTS = autogen.sh util/build-debian-package.sh util/build.sh EXTRA_DIST = $(top_srcdir)/share/genbuild.sh qa/pull-tester/rpc-tests.sh qa/pull-tester/run-bitcoin-cli qa/rpc-tests qa/hush $(DIST_DOCS) $(BIN_CHECKS) diff --git a/build.sh b/build.sh index 908ee2e15..1a2d1c8a0 100755 --- a/build.sh +++ b/build.sh @@ -4,4 +4,4 @@ # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html set -eu -o pipefail -./zcutil/build.sh --disable-tests $@ +./util/build.sh --disable-tests $@ diff --git a/zcutil/afl/afl-build.sh b/util/afl/afl-build.sh similarity index 100% rename from zcutil/afl/afl-build.sh rename to util/afl/afl-build.sh diff --git a/zcutil/afl/afl-get.sh b/util/afl/afl-get.sh similarity index 100% rename from zcutil/afl/afl-get.sh rename to util/afl/afl-get.sh diff --git a/zcutil/afl/afl-getbuildrun.sh b/util/afl/afl-getbuildrun.sh similarity index 100% rename from zcutil/afl/afl-getbuildrun.sh rename to util/afl/afl-getbuildrun.sh diff --git a/zcutil/afl/afl-run.sh b/util/afl/afl-run.sh similarity index 100% rename from zcutil/afl/afl-run.sh rename to util/afl/afl-run.sh diff --git a/zcutil/afl/hush-wrapper b/util/afl/hush-wrapper similarity index 100% rename from zcutil/afl/hush-wrapper rename to util/afl/hush-wrapper diff --git a/zcutil/afl/hush-wrapper-g++ b/util/afl/hush-wrapper-g++ similarity index 100% rename from zcutil/afl/hush-wrapper-g++ rename to util/afl/hush-wrapper-g++ diff --git a/zcutil/afl/hush-wrapper-gcc b/util/afl/hush-wrapper-gcc similarity index 100% rename from zcutil/afl/hush-wrapper-gcc rename to util/afl/hush-wrapper-gcc diff --git a/zcutil/build-arm.sh b/util/build-arm.sh similarity index 100% rename from zcutil/build-arm.sh rename to util/build-arm.sh diff --git a/zcutil/build-debian-package-ARM.sh b/util/build-debian-package-ARM.sh similarity index 100% rename from zcutil/build-debian-package-ARM.sh rename to util/build-debian-package-ARM.sh diff --git a/zcutil/build-debian-package.sh b/util/build-debian-package.sh similarity index 100% rename from zcutil/build-debian-package.sh rename to util/build-debian-package.sh diff --git a/zcutil/build-mac.sh b/util/build-mac.sh similarity index 100% rename from zcutil/build-mac.sh rename to util/build-mac.sh diff --git a/zcutil/build-win.sh b/util/build-win.sh similarity index 100% rename from zcutil/build-win.sh rename to util/build-win.sh diff --git a/zcutil/build.sh b/util/build.sh similarity index 100% rename from zcutil/build.sh rename to util/build.sh diff --git a/zcutil/docker-entrypoint.sh b/util/docker-entrypoint.sh similarity index 100% rename from zcutil/docker-entrypoint.sh rename to util/docker-entrypoint.sh diff --git a/zcutil/docker-hush-cli.sh b/util/docker-hush-cli.sh similarity index 100% rename from zcutil/docker-hush-cli.sh rename to util/docker-hush-cli.sh diff --git a/zcutil/dragon.txt b/util/dragon.txt similarity index 100% rename from zcutil/dragon.txt rename to util/dragon.txt From d2478acea453301bcfff0c89ac975e430f5d5168 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Sun, 18 Sep 2022 14:56:42 -0400 Subject: [PATCH 189/255] continued util change --- DEVELOPING.md | 2 +- util/afl/afl-build.sh | 12 ++++++------ util/afl/afl-get.sh | 4 ++-- util/afl/afl-getbuildrun.sh | 6 +++--- util/build-arm.sh | 2 +- util/build-debian-package-ARM.sh | 2 +- util/build-debian-package.sh | 2 +- util/build.sh | 6 +++--- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/DEVELOPING.md b/DEVELOPING.md index 0aae790f5..069fb7496 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -84,7 +84,7 @@ to generate new unix man pages for that version : After successfully compiling Hush, you can generate a debian package of these binaries with: - ./zcutil/build-debian-package.sh + ./util/build-debian-package.sh This command will not work on Mac OS X. Currently you cannot generate a Debian package from operating systems other than Linux. Oh well. diff --git a/util/afl/afl-build.sh b/util/afl/afl-build.sh index a64d47de3..74d5980ce 100755 --- a/util/afl/afl-build.sh +++ b/util/afl/afl-build.sh @@ -2,9 +2,9 @@ # Copyright (c) 2016-2021 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html -# A wrapper around ./zcutil/build.sh for instrumenting the build with AFL: -# ./zcutil/afl/afl-build.sh -# You may obtain a copy of AFL using ./zcutil/afl/afl-get.sh. +# A wrapper around ./util/build.sh for instrumenting the build with AFL: +# ./util/afl/afl-build.sh +# You may obtain a copy of AFL using ./util/afl/afl-get.sh. set -eu -o pipefail @@ -12,11 +12,11 @@ export AFL_INSTALL_DIR=$(realpath "$1") FUZZ_CASE="$2" shift 2 export AFL_LOG_DIR="$(pwd)" -export ZCUTIL=$(realpath "./zcutil") +export UTIL=$(realpath "./util") cp "./src/fuzzing/$FUZZ_CASE/fuzz.cpp" src/fuzz.cpp -CONFIGURE_FLAGS="--enable-tests=no --enable-fuzz-main" "$ZCUTIL/build.sh" "CC=$ZCUTIL/afl/hush-wrapper-gcc" "CXX=$ZCUTIL/afl/hush-wrapper-g++" AFL_HARDEN=1 "$@" +CONFIGURE_FLAGS="--enable-tests=no --enable-fuzz-main" "$UTIL/build.sh" "CC=$UTIL/afl/hush-wrapper-gcc" "CXX=$UTIL/afl/hush-wrapper-g++" AFL_HARDEN=1 "$@" echo "You can now run AFL as follows:" -echo "$ ./zcutil/afl/afl-run.sh '$AFL_INSTALL_DIR' '$FUZZ_CASE'" +echo "$ ./util/afl/afl-run.sh '$AFL_INSTALL_DIR' '$FUZZ_CASE'" diff --git a/util/afl/afl-get.sh b/util/afl/afl-get.sh index 255adeb17..0156b5105 100755 --- a/util/afl/afl-get.sh +++ b/util/afl/afl-get.sh @@ -3,7 +3,7 @@ # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # Obtains and builds a copy of AFL from source. -# ./zcutil/afl/afl-get.sh +# ./util/afl/afl-get.sh set -eu -o pipefail @@ -32,5 +32,5 @@ make echo "You can now build hushd with AFL instrumentation as follows:" echo "$ make clean # if you've already built hushd without AFL instrumentation" -echo "$ ./zcutil/afl/afl-build.sh '$(pwd)' -j\$(nproc)" +echo "$ ./util/afl/afl-build.sh '$(pwd)' -j\$(nproc)" echo "...where is the name of a directory in src/fuzzing." diff --git a/util/afl/afl-getbuildrun.sh b/util/afl/afl-getbuildrun.sh index de9dba15b..5bd1986f9 100755 --- a/util/afl/afl-getbuildrun.sh +++ b/util/afl/afl-getbuildrun.sh @@ -16,8 +16,8 @@ export AFL_INSTALL_DIR=$(realpath "./afl-temp") if [ ! -d "$AFL_INSTALL_DIR" ]; then mkdir "$AFL_INSTALL_DIR" - ./zcutil/afl/afl-get.sh "$AFL_INSTALL_DIR" + ./util/afl/afl-get.sh "$AFL_INSTALL_DIR" fi -./zcutil/afl/afl-build.sh "$AFL_INSTALL_DIR" "$FUZZ_CASE" -j$(nproc) -./zcutil/afl/afl-run.sh "$AFL_INSTALL_DIR" "$FUZZ_CASE" "$@" +./util/afl/afl-build.sh "$AFL_INSTALL_DIR" "$FUZZ_CASE" -j$(nproc) +./util/afl/afl-run.sh "$AFL_INSTALL_DIR" "$FUZZ_CASE" "$@" diff --git a/util/build-arm.sh b/util/build-arm.sh index c721b3e57..a3a1b927b 100755 --- a/util/build-arm.sh +++ b/util/build-arm.sh @@ -22,7 +22,7 @@ EOF if [ "x$*" = 'x--help' ] then - cat ./zcutil/dragon.txt + cat ./util/dragon.txt cat < Date: Mon, 19 Sep 2022 01:09:36 +0000 Subject: [PATCH 190/255] Update 'doc/release-process.md' --- doc/release-process.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/release-process.md b/doc/release-process.md index c46f54b9a..9a41b71a9 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -73,4 +73,8 @@ Install deps on Linux: - Stop node, wait 20 minutes, and then do a partial sync with new checkpoints - Make Gitea release - Make Git Tag (Gitea can do this) + - Use contrib/devtools/gen-linux-binary-release.sh to make a Linux release binary + - Use util/build-debian-package.sh to make an x86 Debian package for the release + - Use util/build-debian-package-ARM.sh (does this still work?) to make an ARM Debian package for the release + - Upload the debian packages to the Gitea release page, with SHA256 sums From 4ae1d47aec67c2814566ba9bd2831bacfdd3ec9c Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 01:11:22 +0000 Subject: [PATCH 191/255] Update 'doc/release-process.md' --- doc/release-process.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/release-process.md b/doc/release-process.md index 9a41b71a9..adc88c02c 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -62,6 +62,7 @@ Install deps on Linux: - A `CLIENT_VERSION_BUILD` of 50 means "actual non-beta release" - Make sure to keep the values in configure.ac and src/clientversion.h the same. The variables are prefixed wth an underscore in configure.ac - Run ./contrib/devtools/gen-manpages.sh, commit + push results + - PROTIP: Man page creation must be done after updating the version number and recompiling and before Debian package creation - Update checkpoints in src/chainparams.cpp via contrib/checkpoints.pl - checkpoints.pl will just generate the data you need, it must be manually copied into the correct place - Checkpoint are a list of block heights and block hashes that tell a full node the correct block history of the blockchain From a564bc017c6b6fc97506b16c7b4206774ec9ebe9 Mon Sep 17 00:00:00 2001 From: fekt Date: Mon, 19 Sep 2022 03:59:39 +0000 Subject: [PATCH 192/255] RandomX updates for build-win.sh --- util/build-win.sh | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/util/build-win.sh b/util/build-win.sh index 4b1960245..2e573281b 100755 --- a/util/build-win.sh +++ b/util/build-win.sh @@ -8,20 +8,36 @@ CC=x86_64-w64-mingw32-gcc-posix PREFIX="$(pwd)/depends/$HOST" set -eu -o pipefail - set -x -cd "$(dirname "$(readlink -f "$0")")/.." +cd "$(dirname "$(readlink -f "$0")")/.." cd depends/ && make HOST=$HOST V=1 NO_QT=1 -cd ../ +cd .. + +./autogen.sh + +CONFIG_SITE=$PWD/depends/x86_64-w64-mingw32/share/config.site CXXFLAGS="-DPTW32_STATIC_LIB -DCURL_STATICLIB -fopenmp -pthread" ./configure --prefix="${PREFIX}" --host=x86_64-w64-mingw32 --enable-static --disable-shared + +# Build CryptoConditions stuff WD=$PWD cd src/cc echo $PWD ./makecustom cd $WD -./autogen.sh -CONFIG_SITE=$PWD/depends/x86_64-w64-mingw32/share/config.site CXXFLAGS="-DPTW32_STATIC_LIB -DCURL_STATICLIB -fopenmp -pthread" ./configure --prefix="${PREFIX}" --host=x86_64-w64-mingw32 --enable-static --disable-shared +# Build RandomX +cd src/RandomX +if [ -d "build" ] +then + ls -la build/librandomx* +else + mkdir build && cd build + CC="${CC} -g " CXX="${CXX} -g " cmake -DARCH=native .. + make +fi + +cd $WD + sed -i 's/-lboost_system-mt /-lboost_system-mt-s /' configure cd src/ CC="${CC} -g " CXX="${CXX} -g " make V=1 hushd.exe hush-cli.exe hush-tx.exe From c15f1a93b1f2715f4088be18b9025d05429bc91e Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 05:41:59 -0700 Subject: [PATCH 193/255] Add randomx stuff to build-arm.sh --- util/build-arm.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/util/build-arm.sh b/util/build-arm.sh index a3a1b927b..a9b747354 100755 --- a/util/build-arm.sh +++ b/util/build-arm.sh @@ -57,12 +57,25 @@ HOST=aarch64-unknown-linux-gnu BUILD=aarch64-unknown-linux-gnu make "$@" -C ./de ./autogen.sh CONFIG_SITE="$(pwd)/depends/aarch64-unknown-linux-gnu/share/config.site" ./configure --prefix="${PREFIX}" --host=aarch64-unknown-linux-gnu --build=aarch64-unknown-linux-gnu --with-gui=no --enable-rust=no "$HARDENING_ARG" "$LCOV_ARG" CXXFLAGS='-fwrapv -fno-strict-aliasing -g' -#BUILD CCLIB - +# Build CryptoConditions stuff WD=$PWD cd src/cc echo $PWD ./makecustom cd $WD -make "$@" V=1 +# Build RandomX +cd src/RandomX +if [ -d "build" ] +then + ls -la build/librandomx* +else + mkdir build && cd build + # TODO: Do things work without -DARCH=native ? + # TODO: Make an env var for using native arch + # CC="${CC} -g " CXX="${CXX} -g " cmake -DARCH=native .. + CC="${CC} -g " CXX="${CXX} -g " cmake .. + make +fi + +CC="${CC} -g " CXX="${CXX} -g " make "$@" V=1 From 9bf09f353b24ffb0353c04c7e9b10f5b12c26956 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 05:47:35 -0700 Subject: [PATCH 194/255] Add readme to ./util dir --- util/README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 util/README.md diff --git a/util/README.md b/util/README.md new file mode 100644 index 000000000..aadb9d08d --- /dev/null +++ b/util/README.md @@ -0,0 +1,4 @@ +# Hush utilities + +Scripts in this directory are used by Hush developers in the process of development +or in releasing a new version of Hush. From 84c9b786a73e2e34d4398accf4a3889a486fcec0 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 05:52:53 -0700 Subject: [PATCH 195/255] Move checkpoints.pl to util/ --- contrib/README.md | 1 - doc/release-process.md | 2 +- src/chainparams.cpp | 6 +++--- util/README.md | 4 ++++ {contrib => util}/checkpoints.pl | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) rename {contrib => util}/checkpoints.pl (96%) diff --git a/contrib/README.md b/contrib/README.md index 916e4d094..ed2c7408b 100644 --- a/contrib/README.md +++ b/contrib/README.md @@ -8,7 +8,6 @@ Please fix bugs and report things you find. ## Hush Tools -checkpoints.pl - generate checkpoint data for main.cpp block\_time.pl - estimate when a Hush block will happen ## Wallet Tools diff --git a/doc/release-process.md b/doc/release-process.md index adc88c02c..715ff2e0f 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -63,7 +63,7 @@ Install deps on Linux: - Make sure to keep the values in configure.ac and src/clientversion.h the same. The variables are prefixed wth an underscore in configure.ac - Run ./contrib/devtools/gen-manpages.sh, commit + push results - PROTIP: Man page creation must be done after updating the version number and recompiling and before Debian package creation - - Update checkpoints in src/chainparams.cpp via contrib/checkpoints.pl + - Update checkpoints in src/chainparams.cpp via util/checkpoints.pl - checkpoints.pl will just generate the data you need, it must be manually copied into the correct place - Checkpoint are a list of block heights and block hashes that tell a full node the correct block history of the blockchain - Checkpoints make block verification a bit faster, because nodes can say "is this block a descendant of a checkpoint block" instead of doing full consensus checks, which take more time diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 23d7df788..db3a216da 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -557,14 +557,14 @@ void *chainparams_commandline() { pCurrentParams->consensus.vUpgrades[Consensus::UPGRADE_SAPLING].nActivationHeight = ASSETCHAINS_SAPLING; pCurrentParams->consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = ASSETCHAINS_OVERWINTER; - // Generated at 1575831755 via hush3 contrib/checkpoints.pl by Duke Leto + // Generated at 1575831755 via hush3 util/checkpoints.pl by Duke Leto if (strcmp(SMART_CHAIN_SYMBOL,"HUSH3") == 0) { - // Generated at 1596199654 via hush3 contrib/checkpoints.pl by Duke Leto + // Generated at 1596199654 via hush3 util/checkpoints.pl by Duke Leto checkpointData = //(Checkpoints::CCheckpointData) { boost::assign::map_list_of (0, pCurrentParams->consensus.hashGenesisBlock) - // Last updated at 1613482505 via hush3 contrib/checkpoints.pl by Duke Leto + // Last updated at 1613482505 via hush3 util/checkpoints.pl by Duke Leto (5000, uint256S("0x000000018f8543066baa9c5f83e981749da4cb625fad02c187b4a9c4693ebd60")) (10000, uint256S("0x00000002d177d1cbfeaf7c27a2a32766ea9063d222cbcc7623dc08355b07a3ad")) (15000, uint256S("0x000000008dbfbd5d5e27d819bf2989c5658c3494608bfa1320ad0b090660cd44")) diff --git a/util/README.md b/util/README.md index aadb9d08d..efc52a830 100644 --- a/util/README.md +++ b/util/README.md @@ -2,3 +2,7 @@ Scripts in this directory are used by Hush developers in the process of development or in releasing a new version of Hush. + +## Utilities + +checkpoints.pl - generate checkpoint data for chainparams.cpp diff --git a/contrib/checkpoints.pl b/util/checkpoints.pl similarity index 96% rename from contrib/checkpoints.pl rename to util/checkpoints.pl index ec0dd919d..5b49c2b3e 100755 --- a/contrib/checkpoints.pl +++ b/util/checkpoints.pl @@ -21,7 +21,7 @@ my $last = 0; my $now = time(); chomp($blocks); -print "// Generated at $now via hush3 contrib/checkpoints.pl by Duke Leto\n"; +print "// Generated at $now via hush3 util/checkpoints.pl by Duke Leto\n"; while (1) { $count++; From 93207a2faff8efbfe589f18c0e58da099259bb01 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 05:59:41 -0700 Subject: [PATCH 196/255] Add copyrights to some devtools --- contrib/devtools/security-check.py | 3 +++ contrib/devtools/symbol-check.py | 1 + 2 files changed, 4 insertions(+) diff --git a/contrib/devtools/security-check.py b/contrib/devtools/security-check.py index 43c825bde..8eec65b0f 100755 --- a/contrib/devtools/security-check.py +++ b/contrib/devtools/security-check.py @@ -1,4 +1,7 @@ #!/usr/bin/env python +# Copyright (c) 2016-2022 The Hush developers +# Distributed under the GPLv3 software license, see the accompanying +# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html ''' Perform basic ELF security checks on a series of executables. Exit status will be 0 if successful, and the program will be silent. diff --git a/contrib/devtools/symbol-check.py b/contrib/devtools/symbol-check.py index 664895a09..e86b54b2b 100755 --- a/contrib/devtools/symbol-check.py +++ b/contrib/devtools/symbol-check.py @@ -1,5 +1,6 @@ #!/usr/bin/env python # Copyright (c) 2014 Wladimir J. van der Laan +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html ''' From 00aa7eaea46cfb2b930eef08acc02dd9e544664c Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 06:08:53 -0700 Subject: [PATCH 197/255] Remove a tool that was inherited from BTC related to QT code that we don't even have (lulz) --- contrib/devtools/optimize-pngs.py | 73 ------------------------------- 1 file changed, 73 deletions(-) delete mode 100755 contrib/devtools/optimize-pngs.py diff --git a/contrib/devtools/optimize-pngs.py b/contrib/devtools/optimize-pngs.py deleted file mode 100755 index 38aaa00f3..000000000 --- a/contrib/devtools/optimize-pngs.py +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -import subprocess -import hashlib -from PIL import Image - -def file_hash(filename): - '''Return hash of raw file contents''' - with open(filename, 'rb') as f: - return hashlib.sha256(f.read()).hexdigest() - -def content_hash(filename): - '''Return hash of RGBA contents of image''' - i = Image.open(filename) - i = i.convert('RGBA') - data = i.tostring() - return hashlib.sha256(data).hexdigest() - -#optimize png, remove various color profiles, remove ancillary chunks (alla) and text chunks (text) -#pngcrush -brute -ow -rem gAMA -rem cHRM -rem iCCP -rem sRGB -rem alla -rem text - -pngcrush = 'pngcrush' -git = 'git' -folders = ["src/qt/res/movies", "src/qt/res/icons", "src/qt/res/images"] -basePath = subprocess.check_output([git, 'rev-parse', '--show-toplevel']).rstrip('\n') -totalSaveBytes = 0 - -outputArray = [] -for folder in folders: - absFolder=os.path.join(basePath, folder) - for file in os.listdir(absFolder): - extension = os.path.splitext(file)[1] - if extension.lower() == '.png': - print("optimizing "+file+"..."), - file_path = os.path.join(absFolder, file) - fileMetaMap = {'file' : file, 'osize': os.path.getsize(file_path), 'sha256Old' : file_hash(file_path)}; - fileMetaMap['contentHashPre'] = content_hash(file_path) - - pngCrushOutput = "" - try: - pngCrushOutput = subprocess.check_output( - [pngcrush, "-brute", "-ow", "-rem", "gAMA", "-rem", "cHRM", "-rem", "iCCP", "-rem", "sRGB", "-rem", "alla", "-rem", "text", file_path], - stderr=subprocess.STDOUT).rstrip('\n') - except: - print "pngcrush is not installed, aborting..." - sys.exit(0) - - #verify - if "Not a PNG file" in subprocess.check_output([pngcrush, "-n", "-v", file_path], stderr=subprocess.STDOUT): - print "PNG file "+file+" is corrupted after crushing, check out pngcursh version" - sys.exit(1) - - fileMetaMap['sha256New'] = file_hash(file_path) - fileMetaMap['contentHashPost'] = content_hash(file_path) - - if fileMetaMap['contentHashPre'] != fileMetaMap['contentHashPost']: - print "Image contents of PNG file "+file+" before and after crushing don't match" - sys.exit(1) - - fileMetaMap['psize'] = os.path.getsize(file_path) - outputArray.append(fileMetaMap) - print("done\n"), - -print "summary:\n+++++++++++++++++" -for fileDict in outputArray: - oldHash = fileDict['sha256Old'] - newHash = fileDict['sha256New'] - totalSaveBytes += fileDict['osize'] - fileDict['psize'] - print fileDict['file']+"\n size diff from: "+str(fileDict['osize'])+" to: "+str(fileDict['psize'])+"\n old sha256: "+oldHash+"\n new sha256: "+newHash+"\n" - -print "completed. Total reduction: "+str(totalSaveBytes)+" bytes" From 644f43bcc616d1e1410d64c903862184aeff835d Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 06:14:11 -0700 Subject: [PATCH 198/255] move gen-manpages to util/ --- {contrib/devtools => util}/gen-manpages.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {contrib/devtools => util}/gen-manpages.sh (100%) diff --git a/contrib/devtools/gen-manpages.sh b/util/gen-manpages.sh similarity index 100% rename from contrib/devtools/gen-manpages.sh rename to util/gen-manpages.sh From 432ea4b28b00d59ae916dfae2f7d70293cb073c3 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 06:14:34 -0700 Subject: [PATCH 199/255] move replace.pl to util/ --- {contrib/devtools => util}/replace.pl | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {contrib/devtools => util}/replace.pl (100%) diff --git a/contrib/devtools/replace.pl b/util/replace.pl similarity index 100% rename from contrib/devtools/replace.pl rename to util/replace.pl From 2b809c56a0df61a4219de195374f5f3fad0b185a Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 06:16:25 -0700 Subject: [PATCH 200/255] Move things to util/ and update docs+build system references --- DEVELOPING.md | 2 +- Makefile.am | 4 ++-- contrib/devtools/README.md | 2 +- doc/release-process.md | 6 +++--- src/Makefile.am | 4 ++-- {contrib/devtools => util}/security-check.py | 0 {contrib/devtools => util}/symbol-check.py | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) rename {contrib/devtools => util}/security-check.py (100%) rename {contrib/devtools => util}/symbol-check.py (99%) diff --git a/DEVELOPING.md b/DEVELOPING.md index 069fb7496..1de87fcc6 100644 --- a/DEVELOPING.md +++ b/DEVELOPING.md @@ -78,7 +78,7 @@ of a dependency or something inside of Rust, you will need `build.sh` . Make sure that you have updated all version numbers in hushd and compiled, then to generate new unix man pages for that version : - ./contrib/devtools/gen-manpages.sh + ./util/gen-manpages.sh ## Generating new debian packages diff --git a/Makefile.am b/Makefile.am index de977adfc..b76763e10 100644 --- a/Makefile.am +++ b/Makefile.am @@ -24,8 +24,8 @@ BITCOIN_WIN_INSTALLER=$(PACKAGE)-$(PACKAGE_VERSION)-win$(WINDOWS_BITS)-setup$(EX DIST_DOCS = $(wildcard doc/*.md) $(wildcard doc/release-notes/*.md) -BIN_CHECKS=$(top_srcdir)/contrib/devtools/symbol-check.py \ - $(top_srcdir)/contrib/devtools/security-check.py +BIN_CHECKS=$(top_srcdir)/util/symbol-check.py \ + $(top_srcdir)/util/security-check.py diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index fa03b6cff..1b82a47f0 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -14,7 +14,7 @@ still compatible with the minimum supported Linux distribution versions. Example usage after a gitian build: - find ../gitian-builder/build -type f -executable | xargs python contrib/devtools/symbol-check.py + find ../gitian-builder/build -type f -executable | xargs python util/symbol-check.py If only supported symbols are used the return value will be 0 and the output will be empty. diff --git a/doc/release-process.md b/doc/release-process.md index 715ff2e0f..7e1bdd39e 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -61,7 +61,7 @@ Install deps on Linux: - To make a pre-release "beta" you can modify `CLIENT_VERSION_BUILD` but that is rarely done in Hush world. - A `CLIENT_VERSION_BUILD` of 50 means "actual non-beta release" - Make sure to keep the values in configure.ac and src/clientversion.h the same. The variables are prefixed wth an underscore in configure.ac - - Run ./contrib/devtools/gen-manpages.sh, commit + push results + - Run ./util/gen-manpages.sh, commit + push results - PROTIP: Man page creation must be done after updating the version number and recompiling and before Debian package creation - Update checkpoints in src/chainparams.cpp via util/checkpoints.pl - checkpoints.pl will just generate the data you need, it must be manually copied into the correct place @@ -69,12 +69,12 @@ Install deps on Linux: - Checkpoints make block verification a bit faster, because nodes can say "is this block a descendant of a checkpoint block" instead of doing full consensus checks, which take more time - Checkpoints also provide a bit of security against some attacks that would create malicious chainforks - Update man pages - - Update copyright years (if applicable) with contrib/devtools/replace.pl + - Update copyright years (if applicable) with util/replace.pl - Do a fresh clone and fresh sync with new checkpoints - Stop node, wait 20 minutes, and then do a partial sync with new checkpoints - Make Gitea release - Make Git Tag (Gitea can do this) - - Use contrib/devtools/gen-linux-binary-release.sh to make a Linux release binary + - Use util/gen-linux-binary-release.sh to make a Linux release binary - Use util/build-debian-package.sh to make an x86 Debian package for the release - Use util/build-debian-package-ARM.sh (does this still work?) to make an ARM Debian package for the release - Upload the debian packages to the Gitea release page, with SHA256 sums diff --git a/src/Makefile.am b/src/Makefile.am index 797aac856..6a3e3dab8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -683,13 +683,13 @@ clean-local: check-symbols: $(bin_PROGRAMS) if GLIBC_BACK_COMPAT @echo "Checking glibc back compat of [$(bin_PROGRAMS)]..." - $(AM_V_at) READELF=$(READELF) CPPFILT=$(CPPFILT) $(top_srcdir)/contrib/devtools/symbol-check.py $(bin_PROGRAMS) + $(AM_V_at) READELF=$(READELF) CPPFILT=$(CPPFILT) $(top_srcdir)/util/symbol-check.py $(bin_PROGRAMS) endif check-security: $(bin_PROGRAMS) if HARDEN @echo "Checking binary security of [$(bin_PROGRAMS)]..." - $(AM_V_at) READELF=$(READELF) OBJDUMP=$(OBJDUMP) $(top_srcdir)/contrib/devtools/security-check.py $(bin_PROGRAMS) + $(AM_V_at) READELF=$(READELF) OBJDUMP=$(OBJDUMP) $(top_srcdir)/util/security-check.py $(bin_PROGRAMS) endif %.pb.cc %.pb.h: %.proto diff --git a/contrib/devtools/security-check.py b/util/security-check.py similarity index 100% rename from contrib/devtools/security-check.py rename to util/security-check.py diff --git a/contrib/devtools/symbol-check.py b/util/symbol-check.py similarity index 99% rename from contrib/devtools/symbol-check.py rename to util/symbol-check.py index e86b54b2b..312f27e5e 100755 --- a/contrib/devtools/symbol-check.py +++ b/util/symbol-check.py @@ -10,7 +10,7 @@ still compatible with the minimum supported Linux distribution versions. Example usage: - find ../gitian-builder/build -type f -executable | xargs python contrib/devtools/symbol-check.py + find ../gitian-builder/build -type f -executable | xargs python util/symbol-check.py ''' from __future__ import division, print_function import subprocess From 6cd6f7e0bac65a84e5354f0b7a77009926dfeb38 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 06:18:25 -0700 Subject: [PATCH 201/255] Migrate readme docs to util/ --- contrib/devtools/README.md | 26 -------------------------- util/README.md | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index 1b82a47f0..869fa31fe 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -2,28 +2,6 @@ This directory contains tools for developers working on this repository. -## security-check.py - -Perform basic ELF security checks on a series of executables. - -## symbol-check.py - -A script to check that the (Linux) executables produced by gitian only contain -allowed gcc, glibc and libstdc++ version symbols. This makes sure they are -still compatible with the minimum supported Linux distribution versions. - -Example usage after a gitian build: - - find ../gitian-builder/build -type f -executable | xargs python util/symbol-check.py - -If only supported symbols are used the return value will be 0 and the output will be empty. - -If there are 'unsupported' symbols, the return value will be 1 a list like this will be printed: - - .../64/test_bitcoin: symbol memcpy from unsupported version GLIBC_2.14 - .../64/test_bitcoin: symbol __fdelt_chk from unsupported version GLIBC_2.15 - .../64/test_bitcoin: symbol std::out_of_range::~out_of_range() from unsupported version GLIBCXX_3.4.15 - .../64/test_bitcoin: symbol _ZNSt8__detail15_List_nod from unsupported version GLIBCXX_3.4.15 ## update-translations.py @@ -36,7 +14,3 @@ It will do the following automatically: See doc/translation-process.md for more information. -## gen-manpages.sh - -A small script to automatically create manpages in ../../doc/man by running the release binaries with the -help option. -This requires help2man which can be found at: https://www.gnu.org/software/help2man/ diff --git a/util/README.md b/util/README.md index efc52a830..f672e73f1 100644 --- a/util/README.md +++ b/util/README.md @@ -3,6 +3,38 @@ Scripts in this directory are used by Hush developers in the process of development or in releasing a new version of Hush. -## Utilities +Utilities in this directory: -checkpoints.pl - generate checkpoint data for chainparams.cpp +## checkpoints.pl + +Generate checkpoint data for chainparams.cpp . This automates the creation of +block heights and block hashes by asking hushd for the data and then generating +the C++ code needed to embed them in the Hush source code. + +## security-check.py + +Perform basic ELF security checks on a series of executables. + +## symbol-check.py + +A script to check that the (Linux) executables produced by gitian only contain +allowed gcc, glibc and libstdc++ version symbols. This makes sure they are +still compatible with the minimum supported Linux distribution versions. + +Example usage after a gitian build: + + find ../gitian-builder/build -type f -executable | xargs python util/symbol-check.py + +If only supported symbols are used the return value will be 0 and the output will be empty. + +If there are 'unsupported' symbols, the return value will be 1 a list like this will be printed: + + .../64/test_bitcoin: symbol memcpy from unsupported version GLIBC_2.14 + .../64/test_bitcoin: symbol __fdelt_chk from unsupported version GLIBC_2.15 + .../64/test_bitcoin: symbol std::out_of_range::~out_of_range() from unsupported version GLIBCXX_3.4.15 + .../64/test_bitcoin: symbol _ZNSt8__detail15_List_nod from unsupported version GLIBCXX_3.4.15 + +## gen-manpages.sh + +A small script to automatically create manpages in ../../doc/man by running the release binaries with the -help option. +This requires help2man which can be found at: https://www.gnu.org/software/help2man/ From 5b105ce61a626edf0c215f5e852b72817319f6ae Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 06:19:01 -0700 Subject: [PATCH 202/255] This tool does not exist in our repo --- contrib/devtools/README.md | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index 869fa31fe..02694f222 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -2,15 +2,3 @@ This directory contains tools for developers working on this repository. - -## update-translations.py - -Run this script from the root of the repository to update all translations from transifex. -It will do the following automatically: - -- fetch all translations -- post-process them into valid and committable format -- add missing translations to the build system (TODO) - -See doc/translation-process.md for more information. - From 7000ba189cff59d4a85596785dcdaa749d8e376f Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 06:20:15 -0700 Subject: [PATCH 203/255] Move the rest of devtools to util/ --- {contrib/devtools => util}/gen-linux-binary-release.sh | 0 {contrib/devtools => util}/split-debug.sh | 0 {contrib/devtools => util}/test-security-check.py | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {contrib/devtools => util}/gen-linux-binary-release.sh (100%) rename {contrib/devtools => util}/split-debug.sh (100%) rename {contrib/devtools => util}/test-security-check.py (100%) diff --git a/contrib/devtools/gen-linux-binary-release.sh b/util/gen-linux-binary-release.sh similarity index 100% rename from contrib/devtools/gen-linux-binary-release.sh rename to util/gen-linux-binary-release.sh diff --git a/contrib/devtools/split-debug.sh b/util/split-debug.sh similarity index 100% rename from contrib/devtools/split-debug.sh rename to util/split-debug.sh diff --git a/contrib/devtools/test-security-check.py b/util/test-security-check.py similarity index 100% rename from contrib/devtools/test-security-check.py rename to util/test-security-check.py From dd83c0f427cbde4698d036533a15d1bc2e7f18fe Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 06:20:41 -0700 Subject: [PATCH 204/255] Remove contrib/devtools/ --- contrib/devtools/README.md | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 contrib/devtools/README.md diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md deleted file mode 100644 index 02694f222..000000000 --- a/contrib/devtools/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# Contrib Devtools - -This directory contains tools for developers working on this repository. - From 54cfe10994241ef5d6e5f1cd3eb821843d853d3c Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 06:25:18 -0700 Subject: [PATCH 205/255] Document all scripts in util/ --- util/README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/util/README.md b/util/README.md index f672e73f1..a1ff2040f 100644 --- a/util/README.md +++ b/util/README.md @@ -5,12 +5,49 @@ or in releasing a new version of Hush. Utilities in this directory: +## build.sh + +Compile Hush full node code. + +## build-arm.sh + +Compile Hush full node code for ARM architecture. + +## build-debian-package.sh + +Builds an x86 Debain package for Hush. + +## build-debian-package-ARM.sh + +Builds an ARM Debain package for Hush. + +## build-mac.sh + +Compile Hush full node code for mac. NOTE: This is likely broken. + +## build-win.sh + +Compile Hush full node code for windows + ## checkpoints.pl Generate checkpoint data for chainparams.cpp . This automates the creation of block heights and block hashes by asking hushd for the data and then generating the C++ code needed to embed them in the Hush source code. +## docker-entrypoint.sh + +Script to use Hush with Docker. + +## docker-hush-cli.sh + +Convenience script to run hush-cli in a running Docker container. + +## replace.pl + +Replace a string in a set of files by another string. Very useful for updating +a variable name or value across many files, or updating copyrights. + ## security-check.py Perform basic ELF security checks on a series of executables. @@ -38,3 +75,7 @@ If there are 'unsupported' symbols, the return value will be 1 a list like this A small script to automatically create manpages in ../../doc/man by running the release binaries with the -help option. This requires help2man which can be found at: https://www.gnu.org/software/help2man/ + +## gen-linux-binary-release.sh + +Generate linux release binary. From 3a36f544aab5bef3cff524982f247078c2c12182 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 07:15:08 -0700 Subject: [PATCH 206/255] Get rid of boost stacktrace stuff --- src/wallet/asyncrpcoperation_saplingconsolidation.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index 6eb20d2e6..41f1fc07e 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -16,12 +16,6 @@ #include "util.h" #include "utilmoneystr.h" #include "wallet.h" -#include -#include - -// enable function names and line numbers in backtraces -#define BOOST_STACKTRACE_LINK -#define BOOST_STACKTRACE_USE_ADDR2LINE CAmount fConsolidationTxFee = DEFAULT_CONSOLIDATION_FEE; bool fConsolidationMapUsed = false; @@ -50,7 +44,6 @@ void AsyncRPCOperation_saplingconsolidation::main() { set_error_code(code); set_error_message(message); } catch (const runtime_error& e) { - std::cerr << "Consolidation stacktrace:" << '\n' << boost::stacktrace::stacktrace() << '\n'; set_error_code(-1); set_error_code(-1); set_error_message("runtime error: " + string(e.what())); From c7c2a98eafdb3c2eb6031df978b8ba75ece5aa6a Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 11:41:31 -0400 Subject: [PATCH 207/255] Update manpages and add 'make manpages' target --- Makefile.am | 4 ++++ doc/man/hush-cli.1 | 6 +++--- doc/man/hush-tx.1 | 6 +++--- doc/man/hushd.1 | 35 ++++++++++++++++++++++++++++++++--- 4 files changed, 42 insertions(+), 9 deletions(-) diff --git a/Makefile.am b/Makefile.am index b76763e10..1cdfb6ab3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -247,4 +247,8 @@ DISTCHECK_CONFIGURE_FLAGS = --enable-man clean-local: rm -rf test_bitcoin.coverage/ total.coverage/ +manpages: + ./util/gen-manpages.sh + echo "Please review the man pages changes to see if they look correct, then commit and push" + # I also heard about a bug in the UNIVAC but it's too big for this comment. -- Duke diff --git a/doc/man/hush-cli.1 b/doc/man/hush-cli.1 index 51f26c6a4..f2b36ac28 100644 --- a/doc/man/hush-cli.1 +++ b/doc/man/hush-cli.1 @@ -1,9 +1,9 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.13. -.TH HUSH-CLI "1" "September 2022" "hush-cli v3.9.1" "User Commands" +.TH HUSH-CLI "1" "September 2022" "hush-cli v3.9.2" "User Commands" .SH NAME -hush-cli \- manual page for hush-cli v3.9.1 +hush-cli \- manual page for hush-cli v3.9.2 .SH DESCRIPTION -Hush RPC client version v3.9.1\-1799c6c9b +Hush RPC client version v3.9.2\-54cfe1099 .PP In order to ensure you are adequately protecting your privacy when using Hush, please see . diff --git a/doc/man/hush-tx.1 b/doc/man/hush-tx.1 index 8318b2aa2..f34354e45 100644 --- a/doc/man/hush-tx.1 +++ b/doc/man/hush-tx.1 @@ -1,9 +1,9 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.13. -.TH HUSH-TX "1" "September 2022" "hush-tx v3.9.1" "User Commands" +.TH HUSH-TX "1" "September 2022" "hush-tx v3.9.2" "User Commands" .SH NAME -hush-tx \- manual page for hush-tx v3.9.1 +hush-tx \- manual page for hush-tx v3.9.2 .SH DESCRIPTION -hush\-tx utility version v3.9.1\-1799c6c9b +hush\-tx utility version v3.9.2\-54cfe1099 .SS "Usage:" .TP hush\-tx [options] [commands] diff --git a/doc/man/hushd.1 b/doc/man/hushd.1 index eebf51b5b..9f69dd460 100644 --- a/doc/man/hushd.1 +++ b/doc/man/hushd.1 @@ -1,9 +1,9 @@ .\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.13. -.TH HUSHD "1" "September 2022" "hushd v3.9.1" "User Commands" +.TH HUSHD "1" "September 2022" "hushd v3.9.2" "User Commands" .SH NAME -hushd \- manual page for hushd v3.9.1 +hushd \- manual page for hushd v3.9.2 .SH DESCRIPTION -Hush Daemon version v3.9.1\-1799c6c9b +Hush Daemon version v3.9.2\-54cfe1099 .PP In order to ensure you are adequately protecting your privacy when using Hush, please see . @@ -314,6 +314,35 @@ Specify Sapling Address to Consolidate. (default: all) Fee amount in Puposhis used send consolidation transactions. (default 10000) .HP +\fB\-zsweep\fR +.IP +Enable zaddr sweeping, automatically move all shielded funds to a one +address once per X blocks +.HP +\fB\-zsweepaddress=\fR +.IP +Specify the shielded address where swept funds will be sent) +.HP +\fB\-zsweepfee\fR +.IP +Fee amount in puposhis used send sweep transactions. (default 10000) +.HP +\fB\-zsweepinterval\fR +.IP +Sweep shielded funds every X blocks (default 5) +.HP +\fB\-zsweepmaxinputs\fR +.IP +Maximum number of shielded inputs to sweep per transaction (default 8) +.HP +\fB\-zsweepexternal\fR +.IP +Enable sweeping to an external wallet (default false) +.HP +\fB\-zsweepexclude\fR +.IP +Addresses to exclude from sweeping (default none) +.HP \fB\-deletetx\fR .IP Enable Old Transaction Deletion From bf039e366514720fec03306025689c1cc8bad5c6 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 11:42:13 -0400 Subject: [PATCH 208/255] Do not echo this echo command when running --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index 1cdfb6ab3..84a4aed25 100644 --- a/Makefile.am +++ b/Makefile.am @@ -249,6 +249,6 @@ clean-local: manpages: ./util/gen-manpages.sh - echo "Please review the man pages changes to see if they look correct, then commit and push" + @echo "Please review the man pages changes to see if they look correct, then commit and push" # I also heard about a bug in the UNIVAC but it's too big for this comment. -- Duke From afcedbd06a1706c1cd59d31e837692198e02a80b Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 11:43:37 -0400 Subject: [PATCH 209/255] Update docs about make manpages --- doc/release-process.md | 2 +- util/README.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/release-process.md b/doc/release-process.md index 7e1bdd39e..75ea5d4f1 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -61,7 +61,7 @@ Install deps on Linux: - To make a pre-release "beta" you can modify `CLIENT_VERSION_BUILD` but that is rarely done in Hush world. - A `CLIENT_VERSION_BUILD` of 50 means "actual non-beta release" - Make sure to keep the values in configure.ac and src/clientversion.h the same. The variables are prefixed wth an underscore in configure.ac - - Run ./util/gen-manpages.sh, commit + push results + - Run `make manpages`, commit + push results - PROTIP: Man page creation must be done after updating the version number and recompiling and before Debian package creation - Update checkpoints in src/chainparams.cpp via util/checkpoints.pl - checkpoints.pl will just generate the data you need, it must be manually copied into the correct place diff --git a/util/README.md b/util/README.md index a1ff2040f..0c7408f4d 100644 --- a/util/README.md +++ b/util/README.md @@ -76,6 +76,8 @@ If there are 'unsupported' symbols, the return value will be 1 a list like this A small script to automatically create manpages in ../../doc/man by running the release binaries with the -help option. This requires help2man which can be found at: https://www.gnu.org/software/help2man/ +When you type "make manpages" it runs this script. + ## gen-linux-binary-release.sh Generate linux release binary. From 50c4af69f1541d11102c59130c6e873b97fb698f Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 12:54:03 -0400 Subject: [PATCH 210/255] More details about the release process --- doc/release-process.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/doc/release-process.md b/doc/release-process.md index 75ea5d4f1..e72aa90c4 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -62,13 +62,19 @@ Install deps on Linux: - A `CLIENT_VERSION_BUILD` of 50 means "actual non-beta release" - Make sure to keep the values in configure.ac and src/clientversion.h the same. The variables are prefixed wth an underscore in configure.ac - Run `make manpages`, commit + push results + - hushd must be running so the script can automatically get the correct version number + - There is a hack in the script where you can hardcode a version number if hushd isn't running. + - Comment out the HUSHVER line and uncomment the line above it with a hardcoded version number - PROTIP: Man page creation must be done after updating the version number and recompiling and before Debian package creation - Update checkpoints in src/chainparams.cpp via util/checkpoints.pl + - hushd must be running to run this script, since it uses hush-cli to get the data - checkpoints.pl will just generate the data you need, it must be manually copied into the correct place - - Checkpoint are a list of block heights and block hashes that tell a full node the correct block history of the blockchain - - Checkpoints make block verification a bit faster, because nodes can say "is this block a descendant of a checkpoint block" instead of doing full consensus checks, which take more time + - Checkpoints are a list of block heights and block hashes that tell a full node the correct block history of the blockchain + - Checkpoints make block verification a bit faster, because nodes can say "is this block a descendant of a checkpoint block?" instead of doing full consensus checks, which take more time - Checkpoints also provide a bit of security against some attacks that would create malicious chainforks - - Update man pages + - They only provide limited security, because they talk about the past, not future block heights. + - Try to generate checkpoints as close to the release as possible, so you can have a recent block height be protected. + - For instance, don't update checkpoints and then do a release a month later. You can always update checkpoint data again or multiple times - Update copyright years (if applicable) with util/replace.pl - Do a fresh clone and fresh sync with new checkpoints - Stop node, wait 20 minutes, and then do a partial sync with new checkpoints @@ -76,6 +82,7 @@ Install deps on Linux: - Make Git Tag (Gitea can do this) - Use util/gen-linux-binary-release.sh to make a Linux release binary - Use util/build-debian-package.sh to make an x86 Debian package for the release + - Debian packages should be done after you make manpages, because those are included in Debian packages - Use util/build-debian-package-ARM.sh (does this still work?) to make an ARM Debian package for the release - Upload the debian packages to the Gitea release page, with SHA256 sums From 473ec3040428212c062d02b25b6b7e831e4c7f52 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 13:06:39 -0400 Subject: [PATCH 211/255] More checkpoint tribal knowledge --- doc/release-process.md | 6 ++++++ src/chainparams.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/doc/release-process.md b/doc/release-process.md index e72aa90c4..7f57e3ad8 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -68,6 +68,12 @@ Install deps on Linux: - PROTIP: Man page creation must be done after updating the version number and recompiling and before Debian package creation - Update checkpoints in src/chainparams.cpp via util/checkpoints.pl - hushd must be running to run this script, since it uses hush-cli to get the data + - Run `./util/checkpoints.pl &> checkpoints.txt` to generate the latets checkpoint data + - By default it will generate checkpoints for every 1000 blocks, the "stride" + - You can get a different "stride" by passing it in as the first arg to the script + - To get checkpoint data for every 5000 blocks: `./util/checkpoints.pl 5000 &> checkpoints.txt` + - Currently checkpoints from before block 340k are given for every 5k blocks to keep the data smaller + - Look for line which says "HUSH mainnet checkpoint data" near line 560 in chainparams.cpp , that is where checkpoint data begins. - checkpoints.pl will just generate the data you need, it must be manually copied into the correct place - Checkpoints are a list of block heights and block hashes that tell a full node the correct block history of the blockchain - Checkpoints make block verification a bit faster, because nodes can say "is this block a descendant of a checkpoint block?" instead of doing full consensus checks, which take more time diff --git a/src/chainparams.cpp b/src/chainparams.cpp index db3a216da..be0b8ce42 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -559,7 +559,7 @@ void *chainparams_commandline() { pCurrentParams->consensus.vUpgrades[Consensus::UPGRADE_OVERWINTER].nActivationHeight = ASSETCHAINS_OVERWINTER; // Generated at 1575831755 via hush3 util/checkpoints.pl by Duke Leto if (strcmp(SMART_CHAIN_SYMBOL,"HUSH3") == 0) { - // Generated at 1596199654 via hush3 util/checkpoints.pl by Duke Leto + // HUSH mainnet checkpoint data checkpointData = //(Checkpoints::CCheckpointData) { boost::assign::map_list_of From 0fb9db169cd293a51ade5d1ffe4a56f372335d91 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 13:12:37 -0400 Subject: [PATCH 212/255] Basic CLI help and error checking for a valid stride --- util/checkpoints.pl | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/util/checkpoints.pl b/util/checkpoints.pl index 5b49c2b3e..b5eca7109 100755 --- a/util/checkpoints.pl +++ b/util/checkpoints.pl @@ -10,6 +10,16 @@ my $perday = 1152; my $hush = "./src/hush-cli"; my $gethash = "$hush getblockhash"; my $stride = shift || 1000; +if ($stride =~ m/help/) { + print "To generate checkpoint data every 1000 blocks: $0 &> checkpoints.txt\n"; + print "To generate checkpoint data every X blocks: $0 X &> checkpoints.txt\n"; + exit 0; +} + +unless ($stride == int($stride) and $stride >= 0) { + print "Invalid stride! Must be an integer > 0\n"; + exit 1; +} my $count = 0; my $blocks = qx{$hush getblockcount}; if($?) { From 92b387baed2fe2f87f35b4cc7dca55ba2f6487e4 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 13:16:20 -0400 Subject: [PATCH 213/255] Allow custom starting height to generate checkpoint data --- util/checkpoints.pl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/util/checkpoints.pl b/util/checkpoints.pl index b5eca7109..ae273ed85 100755 --- a/util/checkpoints.pl +++ b/util/checkpoints.pl @@ -13,6 +13,7 @@ my $stride = shift || 1000; if ($stride =~ m/help/) { print "To generate checkpoint data every 1000 blocks: $0 &> checkpoints.txt\n"; print "To generate checkpoint data every X blocks: $0 X &> checkpoints.txt\n"; + print "To generate checkpoint data every X blocks starting at height Y: $0 X Y &> checkpoints.txt\n"; exit 0; } @@ -20,6 +21,13 @@ unless ($stride == int($stride) and $stride >= 0) { print "Invalid stride! Must be an integer > 0\n"; exit 1; } +my $start_height = shift || 0; + +unless ($start_height == int($start_height) and $start_height >= 0) { + print "Invalid start_height! Must be an integer > 0\n"; + exit 1; +} + my $count = 0; my $blocks = qx{$hush getblockcount}; if($?) { @@ -35,7 +43,7 @@ print "// Generated at $now via hush3 util/checkpoints.pl by Duke Leto\n"; while (1) { $count++; - my $block = $stride*$count; + my $block = $start_height + $stride*$count; if ($block > $blocks) { $last = $stride*($count-1); #print "last checkpointed block=$last\n"; From 53343051e82315ae00d25f16a3b4a275d2328004 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 13:25:07 -0400 Subject: [PATCH 214/255] Fix bug in calculating the last checkpointed block that is used in the stats --- util/checkpoints.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/checkpoints.pl b/util/checkpoints.pl index ae273ed85..25cf5e3ad 100755 --- a/util/checkpoints.pl +++ b/util/checkpoints.pl @@ -45,7 +45,7 @@ while (1) { $count++; my $block = $start_height + $stride*$count; if ($block > $blocks) { - $last = $stride*($count-1); + $last = $start_height + $stride*($count-1); #print "last checkpointed block=$last\n"; last; } From d52ae9702606d8f4fec8756a2b40a83fd2b7b824 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 13:25:26 -0400 Subject: [PATCH 215/255] Update checkpoint data up to block 1087000 --- src/chainparams.cpp | 285 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 280 insertions(+), 5 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index be0b8ce42..fe1470556 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -564,7 +564,7 @@ void *chainparams_commandline() { { boost::assign::map_list_of (0, pCurrentParams->consensus.hashGenesisBlock) - // Last updated at 1613482505 via hush3 util/checkpoints.pl by Duke Leto + // Generated at 1663607867 via hush3 util/checkpoints.pl by Duke Leto (5000, uint256S("0x000000018f8543066baa9c5f83e981749da4cb625fad02c187b4a9c4693ebd60")) (10000, uint256S("0x00000002d177d1cbfeaf7c27a2a32766ea9063d222cbcc7623dc08355b07a3ad")) (15000, uint256S("0x000000008dbfbd5d5e27d819bf2989c5658c3494608bfa1320ad0b090660cd44")) @@ -1109,11 +1109,286 @@ void *chainparams_commandline() { (811000, uint256S("0x000000135b3c8688693605a5878f5ffc9c486e13e4f12846e27b20da6486df29")) (812000, uint256S("0x000000130932327eb52b9229cb8574b552f39a83d8def5bd2ce12a6094f26093")) (813000, uint256S("0x0000000236505351e3ed94c075d7ab4f91cec65b4d15d8e47338833c744eaf00")) - (814000, uint256S("0x000000025cdfe869ed1ab7cf74c5fdad85e7c2b1b946b2c618d4035db2ae25cb")), - (int64_t) 1643000155, // time of last checkpointed block - (int64_t) 1256633, // total txs - (double) 1264 // txs in the last day before block 814560 + (814000, uint256S("0x000000025cdfe869ed1ab7cf74c5fdad85e7c2b1b946b2c618d4035db2ae25cb")) + (815000, uint256S("0x0000000df6cb366d1a19f44bf3965b113f230cace50ae43d902e36cc1b57c90f")) + (816000, uint256S("0x0000000ce78de6f9de658579a6f50e62b4c40dad76f8cd1c1734e18bb27ce36c")) + (817000, uint256S("0x00000002d556f863beff97cdff35ab19b8b95c8b17732a53794225fe4b1cf79b")) + (818000, uint256S("0x00000000a91755f89698a6039966df4917f14102c5b80c05367c4257f742b90b")) + (819000, uint256S("0x00000004267b5979c64305cb0f7bf39d226cde964311e38703eb9140e814cb76")) + (820000, uint256S("0x0000000607425566e85aaf1359ef51d3259ec2df92db17dc34590eb77285a502")) + (821000, uint256S("0x0000000294b9fa2516ab740b958360adf345415c669a4e13790d0ccd4fcd8131")) + (822000, uint256S("0x00000004c2002010881ddde59c8c8da131c9eeb2008d48516fe8797e3d9936af")) + (823000, uint256S("0x0000000181ba0fb0c33bcdd75f7498783edb6cf4a55cea03ee4b493ffe7911a4")) + (824000, uint256S("0x000000017bb225cfbe64692124d73ad171e629888f43b61df3f9bd457d112b95")) + (825000, uint256S("0x0000000a88847a0390971f151ad158ea274959ae17b41b7ad6879feb5ad08d49")) + (826000, uint256S("0x00000004aac5c10ff8e98390aa9528e360ac9d06abbb6e5a2b314595c40fdb8c")) + (827000, uint256S("0x00000006d00db50776c04ac598f74b2a98a4075f9bcbe316ec9efb3925513941")) + (828000, uint256S("0x0000000b327df01d652145ec09f4c78503e0f88ad68bebf2f3d22e7b66b067ee")) + (829000, uint256S("0x00000008113ea9b858888e82e0aff0d00e2be8f1d235aebfe36abdc9d0fc3f9e")) + (830000, uint256S("0x00000004449ac67abb08ffeb3cd8f830b6699ce39f1ae1abd95ce8c5d05f4696")) + (831000, uint256S("0x000000004f7397d147962983bb60a61702cb7d11c510269ced26e75df3be2690")) + (832000, uint256S("0x00000006ba456ab6e26a64da7332f634c571b102f69d22ef5e51a204496e4772")) + (833000, uint256S("0x0000000309517d3184a0bdeccd6e1bd3e2c99659ae80188636ec75c6f334de71")) + (834000, uint256S("0x00000000207fb66452b2586ad2323180c1c9c9859273c1732e33508ad3adb296")) + (835000, uint256S("0x0000000205b3cd0d3d5685aef16714eb825ecbac18ea7465406afe7f50ee2ad2")) + (836000, uint256S("0x000000019d49b8f7a3fbace5d74b484e8dd26959fb14ec0657426d81e0f98751")) + (837000, uint256S("0x0000000512cc6166087ff6ebd96d9f51082f6107ff0b132d569cf67019ab380c")) + (838000, uint256S("0x0000000217322c5faf9a90f5717c9082206fb6ea8c6910c7b8170ab4f12f4fd7")) + (839000, uint256S("0x00000003d36077dd9999f9a5323efb4e36224bd11f9b48a2d214996fd3740c27")) + (840000, uint256S("0x000000052f0c5fdb92f79d73c2c61e3ed4bf39615f3b6443cc0c06e9cecb6f1d")) + (841000, uint256S("0x00000001dfa9e6e2e2a90cde84d736281ce0acb2660154c51522bfadc403c596")) + (842000, uint256S("0x0000000225d380d6b39fe31bed0b3505a3de935cb0de55d51732237d0d9be477")) + (843000, uint256S("0x0000000157a60eeb0e41cafba5d4c7c0ca4ab2aee4a61be5025333234ce8578f")) + (844000, uint256S("0x00000004bd35390bcfc21f7ce16dbe8da9587bfb9e03a0c4e1fd98e956e1fd4f")) + (845000, uint256S("0x00000000974bf697ff50bbcf10937293456d341f10e8736a65a282f955e590b3")) + (846000, uint256S("0x000000027363e074bdada574f70de7175b4d03518cbf3ae9ced58e94a27b0fa7")) + (847000, uint256S("0x0000000547666106543dec3d692abef6e7d50d17f47fbeb4c759bc077516414d")) + (848000, uint256S("0x000000085af6002f63ea391dbbd212cb5f49048f4c1af21225e254e01c016c33")) + (849000, uint256S("0x000000022b41777e973c0d4721c7b50b09269ed9c773c7599d40e9ca4277dd90")) + (850000, uint256S("0x00000001729fbe957fe72a474c86a12e9a22fbcc4b85b91855f7e4d5904447bc")) + (851000, uint256S("0x000000019f079eab33e5f246d1fc0ce4e393566da78fc8c153ae16a6c5b7ac79")) + (852000, uint256S("0x00000003e2978814f57e0b0012c7624d010cba7f2341da6f822af8fab7d95967")) + (853000, uint256S("0x00000001b80a38e14cfbffcbaa9f66ca397a109467050ae24e416ee8494012ce")) + (854000, uint256S("0x00000002a158ec5176de19f9b6cb174966216e1777f512bd8a5233016483e1a8")) + (855000, uint256S("0x00000001685fa560dd08a137c3cae0024f52536f87ec0e1637cddc1f63ab0174")) + (856000, uint256S("0x000000012ca124b7033438beb46804c6efa1e3ce42eb8e90239a17de4b3838c5")) + (857000, uint256S("0x00000001d07b2ed47523d018445d1bc6425bdb9698ebaa2681278c35fe1aefeb")) + (858000, uint256S("0x0000000096eef875c36ec4a1285b7913e543c3da8fdcffab63bd6bf0059c8e75")) + (859000, uint256S("0x0000000408fff00975dad11a147e164550be93517d562fa1f1a89ddf0f10df1a")) + (860000, uint256S("0x00000000dfe2c0485688443569ef7b02b73abbb0c396fa90996f8ae5267a586a")) + (861000, uint256S("0x0000000275fc7eb611908f172df62457da86834f5773e192128c0344f68caa0e")) + (862000, uint256S("0x00000003dba02d1b0907336bcf1b9f840fb18c6a4290683bf2b02b31f7a18fca")) + (863000, uint256S("0x0000000382cbe3f592d09234fa03f00ec2419b3abe77fd9ad2289e9decc483c8")) + (864000, uint256S("0x0000000122211f2d84c96a22c9693f723fa40715e85bdaffb5275132f6b711c9")) + (865000, uint256S("0x0000000396b5aa22adb2cf49da07c414d038e641e1a022940c85476990d79fb2")) + (866000, uint256S("0x000000038dc1f303227c68dea63f5da71e39aee0f1e51810d0d6d101e5754803")) + (867000, uint256S("0x00000000be49b1bed6238e86cf254d8567bce736454e92ff150c2493e5a1f7c2")) + (868000, uint256S("0x0000000177a283b40cbeea2dc13e8e2ac2120ed37bb70d45da25164e6975f96b")) + (869000, uint256S("0x0000000398feb02eb7e55816bf0493978a8fbeede38441e54bd8a1522950b3ac")) + (870000, uint256S("0x00000003b506bbb8725b883c64f9e3958353b94a9798b4a525d6ddbfb4ce55eb")) + (871000, uint256S("0x000000010cc1a48093ff772811c08b4dcfd514d6bc5f5b7b1a4e61457846b5ae")) + (872000, uint256S("0x00000002b8926624aed8f722db56a39d5598188a27c4585ec804d24a26dfeb67")) + (873000, uint256S("0x000000009784a5f7fbbad6b1c837c47587799841879ea1dacfc4524c7416a69b")) + (874000, uint256S("0x00000002e8aeae774819da3151f0cadd7def30e8e49f3bd257a63cfda01d18df")) + (875000, uint256S("0x0000000053ea639a15c4c8aeda4a35249c2d160263bb07d0620368fa48a3b3b2")) + (876000, uint256S("0x000000041313c888752a0023edef7e222d1db67fb408c2fcde07f9931f25b7c5")) + (877000, uint256S("0x00000003285d233c0c96c9dff78705aa440eaf6e3a7df564f7bec30499d6a543")) + (878000, uint256S("0x000000020a138fbaaab927b2c80633f2ba629ac188e148fb1e879579f0d64699")) + (879000, uint256S("0x00000000e529899898619b9ac8b5e851792f7080eb1717870d24a3fcc02d6eb0")) + (880000, uint256S("0x000000052a432db1e1f301316e814a7c81ac99670c0d535852ca0eb357212f26")) + (881000, uint256S("0x000000017eb97455254d8e15186c91dabfdf0d6c83ac973d30753bb9d600dc43")) + (882000, uint256S("0x00000000e85d7154af2f3e76c486cd64e6699144985230dac70cdf11d6b76e64")) + (883000, uint256S("0x00000000ee27110c95368d2e9ac76f0a0b8bc51bb194a64c92a1eb026a50c025")) + (884000, uint256S("0x0000000270c508491570556486991df763cb65964cf47a6755f8a618cf502476")) + (885000, uint256S("0x00000001c8011638be3fb5e7753f136cf7309bf65be19cc75e04d40de632d3a5")) + (886000, uint256S("0x00000003b2ce8418f95c09d912abd975a3ed65e7520cce39984b91375a13f8e6")) + (887000, uint256S("0x0000000162a4592988a5f7a8c52d8a0427f363c25df7eacd797d8150019a522f")) + (888000, uint256S("0x0000000181a04b20393bff6706250323cee60807794f6e24573f33cf40d6eaeb")) + (889000, uint256S("0x000000016b8d7666f6fd9a7c739f148d070d3373497ec7aa1dc8e4aa2bcee418")) + (890000, uint256S("0x00000001997f47f53a6342e0361705cd623e00e45ef4a55183f6c0085ea3f475")) + (891000, uint256S("0x00000001e7b2a180a07f1676c27814433e2c6673421c2973e4aa8e27d86fe86f")) + (892000, uint256S("0x000000026b271168e39aa175d679d0a1dcea6170ae62191bc6f824503fbd4ef7")) + (893000, uint256S("0x00000001330b7dd01a6bf897bcc61495044efc65c38ecd2da6530aa3ad6240d1")) + (894000, uint256S("0x0000000464a74802df74a38d76411e5e388328a0d2d23093f8baf6f78aac2aec")) + (895000, uint256S("0x000000011ccec37a917aa7bf5206a968b4e602594040bddf4d23a73bc7de8dfd")) + (896000, uint256S("0x00000003073b7cf913770042b17b4294b49d527e21746a26bc6d1ab245573a15")) + (897000, uint256S("0x00000001a4ce2efb696e813847866bb4406c206c40f014072529f94e6e61c8b1")) + (898000, uint256S("0x00000004cc48c4f883f09a6b5d7b07ea58d5d30d55145a606f91f8431bcb0f8b")) + (899000, uint256S("0x000000021ad0d858df3847be91f708561775b109a1cc4ac03ae98b7bc6849d50")) + (900000, uint256S("0x00000004d583fb1fe9915522d67a7ce287b7bc0c8fdc533bc9d69bfa42c21114")) + (901000, uint256S("0x000000020f34f41547a6b99d171cca177b54162cd82ab451aa20c4309afffb8c")) + (902000, uint256S("0x00000001a34dc22f0c54724c0a5d216ffb69adf91d01ed6581287a5b33170b32")) + (903000, uint256S("0x00000000a1a169eec927f7a9f693baf3d245d8514bfee53da8df1b4cfbf49958")) + (904000, uint256S("0x0000000146348c6656e513d798b6a5c30a81515c03e12d9b9bd15bfb42773811")) + (905000, uint256S("0x00000003dfa16e4b5271a4fbbcd8dd765829aef9e98c187ffaaa0ce2533318e7")) + (906000, uint256S("0x00000003b39d37b17faa5d219f69bd414c1d6ff1605a1d345cd19bb2ab19a439")) + (907000, uint256S("0x00000001b22ae264c831db5dd6e0a710ba19683d6f7158fe0b2297266815c043")) + (908000, uint256S("0x0000000296b9af3429d1896f41c892c9093324e250e0e8dc1ca8e4b548035ff8")) + (909000, uint256S("0x00000001b59b5cd319cc4226134383c7385e9350f70a5c06cd24ebf06a0c22f1")) + (910000, uint256S("0x0000000609525a8843a5154ec5852e4a45f88568ce0488f71918979887336974")) + (911000, uint256S("0x00000001bc256a60a91b262f95ae6f7453698f88d41868dbe371495bddd2d8d1")) + (912000, uint256S("0x0000000203706048d0e63a013951083c2de38abb929a6f5900218340f044d5d0")) + (913000, uint256S("0x000000060371dbe13dc3892e852178b47edd9a50fa5bbdbf13b2db177ab6721c")) + (914000, uint256S("0x00000000731990dd05277da899c5cdc5c55677523c98dde26e40a0908eeca6c9")) + (915000, uint256S("0x00000003c0640fe26ee68893bfd18dcaa78b4137991d17731142aa6dcb135944")) + (916000, uint256S("0x00000001662152a289fc0d52778f385ac89f377c41dc63b22c75a87b636f4943")) + (917000, uint256S("0x0000000318a6f2bc69222c9c507411dd0ccbd896a55c8af7b8e3edee654b2de3")) + (918000, uint256S("0x000000008b763e8c2ab62a6579951f6ec6b3389c7c6b65a522e99a63bd97a739")) + (919000, uint256S("0x0000000233571d5f6478ae23ce41a82ebcb363f855d058d66f0ba3919c112a9e")) + (920000, uint256S("0x0000000427e137360eb41ccd29ace37e81cfb755319dcee91a92ba2a4882513d")) + (921000, uint256S("0x000000050e0477cb9b1778dba84589e3dd7d7dd1a1c2a02ad08d332ab97c6a3a")) + (922000, uint256S("0x00000003d9bcc0f005cd59b7a7ee7070b60d7bd9a446dd9683db3ceeac1de384")) + (923000, uint256S("0x000000044e167ff553280f6cb85fb2716ba05cc2ec757b83716feca57d2ec4f1")) + (924000, uint256S("0x00000002bdfd61d89711f727633220d8c9c0cd31ecfa21f31fe3f8da642dbdbd")) + (925000, uint256S("0x00000004d5ec42db6fc7ff14ffbafce84a4fed94bdd445aed8c0b4ca15341ec9")) + (926000, uint256S("0x000000038e14de8aa0edf65370930f7ce17020fffcafc05e9afb01bbcdb13c15")) + (927000, uint256S("0x000000014bf416862cbc79b1d01cb0856fc76bdbfcb70db4955d828b0103ef6c")) + (928000, uint256S("0x0000000265d1e1638d2426922f595f2438766a9ea63ca45f34cf80255da99fd3")) + (929000, uint256S("0x00000002d7cf1bb10144d67364fac39df662cb4e823fa1042950a5796a7771cc")) + (930000, uint256S("0x000000002b3f4a90dc91e81a1e7e6ea9b7d915de51ce50a093f50176fb60ce5b")) + (931000, uint256S("0x00000003bb7bda948663dfd60f3b2720cbbaa10b1f1bbc228fdfc04750be4ff1")) + (932000, uint256S("0x000000005c4638688394adc36df4bcc608df08ca56800ac4eaceeb677afd1a18")) + (933000, uint256S("0x00000004c3157df042d84b36f33e5ed6c4037f8e5b8d7987276ae3270358291e")) + (934000, uint256S("0x0000000393193988615a4c43c123297bef87cd6e376408028f55c36f77196362")) + (935000, uint256S("0x00000003c19101992896cbe965d52e45b2233f3f2002933db13066613e1c0f35")) + (936000, uint256S("0x00000000968337016832fbf62ef162c0aad8c02d6f37833792953d60082b16f0")) + (937000, uint256S("0x000000015e7a21a8dfff99e2ce3a7c822a31feeede401e9f3071064b201c34ce")) + (938000, uint256S("0x000000037f2d515c46071a1a273edcd6c79adae16aa3ee5c07430f6719dd6d72")) + (939000, uint256S("0x0000000267a840284290547bdb380d1e409a54ca9f1155cfad552c93e6679b2c")) + (940000, uint256S("0x00000000fd1f15835042e3a648a46ba8c678d4569fd314b273459c5aa92dd001")) + (941000, uint256S("0x000000038f904bec469e2f9cd513160b8d2a7f271da396fe38821b026366b818")) + (942000, uint256S("0x00000002f11f3b9fd10e9404fbf91eeed8774e2e45fe5216942c0bb04ebab656")) + (943000, uint256S("0x0000000304a091f4b993b8200d41eaeb0543c5a3103c5678ffc0a535dfc38236")) + (944000, uint256S("0x000000040bced4dbdcbe0604354c6a853c72dbb6b50c8c52da468cc8ad0e9681")) + (945000, uint256S("0x0000000046de24d9c0442378778f08322f3c58973d6c741f75f50ab022a7cf5e")) + (946000, uint256S("0x00000001cfd737ef7b4e7d34cbb02290d8c227822aaff0dd8a8d4d48c175f8c8")) + (947000, uint256S("0x00000004f4375fda1d75f98a764c91d8f7dc5a3bb1415e5fce9e6d7696c52c10")) + (948000, uint256S("0x0000000541269e0f44535d415895afdfa09dc6fe2cac0f1429fe29af92461d97")) + (949000, uint256S("0x000000021fa97dade883418f2e14ce58b609d4726613498ed6b9a7b7faef2b46")) + (950000, uint256S("0x00000003fcbf83d67ac4e7fc936122b825919e5b0960d177615b67486994ea0b")) + (951000, uint256S("0x000000016aaa78a202aaecb90dcf8ec793b389e7bb3673f4f13de2e85e1189a9")) + (952000, uint256S("0x00000003607fff01107d1613bd13d60f81d1ef474d20616bf6fac37092328a55")) + (953000, uint256S("0x000000035c19b9ef98b766ae081c501120eaffaa2bf49a313e1811c259e240b1")) + (954000, uint256S("0x00000003f242fafc14e936d5ab81f5558aa65b0bdfc5a92f650cba2d455827ae")) + (955000, uint256S("0x00000003d922090149b5120addc6175239f6063cbeb4ef30bc92ce83a1f9fce0")) + (956000, uint256S("0x00000003770c91edae96c9c7fe9c8876cdb16381b13cc11b9d95d00713cc8aec")) + (957000, uint256S("0x00000005019f09058db9216b101a61c2e61f37d2764640b1e9760cf7a281014c")) + (958000, uint256S("0x0000000456bff3b05a6e47dd4a94987bb5334d90e5aaf834c1f00b1676506b81")) + (959000, uint256S("0x00000004525f22d8c0fcf787c015cdfad4e8c4b9d787da88bd6ad647ea2aef5c")) + (960000, uint256S("0x000000010166f88f1fddf91deeaacc06b52e7da9d1298608f308f13f73e6c926")) + (961000, uint256S("0x000000055411b16bb2e1eb984978f039b95fd660f0f7170594c5645be5677df1")) + (962000, uint256S("0x000000049574e12129466441be84283e285ed61d37827fb7df003864fa67acbe")) + (963000, uint256S("0x0000000083eb3eb9f2568ad43cc9b8e827c23f9850e81a6f7be4e6ea16362cfe")) + (964000, uint256S("0x000000020ea47a19feaaf858655731e2d9f96ed2ab71d6dabea1c2583e26a829")) + (965000, uint256S("0x000000017b2a6a61ccb74789990c37fada264744d20e73174f86951ad58e1495")) + (966000, uint256S("0x000000032c4e3abb3a7ac60fcaf1b1b87520919906608a34c9f4eeb708ffc749")) + (967000, uint256S("0x0000000550923b03a1e361e3e92e43908012002223cc0fed14854d33da9b2065")) + (968000, uint256S("0x00000001ec98ed6e3c3efb5e98e7babb652d175675c4aa380e07d6f05dae4b4b")) + (969000, uint256S("0x0000000617320afeb83964ae57fc656f06fe3f6254b12f4ca94d5201efc2c211")) + (970000, uint256S("0x00000006ccb16c67a49ac724ec636d2f83c95a22bc41cc4df933a8b064092281")) + (971000, uint256S("0x00000000f71e012b5c671d06ca2111b6df8d50f5c16549a602e81f968052ee90")) + (972000, uint256S("0x000000012f6d713f64f6c9c54accca288df17af6006777cb435a3d1a6a84e843")) + (973000, uint256S("0x000000021c37257bf2e55c02444f11a1b60979d2d56a7290dbdb28b8b299238f")) + (974000, uint256S("0x000000001d83b9a5d53c759edf5c00ac184ac7d4266a8b396fcbb504cb4079c6")) + (975000, uint256S("0x00000005b82711efd762b2ea0d7595b28bdf5aed2d486811074e032cc628ed50")) + (976000, uint256S("0x00000003ecf59231d9cca098a845e93a66f4f41cf1c6dfd993ddb182d95a4efe")) + (977000, uint256S("0x000000015db47b61454bc4ace1c65c66fc89ec14d34a4ced7e2b61328bcd1f00")) + (978000, uint256S("0x0000000411d4a37aa6144f8637ee9c8aa011ab021eda959a4764419f8ec4f7f6")) + (979000, uint256S("0x00000002137f49143bbf727f8e4ce8deaa9fd42fc46cf0f3ca2b913a98c632a4")) + (980000, uint256S("0x000000033622593be50ba7ecf03bc657be6890563d082cc90474e09ad8f56fb5")) + (981000, uint256S("0x00000005c2e78844292d8680eb7abefe85c75cf8dbb362376ccb190a6d8e60b3")) + (982000, uint256S("0x00000003d8c71db0c573290b70da5d7cdf92145d3bc6715868f789fa3e25698e")) + (983000, uint256S("0x00000004d79d85d0aa71fce43a05136e4cc09938758aefd9e879d6e60be258a0")) + (984000, uint256S("0x00000003f65d68cacec0dfa9cccd4b46e15798b14be9ce6f22fde8e3c8618ec3")) + (985000, uint256S("0x0000000341d9dc96faca5e5a462b34b9c6d22d65ecfcc56d5147d57dda4c3a59")) + (986000, uint256S("0x00000007e9077e82512804c33e683b5dcca58ceb4d36e654abd178b89b68c202")) + (987000, uint256S("0x00000006929d5b93ee6fd6db9bf100988c85c92b8163ac701a20e98cd9082744")) + (988000, uint256S("0x00000005ff0c1652c244fe20d835f598a423cf1f76d36d1027b24fcbd7d8129f")) + (989000, uint256S("0x000000049340ad6d31f06a9ab1e7e9e619af8206348d1a36a2e8a0b3d78e954e")) + (990000, uint256S("0x0000000301852b2fab793862e4f6f674d5b6974f92d5580c718104b19c852288")) + (991000, uint256S("0x00000002a0910ad7941a9560656dbf6e5b867ad06a52c0b370511893ae817fe6")) + (992000, uint256S("0x0000000844f0b8293c8e63723582afc43af5400a3b0e0a6ea5de55d3c06a9224")) + (993000, uint256S("0x00000001e3cdb499844beb0253ed5950600226d871ddabf5f68a7f30f2188f76")) + (994000, uint256S("0x000000036830f331b19c825421c450dd41583981dcebca382e6ae43a642eec97")) + (995000, uint256S("0x0000000325c5d78ac4b9239ef04543a27c40d046bfb480df953647f11a728e21")) + (996000, uint256S("0x00000002813dd7f47bfa60fa6446b6cd77ac997556e6c2149d75f40ab2c7ad88")) + (997000, uint256S("0x000000052bc685e1ba66049fe51eccdf09094c2caf475eae0260e5aefb888281")) + (998000, uint256S("0x0000000000499a48e5cf027ece31a73326c4cf3f643e88c168425203adc20455")) + (999000, uint256S("0x0000000612d67c808d279e1c40210b503885e50019401f9a6c1ff17990a8c91e")) + (1000000, uint256S("0x00000002e920ff85f57a164e0637d12147e95428b4da8ca2f0dde4192f5df829")) + (1001000, uint256S("0x00000002ef1ed514a63699b72166e137de121ad58c75dbdf777657f5fea1a469")) + (1002000, uint256S("0x0000000234a7551d7fb913c25d70fc6093e637472186561f6fba96126e56c452")) + (1003000, uint256S("0x00000001a8010508ac92adc26a3bf0e779f217b25a0671dc9f7c3234e4355ba6")) + (1004000, uint256S("0x00000005fca0ef6af799a8716b3e5452d64a05c515957cfee853eccb52d066dc")) + (1005000, uint256S("0x000000003f765af69818f8b00281c8922f9546baef2d67650f0ef24cdcfd663f")) + (1006000, uint256S("0x0000000009db83f88a0e31f440df2b017f5acf47d7df88ce0fa82cd6f81506be")) + (1007000, uint256S("0x0000000241d71ce1f52e530f422927c852af90e91796580067087ab80e74584e")) + (1008000, uint256S("0x000000009636e5afe7665220dc079ad496f59d92209c58e3cc36d4db229afd42")) + (1009000, uint256S("0x0000000244b9c61ca661a38afbaed439a5562fd684998b37ab5dc760fd45cf9c")) + (1010000, uint256S("0x00000005048d906875b212da70fbfec2ebb7ee750373d8db1a3d6bc05bc54427")) + (1011000, uint256S("0x0000000297aef0dd91ea4d0617ee3132b4351a0c7c9bfe79fa20d2916ca9bfb5")) + (1012000, uint256S("0x0000000139aa7546bc07065e0e35cb73598e3ce2092aa1d971387374d98535da")) + (1013000, uint256S("0x00000005f12a5b5e7bc651c04c7f70f0c88301742fe894349c37326eb4e31655")) + (1014000, uint256S("0x00000001a789daba42b1c2f15c17bcdcf01416deab7dda2019b895b260d23c28")) + (1015000, uint256S("0x0000000411d719a1bc2b74863b324cdc4c45523bf238e340d16fc8c4456cc3c0")) + (1016000, uint256S("0x0000000447247919dcb1eabeaa830a29572fc2b80c92bde2ffb4dc9d07907fa1")) + (1017000, uint256S("0x000000046fb653d015992c57a2aafcf129b175c6e7e8f936c0d0705c9fcbf3df")) + (1018000, uint256S("0x00000004d43fe6a7441432f5f6f7745a5707afe528116dc54a6cb60c790910af")) + (1019000, uint256S("0x000000038863f02f95dbe67341d1c8e688971188ab64a027f6518297aa41685b")) + (1020000, uint256S("0x0000000736d3a59ad8bf3c343a7c043bead1eb4dd645a0ed3cc220df542b90c4")) + (1021000, uint256S("0x0000000356d22e60db8fd41a86ca8e5040f2af0766ea04e64f5d1a04e9d2b675")) + (1022000, uint256S("0x00000003823597fd08074b2d6432c440ac2a4cef811463bba973785ab9827d81")) + (1023000, uint256S("0x00000002004e0dc6f4029eb5593e70e70b2544dce9bddcda8739945315317922")) + (1024000, uint256S("0x0000000344a757dfea3eb5dbf6f6d036f886049a1232613fd48b293136705e0b")) + (1025000, uint256S("0x0000000027123b99a92b669dd0dfec10774806a021247d0bd57931bbed22f43d")) + (1026000, uint256S("0x000000032408ce350b1b345c4967e2639dccc77f4a1c7edd5e1e4e523733e025")) + (1027000, uint256S("0x0000000334486767dfafe2e1f90c63dd5de91bc129a7782878c4ecfcdde2d98e")) + (1028000, uint256S("0x00000002e5f0ab865aec0903a17debda315d318b467e79a04cae85618d74dde1")) + (1029000, uint256S("0x00000000fad3fadc2f8a5d00d8cd1e515ac1682dd171f7f822e6d4c7b34ba82d")) + (1030000, uint256S("0x00000001b00617506de39d33787569c95287b4d0a3371c56bc8b5e6a4f0e8c08")) + (1031000, uint256S("0x000000034a1f1bc2b2c8b3e208c2c30c38d2630d01caa21c38d1a5fb95ab0a0a")) + (1032000, uint256S("0x0000000195b52cc662fc3f7696fdcdcc524482bd4fed5002cfec03b522538dab")) + (1033000, uint256S("0x00000002359b267356ce02cd33593c7ccb80a7896982d51ae231da46d6866f01")) + (1034000, uint256S("0x0000000398eace8d23f033542a110a933520323de064be8f5b657cf4d6ac136b")) + (1035000, uint256S("0x0000000419b31e382cbd5a592dec4deb830f8133441cc82c2e444ff5819f0dc5")) + (1036000, uint256S("0x00000000c23d9d18e0767f977848a09813267781ba20861bec4b76b1d15a20db")) + (1037000, uint256S("0x00000007cccc9735c16959ee3d027077f2182ed1f4c16ddf47c5b2c5faeea0a9")) + (1038000, uint256S("0x000000056f554ff1bd5c2aa8cc7f5df055efd5500e514308314f0041257f4e60")) + (1039000, uint256S("0x0000000307fa4fe2c2676d68b4cb2548b3e2a3781df345aec1dbdf81fba1994b")) + (1040000, uint256S("0x00000002614fdf2700e084baadb82b6fc7bbf26a3c79c90641be4285cc03af78")) + (1041000, uint256S("0x00000007b3da5130af7ff6a7fa1245954d0092f6114ad19969d5d4daaef6c254")) + (1042000, uint256S("0x000000052ae6c8fea95051b95e7c74264cd627e3fac1d330bdc4847a4523df8f")) + (1043000, uint256S("0x000000032e59e2d4c0bb0f2d7f1c90bd2371d285c9374b4241bd57552f44ab0f")) + (1044000, uint256S("0x000000025b57cc68235a682cfc0f41789af12ecec2f0565edcf7838d2e1fdd7f")) + (1045000, uint256S("0x0000000139b009a949e556b50dcad7284e93aeb5755f9ded12ffe70444fceb39")) + (1046000, uint256S("0x0000000269288d0901870b3caa89018c9acb52b70f856009ff11158cb22c2832")) + (1047000, uint256S("0x00000004e4659c1b1af57087e56c92c29253480aa0be0bb4261a515773770de1")) + (1048000, uint256S("0x000000026e0696b27b2f8a1dbbbb663ecb994bf24753a5c279061dae8e0bf479")) + (1049000, uint256S("0x00000005862ead8de28385ea0970950130f82d775eab61705337b0adc5360c3f")) + (1050000, uint256S("0x00000007d2415d1422b2d69cc7be152720ed7b53730759019cfe90cc3ddb7365")) + (1051000, uint256S("0x00000001422a302d8b23e26a50d86b5cdbf61690f94af2710cb5d0ddd8e0af81")) + (1052000, uint256S("0x000000038d913635fbf6dfe4799a828b1520d2e29f4cde863a70f37c59fcbd3b")) + (1053000, uint256S("0x000000009c4f02597cb047c36d361e0fb77283f07bcd0bcb86fbbf6571892b3d")) + (1054000, uint256S("0x0000000780b6835844313311bc0ac91a9eb7d20dfe51266cddd7cce735552dd3")) + (1055000, uint256S("0x0000000659c01a5b3d7a1e1b33900c3527d900992a32269665c85e110769bae9")) + (1056000, uint256S("0x000000039f3f23dca824a90cbf6f2b1ac8ec8dfaa608d0bd212a5a657971ca2f")) + (1057000, uint256S("0x00000008840c70a3409e26819af871ce1bc2deaccd67f466830338e643732bbb")) + (1058000, uint256S("0x00000007df387a1596a278c3afce173437d10bbf8bfc1d65703c108051ccb8af")) + (1059000, uint256S("0x00000000bed5fc529d8e7578e09eeb982116f5dfe58ead782d6e4c6cf662f493")) + (1060000, uint256S("0x00000002135251aca1227134c34022b7400b8e5499143976fb290fc222c24663")) + (1061000, uint256S("0x00000001c9e002f08d86cf64e57a6bb4673745f2b8d2e937eea57430761955e8")) + (1062000, uint256S("0x00000002e95603528c26aefe6bbb76bb17d0b791f728310b4d3edd954b3d3325")) + (1063000, uint256S("0x000000067e2ffc24c9def026253dee09ef9217352924acb54faaeb8a46d88f0a")) + (1064000, uint256S("0x000000071e23fbe757e04f5b006c6d5e1e5682996d1eb4fb4611ebd064dd12ea")) + (1065000, uint256S("0x000000044f99fe07c4f06fb7da5ab33fb909e2e19104b4fe7831a1f4a7862966")) + (1066000, uint256S("0x00000001dea7668d9cb68470de451777f7ef4415251e77243760fe4bdeb75feb")) + (1067000, uint256S("0x000000040f9a4298cb9a303af92034b6e264a9f3ef939b48aac112d92700194c")) + (1068000, uint256S("0x000000031cf16353f1a15bf1cf0e8b75286ead82f110fdd00b7cef5b7973c684")) + (1069000, uint256S("0x00000001791735171e9cc623b0b66552de25808340907763c9c30934eaf927d4")) + (1070000, uint256S("0x000000044fdfb0a7eef30a2d582e2132833af92f15e9f64fef1daa73c3051bbc")) + (1071000, uint256S("0x00000005066bd8de3b90972861ec83225daca234b62cba386b615a2a20623c00")) + (1072000, uint256S("0x0000000470c89f0db6a224c14d171201a229d1a2aeb16519a513b965c1cb87dd")) + (1073000, uint256S("0x0000000581331131dc1ce222ec38e8415e7ea6a60b3b92beee8742b9863fa394")) + (1074000, uint256S("0x00000000099ef084c8b0fd97f5c620026bde4a19ce7576a4f5b05e428569c516")) + (1075000, uint256S("0x000000065a3c4f4e027e1ecc81fc5c57f489270ccf4a0283e1280469e598efee")) + (1076000, uint256S("0x000000029d923c0d279ac6b8e5f1a327191beab0f40fa41e762c3603a66bc31f")) + (1077000, uint256S("0x000000004f7bcc5b2e441025d570bd7c9f25d31eda4363357153782e4c407bc7")) + (1078000, uint256S("0x00000000201660f24e1c10c7a022bc684833e2e8e03b88d78d5f68e340e008c4")) + (1079000, uint256S("0x000000035e334ec68e40d27ed75e36fcb4c061f0ec69d8b9bc85f8227dbbbc0f")) + (1080000, uint256S("0x0000000480ee77b800ce36773a8c451ba66e702dec0628bdd6725f9a1f88a060")) + (1081000, uint256S("0x000000031f6d1a8dfd0d7700e1470908d9fc7c12624bda4183be79387efcd971")) + (1082000, uint256S("0x00000006267f4a8236efadafba755f8149206d8e531ebb36dd99e5f2f09797d7")) + (1083000, uint256S("0x000000017de5a4b6fa23df969646f07dc165f3adbff7fd9ebac34d739c42a8bf")) + (1084000, uint256S("0x00000004af141f9a5bc2d838d4f8624e1503c7e8d3048924dd850299ea65c360")) + (1085000, uint256S("0x00000003e9ed1a3e3593e19554280c5aa789e2182a42243e9f7bb63bd08ef4d7")) + (1086000, uint256S("0x000000069c32b803dca7ce354f422735c4b1995c43266de5bf288399e0f70324")) + (1087000, uint256S("0x000000027a91bb3d167380a39dc55ad2f8df57d95d08936407b2b1f257b91df6")) + ,(int64_t) 1663567436, // time of last checkpointed block + (int64_t) 1788273, // total txs + (double) 3139 // txs in the last day before block 1087529 + }; + // END HUSH mainnet checkpoint data } else { checkpointData = //(Checkpoints::CCheckpointData) { From 6845ec2087ce6dbfe411ab84e6513b68ce7b27d8 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 13:32:41 -0400 Subject: [PATCH 216/255] Even more details about checkpoints --- doc/release-process.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/doc/release-process.md b/doc/release-process.md index 7f57e3ad8..b1176508f 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -68,12 +68,18 @@ Install deps on Linux: - PROTIP: Man page creation must be done after updating the version number and recompiling and before Debian package creation - Update checkpoints in src/chainparams.cpp via util/checkpoints.pl - hushd must be running to run this script, since it uses hush-cli to get the data - - Run `./util/checkpoints.pl &> checkpoints.txt` to generate the latets checkpoint data + - Look for line which says "END HUSH mainnet checkpoint data" near line 560 in chainparams.cpp , that is where checkpoint data ends + - Find the highest block height of data, let's call it HEIGHT + - Run `./util/checkpoints.pl 1000 HEIGHT &> checkpoints.txt` to generate the latest checkpoint data + - To copy the new data from checkpoints.txt into the file, one way in Vim is to type ":r checkpoints.txt" which will read in a file and paste it as the current cursor + - You will see 3 lines of "stats" at the end of the output, you just pasted in the newest stats. Delete the old stats that should be the 3 lines under the current stats + - The script generates a comment "Generated at ...", that should be moved to the very beginning of the checkpoint data + - Make sure the new code compiles, commit and push + - Run `./util/checkpoints.pl help` to see some basic help - By default it will generate checkpoints for every 1000 blocks, the "stride" - You can get a different "stride" by passing it in as the first arg to the script - To get checkpoint data for every 5000 blocks: `./util/checkpoints.pl 5000 &> checkpoints.txt` - Currently checkpoints from before block 340k are given for every 5k blocks to keep the data smaller - - Look for line which says "HUSH mainnet checkpoint data" near line 560 in chainparams.cpp , that is where checkpoint data begins. - checkpoints.pl will just generate the data you need, it must be manually copied into the correct place - Checkpoints are a list of block heights and block hashes that tell a full node the correct block history of the blockchain - Checkpoints make block verification a bit faster, because nodes can say "is this block a descendant of a checkpoint block?" instead of doing full consensus checks, which take more time From da5bd906af9dcf98750603747c844cd9062b3140 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 13:54:20 -0700 Subject: [PATCH 217/255] Add a windows batch file for hush-smart-chain It would be nice to pass along all CLI params, not just the first 9, since we may need more than that. We should also add copyright lines. --- src/hush-smart-chain.bat | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 src/hush-smart-chain.bat diff --git a/src/hush-smart-chain.bat b/src/hush-smart-chain.bat new file mode 100644 index 000000000..dcbc64ebb --- /dev/null +++ b/src/hush-smart-chain.bat @@ -0,0 +1,7 @@ +@call :GET_CURRENT_DIR +@cd %THIS_DIR% +hushd %1 %2 %3 %4 %5 %6 %7 %8 %9 +@goto :EOF + +:GET_CURRENT_DIR +@pushd %~dp0 From bd8ebb6a1c8bef6c5a1a1759a8ad209d4294154a Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 13:56:46 -0700 Subject: [PATCH 218/255] Pass along all CLI params, not just the first 9 --- src/hush-smart-chain.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hush-smart-chain.bat b/src/hush-smart-chain.bat index dcbc64ebb..303b08eeb 100644 --- a/src/hush-smart-chain.bat +++ b/src/hush-smart-chain.bat @@ -1,6 +1,6 @@ @call :GET_CURRENT_DIR @cd %THIS_DIR% -hushd %1 %2 %3 %4 %5 %6 %7 %8 %9 +hushd %* @goto :EOF :GET_CURRENT_DIR From c1286c4140293ce2c07827dedc7eb346cce1a00a Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 13:58:21 -0700 Subject: [PATCH 219/255] Add copyright lines to HSC batch file --- src/hush-smart-chain.bat | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/hush-smart-chain.bat b/src/hush-smart-chain.bat index 303b08eeb..3499da74f 100644 --- a/src/hush-smart-chain.bat +++ b/src/hush-smart-chain.bat @@ -1,3 +1,6 @@ +:: Copyright (c) 2016-2022 The Hush developers +:: Distributed under the GPLv3 software license, see the accompanying +:: file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html @call :GET_CURRENT_DIR @cd %THIS_DIR% hushd %* From f6457a7ce5898a58e4c8be3f6f0c0eb5a3d14fa4 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 13:59:16 -0700 Subject: [PATCH 220/255] Clarify a confusing comment --- src/hush-smart-chain | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hush-smart-chain b/src/hush-smart-chain index 2a33f0ba0..ae6a56a27 100755 --- a/src/hush-smart-chain +++ b/src/hush-smart-chain @@ -9,6 +9,7 @@ cd $DIR DEFAULTS="" -# People should just use hushd going forward +# People can just use hushd going forward, but this script makes it +# more clear what is going on HUSH="./hushd" $HUSH $DEFAULTS "$@" From 2de20daa66871b7265e71f4a43f56b088c14dcc5 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 15:13:47 -0700 Subject: [PATCH 221/255] Document z_sendmany 'z' ... --- src/wallet/rpcwallet.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a09f33e79..b2fb8ab14 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4859,7 +4859,7 @@ UniValue z_sendmany(const UniValue& params, bool fHelp, const CPubKey& mypk) "\nWhen sending coinbase UTXOs to a zaddr, change is not allowed. The entire value of the UTXO(s) must be consumed." + HelpRequiringPassphrase() + "\n" "\nArguments:\n" - "1. \"fromaddress\" (string, required) The taddr or zaddr to send the funds from.\n" + "1. \"fromaddress\" (string, required) The taddr or zaddr to send the funds from. Use 'z' to spend from any zaddr.\n" "2. \"amounts\" (array, required) An array of json objects representing the amounts to send.\n" " [{\n" " \"address\":address (string, required) The address is a taddr or zaddr\n" From 5d2307a709a89f9683bb3bbbf7bb3d4d056b6083 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 15:45:30 -0700 Subject: [PATCH 222/255] Update copyrights to 2022 --- Dockerfile | 2 +- Makefile.am | 2 +- autogen.sh | 2 +- contrib/block_time.pl | 2 +- contrib/fresh_clone_compile_and_run.sh | 2 +- contrib/hush_halvings | 2 +- contrib/hush_scanner | 2 +- contrib/hush_supply | 2 +- contrib/verify-commits/gpg.sh | 2 +- contrib/verify-commits/pre-push-hook.sh | 2 +- contrib/verify-commits/verify-commits.sh | 2 +- depends/funcs.mk | 2 +- doc/man/hush-cli.1 | 2 +- doc/man/hush-tx.1 | 2 +- doc/man/hushd.1 | 2 +- migratecoin.sh | 2 +- qa/hush/create_benchmark_archive.py | 2 +- qa/hush/create_wallet_200k_utxos.py | 2 +- qa/hush/full-test-suite.sh | 2 +- qa/hush/full_test_suite.py | 2 +- qa/pull-tester/rpc-tests.sh | 2 +- qa/pull-tester/run-bitcoin-cli | 2 +- qa/pull-tester/run-bitcoind-for-test.sh.in | 2 +- qa/pull-tester/tests-config.sh.in | 2 +- qa/rpc-tests/ac_private.py | 2 +- qa/rpc-tests/addressindex.py | 2 +- qa/rpc-tests/bip65-cltv-p2p.py | 2 +- qa/rpc-tests/bipdersig-p2p.py | 2 +- qa/rpc-tests/blockchain.py | 2 +- qa/rpc-tests/cryptoconditions.py | 2 +- qa/rpc-tests/cryptoconditions_channels.py | 2 +- qa/rpc-tests/cryptoconditions_dice.py | 2 +- qa/rpc-tests/cryptoconditions_faucet.py | 2 +- qa/rpc-tests/cryptoconditions_gateways.py | 2 +- qa/rpc-tests/cryptoconditions_heir.py | 2 +- qa/rpc-tests/cryptoconditions_oracles.py | 2 +- qa/rpc-tests/cryptoconditions_rewards.py | 2 +- qa/rpc-tests/cryptoconditions_token.py | 2 +- qa/rpc-tests/decodescript.py | 2 +- qa/rpc-tests/disablewallet.py | 2 +- qa/rpc-tests/dpowconfs.py | 2 +- qa/rpc-tests/feature_walletfile.py | 2 +- qa/rpc-tests/finalsaplingroot.py | 2 +- qa/rpc-tests/forknotify.py | 2 +- qa/rpc-tests/fundrawtransaction.py | 2 +- qa/rpc-tests/getblocktemplate.py | 2 +- qa/rpc-tests/getblocktemplate_longpoll.py | 2 +- qa/rpc-tests/getblocktemplate_proposals.py | 2 +- qa/rpc-tests/getchaintips.py | 2 +- qa/rpc-tests/hardforkdetection.py | 2 +- qa/rpc-tests/httpbasics.py | 2 +- qa/rpc-tests/invalidateblock.py | 2 +- qa/rpc-tests/invalidblockrequest.py | 2 +- qa/rpc-tests/ivk_import_export.py | 2 +- qa/rpc-tests/key_import_export.py | 2 +- qa/rpc-tests/keypool.py | 2 +- qa/rpc-tests/listtransactions.py | 2 +- qa/rpc-tests/maxblocksinflight.py | 2 +- qa/rpc-tests/mempool_nu_activation.py | 2 +- qa/rpc-tests/mempool_reorg.py | 2 +- qa/rpc-tests/mempool_resurrect_test.py | 2 +- qa/rpc-tests/mempool_spendcoinbase.py | 2 +- qa/rpc-tests/mempool_tx_expiry.py | 2 +- qa/rpc-tests/mempool_tx_input_limit.py | 2 +- qa/rpc-tests/merkle_blocks.py | 2 +- qa/rpc-tests/nodehandling.py | 2 +- qa/rpc-tests/nspv_client_test.py | 2 +- qa/rpc-tests/p2p-acceptblock.py | 2 +- qa/rpc-tests/p2p_node_bloom.py | 2 +- qa/rpc-tests/p2p_txexpiry_dos.py | 2 +- qa/rpc-tests/prioritisetransaction.py | 2 +- qa/rpc-tests/proxy_test.py | 2 +- qa/rpc-tests/pruning.py | 2 +- qa/rpc-tests/rawtransactions.py | 2 +- qa/rpc-tests/receivedby.py | 2 +- qa/rpc-tests/regtest_signrawtransaction.py | 2 +- qa/rpc-tests/reindex.py | 2 +- qa/rpc-tests/rest.py | 2 +- qa/rpc-tests/rewind_index.py | 2 +- qa/rpc-tests/rpcbind_test.py | 2 +- qa/rpc-tests/script_test.py | 2 +- qa/rpc-tests/signrawtransaction_offline.py | 2 +- qa/rpc-tests/signrawtransactions.py | 2 +- qa/rpc-tests/smartfees.py | 2 +- qa/rpc-tests/spentindex.py | 2 +- qa/rpc-tests/test_framework/authproxy.py | 2 +- qa/rpc-tests/test_framework/bignum.py | 2 +- qa/rpc-tests/test_framework/blockstore.py | 2 +- qa/rpc-tests/test_framework/blocktools.py | 2 +- qa/rpc-tests/test_framework/comptool.py | 2 +- qa/rpc-tests/test_framework/equihash.py | 2 +- qa/rpc-tests/test_framework/mininode.py | 2 +- qa/rpc-tests/test_framework/netutil.py | 2 +- qa/rpc-tests/test_framework/script.py | 2 +- qa/rpc-tests/test_framework/socks5.py | 2 +- qa/rpc-tests/test_framework/test_framework.py | 2 +- qa/rpc-tests/timestampindex.py | 2 +- qa/rpc-tests/txindex.py | 2 +- qa/rpc-tests/txn_doublespend.py | 2 +- qa/rpc-tests/wallet.py | 2 +- qa/rpc-tests/wallet_1941.py | 2 +- qa/rpc-tests/wallet_addresses.py | 2 +- qa/rpc-tests/wallet_anchorfork.py | 2 +- qa/rpc-tests/wallet_changeindicator.py | 2 +- qa/rpc-tests/wallet_import_export.py | 2 +- qa/rpc-tests/wallet_listnotes.py | 2 +- qa/rpc-tests/wallet_listreceived.py | 2 +- qa/rpc-tests/wallet_mergetoaddress.py | 2 +- qa/rpc-tests/wallet_nullifiers.py | 2 +- qa/rpc-tests/wallet_overwintertx.py | 2 +- qa/rpc-tests/wallet_persistence.py | 2 +- qa/rpc-tests/wallet_protectcoinbase.py | 2 +- qa/rpc-tests/wallet_sapling.py | 2 +- qa/rpc-tests/wallet_shieldcoinbase.py | 2 +- qa/rpc-tests/wallet_shieldcoinbase_sapling.py | 2 +- qa/rpc-tests/wallet_treestate.py | 2 +- qa/rpc-tests/walletbackup.py | 2 +- qa/rpc-tests/zapwallettxes.py | 2 +- qa/rpc-tests/zkey_import_export.py | 2 +- src/Makefile.am | 2 +- src/Makefile.gtest.include | 2 +- src/Makefile.test-hush.include | 2 +- src/addressindex.h | 2 +- src/addrman.cpp | 2 +- src/addrman.h | 2 +- src/alert.cpp | 2 +- src/alert.h | 2 +- src/alertkeys.h | 2 +- src/amount.cpp | 2 +- src/amount.h | 2 +- src/arith_uint256.cpp | 2 +- src/arith_uint256.h | 2 +- src/assetchains_stop | 2 +- src/asyncrpcoperation.cpp | 2 +- src/asyncrpcoperation.h | 2 +- src/asyncrpcqueue.cpp | 2 +- src/asyncrpcqueue.h | 2 +- src/base58.cpp | 2 +- src/bech32.cpp | 2 +- src/bech32.h | 2 +- src/bitcoin-cli.cpp | 2 +- src/bitcoind.cpp | 2 +- src/bloom.cpp | 2 +- src/cc/CCGateways.h | 2 +- src/cc/CCHeir.h | 2 +- src/cc/CCImportGateway.h | 2 +- src/cc/CCMarmara.h | 2 +- src/cc/CCOracles.h | 2 +- src/cc/CCPayments.h | 2 +- src/cc/CCPegs.h | 2 +- src/cc/CCPrices.h | 2 +- src/cc/CC_made_easy.md | 2 +- src/cc/CCassets.h | 2 +- src/cc/CCassetsCore.cpp | 2 +- src/cc/CCassetstx.cpp | 2 +- src/cc/CCauction.h | 2 +- src/cc/CCchannels.h | 2 +- src/cc/CCcustom.cpp | 2 +- src/cc/CCdice.h | 2 +- src/cc/CCfaucet.h | 2 +- src/cc/CCfsm.h | 2 +- src/cc/CCinclude.h | 2 +- src/cc/CClotto.h | 2 +- src/cc/CCrewards.h | 2 +- src/cc/CCtokens.cpp | 2 +- src/cc/CCtokens.h | 2 +- src/cc/CCtokenutils.cpp | 2 +- src/cc/CCtx.cpp | 2 +- src/cc/CCutilbits.cpp | 2 +- src/cc/CCutils.cpp | 2 +- src/cc/assets.cpp | 2 +- src/cc/auction.cpp | 2 +- src/cc/betprotocol.cpp | 2 +- src/cc/betprotocol.h | 2 +- src/cc/cclib.cpp | 2 +- src/cc/channels.cpp | 2 +- src/cc/crypto777/OS_portable.h | 2 +- src/cc/customcc.cpp | 2 +- src/cc/customcc.h | 2 +- src/cc/dapps/Makefile | 2 +- src/cc/dapps/cJSON.c | 2 +- src/cc/dapps/dappinc.h | 2 +- src/cc/dapps/dappstd.c | 2 +- src/cc/dapps/hushdex.c | 2 +- src/cc/dapps/zmigrate.c | 2 +- src/cc/dice.cpp | 2 +- src/cc/dilithium.c | 2 +- src/cc/dilithium.h | 2 +- src/cc/disputepayout.cpp | 2 +- src/cc/eval.cpp | 2 +- src/cc/eval.h | 2 +- src/cc/faucet.cpp | 2 +- src/cc/fsm.cpp | 2 +- src/cc/games/prices.c | 2 +- src/cc/games/prices.cpp | 2 +- src/cc/games/prices.h | 2 +- src/cc/games/tetris.c | 2 +- src/cc/games/tetris.h | 2 +- src/cc/gamescc.cpp | 2 +- src/cc/gamescc.h | 2 +- src/cc/gateways.cpp | 2 +- src/cc/heir.cpp | 2 +- src/cc/heir_validate.h | 2 +- src/cc/import.cpp | 2 +- src/cc/importgateway.cpp | 2 +- src/cc/importpayout.cpp | 2 +- src/cc/includes/cJSON.h | 2 +- src/cc/includes/curve25519.h | 2 +- src/cc/includes/libgfshare.h | 2 +- src/cc/includes/tweetnacl.h | 2 +- src/cc/includes/uthash.h | 2 +- src/cc/includes/utlist.h | 2 +- src/cc/lotto.cpp | 2 +- src/cc/makecclib | 2 +- src/cc/makerogue | 2 +- src/cc/musig.cpp | 2 +- src/cc/oracles.cpp | 2 +- src/cc/payments.cpp | 2 +- src/cc/pegs.cpp | 2 +- src/cc/prices.cpp | 2 +- src/cc/rewards.cpp | 2 +- src/cc/rogue/Makefile.in | 2 +- src/cc/rogue/armor.c | 2 +- src/cc/rogue/chase.c | 2 +- src/cc/rogue/command.c | 2 +- src/cc/rogue/cursesd.c | 2 +- src/cc/rogue/cursesd.h | 2 +- src/cc/rogue/daemon.c | 2 +- src/cc/rogue/daemons.c | 2 +- src/cc/rogue/extern.c | 2 +- src/cc/rogue/extern.h | 2 +- src/cc/rogue/fight.c | 2 +- src/cc/rogue/init.c | 2 +- src/cc/rogue/io.c | 2 +- src/cc/rogue/list.c | 2 +- src/cc/rogue/mach_dep.c | 2 +- src/cc/rogue/main.c | 2 +- src/cc/rogue/mdport.c | 2 +- src/cc/rogue/misc.c | 2 +- src/cc/rogue/monsters.c | 2 +- src/cc/rogue/move.c | 2 +- src/cc/rogue/new_level.c | 2 +- src/cc/rogue/options.c | 2 +- src/cc/rogue/pack.c | 2 +- src/cc/rogue/passages.c | 2 +- src/cc/rogue/potions.c | 2 +- src/cc/rogue/rings.c | 2 +- src/cc/rogue/rip.c | 2 +- src/cc/rogue/rogue.c | 2 +- src/cc/rogue/rogue.h | 2 +- src/cc/rogue/rogue_player.h | 2 +- src/cc/rogue/rooms.c | 2 +- src/cc/rogue/save.c | 2 +- src/cc/rogue/score.h | 2 +- src/cc/rogue/scrolls.c | 2 +- src/cc/rogue/state.c | 2 +- src/cc/rogue/sticks.c | 2 +- src/cc/rogue/things.c | 2 +- src/cc/rogue/vers.c | 2 +- src/cc/rogue/weapons.c | 2 +- src/cc/rogue/wizard.c | 2 +- src/cc/rogue/xcrypt.c | 2 +- src/cc/rogue_rpc.cpp | 2 +- src/cc/sudoku.cpp | 2 +- src/cc/utils.h | 2 +- src/chain.cpp | 2 +- src/chain.h | 2 +- src/chainparams.cpp | 2 +- src/chainparams.h | 2 +- src/chainparamsbase.cpp | 2 +- src/checkpoints.cpp | 2 +- src/checkpoints.h | 2 +- src/checkqueue.h | 2 +- src/clientversion.cpp | 2 +- src/clientversion.h | 2 +- src/coincontrol.h | 2 +- src/coins.cpp | 2 +- src/coins.h | 2 +- src/compressor.cpp | 2 +- src/consensus/params.h | 2 +- src/consensus/upgrades.cpp | 2 +- src/core_memusage.h | 2 +- src/core_read.cpp | 2 +- src/core_write.cpp | 2 +- src/crosschain.cpp | 2 +- src/crosschain.h | 2 +- src/crosschain_authority.cpp | 2 +- src/crypto/common.h | 2 +- src/crypto/equihash.h | 2 +- src/cryptoconditions/AUTHORS | 2 +- src/cryptoconditions/src/anon.c | 2 +- src/cryptoconditions/src/asn/BIT_STRING.c | 2 +- src/cryptoconditions/src/asn/BIT_STRING.h | 2 +- src/cryptoconditions/src/asn/CompoundSha256Condition.c | 2 +- src/cryptoconditions/src/asn/CompoundSha256Condition.h | 2 +- src/cryptoconditions/src/asn/Condition.c | 2 +- src/cryptoconditions/src/asn/Condition.h | 2 +- src/cryptoconditions/src/asn/ConditionTypes.c | 2 +- src/cryptoconditions/src/asn/ConditionTypes.h | 2 +- src/cryptoconditions/src/asn/Ed25519FingerprintContents.c | 2 +- src/cryptoconditions/src/asn/Ed25519FingerprintContents.h | 2 +- src/cryptoconditions/src/asn/Ed25519Sha512Fulfillment.c | 2 +- src/cryptoconditions/src/asn/Ed25519Sha512Fulfillment.h | 2 +- src/cryptoconditions/src/asn/EvalFulfillment.c | 2 +- src/cryptoconditions/src/asn/EvalFulfillment.h | 2 +- src/cryptoconditions/src/asn/Fulfillment.c | 2 +- src/cryptoconditions/src/asn/Fulfillment.h | 2 +- src/cryptoconditions/src/asn/INTEGER.c | 2 +- src/cryptoconditions/src/asn/INTEGER.h | 2 +- src/cryptoconditions/src/asn/NativeEnumerated.c | 2 +- src/cryptoconditions/src/asn/NativeEnumerated.h | 2 +- src/cryptoconditions/src/asn/NativeInteger.c | 2 +- src/cryptoconditions/src/asn/NativeInteger.h | 2 +- src/cryptoconditions/src/asn/OCTET_STRING.c | 2 +- src/cryptoconditions/src/asn/OCTET_STRING.h | 2 +- src/cryptoconditions/src/asn/PrefixFingerprintContents.c | 2 +- src/cryptoconditions/src/asn/PrefixFingerprintContents.h | 2 +- src/cryptoconditions/src/asn/PrefixFulfillment.c | 2 +- src/cryptoconditions/src/asn/PrefixFulfillment.h | 2 +- src/cryptoconditions/src/asn/PreimageFulfillment.c | 2 +- src/cryptoconditions/src/asn/PreimageFulfillment.h | 2 +- src/cryptoconditions/src/asn/RsaFingerprintContents.c | 2 +- src/cryptoconditions/src/asn/RsaFingerprintContents.h | 2 +- src/cryptoconditions/src/asn/RsaSha256Fulfillment.c | 2 +- src/cryptoconditions/src/asn/RsaSha256Fulfillment.h | 2 +- src/cryptoconditions/src/asn/Secp256k1FingerprintContents.c | 2 +- src/cryptoconditions/src/asn/Secp256k1FingerprintContents.h | 2 +- src/cryptoconditions/src/asn/Secp256k1Fulfillment.c | 2 +- src/cryptoconditions/src/asn/Secp256k1Fulfillment.h | 2 +- src/cryptoconditions/src/asn/SimpleSha256Condition.c | 2 +- src/cryptoconditions/src/asn/SimpleSha256Condition.h | 2 +- src/cryptoconditions/src/asn/ThresholdFingerprintContents.c | 2 +- src/cryptoconditions/src/asn/ThresholdFingerprintContents.h | 2 +- src/cryptoconditions/src/asn/ThresholdFulfillment.c | 2 +- src/cryptoconditions/src/asn/ThresholdFulfillment.h | 2 +- src/cryptoconditions/src/asn/asn_SET_OF.c | 2 +- src/cryptoconditions/src/asn/asn_SET_OF.h | 2 +- src/cryptoconditions/src/asn/asn_application.h | 2 +- src/cryptoconditions/src/asn/asn_codecs.h | 2 +- src/cryptoconditions/src/asn/asn_codecs_prim.c | 2 +- src/cryptoconditions/src/asn/asn_codecs_prim.h | 2 +- src/cryptoconditions/src/asn/asn_internal.h | 2 +- src/cryptoconditions/src/asn/asn_system.h | 2 +- src/cryptoconditions/src/asn/ber_decoder.c | 2 +- src/cryptoconditions/src/asn/ber_decoder.h | 2 +- src/cryptoconditions/src/asn/ber_tlv_length.c | 2 +- src/cryptoconditions/src/asn/ber_tlv_length.h | 2 +- src/cryptoconditions/src/asn/ber_tlv_tag.c | 2 +- src/cryptoconditions/src/asn/ber_tlv_tag.h | 2 +- src/cryptoconditions/src/asn/constr_CHOICE.c | 2 +- src/cryptoconditions/src/asn/constr_CHOICE.h | 2 +- src/cryptoconditions/src/asn/constr_SEQUENCE.c | 2 +- src/cryptoconditions/src/asn/constr_SEQUENCE.h | 2 +- src/cryptoconditions/src/asn/constr_SET_OF.c | 2 +- src/cryptoconditions/src/asn/constr_SET_OF.h | 2 +- src/cryptoconditions/src/asn/constr_TYPE.c | 2 +- src/cryptoconditions/src/asn/constr_TYPE.h | 2 +- src/cryptoconditions/src/asn/constraints.c | 2 +- src/cryptoconditions/src/asn/constraints.h | 2 +- src/cryptoconditions/src/asn/der_encoder.c | 2 +- src/cryptoconditions/src/asn/der_encoder.h | 2 +- src/cryptoconditions/src/asn/per_decoder.c | 2 +- src/cryptoconditions/src/asn/per_decoder.h | 2 +- src/cryptoconditions/src/asn/per_encoder.c | 2 +- src/cryptoconditions/src/asn/per_encoder.h | 2 +- src/cryptoconditions/src/asn/per_opentype.c | 2 +- src/cryptoconditions/src/asn/per_opentype.h | 2 +- src/cryptoconditions/src/asn/per_support.c | 2 +- src/cryptoconditions/src/asn/per_support.h | 2 +- src/cryptoconditions/src/asn/xer_decoder.c | 2 +- src/cryptoconditions/src/asn/xer_decoder.h | 2 +- src/cryptoconditions/src/asn/xer_encoder.c | 2 +- src/cryptoconditions/src/asn/xer_encoder.h | 2 +- src/cryptoconditions/src/asn/xer_support.c | 2 +- src/cryptoconditions/src/asn/xer_support.h | 2 +- src/cryptoconditions/src/cryptoconditions.c | 2 +- src/cryptoconditions/src/ed25519.c | 2 +- src/cryptoconditions/src/eval.c | 2 +- src/cryptoconditions/src/include/cJSON.c | 2 +- src/cryptoconditions/src/include/cJSON.h | 2 +- src/cryptoconditions/src/include/libbase58.h | 2 +- src/cryptoconditions/src/include/sha256.c | 2 +- src/cryptoconditions/src/include/sha256.h | 2 +- src/cryptoconditions/src/include/tweetnacl.c | 2 +- src/cryptoconditions/src/include/tweetnacl.h | 2 +- src/cryptoconditions/src/internal.h | 2 +- src/cryptoconditions/src/json_rpc.c | 2 +- src/cryptoconditions/src/prefix.c | 2 +- src/cryptoconditions/src/preimage.c | 2 +- src/cryptoconditions/src/secp256k1.c | 2 +- src/cryptoconditions/src/threshold.c | 2 +- src/cryptoconditions/src/utils.c | 2 +- src/dbwrapper.cpp | 2 +- src/dbwrapper.h | 2 +- src/deprecation.cpp | 2 +- src/deprecation.h | 2 +- src/fs.cpp | 2 +- src/fs.h | 2 +- src/gtest/json_test_vectors.cpp | 2 +- src/gtest/json_test_vectors.h | 2 +- src/gtest/main.cpp | 2 +- src/gtest/test_block.cpp | 2 +- src/gtest/test_checkblock.cpp | 2 +- src/gtest/test_checktransaction.cpp | 2 +- src/gtest/test_deprecation.cpp | 2 +- src/gtest/test_equihash.cpp | 2 +- src/gtest/test_httprpc.cpp | 2 +- src/gtest/test_keys.cpp | 2 +- src/gtest/test_keystore.cpp | 2 +- src/gtest/test_libzcash_utils.cpp | 2 +- src/gtest/test_mempool.cpp | 2 +- src/gtest/test_merkletree.cpp | 2 +- src/gtest/test_metrics.cpp | 2 +- src/gtest/test_miner.cpp | 2 +- src/gtest/test_noteencryption.cpp | 2 +- src/gtest/test_pedersen_hash.cpp | 2 +- src/gtest/test_pow.cpp | 2 +- src/gtest/test_random.cpp | 2 +- src/gtest/test_rpc.cpp | 2 +- src/gtest/test_sapling_note.cpp | 2 +- src/gtest/test_tautology.cpp | 2 +- src/gtest/test_transaction_builder.cpp | 2 +- src/gtest/test_txid.cpp | 2 +- src/gtest/test_upgrades.cpp | 2 +- src/gtest/test_validation.cpp | 2 +- src/gtest/test_zip32.cpp | 2 +- src/gtest/utils.cpp | 2 +- src/hash.cpp | 2 +- src/hash.h | 2 +- src/httprpc.cpp | 2 +- src/httpserver.cpp | 2 +- src/httpserver.h | 2 +- src/hush-tx.cpp | 2 +- src/hush.h | 2 +- src/hush/tlsenums.h | 2 +- src/hush/tlsmanager.cpp | 2 +- src/hush/tlsmanager.h | 2 +- src/hush/utiltls.cpp | 2 +- src/hush/utiltls.h | 2 +- src/hush_bitcoind.h | 2 +- src/hush_cJSON.h | 2 +- src/hush_ccdata.h | 2 +- src/hush_curve25519.h | 2 +- src/hush_events.h | 2 +- src/hush_gateway.h | 2 +- src/hush_globals.h | 2 +- src/hush_kv.h | 2 +- src/hush_nSPV.h | 2 +- src/hush_nSPV_fullnode.h | 2 +- src/hush_nSPV_wallet.h | 2 +- src/hush_notary.h | 2 +- src/hush_pax.h | 2 +- src/hush_structs.h | 2 +- src/hush_utils.h | 2 +- src/importcoin.cpp | 2 +- src/importcoin.h | 2 +- src/init.cpp | 2 +- src/init.h | 2 +- src/key.cpp | 2 +- src/key.h | 2 +- src/key_io.cpp | 2 +- src/key_io.h | 2 +- src/keystore.cpp | 2 +- src/keystore.h | 2 +- src/main.cpp | 2 +- src/main.h | 2 +- src/merkleblock.cpp | 2 +- src/metrics.cpp | 2 +- src/metrics.h | 2 +- src/miner.h | 2 +- src/net.cpp | 2 +- src/net.h | 2 +- src/netbase.cpp | 2 +- src/notarizationdb.cpp | 2 +- src/notarizationdb.h | 2 +- src/noui.cpp | 2 +- src/pow.cpp | 2 +- src/pow.h | 2 +- src/pow/tromp/equi_miner.h | 2 +- src/pow/tromp/osx_barrier.h | 2 +- src/prevector.h | 2 +- src/primitives/block.cpp | 2 +- src/primitives/block.h | 2 +- src/primitives/transaction.cpp | 2 +- src/primitives/transaction.h | 2 +- src/protocol.cpp | 2 +- src/protocol.h | 2 +- src/pubkey.cpp | 2 +- src/pubkey.h | 2 +- src/purge | 2 +- src/random.cpp | 2 +- src/rest.cpp | 2 +- src/rpc/blockchain.cpp | 2 +- src/rpc/client.cpp | 2 +- src/rpc/crosschain.cpp | 2 +- src/rpc/mining.cpp | 2 +- src/rpc/net.cpp | 2 +- src/rpc/rawtransaction.cpp | 2 +- src/rpc/register.h | 2 +- src/rpc/server.cpp | 2 +- src/rpc/server.h | 2 +- src/scheduler.cpp | 2 +- src/script/interpreter.cpp | 2 +- src/script/standard.cpp | 2 +- src/script/standard.h | 2 +- src/sendalert.cpp | 4 ++-- src/smartchains | 2 +- src/support/allocators/secure.h | 2 +- src/support/allocators/zeroafterfree.h | 2 +- src/sync.cpp | 2 +- src/test-hush/main.cpp | 2 +- src/test-hush/test_addrman.cpp | 2 +- src/test-hush/test_coinimport.cpp | 2 +- src/test-hush/test_cryptoconditions.cpp | 2 +- src/test-hush/test_eval_bet.cpp | 2 +- src/test-hush/test_eval_notarization.cpp | 2 +- src/test-hush/test_netbase_tests.cpp | 2 +- src/test-hush/test_parse_notarization.cpp | 2 +- src/test-hush/testutils.cpp | 2 +- src/test-hush/testutils.h | 2 +- src/test/Checkpoints_tests.cpp | 2 +- src/test/DoS_tests.cpp | 2 +- src/test/accounting_tests.cpp | 2 +- src/test/addrman_tests.cpp | 2 +- src/test/allocator_tests.cpp | 2 +- src/test/arith_uint256_tests.cpp | 2 +- src/test/base32_tests.cpp | 2 +- src/test/base58_tests.cpp | 2 +- src/test/base64_tests.cpp | 2 +- src/test/bctest.py | 2 +- src/test/bech32_tests.cpp | 2 +- src/test/bip32_tests.cpp | 2 +- src/test/bitcoin-util-test.py | 2 +- src/test/bloom_tests.cpp | 2 +- src/test/checkblock_tests.cpp | 2 +- src/test/coins_tests.cpp | 2 +- src/test/compress_tests.cpp | 2 +- src/test/convertbits_tests.cpp | 2 +- src/test/crypto_tests.cpp | 2 +- src/test/dbwrapper_tests.cpp | 2 +- src/test/equihash_tests.cpp | 2 +- src/test/getarg_tests.cpp | 2 +- src/test/hash_tests.cpp | 2 +- src/test/key_tests.cpp | 2 +- src/test/main_tests.cpp | 2 +- src/test/mempool_tests.cpp | 2 +- src/test/miner_tests.cpp | 2 +- src/test/mruset_tests.cpp | 2 +- src/test/multisig_tests.cpp | 2 +- src/test/netbase_tests.cpp | 2 +- src/test/pmt_tests.cpp | 2 +- src/test/policyestimator_tests.cpp | 2 +- src/test/pow_tests.cpp | 2 +- src/test/prevector_tests.cpp | 2 +- src/test/raii_event_tests.cpp | 2 +- src/test/reverselock_tests.cpp | 2 +- src/test/rpc_tests.cpp | 2 +- src/test/rpc_wallet_tests.cpp | 2 +- src/test/sanity_tests.cpp | 2 +- src/test/scheduler_tests.cpp | 2 +- src/test/script_P2PKH_tests.cpp | 2 +- src/test/script_P2SH_tests.cpp | 2 +- src/test/script_tests.cpp | 2 +- src/test/scriptnum_tests.cpp | 2 +- src/test/serialize_tests.cpp | 2 +- src/test/sha256compress_tests.cpp | 2 +- src/test/sighash_tests.cpp | 2 +- src/test/sigopcount_tests.cpp | 2 +- src/test/skiplist_tests.cpp | 2 +- src/test/test_bitcoin.cpp | 2 +- src/test/test_bitcoin.h | 2 +- src/test/timedata_tests.cpp | 2 +- src/test/torcontrol_tests.cpp | 2 +- src/test/transaction_tests.cpp | 2 +- src/test/uint256_tests.cpp | 2 +- src/test/univalue_tests.cpp | 2 +- src/test/util_tests.cpp | 2 +- src/test/wallet-utility.py | 2 +- src/timedata.cpp | 2 +- src/timedata.h | 2 +- src/torcontrol.cpp | 2 +- src/torcontrol.h | 2 +- src/transaction_builder.cpp | 2 +- src/transaction_builder.h | 2 +- src/tush-cli | 2 +- src/tushd | 2 +- src/txdb.cpp | 2 +- src/txdb.h | 2 +- src/txmempool.cpp | 2 +- src/txmempool.h | 2 +- src/uint256.cpp | 2 +- src/util.cpp | 2 +- src/util.h | 2 +- src/utilmoneystr.cpp | 2 +- src/utilstrencodings.cpp | 2 +- src/utiltime.cpp | 2 +- src/validationinterface.cpp | 2 +- src/validationinterface.h | 2 +- src/version.h | 2 +- src/wallet-utility.cpp | 2 +- src/wallet/asyncrpcoperation_mergetoaddress.cpp | 2 +- src/wallet/asyncrpcoperation_mergetoaddress.h | 2 +- src/wallet/asyncrpcoperation_saplingconsolidation.cpp | 2 +- src/wallet/asyncrpcoperation_sendmany.cpp | 2 +- src/wallet/asyncrpcoperation_sendmany.h | 2 +- src/wallet/asyncrpcoperation_shieldcoinbase.cpp | 2 +- src/wallet/asyncrpcoperation_shieldcoinbase.h | 2 +- src/wallet/crypter.cpp | 2 +- src/wallet/crypter.h | 2 +- src/wallet/db.cpp | 2 +- src/wallet/gtest/test_transaction.cpp | 2 +- src/wallet/gtest/test_wallet.cpp | 2 +- src/wallet/gtest/test_wallet_zkeys.cpp | 2 +- src/wallet/rpcdump.cpp | 2 +- src/wallet/rpchushwallet.cpp | 2 +- src/wallet/rpcwallet.cpp | 2 +- src/wallet/test/wallet_tests.cpp | 2 +- src/wallet/wallet.cpp | 2 +- src/wallet/wallet.h | 2 +- src/wallet/walletdb.cpp | 2 +- src/zcash/Address.cpp | 2 +- src/zcash/Address.hpp | 2 +- src/zcash/IncrementalMerkleTree.cpp | 2 +- src/zcash/IncrementalMerkleTree.hpp | 2 +- src/zcash/JoinSplit.cpp | 2 +- src/zcash/JoinSplit.hpp | 2 +- src/zcash/Note.cpp | 2 +- src/zcash/Note.hpp | 2 +- src/zcash/NoteEncryption.cpp | 2 +- src/zcash/NoteEncryption.hpp | 2 +- src/zcash/Proof.cpp | 2 +- src/zcash/Proof.hpp | 2 +- src/zcash/Zcash.h | 2 +- src/zcash/prf.cpp | 2 +- src/zcash/prf.h | 2 +- src/zcash/util.cpp | 2 +- src/zcash/util.h | 2 +- src/zcash/zip32.cpp | 2 +- src/zcash/zip32.h | 2 +- src/zush | 2 +- toolchain-info.sh | 2 +- util/afl/afl-build.sh | 2 +- util/afl/afl-get.sh | 2 +- util/afl/afl-getbuildrun.sh | 2 +- util/afl/afl-run.sh | 2 +- util/build-arm.sh | 2 +- util/build-debian-package.sh | 2 +- util/build-mac.sh | 2 +- util/build-win.sh | 2 +- util/checkpoints.pl | 2 +- util/docker-entrypoint.sh | 2 +- util/gen-manpages.sh | 2 +- 652 files changed, 653 insertions(+), 653 deletions(-) diff --git a/Dockerfile b/Dockerfile index b89a159a0..7e639b16f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html FROM ubuntu:16.04 diff --git a/Makefile.am b/Makefile.am index 84a4aed25..48c498853 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -# Copyright 2016-2021 The Hush developers +# Copyright 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/autogen.sh b/autogen.sh index 6932fae53..2aa9ad130 100755 --- a/autogen.sh +++ b/autogen.sh @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html set -e diff --git a/contrib/block_time.pl b/contrib/block_time.pl index 0366aa8f9..cb11ed239 100755 --- a/contrib/block_time.pl +++ b/contrib/block_time.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html use warnings; diff --git a/contrib/fresh_clone_compile_and_run.sh b/contrib/fresh_clone_compile_and_run.sh index 54fc69ed6..9f92a0ca6 100644 --- a/contrib/fresh_clone_compile_and_run.sh +++ b/contrib/fresh_clone_compile_and_run.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # OPEN BOUNTY diff --git a/contrib/hush_halvings b/contrib/hush_halvings index 80bb24b04..cfb899ced 100755 --- a/contrib/hush_halvings +++ b/contrib/hush_halvings @@ -1,5 +1,5 @@ #!/usr/bin/env perl -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 use strict; diff --git a/contrib/hush_scanner b/contrib/hush_scanner index 6ec4300b9..af4ee4144 100755 --- a/contrib/hush_scanner +++ b/contrib/hush_scanner @@ -1,5 +1,5 @@ #!/usr/bin/env perl -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html use strict; diff --git a/contrib/hush_supply b/contrib/hush_supply index e12770f84..ef78fef3c 100755 --- a/contrib/hush_supply +++ b/contrib/hush_supply @@ -1,5 +1,5 @@ #!/usr/bin/env perl -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 use warnings; use strict; diff --git a/contrib/verify-commits/gpg.sh b/contrib/verify-commits/gpg.sh index dc6eb9c61..b25d5dc5c 100755 --- a/contrib/verify-commits/gpg.sh +++ b/contrib/verify-commits/gpg.sh @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html INPUT=$(. -Copyright (C) 2016-2021 Duke Leto and The Hush Developers +Copyright (C) 2016-2022 Duke Leto and The Hush Developers Copyright (C) 2016-2020 jl777 and SuperNET developers Copyright (C) 2016-2018 The Zcash developers Copyright (C) 2009-2014 The Bitcoin Core developers diff --git a/doc/man/hush-tx.1 b/doc/man/hush-tx.1 index f34354e45..4a01ad1e7 100644 --- a/doc/man/hush-tx.1 +++ b/doc/man/hush-tx.1 @@ -88,7 +88,7 @@ Set register NAME to given JSON\-STRING In order to ensure you are adequately protecting your privacy when using Hush, please see . -Copyright (C) 2016-2021 Duke Leto and The Hush Developers +Copyright (C) 2016-2022 Duke Leto and The Hush Developers Copyright (C) 2016-2020 jl777 and SuperNET developers Copyright (C) 2016-2018 The Zcash developers Copyright (C) 2009-2014 The Bitcoin Core developers diff --git a/doc/man/hushd.1 b/doc/man/hushd.1 index 9f69dd460..3cd181f7c 100644 --- a/doc/man/hushd.1 +++ b/doc/man/hushd.1 @@ -724,7 +724,7 @@ Enforce transaction\-rate limit, default 0 In order to ensure you are adequately protecting your privacy when using Hush, please see . -Copyright (C) 2016-2021 Duke Leto and The Hush Developers +Copyright (C) 2016-2022 Duke Leto and The Hush Developers Copyright (C) 2016-2020 jl777 and SuperNET developers Copyright (C) 2016-2018 The Zcash developers Copyright (C) 2009-2014 The Bitcoin Core developers diff --git a/migratecoin.sh b/migratecoin.sh index 95aea910c..f34215197 100644 --- a/migratecoin.sh +++ b/migratecoin.sh @@ -1,5 +1,5 @@ #!/usr/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # This script makes the neccesary transactions to migrate diff --git a/qa/hush/create_benchmark_archive.py b/qa/hush/create_benchmark_archive.py index 68938297e..5f9a08721 100644 --- a/qa/hush/create_benchmark_archive.py +++ b/qa/hush/create_benchmark_archive.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html import binascii diff --git a/qa/hush/create_wallet_200k_utxos.py b/qa/hush/create_wallet_200k_utxos.py index 3499cdd70..d2174e864 100644 --- a/qa/hush/create_wallet_200k_utxos.py +++ b/qa/hush/create_wallet_200k_utxos.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2017 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/hush/full-test-suite.sh b/qa/hush/full-test-suite.sh index 0618ccdca..b7fb37f0a 100755 --- a/qa/hush/full-test-suite.sh +++ b/qa/hush/full-test-suite.sh @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Execute all of the automated tests related to Hush # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/hush/full_test_suite.py b/qa/hush/full_test_suite.py index 87fcc6ac0..c8cc05e45 100755 --- a/qa/hush/full_test_suite.py +++ b/qa/hush/full_test_suite.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # Execute all of the automated tests related to Hush diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index 153f7b4a6..3bafe170c 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 set -e -o pipefail diff --git a/qa/pull-tester/run-bitcoin-cli b/qa/pull-tester/run-bitcoin-cli index 74f9b19e8..2e7b326af 100755 --- a/qa/pull-tester/run-bitcoin-cli +++ b/qa/pull-tester/run-bitcoin-cli @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 # This is a thin wrapper around bitcoin-cli that strips the Windows-style EOLs diff --git a/qa/pull-tester/run-bitcoind-for-test.sh.in b/qa/pull-tester/run-bitcoind-for-test.sh.in index 0ae527293..4527dff7b 100755 --- a/qa/pull-tester/run-bitcoind-for-test.sh.in +++ b/qa/pull-tester/run-bitcoind-for-test.sh.in @@ -1,7 +1,7 @@ #!/bin/bash # THIS FILE IS GENERATED FROM run-bitcoind-for-test.sh.in # Copyright (c) 2013-2014 The Bitcoin Core developers -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 # HUSH_LOAD_TIMEOUT=500 diff --git a/qa/pull-tester/tests-config.sh.in b/qa/pull-tester/tests-config.sh.in index d48d5bbc5..824b9d2a1 100755 --- a/qa/pull-tester/tests-config.sh.in +++ b/qa/pull-tester/tests-config.sh.in @@ -1,7 +1,7 @@ #!/bin/bash # THIS FILE IS GENERATED FROM tests-config.sh.in # Copyright (c) 2013-2014 The Bitcoin Core developers -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 BUILDDIR="@abs_top_builddir@" diff --git a/qa/rpc-tests/ac_private.py b/qa/rpc-tests/ac_private.py index 7c066529a..03675b6b1 100755 --- a/qa/rpc-tests/ac_private.py +++ b/qa/rpc-tests/ac_private.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 SuperNET developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/addressindex.py b/qa/rpc-tests/addressindex.py index 3f2e77c96..62483e40a 100755 --- a/qa/rpc-tests/addressindex.py +++ b/qa/rpc-tests/addressindex.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # Copyright (c) 2014-2015 The Bitcoin Core developers -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # Test addressindex generation and fetching diff --git a/qa/rpc-tests/bip65-cltv-p2p.py b/qa/rpc-tests/bip65-cltv-p2p.py index f8d637e64..60bab6854 100755 --- a/qa/rpc-tests/bip65-cltv-p2p.py +++ b/qa/rpc-tests/bip65-cltv-p2p.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/bipdersig-p2p.py b/qa/rpc-tests/bipdersig-p2p.py index bba8ff01b..f83f0a2c7 100755 --- a/qa/rpc-tests/bipdersig-p2p.py +++ b/qa/rpc-tests/bipdersig-p2p.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3/X11 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # diff --git a/qa/rpc-tests/blockchain.py b/qa/rpc-tests/blockchain.py index 7cd728d30..b66a6b3bc 100755 --- a/qa/rpc-tests/blockchain.py +++ b/qa/rpc-tests/blockchain.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/cryptoconditions.py b/qa/rpc-tests/cryptoconditions.py index 85016f2d5..2c6f95847 100755 --- a/qa/rpc-tests/cryptoconditions.py +++ b/qa/rpc-tests/cryptoconditions.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 SuperNET developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/cryptoconditions_channels.py b/qa/rpc-tests/cryptoconditions_channels.py index 9273efbe9..127df77ee 100755 --- a/qa/rpc-tests/cryptoconditions_channels.py +++ b/qa/rpc-tests/cryptoconditions_channels.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 SuperNET developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/cryptoconditions_dice.py b/qa/rpc-tests/cryptoconditions_dice.py index 894b25d0d..4f9d8c7c4 100755 --- a/qa/rpc-tests/cryptoconditions_dice.py +++ b/qa/rpc-tests/cryptoconditions_dice.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 SuperNET developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/cryptoconditions_faucet.py b/qa/rpc-tests/cryptoconditions_faucet.py index af9e8e033..3cccaf2db 100755 --- a/qa/rpc-tests/cryptoconditions_faucet.py +++ b/qa/rpc-tests/cryptoconditions_faucet.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 SuperNET developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/cryptoconditions_gateways.py b/qa/rpc-tests/cryptoconditions_gateways.py index b979e99ce..d60452269 100755 --- a/qa/rpc-tests/cryptoconditions_gateways.py +++ b/qa/rpc-tests/cryptoconditions_gateways.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 SuperNET developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/cryptoconditions_heir.py b/qa/rpc-tests/cryptoconditions_heir.py index 99ddb9af0..9ce32a625 100755 --- a/qa/rpc-tests/cryptoconditions_heir.py +++ b/qa/rpc-tests/cryptoconditions_heir.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 SuperNET developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/cryptoconditions_oracles.py b/qa/rpc-tests/cryptoconditions_oracles.py index 39672ba53..255b372f6 100755 --- a/qa/rpc-tests/cryptoconditions_oracles.py +++ b/qa/rpc-tests/cryptoconditions_oracles.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 SuperNET developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/cryptoconditions_rewards.py b/qa/rpc-tests/cryptoconditions_rewards.py index 7e4f0a879..3c1452ed4 100755 --- a/qa/rpc-tests/cryptoconditions_rewards.py +++ b/qa/rpc-tests/cryptoconditions_rewards.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 SuperNET developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/cryptoconditions_token.py b/qa/rpc-tests/cryptoconditions_token.py index 6df6b11a9..dbded0062 100755 --- a/qa/rpc-tests/cryptoconditions_token.py +++ b/qa/rpc-tests/cryptoconditions_token.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 SuperNET developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/decodescript.py b/qa/rpc-tests/decodescript.py index 70a7cdfbb..f4d63d317 100755 --- a/qa/rpc-tests/decodescript.py +++ b/qa/rpc-tests/decodescript.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2015 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/disablewallet.py b/qa/rpc-tests/disablewallet.py index ecefd096f..bb4cda6e5 100755 --- a/qa/rpc-tests/disablewallet.py +++ b/qa/rpc-tests/disablewallet.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/dpowconfs.py b/qa/rpc-tests/dpowconfs.py index 340db0bd6..89fb640ad 100755 --- a/qa/rpc-tests/dpowconfs.py +++ b/qa/rpc-tests/dpowconfs.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2019 Duke Leto who wrote "The SuperNET developers" while never agreeing to the developer agreement nor being listed in AUTHORS # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/feature_walletfile.py b/qa/rpc-tests/feature_walletfile.py index 5487a5245..b0364a7d3 100755 --- a/qa/rpc-tests/feature_walletfile.py +++ b/qa/rpc-tests/feature_walletfile.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # Copyright (c) 2017 The Bitcoin Core developers -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html """Test wallet file location.""" diff --git a/qa/rpc-tests/finalsaplingroot.py b/qa/rpc-tests/finalsaplingroot.py index 15078709d..b82053eb0 100755 --- a/qa/rpc-tests/finalsaplingroot.py +++ b/qa/rpc-tests/finalsaplingroot.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/forknotify.py b/qa/rpc-tests/forknotify.py index d017d2409..1f615f930 100755 --- a/qa/rpc-tests/forknotify.py +++ b/qa/rpc-tests/forknotify.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/fundrawtransaction.py b/qa/rpc-tests/fundrawtransaction.py index daae872e4..3a9ac0ca6 100755 --- a/qa/rpc-tests/fundrawtransaction.py +++ b/qa/rpc-tests/fundrawtransaction.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/getblocktemplate.py b/qa/rpc-tests/getblocktemplate.py index 308a21729..6d771b360 100755 --- a/qa/rpc-tests/getblocktemplate.py +++ b/qa/rpc-tests/getblocktemplate.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2016 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/getblocktemplate_longpoll.py b/qa/rpc-tests/getblocktemplate_longpoll.py index f2bf82172..ab393755b 100755 --- a/qa/rpc-tests/getblocktemplate_longpoll.py +++ b/qa/rpc-tests/getblocktemplate_longpoll.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/getblocktemplate_proposals.py b/qa/rpc-tests/getblocktemplate_proposals.py index 61c33af1c..f75032091 100755 --- a/qa/rpc-tests/getblocktemplate_proposals.py +++ b/qa/rpc-tests/getblocktemplate_proposals.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/getchaintips.py b/qa/rpc-tests/getchaintips.py index e40664196..84c3f7f6c 100755 --- a/qa/rpc-tests/getchaintips.py +++ b/qa/rpc-tests/getchaintips.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/hardforkdetection.py b/qa/rpc-tests/hardforkdetection.py index f98d274a8..bcd13e0d4 100755 --- a/qa/rpc-tests/hardforkdetection.py +++ b/qa/rpc-tests/hardforkdetection.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # # Test hard fork detection diff --git a/qa/rpc-tests/httpbasics.py b/qa/rpc-tests/httpbasics.py index 034ff2a4d..ff5544a2c 100755 --- a/qa/rpc-tests/httpbasics.py +++ b/qa/rpc-tests/httpbasics.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/invalidateblock.py b/qa/rpc-tests/invalidateblock.py index 4edad27df..ea189ff85 100755 --- a/qa/rpc-tests/invalidateblock.py +++ b/qa/rpc-tests/invalidateblock.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/invalidblockrequest.py b/qa/rpc-tests/invalidblockrequest.py index e8440a8e7..f806d07ec 100755 --- a/qa/rpc-tests/invalidblockrequest.py +++ b/qa/rpc-tests/invalidblockrequest.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # # Distributed under the GPLv3/X11 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/ivk_import_export.py b/qa/rpc-tests/ivk_import_export.py index 6431edda2..a5eaf5233 100755 --- a/qa/rpc-tests/ivk_import_export.py +++ b/qa/rpc-tests/ivk_import_export.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2019 Bartlomiej Lisiecki # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/key_import_export.py b/qa/rpc-tests/key_import_export.py index 54b07b2ee..f7e13a732 100755 --- a/qa/rpc-tests/key_import_export.py +++ b/qa/rpc-tests/key_import_export.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2017 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/keypool.py b/qa/rpc-tests/keypool.py index a64d79525..0a22cae8a 100755 --- a/qa/rpc-tests/keypool.py +++ b/qa/rpc-tests/keypool.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/listtransactions.py b/qa/rpc-tests/listtransactions.py index ace7e9090..f82494ca2 100755 --- a/qa/rpc-tests/listtransactions.py +++ b/qa/rpc-tests/listtransactions.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/maxblocksinflight.py b/qa/rpc-tests/maxblocksinflight.py index b0c7ad66f..4b7e6e624 100755 --- a/qa/rpc-tests/maxblocksinflight.py +++ b/qa/rpc-tests/maxblocksinflight.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # # Distributed under the GPLv3/X11 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/mempool_nu_activation.py b/qa/rpc-tests/mempool_nu_activation.py index 36d8493cc..fead09452 100755 --- a/qa/rpc-tests/mempool_nu_activation.py +++ b/qa/rpc-tests/mempool_nu_activation.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/mempool_reorg.py b/qa/rpc-tests/mempool_reorg.py index 4c39eba46..e08b5985f 100755 --- a/qa/rpc-tests/mempool_reorg.py +++ b/qa/rpc-tests/mempool_reorg.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/mempool_resurrect_test.py b/qa/rpc-tests/mempool_resurrect_test.py index 3c3b1c9d7..6afad2c7d 100755 --- a/qa/rpc-tests/mempool_resurrect_test.py +++ b/qa/rpc-tests/mempool_resurrect_test.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/mempool_spendcoinbase.py b/qa/rpc-tests/mempool_spendcoinbase.py index 7a80d034e..ee6465868 100755 --- a/qa/rpc-tests/mempool_spendcoinbase.py +++ b/qa/rpc-tests/mempool_spendcoinbase.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/mempool_tx_expiry.py b/qa/rpc-tests/mempool_tx_expiry.py index 078028a6e..de43e3bf3 100755 --- a/qa/rpc-tests/mempool_tx_expiry.py +++ b/qa/rpc-tests/mempool_tx_expiry.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/mempool_tx_input_limit.py b/qa/rpc-tests/mempool_tx_input_limit.py index e88db77f1..28761aca8 100755 --- a/qa/rpc-tests/mempool_tx_input_limit.py +++ b/qa/rpc-tests/mempool_tx_input_limit.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2017 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/merkle_blocks.py b/qa/rpc-tests/merkle_blocks.py index 4d4103ed9..4de09a02d 100755 --- a/qa/rpc-tests/merkle_blocks.py +++ b/qa/rpc-tests/merkle_blocks.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/nodehandling.py b/qa/rpc-tests/nodehandling.py index ca5c7c319..f23e19ade 100755 --- a/qa/rpc-tests/nodehandling.py +++ b/qa/rpc-tests/nodehandling.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/nspv_client_test.py b/qa/rpc-tests/nspv_client_test.py index c232389f2..45606cec1 100755 --- a/qa/rpc-tests/nspv_client_test.py +++ b/qa/rpc-tests/nspv_client_test.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html import sys diff --git a/qa/rpc-tests/p2p-acceptblock.py b/qa/rpc-tests/p2p-acceptblock.py index 22bc4212d..4dccdfae5 100755 --- a/qa/rpc-tests/p2p-acceptblock.py +++ b/qa/rpc-tests/p2p-acceptblock.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # # Distributed under the GPLv3/X11 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/p2p_node_bloom.py b/qa/rpc-tests/p2p_node_bloom.py index 78d4021f3..6bbb3be57 100755 --- a/qa/rpc-tests/p2p_node_bloom.py +++ b/qa/rpc-tests/p2p_node_bloom.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/p2p_txexpiry_dos.py b/qa/rpc-tests/p2p_txexpiry_dos.py index bde410d6a..c870f2e74 100755 --- a/qa/rpc-tests/p2p_txexpiry_dos.py +++ b/qa/rpc-tests/p2p_txexpiry_dos.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/prioritisetransaction.py b/qa/rpc-tests/prioritisetransaction.py index 813f5c00d..4038c7a8f 100755 --- a/qa/rpc-tests/prioritisetransaction.py +++ b/qa/rpc-tests/prioritisetransaction.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2017 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/proxy_test.py b/qa/rpc-tests/proxy_test.py index 15b83c66c..1a200db56 100755 --- a/qa/rpc-tests/proxy_test.py +++ b/qa/rpc-tests/proxy_test.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2015 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/pruning.py b/qa/rpc-tests/pruning.py index 16714e0f2..44d8c8b5d 100755 --- a/qa/rpc-tests/pruning.py +++ b/qa/rpc-tests/pruning.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/rawtransactions.py b/qa/rpc-tests/rawtransactions.py index 872c4f28c..b59d4f073 100755 --- a/qa/rpc-tests/rawtransactions.py +++ b/qa/rpc-tests/rawtransactions.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/receivedby.py b/qa/rpc-tests/receivedby.py index bb50e07f3..a2e3bc224 100755 --- a/qa/rpc-tests/receivedby.py +++ b/qa/rpc-tests/receivedby.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/regtest_signrawtransaction.py b/qa/rpc-tests/regtest_signrawtransaction.py index aaeb9107a..520d7fca9 100755 --- a/qa/rpc-tests/regtest_signrawtransaction.py +++ b/qa/rpc-tests/regtest_signrawtransaction.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/reindex.py b/qa/rpc-tests/reindex.py index 988ee21f4..f8f06d96a 100755 --- a/qa/rpc-tests/reindex.py +++ b/qa/rpc-tests/reindex.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # Copyright (c) 2014 The Bitcoin Core developers -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 # # Test -reindex with CheckBlockIndex diff --git a/qa/rpc-tests/rest.py b/qa/rpc-tests/rest.py index 2be0254c7..a1ba0cc06 100755 --- a/qa/rpc-tests/rest.py +++ b/qa/rpc-tests/rest.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/rewind_index.py b/qa/rpc-tests/rewind_index.py index ea971a818..65d1d2a13 100755 --- a/qa/rpc-tests/rewind_index.py +++ b/qa/rpc-tests/rewind_index.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/rpcbind_test.py b/qa/rpc-tests/rpcbind_test.py index 17835c694..d95e9aca5 100755 --- a/qa/rpc-tests/rpcbind_test.py +++ b/qa/rpc-tests/rpcbind_test.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/script_test.py b/qa/rpc-tests/script_test.py index a4d59e2bc..4175e7d13 100755 --- a/qa/rpc-tests/script_test.py +++ b/qa/rpc-tests/script_test.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # # Distributed under the GPLv3/X11 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/signrawtransaction_offline.py b/qa/rpc-tests/signrawtransaction_offline.py index f0fba1c50..84f3e1888 100755 --- a/qa/rpc-tests/signrawtransaction_offline.py +++ b/qa/rpc-tests/signrawtransaction_offline.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/signrawtransactions.py b/qa/rpc-tests/signrawtransactions.py index 332ffd635..a7fe196b1 100755 --- a/qa/rpc-tests/signrawtransactions.py +++ b/qa/rpc-tests/signrawtransactions.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2015 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/smartfees.py b/qa/rpc-tests/smartfees.py index 0d689e9e8..19c233d4f 100755 --- a/qa/rpc-tests/smartfees.py +++ b/qa/rpc-tests/smartfees.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014-2015 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/spentindex.py b/qa/rpc-tests/spentindex.py index f4b8f9209..2300df6c3 100755 --- a/qa/rpc-tests/spentindex.py +++ b/qa/rpc-tests/spentindex.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014-2015 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/test_framework/authproxy.py b/qa/rpc-tests/test_framework/authproxy.py index c4bd79c04..32cf6fd0d 100644 --- a/qa/rpc-tests/test_framework/authproxy.py +++ b/qa/rpc-tests/test_framework/authproxy.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/test_framework/bignum.py b/qa/rpc-tests/test_framework/bignum.py index 6b764a389..cf6e9418f 100644 --- a/qa/rpc-tests/test_framework/bignum.py +++ b/qa/rpc-tests/test_framework/bignum.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # This file is from python-bitcoinlib. diff --git a/qa/rpc-tests/test_framework/blockstore.py b/qa/rpc-tests/test_framework/blockstore.py index 9a7c2bd35..6687be3df 100644 --- a/qa/rpc-tests/test_framework/blockstore.py +++ b/qa/rpc-tests/test_framework/blockstore.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # BlockStore: a helper class that keeps a map of blocks and implements diff --git a/qa/rpc-tests/test_framework/blocktools.py b/qa/rpc-tests/test_framework/blocktools.py index 9955b4324..260ea9f62 100644 --- a/qa/rpc-tests/test_framework/blocktools.py +++ b/qa/rpc-tests/test_framework/blocktools.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # blocktools.py - utilities for manipulating blocks and transactions diff --git a/qa/rpc-tests/test_framework/comptool.py b/qa/rpc-tests/test_framework/comptool.py index a0f46d464..9daaae04e 100755 --- a/qa/rpc-tests/test_framework/comptool.py +++ b/qa/rpc-tests/test_framework/comptool.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/test_framework/equihash.py b/qa/rpc-tests/test_framework/equihash.py index 2f7b74c1e..e0d9cf306 100755 --- a/qa/rpc-tests/test_framework/equihash.py +++ b/qa/rpc-tests/test_framework/equihash.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html from operator import itemgetter diff --git a/qa/rpc-tests/test_framework/mininode.py b/qa/rpc-tests/test_framework/mininode.py index ecbef5e24..421691bcb 100755 --- a/qa/rpc-tests/test_framework/mininode.py +++ b/qa/rpc-tests/test_framework/mininode.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # mininode.py - Bitcoin P2P network half-a-node diff --git a/qa/rpc-tests/test_framework/netutil.py b/qa/rpc-tests/test_framework/netutil.py index 07e7460ce..57baecdc0 100644 --- a/qa/rpc-tests/test_framework/netutil.py +++ b/qa/rpc-tests/test_framework/netutil.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/test_framework/script.py b/qa/rpc-tests/test_framework/script.py index 320151f7d..ae8a2fc7a 100644 --- a/qa/rpc-tests/test_framework/script.py +++ b/qa/rpc-tests/test_framework/script.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # This file is modified from python-bitcoinlib. diff --git a/qa/rpc-tests/test_framework/socks5.py b/qa/rpc-tests/test_framework/socks5.py index 27f67225e..9138f221b 100644 --- a/qa/rpc-tests/test_framework/socks5.py +++ b/qa/rpc-tests/test_framework/socks5.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2015 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/test_framework/test_framework.py b/qa/rpc-tests/test_framework/test_framework.py index 55565a2d3..8fa2876ea 100755 --- a/qa/rpc-tests/test_framework/test_framework.py +++ b/qa/rpc-tests/test_framework/test_framework.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # Copyright (c) 2014 The Bitcoin Core developers -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # Base class for RPC testing diff --git a/qa/rpc-tests/timestampindex.py b/qa/rpc-tests/timestampindex.py index 17401d607..ca37d469d 100755 --- a/qa/rpc-tests/timestampindex.py +++ b/qa/rpc-tests/timestampindex.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014-2015 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/txindex.py b/qa/rpc-tests/txindex.py index 9424e75f9..89e5a6886 100755 --- a/qa/rpc-tests/txindex.py +++ b/qa/rpc-tests/txindex.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014-2015 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/txn_doublespend.py b/qa/rpc-tests/txn_doublespend.py index dd5fbafad..e3952f43e 100755 --- a/qa/rpc-tests/txn_doublespend.py +++ b/qa/rpc-tests/txn_doublespend.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet.py b/qa/rpc-tests/wallet.py index 27b603a14..6ef8e3162 100755 --- a/qa/rpc-tests/wallet.py +++ b/qa/rpc-tests/wallet.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_1941.py b/qa/rpc-tests/wallet_1941.py index f69f04d4d..678e75af4 100755 --- a/qa/rpc-tests/wallet_1941.py +++ b/qa/rpc-tests/wallet_1941.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2016 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_addresses.py b/qa/rpc-tests/wallet_addresses.py index 67ffa2975..53f16fcc4 100755 --- a/qa/rpc-tests/wallet_addresses.py +++ b/qa/rpc-tests/wallet_addresses.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_anchorfork.py b/qa/rpc-tests/wallet_anchorfork.py index cab7a6d1e..46e5cf3c5 100755 --- a/qa/rpc-tests/wallet_anchorfork.py +++ b/qa/rpc-tests/wallet_anchorfork.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_changeindicator.py b/qa/rpc-tests/wallet_changeindicator.py index b1027c09c..21274208a 100755 --- a/qa/rpc-tests/wallet_changeindicator.py +++ b/qa/rpc-tests/wallet_changeindicator.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_import_export.py b/qa/rpc-tests/wallet_import_export.py index c5c71acd8..b3a266cbe 100755 --- a/qa/rpc-tests/wallet_import_export.py +++ b/qa/rpc-tests/wallet_import_export.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_listnotes.py b/qa/rpc-tests/wallet_listnotes.py index 6c80b96ac..66715a682 100755 --- a/qa/rpc-tests/wallet_listnotes.py +++ b/qa/rpc-tests/wallet_listnotes.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_listreceived.py b/qa/rpc-tests/wallet_listreceived.py index 3cbb49aae..ca48cb975 100755 --- a/qa/rpc-tests/wallet_listreceived.py +++ b/qa/rpc-tests/wallet_listreceived.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_mergetoaddress.py b/qa/rpc-tests/wallet_mergetoaddress.py index ea4a3b910..0684ccf1e 100755 --- a/qa/rpc-tests/wallet_mergetoaddress.py +++ b/qa/rpc-tests/wallet_mergetoaddress.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2017 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_nullifiers.py b/qa/rpc-tests/wallet_nullifiers.py index 7eed3c984..d2cd485cc 100755 --- a/qa/rpc-tests/wallet_nullifiers.py +++ b/qa/rpc-tests/wallet_nullifiers.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2016 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_overwintertx.py b/qa/rpc-tests/wallet_overwintertx.py index fdd7a1947..6f8c03dce 100755 --- a/qa/rpc-tests/wallet_overwintertx.py +++ b/qa/rpc-tests/wallet_overwintertx.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_persistence.py b/qa/rpc-tests/wallet_persistence.py index 4cf2c52f0..90076b867 100755 --- a/qa/rpc-tests/wallet_persistence.py +++ b/qa/rpc-tests/wallet_persistence.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_protectcoinbase.py b/qa/rpc-tests/wallet_protectcoinbase.py index c6f9c2760..9f91ff55f 100755 --- a/qa/rpc-tests/wallet_protectcoinbase.py +++ b/qa/rpc-tests/wallet_protectcoinbase.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2016 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_sapling.py b/qa/rpc-tests/wallet_sapling.py index 7e58a08d9..9cb120583 100755 --- a/qa/rpc-tests/wallet_sapling.py +++ b/qa/rpc-tests/wallet_sapling.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2018 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_shieldcoinbase.py b/qa/rpc-tests/wallet_shieldcoinbase.py index befd8c5a1..4747c2c1e 100755 --- a/qa/rpc-tests/wallet_shieldcoinbase.py +++ b/qa/rpc-tests/wallet_shieldcoinbase.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2017 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/wallet_shieldcoinbase_sapling.py b/qa/rpc-tests/wallet_shieldcoinbase_sapling.py index 6ef6da873..aa5d733e1 100755 --- a/qa/rpc-tests/wallet_shieldcoinbase_sapling.py +++ b/qa/rpc-tests/wallet_shieldcoinbase_sapling.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html import inspect diff --git a/qa/rpc-tests/wallet_treestate.py b/qa/rpc-tests/wallet_treestate.py index f3374ac21..d0dc37528 100755 --- a/qa/rpc-tests/wallet_treestate.py +++ b/qa/rpc-tests/wallet_treestate.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2016 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/walletbackup.py b/qa/rpc-tests/walletbackup.py index 33aa82694..f43947869 100755 --- a/qa/rpc-tests/walletbackup.py +++ b/qa/rpc-tests/walletbackup.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/zapwallettxes.py b/qa/rpc-tests/zapwallettxes.py index fb4b84caf..e14939fd0 100755 --- a/qa/rpc-tests/zapwallettxes.py +++ b/qa/rpc-tests/zapwallettxes.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2014 The Bitcoin Core developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/rpc-tests/zkey_import_export.py b/qa/rpc-tests/zkey_import_export.py index 0fc78fd3b..b4abff512 100755 --- a/qa/rpc-tests/zkey_import_export.py +++ b/qa/rpc-tests/zkey_import_export.py @@ -1,5 +1,5 @@ #!/usr/bin/env python2 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright (c) 2017 The Zcash developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/Makefile.am b/src/Makefile.am index 6a3e3dab8..5fe0118c0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -# Copyright 2016-2021 The Hush developers +# Copyright 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include index 5f170384a..8cd1a5aba 100644 --- a/src/Makefile.gtest.include +++ b/src/Makefile.gtest.include @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 TESTS += hush-gtest bin_PROGRAMS += hush-gtest diff --git a/src/Makefile.test-hush.include b/src/Makefile.test-hush.include index 9d6379ea0..0cc4e43c1 100644 --- a/src/Makefile.test-hush.include +++ b/src/Makefile.test-hush.include @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/addressindex.h b/src/addressindex.h index 369bd1671..778295c27 100644 --- a/src/addressindex.h +++ b/src/addressindex.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2015 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/addrman.cpp b/src/addrman.cpp index 36c361f01..d9b8a07cb 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2012 Pieter Wuille -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/addrman.h b/src/addrman.h index 68419ea61..5738913d4 100644 --- a/src/addrman.h +++ b/src/addrman.h @@ -1,5 +1,5 @@ // Copyright (c) 2012 Pieter Wuille -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/alert.cpp b/src/alert.cpp index 00cb4f8e2..9560a0c87 100644 --- a/src/alert.cpp +++ b/src/alert.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/alert.h b/src/alert.h index 16c063451..f461c51c5 100644 --- a/src/alert.h +++ b/src/alert.h @@ -1,6 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/alertkeys.h b/src/alertkeys.h index 8e477e446..0de5d269e 100644 --- a/src/alertkeys.h +++ b/src/alertkeys.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/amount.cpp b/src/amount.cpp index 987bfadae..0e2d7ae33 100644 --- a/src/amount.cpp +++ b/src/amount.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/amount.h b/src/amount.h index 46fcb740d..88ba196f0 100644 --- a/src/amount.h +++ b/src/amount.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/arith_uint256.cpp b/src/arith_uint256.cpp index 6d5b92aad..da2dcd58b 100644 --- a/src/arith_uint256.cpp +++ b/src/arith_uint256.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/arith_uint256.h b/src/arith_uint256.h index c5e3e37db..9b462cb04 100644 --- a/src/arith_uint256.h +++ b/src/arith_uint256.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/assetchains_stop b/src/assetchains_stop index a44e3c403..e5ccc0fcb 100755 --- a/src/assetchains_stop +++ b/src/assetchains_stop @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers set -eo pipefail hush_cli='./hush-cli' diff --git a/src/asyncrpcoperation.cpp b/src/asyncrpcoperation.cpp index d62fdc584..c0c274901 100644 --- a/src/asyncrpcoperation.cpp +++ b/src/asyncrpcoperation.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2016 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/asyncrpcoperation.h b/src/asyncrpcoperation.h index e401ecf36..2bcf75d63 100644 --- a/src/asyncrpcoperation.h +++ b/src/asyncrpcoperation.h @@ -1,5 +1,5 @@ // Copyright (c) 2016 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/asyncrpcqueue.cpp b/src/asyncrpcqueue.cpp index a88f0c18c..c7556a4b9 100644 --- a/src/asyncrpcqueue.cpp +++ b/src/asyncrpcqueue.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2016 The Zcash developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/asyncrpcqueue.h b/src/asyncrpcqueue.h index fbe79f0f0..6369f2134 100644 --- a/src/asyncrpcqueue.h +++ b/src/asyncrpcqueue.h @@ -1,5 +1,5 @@ // Copyright (c) 2016 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/base58.cpp b/src/base58.cpp index 31233ac94..deb64ddcc 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/bech32.cpp b/src/bech32.cpp index 778761a6d..fa0562d0a 100644 --- a/src/bech32.cpp +++ b/src/bech32.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2017 Pieter Wuille -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/bech32.h b/src/bech32.h index 42b3702bd..a0fec7558 100644 --- a/src/bech32.h +++ b/src/bech32.h @@ -1,5 +1,5 @@ // Copyright (c) 2017 Pieter Wuille -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 79e7701fc..d6ac78c25 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index 9e5a2b43a..4de9f9e61 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/bloom.cpp b/src/bloom.cpp index bf96141c3..81410adda 100644 --- a/src/bloom.cpp +++ b/src/bloom.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/cc/CCGateways.h b/src/cc/CCGateways.h index 2a7b43afb..ca4adbee0 100644 --- a/src/cc/CCGateways.h +++ b/src/cc/CCGateways.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCHeir.h b/src/cc/CCHeir.h index 106ffd5af..762b37b9c 100644 --- a/src/cc/CCHeir.h +++ b/src/cc/CCHeir.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCImportGateway.h b/src/cc/CCImportGateway.h index 0aa537fe8..27aade681 100644 --- a/src/cc/CCImportGateway.h +++ b/src/cc/CCImportGateway.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCMarmara.h b/src/cc/CCMarmara.h index 3e6307ac1..67e21cc8c 100644 --- a/src/cc/CCMarmara.h +++ b/src/cc/CCMarmara.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCOracles.h b/src/cc/CCOracles.h index ad939bd5b..9f519706f 100644 --- a/src/cc/CCOracles.h +++ b/src/cc/CCOracles.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCPayments.h b/src/cc/CCPayments.h index 5fd6a1bfc..f6c556ad3 100644 --- a/src/cc/CCPayments.h +++ b/src/cc/CCPayments.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCPegs.h b/src/cc/CCPegs.h index c8b4649f4..309a4646e 100644 --- a/src/cc/CCPegs.h +++ b/src/cc/CCPegs.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCPrices.h b/src/cc/CCPrices.h index e715706b9..a1238d134 100644 --- a/src/cc/CCPrices.h +++ b/src/cc/CCPrices.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CC_made_easy.md b/src/cc/CC_made_easy.md index 79655dcbc..cd5f62577 100644 --- a/src/cc/CC_made_easy.md +++ b/src/cc/CC_made_easy.md @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * diff --git a/src/cc/CCassets.h b/src/cc/CCassets.h index 03af560e8..d2fbfb051 100644 --- a/src/cc/CCassets.h +++ b/src/cc/CCassets.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCassetsCore.cpp b/src/cc/CCassetsCore.cpp index 41d33b1af..963ff4dd0 100644 --- a/src/cc/CCassetsCore.cpp +++ b/src/cc/CCassetsCore.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCassetstx.cpp b/src/cc/CCassetstx.cpp index d9c3eb177..36eb1050d 100644 --- a/src/cc/CCassetstx.cpp +++ b/src/cc/CCassetstx.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCauction.h b/src/cc/CCauction.h index 0d459495b..dc7994810 100644 --- a/src/cc/CCauction.h +++ b/src/cc/CCauction.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCchannels.h b/src/cc/CCchannels.h index 911cf5f81..39271616e 100644 --- a/src/cc/CCchannels.h +++ b/src/cc/CCchannels.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCcustom.cpp b/src/cc/CCcustom.cpp index 3b2ad457e..4df015f5b 100644 --- a/src/cc/CCcustom.cpp +++ b/src/cc/CCcustom.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCdice.h b/src/cc/CCdice.h index 967b51907..3082d8495 100644 --- a/src/cc/CCdice.h +++ b/src/cc/CCdice.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCfaucet.h b/src/cc/CCfaucet.h index c9096eabf..7e59c1342 100644 --- a/src/cc/CCfaucet.h +++ b/src/cc/CCfaucet.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCfsm.h b/src/cc/CCfsm.h index 56e42dabf..f88ccbf0c 100644 --- a/src/cc/CCfsm.h +++ b/src/cc/CCfsm.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCinclude.h b/src/cc/CCinclude.h index f2d8e8733..3ab89bd2e 100644 --- a/src/cc/CCinclude.h +++ b/src/cc/CCinclude.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CClotto.h b/src/cc/CClotto.h index a241c2091..5c05fa42c 100644 --- a/src/cc/CClotto.h +++ b/src/cc/CClotto.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCrewards.h b/src/cc/CCrewards.h index 1511b698c..090712ba6 100644 --- a/src/cc/CCrewards.h +++ b/src/cc/CCrewards.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCtokens.cpp b/src/cc/CCtokens.cpp index e1a06b768..ed95a528e 100644 --- a/src/cc/CCtokens.cpp +++ b/src/cc/CCtokens.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCtokens.h b/src/cc/CCtokens.h index 0fc967ea6..211de2794 100644 --- a/src/cc/CCtokens.h +++ b/src/cc/CCtokens.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCtokenutils.cpp b/src/cc/CCtokenutils.cpp index 06f628ebd..201acaeea 100644 --- a/src/cc/CCtokenutils.cpp +++ b/src/cc/CCtokenutils.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCtx.cpp b/src/cc/CCtx.cpp index a36f61e16..c4b683933 100644 --- a/src/cc/CCtx.cpp +++ b/src/cc/CCtx.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCutilbits.cpp b/src/cc/CCutilbits.cpp index 1f43f884f..c74f26784 100644 --- a/src/cc/CCutilbits.cpp +++ b/src/cc/CCutilbits.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/CCutils.cpp b/src/cc/CCutils.cpp index e40698ac6..0fc5f212b 100644 --- a/src/cc/CCutils.cpp +++ b/src/cc/CCutils.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/assets.cpp b/src/cc/assets.cpp index bbf624d77..b4fdecc92 100644 --- a/src/cc/assets.cpp +++ b/src/cc/assets.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/auction.cpp b/src/cc/auction.cpp index 3f8697c7a..bdfd11f4c 100644 --- a/src/cc/auction.cpp +++ b/src/cc/auction.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/betprotocol.cpp b/src/cc/betprotocol.cpp index c6b76bb2c..d6a3cb5a8 100644 --- a/src/cc/betprotocol.cpp +++ b/src/cc/betprotocol.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/betprotocol.h b/src/cc/betprotocol.h index 5dd920aba..5bfe78ef8 100644 --- a/src/cc/betprotocol.h +++ b/src/cc/betprotocol.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/cclib.cpp b/src/cc/cclib.cpp index 30df42f3a..6046c2235 100644 --- a/src/cc/cclib.cpp +++ b/src/cc/cclib.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/channels.cpp b/src/cc/channels.cpp index 389de64d8..aeb13a311 100644 --- a/src/cc/channels.cpp +++ b/src/cc/channels.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/crypto777/OS_portable.h b/src/cc/crypto777/OS_portable.h index 892a6ad3d..52f92a383 100644 --- a/src/cc/crypto777/OS_portable.h +++ b/src/cc/crypto777/OS_portable.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * diff --git a/src/cc/customcc.cpp b/src/cc/customcc.cpp index c1b1c9028..cc4f335f0 100644 --- a/src/cc/customcc.cpp +++ b/src/cc/customcc.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/customcc.h b/src/cc/customcc.h index c88f6333d..9d5b18911 100644 --- a/src/cc/customcc.h +++ b/src/cc/customcc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/dapps/Makefile b/src/cc/dapps/Makefile index 66e10d972..22b543614 100644 --- a/src/cc/dapps/Makefile +++ b/src/cc/dapps/Makefile @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021 The Hush Developers +# Copyright (c) 2016-2022 The Hush Developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # Just type make to compile all dat dapp code, fellow cypherpunkz diff --git a/src/cc/dapps/cJSON.c b/src/cc/dapps/cJSON.c index eb38b80cc..2901f4968 100644 --- a/src/cc/dapps/cJSON.c +++ b/src/cc/dapps/cJSON.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/dapps/dappinc.h b/src/cc/dapps/dappinc.h index f81db7dd2..29639ba83 100644 --- a/src/cc/dapps/dappinc.h +++ b/src/cc/dapps/dappinc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/dapps/dappstd.c b/src/cc/dapps/dappstd.c index 67cb6b9cb..73ca6773c 100644 --- a/src/cc/dapps/dappstd.c +++ b/src/cc/dapps/dappstd.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/dapps/hushdex.c b/src/cc/dapps/hushdex.c index 8f4b89f2c..202265de4 100644 --- a/src/cc/dapps/hushdex.c +++ b/src/cc/dapps/hushdex.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/dapps/zmigrate.c b/src/cc/dapps/zmigrate.c index e8b547c6b..115dc02b0 100644 --- a/src/cc/dapps/zmigrate.c +++ b/src/cc/dapps/zmigrate.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/dice.cpp b/src/cc/dice.cpp index 67e5ff1bf..222da953a 100644 --- a/src/cc/dice.cpp +++ b/src/cc/dice.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/dilithium.c b/src/cc/dilithium.c index 4d7b0fd04..733f3716b 100644 --- a/src/cc/dilithium.c +++ b/src/cc/dilithium.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/cc/dilithium.h b/src/cc/dilithium.h index 9282dee9d..5023a6a51 100644 --- a/src/cc/dilithium.h +++ b/src/cc/dilithium.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/cc/disputepayout.cpp b/src/cc/disputepayout.cpp index 24ab02b74..23017a664 100644 --- a/src/cc/disputepayout.cpp +++ b/src/cc/disputepayout.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/eval.cpp b/src/cc/eval.cpp index c99160a3b..d3d62a4ac 100644 --- a/src/cc/eval.cpp +++ b/src/cc/eval.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/eval.h b/src/cc/eval.h index 5c6784086..1c4fb2616 100644 --- a/src/cc/eval.h +++ b/src/cc/eval.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/faucet.cpp b/src/cc/faucet.cpp index c7cf29fc4..d46920a50 100644 --- a/src/cc/faucet.cpp +++ b/src/cc/faucet.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/fsm.cpp b/src/cc/fsm.cpp index 64c71405c..2deeb1a62 100644 --- a/src/cc/fsm.cpp +++ b/src/cc/fsm.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/games/prices.c b/src/cc/games/prices.c index dc046d667..ad264f008 100644 --- a/src/cc/games/prices.c +++ b/src/cc/games/prices.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/cc/games/prices.cpp b/src/cc/games/prices.cpp index 287960830..85d84b730 100644 --- a/src/cc/games/prices.cpp +++ b/src/cc/games/prices.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/games/prices.h b/src/cc/games/prices.h index 258385651..0d4e32e49 100644 --- a/src/cc/games/prices.h +++ b/src/cc/games/prices.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/cc/games/tetris.c b/src/cc/games/tetris.c index 848e9aacc..882e8b4cf 100644 --- a/src/cc/games/tetris.c +++ b/src/cc/games/tetris.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/cc/games/tetris.h b/src/cc/games/tetris.h index 7ef7a9aec..0a9b2e3d2 100644 --- a/src/cc/games/tetris.h +++ b/src/cc/games/tetris.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/cc/gamescc.cpp b/src/cc/gamescc.cpp index 80251819f..02719d985 100644 --- a/src/cc/gamescc.cpp +++ b/src/cc/gamescc.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/gamescc.h b/src/cc/gamescc.h index 1e70b8647..04ac92861 100644 --- a/src/cc/gamescc.h +++ b/src/cc/gamescc.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #ifndef H_GAMESCC_H diff --git a/src/cc/gateways.cpp b/src/cc/gateways.cpp index 4a38c9daf..90f0e81b8 100644 --- a/src/cc/gateways.cpp +++ b/src/cc/gateways.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/heir.cpp b/src/cc/heir.cpp index c0ac21b0b..78a767bac 100644 --- a/src/cc/heir.cpp +++ b/src/cc/heir.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/heir_validate.h b/src/cc/heir_validate.h index 9e0afa0cb..b2fbec20a 100644 --- a/src/cc/heir_validate.h +++ b/src/cc/heir_validate.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #ifndef HEIR_VALIDATE_H diff --git a/src/cc/import.cpp b/src/cc/import.cpp index 61e901e84..4b0b86060 100644 --- a/src/cc/import.cpp +++ b/src/cc/import.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/importgateway.cpp b/src/cc/importgateway.cpp index 12ab0f90e..95d2b5acc 100644 --- a/src/cc/importgateway.cpp +++ b/src/cc/importgateway.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/importpayout.cpp b/src/cc/importpayout.cpp index 481e846f0..b4da2d352 100644 --- a/src/cc/importpayout.cpp +++ b/src/cc/importpayout.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/includes/cJSON.h b/src/cc/includes/cJSON.h index 47c24b8e9..4db0fc3cb 100644 --- a/src/cc/includes/cJSON.h +++ b/src/cc/includes/cJSON.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/includes/curve25519.h b/src/cc/includes/curve25519.h index f55f0b785..b8ccac1a1 100644 --- a/src/cc/includes/curve25519.h +++ b/src/cc/includes/curve25519.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/includes/libgfshare.h b/src/cc/includes/libgfshare.h index 113fd77ec..9dd21a35c 100644 --- a/src/cc/includes/libgfshare.h +++ b/src/cc/includes/libgfshare.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/includes/tweetnacl.h b/src/cc/includes/tweetnacl.h index 2539eb8d0..188cdf525 100644 --- a/src/cc/includes/tweetnacl.h +++ b/src/cc/includes/tweetnacl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #ifndef TWEETNACL_H diff --git a/src/cc/includes/uthash.h b/src/cc/includes/uthash.h index accf4edf2..edcfdfcf8 100644 --- a/src/cc/includes/uthash.h +++ b/src/cc/includes/uthash.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/cc/includes/utlist.h b/src/cc/includes/utlist.h index c4d8f900a..c9481f3a2 100644 --- a/src/cc/includes/utlist.h +++ b/src/cc/includes/utlist.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/lotto.cpp b/src/cc/lotto.cpp index 5d1ac148b..187270fa3 100644 --- a/src/cc/lotto.cpp +++ b/src/cc/lotto.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/makecclib b/src/cc/makecclib index c7815ccde..c115cd0c1 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/cc/makerogue b/src/cc/makerogue index 408b35c77..2bbcbb0cb 100755 --- a/src/cc/makerogue +++ b/src/cc/makerogue @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright 2016-2021 The Hush developers +# Copyright 2016-2022 The Hush developers cd rogue; make clean; diff --git a/src/cc/musig.cpp b/src/cc/musig.cpp index 363cca280..ef90df7ba 100644 --- a/src/cc/musig.cpp +++ b/src/cc/musig.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/oracles.cpp b/src/cc/oracles.cpp index fc3a0be41..179ad7414 100644 --- a/src/cc/oracles.cpp +++ b/src/cc/oracles.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/payments.cpp b/src/cc/payments.cpp index 4fd071fd6..886e9a2d9 100644 --- a/src/cc/payments.cpp +++ b/src/cc/payments.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/pegs.cpp b/src/cc/pegs.cpp index 47570fe05..056c9b44a 100644 --- a/src/cc/pegs.cpp +++ b/src/cc/pegs.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/prices.cpp b/src/cc/prices.cpp index a96e1ea8d..4eb1c65f3 100644 --- a/src/cc/prices.cpp +++ b/src/cc/prices.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/rewards.cpp b/src/cc/rewards.cpp index 76ce0b8dd..e48076700 100644 --- a/src/cc/rewards.cpp +++ b/src/cc/rewards.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/rogue/Makefile.in b/src/cc/rogue/Makefile.in index c215fbcb1..fa089d0ce 100644 --- a/src/cc/rogue/Makefile.in +++ b/src/cc/rogue/Makefile.in @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html ############################################################################### diff --git a/src/cc/rogue/armor.c b/src/cc/rogue/armor.c index 33bc628cc..2c74b3a90 100644 --- a/src/cc/rogue/armor.c +++ b/src/cc/rogue/armor.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/chase.c b/src/cc/rogue/chase.c index f0d6e6841..188e36b39 100644 --- a/src/cc/rogue/chase.c +++ b/src/cc/rogue/chase.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/command.c b/src/cc/rogue/command.c index dd12d2e25..678c13066 100644 --- a/src/cc/rogue/command.c +++ b/src/cc/rogue/command.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/cursesd.c b/src/cc/rogue/cursesd.c index 84ba3387f..40a9c4d5a 100644 --- a/src/cc/rogue/cursesd.c +++ b/src/cc/rogue/cursesd.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/rogue/cursesd.h b/src/cc/rogue/cursesd.h index 748e594ff..589a99361 100644 --- a/src/cc/rogue/cursesd.h +++ b/src/cc/rogue/cursesd.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/rogue/daemon.c b/src/cc/rogue/daemon.c index 20ca53e94..2a4734960 100644 --- a/src/cc/rogue/daemon.c +++ b/src/cc/rogue/daemon.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/daemons.c b/src/cc/rogue/daemons.c index 80a9e8549..11bf96f82 100644 --- a/src/cc/rogue/daemons.c +++ b/src/cc/rogue/daemons.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/extern.c b/src/cc/rogue/extern.c index bf904006b..c12a61295 100644 --- a/src/cc/rogue/extern.c +++ b/src/cc/rogue/extern.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/extern.h b/src/cc/rogue/extern.h index a0ce9dd37..ed749986b 100644 --- a/src/cc/rogue/extern.h +++ b/src/cc/rogue/extern.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/fight.c b/src/cc/rogue/fight.c index 8c8d65c3f..24f477621 100644 --- a/src/cc/rogue/fight.c +++ b/src/cc/rogue/fight.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/init.c b/src/cc/rogue/init.c index 7169ff117..4755c8e60 100644 --- a/src/cc/rogue/init.c +++ b/src/cc/rogue/init.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/io.c b/src/cc/rogue/io.c index bdb449351..0996b3e29 100644 --- a/src/cc/rogue/io.c +++ b/src/cc/rogue/io.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/list.c b/src/cc/rogue/list.c index 6f12a0795..c0e97ca41 100644 --- a/src/cc/rogue/list.c +++ b/src/cc/rogue/list.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/mach_dep.c b/src/cc/rogue/mach_dep.c index 5d12fb0ac..5d9bf07ee 100644 --- a/src/cc/rogue/mach_dep.c +++ b/src/cc/rogue/mach_dep.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index 5ded26d56..01324ec3f 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/rogue/mdport.c b/src/cc/rogue/mdport.c index d6c6b019e..caeb57946 100644 --- a/src/cc/rogue/mdport.c +++ b/src/cc/rogue/mdport.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/misc.c b/src/cc/rogue/misc.c index 0cc3b23c7..5da9ce0aa 100644 --- a/src/cc/rogue/misc.c +++ b/src/cc/rogue/misc.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/monsters.c b/src/cc/rogue/monsters.c index 433fa89ea..6485082e4 100644 --- a/src/cc/rogue/monsters.c +++ b/src/cc/rogue/monsters.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/move.c b/src/cc/rogue/move.c index e3e265119..d4107150c 100644 --- a/src/cc/rogue/move.c +++ b/src/cc/rogue/move.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/new_level.c b/src/cc/rogue/new_level.c index 47453ef92..def062547 100644 --- a/src/cc/rogue/new_level.c +++ b/src/cc/rogue/new_level.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/options.c b/src/cc/rogue/options.c index dfecdcb89..5cf0150b5 100644 --- a/src/cc/rogue/options.c +++ b/src/cc/rogue/options.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/pack.c b/src/cc/rogue/pack.c index 72ee6031c..0ad0e7420 100644 --- a/src/cc/rogue/pack.c +++ b/src/cc/rogue/pack.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/passages.c b/src/cc/rogue/passages.c index 099193269..e9aea4611 100644 --- a/src/cc/rogue/passages.c +++ b/src/cc/rogue/passages.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/potions.c b/src/cc/rogue/potions.c index 314f91916..4d952ada6 100644 --- a/src/cc/rogue/potions.c +++ b/src/cc/rogue/potions.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/rings.c b/src/cc/rogue/rings.c index 5812f9421..cb1b9f5b3 100644 --- a/src/cc/rogue/rings.c +++ b/src/cc/rogue/rings.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/rip.c b/src/cc/rogue/rip.c index 29c3e1566..43a2a42ae 100644 --- a/src/cc/rogue/rip.c +++ b/src/cc/rogue/rip.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/rogue.c b/src/cc/rogue/rogue.c index 9f135f894..54ad07f1b 100644 --- a/src/cc/rogue/rogue.c +++ b/src/cc/rogue/rogue.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/rogue.h b/src/cc/rogue/rogue.h index 94a72d636..1b3e4a070 100644 --- a/src/cc/rogue/rogue.h +++ b/src/cc/rogue/rogue.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/rogue_player.h b/src/cc/rogue/rogue_player.h index 8aa7ae755..474198b6c 100644 --- a/src/cc/rogue/rogue_player.h +++ b/src/cc/rogue/rogue_player.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cc/rogue/rooms.c b/src/cc/rogue/rooms.c index 9ad2c8cfe..a5521f516 100644 --- a/src/cc/rogue/rooms.c +++ b/src/cc/rogue/rooms.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/save.c b/src/cc/rogue/save.c index ab01d49c5..3d09bb0c4 100644 --- a/src/cc/rogue/save.c +++ b/src/cc/rogue/save.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/score.h b/src/cc/rogue/score.h index 4905e8a5e..c97b27cf3 100644 --- a/src/cc/rogue/score.h +++ b/src/cc/rogue/score.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/scrolls.c b/src/cc/rogue/scrolls.c index 7fe34a05c..6153aad5d 100644 --- a/src/cc/rogue/scrolls.c +++ b/src/cc/rogue/scrolls.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/state.c b/src/cc/rogue/state.c index cf140dc19..08a6d469f 100644 --- a/src/cc/rogue/state.c +++ b/src/cc/rogue/state.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/sticks.c b/src/cc/rogue/sticks.c index 8dc119b3d..416adc423 100644 --- a/src/cc/rogue/sticks.c +++ b/src/cc/rogue/sticks.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/things.c b/src/cc/rogue/things.c index fc076b112..3ef9e889e 100644 --- a/src/cc/rogue/things.c +++ b/src/cc/rogue/things.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/vers.c b/src/cc/rogue/vers.c index d733e9e81..7973d231b 100644 --- a/src/cc/rogue/vers.c +++ b/src/cc/rogue/vers.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/weapons.c b/src/cc/rogue/weapons.c index 2df9faf65..a2c36a406 100644 --- a/src/cc/rogue/weapons.c +++ b/src/cc/rogue/weapons.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/wizard.c b/src/cc/rogue/wizard.c index d36e8a3b3..ee28bb1d5 100644 --- a/src/cc/rogue/wizard.c +++ b/src/cc/rogue/wizard.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue/xcrypt.c b/src/cc/rogue/xcrypt.c index 9a2b7fd39..c5d9f1bad 100644 --- a/src/cc/rogue/xcrypt.c +++ b/src/cc/rogue/xcrypt.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cc/rogue_rpc.cpp b/src/cc/rogue_rpc.cpp index b1fd8635d..22b154b0d 100644 --- a/src/cc/rogue_rpc.cpp +++ b/src/cc/rogue_rpc.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/cc/sudoku.cpp b/src/cc/sudoku.cpp index 4feda6701..d887cd6c4 100644 --- a/src/cc/sudoku.cpp +++ b/src/cc/sudoku.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html // From https://github.com/attractivechaos/plb/blob/master/sudoku/incoming/sudoku_solver.c diff --git a/src/cc/utils.h b/src/cc/utils.h index 5422b92a3..5d2bc2cba 100644 --- a/src/cc/utils.h +++ b/src/cc/utils.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/chain.cpp b/src/chain.cpp index d2b7382d9..e04bc1736 100644 --- a/src/chain.cpp +++ b/src/chain.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/chain.h b/src/chain.h index 3162f6634..2e49e64c4 100644 --- a/src/chain.h +++ b/src/chain.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/chainparams.cpp b/src/chainparams.cpp index fe1470556..6f44af2da 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html ///////////////////////////////////////////////////////////////////////////////// diff --git a/src/chainparams.h b/src/chainparams.h index 350aeb4de..9e2707b31 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp index 1f0eb7740..4244e7f53 100644 --- a/src/chainparamsbase.cpp +++ b/src/chainparamsbase.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/checkpoints.cpp b/src/checkpoints.cpp index 9a0b7a67d..c9ac9b783 100644 --- a/src/checkpoints.cpp +++ b/src/checkpoints.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/checkpoints.h b/src/checkpoints.h index 8a6cbb015..75462e1d1 100644 --- a/src/checkpoints.h +++ b/src/checkpoints.h @@ -1,5 +1,5 @@ // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/checkqueue.h b/src/checkqueue.h index 9cbf25cf2..bea5ed1bb 100644 --- a/src/checkqueue.h +++ b/src/checkqueue.h @@ -1,5 +1,5 @@ // Copyright (c) 2012-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/clientversion.cpp b/src/clientversion.cpp index cd6126eb1..49af10dda 100644 --- a/src/clientversion.cpp +++ b/src/clientversion.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2012-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/clientversion.h b/src/clientversion.h index 461c4c197..bc2ab199f 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2014 The Bitcoin Core developers // Copyright (c) 2016-2017 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html // What happened to the SuperNET developers, who cared about privacy? diff --git a/src/coincontrol.h b/src/coincontrol.h index 3f8d0539d..e7dfbf13d 100644 --- a/src/coincontrol.h +++ b/src/coincontrol.h @@ -1,5 +1,5 @@ // Copyright (c) 2011-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/coins.cpp b/src/coins.cpp index 0c3af3863..57e692444 100644 --- a/src/coins.cpp +++ b/src/coins.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2012-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/coins.h b/src/coins.h index 282fe816c..c9cae350b 100644 --- a/src/coins.h +++ b/src/coins.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/compressor.cpp b/src/compressor.cpp index b55313486..b3f06e47e 100644 --- a/src/compressor.cpp +++ b/src/compressor.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/consensus/params.h b/src/consensus/params.h index f3484e6e9..3a6e2cceb 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/consensus/upgrades.cpp b/src/consensus/upgrades.cpp index a24e74658..9be24c20b 100644 --- a/src/consensus/upgrades.cpp +++ b/src/consensus/upgrades.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2018 The Zcash developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/core_memusage.h b/src/core_memusage.h index 9e680cbe4..636bbf79f 100644 --- a/src/core_memusage.h +++ b/src/core_memusage.h @@ -1,5 +1,5 @@ // Copyright (c) 2015 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/core_read.cpp b/src/core_read.cpp index d092f6624..3e01a37e3 100644 --- a/src/core_read.cpp +++ b/src/core_read.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/core_write.cpp b/src/core_write.cpp index 67953e2fa..8b890db21 100644 --- a/src/core_write.cpp +++ b/src/core_write.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/crosschain.cpp b/src/crosschain.cpp index 7968b7292..68c5ce23d 100644 --- a/src/crosschain.cpp +++ b/src/crosschain.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/crosschain.h b/src/crosschain.h index f20a1c6f1..4d085166e 100644 --- a/src/crosschain.h +++ b/src/crosschain.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/crosschain_authority.cpp b/src/crosschain_authority.cpp index 2a63998a1..d3c1ff6e1 100644 --- a/src/crosschain_authority.cpp +++ b/src/crosschain_authority.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "cc/eval.h" diff --git a/src/crypto/common.h b/src/crypto/common.h index e299f4098..d07ff0730 100644 --- a/src/crypto/common.h +++ b/src/crypto/common.h @@ -1,5 +1,5 @@ // Copyright (c) 2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Released under the GPLv3 // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/crypto/equihash.h b/src/crypto/equihash.h index 968fbdd79..23530cc61 100644 --- a/src/crypto/equihash.h +++ b/src/crypto/equihash.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2016 Jack Grigg // Copyright (c) 2016 The Zcash developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/cryptoconditions/AUTHORS b/src/cryptoconditions/AUTHORS index bf0bcc88b..3baf5f36e 100644 --- a/src/cryptoconditions/AUTHORS +++ b/src/cryptoconditions/AUTHORS @@ -4,6 +4,6 @@ Copyright 2017 Scott Sadler # Current Authors -Copyright (c) 2016-2021 The Hush Developers +Copyright (c) 2016-2022 The Hush Developers Relicensed to GPLv3 on Nov 21st 2020. diff --git a/src/cryptoconditions/src/anon.c b/src/cryptoconditions/src/anon.c index 57c5cac45..3ec319cde 100644 --- a/src/cryptoconditions/src/anon.c +++ b/src/cryptoconditions/src/anon.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * diff --git a/src/cryptoconditions/src/asn/BIT_STRING.c b/src/cryptoconditions/src/asn/BIT_STRING.c index 6db8df17c..89df2aebf 100644 --- a/src/cryptoconditions/src/asn/BIT_STRING.c +++ b/src/cryptoconditions/src/asn/BIT_STRING.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/BIT_STRING.h b/src/cryptoconditions/src/asn/BIT_STRING.h index 6ce2b9091..415dc9475 100644 --- a/src/cryptoconditions/src/asn/BIT_STRING.h +++ b/src/cryptoconditions/src/asn/BIT_STRING.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/CompoundSha256Condition.c b/src/cryptoconditions/src/asn/CompoundSha256Condition.c index a14b50a5b..a6670a69f 100644 --- a/src/cryptoconditions/src/asn/CompoundSha256Condition.c +++ b/src/cryptoconditions/src/asn/CompoundSha256Condition.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/CompoundSha256Condition.h b/src/cryptoconditions/src/asn/CompoundSha256Condition.h index b8604c113..c80c38e63 100644 --- a/src/cryptoconditions/src/asn/CompoundSha256Condition.h +++ b/src/cryptoconditions/src/asn/CompoundSha256Condition.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/Condition.c b/src/cryptoconditions/src/asn/Condition.c index d48d14433..022d40199 100644 --- a/src/cryptoconditions/src/asn/Condition.c +++ b/src/cryptoconditions/src/asn/Condition.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/Condition.h b/src/cryptoconditions/src/asn/Condition.h index a67d6f617..f89f3691e 100644 --- a/src/cryptoconditions/src/asn/Condition.h +++ b/src/cryptoconditions/src/asn/Condition.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/ConditionTypes.c b/src/cryptoconditions/src/asn/ConditionTypes.c index 28368b87c..8bde4c5ff 100644 --- a/src/cryptoconditions/src/asn/ConditionTypes.c +++ b/src/cryptoconditions/src/asn/ConditionTypes.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/ConditionTypes.h b/src/cryptoconditions/src/asn/ConditionTypes.h index 4ef2a745c..a517a835e 100644 --- a/src/cryptoconditions/src/asn/ConditionTypes.h +++ b/src/cryptoconditions/src/asn/ConditionTypes.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/Ed25519FingerprintContents.c b/src/cryptoconditions/src/asn/Ed25519FingerprintContents.c index 52fc23f72..7f84b2d59 100644 --- a/src/cryptoconditions/src/asn/Ed25519FingerprintContents.c +++ b/src/cryptoconditions/src/asn/Ed25519FingerprintContents.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/Ed25519FingerprintContents.h b/src/cryptoconditions/src/asn/Ed25519FingerprintContents.h index fbebcbd69..7030f86cf 100644 --- a/src/cryptoconditions/src/asn/Ed25519FingerprintContents.h +++ b/src/cryptoconditions/src/asn/Ed25519FingerprintContents.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/Ed25519Sha512Fulfillment.c b/src/cryptoconditions/src/asn/Ed25519Sha512Fulfillment.c index 24c74e786..f95636c4b 100644 --- a/src/cryptoconditions/src/asn/Ed25519Sha512Fulfillment.c +++ b/src/cryptoconditions/src/asn/Ed25519Sha512Fulfillment.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/Ed25519Sha512Fulfillment.h b/src/cryptoconditions/src/asn/Ed25519Sha512Fulfillment.h index cf41cadc0..739467750 100644 --- a/src/cryptoconditions/src/asn/Ed25519Sha512Fulfillment.h +++ b/src/cryptoconditions/src/asn/Ed25519Sha512Fulfillment.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/EvalFulfillment.c b/src/cryptoconditions/src/asn/EvalFulfillment.c index c020697be..06453f83a 100644 --- a/src/cryptoconditions/src/asn/EvalFulfillment.c +++ b/src/cryptoconditions/src/asn/EvalFulfillment.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/EvalFulfillment.h b/src/cryptoconditions/src/asn/EvalFulfillment.h index 3c7e0f7de..b09f0b1cc 100644 --- a/src/cryptoconditions/src/asn/EvalFulfillment.h +++ b/src/cryptoconditions/src/asn/EvalFulfillment.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/Fulfillment.c b/src/cryptoconditions/src/asn/Fulfillment.c index d0fb00481..428372bcf 100644 --- a/src/cryptoconditions/src/asn/Fulfillment.c +++ b/src/cryptoconditions/src/asn/Fulfillment.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/Fulfillment.h b/src/cryptoconditions/src/asn/Fulfillment.h index 7df390cb8..5d409f46d 100644 --- a/src/cryptoconditions/src/asn/Fulfillment.h +++ b/src/cryptoconditions/src/asn/Fulfillment.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/INTEGER.c b/src/cryptoconditions/src/asn/INTEGER.c index 8e4da42ee..b3b1b7434 100644 --- a/src/cryptoconditions/src/asn/INTEGER.c +++ b/src/cryptoconditions/src/asn/INTEGER.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/INTEGER.h b/src/cryptoconditions/src/asn/INTEGER.h index a0affd22c..e8d56f155 100644 --- a/src/cryptoconditions/src/asn/INTEGER.h +++ b/src/cryptoconditions/src/asn/INTEGER.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/NativeEnumerated.c b/src/cryptoconditions/src/asn/NativeEnumerated.c index 9e8402ab0..4f71048d2 100644 --- a/src/cryptoconditions/src/asn/NativeEnumerated.c +++ b/src/cryptoconditions/src/asn/NativeEnumerated.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/NativeEnumerated.h b/src/cryptoconditions/src/asn/NativeEnumerated.h index aa7106a74..036fe1f7a 100644 --- a/src/cryptoconditions/src/asn/NativeEnumerated.h +++ b/src/cryptoconditions/src/asn/NativeEnumerated.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/NativeInteger.c b/src/cryptoconditions/src/asn/NativeInteger.c index c856754ff..16a23aa64 100644 --- a/src/cryptoconditions/src/asn/NativeInteger.c +++ b/src/cryptoconditions/src/asn/NativeInteger.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/NativeInteger.h b/src/cryptoconditions/src/asn/NativeInteger.h index 2eff4adbd..76d9d16b3 100644 --- a/src/cryptoconditions/src/asn/NativeInteger.h +++ b/src/cryptoconditions/src/asn/NativeInteger.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/OCTET_STRING.c b/src/cryptoconditions/src/asn/OCTET_STRING.c index 1ef107d85..c7d818352 100644 --- a/src/cryptoconditions/src/asn/OCTET_STRING.c +++ b/src/cryptoconditions/src/asn/OCTET_STRING.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/OCTET_STRING.h b/src/cryptoconditions/src/asn/OCTET_STRING.h index 41f024dac..d0a080877 100644 --- a/src/cryptoconditions/src/asn/OCTET_STRING.h +++ b/src/cryptoconditions/src/asn/OCTET_STRING.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/PrefixFingerprintContents.c b/src/cryptoconditions/src/asn/PrefixFingerprintContents.c index 43717477f..4c6171fcd 100644 --- a/src/cryptoconditions/src/asn/PrefixFingerprintContents.c +++ b/src/cryptoconditions/src/asn/PrefixFingerprintContents.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/PrefixFingerprintContents.h b/src/cryptoconditions/src/asn/PrefixFingerprintContents.h index 4e2993220..aa9b79a01 100644 --- a/src/cryptoconditions/src/asn/PrefixFingerprintContents.h +++ b/src/cryptoconditions/src/asn/PrefixFingerprintContents.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/PrefixFulfillment.c b/src/cryptoconditions/src/asn/PrefixFulfillment.c index 8e196e0a8..51d8e7a74 100644 --- a/src/cryptoconditions/src/asn/PrefixFulfillment.c +++ b/src/cryptoconditions/src/asn/PrefixFulfillment.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/PrefixFulfillment.h b/src/cryptoconditions/src/asn/PrefixFulfillment.h index 2452db17c..b6c6f410f 100644 --- a/src/cryptoconditions/src/asn/PrefixFulfillment.h +++ b/src/cryptoconditions/src/asn/PrefixFulfillment.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/PreimageFulfillment.c b/src/cryptoconditions/src/asn/PreimageFulfillment.c index b1b18bcd3..c98df0ed1 100644 --- a/src/cryptoconditions/src/asn/PreimageFulfillment.c +++ b/src/cryptoconditions/src/asn/PreimageFulfillment.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/PreimageFulfillment.h b/src/cryptoconditions/src/asn/PreimageFulfillment.h index 8a46bef28..8329b47df 100644 --- a/src/cryptoconditions/src/asn/PreimageFulfillment.h +++ b/src/cryptoconditions/src/asn/PreimageFulfillment.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/RsaFingerprintContents.c b/src/cryptoconditions/src/asn/RsaFingerprintContents.c index 2a7e9a83a..a21b33069 100644 --- a/src/cryptoconditions/src/asn/RsaFingerprintContents.c +++ b/src/cryptoconditions/src/asn/RsaFingerprintContents.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/RsaFingerprintContents.h b/src/cryptoconditions/src/asn/RsaFingerprintContents.h index 456555c30..095ebd4ce 100644 --- a/src/cryptoconditions/src/asn/RsaFingerprintContents.h +++ b/src/cryptoconditions/src/asn/RsaFingerprintContents.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/RsaSha256Fulfillment.c b/src/cryptoconditions/src/asn/RsaSha256Fulfillment.c index d2a88e72c..52d58d1fa 100644 --- a/src/cryptoconditions/src/asn/RsaSha256Fulfillment.c +++ b/src/cryptoconditions/src/asn/RsaSha256Fulfillment.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/RsaSha256Fulfillment.h b/src/cryptoconditions/src/asn/RsaSha256Fulfillment.h index cd1d51be8..64a78cbf2 100644 --- a/src/cryptoconditions/src/asn/RsaSha256Fulfillment.h +++ b/src/cryptoconditions/src/asn/RsaSha256Fulfillment.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/Secp256k1FingerprintContents.c b/src/cryptoconditions/src/asn/Secp256k1FingerprintContents.c index 4d04257b1..b7ea1b971 100644 --- a/src/cryptoconditions/src/asn/Secp256k1FingerprintContents.c +++ b/src/cryptoconditions/src/asn/Secp256k1FingerprintContents.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/Secp256k1FingerprintContents.h b/src/cryptoconditions/src/asn/Secp256k1FingerprintContents.h index 716dbb754..7fbadb386 100644 --- a/src/cryptoconditions/src/asn/Secp256k1FingerprintContents.h +++ b/src/cryptoconditions/src/asn/Secp256k1FingerprintContents.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/Secp256k1Fulfillment.c b/src/cryptoconditions/src/asn/Secp256k1Fulfillment.c index 6980e62b4..53689d049 100644 --- a/src/cryptoconditions/src/asn/Secp256k1Fulfillment.c +++ b/src/cryptoconditions/src/asn/Secp256k1Fulfillment.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/Secp256k1Fulfillment.h b/src/cryptoconditions/src/asn/Secp256k1Fulfillment.h index 398820556..a672a55d6 100644 --- a/src/cryptoconditions/src/asn/Secp256k1Fulfillment.h +++ b/src/cryptoconditions/src/asn/Secp256k1Fulfillment.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/SimpleSha256Condition.c b/src/cryptoconditions/src/asn/SimpleSha256Condition.c index aaaaa5e69..0633348fc 100644 --- a/src/cryptoconditions/src/asn/SimpleSha256Condition.c +++ b/src/cryptoconditions/src/asn/SimpleSha256Condition.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/SimpleSha256Condition.h b/src/cryptoconditions/src/asn/SimpleSha256Condition.h index 8dc40fec8..3e883d5d3 100644 --- a/src/cryptoconditions/src/asn/SimpleSha256Condition.h +++ b/src/cryptoconditions/src/asn/SimpleSha256Condition.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/ThresholdFingerprintContents.c b/src/cryptoconditions/src/asn/ThresholdFingerprintContents.c index e42b6b4d0..38248ccfc 100644 --- a/src/cryptoconditions/src/asn/ThresholdFingerprintContents.c +++ b/src/cryptoconditions/src/asn/ThresholdFingerprintContents.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/ThresholdFingerprintContents.h b/src/cryptoconditions/src/asn/ThresholdFingerprintContents.h index 77fdd272b..fcaf3c032 100644 --- a/src/cryptoconditions/src/asn/ThresholdFingerprintContents.h +++ b/src/cryptoconditions/src/asn/ThresholdFingerprintContents.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/ThresholdFulfillment.c b/src/cryptoconditions/src/asn/ThresholdFulfillment.c index c060fd38a..ef8aa26fa 100644 --- a/src/cryptoconditions/src/asn/ThresholdFulfillment.c +++ b/src/cryptoconditions/src/asn/ThresholdFulfillment.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/ThresholdFulfillment.h b/src/cryptoconditions/src/asn/ThresholdFulfillment.h index 2bc145aef..1c2a38a3c 100644 --- a/src/cryptoconditions/src/asn/ThresholdFulfillment.h +++ b/src/cryptoconditions/src/asn/ThresholdFulfillment.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/asn_SET_OF.c b/src/cryptoconditions/src/asn/asn_SET_OF.c index cc2bd5c1a..8223117e3 100644 --- a/src/cryptoconditions/src/asn/asn_SET_OF.c +++ b/src/cryptoconditions/src/asn/asn_SET_OF.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/asn_SET_OF.h b/src/cryptoconditions/src/asn/asn_SET_OF.h index 1beb19090..7346d4d59 100644 --- a/src/cryptoconditions/src/asn/asn_SET_OF.h +++ b/src/cryptoconditions/src/asn/asn_SET_OF.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/asn_application.h b/src/cryptoconditions/src/asn/asn_application.h index 2e03c0973..1fc5994bd 100644 --- a/src/cryptoconditions/src/asn/asn_application.h +++ b/src/cryptoconditions/src/asn/asn_application.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/asn_codecs.h b/src/cryptoconditions/src/asn/asn_codecs.h index 22fe3a130..2194160de 100644 --- a/src/cryptoconditions/src/asn/asn_codecs.h +++ b/src/cryptoconditions/src/asn/asn_codecs.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/asn_codecs_prim.c b/src/cryptoconditions/src/asn/asn_codecs_prim.c index 0cecf9201..9cbce8a52 100644 --- a/src/cryptoconditions/src/asn/asn_codecs_prim.c +++ b/src/cryptoconditions/src/asn/asn_codecs_prim.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/asn_codecs_prim.h b/src/cryptoconditions/src/asn/asn_codecs_prim.h index 853e9ded6..45c4368af 100644 --- a/src/cryptoconditions/src/asn/asn_codecs_prim.h +++ b/src/cryptoconditions/src/asn/asn_codecs_prim.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/asn_internal.h b/src/cryptoconditions/src/asn/asn_internal.h index f5996bbed..7e864792f 100644 --- a/src/cryptoconditions/src/asn/asn_internal.h +++ b/src/cryptoconditions/src/asn/asn_internal.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/asn_system.h b/src/cryptoconditions/src/asn/asn_system.h index 1190cc94a..0f8e85652 100644 --- a/src/cryptoconditions/src/asn/asn_system.h +++ b/src/cryptoconditions/src/asn/asn_system.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/ber_decoder.c b/src/cryptoconditions/src/asn/ber_decoder.c index 693df71f3..e1aa1cd73 100644 --- a/src/cryptoconditions/src/asn/ber_decoder.c +++ b/src/cryptoconditions/src/asn/ber_decoder.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/ber_decoder.h b/src/cryptoconditions/src/asn/ber_decoder.h index ecffc78bf..94c27b5d5 100644 --- a/src/cryptoconditions/src/asn/ber_decoder.h +++ b/src/cryptoconditions/src/asn/ber_decoder.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/ber_tlv_length.c b/src/cryptoconditions/src/asn/ber_tlv_length.c index 880d4f106..79c723421 100644 --- a/src/cryptoconditions/src/asn/ber_tlv_length.c +++ b/src/cryptoconditions/src/asn/ber_tlv_length.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/ber_tlv_length.h b/src/cryptoconditions/src/asn/ber_tlv_length.h index db678bd0d..1f09d0dde 100644 --- a/src/cryptoconditions/src/asn/ber_tlv_length.h +++ b/src/cryptoconditions/src/asn/ber_tlv_length.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/ber_tlv_tag.c b/src/cryptoconditions/src/asn/ber_tlv_tag.c index e0c5729e9..a0e7f8c08 100644 --- a/src/cryptoconditions/src/asn/ber_tlv_tag.c +++ b/src/cryptoconditions/src/asn/ber_tlv_tag.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/ber_tlv_tag.h b/src/cryptoconditions/src/asn/ber_tlv_tag.h index 649ff07ae..47ffa5772 100644 --- a/src/cryptoconditions/src/asn/ber_tlv_tag.h +++ b/src/cryptoconditions/src/asn/ber_tlv_tag.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/constr_CHOICE.c b/src/cryptoconditions/src/asn/constr_CHOICE.c index 100b50273..73094b0bf 100644 --- a/src/cryptoconditions/src/asn/constr_CHOICE.c +++ b/src/cryptoconditions/src/asn/constr_CHOICE.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/constr_CHOICE.h b/src/cryptoconditions/src/asn/constr_CHOICE.h index a397c82e5..ec2e6a506 100644 --- a/src/cryptoconditions/src/asn/constr_CHOICE.h +++ b/src/cryptoconditions/src/asn/constr_CHOICE.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/constr_SEQUENCE.c b/src/cryptoconditions/src/asn/constr_SEQUENCE.c index dbe4585d6..696dc0220 100644 --- a/src/cryptoconditions/src/asn/constr_SEQUENCE.c +++ b/src/cryptoconditions/src/asn/constr_SEQUENCE.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/constr_SEQUENCE.h b/src/cryptoconditions/src/asn/constr_SEQUENCE.h index 170a2e65c..11a55a4f1 100644 --- a/src/cryptoconditions/src/asn/constr_SEQUENCE.h +++ b/src/cryptoconditions/src/asn/constr_SEQUENCE.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/constr_SET_OF.c b/src/cryptoconditions/src/asn/constr_SET_OF.c index acb570453..84196dc0e 100644 --- a/src/cryptoconditions/src/asn/constr_SET_OF.c +++ b/src/cryptoconditions/src/asn/constr_SET_OF.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/constr_SET_OF.h b/src/cryptoconditions/src/asn/constr_SET_OF.h index e3f5903fb..184ce08fc 100644 --- a/src/cryptoconditions/src/asn/constr_SET_OF.h +++ b/src/cryptoconditions/src/asn/constr_SET_OF.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/constr_TYPE.c b/src/cryptoconditions/src/asn/constr_TYPE.c index 2f20284d7..09c5e22da 100644 --- a/src/cryptoconditions/src/asn/constr_TYPE.c +++ b/src/cryptoconditions/src/asn/constr_TYPE.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/constr_TYPE.h b/src/cryptoconditions/src/asn/constr_TYPE.h index cb170366b..6a4a4c793 100644 --- a/src/cryptoconditions/src/asn/constr_TYPE.h +++ b/src/cryptoconditions/src/asn/constr_TYPE.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/constraints.c b/src/cryptoconditions/src/asn/constraints.c index 423c98de4..9156af35f 100644 --- a/src/cryptoconditions/src/asn/constraints.c +++ b/src/cryptoconditions/src/asn/constraints.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "asn_internal.h" diff --git a/src/cryptoconditions/src/asn/constraints.h b/src/cryptoconditions/src/asn/constraints.h index 081ad0664..071a33f40 100644 --- a/src/cryptoconditions/src/asn/constraints.h +++ b/src/cryptoconditions/src/asn/constraints.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/der_encoder.c b/src/cryptoconditions/src/asn/der_encoder.c index 88cefa9eb..5b8aff86e 100644 --- a/src/cryptoconditions/src/asn/der_encoder.c +++ b/src/cryptoconditions/src/asn/der_encoder.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/der_encoder.h b/src/cryptoconditions/src/asn/der_encoder.h index e16d2d153..21c0021e0 100644 --- a/src/cryptoconditions/src/asn/der_encoder.h +++ b/src/cryptoconditions/src/asn/der_encoder.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/per_decoder.c b/src/cryptoconditions/src/asn/per_decoder.c index 39615d05b..25d078149 100644 --- a/src/cryptoconditions/src/asn/per_decoder.c +++ b/src/cryptoconditions/src/asn/per_decoder.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "asn_application.h" diff --git a/src/cryptoconditions/src/asn/per_decoder.h b/src/cryptoconditions/src/asn/per_decoder.h index 3d13859d7..d3a038a4a 100644 --- a/src/cryptoconditions/src/asn/per_decoder.h +++ b/src/cryptoconditions/src/asn/per_decoder.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/per_encoder.c b/src/cryptoconditions/src/asn/per_encoder.c index d0ff9139b..063a0be06 100644 --- a/src/cryptoconditions/src/asn/per_encoder.c +++ b/src/cryptoconditions/src/asn/per_encoder.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "asn_application.h" diff --git a/src/cryptoconditions/src/asn/per_encoder.h b/src/cryptoconditions/src/asn/per_encoder.h index da255b556..c9b451c70 100644 --- a/src/cryptoconditions/src/asn/per_encoder.h +++ b/src/cryptoconditions/src/asn/per_encoder.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/per_opentype.c b/src/cryptoconditions/src/asn/per_opentype.c index 7f7ee61d9..573667e74 100644 --- a/src/cryptoconditions/src/asn/per_opentype.c +++ b/src/cryptoconditions/src/asn/per_opentype.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/per_opentype.h b/src/cryptoconditions/src/asn/per_opentype.h index 43b16552f..f0b998784 100644 --- a/src/cryptoconditions/src/asn/per_opentype.h +++ b/src/cryptoconditions/src/asn/per_opentype.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/per_support.c b/src/cryptoconditions/src/asn/per_support.c index ad898484d..39fb38b5e 100644 --- a/src/cryptoconditions/src/asn/per_support.c +++ b/src/cryptoconditions/src/asn/per_support.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/per_support.h b/src/cryptoconditions/src/asn/per_support.h index 75a72744f..cdb064a5a 100644 --- a/src/cryptoconditions/src/asn/per_support.h +++ b/src/cryptoconditions/src/asn/per_support.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/xer_decoder.c b/src/cryptoconditions/src/asn/xer_decoder.c index 585ad847c..a09e1b7d1 100644 --- a/src/cryptoconditions/src/asn/xer_decoder.c +++ b/src/cryptoconditions/src/asn/xer_decoder.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/xer_decoder.h b/src/cryptoconditions/src/asn/xer_decoder.h index 2893e323e..6ee5fb61a 100644 --- a/src/cryptoconditions/src/asn/xer_decoder.h +++ b/src/cryptoconditions/src/asn/xer_decoder.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/xer_encoder.c b/src/cryptoconditions/src/asn/xer_encoder.c index c187de5b3..26c9c92da 100644 --- a/src/cryptoconditions/src/asn/xer_encoder.c +++ b/src/cryptoconditions/src/asn/xer_encoder.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/xer_encoder.h b/src/cryptoconditions/src/asn/xer_encoder.h index 470808a1c..fb58a37d6 100644 --- a/src/cryptoconditions/src/asn/xer_encoder.h +++ b/src/cryptoconditions/src/asn/xer_encoder.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/asn/xer_support.c b/src/cryptoconditions/src/asn/xer_support.c index 0826eed81..85c6e320f 100644 --- a/src/cryptoconditions/src/asn/xer_support.c +++ b/src/cryptoconditions/src/asn/xer_support.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/asn/xer_support.h b/src/cryptoconditions/src/asn/xer_support.h index 91657bf43..b041f3310 100644 --- a/src/cryptoconditions/src/asn/xer_support.h +++ b/src/cryptoconditions/src/asn/xer_support.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/cryptoconditions.c b/src/cryptoconditions/src/cryptoconditions.c index e891fca30..a6b2d9156 100644 --- a/src/cryptoconditions/src/cryptoconditions.c +++ b/src/cryptoconditions/src/cryptoconditions.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cryptoconditions/src/ed25519.c b/src/cryptoconditions/src/ed25519.c index 9ec8f591b..604c07c02 100644 --- a/src/cryptoconditions/src/ed25519.c +++ b/src/cryptoconditions/src/ed25519.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cryptoconditions/src/eval.c b/src/cryptoconditions/src/eval.c index d32e380ba..3b33110f7 100644 --- a/src/cryptoconditions/src/eval.c +++ b/src/cryptoconditions/src/eval.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cryptoconditions/src/include/cJSON.c b/src/cryptoconditions/src/include/cJSON.c index 19d4a3607..3a4c6f7d3 100644 --- a/src/cryptoconditions/src/include/cJSON.c +++ b/src/cryptoconditions/src/include/cJSON.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/include/cJSON.h b/src/cryptoconditions/src/include/cJSON.h index 492d61e36..8b643f561 100644 --- a/src/cryptoconditions/src/include/cJSON.h +++ b/src/cryptoconditions/src/include/cJSON.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/cryptoconditions/src/include/libbase58.h b/src/cryptoconditions/src/include/libbase58.h index 91ce97465..87b546e5e 100644 --- a/src/cryptoconditions/src/include/libbase58.h +++ b/src/cryptoconditions/src/include/libbase58.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cryptoconditions/src/include/sha256.c b/src/cryptoconditions/src/include/sha256.c index ce23e0814..743ac3420 100644 --- a/src/cryptoconditions/src/include/sha256.c +++ b/src/cryptoconditions/src/include/sha256.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/include/sha256.h b/src/cryptoconditions/src/include/sha256.h index 7c952b0ea..594127427 100644 --- a/src/cryptoconditions/src/include/sha256.h +++ b/src/cryptoconditions/src/include/sha256.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /*- diff --git a/src/cryptoconditions/src/include/tweetnacl.c b/src/cryptoconditions/src/include/tweetnacl.c index d07f81066..5bc6fb071 100644 --- a/src/cryptoconditions/src/include/tweetnacl.c +++ b/src/cryptoconditions/src/include/tweetnacl.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "tweetnacl.h" diff --git a/src/cryptoconditions/src/include/tweetnacl.h b/src/cryptoconditions/src/include/tweetnacl.h index 89a7de1d5..80c7d833e 100644 --- a/src/cryptoconditions/src/include/tweetnacl.h +++ b/src/cryptoconditions/src/include/tweetnacl.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #ifndef TWEETNACL_H diff --git a/src/cryptoconditions/src/internal.h b/src/cryptoconditions/src/internal.h index e7950c2ea..f84a2ec09 100644 --- a/src/cryptoconditions/src/internal.h +++ b/src/cryptoconditions/src/internal.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * diff --git a/src/cryptoconditions/src/json_rpc.c b/src/cryptoconditions/src/json_rpc.c index 1ab57d0cc..42be07b5a 100644 --- a/src/cryptoconditions/src/json_rpc.c +++ b/src/cryptoconditions/src/json_rpc.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cryptoconditions/src/prefix.c b/src/cryptoconditions/src/prefix.c index fc784dca5..e639a6cc9 100644 --- a/src/cryptoconditions/src/prefix.c +++ b/src/cryptoconditions/src/prefix.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cryptoconditions/src/preimage.c b/src/cryptoconditions/src/preimage.c index 765677902..4518f2402 100644 --- a/src/cryptoconditions/src/preimage.c +++ b/src/cryptoconditions/src/preimage.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cryptoconditions/src/secp256k1.c b/src/cryptoconditions/src/secp256k1.c index af46ad5dc..ffcca123c 100644 --- a/src/cryptoconditions/src/secp256k1.c +++ b/src/cryptoconditions/src/secp256k1.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cryptoconditions/src/threshold.c b/src/cryptoconditions/src/threshold.c index 323066e54..28fcaa6ed 100644 --- a/src/cryptoconditions/src/threshold.c +++ b/src/cryptoconditions/src/threshold.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/cryptoconditions/src/utils.c b/src/cryptoconditions/src/utils.c index 39b8d0566..69e5a8b7c 100644 --- a/src/cryptoconditions/src/utils.c +++ b/src/cryptoconditions/src/utils.c @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/dbwrapper.cpp b/src/dbwrapper.cpp index c4ee678e9..1d62f1a01 100644 --- a/src/dbwrapper.cpp +++ b/src/dbwrapper.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2012-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/dbwrapper.h b/src/dbwrapper.h index 113bc0b41..3a1813caf 100644 --- a/src/dbwrapper.h +++ b/src/dbwrapper.h @@ -1,5 +1,5 @@ // Copyright (c) 2012-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/deprecation.cpp b/src/deprecation.cpp index bdbda95cf..3c68fc07e 100644 --- a/src/deprecation.cpp +++ b/src/deprecation.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2017 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/deprecation.h b/src/deprecation.h index b98cf3ec6..c9c765e98 100644 --- a/src/deprecation.h +++ b/src/deprecation.h @@ -1,5 +1,5 @@ // Copyright (c) 2017 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/fs.cpp b/src/fs.cpp index 0c6a60014..baef9c2e2 100644 --- a/src/fs.cpp +++ b/src/fs.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers #include "fs.h" namespace fsbridge { diff --git a/src/fs.h b/src/fs.h index 5152d5071..ba5b16a05 100644 --- a/src/fs.h +++ b/src/fs.h @@ -1,5 +1,5 @@ // Copyright (c) 2017 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/gtest/json_test_vectors.cpp b/src/gtest/json_test_vectors.cpp index 81143df49..73a28c422 100644 --- a/src/gtest/json_test_vectors.cpp +++ b/src/gtest/json_test_vectors.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "json_test_vectors.h" diff --git a/src/gtest/json_test_vectors.h b/src/gtest/json_test_vectors.h index ca8d7726e..82b7fda66 100644 --- a/src/gtest/json_test_vectors.h +++ b/src/gtest/json_test_vectors.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/main.cpp b/src/gtest/main.cpp index be474239b..e7340cecf 100644 --- a/src/gtest/main.cpp +++ b/src/gtest/main.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "gmock/gmock.h" diff --git a/src/gtest/test_block.cpp b/src/gtest/test_block.cpp index 85a04dfea..b19687e96 100644 --- a/src/gtest/test_block.cpp +++ b/src/gtest/test_block.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_checkblock.cpp b/src/gtest/test_checkblock.cpp index a93de7527..306ab6e6a 100644 --- a/src/gtest/test_checkblock.cpp +++ b/src/gtest/test_checkblock.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_checktransaction.cpp b/src/gtest/test_checktransaction.cpp index 581315934..7bdfb10e0 100644 --- a/src/gtest/test_checktransaction.cpp +++ b/src/gtest/test_checktransaction.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_deprecation.cpp b/src/gtest/test_deprecation.cpp index 86359b706..af546b860 100644 --- a/src/gtest/test_deprecation.cpp +++ b/src/gtest/test_deprecation.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // Released under the GPLv3 diff --git a/src/gtest/test_equihash.cpp b/src/gtest/test_equihash.cpp index e3f950ff5..47d6db175 100644 --- a/src/gtest/test_equihash.cpp +++ b/src/gtest/test_equihash.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #if defined(HAVE_CONFIG_H) diff --git a/src/gtest/test_httprpc.cpp b/src/gtest/test_httprpc.cpp index e362a0cc7..0dc27975e 100644 --- a/src/gtest/test_httprpc.cpp +++ b/src/gtest/test_httprpc.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_keys.cpp b/src/gtest/test_keys.cpp index 18e4f2d78..ca18ddf79 100644 --- a/src/gtest/test_keys.cpp +++ b/src/gtest/test_keys.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_keystore.cpp b/src/gtest/test_keystore.cpp index e0d57c64f..80a1200f3 100644 --- a/src/gtest/test_keystore.cpp +++ b/src/gtest/test_keystore.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_libzcash_utils.cpp b/src/gtest/test_libzcash_utils.cpp index 137aa7825..a0dc21e2d 100644 --- a/src/gtest/test_libzcash_utils.cpp +++ b/src/gtest/test_libzcash_utils.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_mempool.cpp b/src/gtest/test_mempool.cpp index a5c5c4b6c..ea6bcf52b 100644 --- a/src/gtest/test_mempool.cpp +++ b/src/gtest/test_mempool.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_merkletree.cpp b/src/gtest/test_merkletree.cpp index 8f8c0bd24..224d69a3e 100644 --- a/src/gtest/test_merkletree.cpp +++ b/src/gtest/test_merkletree.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_metrics.cpp b/src/gtest/test_metrics.cpp index a14e06527..84f027cb9 100644 --- a/src/gtest/test_metrics.cpp +++ b/src/gtest/test_metrics.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_miner.cpp b/src/gtest/test_miner.cpp index d12ffb3d8..9f2362b91 100644 --- a/src/gtest/test_miner.cpp +++ b/src/gtest/test_miner.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_noteencryption.cpp b/src/gtest/test_noteencryption.cpp index dc58903ae..96a0a2d5c 100644 --- a/src/gtest/test_noteencryption.cpp +++ b/src/gtest/test_noteencryption.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_pedersen_hash.cpp b/src/gtest/test_pedersen_hash.cpp index 3a7d80406..d5d43c0ae 100644 --- a/src/gtest/test_pedersen_hash.cpp +++ b/src/gtest/test_pedersen_hash.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_pow.cpp b/src/gtest/test_pow.cpp index bbda2854e..10b0211af 100644 --- a/src/gtest/test_pow.cpp +++ b/src/gtest/test_pow.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_random.cpp b/src/gtest/test_random.cpp index 12dbe020e..6622ae082 100644 --- a/src/gtest/test_random.cpp +++ b/src/gtest/test_random.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_rpc.cpp b/src/gtest/test_rpc.cpp index 1a2caff19..c64b7604c 100644 --- a/src/gtest/test_rpc.cpp +++ b/src/gtest/test_rpc.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_sapling_note.cpp b/src/gtest/test_sapling_note.cpp index ee313dbc5..d157d9f9f 100644 --- a/src/gtest/test_sapling_note.cpp +++ b/src/gtest/test_sapling_note.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_tautology.cpp b/src/gtest/test_tautology.cpp index b7cbc9d73..44daccdc4 100644 --- a/src/gtest/test_tautology.cpp +++ b/src/gtest/test_tautology.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_transaction_builder.cpp b/src/gtest/test_transaction_builder.cpp index a6ec68e5a..9e4fae718 100644 --- a/src/gtest/test_transaction_builder.cpp +++ b/src/gtest/test_transaction_builder.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "chainparams.h" diff --git a/src/gtest/test_txid.cpp b/src/gtest/test_txid.cpp index 3d553c021..6cf5dbd6c 100644 --- a/src/gtest/test_txid.cpp +++ b/src/gtest/test_txid.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_upgrades.cpp b/src/gtest/test_upgrades.cpp index affc4c47d..d8e26f0dd 100644 --- a/src/gtest/test_upgrades.cpp +++ b/src/gtest/test_upgrades.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_validation.cpp b/src/gtest/test_validation.cpp index 1f80e608e..41e394d4f 100644 --- a/src/gtest/test_validation.cpp +++ b/src/gtest/test_validation.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/test_zip32.cpp b/src/gtest/test_zip32.cpp index 0c27b01c4..4391c7592 100644 --- a/src/gtest/test_zip32.cpp +++ b/src/gtest/test_zip32.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/gtest/utils.cpp b/src/gtest/utils.cpp index c19a2ad21..ed284ae12 100644 --- a/src/gtest/utils.cpp +++ b/src/gtest/utils.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html int GenZero(int n) diff --git a/src/hash.cpp b/src/hash.cpp index 1a9b34050..529940270 100644 --- a/src/hash.cpp +++ b/src/hash.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2013-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/hash.h b/src/hash.h index f5f6560f2..a37c00a1d 100644 --- a/src/hash.h +++ b/src/hash.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/httprpc.cpp b/src/httprpc.cpp index fd6849e61..5b70c3215 100644 --- a/src/httprpc.cpp +++ b/src/httprpc.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/httpserver.cpp b/src/httpserver.cpp index 58cc9ca45..2f9761a93 100644 --- a/src/httpserver.cpp +++ b/src/httpserver.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2015 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/httpserver.h b/src/httpserver.h index 348ccda2b..8133c8d94 100644 --- a/src/httpserver.h +++ b/src/httpserver.h @@ -1,5 +1,5 @@ // Copyright (c) 2015 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/hush-tx.cpp b/src/hush-tx.cpp index 2d9814aa2..6d3f2f94c 100644 --- a/src/hush-tx.cpp +++ b/src/hush-tx.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush.h b/src/hush.h index 1c2954d9d..9ebcd2948 100644 --- a/src/hush.h +++ b/src/hush.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush/tlsenums.h b/src/hush/tlsenums.h index e75e1993a..22427d656 100644 --- a/src/hush/tlsenums.h +++ b/src/hush/tlsenums.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/hush/tlsmanager.cpp b/src/hush/tlsmanager.cpp index 51e2ea064..8cc726917 100644 --- a/src/hush/tlsmanager.cpp +++ b/src/hush/tlsmanager.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/hush/tlsmanager.h b/src/hush/tlsmanager.h index 5dd7f89e2..ca934a278 100644 --- a/src/hush/tlsmanager.h +++ b/src/hush/tlsmanager.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/hush/utiltls.cpp b/src/hush/utiltls.cpp index e06b28ee1..f8fcd4636 100644 --- a/src/hush/utiltls.cpp +++ b/src/hush/utiltls.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2017 The Zen Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/hush/utiltls.h b/src/hush/utiltls.h index 206f6bdf0..c89045f8d 100644 --- a/src/hush/utiltls.h +++ b/src/hush/utiltls.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2017 The Zen Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/hush_bitcoind.h b/src/hush_bitcoind.h index d690cc8a2..b8b5a463d 100644 --- a/src/hush_bitcoind.h +++ b/src/hush_bitcoind.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush Developers +// Copyright (c) 2016-2022 The Hush Developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush_cJSON.h b/src/hush_cJSON.h index d7eb3a4dd..ec4b85a91 100644 --- a/src/hush_cJSON.h +++ b/src/hush_cJSON.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /* diff --git a/src/hush_ccdata.h b/src/hush_ccdata.h index 498419ab1..0d6febbc9 100644 --- a/src/hush_ccdata.h +++ b/src/hush_ccdata.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush_curve25519.h b/src/hush_curve25519.h index 688d9cc9b..fb8a86e65 100644 --- a/src/hush_curve25519.h +++ b/src/hush_curve25519.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush_events.h b/src/hush_events.h index 00832ae23..e5c804941 100644 --- a/src/hush_events.h +++ b/src/hush_events.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush_gateway.h b/src/hush_gateway.h index 2f701cfb6..9c7952045 100644 --- a/src/hush_gateway.h +++ b/src/hush_gateway.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush_globals.h b/src/hush_globals.h index 9dc68449f..e2b8d8e33 100644 --- a/src/hush_globals.h +++ b/src/hush_globals.h @@ -1,4 +1,4 @@ -// Copyright 2016-2021 The Hush Developers +// Copyright 2016-2022 The Hush Developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush_kv.h b/src/hush_kv.h index 9149c9ec4..8d067b25a 100644 --- a/src/hush_kv.h +++ b/src/hush_kv.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush_nSPV.h b/src/hush_nSPV.h index f8e1645d1..564f217e1 100644 --- a/src/hush_nSPV.h +++ b/src/hush_nSPV.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush_nSPV_fullnode.h b/src/hush_nSPV_fullnode.h index be4fbce15..50e650073 100644 --- a/src/hush_nSPV_fullnode.h +++ b/src/hush_nSPV_fullnode.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush_nSPV_wallet.h b/src/hush_nSPV_wallet.h index 05c5d489f..0053fbcde 100644 --- a/src/hush_nSPV_wallet.h +++ b/src/hush_nSPV_wallet.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush_notary.h b/src/hush_notary.h index 6090b4f86..319ed0a05 100644 --- a/src/hush_notary.h +++ b/src/hush_notary.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush_pax.h b/src/hush_pax.h index fe2f946ad..7cfb08750 100644 --- a/src/hush_pax.h +++ b/src/hush_pax.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush_structs.h b/src/hush_structs.h index 121100b55..5f1c22e38 100644 --- a/src/hush_structs.h +++ b/src/hush_structs.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/hush_utils.h b/src/hush_utils.h index 7708b156c..ae19fce95 100644 --- a/src/hush_utils.h +++ b/src/hush_utils.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/importcoin.cpp b/src/importcoin.cpp index f6da631c7..0f14d5654 100644 --- a/src/importcoin.cpp +++ b/src/importcoin.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/importcoin.h b/src/importcoin.h index f903d2e03..01f43bf57 100644 --- a/src/importcoin.h +++ b/src/importcoin.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/init.cpp b/src/init.cpp index 5739c8b3b..9c9f36329 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html // What happened to the SuperNET devs, who were dedicated to privacy??? diff --git a/src/init.h b/src/init.h index d87c862a0..df930fd62 100644 --- a/src/init.h +++ b/src/init.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/key.cpp b/src/key.cpp index 83f831ada..2ca251f2f 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2009-2014 The Bitcoin Core developers // Copyright (c) 2017 The Zcash developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/key.h b/src/key.h index 80d0a643d..e65e5f29c 100644 --- a/src/key.h +++ b/src/key.h @@ -1,7 +1,7 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Copyright (c) 2017 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/key_io.cpp b/src/key_io.cpp index d575d97df..c3d5471d5 100644 --- a/src/key_io.cpp +++ b/src/key_io.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2014-2016 The Bitcoin Core developers // Copyright (c) 2016-2018 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/key_io.h b/src/key_io.h index f4647ee9f..c70971cbb 100644 --- a/src/key_io.h +++ b/src/key_io.h @@ -1,7 +1,7 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2015 The Bitcoin Core developers // Copyright (c) 2016-2018 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/keystore.cpp b/src/keystore.cpp index 072b29ef9..9baa44495 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/keystore.h b/src/keystore.h index 27486d583..39a7013e9 100644 --- a/src/keystore.h +++ b/src/keystore.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/main.cpp b/src/main.cpp index 4e466ba45..acef0dd50 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/main.h b/src/main.h index f2e5ad38d..034629dbc 100644 --- a/src/main.h +++ b/src/main.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/merkleblock.cpp b/src/merkleblock.cpp index 86df55cac..7cde7ed36 100644 --- a/src/merkleblock.cpp +++ b/src/merkleblock.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/metrics.cpp b/src/metrics.cpp index c6022cb95..0653b519e 100644 --- a/src/metrics.cpp +++ b/src/metrics.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2016 The Zcash developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/metrics.h b/src/metrics.h index 274f3ab95..73d10c890 100644 --- a/src/metrics.h +++ b/src/metrics.h @@ -1,5 +1,5 @@ // Copyright (c) 2016 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/miner.h b/src/miner.h index 2cdd5106b..4a8ca6190 100644 --- a/src/miner.h +++ b/src/miner.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/net.cpp b/src/net.cpp index 40e5070de..5b1bcf5ac 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/net.h b/src/net.h index d55d500e1..d96c65e01 100644 --- a/src/net.h +++ b/src/net.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/netbase.cpp b/src/netbase.cpp index 034bbe8f2..070734ce8 100644 --- a/src/netbase.cpp +++ b/src/netbase.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/notarizationdb.cpp b/src/notarizationdb.cpp index 9ff61a8ed..79479e7bf 100644 --- a/src/notarizationdb.cpp +++ b/src/notarizationdb.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "dbwrapper.h" diff --git a/src/notarizationdb.h b/src/notarizationdb.h index b6e3f7684..db72936e3 100644 --- a/src/notarizationdb.h +++ b/src/notarizationdb.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #ifndef HUSH_NOTARISATIONDB_H diff --git a/src/noui.cpp b/src/noui.cpp index e0bd76e4d..2bad045a7 100644 --- a/src/noui.cpp +++ b/src/noui.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/pow.cpp b/src/pow.cpp index 757929a19..753378ba9 100644 --- a/src/pow.cpp +++ b/src/pow.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/pow.h b/src/pow.h index 0d6fd7f93..bccbf321e 100644 --- a/src/pow.h +++ b/src/pow.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/pow/tromp/equi_miner.h b/src/pow/tromp/equi_miner.h index 74311018e..fa719b1f8 100644 --- a/src/pow/tromp/equi_miner.h +++ b/src/pow/tromp/equi_miner.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html // Copyright (c) 2016 John Tromp, The Zcash developers diff --git a/src/pow/tromp/osx_barrier.h b/src/pow/tromp/osx_barrier.h index 16a365aeb..821886839 100644 --- a/src/pow/tromp/osx_barrier.h +++ b/src/pow/tromp/osx_barrier.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #ifdef __APPLE__ diff --git a/src/prevector.h b/src/prevector.h index 5d71e298b..47f527d24 100644 --- a/src/prevector.h +++ b/src/prevector.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #ifndef _HUSH_PREVECTOR_H_ diff --git a/src/primitives/block.cpp b/src/primitives/block.cpp index adf62f2d1..4db84e47c 100644 --- a/src/primitives/block.cpp +++ b/src/primitives/block.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/primitives/block.h b/src/primitives/block.h index a3751dc48..7fc351a65 100644 --- a/src/primitives/block.h +++ b/src/primitives/block.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/primitives/transaction.cpp b/src/primitives/transaction.cpp index 7e2580149..0f72f351a 100644 --- a/src/primitives/transaction.cpp +++ b/src/primitives/transaction.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/primitives/transaction.h b/src/primitives/transaction.h index 3c6df21b2..26fd25590 100644 --- a/src/primitives/transaction.h +++ b/src/primitives/transaction.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/protocol.cpp b/src/protocol.cpp index 9da8265c3..402c9213d 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/protocol.h b/src/protocol.h index d21139d35..d201d6f10 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/pubkey.cpp b/src/pubkey.cpp index 28e2595f3..9df95f232 100644 --- a/src/pubkey.cpp +++ b/src/pubkey.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2014 The Bitcoin Core developers // Copyright (c) 2017 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/pubkey.h b/src/pubkey.h index fd56c62d2..689fe9352 100644 --- a/src/pubkey.h +++ b/src/pubkey.h @@ -1,7 +1,7 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Copyright (c) 2017 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/purge b/src/purge index df6624596..d34b6f72b 100755 --- a/src/purge +++ b/src/purge @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 echo "Purging $1" diff --git a/src/random.cpp b/src/random.cpp index 8259118b3..2c13a4cce 100644 --- a/src/random.cpp +++ b/src/random.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/rest.cpp b/src/rest.cpp index 2a2dd5238..608fb7a30 100644 --- a/src/rest.cpp +++ b/src/rest.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 90b8e7201..e5ac31769 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index e427ec3ff..4c89b2bc3 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/rpc/crosschain.cpp b/src/rpc/crosschain.cpp index d3e54dc68..bfb195019 100644 --- a/src/rpc/crosschain.cpp +++ b/src/rpc/crosschain.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index ab6a75e96..275617dab 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/rpc/net.cpp b/src/rpc/net.cpp index 7f49f785b..afd5d470b 100644 --- a/src/rpc/net.cpp +++ b/src/rpc/net.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 2e82c061a..635d71d7c 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2015 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/rpc/register.h b/src/rpc/register.h index 7c545da48..19f5c4645 100644 --- a/src/rpc/register.h +++ b/src/rpc/register.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2009-2016 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 74dc863ce..73ed8f383 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/rpc/server.h b/src/rpc/server.h index 3b3e11c6a..31a2fb0a8 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -1,6 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush Developers +// Copyright (c) 2016-2022 The Hush Developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/scheduler.cpp b/src/scheduler.cpp index 9c4ebf334..37882c753 100644 --- a/src/scheduler.cpp +++ b/src/scheduler.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2015 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/script/interpreter.cpp b/src/script/interpreter.cpp index fc8b8f6f9..9a54b8b10 100644 --- a/src/script/interpreter.cpp +++ b/src/script/interpreter.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/script/standard.cpp b/src/script/standard.cpp index 6a845499d..a40d7cd92 100644 --- a/src/script/standard.cpp +++ b/src/script/standard.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/script/standard.h b/src/script/standard.h index 697150372..645912873 100644 --- a/src/script/standard.h +++ b/src/script/standard.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/sendalert.cpp b/src/sendalert.cpp index e426cc09f..73116c4b8 100644 --- a/src/sendalert.cpp +++ b/src/sendalert.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2016 The Zcash developers // Original code from: https://gist.github.com/laanwj/0e689cfa37b52bcbbb44 // Distributed under the GPLv3 software license, see the accompanying @@ -56,7 +56,7 @@ the bad alert. */ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "main.h" diff --git a/src/smartchains b/src/smartchains index 1a210dd01..68a340bb9 100755 --- a/src/smartchains +++ b/src/smartchains @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2018-2021 The Hush developers +# Copyright (c) 2018-2022 The Hush developers set -eo pipefail # You can now add delay line to pubkey.txt file diff --git a/src/support/allocators/secure.h b/src/support/allocators/secure.h index 90b9105ce..ceaf54b80 100644 --- a/src/support/allocators/secure.h +++ b/src/support/allocators/secure.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/support/allocators/zeroafterfree.h b/src/support/allocators/zeroafterfree.h index e72715f6a..fac487c55 100644 --- a/src/support/allocators/zeroafterfree.h +++ b/src/support/allocators/zeroafterfree.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/sync.cpp b/src/sync.cpp index 209dd9edb..1f82d6728 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2011-2012 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/test-hush/main.cpp b/src/test-hush/main.cpp index 1a75d4196..d33791446 100644 --- a/src/test-hush/main.cpp +++ b/src/test-hush/main.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "key.h" diff --git a/src/test-hush/test_addrman.cpp b/src/test-hush/test_addrman.cpp index 29d5fc319..50ffa82f0 100644 --- a/src/test-hush/test_addrman.cpp +++ b/src/test-hush/test_addrman.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/test-hush/test_coinimport.cpp b/src/test-hush/test_coinimport.cpp index f4a4de578..3f44767db 100644 --- a/src/test-hush/test_coinimport.cpp +++ b/src/test-hush/test_coinimport.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test-hush/test_cryptoconditions.cpp b/src/test-hush/test_cryptoconditions.cpp index 09cf5de1d..30e10de71 100644 --- a/src/test-hush/test_cryptoconditions.cpp +++ b/src/test-hush/test_cryptoconditions.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/test-hush/test_eval_bet.cpp b/src/test-hush/test_eval_bet.cpp index 51c9eda42..86cf33ca7 100644 --- a/src/test-hush/test_eval_bet.cpp +++ b/src/test-hush/test_eval_bet.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/test-hush/test_eval_notarization.cpp b/src/test-hush/test_eval_notarization.cpp index d42327718..e394ab8aa 100644 --- a/src/test-hush/test_eval_notarization.cpp +++ b/src/test-hush/test_eval_notarization.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/test-hush/test_netbase_tests.cpp b/src/test-hush/test_netbase_tests.cpp index fdd8605fb..12e2267c2 100644 --- a/src/test-hush/test_netbase_tests.cpp +++ b/src/test-hush/test_netbase_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/test-hush/test_parse_notarization.cpp b/src/test-hush/test_parse_notarization.cpp index 0ee04a817..9a4f8e89e 100644 --- a/src/test-hush/test_parse_notarization.cpp +++ b/src/test-hush/test_parse_notarization.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/test-hush/testutils.cpp b/src/test-hush/testutils.cpp index e68491f3b..2fa8ccfd5 100644 --- a/src/test-hush/testutils.cpp +++ b/src/test-hush/testutils.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/test-hush/testutils.h b/src/test-hush/testutils.h index 4ac099606..f5626fd74 100644 --- a/src/test-hush/testutils.h +++ b/src/test-hush/testutils.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #ifndef HUSH_TESTUTILS_H diff --git a/src/test/Checkpoints_tests.cpp b/src/test/Checkpoints_tests.cpp index 12c9fdb30..7d48beb6c 100644 --- a/src/test/Checkpoints_tests.cpp +++ b/src/test/Checkpoints_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2011-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/DoS_tests.cpp b/src/test/DoS_tests.cpp index dff34f154..c1e1a1a74 100644 --- a/src/test/DoS_tests.cpp +++ b/src/test/DoS_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2011-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/accounting_tests.cpp b/src/test/accounting_tests.cpp index 3878b0bcd..53f08c573 100644 --- a/src/test/accounting_tests.cpp +++ b/src/test/accounting_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2012-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/addrman_tests.cpp b/src/test/addrman_tests.cpp index 713a177ee..858c8704e 100644 --- a/src/test/addrman_tests.cpp +++ b/src/test/addrman_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2012-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "addrman.h" diff --git a/src/test/allocator_tests.cpp b/src/test/allocator_tests.cpp index 57910903f..6b0b6b1ac 100644 --- a/src/test/allocator_tests.cpp +++ b/src/test/allocator_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2012-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/arith_uint256_tests.cpp b/src/test/arith_uint256_tests.cpp index a9dc387a4..05ebb1d46 100644 --- a/src/test/arith_uint256_tests.cpp +++ b/src/test/arith_uint256_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2011-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/base32_tests.cpp b/src/test/base32_tests.cpp index 2268aaf67..0886ef1e5 100644 --- a/src/test/base32_tests.cpp +++ b/src/test/base32_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2012-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/base58_tests.cpp b/src/test/base58_tests.cpp index 2d7c1fd63..49f6a429f 100644 --- a/src/test/base58_tests.cpp +++ b/src/test/base58_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2011-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/base64_tests.cpp b/src/test/base64_tests.cpp index 443350ded..28a47de4b 100644 --- a/src/test/base64_tests.cpp +++ b/src/test/base64_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2011-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/bctest.py b/src/test/bctest.py index 77a0d821b..55b830485 100644 --- a/src/test/bctest.py +++ b/src/test/bctest.py @@ -1,5 +1,5 @@ # Copyright 2014 BitPay, Inc. -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/bech32_tests.cpp b/src/test/bech32_tests.cpp index 0e1168f61..574843371 100644 --- a/src/test/bech32_tests.cpp +++ b/src/test/bech32_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2017 Pieter Wuille -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/bip32_tests.cpp b/src/test/bip32_tests.cpp index 4708be5a2..d2f8e47ce 100644 --- a/src/test/bip32_tests.cpp +++ b/src/test/bip32_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/bitcoin-util-test.py b/src/test/bitcoin-util-test.py index a5bbba3bd..2eb05fab5 100755 --- a/src/test/bitcoin-util-test.py +++ b/src/test/bitcoin-util-test.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Copyright 2014 BitPay, Inc. # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/bloom_tests.cpp b/src/test/bloom_tests.cpp index 95a5788a7..ba5d31c01 100644 --- a/src/test/bloom_tests.cpp +++ b/src/test/bloom_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2012-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/checkblock_tests.cpp b/src/test/checkblock_tests.cpp index af9476a7c..5828537ef 100644 --- a/src/test/checkblock_tests.cpp +++ b/src/test/checkblock_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2013-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/coins_tests.cpp b/src/test/coins_tests.cpp index 28f437715..eddb5e288 100644 --- a/src/test/coins_tests.cpp +++ b/src/test/coins_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/compress_tests.cpp b/src/test/compress_tests.cpp index 89ab20e9e..0f998125e 100644 --- a/src/test/compress_tests.cpp +++ b/src/test/compress_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2012-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/convertbits_tests.cpp b/src/test/convertbits_tests.cpp index 59da44a7f..65228336a 100644 --- a/src/test/convertbits_tests.cpp +++ b/src/test/convertbits_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2018 The Zcash developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/crypto_tests.cpp b/src/test/crypto_tests.cpp index 72cdd961c..0786de166 100644 --- a/src/test/crypto_tests.cpp +++ b/src/test/crypto_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/dbwrapper_tests.cpp b/src/test/dbwrapper_tests.cpp index 8ccb44bb1..95150bf3f 100644 --- a/src/test/dbwrapper_tests.cpp +++ b/src/test/dbwrapper_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2018 The Zcash developers // Copyright (c) 2012-2017 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/test/equihash_tests.cpp b/src/test/equihash_tests.cpp index 781281610..e9c280d3c 100644 --- a/src/test/equihash_tests.cpp +++ b/src/test/equihash_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2016 Jack Grigg // Copyright (c) 2016 The Zcash developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/test/getarg_tests.cpp b/src/test/getarg_tests.cpp index 17755b807..6dfb5ba83 100644 --- a/src/test/getarg_tests.cpp +++ b/src/test/getarg_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/hash_tests.cpp b/src/test/hash_tests.cpp index c074add74..c95d77d2b 100644 --- a/src/test/hash_tests.cpp +++ b/src/test/hash_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/key_tests.cpp b/src/test/key_tests.cpp index 7f188e0ae..046760579 100644 --- a/src/test/key_tests.cpp +++ b/src/test/key_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2012-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/main_tests.cpp b/src/test/main_tests.cpp index 92f952968..16a93ccab 100644 --- a/src/test/main_tests.cpp +++ b/src/test/main_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/mempool_tests.cpp b/src/test/mempool_tests.cpp index 553867c66..99e941ec2 100644 --- a/src/test/mempool_tests.cpp +++ b/src/test/mempool_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2011-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/miner_tests.cpp b/src/test/miner_tests.cpp index 52f0a0211..b15a84b90 100644 --- a/src/test/miner_tests.cpp +++ b/src/test/miner_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2011-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/mruset_tests.cpp b/src/test/mruset_tests.cpp index 9eef2896c..161a0b191 100644 --- a/src/test/mruset_tests.cpp +++ b/src/test/mruset_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/multisig_tests.cpp b/src/test/multisig_tests.cpp index b4a512210..b365bf6d0 100644 --- a/src/test/multisig_tests.cpp +++ b/src/test/multisig_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2011-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/netbase_tests.cpp b/src/test/netbase_tests.cpp index db157164e..fe9160fda 100644 --- a/src/test/netbase_tests.cpp +++ b/src/test/netbase_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/pmt_tests.cpp b/src/test/pmt_tests.cpp index 61f85defb..34508ffb7 100644 --- a/src/test/pmt_tests.cpp +++ b/src/test/pmt_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/policyestimator_tests.cpp b/src/test/policyestimator_tests.cpp index a878a55cf..fbcb26881 100644 --- a/src/test/policyestimator_tests.cpp +++ b/src/test/policyestimator_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2011-2015 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/pow_tests.cpp b/src/test/pow_tests.cpp index d12f47468..f18c5e81c 100644 --- a/src/test/pow_tests.cpp +++ b/src/test/pow_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2015 The Bitcoin Core developers // Distributed under the GPLv3/X11 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/prevector_tests.cpp b/src/test/prevector_tests.cpp index a4e688154..f82fc0add 100644 --- a/src/test/prevector_tests.cpp +++ b/src/test/prevector_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2015 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/raii_event_tests.cpp b/src/test/raii_event_tests.cpp index 450d11228..26e6501f3 100644 --- a/src/test/raii_event_tests.cpp +++ b/src/test/raii_event_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2016 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/reverselock_tests.cpp b/src/test/reverselock_tests.cpp index f5701ec38..b49094d38 100644 --- a/src/test/reverselock_tests.cpp +++ b/src/test/reverselock_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2015 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp index 74d303785..a5066721a 100644 --- a/src/test/rpc_tests.cpp +++ b/src/test/rpc_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/rpc_wallet_tests.cpp b/src/test/rpc_wallet_tests.cpp index f2b614a84..d52be3600 100644 --- a/src/test/rpc_wallet_tests.cpp +++ b/src/test/rpc_wallet_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2013-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/sanity_tests.cpp b/src/test/sanity_tests.cpp index 6d7df75e8..ce5c2a870 100644 --- a/src/test/sanity_tests.cpp +++ b/src/test/sanity_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/scheduler_tests.cpp b/src/test/scheduler_tests.cpp index 1c4018ad9..6cfd8854e 100644 --- a/src/test/scheduler_tests.cpp +++ b/src/test/scheduler_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/script_P2PKH_tests.cpp b/src/test/script_P2PKH_tests.cpp index 70729446e..95d894b6b 100644 --- a/src/test/script_P2PKH_tests.cpp +++ b/src/test/script_P2PKH_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2015 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/script_P2SH_tests.cpp b/src/test/script_P2SH_tests.cpp index 295e03ef8..c353bb70c 100644 --- a/src/test/script_P2SH_tests.cpp +++ b/src/test/script_P2SH_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/script_tests.cpp b/src/test/script_tests.cpp index f031787a8..fa6f74dce 100644 --- a/src/test/script_tests.cpp +++ b/src/test/script_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2011-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/scriptnum_tests.cpp b/src/test/scriptnum_tests.cpp index 84538a968..b67a8358a 100644 --- a/src/test/scriptnum_tests.cpp +++ b/src/test/scriptnum_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/serialize_tests.cpp b/src/test/serialize_tests.cpp index ec7d69649..e52cddb04 100644 --- a/src/test/serialize_tests.cpp +++ b/src/test/serialize_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/sha256compress_tests.cpp b/src/test/sha256compress_tests.cpp index fcf6ffabb..9db755e41 100644 --- a/src/test/sha256compress_tests.cpp +++ b/src/test/sha256compress_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "test/test_bitcoin.h" diff --git a/src/test/sighash_tests.cpp b/src/test/sighash_tests.cpp index dd5159259..92a7bfc6a 100644 --- a/src/test/sighash_tests.cpp +++ b/src/test/sighash_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/sigopcount_tests.cpp b/src/test/sigopcount_tests.cpp index b40213d60..f551a9a76 100644 --- a/src/test/sigopcount_tests.cpp +++ b/src/test/sigopcount_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/skiplist_tests.cpp b/src/test/skiplist_tests.cpp index 460ef4f10..5fd52cb34 100644 --- a/src/test/skiplist_tests.cpp +++ b/src/test/skiplist_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/test_bitcoin.cpp b/src/test/test_bitcoin.cpp index 6d4d91485..df4462240 100644 --- a/src/test/test_bitcoin.cpp +++ b/src/test/test_bitcoin.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2011-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/test_bitcoin.h b/src/test/test_bitcoin.h index bba2ce335..99a4abc00 100644 --- a/src/test/test_bitcoin.h +++ b/src/test/test_bitcoin.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #ifndef HUSH_TEST_TEST_HUSH_H diff --git a/src/test/timedata_tests.cpp b/src/test/timedata_tests.cpp index 992419adb..0c9037c97 100644 --- a/src/test/timedata_tests.cpp +++ b/src/test/timedata_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2011-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/torcontrol_tests.cpp b/src/test/torcontrol_tests.cpp index fc4054d35..1e58d13a2 100644 --- a/src/test/torcontrol_tests.cpp +++ b/src/test/torcontrol_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2017 The Zcash developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/transaction_tests.cpp b/src/test/transaction_tests.cpp index ed452a007..269d7c521 100644 --- a/src/test/transaction_tests.cpp +++ b/src/test/transaction_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2011-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/uint256_tests.cpp b/src/test/uint256_tests.cpp index db330cc49..66bf4c439 100644 --- a/src/test/uint256_tests.cpp +++ b/src/test/uint256_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2011-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/univalue_tests.cpp b/src/test/univalue_tests.cpp index 020133b57..ddf677491 100644 --- a/src/test/univalue_tests.cpp +++ b/src/test/univalue_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright 2014 BitPay, Inc. // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index c10d356f3..99249a6a2 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2011-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/test/wallet-utility.py b/src/test/wallet-utility.py index d5a5ba3db..c39f127dc 100644 --- a/src/test/wallet-utility.py +++ b/src/test/wallet-utility.py @@ -1,6 +1,6 @@ #!/usr/bin/python # Copyright 2014 BitPay, Inc. -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers ## Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/timedata.cpp b/src/timedata.cpp index 2b891e0b6..7e9f081b3 100644 --- a/src/timedata.cpp +++ b/src/timedata.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2020 The Zcash developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/timedata.h b/src/timedata.h index 8bb0e0d3d..a9a0124bb 100644 --- a/src/timedata.h +++ b/src/timedata.h @@ -1,5 +1,5 @@ // Copyright (c) 2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2020 The Zcash developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp index d0743a298..9d115d122 100644 --- a/src/torcontrol.cpp +++ b/src/torcontrol.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2015-2017 The Bitcoin Core developers // Copyright (c) 2017 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/torcontrol.h b/src/torcontrol.h index f7e281429..ff0a3ea10 100644 --- a/src/torcontrol.h +++ b/src/torcontrol.h @@ -1,5 +1,5 @@ // Copyright (c) 2015 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/transaction_builder.cpp b/src/transaction_builder.cpp index 0dfd5a299..f2ac051dc 100644 --- a/src/transaction_builder.cpp +++ b/src/transaction_builder.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2018 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/transaction_builder.h b/src/transaction_builder.h index 6c4d20302..64a2ccb87 100644 --- a/src/transaction_builder.h +++ b/src/transaction_builder.h @@ -1,5 +1,5 @@ // Copyright (c) 2018 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/tush-cli b/src/tush-cli index fa40e9f81..d2442d3fb 100755 --- a/src/tush-cli +++ b/src/tush-cli @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # set working directory to the location of this script # readlink -f does not always exist diff --git a/src/tushd b/src/tushd index 9089ffe8c..6b9ec3886 100755 --- a/src/tushd +++ b/src/tushd @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/txdb.cpp b/src/txdb.cpp index 15f2b99cc..6f2301049 100644 --- a/src/txdb.cpp +++ b/src/txdb.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/txdb.h b/src/txdb.h index 5122957e2..a53c6aece 100644 --- a/src/txdb.h +++ b/src/txdb.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 4c30fdfcb..60a1b59d1 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/txmempool.h b/src/txmempool.h index 3f3abb47e..97c85be48 100644 --- a/src/txmempool.h +++ b/src/txmempool.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/uint256.cpp b/src/uint256.cpp index 97c0cb007..ad8d3ff8b 100644 --- a/src/uint256.cpp +++ b/src/uint256.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/util.cpp b/src/util.cpp index ed894a37f..e9d0a63e5 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/util.h b/src/util.h index c7898c179..d562e3b62 100644 --- a/src/util.h +++ b/src/util.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/utilmoneystr.cpp b/src/utilmoneystr.cpp index 78d8a1d00..c03039ea3 100644 --- a/src/utilmoneystr.cpp +++ b/src/utilmoneystr.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "utilmoneystr.h" diff --git a/src/utilstrencodings.cpp b/src/utilstrencodings.cpp index 4a2815968..b55036766 100644 --- a/src/utilstrencodings.cpp +++ b/src/utilstrencodings.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/utiltime.cpp b/src/utiltime.cpp index bc5e3d69c..34933b15f 100644 --- a/src/utiltime.cpp +++ b/src/utiltime.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/validationinterface.cpp b/src/validationinterface.cpp index d9b06eb96..dd29ec75a 100644 --- a/src/validationinterface.cpp +++ b/src/validationinterface.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html . diff --git a/src/validationinterface.h b/src/validationinterface.h index 08be11730..deca0dda4 100644 --- a/src/validationinterface.h +++ b/src/validationinterface.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/version.h b/src/version.h index a08199ef3..da95222dd 100644 --- a/src/version.h +++ b/src/version.h @@ -1,5 +1,5 @@ // Copyright (c) 2012-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/wallet-utility.cpp b/src/wallet-utility.cpp index a82dfa3b7..fd4731af2 100644 --- a/src/wallet-utility.cpp +++ b/src/wallet-utility.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.cpp b/src/wallet/asyncrpcoperation_mergetoaddress.cpp index d1f207571..166bb7fbd 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.cpp +++ b/src/wallet/asyncrpcoperation_mergetoaddress.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2017 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html . diff --git a/src/wallet/asyncrpcoperation_mergetoaddress.h b/src/wallet/asyncrpcoperation_mergetoaddress.h index afc029b74..712c193db 100644 --- a/src/wallet/asyncrpcoperation_mergetoaddress.h +++ b/src/wallet/asyncrpcoperation_mergetoaddress.h @@ -1,5 +1,5 @@ // Copyright (c) 2017 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp index 41f1fc07e..95f81b225 100644 --- a/src/wallet/asyncrpcoperation_saplingconsolidation.cpp +++ b/src/wallet/asyncrpcoperation_saplingconsolidation.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2019 CryptoForge // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/wallet/asyncrpcoperation_sendmany.cpp b/src/wallet/asyncrpcoperation_sendmany.cpp index 28fad9c60..8dd577b0f 100644 --- a/src/wallet/asyncrpcoperation_sendmany.cpp +++ b/src/wallet/asyncrpcoperation_sendmany.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2016 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/wallet/asyncrpcoperation_sendmany.h b/src/wallet/asyncrpcoperation_sendmany.h index 7000eaf10..21b340e74 100644 --- a/src/wallet/asyncrpcoperation_sendmany.h +++ b/src/wallet/asyncrpcoperation_sendmany.h @@ -1,5 +1,5 @@ // Copyright (c) 2016 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp index a4d4857e0..30c111e4f 100644 --- a/src/wallet/asyncrpcoperation_shieldcoinbase.cpp +++ b/src/wallet/asyncrpcoperation_shieldcoinbase.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2017 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/wallet/asyncrpcoperation_shieldcoinbase.h b/src/wallet/asyncrpcoperation_shieldcoinbase.h index 4121cbd2e..286495a9d 100644 --- a/src/wallet/asyncrpcoperation_shieldcoinbase.h +++ b/src/wallet/asyncrpcoperation_shieldcoinbase.h @@ -1,5 +1,5 @@ // Copyright (c) 2017 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/wallet/crypter.cpp b/src/wallet/crypter.cpp index ff0da14d6..f8eb10278 100644 --- a/src/wallet/crypter.cpp +++ b/src/wallet/crypter.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2013 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/wallet/crypter.h b/src/wallet/crypter.h index 8df203a4b..45e106380 100644 --- a/src/wallet/crypter.h +++ b/src/wallet/crypter.h @@ -1,5 +1,5 @@ // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/wallet/db.cpp b/src/wallet/db.cpp index ec312a6d0..515704632 100644 --- a/src/wallet/db.cpp +++ b/src/wallet/db.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/wallet/gtest/test_transaction.cpp b/src/wallet/gtest/test_transaction.cpp index 9807c5774..5e4bf8ca1 100644 --- a/src/wallet/gtest/test_transaction.cpp +++ b/src/wallet/gtest/test_transaction.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/wallet/gtest/test_wallet.cpp b/src/wallet/gtest/test_wallet.cpp index 7dd5fd683..1c10f673b 100644 --- a/src/wallet/gtest/test_wallet.cpp +++ b/src/wallet/gtest/test_wallet.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/wallet/gtest/test_wallet_zkeys.cpp b/src/wallet/gtest/test_wallet_zkeys.cpp index 3a2c48845..9f105e057 100644 --- a/src/wallet/gtest/test_wallet_zkeys.cpp +++ b/src/wallet/gtest/test_wallet_zkeys.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include diff --git a/src/wallet/rpcdump.cpp b/src/wallet/rpcdump.cpp index 8b3b932c1..6d30a706c 100644 --- a/src/wallet/rpcdump.cpp +++ b/src/wallet/rpcdump.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/wallet/rpchushwallet.cpp b/src/wallet/rpchushwallet.cpp index c13f22a97..c92cda44b 100644 --- a/src/wallet/rpchushwallet.cpp +++ b/src/wallet/rpchushwallet.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2019 Cryptoforge // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index b2fb8ab14..ee346ddc9 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/wallet/test/wallet_tests.cpp b/src/wallet/test/wallet_tests.cpp index 3831aaed4..bf250fabe 100644 --- a/src/wallet/test/wallet_tests.cpp +++ b/src/wallet/test/wallet_tests.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2012-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 3a84f267e..1981ce21c 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index ec2937a1d..058cc30d7 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 7b286c2c7..1135c4e7e 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/zcash/Address.cpp b/src/zcash/Address.cpp index 58e0c9edc..0b4f22abc 100644 --- a/src/zcash/Address.cpp +++ b/src/zcash/Address.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zcash/Address.hpp b/src/zcash/Address.hpp index a1465651c..5e23f11da 100644 --- a/src/zcash/Address.hpp +++ b/src/zcash/Address.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zcash/IncrementalMerkleTree.cpp b/src/zcash/IncrementalMerkleTree.cpp index 5b3855497..1740675f5 100644 --- a/src/zcash/IncrementalMerkleTree.cpp +++ b/src/zcash/IncrementalMerkleTree.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zcash/IncrementalMerkleTree.hpp b/src/zcash/IncrementalMerkleTree.hpp index 03fa51fda..323688f9a 100644 --- a/src/zcash/IncrementalMerkleTree.hpp +++ b/src/zcash/IncrementalMerkleTree.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zcash/JoinSplit.cpp b/src/zcash/JoinSplit.cpp index 823d37d06..b0aba24e8 100644 --- a/src/zcash/JoinSplit.cpp +++ b/src/zcash/JoinSplit.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #include "JoinSplit.hpp" diff --git a/src/zcash/JoinSplit.hpp b/src/zcash/JoinSplit.hpp index 7d6efcdef..4aa367fb5 100644 --- a/src/zcash/JoinSplit.hpp +++ b/src/zcash/JoinSplit.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zcash/Note.cpp b/src/zcash/Note.cpp index 3c0054937..4213624ac 100644 --- a/src/zcash/Note.cpp +++ b/src/zcash/Note.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zcash/Note.hpp b/src/zcash/Note.hpp index c170e0722..54b531992 100644 --- a/src/zcash/Note.hpp +++ b/src/zcash/Note.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zcash/NoteEncryption.cpp b/src/zcash/NoteEncryption.cpp index 9f87e21d9..3a655e742 100644 --- a/src/zcash/NoteEncryption.cpp +++ b/src/zcash/NoteEncryption.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zcash/NoteEncryption.hpp b/src/zcash/NoteEncryption.hpp index 2bc6c8d8f..fddf56be7 100644 --- a/src/zcash/NoteEncryption.hpp +++ b/src/zcash/NoteEncryption.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zcash/Proof.cpp b/src/zcash/Proof.cpp index c1ef1bed7..ccad05930 100644 --- a/src/zcash/Proof.cpp +++ b/src/zcash/Proof.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zcash/Proof.hpp b/src/zcash/Proof.hpp index 7c5dadb9a..d232e99cd 100644 --- a/src/zcash/Proof.hpp +++ b/src/zcash/Proof.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zcash/Zcash.h b/src/zcash/Zcash.h index 8b7b2240e..3e961d208 100644 --- a/src/zcash/Zcash.h +++ b/src/zcash/Zcash.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #ifndef ZC_ZCASH_H_ diff --git a/src/zcash/prf.cpp b/src/zcash/prf.cpp index e3685eb38..fa3aa5082 100644 --- a/src/zcash/prf.cpp +++ b/src/zcash/prf.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zcash/prf.h b/src/zcash/prf.h index 882ba6403..5af11d583 100644 --- a/src/zcash/prf.h +++ b/src/zcash/prf.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html // Zcash uses SHA256Compress as a PRF for various components diff --git a/src/zcash/util.cpp b/src/zcash/util.cpp index 1ad7a8b5e..88d73a38c 100644 --- a/src/zcash/util.cpp +++ b/src/zcash/util.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zcash/util.h b/src/zcash/util.h index 3bd67e6d1..9d5ea22eb 100644 --- a/src/zcash/util.h +++ b/src/zcash/util.h @@ -1,4 +1,4 @@ -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #ifndef ZC_UTIL_H_ diff --git a/src/zcash/zip32.cpp b/src/zcash/zip32.cpp index c01b57774..eda38bed5 100644 --- a/src/zcash/zip32.cpp +++ b/src/zcash/zip32.cpp @@ -1,5 +1,5 @@ // Copyright (c) 2018 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zcash/zip32.h b/src/zcash/zip32.h index 47887351a..588282922 100644 --- a/src/zcash/zip32.h +++ b/src/zcash/zip32.h @@ -1,5 +1,5 @@ // Copyright (c) 2018 The Zcash developers -// Copyright (c) 2016-2021 The Hush developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/zush b/src/zush index 5aefa7a9e..d464315e5 100755 --- a/src/zush +++ b/src/zush @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # set working directory to the location of this script # readlink -f does not always exist diff --git a/toolchain-info.sh b/toolchain-info.sh index 5dca7ab6e..c475653a4 100755 --- a/toolchain-info.sh +++ b/toolchain-info.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html #TODO: detect other versions of gcc/clang diff --git a/util/afl/afl-build.sh b/util/afl/afl-build.sh index 74d5980ce..38df90ad3 100755 --- a/util/afl/afl-build.sh +++ b/util/afl/afl-build.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # A wrapper around ./util/build.sh for instrumenting the build with AFL: diff --git a/util/afl/afl-get.sh b/util/afl/afl-get.sh index 0156b5105..0697d036c 100755 --- a/util/afl/afl-get.sh +++ b/util/afl/afl-get.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # Obtains and builds a copy of AFL from source. diff --git a/util/afl/afl-getbuildrun.sh b/util/afl/afl-getbuildrun.sh index 5bd1986f9..7d6c21cad 100755 --- a/util/afl/afl-getbuildrun.sh +++ b/util/afl/afl-getbuildrun.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # Builds AFL and an instrumented hushd, then begins fuzzing. diff --git a/util/afl/afl-run.sh b/util/afl/afl-run.sh index 69e8cd9fd..4c8ed2d48 100755 --- a/util/afl/afl-run.sh +++ b/util/afl/afl-run.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/util/build-arm.sh b/util/build-arm.sh index a9b747354..36204427c 100755 --- a/util/build-arm.sh +++ b/util/build-arm.sh @@ -1,6 +1,6 @@ #!/bin/bash # Copyright (c) 2019-2020 radix42 -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Original aarch64 port by radix42. Thank you! # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/util/build-debian-package.sh b/util/build-debian-package.sh index 271ccfb2a..ad88ac90f 100755 --- a/util/build-debian-package.sh +++ b/util/build-debian-package.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html ## Usage: ./util/build-debian-package.sh diff --git a/util/build-mac.sh b/util/build-mac.sh index 1418e9d53..cb475cd41 100755 --- a/util/build-mac.sh +++ b/util/build-mac.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/util/build-win.sh b/util/build-win.sh index 2e573281b..a5b865046 100755 --- a/util/build-win.sh +++ b/util/build-win.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html export HOST=x86_64-w64-mingw32 diff --git a/util/checkpoints.pl b/util/checkpoints.pl index 25cf5e3ad..f0c84726b 100755 --- a/util/checkpoints.pl +++ b/util/checkpoints.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html use warnings; diff --git a/util/docker-entrypoint.sh b/util/docker-entrypoint.sh index 38009eae8..38e0bcfb9 100755 --- a/util/docker-entrypoint.sh +++ b/util/docker-entrypoint.sh @@ -1,5 +1,5 @@ #!/bin/bash -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/util/gen-manpages.sh b/util/gen-manpages.sh index bb2f48f5d..fadeed274 100755 --- a/util/gen-manpages.sh +++ b/util/gen-manpages.sh @@ -1,5 +1,5 @@ #!/bin/sh -# Copyright (c) 2016-2021 The Hush developers +# Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 TOPDIR=${TOPDIR:-$(git rev-parse --show-toplevel)} From d5112907b47168c12f3a8622387d65ce523f51e4 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 15:49:44 -0700 Subject: [PATCH 223/255] Write script to update copyrights --- util/update-copyrights.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 util/update-copyrights.sh diff --git a/util/update-copyrights.sh b/util/update-copyrights.sh new file mode 100755 index 000000000..b243d40e7 --- /dev/null +++ b/util/update-copyrights.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# Copyright (c) 2016-2022 The Hush developers +# Released under the GPLv3 + +# Usage: update-copyrights.sh 2021 2022 +# TODO: verify $1 and $2 exist +# TODO: verify ack and xargs exist on this system + +ack -l -i "201.-202.*Hush dev" | xargs ./util/replace.pl -$1 -$2 From b7b269448f98daf2da7ad00fd1f25720a6c83185 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 15:54:01 -0700 Subject: [PATCH 224/255] Update copyrights that have an initial year of 2020 or later --- src/stratum.cpp | 6 +++--- src/stratum.h | 4 ++-- util/update-copyrights.sh | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/stratum.cpp b/src/stratum.cpp index cf5ee5ac6..287cd609d 100644 --- a/src/stratum.cpp +++ b/src/stratum.cpp @@ -1,6 +1,6 @@ -// Copyright (c) 2021-2021 The Hush developers -// Copyright (c) 2020-2021 The Freicoin Developers -// Copyright (c) 2021-2021 Decker +// Copyright (c) 2021-2022 The Hush developers +// Copyright (c) 2020-2022 The Freicoin Developers +// Copyright (c) 2021-2022 Decker // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. diff --git a/src/stratum.h b/src/stratum.h index 56dc52056..0abcbbaf7 100644 --- a/src/stratum.h +++ b/src/stratum.h @@ -1,5 +1,5 @@ -// Copyright (c) 2021-2021 The Hush developers -// Copyright (c) 2020-2021 The Freicoin Developers +// Copyright (c) 2021-2022 The Hush developers +// Copyright (c) 2020-2022 The Freicoin Developers // This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. diff --git a/util/update-copyrights.sh b/util/update-copyrights.sh index b243d40e7..ba9a9c5e3 100755 --- a/util/update-copyrights.sh +++ b/util/update-copyrights.sh @@ -6,4 +6,4 @@ # TODO: verify $1 and $2 exist # TODO: verify ack and xargs exist on this system -ack -l -i "201.-202.*Hush dev" | xargs ./util/replace.pl -$1 -$2 +ack -l -i "20..-20..*Hush dev" | xargs ./util/replace.pl -$1 -$2 From f02a81fa4c34bc8ac2dafad0fd46261c7b21139b Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 16:02:05 -0700 Subject: [PATCH 225/255] Also update COPYRIGHT_YEAR in clientversion.h and teach update-copyrights.sh how to do it --- src/clientversion.h | 2 +- util/update-copyrights.sh | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/clientversion.h b/src/clientversion.h index bc2ab199f..6b805fdc4 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -40,7 +40,7 @@ * Copyright year (2009-this) * Todo: update this when changing our copyright comments in the source */ -#define COPYRIGHT_YEAR 2021 +#define COPYRIGHT_YEAR 2022 #endif //HAVE_CONFIG_H diff --git a/util/update-copyrights.sh b/util/update-copyrights.sh index ba9a9c5e3..f4b1ce2ae 100755 --- a/util/update-copyrights.sh +++ b/util/update-copyrights.sh @@ -6,4 +6,8 @@ # TODO: verify $1 and $2 exist # TODO: verify ack and xargs exist on this system +# This update comments in soure code ack -l -i "20..-20..*Hush dev" | xargs ./util/replace.pl -$1 -$2 + +# This updates the define which is used by C++ help output +./util/replace.pl "COPYRIGHT_YEAR $1" "COPYRIGHT_YEAR $2" src/clientversion.h From 86a2c1c73ccc5d6d65e36c19e79ad3512d4d20d4 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 16:10:02 -0700 Subject: [PATCH 226/255] Lern 2 spel --- util/update-copyrights.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/update-copyrights.sh b/util/update-copyrights.sh index f4b1ce2ae..5a5c09cb1 100755 --- a/util/update-copyrights.sh +++ b/util/update-copyrights.sh @@ -6,7 +6,7 @@ # TODO: verify $1 and $2 exist # TODO: verify ack and xargs exist on this system -# This update comments in soure code +# This update comments in source code ack -l -i "20..-20..*Hush dev" | xargs ./util/replace.pl -$1 -$2 # This updates the define which is used by C++ help output From 2a8dbbad7b2c888f3860803888699504ea2eefdf Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 16:30:39 -0700 Subject: [PATCH 227/255] Make shell scripts more portable by using /usr/bin/env bash --- contrib/fresh_clone_compile_and_run.sh | 2 +- contrib/gitian-descriptors/gitian-linux.yml | 4 ++-- contrib/gitian-descriptors/gitian-osx-signer.yml | 2 +- contrib/gitian-descriptors/gitian-osx.yml | 4 ++-- contrib/gitian-descriptors/gitian-win.yml | 8 ++++---- contrib/init/hushd.init | 2 +- contrib/snapshot/airdrop_hush3.sh | 2 +- contrib/snapshot/testnet_airdrop_hush3.sh | 2 +- contrib/tidy_datadir.sh | 2 +- contrib/verify-commits/pre-push-hook.sh | 2 +- contrib/verify-commits/verify-commits.sh | 2 +- contrib/verifysfbinaries/verify.sh | 2 +- migratecoin.sh | 2 +- qa/hush/checksec.sh | 2 +- qa/pull-tester/cc-tests.sh | 2 +- qa/pull-tester/rpc-tests.sh | 2 +- qa/pull-tester/run-bitcoin-cli | 2 +- qa/pull-tester/run-bitcoind-for-test.sh.in | 2 +- qa/pull-tester/tests-config.sh.in | 2 +- src/assetchains_stop | 2 +- src/cc/makecclib | 2 +- src/purge | 2 +- src/sc/hush | 2 +- src/sc/koolaid | 2 +- src/sc/kush | 2 +- src/sc/zex | 2 +- src/smartchains | 2 +- src/smartchains.old | 2 +- src/tush-cli | 2 +- src/zush | 2 +- test_randomx | 2 +- toolchain-info.sh | 2 +- util/build-arm.sh | 2 +- util/build-debian-package.sh | 2 +- util/build-mac.sh | 2 +- util/build-win.sh | 2 +- util/docker-entrypoint.sh | 2 +- util/docker-hush-cli.sh | 2 +- util/gen-linux-binary-release.sh | 2 +- 39 files changed, 44 insertions(+), 44 deletions(-) diff --git a/contrib/fresh_clone_compile_and_run.sh b/contrib/fresh_clone_compile_and_run.sh index 9f92a0ca6..4e481822f 100644 --- a/contrib/fresh_clone_compile_and_run.sh +++ b/contrib/fresh_clone_compile_and_run.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/contrib/gitian-descriptors/gitian-linux.yml b/contrib/gitian-descriptors/gitian-linux.yml index 317bd8694..da8be060b 100644 --- a/contrib/gitian-descriptors/gitian-linux.yml +++ b/contrib/gitian-descriptors/gitian-linux.yml @@ -53,7 +53,7 @@ script: | function create_global_faketime_wrappers { for prog in ${FAKETIME_PROGS}; do - echo '#!/bin/bash' > ${WRAP_DIR}/${prog} + echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${prog} echo "REAL=\`which -a ${prog} | grep -v ${WRAP_DIR}/${prog} | head -1\`" >> ${WRAP_DIR}/${prog} echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${prog} echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${prog} @@ -65,7 +65,7 @@ script: | function create_per-host_faketime_wrappers { for i in $HOSTS; do for prog in ${FAKETIME_HOST_PROGS}; do - echo '#!/bin/bash' > ${WRAP_DIR}/${i}-${prog} + echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}-${prog} echo "REAL=\`which -a ${i}-${prog} | grep -v ${WRAP_DIR}/${i}-${prog} | head -1\`" >> ${WRAP_DIR}/${i}-${prog} echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${i}-${prog} echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${i}-${prog} diff --git a/contrib/gitian-descriptors/gitian-osx-signer.yml b/contrib/gitian-descriptors/gitian-osx-signer.yml index b00eb2fb9..73a2f12f3 100644 --- a/contrib/gitian-descriptors/gitian-osx-signer.yml +++ b/contrib/gitian-descriptors/gitian-osx-signer.yml @@ -20,7 +20,7 @@ script: | # Create global faketime wrappers for prog in ${FAKETIME_PROGS}; do - echo '#!/bin/bash' > ${WRAP_DIR}/${prog} + echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${prog} echo "REAL=\`which -a ${prog} | grep -v ${WRAP_DIR}/${prog} | head -1\`" >> ${WRAP_DIR}/${prog} echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${prog} echo "export FAKETIME=\"${REFERENCE_DATETIME}\"" >> ${WRAP_DIR}/${prog} diff --git a/contrib/gitian-descriptors/gitian-osx.yml b/contrib/gitian-descriptors/gitian-osx.yml index 794a82af8..4d5a8736f 100644 --- a/contrib/gitian-descriptors/gitian-osx.yml +++ b/contrib/gitian-descriptors/gitian-osx.yml @@ -48,7 +48,7 @@ script: | function create_global_faketime_wrappers { for prog in ${FAKETIME_PROGS}; do - echo '#!/bin/bash' > ${WRAP_DIR}/${prog} + echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${prog} echo "REAL=\`which -a ${prog} | grep -v ${WRAP_DIR}/${prog} | head -1\`" >> ${WRAP_DIR}/${prog} echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${prog} echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${prog} @@ -60,7 +60,7 @@ script: | function create_per-host_faketime_wrappers { for i in $HOSTS; do for prog in ${FAKETIME_HOST_PROGS}; do - echo '#!/bin/bash' > ${WRAP_DIR}/${i}-${prog} + echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}-${prog} echo "REAL=\`which -a ${i}-${prog} | grep -v ${WRAP_DIR}/${i}-${prog} | head -1\`" >> ${WRAP_DIR}/${i}-${prog} echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${i}-${prog} echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${i}-${prog} diff --git a/contrib/gitian-descriptors/gitian-win.yml b/contrib/gitian-descriptors/gitian-win.yml index 44fc4e356..cab6187fa 100644 --- a/contrib/gitian-descriptors/gitian-win.yml +++ b/contrib/gitian-descriptors/gitian-win.yml @@ -47,7 +47,7 @@ script: | function create_global_faketime_wrappers { for prog in ${FAKETIME_PROGS}; do - echo '#!/bin/bash' > ${WRAP_DIR}/${prog} + echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${prog} echo "REAL=\`which -a ${prog} | grep -v ${WRAP_DIR}/${prog} | head -1\`" >> ${WRAP_DIR}/${prog} echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${prog} echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${prog} @@ -59,7 +59,7 @@ script: | function create_per-host_faketime_wrappers { for i in $HOSTS; do for prog in ${FAKETIME_HOST_PROGS}; do - echo '#!/bin/bash' > ${WRAP_DIR}/${i}-${prog} + echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}-${prog} echo "REAL=\`which -a ${i}-${prog} | grep -v ${WRAP_DIR}/${i}-${prog} | head -1\`" >> ${WRAP_DIR}/${i}-${prog} echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${i}-${prog} echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${i}-${prog} @@ -75,14 +75,14 @@ script: | for i in $HOSTS; do mkdir -p ${WRAP_DIR}/${i} for prog in collect2; do - echo '#!/bin/bash' > ${WRAP_DIR}/${i}/${prog} + echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}/${prog} REAL=$(${i}-gcc -print-prog-name=${prog}) echo "export MALLOC_PERTURB_=255" >> ${WRAP_DIR}/${i}/${prog} echo "${REAL} \$@" >> $WRAP_DIR/${i}/${prog} chmod +x ${WRAP_DIR}/${i}/${prog} done for prog in gcc g++; do - echo '#!/bin/bash' > ${WRAP_DIR}/${i}-${prog} + echo '#!/usr/bin/env bash' > ${WRAP_DIR}/${i}-${prog} echo "REAL=\`which -a ${i}-${prog} | grep -v ${WRAP_DIR}/${i}-${prog} | head -1\`" >> ${WRAP_DIR}/${i}-${prog} echo 'export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/faketime/libfaketime.so.1' >> ${WRAP_DIR}/${i}-${prog} echo "export FAKETIME=\"$1\"" >> ${WRAP_DIR}/${i}-${prog} diff --git a/contrib/init/hushd.init b/contrib/init/hushd.init index 225a5ea2a..370aaf101 100644 --- a/contrib/init/hushd.init +++ b/contrib/init/hushd.init @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # hushd The hush core server. # diff --git a/contrib/snapshot/airdrop_hush3.sh b/contrib/snapshot/airdrop_hush3.sh index 87a68369c..c3ee8b700 100755 --- a/contrib/snapshot/airdrop_hush3.sh +++ b/contrib/snapshot/airdrop_hush3.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # This code inspired by and dedicated to Decker echo "Airdropping funds to HUSH3, hold onto your butts..." diff --git a/contrib/snapshot/testnet_airdrop_hush3.sh b/contrib/snapshot/testnet_airdrop_hush3.sh index fd20926d4..33dee5a1a 100755 --- a/contrib/snapshot/testnet_airdrop_hush3.sh +++ b/contrib/snapshot/testnet_airdrop_hush3.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # This code inspired by and dedicated to Decker echo "Airdropping funds to HUSH3, hold onto your butts..." diff --git a/contrib/tidy_datadir.sh b/contrib/tidy_datadir.sh index 6e5300394..7cc5b3834 100755 --- a/contrib/tidy_datadir.sh +++ b/contrib/tidy_datadir.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2018-2020 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/contrib/verify-commits/pre-push-hook.sh b/contrib/verify-commits/pre-push-hook.sh index c572517e9..1c98dc9a8 100755 --- a/contrib/verify-commits/pre-push-hook.sh +++ b/contrib/verify-commits/pre-push-hook.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/contrib/verify-commits/verify-commits.sh b/contrib/verify-commits/verify-commits.sh index 74216fbd2..275e6cb00 100755 --- a/contrib/verify-commits/verify-commits.sh +++ b/contrib/verify-commits/verify-commits.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/contrib/verifysfbinaries/verify.sh b/contrib/verifysfbinaries/verify.sh index 3eb469388..67af138cb 100755 --- a/contrib/verifysfbinaries/verify.sh +++ b/contrib/verifysfbinaries/verify.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash ### This script attempts to download the signature file SHA256SUMS.asc from bitcoin.org ### It first checks if the signature passes, and then downloads the files specified in diff --git a/migratecoin.sh b/migratecoin.sh index f34215197..a32d30a5f 100644 --- a/migratecoin.sh +++ b/migratecoin.sh @@ -1,4 +1,4 @@ -#!/usr/bin/bash +#!/usr/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/qa/hush/checksec.sh b/qa/hush/checksec.sh index dd1f72e54..2a4897030 100755 --- a/qa/hush/checksec.sh +++ b/qa/hush/checksec.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # The BSD License (http://www.opensource.org/licenses/bsd-license.php) # specifies the terms and conditions of use for checksec.sh: diff --git a/qa/pull-tester/cc-tests.sh b/qa/pull-tester/cc-tests.sh index d68671e12..bfce8ff74 100755 --- a/qa/pull-tester/cc-tests.sh +++ b/qa/pull-tester/cc-tests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash set -e -o pipefail CURDIR=$(cd $(dirname "$0"); pwd) diff --git a/qa/pull-tester/rpc-tests.sh b/qa/pull-tester/rpc-tests.sh index 3bafe170c..07e123b6f 100755 --- a/qa/pull-tester/rpc-tests.sh +++ b/qa/pull-tester/rpc-tests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 diff --git a/qa/pull-tester/run-bitcoin-cli b/qa/pull-tester/run-bitcoin-cli index 2e7b326af..c7f09ce8a 100755 --- a/qa/pull-tester/run-bitcoin-cli +++ b/qa/pull-tester/run-bitcoin-cli @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 diff --git a/qa/pull-tester/run-bitcoind-for-test.sh.in b/qa/pull-tester/run-bitcoind-for-test.sh.in index 4527dff7b..40b6683ad 100755 --- a/qa/pull-tester/run-bitcoind-for-test.sh.in +++ b/qa/pull-tester/run-bitcoind-for-test.sh.in @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # THIS FILE IS GENERATED FROM run-bitcoind-for-test.sh.in # Copyright (c) 2013-2014 The Bitcoin Core developers # Copyright (c) 2016-2022 The Hush developers diff --git a/qa/pull-tester/tests-config.sh.in b/qa/pull-tester/tests-config.sh.in index 824b9d2a1..6718ffbc1 100755 --- a/qa/pull-tester/tests-config.sh.in +++ b/qa/pull-tester/tests-config.sh.in @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # THIS FILE IS GENERATED FROM tests-config.sh.in # Copyright (c) 2013-2014 The Bitcoin Core developers # Copyright (c) 2016-2022 The Hush developers diff --git a/src/assetchains_stop b/src/assetchains_stop index e5ccc0fcb..e20e4f89a 100755 --- a/src/assetchains_stop +++ b/src/assetchains_stop @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers set -eo pipefail hush_cli='./hush-cli' diff --git a/src/cc/makecclib b/src/cc/makecclib index c115cd0c1..dc389ecaf 100755 --- a/src/cc/makecclib +++ b/src/cc/makecclib @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/purge b/src/purge index d34b6f72b..6b037f221 100755 --- a/src/purge +++ b/src/purge @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 diff --git a/src/sc/hush b/src/sc/hush index 9ac3edcd4..53fd07fe0 100755 --- a/src/sc/hush +++ b/src/sc/hush @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2018-2020 The Hush developers #set working directory to the location of this script DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" diff --git a/src/sc/koolaid b/src/sc/koolaid index 5c3543ecf..3d9835cb7 100755 --- a/src/sc/koolaid +++ b/src/sc/koolaid @@ -1,3 +1,3 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2018-2020 The Hush developers ./hush-smart-chain -ac_name=KOOLAID $@ diff --git a/src/sc/kush b/src/sc/kush index b39a0d5fd..716848019 100755 --- a/src/sc/kush +++ b/src/sc/kush @@ -1,3 +1,3 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2018-2020 The Hush developers ./hush-smart-chain -ac_name=KUSH $@ diff --git a/src/sc/zex b/src/sc/zex index 2c95cf1a9..56b2975af 100755 --- a/src/sc/zex +++ b/src/sc/zex @@ -1,3 +1,3 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2018-2020 The Hush developers ./hush-smart-chain -ac_name=ZEX $@ diff --git a/src/smartchains b/src/smartchains index 68a340bb9..d457637fe 100755 --- a/src/smartchains +++ b/src/smartchains @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2018-2022 The Hush developers set -eo pipefail diff --git a/src/smartchains.old b/src/smartchains.old index 3a369677f..8a5aff049 100755 --- a/src/smartchains.old +++ b/src/smartchains.old @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2018-2020 The Hush developers set -x delay=60 diff --git a/src/tush-cli b/src/tush-cli index d2442d3fb..248094b68 100755 --- a/src/tush-cli +++ b/src/tush-cli @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # set working directory to the location of this script diff --git a/src/zush b/src/zush index d464315e5..d9bb30f4f 100755 --- a/src/zush +++ b/src/zush @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # set working directory to the location of this script diff --git a/test_randomx b/test_randomx index df45890d8..bc41bb85c 100755 --- a/test_randomx +++ b/test_randomx @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # any CLI args given to this script will be passed along # example: ./test_randomx -debug=randomx diff --git a/toolchain-info.sh b/toolchain-info.sh index c475653a4..68445ca40 100755 --- a/toolchain-info.sh +++ b/toolchain-info.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/util/build-arm.sh b/util/build-arm.sh index 36204427c..f22ed7acf 100755 --- a/util/build-arm.sh +++ b/util/build-arm.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2019-2020 radix42 # Copyright (c) 2016-2022 The Hush developers # Original aarch64 port by radix42. Thank you! diff --git a/util/build-debian-package.sh b/util/build-debian-package.sh index ad88ac90f..745273231 100755 --- a/util/build-debian-package.sh +++ b/util/build-debian-package.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/util/build-mac.sh b/util/build-mac.sh index cb475cd41..c86b6cef4 100755 --- a/util/build-mac.sh +++ b/util/build-mac.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/util/build-win.sh b/util/build-win.sh index a5b865046..8fdcee6d7 100755 --- a/util/build-win.sh +++ b/util/build-win.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/util/docker-entrypoint.sh b/util/docker-entrypoint.sh index 38e0bcfb9..0607b1f25 100755 --- a/util/docker-entrypoint.sh +++ b/util/docker-entrypoint.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/util/docker-hush-cli.sh b/util/docker-hush-cli.sh index 9c2c11cee..edd8f7e7d 100755 --- a/util/docker-hush-cli.sh +++ b/util/docker-hush-cli.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2019-2020 Hush developers /hush/src/hush-cli $@ diff --git a/util/gen-linux-binary-release.sh b/util/gen-linux-binary-release.sh index cd4cec2b7..d3df4b618 100755 --- a/util/gen-linux-binary-release.sh +++ b/util/gen-linux-binary-release.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright (c) 2016-2022 The Hush developers # Released under the GPLv3 From b41ff1b0da44d9b5a61aa65599aa9d652bfbe178 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Mon, 19 Sep 2022 16:32:46 -0700 Subject: [PATCH 228/255] Make block_time.pl more portable --- contrib/block_time.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/block_time.pl b/contrib/block_time.pl index cb11ed239..9e980ea29 100755 --- a/contrib/block_time.pl +++ b/contrib/block_time.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/bin/env perl # Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html From 44e1836e52d83688930fb56f741347c2abe34330 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 21:49:49 -0400 Subject: [PATCH 229/255] Make this script executable --- contrib/fresh_clone_compile_and_run.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 contrib/fresh_clone_compile_and_run.sh diff --git a/contrib/fresh_clone_compile_and_run.sh b/contrib/fresh_clone_compile_and_run.sh old mode 100644 new mode 100755 From 27736e80aee9849579ef9ee3d7528ec2c1807c3e Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 22:05:18 -0400 Subject: [PATCH 230/255] Make this script take the branch and number of jobs as args --- contrib/fresh_clone_compile_and_run.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/contrib/fresh_clone_compile_and_run.sh b/contrib/fresh_clone_compile_and_run.sh index 4e481822f..71a12c124 100755 --- a/contrib/fresh_clone_compile_and_run.sh +++ b/contrib/fresh_clone_compile_and_run.sh @@ -2,18 +2,24 @@ # Copyright (c) 2016-2022 The Hush developers # Distributed under the GPLv3 software license, see the accompanying # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html -# OPEN BOUNTY -# Send your CPU and RAM and time it takes to sync a HUSH full node for -# 5 HUSH as thanks for decentralized performance testing + +# Usage: $0 BRANCH JOBS + +BRANCH=$1 + git clone https://git.hush.is/hush/hush3 cd hush3 +git checkout $BRANCH # Build with 2 cores # You need 2GB of RAM per core, don't use too many # (GB of RAM)/2 - 1 is the optimal core count for compiling Hush # `nproc` tells you how many cores you have -JOBS=2 +JOBS=$2 +JOBZ=$(nproc) # if build.sh fails, we can use many more jobs with make # Want to fix this parrallel-only build system bug we inherited ? you are a new hush dev -./build.sh -j$JOBS;make -j$JOBS;make -j$JOBS;make -j$JOBS +# Sometimes the parrallel build fails because of a race condition, so +# we do it a few times to Make Really Sure +./build.sh -j$JOBS;make -j$JOBZ;make -j$JOBZ;make -j$JOBZ ./src/hushd &> hush.log & # You can give the entire or parts of this file to Hush developers for debugging, # but there is a lot of metadata!!! We don't want any more than we need to fix bugz From 4b2135f15697ad66ffc951531b91c3991decd852 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 22:09:37 -0400 Subject: [PATCH 231/255] Add some basic error-checking --- contrib/fresh_clone_compile_and_run.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/fresh_clone_compile_and_run.sh b/contrib/fresh_clone_compile_and_run.sh index 71a12c124..bc0364cf9 100755 --- a/contrib/fresh_clone_compile_and_run.sh +++ b/contrib/fresh_clone_compile_and_run.sh @@ -4,13 +4,15 @@ # file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html # Usage: $0 BRANCH JOBS +# TODO: default to master branch with 2 jobs + +set -eu -o pipefail BRANCH=$1 git clone https://git.hush.is/hush/hush3 cd hush3 git checkout $BRANCH -# Build with 2 cores # You need 2GB of RAM per core, don't use too many # (GB of RAM)/2 - 1 is the optimal core count for compiling Hush # `nproc` tells you how many cores you have From 669447ba24b7344611225a01b6cbbad5071dec3d Mon Sep 17 00:00:00 2001 From: jahway603 Date: Mon, 19 Sep 2022 22:11:12 -0400 Subject: [PATCH 232/255] added cmake check for build-arm.sh --- util/build-arm.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/util/build-arm.sh b/util/build-arm.sh index f22ed7acf..16b195520 100755 --- a/util/build-arm.sh +++ b/util/build-arm.sh @@ -7,6 +7,12 @@ set -eu -o pipefail +# Check if cmake, a new dependency for randomx support, is installed on system and exits if it is not +if ! [ -x "$(command -v cmake)" ]; then + echo 'Error: cmake is not installed. Install cmake and try again.' >&2 + exit 1 +fi + cat <<'EOF' .~~~~~~~~~~~~~~~~. {{ Building Hush!! }} From 9e719cf3e70429a6049bf663269b4acfcc803647 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Mon, 19 Sep 2022 22:22:11 -0400 Subject: [PATCH 233/255] Live dangerously since we don't care about intermittent build.sh failures --- contrib/fresh_clone_compile_and_run.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/fresh_clone_compile_and_run.sh b/contrib/fresh_clone_compile_and_run.sh index bc0364cf9..a895f3cc3 100755 --- a/contrib/fresh_clone_compile_and_run.sh +++ b/contrib/fresh_clone_compile_and_run.sh @@ -6,7 +6,8 @@ # Usage: $0 BRANCH JOBS # TODO: default to master branch with 2 jobs -set -eu -o pipefail +# we don't want this for our build.sh and make commands +#set -eu -o pipefail BRANCH=$1 From e836a3c0c61d1fff910e1391504cc97a1e511ba4 Mon Sep 17 00:00:00 2001 From: jahway603 Date: Tue, 20 Sep 2022 01:21:13 -0400 Subject: [PATCH 234/255] fixed help2man check --- util/gen-manpages.sh | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/util/gen-manpages.sh b/util/gen-manpages.sh index fadeed274..8729932ab 100755 --- a/util/gen-manpages.sh +++ b/util/gen-manpages.sh @@ -11,17 +11,8 @@ HUSHCLI=${HUSHCLI:-$SRCDIR/hush-cli} HUSHTX=${HUSHTX:-$SRCDIR/hush-tx} [ ! -x $HUSHD ] && echo "$HUSHD not found or not executable." && exit 1 - -# TODO: this does not work correctly, when help2man is installed, it still fails -# Check if help2man is installed -# If not then display error to user and exit -#if ! command -v help2man &> /dev/null -#then -# echo "help2man could not be found" -# echo "Please install from your Linux package manager and try again" -# echo "On Debian-based systems you can do: apt-get install help2man" -# exit -#fi +# Check if help2man is installed & if not then display error to user and exit +[ ! -x "$(command -v help2man)" ] && echo "help2man could not be found" && echo "Please install from your Linux package manager and try again" && echo "On Debian-based systems you can do: apt-get install help2man" && exit 1 # use this if hushd is not running #HUSHVER="v3.6.2" From ab83649c1a1271fa777c8abffc884ef65ce3aabe Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 21 Sep 2022 09:04:32 -0400 Subject: [PATCH 235/255] Add gen-zaddrs.pl and improve docs --- contrib/README.md | 20 ++++++++++++++++++-- contrib/gen-zaddrs.pl | 17 +++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100755 contrib/gen-zaddrs.pl diff --git a/contrib/README.md b/contrib/README.md index ed2c7408b..36c04c969 100644 --- a/contrib/README.md +++ b/contrib/README.md @@ -6,9 +6,25 @@ Do not expect all scripts to work! Please fix bugs and report things you find. -## Hush Tools +# Hush Tools + +## block\_time.pl + +Estimate when a Hush block will happen. + +Example: + + ./contrib/block_time.pl 123456 # Print out datetime of when block height 123456 happens + +## gen-zaddrs.pl + +Generate zaddrs in bulk, by default 50 at a time. Prints out a zaddr one per line. + +Example: + + ./contrib/gen-zaddrs.pl # generate 50 zaddrs + ./contrib/gen-zaddrs.pl 500 # generate 500 zaddrs -block\_time.pl - estimate when a Hush block will happen ## Wallet Tools diff --git a/contrib/gen-zaddrs.pl b/contrib/gen-zaddrs.pl new file mode 100755 index 000000000..ccf8e8e78 --- /dev/null +++ b/contrib/gen-zaddrs.pl @@ -0,0 +1,17 @@ +#!/usr/bin/env perl +# Copyright 2019-2022 The Hush developers +# Released under the GPLv3 +use warnings; +use strict; + +my $hush = "./src/hush-cli"; +my $znew = "$hush z_getnewaddress"; +my $count = 1; +my $howmany = shift || 50; + +while ($count < $howmany) { + my $zaddr = qx{$znew}; + chomp($zaddr); + print qq{$zaddr\n}; + $count++; +} From 005f1e00bcf850ae0e6be2bf1083afa877600ed2 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 21 Sep 2022 08:38:10 -0700 Subject: [PATCH 236/255] Update copyrights --- src/hush_defs.h | 2 +- src/pow/tromp/equi.h | 2 +- src/sc/hush | 2 +- src/sc/koolaid | 2 +- src/sc/kush | 2 +- src/sc/zex | 2 +- src/sietch.h | 2 +- src/smartchains.old | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/hush_defs.h b/src/hush_defs.h index c4a0b5425..36354b909 100644 --- a/src/hush_defs.h +++ b/src/hush_defs.h @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 The Hush developers +// Copyright (c) 2019-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/pow/tromp/equi.h b/src/pow/tromp/equi.h index fd89da587..85b780ea1 100644 --- a/src/pow/tromp/equi.h +++ b/src/pow/tromp/equi.h @@ -1,4 +1,4 @@ -// Copyright (c) 2019-2020 The Hush developers +// Copyright (c) 2019-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html // Copyright (c) 2016-2016 John Tromp, The Zcash developers diff --git a/src/sc/hush b/src/sc/hush index 53fd07fe0..b730c9342 100755 --- a/src/sc/hush +++ b/src/sc/hush @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright (c) 2018-2020 The Hush developers +# Copyright (c) 2018-2022 The Hush developers #set working directory to the location of this script DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd $DIR diff --git a/src/sc/koolaid b/src/sc/koolaid index 3d9835cb7..7d705c55c 100755 --- a/src/sc/koolaid +++ b/src/sc/koolaid @@ -1,3 +1,3 @@ #!/usr/bin/env bash -# Copyright (c) 2018-2020 The Hush developers +# Copyright (c) 2018-2022 The Hush developers ./hush-smart-chain -ac_name=KOOLAID $@ diff --git a/src/sc/kush b/src/sc/kush index 716848019..ed2254506 100755 --- a/src/sc/kush +++ b/src/sc/kush @@ -1,3 +1,3 @@ #!/usr/bin/env bash -# Copyright (c) 2018-2020 The Hush developers +# Copyright (c) 2018-2022 The Hush developers ./hush-smart-chain -ac_name=KUSH $@ diff --git a/src/sc/zex b/src/sc/zex index 56b2975af..ac8947082 100755 --- a/src/sc/zex +++ b/src/sc/zex @@ -1,3 +1,3 @@ #!/usr/bin/env bash -# Copyright (c) 2018-2020 The Hush developers +# Copyright (c) 2018-2022 The Hush developers ./hush-smart-chain -ac_name=ZEX $@ diff --git a/src/sietch.h b/src/sietch.h index 689bb312a..3e6b2c87d 100644 --- a/src/sietch.h +++ b/src/sietch.h @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright © 2016-2020 The Hush developers * + * Copyright © 2016-2022 The Hush developers * * * * See the AUTHORS and LICENSE files at * * the top-level directory of this distribution for the individual copyright * diff --git a/src/smartchains.old b/src/smartchains.old index 8a5aff049..92ad9bcc8 100755 --- a/src/smartchains.old +++ b/src/smartchains.old @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# Copyright (c) 2018-2020 The Hush developers +# Copyright (c) 2018-2022 The Hush developers set -x delay=60 source pubkey.txt From f791613c706821794bfcda78c6ab7c7545ab11ce Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 21 Sep 2022 08:44:34 -0700 Subject: [PATCH 237/255] Add copyright to files missing Hush copyright lines --- src/base58.h | 1 + src/bloom.h | 1 + src/cJSON.h | 1 + src/chainparamsbase.h | 1 + src/chainparamsseeds.h | 1 + src/compat.h | 1 + src/compressor.h | 1 + src/core_io.h | 1 + src/httprpc.h | 1 + src/hush_nSPV_defs.h | 1 + src/hush_nSPV_superlite.h | 1 + src/hush_nk.h | 2 ++ src/limitedmap.h | 1 + src/memusage.h | 1 + src/merkleblock.h | 1 + src/mini-gmp.h | 1 + src/mruset.h | 1 + src/netbase.h | 1 + src/noui.h | 1 + src/random.h | 1 + src/reverselock.h | 1 + src/scheduler.h | 1 + src/spentindex.h | 3 ++- src/streams.h | 1 + src/sync.h | 1 + src/threadsafety.h | 1 + src/tinyformat.h | 1 + src/ui_interface.h | 1 + src/uint252.h | 1 + src/uint256.h | 1 + src/undo.h | 1 + src/uthash.h | 2 +- src/utilmoneystr.h | 1 + src/utilstrencodings.h | 1 + src/utiltime.h | 1 + src/utlist.h | 1 + 36 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/base58.h b/src/base58.h index 1032a4f00..423107c15 100644 --- a/src/base58.h +++ b/src/base58.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/bloom.h b/src/bloom.h index 22f3bd396..d2eabaa8f 100644 --- a/src/bloom.h +++ b/src/bloom.h @@ -1,4 +1,5 @@ // Copyright (c) 2012-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/cJSON.h b/src/cJSON.h index 2a6139680..e4a31634b 100644 --- a/src/cJSON.h +++ b/src/cJSON.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers /* Copyright (c) 2009-2017 Dave Gamble and cJSON contributors diff --git a/src/chainparamsbase.h b/src/chainparamsbase.h index 1fbdec8bd..f4fc66e92 100644 --- a/src/chainparamsbase.h +++ b/src/chainparamsbase.h @@ -1,4 +1,5 @@ // Copyright (c) 2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/chainparamsseeds.h b/src/chainparamsseeds.h index 5d539bbb7..663a9bcac 100644 --- a/src/chainparamsseeds.h +++ b/src/chainparamsseeds.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * diff --git a/src/compat.h b/src/compat.h index af902e705..045774e27 100644 --- a/src/compat.h +++ b/src/compat.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/compressor.h b/src/compressor.h index 5c6bc4381..cf4ba6a35 100644 --- a/src/compressor.h +++ b/src/compressor.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/core_io.h b/src/core_io.h index cc4445b9a..3e413e343 100644 --- a/src/core_io.h +++ b/src/core_io.h @@ -1,4 +1,5 @@ // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/httprpc.h b/src/httprpc.h index 2118d2fef..ef3a7243b 100644 --- a/src/httprpc.h +++ b/src/httprpc.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2015 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/hush_nSPV_defs.h b/src/hush_nSPV_defs.h index 71922e5ce..a52e92500 100644 --- a/src/hush_nSPV_defs.h +++ b/src/hush_nSPV_defs.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * diff --git a/src/hush_nSPV_superlite.h b/src/hush_nSPV_superlite.h index 585f905f0..f9e02bcb8 100644 --- a/src/hush_nSPV_superlite.h +++ b/src/hush_nSPV_superlite.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * diff --git a/src/hush_nk.h b/src/hush_nk.h index a0ce3cf07..3eb3ae98f 100644 --- a/src/hush_nk.h +++ b/src/hush_nk.h @@ -1,9 +1,11 @@ +// Copyright (c) 2016-2022 The Hush developers #ifndef HUSH_NK_H #define HUSH_NK_H //#define ASSETCHAINS_N 77 //#define ASSETCHAINS_K 3 +// Equihash (N,K) param defaults when using -ac_nk #define ASSETCHAINS_N 96 #define ASSETCHAINS_K 5 diff --git a/src/limitedmap.h b/src/limitedmap.h index b1b521c86..e41496ffd 100644 --- a/src/limitedmap.h +++ b/src/limitedmap.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/memusage.h b/src/memusage.h index 9f97828df..4c06ec22b 100644 --- a/src/memusage.h +++ b/src/memusage.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2015 The Bitcoin developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/merkleblock.h b/src/merkleblock.h index 1fe1683b9..fb9b925f2 100644 --- a/src/merkleblock.h +++ b/src/merkleblock.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/mini-gmp.h b/src/mini-gmp.h index 56647ee77..9b1e0c2d5 100644 --- a/src/mini-gmp.h +++ b/src/mini-gmp.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers /* mini-gmp, a minimalistic implementation of a GNU GMP subset. Copyright 2011-2015 Free Software Foundation, Inc. diff --git a/src/mruset.h b/src/mruset.h index e59c4f14c..1433198ad 100644 --- a/src/mruset.h +++ b/src/mruset.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2012-2015 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/netbase.h b/src/netbase.h index 2c7259794..e4f58614a 100644 --- a/src/netbase.h +++ b/src/netbase.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2009-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/noui.h b/src/noui.h index 8086533b4..e3ed152e4 100644 --- a/src/noui.h +++ b/src/noui.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/random.h b/src/random.h index c51f05b5d..6f8953136 100644 --- a/src/random.h +++ b/src/random.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/reverselock.h b/src/reverselock.h index e57dbca59..0fd50d651 100644 --- a/src/reverselock.h +++ b/src/reverselock.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2015 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/scheduler.h b/src/scheduler.h index 173f23211..b6fa2abc5 100644 --- a/src/scheduler.h +++ b/src/scheduler.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2015 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/spentindex.h b/src/spentindex.h index 24f266eae..f96137854 100644 --- a/src/spentindex.h +++ b/src/spentindex.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2015 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html @@ -95,4 +96,4 @@ struct CSpentIndexKeyCompare } }; -#endif // HUSH_SPENTINDEX_H \ No newline at end of file +#endif // HUSH_SPENTINDEX_H diff --git a/src/streams.h b/src/streams.h index 5c22c9bbc..247bda717 100644 --- a/src/streams.h +++ b/src/streams.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/sync.h b/src/sync.h index bdda6d166..2bbf5f826 100644 --- a/src/sync.h +++ b/src/sync.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/threadsafety.h b/src/threadsafety.h index 58f75ea69..b7c7db594 100644 --- a/src/threadsafety.h +++ b/src/threadsafety.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2012 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/tinyformat.h b/src/tinyformat.h index 4bb96953d..1dc522cf0 100644 --- a/src/tinyformat.h +++ b/src/tinyformat.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // tinyformat.h // Copyright (C) 2011, Chris Foster [chris42f (at) gmail (d0t) com] // diff --git a/src/ui_interface.h b/src/ui_interface.h index 94ed742fa..c5ace5996 100644 --- a/src/ui_interface.h +++ b/src/ui_interface.h @@ -1,5 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2012 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/uint252.h b/src/uint252.h index e7b98ddf0..08b6bd401 100644 --- a/src/uint252.h +++ b/src/uint252.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers #ifndef UINT252_H #define UINT252_H diff --git a/src/uint256.h b/src/uint256.h index 927314962..8ecca59a2 100644 --- a/src/uint256.h +++ b/src/uint256.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/undo.h b/src/undo.h index 01cb325ad..f78a168b1 100644 --- a/src/undo.h +++ b/src/undo.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/uthash.h b/src/uthash.h index 7b99c0133..1063daa0b 100644 --- a/src/uthash.h +++ b/src/uthash.h @@ -1,4 +1,4 @@ - +// Copyright (c) 2016-2022 The Hush developers /* Copyright (c) 2003-2014, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. diff --git a/src/utilmoneystr.h b/src/utilmoneystr.h index bc3bce2b3..79aafaa6a 100644 --- a/src/utilmoneystr.h +++ b/src/utilmoneystr.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers + // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/utilstrencodings.h b/src/utilstrencodings.h index fe90b9237..ae3c2c117 100644 --- a/src/utilstrencodings.h +++ b/src/utilstrencodings.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/utiltime.h b/src/utiltime.h index 8c6575844..3f4b8061a 100644 --- a/src/utiltime.h +++ b/src/utiltime.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/utlist.h b/src/utlist.h index 93c7ceef0..67ac97720 100644 --- a/src/utlist.h +++ b/src/utlist.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers /* Copyright (c) 2007-2014, Troy D. Hanson http://troydhanson.github.com/uthash/ All rights reserved. From 43ef851f8c3981e67c8db27fc68750f6620c86c6 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 21 Sep 2022 08:46:02 -0700 Subject: [PATCH 238/255] Add copyright to files missing Hush copyright lines --- src/rpc/client.h | 1 + src/rpc/protocol.cpp | 1 + src/rpc/protocol.h | 1 + src/rpc/testtransactions.cpp | 1 + 4 files changed, 4 insertions(+) diff --git a/src/rpc/client.h b/src/rpc/client.h index e0955339c..f2f02661f 100644 --- a/src/rpc/client.h +++ b/src/rpc/client.h @@ -1,5 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/rpc/protocol.cpp b/src/rpc/protocol.cpp index a43c67462..3d8553043 100644 --- a/src/rpc/protocol.cpp +++ b/src/rpc/protocol.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/rpc/protocol.h b/src/rpc/protocol.h index d8f37d9d0..a5602badf 100644 --- a/src/rpc/protocol.h +++ b/src/rpc/protocol.h @@ -1,5 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/rpc/testtransactions.cpp b/src/rpc/testtransactions.cpp index 84403f3bc..c8a7e8d96 100644 --- a/src/rpc/testtransactions.cpp +++ b/src/rpc/testtransactions.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html From 2564f6a66f4ea32fb64870b63295fc76c1593e05 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 21 Sep 2022 08:47:45 -0700 Subject: [PATCH 239/255] Add copyright to files missing Hush copyright lines --- src/script/cc.cpp | 1 + src/script/cc.h | 1 + src/script/interpreter.h | 1 + src/script/script.cpp | 1 + src/script/script.h | 1 + src/script/script_error.cpp | 1 + src/script/script_error.h | 1 + src/script/serverchecker.cpp | 1 + src/script/serverchecker.h | 1 + src/script/sigcache.cpp | 1 + src/script/sigcache.h | 1 + src/script/sign.cpp | 1 + src/script/sign.h | 1 + src/script/zcashconsensus.cpp | 1 + src/script/zcashconsensus.h | 1 + 15 files changed, 15 insertions(+) diff --git a/src/script/cc.cpp b/src/script/cc.cpp index a0770a9b2..b86497d1b 100644 --- a/src/script/cc.cpp +++ b/src/script/cc.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * diff --git a/src/script/cc.h b/src/script/cc.h index b3ee612a5..9bdfbeae5 100644 --- a/src/script/cc.h +++ b/src/script/cc.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * * * diff --git a/src/script/interpreter.h b/src/script/interpreter.h index e7cf38cb0..8baf705b8 100644 --- a/src/script/interpreter.h +++ b/src/script/interpreter.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/script/script.cpp b/src/script/script.cpp index 37ca60630..6b2fe2e30 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/script/script.h b/src/script/script.h index 1b804d4c1..104d45852 100644 --- a/src/script/script.h +++ b/src/script/script.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/script/script_error.cpp b/src/script/script_error.cpp index e555e1422..17766c488 100644 --- a/src/script/script_error.cpp +++ b/src/script/script_error.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/script/script_error.h b/src/script/script_error.h index 2219544b0..b31c0ebe6 100644 --- a/src/script/script_error.h +++ b/src/script/script_error.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/script/serverchecker.cpp b/src/script/serverchecker.cpp index 9227344ac..ec6008046 100644 --- a/src/script/serverchecker.cpp +++ b/src/script/serverchecker.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/script/serverchecker.h b/src/script/serverchecker.h index a541247b2..f6c581d40 100644 --- a/src/script/serverchecker.h +++ b/src/script/serverchecker.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/script/sigcache.cpp b/src/script/sigcache.cpp index 56733d94b..265867d99 100644 --- a/src/script/sigcache.cpp +++ b/src/script/sigcache.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/script/sigcache.h b/src/script/sigcache.h index 92406fabb..701ec78f4 100644 --- a/src/script/sigcache.h +++ b/src/script/sigcache.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/script/sign.cpp b/src/script/sign.cpp index 62785f870..56e379599 100644 --- a/src/script/sign.cpp +++ b/src/script/sign.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/script/sign.h b/src/script/sign.h index 190d23d35..a68fac011 100644 --- a/src/script/sign.h +++ b/src/script/sign.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/script/zcashconsensus.cpp b/src/script/zcashconsensus.cpp index 5119b8229..80b6cd55e 100644 --- a/src/script/zcashconsensus.cpp +++ b/src/script/zcashconsensus.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/script/zcashconsensus.h b/src/script/zcashconsensus.h index 0ccccd047..4ed1f428f 100644 --- a/src/script/zcashconsensus.h +++ b/src/script/zcashconsensus.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html From 35df2aa91f2b8517ca1418bc9f1a213d5949ccf8 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 21 Sep 2022 08:48:42 -0700 Subject: [PATCH 240/255] Add copyright to files missing Hush copyright lines --- src/wallet/db.h | 1 + src/wallet/rpcwallet.h | 1 + src/wallet/wallet_ismine.cpp | 1 + src/wallet/wallet_ismine.h | 1 + 4 files changed, 4 insertions(+) diff --git a/src/wallet/db.h b/src/wallet/db.h index 93a624eef..b9e72c64a 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/wallet/rpcwallet.h b/src/wallet/rpcwallet.h index a05d3b820..306e19570 100644 --- a/src/wallet/rpcwallet.h +++ b/src/wallet/rpcwallet.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2016 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/wallet/wallet_ismine.cpp b/src/wallet/wallet_ismine.cpp index 40b27a9d2..bad5302e3 100644 --- a/src/wallet/wallet_ismine.cpp +++ b/src/wallet/wallet_ismine.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/wallet/wallet_ismine.h b/src/wallet/wallet_ismine.h index a6a9cd550..d843aeaa3 100644 --- a/src/wallet/wallet_ismine.h +++ b/src/wallet/wallet_ismine.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html From 03e13087837b80a48a9e820d8744dda62b2ea4d1 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 21 Sep 2022 08:50:10 -0700 Subject: [PATCH 241/255] Add copyright to files missing Hush copyright lines --- src/consensus/consensus.h | 1 + src/policy/fees.cpp | 1 + src/policy/fees.h | 1 + 3 files changed, 3 insertions(+) diff --git a/src/consensus/consensus.h b/src/consensus/consensus.h index 9a998af9d..2e22952ed 100644 --- a/src/consensus/consensus.h +++ b/src/consensus/consensus.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html /****************************************************************************** diff --git a/src/policy/fees.cpp b/src/policy/fees.cpp index 160158151..39c3efa36 100644 --- a/src/policy/fees.cpp +++ b/src/policy/fees.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2015 The Bitcoin developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/policy/fees.h b/src/policy/fees.h index 92652cab5..a1346bd32 100644 --- a/src/policy/fees.h +++ b/src/policy/fees.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2015 The Bitcoin developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html From ad3a35fcba1a09c658d2baf5eb8125a65a9d1579 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 21 Sep 2022 08:54:08 -0700 Subject: [PATCH 242/255] Add copyright to files missing Hush copyright lines --- src/mini-gmp.c | 1 + src/support/cleanse.cpp | 1 + src/support/cleanse.h | 1 + src/support/events.h | 1 + src/support/pagelocker.cpp | 1 + src/support/pagelocker.h | 1 + src/util/asmap.cpp | 1 + src/util/asmap.h | 1 + src/utilmoneystr.h | 2 +- 9 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/mini-gmp.c b/src/mini-gmp.c index f9ee23f15..6bd00d349 100644 --- a/src/mini-gmp.c +++ b/src/mini-gmp.c @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers /* mini-gmp, a minimalistic implementation of a GNU GMP subset. Contributed to the GNU project by Niels Möller diff --git a/src/support/cleanse.cpp b/src/support/cleanse.cpp index 7c58c94fe..9bd282df7 100644 --- a/src/support/cleanse.cpp +++ b/src/support/cleanse.cpp @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2015 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/support/cleanse.h b/src/support/cleanse.h index dc60b3cf6..6ec05412a 100644 --- a/src/support/cleanse.h +++ b/src/support/cleanse.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2015 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/support/events.h b/src/support/events.h index 0027b5665..d00025fc6 100644 --- a/src/support/events.h +++ b/src/support/events.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2016 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/support/pagelocker.cpp b/src/support/pagelocker.cpp index 4eaa9f0ba..f7b0ea6f2 100644 --- a/src/support/pagelocker.cpp +++ b/src/support/pagelocker.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2009-2013 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/support/pagelocker.h b/src/support/pagelocker.h index 851854869..9c3d3aedb 100644 --- a/src/support/pagelocker.h +++ b/src/support/pagelocker.h @@ -1,5 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2013 The Bitcoin Core developers +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/util/asmap.cpp b/src/util/asmap.cpp index 42c139a25..e515f6b6d 100644 --- a/src/util/asmap.cpp +++ b/src/util/asmap.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2019-2020 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/util/asmap.h b/src/util/asmap.h index 470cfbebd..9dc796d6f 100644 --- a/src/util/asmap.h +++ b/src/util/asmap.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2019 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. diff --git a/src/utilmoneystr.h b/src/utilmoneystr.h index 79aafaa6a..381f7357a 100644 --- a/src/utilmoneystr.h +++ b/src/utilmoneystr.h @@ -1,6 +1,6 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2014 The Bitcoin Core developers - +// Copyright (c) 2016-2022 The Hush developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html From ea93a31c093e9c5abc70084d24579df6bea39e52 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 21 Sep 2022 08:56:10 -0700 Subject: [PATCH 243/255] Add copyright to files missing Hush copyright lines --- src/hush_cJSON.c | 1 + util/afl/hush-wrapper | 1 + util/test-security-check.py | 1 + 3 files changed, 3 insertions(+) diff --git a/src/hush_cJSON.c b/src/hush_cJSON.c index facf79f2a..1b996e881 100644 --- a/src/hush_cJSON.c +++ b/src/hush_cJSON.c @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers /* Copyright (c) 2009 Dave Gamble diff --git a/util/afl/hush-wrapper b/util/afl/hush-wrapper index d316cae74..210ef1f01 100755 --- a/util/afl/hush-wrapper +++ b/util/afl/hush-wrapper @@ -1,4 +1,5 @@ #!/usr/bin/env bash +# Copyright (c) 2016-2022 The Hush developers set -ex -o pipefail diff --git a/util/test-security-check.py b/util/test-security-check.py index 324b7bcd8..0fee542ca 100755 --- a/util/test-security-check.py +++ b/util/test-security-check.py @@ -1,4 +1,5 @@ #!/usr/bin/env python2 +# Copyright (c) 2016-2022 The Hush developers ''' Test script for security-check.py ''' From 6e6dfabbe2103c537bfa186a141e1c4a912a3cb4 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 21 Sep 2022 08:57:41 -0700 Subject: [PATCH 244/255] Add copyright to files missing Hush copyright lines --- src/cc/games/tetris.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cc/games/tetris.cpp b/src/cc/games/tetris.cpp index cd609154d..fc1830686 100644 --- a/src/cc/games/tetris.cpp +++ b/src/cc/games/tetris.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers /****************************************************************************** * Copyright © 2014-2019 The SuperNET Developers. * From 1e40d2711db80a6d0a35d7430868bd208f4bd89e Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Wed, 21 Sep 2022 08:59:19 -0700 Subject: [PATCH 245/255] Add copyright to files missing Hush copyright lines --- src/crypto/common.h | 1 + src/crypto/equihash.cpp | 1 + src/crypto/hmac_sha256.cpp | 1 + src/crypto/hmac_sha256.h | 1 + src/crypto/hmac_sha512.cpp | 1 + src/crypto/hmac_sha512.h | 1 + src/crypto/ripemd160.cpp | 1 + src/crypto/ripemd160.h | 1 + src/crypto/sha1.cpp | 1 + src/crypto/sha1.h | 1 + src/crypto/sha256.cpp | 1 + src/crypto/sha256.h | 1 + src/crypto/sha256_sse4.cpp | 1 + src/crypto/sha512.cpp | 1 + src/crypto/sha512.h | 1 + 15 files changed, 15 insertions(+) diff --git a/src/crypto/common.h b/src/crypto/common.h index d07ff0730..2b6be0901 100644 --- a/src/crypto/common.h +++ b/src/crypto/common.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Copyright (c) 2016-2022 The Hush developers // Released under the GPLv3 diff --git a/src/crypto/equihash.cpp b/src/crypto/equihash.cpp index 07f82bcbe..9dc920212 100644 --- a/src/crypto/equihash.cpp +++ b/src/crypto/equihash.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2016 Jack Grigg // Copyright (c) 2016 The Zcash developers // Distributed under the GPLv3 software license, see the accompanying diff --git a/src/crypto/hmac_sha256.cpp b/src/crypto/hmac_sha256.cpp index 9e7863239..61622d9e4 100644 --- a/src/crypto/hmac_sha256.cpp +++ b/src/crypto/hmac_sha256.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/crypto/hmac_sha256.h b/src/crypto/hmac_sha256.h index 63daebb2a..1847e78d1 100644 --- a/src/crypto/hmac_sha256.h +++ b/src/crypto/hmac_sha256.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/crypto/hmac_sha512.cpp b/src/crypto/hmac_sha512.cpp index cc1b33be1..c4409613c 100644 --- a/src/crypto/hmac_sha512.cpp +++ b/src/crypto/hmac_sha512.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/crypto/hmac_sha512.h b/src/crypto/hmac_sha512.h index 661216f29..5deaae851 100644 --- a/src/crypto/hmac_sha512.h +++ b/src/crypto/hmac_sha512.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/crypto/ripemd160.cpp b/src/crypto/ripemd160.cpp index 05d0c8237..f5c88e7df 100644 --- a/src/crypto/ripemd160.cpp +++ b/src/crypto/ripemd160.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/crypto/ripemd160.h b/src/crypto/ripemd160.h index 61fd27def..28d76c6ba 100644 --- a/src/crypto/ripemd160.h +++ b/src/crypto/ripemd160.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/crypto/sha1.cpp b/src/crypto/sha1.cpp index e9570c8f7..f29489ba0 100644 --- a/src/crypto/sha1.cpp +++ b/src/crypto/sha1.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/crypto/sha1.h b/src/crypto/sha1.h index 1831d3ea5..982915dc3 100644 --- a/src/crypto/sha1.h +++ b/src/crypto/sha1.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/crypto/sha256.cpp b/src/crypto/sha256.cpp index 90c682b75..fd39de951 100644 --- a/src/crypto/sha256.cpp +++ b/src/crypto/sha256.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/crypto/sha256.h b/src/crypto/sha256.h index e4f42a62e..e54cd94a5 100644 --- a/src/crypto/sha256.h +++ b/src/crypto/sha256.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014-2016 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/crypto/sha256_sse4.cpp b/src/crypto/sha256_sse4.cpp index 75f82b525..dda4401f0 100644 --- a/src/crypto/sha256_sse4.cpp +++ b/src/crypto/sha256_sse4.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2017 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/crypto/sha512.cpp b/src/crypto/sha512.cpp index 3ccf1e222..7099fbbbe 100644 --- a/src/crypto/sha512.cpp +++ b/src/crypto/sha512.cpp @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html diff --git a/src/crypto/sha512.h b/src/crypto/sha512.h index 8b10b9c51..9a348f874 100644 --- a/src/crypto/sha512.h +++ b/src/crypto/sha512.h @@ -1,3 +1,4 @@ +// Copyright (c) 2016-2022 The Hush developers // Copyright (c) 2014 The Bitcoin Core developers // Distributed under the GPLv3 software license, see the accompanying // file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html From 7e6220afacb28cf152539adda5ada0c98220b9fe Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 21 Sep 2022 22:18:19 -0400 Subject: [PATCH 246/255] Add release notes details to release process docs --- doc/release-process.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/release-process.md b/doc/release-process.md index b1176508f..60b693efc 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -88,6 +88,8 @@ Install deps on Linux: - Try to generate checkpoints as close to the release as possible, so you can have a recent block height be protected. - For instance, don't update checkpoints and then do a release a month later. You can always update checkpoint data again or multiple times - Update copyright years (if applicable) with util/replace.pl + - Update doc/relnotes/README.md + - To get the stats of file changes: `git diff --stat master...dev` - Do a fresh clone and fresh sync with new checkpoints - Stop node, wait 20 minutes, and then do a partial sync with new checkpoints - Make Gitea release From 3606703297abb1e563e8999eaf6f19ca8ed53a83 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Wed, 21 Sep 2022 23:22:37 -0400 Subject: [PATCH 247/255] Update relnotes for 3.9.2 'Anecdotal Axolotl' --- doc/relnotes/README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/doc/relnotes/README.md b/doc/relnotes/README.md index 3993799ae..baf478fd0 100644 --- a/doc/relnotes/README.md +++ b/doc/relnotes/README.md @@ -10,6 +10,41 @@ and no longer on Github, since they banned Duke Leto and also because they censor many people around the world and work with evil organizations. +# Hush 3.9.2 "Anecdotal Axolotl" + +``` + 966 files changed, 26999 insertions(+), 2758 deletions(-) +``` + +This is an OPTIONAL release. It is recommended for exchanges, solo miners and mining pools to update to this release +since it contains various bugfixes and improvements that will benefit busy wallets. + + * This release adds RandomX support in Hush Smart Chains (HSCs) + * When creating a new HSC specify `-ac_algo=randomx` to use RandomX instead of Equihash + * Example: `hush-smart-chain -ac_name=RANDX -ac_algo=randomx ...` + * This allows HSCs to be mined with CPUs instead of ASICs + * Because of RandomX, `cmake` is a new dependency needed to compile Hush from source + * More detailed documentation available at ... + * A new feature called "zsweep" has been added, which defaults to disabled. + * It will sweep funds from all zaddrs into a single specified zaddr + * A new RPC `z_sweepstatus` will show various details about the sweeping + * There are many advanced options to it, see full docs at ... + * Expired transactions will not be relayed and nodes who relay expired transactions are no longer banned + * A node relaying expired transactions is usually misconfigured or confused, not attacking us + * This change means node operators no longer need to deal with unbanning or allowlisting confused nodes + * Fix a rare coredump that could happen when nodes have many unconfirmed or expired transactions + * New RPC: `getblockmerkletree`, which will show the full Merkle Tree for a block height + * New RPC: `z_consolidationstatus` is similar to `z_sweepstatus` and will show config+stats about consolidation + * New RPC: `z_anonsettxdelta` : Returns delta (difference) in the anonset for a given txid. + * A delta > 0 increases the anonset + * A delta < 0 reduces the anonset + * A delta=0 leaves the anonset the same + * New RPC: `z_anonsetblockdelta` : Returns delta (difference) in the anonset for a given block. + * getrawtransaction RPC now returns a "size" key with the size in bytes of a transaction + * sendmany RPC will now reject transactions that send to taddrs immediately, instead of them being rejected in mempool + * Preliminary support for FreeBSD has been added to the Hush build system + * ZeroMQ support has been removed from Hush + # Hush 3.9.1 "Luciferous Locust" This is an OPTIONAL release. It is most important for users with large wallets, as it fixes an important From 2eada0a1bdffdb717b8e662a3905322983399a2b Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 23 Sep 2022 05:47:50 -0400 Subject: [PATCH 248/255] Add zsweep+consolidation docs originally written by jahway603 --- doc/zsweep-consolidation.md | 76 +++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 doc/zsweep-consolidation.md diff --git a/doc/zsweep-consolidation.md b/doc/zsweep-consolidation.md new file mode 100644 index 000000000..43e62ed2e --- /dev/null +++ b/doc/zsweep-consolidation.md @@ -0,0 +1,76 @@ +# zsweep and consolidation + +This is to document zsweep and consolidation for advanced HUSH users. + +**Warning: If you don't know what Zsweep or Consolidation are, there is a good chance that you will not be using these advanced options. User beware!** + +# Table of Contents +1. [Using Zsweep](#zsweep) +1. [Using Consolidation](#consolidation) +1. [Using Zsweep & Consolidation Together](#zsweep-&-consolidation-together) + +# Pre-Step & Further Details + +A user can use these options at the command line, but it is **recommended to configure these options within the HUSH3.conf file**. + +Consolidation takes many unspent shielded UTXOs (zutxos) into one zutxo, which makes spending them in the future faster and potentially cost less in fees. It also helps prevent certain kinds of metadata leakages and spam attacks. It is not recommended for very large wallets (wallet.dat files with thousands of transactions) for performance reasons. This is why it defaults to OFF for CLI full nodes but ON for GUI wallets that use an embedded hushd. + +Zsweep is when you sweep numerous zutxos into one z-address that you configure. This z-address can be local to that system or it can be configured to sweep to a remote wallet on a different system with the zsweepexternal=1 option, which is explained below in the Zsweep section. + +## Zsweep + +1. We add the following to our conf file as per the Pre-Step. + ``` + zsweep=1 + zsweepaddress=zs1... + ``` + +1. The above zsweepaddress will be the z-address you want to sweep into (zs1... is a placeholder for this documentation) and it must exist within the same local wallet you are configuring this for. If you want to zsweep to an address on another computer, then set zsweepexternal=1 as explained in the options below. + +1. The following are optional zsweep settings with their details: + + | Zsweep Option Name| Details of what it does | + |-------------------|-------------------------| + | zsweepexternal=1 | Will enable the option to zsweep to an "external" z-address which exists in a wallet on a different system. | + | zsweepinterval=5 | By default zsweep runs every 5 blocks, so set and modify this value to change that. | + | zsweepmaxinputs=50 | By default zsweep makes sure to not reduce the anonset in any tx by having a maximum number of inputs of 8. This should be fine for new wallets, but if you have an existing wallet with many zutxos it can be changed with this option. Keep in mind that large values will make sweeping faster at the expense of reducing the AnonSet. | + | zsweepfee=0 | The default zsweep fee is 10000 puposhis or 0.0001 HUSH, the default for all transactions. To use fee=0 for zsweep transactions, set this option. | + | zsweepexclude=zs1... | Exclude a certain address from being swept. Can be used multiple times to exclude multiple addressses | + +1. The following HUSH RPC will let you view your zsweep configuration options and run-time stats at the command line: `hush-cli z_sweepstatus` + +## Consolidation + +1. We add the following to our conf file as per the Pre-Step. + ``` + consolidation=1 + ``` + +1. The following are optional consolidation settings with their details: + + | Consolidation Option Name| Details of what it does | + |--------------------------|-------------------------| + | consolidationtxfee=0 | The default consolidation fee is 10000 puposhis or 0.0001 HUSH, the default for all transactions. To use fee=0 for consolidation transactions, set this option. | + | consolidatesaplingaddress=zs1... | Default of consolidation is set to all, but you can set this option if you have one specific z-address (zs1... is a placeholder for this documentation) that you want to only consolidate to. | + +1. The following HUSH RPC will let you view your consolidation configuration options and run-time stats at the command line: `hush-cli z_sweepstatus` + +## Zsweep & Consolidation Together + +1. We add the following to our conf file as per the Pre-Step. + ``` + zsweep=1 + zsweepaddress=zs1... + consolidation=1 + ``` + +1. Then follow along with the zsweep section above if you want to set specific options for the zsweep behavior. + +### Copyright + +jahway603 and The Hush Developers + +### License + +GPLv3 + From 804852e99c21e38e0f8498130b06c291ba0346a5 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 23 Sep 2022 06:57:31 -0400 Subject: [PATCH 249/255] Document RandomX --- doc/randomx.md | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 doc/randomx.md diff --git a/doc/randomx.md b/doc/randomx.md new file mode 100644 index 000000000..a690ded2b --- /dev/null +++ b/doc/randomx.md @@ -0,0 +1,104 @@ +# RandomX + +Hush Smart Chains support using RandomX as a Proof-Of-Work algorithm as of release 3.9.2 . +This means you can now launch a privacy coin with Hush tech that can be mined with a CPU +instead of requiring an ASIC or GPU. RandomX is the same algorithm that Monero (XMR) and +various other cryptocoins use. As far as we know, Hush Smart Chains are the first coins +based on Zcash Protocol that can use the RandomX PoW algorithm. Many thanks to all the +people who helped make this possible. + +# Example + +The following command can be used to launch an HSC on a single computer. Each option will be explained. +HSC CLI arguments that start with `-ac_` means they *Affect Consensus*. + +``` +./src/hush-smart-chain -ac_halving=100 -ac_algo=randomx -ac_name=RANDOMX -ac_private=1 -ac_blocktime=15 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 -testnode=1 +``` + + * `hush-smart-chain` is the script used to launch or connect to HSCs + * It lives in the `./src` directory, next to `hushd` and `hush-cli` + * It is called `hush-smart-chain.bat` on Windows + * `-ac_halving=100` means "the block reward halves every 100 blocks" + * `-ac_algo=randomx` means "use RandomX for Proof-Of-Work + * The default is Equihash (200,9) + * `-ac_name=RANDOMX` sets the name of the HSC to RANDOMX + * `-ac_private=1` means only z2z transactions will be allowed, like HUSH mainnet + * `-ac_blocktime=15` means blocks will be 15 seconds on average + * The default is 60 seconds + * `-ac_reward=500000000` means the block reward will start at 5 RANDOMX coins per block + * This argument is given in satoshis + * `-ac_supply=55555` means an existing supply of 55555 will exist at block 1 + * This argument is given in coins, not satoshis + * This is sometimes called a "pre-mine" and is useful when migrating an existing coin + * Block 0 of HSC's is always the BTC mainnet genesis block. + * So the genesis block of HSC's is actually block 1, not block 0 + * `-gen=1` means this node is a mining node + * `-genproclimit=1` means use 1 CPU thread will be used for mining + * `-testnode=1` means only 1 node can be used to mine a genesis block + * testnode is primarily for testing, when launching a real genesis block, this option should not be used + * By default, at least two nodes are required to mine a genesis block + * One node would use +``` +# first node +./src/hush-smart-chain -ac_halving=100 -ac_algo=randomx -ac_name=RANDOMX -ac_private=1 -ac_blocktime=15 -ac_reward=500000000 -ac_supply=55555 +``` + * And the second node would use: +``` +# mining node. NOTE: This node will mine the genesis block and pre-mine, if any +./src/hush-smart-chain -ac_halving=100 -ac_algo=randomx -ac_name=RANDOMX -ac_private=1 -ac_blocktime=15 -ac_reward=500000000 -ac_supply=55555 -gen=1 -genproclimit=1 +``` + +# Advanced Options + +HUSH RandomX currently has two advanced options that some may want to use: + + * `ac_randomx_interval` controls how often the RandomX key block will change + * The default is 1024 blocks and is good for most use cases. + * This corresponds to ~17 hours for HSCs with the default block time of 60s + * `ac_randomx_lag` sets the number of blocks to wait before updating the key block + * The default is 64 blocks + * This corresponds to 64 mins for HSCs with the default block time of 60s + * `ac_randomx_interval` should always be larger than 2 times `ac_randomx_lag` + * Setting these to arbitrary values could affect the chain security of your coin + * It is not recommended to change these values unless you are really sure why you are doing it + +# RandomX Internals + +This section is not required reading if you just want to use it as a PoW algorithm for an HSC. Here we will explain how the internals of RandomX works inside of the Hush codebase. + +We use the official RandomX implementation from https://github.com/tevador/RandomX with custom configuration options. If some type of hardware is created to mine the XMR RandomX algorithm, it will not be compatible with the Hush RandomX algorithm. This is by design. All Hush Smart Chains use the same RandomX config options, so if a hardware device is created to mine one HSC that uses RandomX, it can be used to mine any HSC using RandomX. Every HSC with unique consensus parameters will start off with it's own unique key block with at least 9 bytes of entropy. + +The source code of RandomX is embedded in the Hush source code at `./src/RandomX` and the configuration options used are at `./src/RandomX/src/configuration.h` . + +The changes from default RandomX configuration options are listed below. + +``` + //Argon2d salt +-#define RANDOMX_ARGON_SALT "RandomX\x03" ++#define RANDOMX_ARGON_SALT "RandomXHUSH\x03" + + //Number of Argon2d iterations for Cache initialization. +-#define RANDOMX_ARGON_ITERATIONS 3 ++#define RANDOMX_ARGON_ITERATIONS 5 + + //Number of parallel lanes for Cache initialization. + #define RANDOMX_ARGON_LANES 1 +@@ -53,13 +53,13 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + #define RANDOMX_DATASET_EXTRA_SIZE 33554368 + + //Number of instructions in a RandomX program. Must be divisible by 8. +-#define RANDOMX_PROGRAM_SIZE 256 ++#define RANDOMX_PROGRAM_SIZE 512 + + //Number of iterations during VM execution. +-#define RANDOMX_PROGRAM_ITERATIONS 2048 ++#define RANDOMX_PROGRAM_ITERATIONS 4096 + + //Number of chained VM executions per hash. +-#define RANDOMX_PROGRAM_COUNT 8 ++#define RANDOMX_PROGRAM_COUNT 16 + +``` +RandomX opcode frequencies were not modfiied, the defaults are used. + From 819f99cc07bde0bcfec62d53031367c2ca002622 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 25 Sep 2022 06:27:33 -0700 Subject: [PATCH 250/255] Basic HSC docs --- doc/hsc.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 doc/hsc.md diff --git a/doc/hsc.md b/doc/hsc.md new file mode 100644 index 000000000..5d5be9496 --- /dev/null +++ b/doc/hsc.md @@ -0,0 +1,20 @@ +# Hush Smart Chains + +An overview of HSCs can be found here: + +https://git.hush.is/hush/hush-smart-chains + +Hush Smart Chains allow you to create a privacy coin with no custom C++ code, just running one command! +The new coin that is created can use either Equihash PoW (ASIC or GPU) or RandomX PoW (CPU). + +## HSC Creator + +https://git.hush.is/hush/hsc-creator with its site https://hush.is/hsc-creator + +## HSC HOWTO + +https://git.hush.is/onryo/hush-smart-chain-how-to + +## HSC CLI + +https://git.hush.is/jahway603/hsc-cli From bffa3ce042664eed7f59437401c70806d1aa9f98 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 25 Sep 2022 06:32:03 -0700 Subject: [PATCH 251/255] Update 3.9.2 relnotes --- doc/relnotes/README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/relnotes/README.md b/doc/relnotes/README.md index baf478fd0..6502a6143 100644 --- a/doc/relnotes/README.md +++ b/doc/relnotes/README.md @@ -24,11 +24,12 @@ since it contains various bugfixes and improvements that will benefit busy walle * Example: `hush-smart-chain -ac_name=RANDX -ac_algo=randomx ...` * This allows HSCs to be mined with CPUs instead of ASICs * Because of RandomX, `cmake` is a new dependency needed to compile Hush from source - * More detailed documentation available at ... + * More detailed documentation available at https://git.hush.is/hush/hush3/src/branch/dev/doc/randomx.md + * For general info about HSCs see https://git.hush.is/hush/hush3/src/branch/dev/doc/hsc.md * A new feature called "zsweep" has been added, which defaults to disabled. * It will sweep funds from all zaddrs into a single specified zaddr * A new RPC `z_sweepstatus` will show various details about the sweeping - * There are many advanced options to it, see full docs at ... + * There are many advanced options to it, see full docs at https://git.hush.is/hush/hush3/src/branch/dev/doc/zsweep-consolidation.md * Expired transactions will not be relayed and nodes who relay expired transactions are no longer banned * A node relaying expired transactions is usually misconfigured or confused, not attacking us * This change means node operators no longer need to deal with unbanning or allowlisting confused nodes @@ -43,6 +44,9 @@ since it contains various bugfixes and improvements that will benefit busy walle * getrawtransaction RPC now returns a "size" key with the size in bytes of a transaction * sendmany RPC will now reject transactions that send to taddrs immediately, instead of them being rejected in mempool * Preliminary support for FreeBSD has been added to the Hush build system + * New contrib scripts: + * `contrib/gen-zaddrs.pl` - Generate zaddrs in bulk, defaults to 50 + * `contrib/sdl_checkpoints.pl` - Generate SDL checkpoints using `getblockmerkletree` * ZeroMQ support has been removed from Hush # Hush 3.9.1 "Luciferous Locust" From be7f35569175409507dabfcbb879ceb8ff9d912e Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Sun, 25 Sep 2022 09:02:30 -0700 Subject: [PATCH 252/255] RandomX for HSC docs --- doc/hsc.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/hsc.md b/doc/hsc.md index 5d5be9496..3ff3bc263 100644 --- a/doc/hsc.md +++ b/doc/hsc.md @@ -18,3 +18,7 @@ https://git.hush.is/onryo/hush-smart-chain-how-to ## HSC CLI https://git.hush.is/jahway603/hsc-cli + +## RandomX for HSCs + +Detailed docs on how to use RandomX Proof-of-Work is here: https://git.hush.is/hush/hush3/src/branch/dev/doc/randomx.md From f792488328dd87231542f8bcae8f3bf9c930f3d3 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 27 Sep 2022 05:01:35 -0700 Subject: [PATCH 253/255] Improve release process docs --- doc/release-process.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/release-process.md b/doc/release-process.md index 60b693efc..d631104a4 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -92,8 +92,9 @@ Install deps on Linux: - To get the stats of file changes: `git diff --stat master...dev` - Do a fresh clone and fresh sync with new checkpoints - Stop node, wait 20 minutes, and then do a partial sync with new checkpoints - - Make Gitea release - - Make Git Tag (Gitea can do this) + - Merge dev into master: `git checkout master; git pull && git merge --no-ff dev` + - The above command will not merge if "git pull" creates a merge conflict + - Make Gitea release with git tag from master branch (make sure to merge dev in first) - Use util/gen-linux-binary-release.sh to make a Linux release binary - Use util/build-debian-package.sh to make an x86 Debian package for the release - Debian packages should be done after you make manpages, because those are included in Debian packages From 9cf440ae2ded902cd157a0f50e626e2045309fa7 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 27 Sep 2022 05:02:46 -0700 Subject: [PATCH 254/255] Explain git-fu in reldocs --- doc/release-process.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/release-process.md b/doc/release-process.md index d631104a4..94a4a5ba3 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -92,8 +92,9 @@ Install deps on Linux: - To get the stats of file changes: `git diff --stat master...dev` - Do a fresh clone and fresh sync with new checkpoints - Stop node, wait 20 minutes, and then do a partial sync with new checkpoints - - Merge dev into master: `git checkout master; git pull && git merge --no-ff dev` + - Merge dev into master: `git checkout master; git pull && git merge --no-ff dev && git push` - The above command will not merge if "git pull" creates a merge conflict + - The above command will not push if there is a problem with merging dev - Make Gitea release with git tag from master branch (make sure to merge dev in first) - Use util/gen-linux-binary-release.sh to make a Linux release binary - Use util/build-debian-package.sh to make an x86 Debian package for the release From 517e16f1b0c70f87b9dc24b5d6da47201c4df0f0 Mon Sep 17 00:00:00 2001 From: "Jonathan \"Duke\" Leto" Date: Tue, 27 Sep 2022 05:04:31 -0700 Subject: [PATCH 255/255] Ensure local dev branch is up-to-date before merging dev --- doc/release-process.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/release-process.md b/doc/release-process.md index 94a4a5ba3..cdfbeec24 100644 --- a/doc/release-process.md +++ b/doc/release-process.md @@ -92,7 +92,8 @@ Install deps on Linux: - To get the stats of file changes: `git diff --stat master...dev` - Do a fresh clone and fresh sync with new checkpoints - Stop node, wait 20 minutes, and then do a partial sync with new checkpoints - - Merge dev into master: `git checkout master; git pull && git merge --no-ff dev && git push` + - Merge dev into master: `git checkout dev && git pull && git checkout master && git pull && git merge --no-ff dev && git push` + - The above command makes sure that your local dev branch is up to date before doing anything - The above command will not merge if "git pull" creates a merge conflict - The above command will not push if there is a problem with merging dev - Make Gitea release with git tag from master branch (make sure to merge dev in first)