forked from lthn/blockchain
Merge branch 'develop' into release
This commit is contained in:
commit
5b3eb2937e
9 changed files with 91 additions and 20 deletions
|
|
@ -108,6 +108,13 @@ if(NOT MSVC AND NOT APPLE AND NOT CLANG) # TODO(unassigned): do we really need
|
|||
target_compile_options(common PRIVATE -fno-var-tracking-assignments)
|
||||
endif()
|
||||
|
||||
# disable specific warning in order not to touch original code by D. J. Bernstein
|
||||
if(MSVC)
|
||||
set_source_files_properties("crypto/chacha8_stream.c" PROPERTIES COMPILE_FLAGS "/wd4018")
|
||||
else()
|
||||
set_source_files_properties("crypto/chacha8_stream.c" PROPERTIES COMPILE_FLAGS "-Wno-sign-compare -Wno-strict-prototypes")
|
||||
endif()
|
||||
|
||||
add_library(crypto ${CRYPTO})
|
||||
|
||||
add_library(currency_core ${CURRENCY_CORE})
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace crypto
|
|||
const scalar_t c_scalar_P = { 0xffffffffffffffed, 0xffffffffffffffff, 0xffffffffffffffff, 0x7fffffffffffffff };
|
||||
const scalar_t c_scalar_Pm1 = { 0xffffffffffffffec, 0xffffffffffffffff, 0xffffffffffffffff, 0x7fffffffffffffff };
|
||||
const scalar_t c_scalar_256m1 = { 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff, 0xffffffffffffffff };
|
||||
const scalar_t c_scalar_1div8 = { 0x6106e529e2dc2f79, 0x7d39db37d1cdad0, 0x0, 0x600000000000000 };
|
||||
const scalar_t c_scalar_1div8 = { 0x6106e529e2dc2f79, 0x07d39db37d1cdad0, 0x0, 0x0600000000000000 };
|
||||
|
||||
const point_t c_point_H = { 0x05087c1f5b9b32d6, 0x00547595f445c3b5, 0x764df64578552f2a, 0x8a49a651e0e0da45 }; // == Hp(G), this is being checked in bpp_basics
|
||||
const point_t c_point_0 = point_t(point_t::tag_zero());
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
#include <string>
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
#include "crypto.h"
|
||||
#include "epee/include/string_tools.h"
|
||||
|
||||
namespace crypto
|
||||
{
|
||||
|
|
@ -88,6 +87,47 @@ namespace crypto
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
template<typename t_pod_type>
|
||||
bool parse_tpod_from_hex_string(const std::string& hex_str, t_pod_type& t_pod)
|
||||
{
|
||||
static const int16_t char_map[256] = { // 0-9, a-f, A-F is only allowed
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00 - 0x1F
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, // 0x20 - 0x3F
|
||||
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x40 - 0x5F
|
||||
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x60 - 0x7F
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x80 - 0x9F
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xA0 - 0xBF
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xC0 - 0xDF
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 }; // 0xE0 - 0xFF
|
||||
|
||||
size_t pod_size = sizeof t_pod;
|
||||
uint8_t *p = reinterpret_cast<uint8_t*>(&t_pod);
|
||||
|
||||
if (hex_str.size() != 2 * pod_size)
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < pod_size; ++i)
|
||||
{
|
||||
int16_t hi = char_map[static_cast<uint8_t>(hex_str[2 * i])];
|
||||
int16_t lo = char_map[static_cast<uint8_t>(hex_str[2 * i + 1])];
|
||||
if (hi < 0 || lo < 0)
|
||||
{
|
||||
// invalid characters in hex_str
|
||||
memset(p, 0, pod_size);
|
||||
return false;
|
||||
}
|
||||
p[i] = static_cast<uint8_t>(hi * 16 + lo); // write byte to pod
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename t_pod_type>
|
||||
t_pod_type parse_tpod_from_hex_string(const std::string& hex_str)
|
||||
{
|
||||
t_pod_type t_pod = AUTO_VAL_INIT(t_pod);
|
||||
parse_tpod_from_hex_string(hex_str, t_pod);
|
||||
return t_pod;
|
||||
}
|
||||
|
||||
//
|
||||
// scalar_t - holds a 256-bit scalar, normally in [0..L-1]
|
||||
|
|
@ -364,7 +404,7 @@ namespace crypto
|
|||
|
||||
std::string to_string_as_secret_key() const
|
||||
{
|
||||
return epee::string_tools::pod_to_hex(*this);
|
||||
return pod_to_hex(*this);
|
||||
}
|
||||
|
||||
template<typename MP_type>
|
||||
|
|
@ -458,7 +498,7 @@ namespace crypto
|
|||
bool from_string(const std::string& str)
|
||||
{
|
||||
crypto::public_key pk;
|
||||
if (!epee::string_tools::parse_tpod_from_hex_string(str, pk))
|
||||
if (!parse_tpod_from_hex_string(str, pk))
|
||||
return false;
|
||||
return from_public_key(pk);
|
||||
}
|
||||
|
|
@ -591,19 +631,19 @@ namespace crypto
|
|||
friend std::ostream& operator<<(std::ostream& ss, const point_t &v)
|
||||
{
|
||||
crypto::public_key pk = v.to_public_key();
|
||||
return ss << epee::string_tools::pod_to_hex(pk);
|
||||
return ss << pod_to_hex(pk);
|
||||
}
|
||||
|
||||
operator std::string() const
|
||||
{
|
||||
crypto::public_key pk = to_public_key();
|
||||
return epee::string_tools::pod_to_hex(pk);
|
||||
return pod_to_hex(pk);
|
||||
}
|
||||
|
||||
std::string to_string() const
|
||||
{
|
||||
crypto::public_key pk = to_public_key();
|
||||
return epee::string_tools::pod_to_hex(pk);
|
||||
return pod_to_hex(pk);
|
||||
}
|
||||
|
||||
std::string to_hex_comma_separated_bytes_str() const
|
||||
|
|
|
|||
|
|
@ -27,5 +27,5 @@ void cn_fast_hash_old(const void *data, size_t length, char *hash)
|
|||
|
||||
void cn_fast_hash(const void *data, size_t length, char *hash)
|
||||
{
|
||||
keccak(data, (int)length, hash, HASH_SIZE);
|
||||
keccak(data, (int)length, (uint8_t*)hash, HASH_SIZE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5779,7 +5779,7 @@ bool blockchain_storage::prevalidate_block(const block& bl)
|
|||
get_block_height(bl) <= m_core_runtime_config.hard_fork_03_starts_after_height
|
||||
)
|
||||
{
|
||||
if (bl.major_version == HF1_BLOCK_MAJOR_VERSION)
|
||||
if (bl.major_version <= HF1_BLOCK_MAJOR_VERSION )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -219,10 +219,17 @@ bool test_generator::construct_block(currency::block& blk,
|
|||
const std::list<currency::transaction>& tx_list,
|
||||
const std::list<currency::account_base>& coin_stake_sources)//in case of PoS block
|
||||
{
|
||||
if (height > m_hardfork_01_after_heigh)
|
||||
blk.major_version = CURRENT_BLOCK_MAJOR_VERSION;
|
||||
else
|
||||
// if (height > m_hardfork_01_after_heigh)
|
||||
// blk.major_version = CURRENT_BLOCK_MAJOR_VERSION;
|
||||
// else
|
||||
// blk.major_version = BLOCK_MAJOR_VERSION_INITAL;
|
||||
|
||||
if (height <= m_hardfork_01_after_heigh)
|
||||
blk.major_version = BLOCK_MAJOR_VERSION_INITAL;
|
||||
else if (height <= m_hardfork_03_after_heigh)
|
||||
blk.major_version = HF1_BLOCK_MAJOR_VERSION;
|
||||
else
|
||||
blk.major_version = CURRENT_BLOCK_MAJOR_VERSION;
|
||||
|
||||
blk.minor_version = CURRENT_BLOCK_MINOR_VERSION;
|
||||
blk.timestamp = timestamp;
|
||||
|
|
|
|||
|
|
@ -1007,6 +1007,9 @@ int main(int argc, char* argv[])
|
|||
GENERATE_AND_PLAY(hard_fork_1_chain_switch_pow_only);
|
||||
GENERATE_AND_PLAY(hard_fork_1_checkpoint_basic_test);
|
||||
GENERATE_AND_PLAY(hard_fork_1_pos_locked_height_vs_time);
|
||||
//GENERATE_AND_PLAY(hard_fork_1_pos_and_locked_coins);
|
||||
|
||||
|
||||
|
||||
// Hardfork 2 tests
|
||||
GENERATE_AND_PLAY(hard_fork_2_tx_payer_in_wallet);
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ bool hard_fork_1_unlock_time_2_in_normal_tx::generate(std::vector<test_event_ent
|
|||
MAKE_NEXT_BLOCK(events, blk_2, blk_1, miner_acc); // hardfork should happen here
|
||||
MAKE_NEXT_BLOCK(events, blk_3, blk_2, miner_acc);
|
||||
// make sure hardfork went okay
|
||||
CHECK_AND_ASSERT_MES(blk_2.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_3.major_version == CURRENT_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
|
||||
CHECK_AND_ASSERT_MES(blk_2.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_3.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
|
||||
|
||||
|
||||
//
|
||||
|
|
@ -218,7 +218,7 @@ bool hard_fork_1_unlock_time_2_in_coinbase::generate(std::vector<test_event_entr
|
|||
MAKE_NEXT_BLOCK(events, blk_3, blk_2, miner_acc); // hardfork should happen here
|
||||
MAKE_NEXT_BLOCK(events, blk_4, blk_3, miner_acc);
|
||||
// make sure hardfork went okay
|
||||
CHECK_AND_ASSERT_MES(blk_3.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_4.major_version == CURRENT_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
|
||||
CHECK_AND_ASSERT_MES(blk_3.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_4.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
|
||||
|
||||
|
||||
// after hardfork 1
|
||||
|
|
@ -279,7 +279,7 @@ bool hard_fork_1_chain_switch_pow_only::generate(std::vector<test_event_entry>&
|
|||
MAKE_NEXT_BLOCK(events, blk_3a, blk_2a, miner_acc); // hardfork should happen here
|
||||
MAKE_NEXT_BLOCK(events, blk_4a, blk_3a, miner_acc);
|
||||
// make sure hardfork went okay
|
||||
CHECK_AND_ASSERT_MES(blk_3a.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_4a.major_version == CURRENT_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
|
||||
CHECK_AND_ASSERT_MES(blk_3a.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_4a.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
|
||||
|
||||
|
||||
//
|
||||
|
|
@ -357,7 +357,7 @@ bool hard_fork_1_checkpoint_basic_test::generate(std::vector<test_event_entry>&
|
|||
MAKE_NEXT_BLOCK(events, blk_3, blk_2, miner_acc); // <-- hard fork
|
||||
MAKE_NEXT_BLOCK(events, blk_4, blk_3, miner_acc);
|
||||
// make sure hardfork went okay
|
||||
CHECK_AND_ASSERT_MES(blk_3.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_4.major_version == CURRENT_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
|
||||
CHECK_AND_ASSERT_MES(blk_3.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_4.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
|
||||
|
||||
//
|
||||
// after hardfork 1
|
||||
|
|
@ -397,7 +397,7 @@ bool hard_fork_1_checkpoint_basic_test::generate(std::vector<test_event_entry>&
|
|||
|
||||
pos_block_builder pb;
|
||||
pb.step1_init_header(height, prev_id);
|
||||
pb.m_block.major_version = CURRENT_BLOCK_MAJOR_VERSION;
|
||||
pb.m_block.major_version = HF1_BLOCK_MAJOR_VERSION;
|
||||
pb.step2_set_txs(std::vector<transaction>());
|
||||
pb.step3_build_stake_kernel(stake_output_amount, stake_output_gidx, stake_output_key_image, diff, prev_id, null_hash, prev_block.timestamp);
|
||||
pb.step4_generate_coinbase_tx(generator.get_timestamps_median(prev_id), generator.get_already_generated_coins(prev_block), miner_acc.get_public_address(), stakeholder.get_public_address());
|
||||
|
|
@ -584,7 +584,7 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector<test_event_entry>& e
|
|||
MAKE_NEXT_BLOCK(events, blk_2, blk_1r, miner_acc);
|
||||
MAKE_NEXT_BLOCK(events, blk_3, blk_2, miner_acc);
|
||||
// make sure hardfork went okay
|
||||
CHECK_AND_ASSERT_MES(blk_2.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_3.major_version == CURRENT_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
|
||||
CHECK_AND_ASSERT_MES(blk_2.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_3.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
|
||||
|
||||
|
||||
// try to make a PoS block with locked stake after the hardfork
|
||||
|
|
@ -726,7 +726,7 @@ bool hard_fork_1_pos_locked_height_vs_time::generate(std::vector<test_event_entr
|
|||
MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0); // first block after hardfork
|
||||
|
||||
// make sure hardfork went okay
|
||||
CHECK_AND_ASSERT_MES(blk_0r.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_1.major_version == CURRENT_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
|
||||
CHECK_AND_ASSERT_MES(blk_0r.major_version != CURRENT_BLOCK_MAJOR_VERSION && blk_1.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
|
||||
|
||||
REWIND_BLOCKS_N_WITH_TIME(events, blk_1r, blk_1, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1);
|
||||
|
||||
|
|
@ -840,7 +840,7 @@ bool hard_fork_1_pos_locked_height_vs_time::generate(std::vector<test_event_entr
|
|||
|
||||
pos_block_builder pb;
|
||||
pb.step1_init_header(height, prev_id);
|
||||
pb.m_block.major_version = CURRENT_BLOCK_MAJOR_VERSION;
|
||||
pb.m_block.major_version = HF1_BLOCK_MAJOR_VERSION;
|
||||
pb.step2_set_txs(std::vector<transaction>());
|
||||
pb.step3_build_stake_kernel(stake_output_amount, stake_output_gidx, stake_output_key_image, diff, prev_id, null_hash, prev_block.timestamp);
|
||||
pb.step4_generate_coinbase_tx(generator.get_timestamps_median(prev_id), generator.get_already_generated_coins(prev_block), miner_acc.get_public_address(), stakeholder.get_public_address());
|
||||
|
|
|
|||
|
|
@ -1385,6 +1385,20 @@ TEST(ml2s, sig_verif_performance_2)
|
|||
}
|
||||
|
||||
|
||||
TEST(crypto, hex_tools)
|
||||
{
|
||||
ASSERT_EQ(parse_tpod_from_hex_string<uint8_t>("00"), 0x00);
|
||||
ASSERT_EQ(parse_tpod_from_hex_string<uint8_t>("01"), 0x01);
|
||||
ASSERT_EQ(parse_tpod_from_hex_string<uint8_t>("f1"), 0xf1);
|
||||
ASSERT_EQ(parse_tpod_from_hex_string<uint8_t>("fe"), 0xfe);
|
||||
ASSERT_EQ(parse_tpod_from_hex_string<uint64_t>("efcdab8967452301"), 0x0123456789abcdef);
|
||||
ASSERT_EQ(parse_tpod_from_hex_string<uint64_t>("0123456789abcdef"), 0xefcdab8967452301);
|
||||
ASSERT_EQ(parse_tpod_from_hex_string<scalar_t>("ecffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f"), c_scalar_Pm1);
|
||||
ASSERT_EQ(parse_tpod_from_hex_string<scalar_t>("792fdce229e50661d0da1c7db39dd30700000000000000000000000000000006"), c_scalar_1div8);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// test's runner
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue