Test for cn_slow_hash_with_multiplier added

This commit is contained in:
pmitchev
2018-01-28 06:12:25 +02:00
parent 7b8f61aaf3
commit 3ef10cd64c
5 changed files with 294 additions and 8 deletions
+4 -2
View File
@@ -23,7 +23,7 @@
"MAINNET_SEED_NODES":"full_addrs.insert(\"74.91.23.186:11180\");\nfull_addrs.insert(\"192.187.114.114:11180\");\nfull_addrs.insert(\"34.200.218.170:11180\");\nfull_addrs.insert(\"144.76.104.208:11180\");\n",
"MAINET_CHECKPOINTS":" ADD_CHECKPOINT(1, \"1440a20f078bf3264822234b347f8382606577d73d4e9d3cb7296d73889bc421\");\n ADD_CHECKPOINT(100, \"6dd13aaab16679f49ee6b2b75c7dc99b1fd09ab2282b18cb4b55b73110655742\");\n ADD_CHECKPOINT(1000, \"bc6458452fd0575a314089bf302f6fd68ebaa2d689c42f3365293b96bbdf1f25\");\n ADD_CHECKPOINT(10000, \"1ac1ebd25baf0d6ec593daa3389f1aa7e860ff2cc29f3cf1be586d245b379da4\");\n ADD_CHECKPOINT(15000, \"15567af42afc1ed00538f53b5e3822d421e3ed6372ca79f4ea4e3e3bab709a87\");\n ADD_CHECKPOINT(175500, \"3f7dd748b3b863b04654d87a387f2b65a365f467188971f3192eab2368e64a35\");\n ADD_CHECKPOINT(450000, \"f69a6e57c4dd5df2f492c9d31c50f11aad2c25a64d540ce5f5d11b572aec8ab7\");\n ADD_CHECKPOINT(540000, \"94e19cf9d5a16ae90f67c321f8376b87da21d6d6c2cb0957b9ab558dca66c1dc\");\n ADD_CHECKPOINT(592001, \"e8bc936b287a9c426a15cf127624b064c88e6d37655cc87f9a62cf1623c62385\");\n ADD_CHECKPOINT(798358, \"804c7fe07511d9387e7cda534c9e8b644d406d8d0ff299799a8177850d4e75a0\");\n ADD_CHECKPOINT(871000, \"99f7e5460da3fb4e2b15214017b0a17ff0294823ad852259ff837f0ffeeb90f0\");\n",
"MAINNET_HARDFORKS":"{ 1, 1, 0, 1341378000 }",
"MAINNET_HARDFORK_V1_LAST_BLOCK":18446744073709551615,
"MAINNET_HARDFORK_V1_LAST_BLOCK": -1,
"MAINNET_HARDFORK_V1HF":592000,
"P2P_STAT_TRUSTED_PUB_KEY": "",
@@ -32,9 +32,11 @@
"TESTNET_GENESIS_TX": "013c01ff0001ffffffffffff03029b2e4c0281c0b02e7c53291a94d1d0cbff8883f8024f5142ee494ffbbd08807121017c18fb180e05e89625b8324cd22ceeb3d4925ebaa5c274c9e927b2cf5669ffd6",
"MAINNET_NETWORK_ID": "0x32 ,0x32, 0xF3, 0x91 , 0x81, 0x18 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x10",
"TESTNET_NETWORK_ID": "0x32 ,0x32, 0xF3, 0x91 , 0x81, 0x18 , 0x41, 0x61, 0x17, 0x31, 0x00, 0x82, 0x16, 0xA1, 0xA1, 0x11",
"MONEY_SUPPLY": 18446744073709551615,
"MONEY_SUPPLY": -1,
"FINAL_SUBSIDY_PER_MINUTE": 0,
"MINIMUM_RELAY_FEE": 1000000,
"DEFAULT_FEE": 10000000000,
"NO_FEE_PER_KB_FEE_MAX_HEIGHT": -1,
"EMISSION_SPEED_FACTOR_PER_MINUTE_V1": 20,
"EMISSION_SPEED_FACTOR_PER_MINUTE_V1HF":18,
"DIFFICULTY_WINDOW_V1": 720,
+206 -5
View File
@@ -82,10 +82,63 @@
],
"var": "MEMORY_MULTIPLIER_V1HF"
}
},
{
"description": "NO_FEE_PER_KB",
"action": "add_above",
"marker": "#define FEE_PER_KB_OLD",
"parameters": {
"text": [
"#define MINIMUM_RELAY_FEE %s"
],
"replace_text_alt": [
"#define MINIMUM_RELAY_FEE 0"
],
"var": "MINIMUM_RELAY_FEE"
}
}
]
},
{
"path": "/src/cryptonote_config.h",
"changes": [
{
"description": "NO_FEE_PER_KB",
"action": "add_above",
"marker": "#define FEE_PER_KB_OLD",
"parameters": {
"text": [
"#define DEFAULT_FEE %s"
],
"replace_text_alt": [
"#define DEFAULT_FEE 0"
],
"var": "DEFAULT_FEE"
}
}
]
},
{
"path": "/src/cryptonote_config.h",
"changes": [
{
"description": "NO_FEE_PER_KB",
"action": "add_above",
"marker": "#define FEE_PER_KB_OLD",
"parameters": {
"text": [
"#define NO_FEE_PER_KB_FEE_MAX_HEIGHT %s"
],
"replace_text_alt": [
"#define NO_FEE_PER_KB_FEE_MAX_HEIGHT 0"
],
"var": "NO_FEE_PER_KB_FEE_MAX_HEIGHT"
}
}
]
},
{
"path": "/src/crypto/slow-hash.c",
"changes": [
@@ -143,6 +196,10 @@
" cn_slow_hash_with_multiplier(data, length, hash, 1);",
"}",
"",
"void cn_slow_hash_with_multiplier_test(const void *data, size_t length, char *hash) {",
" cn_slow_hash_with_multiplier(data, length, hash, 0.5);",
"}",
"",
"void cn_slow_hash_with_multiplier(const void *data, size_t length, char *hash, double memory_multiplier) {"
]
}
@@ -157,6 +214,11 @@
" cn_slow_hash_with_multiplier(data, length, hash, 1);",
"}",
"",
"void cn_slow_hash_with_multiplier_test(const void *data, size_t length, char *hash)",
"{",
" cn_slow_hash_with_multiplier(data, length, hash, 0.5);",
"}",
"",
"void cn_slow_hash_with_multiplier(const void *data, size_t length, char *hash, double memory_multiplier)"
]
}
@@ -209,7 +271,9 @@
"marker": "void cn_slow_hash(const void *data, size_t length, char *hash);",
"parameters": {
"text": [
"void cn_slow_hash_with_multiplier(const void *data, size_t length, char *hash, double memory_multiplier);" ]
"void cn_slow_hash_with_multiplier_test(const void *data, size_t length, char *hash);",
"void cn_slow_hash_with_multiplier(const void *data, size_t length, char *hash, double memory_multiplier);"
]
}
}
]
@@ -222,6 +286,10 @@
"marker": "inline void cn_slow_hash(const void *data, std::size_t length, hash &hash) {",
"parameters": {
"text": [
"inline void cn_slow_hash_with_multiplier_test(const void *data, std::size_t length, hash &hash) {",
" cn_slow_hash_with_multiplier_test(data, length, reinterpret_cast<char *>(&hash));",
"}",
"",
"inline void cn_slow_hash_with_multiplier(const void *data, std::size_t length, hash &hash, double memory_multiplier) {",
" cn_slow_hash_with_multiplier(data, length, reinterpret_cast<char *>(&hash), memory_multiplier);",
"}",
@@ -338,7 +406,7 @@
"marker": "crypto::cn_slow_hash(bd.data(), bd.size(), res);",
"parameters": {
"text": [
" size_t memory_multiplier = 1;",
" double memory_multiplier = 1;",
" if (height >= MAINNET_HARDFORK_V1HF)",
" memory_multiplier = MEMORY_MULTIPLIER_V1HF;",
" crypto::cn_slow_hash_with_multiplier(bd.data(), bd.size(), res, memory_multiplier);"
@@ -362,6 +430,48 @@
]
},
{
"path": "/src/wallet/wallet2.cpp",
"changes": [
{
"description": "NO_FEE_PER_KB",
"action": "replace",
"marker": "uint64_t needed_fee = calculate_fee(fee_per_kb, estimated_tx_size, fee_multiplier);",
"parameters": {
"text": [
" uint64_t needed_fee = 0;",
" if (NO_FEE_PER_KB_FEE_MAX_HEIGHT <= m_blockchain.size())",
" needed_fee = calculate_fee(DEFAULT_FEE, 1, fee_multiplier);",
" else",
" needed_fee = calculate_fee(fee_per_kb, estimated_tx_size, fee_multiplier);"
]
}
}
]
},
{
"path": "/src/wallet/wallet2.cpp",
"multiline": true,
"changes": [
{
"description": "NO_FEE_PER_KB",
"action": "replace",
"marker": "transfer\\(dst_vector, fake_outs_count, unused_transfers_indices, unlock_time, needed_fee, extra, tx, ptx, trusted_daemon\\);[^a]+auto txBlob = t_serializable_object_to_blob\\(ptx.tx\\);[^n]+needed_fee = calculate_fee\\(fee_per_kb, txBlob, fee_multiplier\\);",
"parameters": {
"text": [
"transfer(dst_vector, fake_outs_count, unused_transfers_indices, unlock_time, needed_fee, extra, tx, ptx, trusted_daemon);",
" auto txBlob = t_serializable_object_to_blob(ptx.tx);",
" if (NO_FEE_PER_KB_FEE_MAX_HEIGHT <= m_blockchain.size())",
" needed_fee = calculate_fee(DEFAULT_FEE, 1, fee_multiplier);",
" else",
" needed_fee = calculate_fee(fee_per_kb, txBlob, fee_multiplier);"
]
}
}
]
},
{
"path": "/src/cryptonote_core/tx_pool.h",
"changes": [
@@ -380,6 +490,21 @@
{
"path": "/src/cryptonote_core/tx_pool.cpp",
"changes": [
{
"description": "NO_FEE_PER_KB",
"action": "add_below",
"marker": "fee = inputs_amount - outputs_amount;",
"parameters": {
"text": [
" if (!kept_by_block && fee < MINIMUM_RELAY_FEE)",
" {",
" LOG_PRINT_L1(\"transaction fee is not enough: \" << print_money(fee) << \", minumim fee: \" << print_money(DEFAULT_FEE));",
" tvc.m_verifivation_failed = true;",
" return false;",
" }"
]
}
},
{
"action": "replace",
"marker": "bool tx_memory_pool::fill_block_template(block &bl, size_t median_size, uint64_t already_generated_coins, size_t &total_size, uint64_t &fee, uint64_t &expected_reward, uint8_t version)",
@@ -413,8 +538,6 @@
}
]
},
{
"path": "/src/cryptonote_basic/difficulty.h",
"changes": [
@@ -464,6 +587,84 @@
}
]
},
{
"path": "/tests/performance_tests/CMakeLists.txt",
"changes": [
{
"action": "add_below",
"marker": "cn_slow_hash.h",
"parameters": {
"text": [
" cn_slow_hash_with_multiplier_test.h"
]
}
}
]
},
{
"path": "/tests/hash/CMakeLists.txt",
"changes": [
{
"action": "replace",
"marker": "foreach (hash IN ITEMS fast slow tree extra-blake extra-groestl extra-jh extra-skein)",
"parameters": {
"text": [
"foreach (hash IN ITEMS fast slow slow-with-multiplier tree extra-blake extra-groestl extra-jh extra-skein)"
]
}
}
]
},
{
"path": "/tests/hash/main.cpp",
"changes": [
{
"action": "replace",
"marker": "} hashes[] = {{\"fast\", cn_fast_hash}, {\"slow\", cn_slow_hash}, {\"tree\", hash_tree},",
"parameters": {
"text": [
"} hashes[] = {{\"fast\", cn_fast_hash}, {\"slow\", cn_slow_hash}, {\"slow-with-multiplier\", cn_slow_hash_with_multiplier_test}, {\"tree\", hash_tree},"
]
}
}
]
},
{
"path": "/tests/performance_tests/main.cpp",
"changes": [
{
"action": "add_below",
"marker": "#include \"cn_slow_hash.h\"",
"parameters": {
"text": [
"#include \"cn_slow_hash_with_multiplier_test.h\""
]
}
},
{
"action": "add_below",
"marker": "test_cn_slow_hash);",
"parameters": {
"text": [
" TEST_PERFORMANCE0(test_cn_slow_hash_with_multiplier_test);"
]
}
}
]
},
{
"path": "/tests/performance_tests/cn_slow_hash_with_multiplier_test.h",
"action": "add",
"source": "/aeon/files/tests/performance_tests/cn_slow_hash_with_multiplier_test.h"
},
{
"path": "/tests/hash/tests-slow-with-multiplier.txt",
"action": "add",
"source": "/aeon/files/tests/hash/tests-slow-with-multiplier.txt"
},
{
"path": "/src/blocks/blocks.dat",
"action": "add",
@@ -0,0 +1 @@
afffe6c3084b0de799f6851389619bfe36be4705e4fb9e5039f8044b0decf8ea 63617665617420656d70746f72
@@ -0,0 +1,73 @@
// Copyright (c) 2018, The Aeon 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.
//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#pragma once
#include "string_tools.h"
#include "crypto/crypto.h"
#include "cryptonote_basic/cryptonote_basic.h"
class test_cn_slow_hash_with_multiplier_test
{
public:
static const size_t loop_count = 10;
#pragma pack(push, 1)
struct data_t
{
char data[13];
};
#pragma pack(pop)
static_assert(13 == sizeof(data_t), "Invalid structure size");
bool init()
{
if (!epee::string_tools::hex_to_pod("63617665617420656d70746f72", m_data))
return false;
if (!epee::string_tools::hex_to_pod("afffe6c3084b0de799f6851389619bfe36be4705e4fb9e5039f8044b0decf8ea", m_expected_hash))
return false;
return true;
}
bool test()
{
crypto::hash hash;
crypto::cn_slow_hash_with_multiplier_test(&m_data, sizeof(m_data), hash);
return hash == m_expected_hash;
}
private:
data_t m_data;
crypto::hash m_expected_hash;
};
+10 -1
View File
@@ -42,6 +42,12 @@ function generate_coin {
git clone "${__CONFIG_base_coin_git}" "${BASE_COIN_PATH}"
fi
if [[ ! -z $BRANCH ]]; then
cd "${BASE_COIN_PATH}"
git checkout ${BRANCH}
cd "${PROJECT_DIR}"
fi
# Exit if base coin does not exists
if [ ! -d "${BASE_COIN_PATH}" ]; then
echo "Base coin does not exists"
@@ -93,6 +99,7 @@ Reads a config file and creates and compiles Cryptonote coin. "config.json" as d
-h display this help and exit
-f config file
-b branch
-c compile arguments
EOF
}
@@ -104,7 +111,7 @@ OPTIND=1 # Reset in case getopts has been used previously in the shell.
CONFIG_FILE='config.json'
COMPILE_ARGS=''
while getopts "h?f:c:" opt; do
while getopts "h?f:b:c:" opt; do
case "$opt" in
h|\?)
show_help
@@ -112,6 +119,8 @@ while getopts "h?f:c:" opt; do
;;
f) CONFIG_FILE=${OPTARG}
;;
b) BRANCH=${OPTARG}
;;
c) COMPILE_ARGS=${OPTARG}
;;
esac