1
0
Fork 0
forked from lthn/blockchain

Merge branch 'release'

This commit is contained in:
sowle 2021-06-02 16:27:06 +03:00
commit 53e0a4e953
No known key found for this signature in database
GPG key ID: C07A24B2D89D49FC
15 changed files with 380 additions and 294 deletions

View file

@ -4110,209 +4110,66 @@ void sc_muladd(unsigned char* s, const unsigned char* a,
s[31] = s11 >> 17;
}
// out = z ^ -1 (= z ^ (L - 2) according to Fermat little theorem)
void sc_invert(unsigned char* out, const unsigned char* z)
/* libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c */
void sc_sqmul(unsigned char s[32], const int n, const unsigned char a[32])
{
memcpy(out, z, 32);
for (size_t i = 0; i < 128; ++i)
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
int i;
for (i = 0; i < n; ++i)
sc_mul(s, s, s);
sc_mul(s, s, a);
}
/* libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c */
void sc_invert(unsigned char* recip, const unsigned char* s)
{
unsigned char _10[32], _100[32], _1000[32], _10000[32], _100000[32],
_1000000[32], _10010011[32], _10010111[32], _100110[32], _1010[32],
_1010000[32], _1010011[32], _1011[32], _10110[32], _10111101[32],
_11[32], _1100011[32], _1100111[32], _11010011[32], _1101011[32],
_11100111[32], _11101011[32], _11110101[32];
sc_mul(_10, s, s);
sc_mul(_11, s, _10);
sc_mul(_100, s, _11);
sc_mul(_1000, _100, _100);
sc_mul(_1010, _10, _1000);
sc_mul(_1011, s, _1010);
sc_mul(_10000, _1000, _1000);
sc_mul(_10110, _1011, _1011);
sc_mul(_100000, _1010, _10110);
sc_mul(_100110, _10000, _10110);
sc_mul(_1000000, _100000, _100000);
sc_mul(_1010000, _10000, _1000000);
sc_mul(_1010011, _11, _1010000);
sc_mul(_1100011, _10000, _1010011);
sc_mul(_1100111, _100, _1100011);
sc_mul(_1101011, _100, _1100111);
sc_mul(_10010011, _1000000, _1010011);
sc_mul(_10010111, _100, _10010011);
sc_mul(_10111101, _100110, _10010111);
sc_mul(_11010011, _10110, _10111101);
sc_mul(_11100111, _1010000, _10010111);
sc_mul(_11101011, _100, _11100111);
sc_mul(_11110101, _1010, _11101011);
sc_mul(recip, _1011, _11110101);
sc_sqmul(recip, 126, _1010011);
sc_sqmul(recip, 9, _10);
sc_mul(recip, recip, _11110101);
sc_sqmul(recip, 7, _1100111);
sc_sqmul(recip, 9, _11110101);
sc_sqmul(recip, 11, _10111101);
sc_sqmul(recip, 8, _11100111);
sc_sqmul(recip, 9, _1101011);
sc_sqmul(recip, 6, _1011);
sc_sqmul(recip, 14, _10010011);
sc_sqmul(recip, 10, _1100011);
sc_sqmul(recip, 9, _10010111);
sc_sqmul(recip, 10, _11110101);
sc_sqmul(recip, 8, _11010011);
sc_sqmul(recip, 8, _11101011);
}
/*

View file

@ -271,6 +271,11 @@ namespace crypto
return sc_check(&m_s[0]) == 0;
}
void reduce()
{
sc_reduce32(&m_s[0]);
}
scalar_t operator+(const scalar_t& v) const
{
scalar_t result;
@ -394,7 +399,7 @@ namespace crypto
friend std::ostream& operator<<(std::ostream& ss, const scalar_t &v)
{
return ss << "0x" << pod_to_hex_reversed(v);
return ss << pod_to_hex(v);
}
std::string to_string_as_hex_number() const
@ -510,6 +515,11 @@ namespace crypto
return result;
}
void to_public_key(crypto::public_key& result) const
{
ge_p3_tobytes((unsigned char*)&result, &m_p3);
}
crypto::key_image to_key_image() const
{
crypto::key_image result;
@ -562,10 +572,17 @@ namespace crypto
friend point_t operator*(const scalar_t& lhs, const point_t& rhs)
{
point_t result;
ge_scalarmult_p3(&result.m_p3, reinterpret_cast<const unsigned char*>(&lhs), &rhs.m_p3);
ge_scalarmult_p3(&result.m_p3, lhs.m_s, &rhs.m_p3);
return result;
}
point_t& operator*=(const scalar_t& rhs)
{
// TODO: ge_scalarmult_vartime_p3
ge_scalarmult_p3(&m_p3, rhs.m_s, &m_p3);
return *this;
}
friend point_t operator/(const point_t& lhs, const scalar_t& rhs)
{
point_t result;
@ -742,6 +759,11 @@ namespace crypto
m_elements.reserve(elements_count);
}
void resize(size_t elements_count)
{
m_elements.resize(elements_count);
}
void clear()
{
m_elements.clear();
@ -771,6 +793,16 @@ namespace crypto
m_elements.emplace_back(pk);
}
scalar_t& access_scalar(size_t index)
{
return m_elements[index].scalar;
}
public_key& access_public_key(size_t index)
{
return m_elements[index].pk;
}
void add_points_array(const std::vector<point_t>& points_array)
{
for (size_t i = 0, size = points_array.size(); i < size; ++i)
@ -798,9 +830,20 @@ namespace crypto
this->clear();
return scalar_t(hash); // this will reduce to L
}
void assign_calc_hash(scalar_t& result, bool clear = true)
{
static_assert(sizeof result == sizeof(crypto::hash), "size missmatch");
size_t data_size_bytes = m_elements.size() * sizeof(item_t);
crypto::cn_fast_hash(m_elements.data(), data_size_bytes, (crypto::hash&)result);
result.reduce();
if (clear)
this->clear();
}
union item_t
{
item_t() {}
item_t(const scalar_t& scalar) : scalar(scalar) {}
item_t(const crypto::public_key& pk) : pk(pk) {}
item_t(const crypto::key_image& ki) : ki(ki) {}

View file

@ -1438,7 +1438,7 @@ bool blockchain_storage::create_block_template(const create_block_template_param
CRITICAL_REGION_BEGIN(m_read_lock);
height = m_db_blocks.size();
if(height <= m_core_runtime_config.hard_fork_01_starts_after_height)
b.major_version = BLOCK_MAJOR_VERSION_INITAL;
b.major_version = BLOCK_MAJOR_VERSION_INITIAL;
else if(height <= m_core_runtime_config.hard_fork_03_starts_after_height)
b.major_version = HF1_BLOCK_MAJOR_VERSION;
else
@ -5770,7 +5770,7 @@ bool blockchain_storage::is_after_hardfork_3_zone(uint64_t height)const
bool blockchain_storage::prevalidate_block(const block& bl)
{
//before hard_fork1
if (bl.major_version == BLOCK_MAJOR_VERSION_INITAL && get_block_height(bl) <= m_core_runtime_config.hard_fork_01_starts_after_height)
if (bl.major_version == BLOCK_MAJOR_VERSION_INITIAL && get_block_height(bl) <= m_core_runtime_config.hard_fork_01_starts_after_height)
return true;

View file

@ -26,6 +26,18 @@ namespace currency
uint64_t hard_fork_02_starts_after_height;
uint64_t hard_fork_03_starts_after_height;
bool is_hardfork_active_for_height(size_t hardfork_id, uint64_t height) const
{
switch (hardfork_id)
{
case 0: return true;
case 1: return height > hard_fork_01_starts_after_height;
case 2: return height > hard_fork_02_starts_after_height;
case 3: return height > hard_fork_03_starts_after_height;
default: return false;
}
}
static uint64_t _default_core_time_function()
{
return time(NULL);

View file

@ -232,7 +232,7 @@
//hard forks section
#define BLOCK_MAJOR_VERSION_GENESIS 1
#define BLOCK_MINOR_VERSION_GENESIS 0
#define BLOCK_MAJOR_VERSION_INITAL 0
#define BLOCK_MAJOR_VERSION_INITIAL 0
#ifndef TESTNET
#define ZANO_HARDFORK_01_AFTER_HEIGHT 194624
#define ZANO_HARDFORK_02_AFTER_HEIGHT 999999

View file

@ -1 +1 @@
*.user
*.user

View file

@ -8,6 +8,6 @@
#define PROJECT_REVISION "0"
#define PROJECT_VERSION PROJECT_MAJOR_VERSION "." PROJECT_MINOR_VERSION "." PROJECT_REVISION
#define PROJECT_VERSION_BUILD_NO 121
#define PROJECT_VERSION_BUILD_NO 122
#define PROJECT_VERSION_BUILD_NO_STR STRINGIFY_EXPAND(PROJECT_VERSION_BUILD_NO)
#define PROJECT_VERSION_LONG PROJECT_VERSION "." PROJECT_VERSION_BUILD_NO_STR "[" BUILD_COMMIT_ID "]"

View file

@ -222,10 +222,10 @@ bool test_generator::construct_block(currency::block& blk,
// if (height > m_hardfork_01_after_heigh)
// blk.major_version = CURRENT_BLOCK_MAJOR_VERSION;
// else
// blk.major_version = BLOCK_MAJOR_VERSION_INITAL;
// blk.major_version = BLOCK_MAJOR_VERSION_INITIAL;
if (height <= m_hardfork_01_after_heigh)
blk.major_version = BLOCK_MAJOR_VERSION_INITAL;
blk.major_version = BLOCK_MAJOR_VERSION_INITIAL;
else if (height <= m_hardfork_03_after_heigh)
blk.major_version = HF1_BLOCK_MAJOR_VERSION;
else
@ -878,7 +878,7 @@ bool test_generator::construct_block(int64_t manual_timestamp_adjustment,
size_t txs_sizes/* = 0*/)
{
size_t height = get_block_height(prev_block) + 1;
blk.major_version = actual_params & bf_major_ver ? major_ver : BLOCK_MAJOR_VERSION_INITAL;
blk.major_version = actual_params & bf_major_ver ? major_ver : BLOCK_MAJOR_VERSION_INITIAL;
blk.minor_version = actual_params & bf_minor_ver ? minor_ver : CURRENT_BLOCK_MINOR_VERSION;
blk.timestamp = actual_params & bf_timestamp ? timestamp : (height > 10 ? prev_block.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN: prev_block.timestamp + DIFFICULTY_BLOCKS_ESTIMATE_TIMESPAN-POW_DIFF_UP_TIMESTAMP_DELTA); // Keep difficulty unchanged
blk.prev_id = actual_params & bf_prev_id ? prev_id : get_block_hash(prev_block);
@ -2099,6 +2099,7 @@ test_chain_unit_enchanced::test_chain_unit_enchanced()
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, print_tx_pool);
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, remove_stuck_txs);
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, check_offers_count);
REGISTER_CALLBACK_METHOD(test_chain_unit_enchanced, check_hardfork_active);
}
bool test_chain_unit_enchanced::configure_core(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
@ -2118,6 +2119,7 @@ void test_chain_unit_enchanced::set_hard_fork_heights_to_generator(test_generato
{
generator.set_hardfork_height(1, m_hardfork_01_height);
generator.set_hardfork_height(2, m_hardfork_02_height);
generator.set_hardfork_height(3, m_hardfork_03_height);
}
bool test_chain_unit_enchanced::check_top_block(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
@ -2232,3 +2234,19 @@ bool test_chain_unit_enchanced::check_offers_count(currency::core& c, size_t ev_
return true;
}
bool test_chain_unit_enchanced::check_hardfork_active(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events)
{
size_t hardfork_id_to_check = 0;
const std::string& params = boost::get<callback_entry>(events[ev_index]).callback_params;
CHECK_AND_ASSERT_MES(epee::string_tools::hex_to_pod(params, hardfork_id_to_check), false, "hex_to_pod failed, params = " << params);
uint64_t top_block_height = c.get_top_block_height();
if (!c.get_blockchain_storage().get_core_runtime_config().is_hardfork_active_for_height(hardfork_id_to_check, top_block_height))
{
LOG_ERROR("Hardfork #" << hardfork_id_to_check << " is not active yet (top block height is " << top_block_height << ")");
return false;
}
return true;
}

View file

@ -308,6 +308,7 @@ public:
bool print_tx_pool(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
bool remove_stuck_txs(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
bool check_offers_count(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
bool check_hardfork_active(currency::core& c, size_t ev_index, const std::vector<test_event_entry>& events);
protected:
struct params_top_block
@ -322,6 +323,7 @@ protected:
size_t m_unverifiable_tx_index;
size_t m_orphan_block_index;
// the following members is intended to be set by coretests with specific HF-related needs
uint64_t m_hardfork_01_height;
uint64_t m_hardfork_02_height;
uint64_t m_hardfork_03_height;

View file

@ -1007,7 +1007,7 @@ 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);
GENERATE_AND_PLAY(hard_fork_1_pos_and_locked_coins);

View file

@ -113,8 +113,8 @@ 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 == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
CHECK_AND_ASSERT_MES(blk_2.major_version != HF1_BLOCK_MAJOR_VERSION && blk_3.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
DO_CALLBACK_PARAMS(events, "check_hardfork_active", static_cast<size_t>(1));
//
// after hardfork 1
@ -218,8 +218,8 @@ 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 == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
CHECK_AND_ASSERT_MES(blk_3.major_version != HF1_BLOCK_MAJOR_VERSION && blk_4.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
DO_CALLBACK_PARAMS(events, "check_hardfork_active", static_cast<size_t>(1));
// after hardfork 1
@ -279,8 +279,8 @@ 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 == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
CHECK_AND_ASSERT_MES(blk_3a.major_version != HF1_BLOCK_MAJOR_VERSION && blk_4a.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
DO_CALLBACK_PARAMS(events, "check_hardfork_active", static_cast<size_t>(1));
//
// after hardfork 1
@ -357,7 +357,8 @@ 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 == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
CHECK_AND_ASSERT_MES(blk_3.major_version != HF1_BLOCK_MAJOR_VERSION && blk_4.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
DO_CALLBACK_PARAMS(events, "check_hardfork_active", static_cast<size_t>(1));
//
// after hardfork 1
@ -494,7 +495,7 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector<test_event_entry>& e
DO_CALLBACK_PARAMS(events, "check_outputs_with_unique_amount", unique_amount_params(unique_amount_bob, 0) );
// create few locked outputs in the blockchain with unique amount
// tx_0 : miner -> Alice
// tx_0 : miner -> Alice (locked till block 100 using etc_tx_details_unlock_time)
std::vector<extra_v> extra;
etc_tx_details_unlock_time ut = AUTO_VAL_INIT(ut);
ut.v = 100; // locked until block 100
@ -509,7 +510,7 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector<test_event_entry>& e
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
events.push_back(tx_0);
// tx_1 : miner -> Bob
// tx_1 : miner -> Bob (locked till block 100 using etc_tx_details_unlock_time2)
extra.clear();
uint64_t ut2_unlock_time = 100; // locked until block 100
etc_tx_details_unlock_time2 ut2 = AUTO_VAL_INIT(ut2);
@ -524,16 +525,19 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector<test_event_entry>& e
transaction tx_1 = AUTO_VAL_INIT(tx_1);
r = construct_tx_to_key(events, tx_1, blk_0r, miner_acc, destinations, TESTS_DEFAULT_FEE, 0, 0, extra);
CHECK_AND_ASSERT_MES(r, false, "construct_tx failed");
DO_CALLBACK(events, "mark_invalid_tx");
events.push_back(tx_1);
// etc_tx_details_unlock_time is allowed prior to HF 1 so tx_0 should pass all the checks nicely
MAKE_NEXT_BLOCK_TX1(events, blk_1, blk_0r, miner_acc, tx_0);
// block with tx_1 should be rejected because etc_tx_details_unlock_time2 is not allowed prior to hardfork 1
DO_CALLBACK(events, "mark_invalid_block");
MAKE_NEXT_BLOCK_TX1(events, blk_1b, blk_1, miner_acc, tx_1);
//DO_CALLBACK(events, "mark_invalid_block");
//MAKE_NEXT_BLOCK_TX1(events, blk_1b, blk_1, miner_acc, tx_1);
REWIND_BLOCKS_N_WITH_TIME(events, blk_1r, blk_1, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
// Alice should have received 5 * unique_amount_alice coins via tx_0
DO_CALLBACK_PARAMS(events, "check_outputs_with_unique_amount", unique_amount_params(unique_amount_alice, 5) );
// make sure outputs with m_unique_amount are still locked
@ -583,9 +587,9 @@ 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 == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
// make sure hardfork 1 went okay
CHECK_AND_ASSERT_MES(blk_2.major_version != HF1_BLOCK_MAJOR_VERSION && blk_3.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
DO_CALLBACK_PARAMS(events, "check_hardfork_active", static_cast<size_t>(1));
// try to make a PoS block with locked stake after the hardfork
@ -609,7 +613,7 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector<test_event_entry>& e
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());
@ -622,6 +626,7 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector<test_event_entry>& e
events.push_back(blk_4b);
// blk_4 with tx_1 (etc_tx_details_unlock_time2) should be accepted after hardfork 1
events.push_back(tx_1);
MAKE_NEXT_BLOCK_TX1(events, blk_4, blk_3, miner_acc, tx_1);
block prev = blk_4;
@ -629,11 +634,13 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector<test_event_entry>& e
{
MAKE_NEXT_POS_BLOCK(events, b, prev, miner_acc, std::list<currency::account_base>{miner_acc});
prev = b;
events.push_back(event_core_time(get_actual_timestamp(b) + 100));
}
//REWIND_BLOCKS_N_WITH_TIME(events, blk_4r, blk_4, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW);
// try to make a PoS block with the stake locked using etc_tx_details_unlock_time2 (it's still locked)
block blk_5;
{
const block& prev_block = prev;
@ -654,7 +661,7 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector<test_event_entry>& e
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());
@ -666,7 +673,6 @@ bool hard_fork_1_pos_and_locked_coins::generate(std::vector<test_event_entry>& e
DO_CALLBACK(events, "mark_invalid_block");
events.push_back(blk_5);
return true;
}
@ -726,7 +732,8 @@ 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 == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
CHECK_AND_ASSERT_MES(blk_0r.major_version != HF1_BLOCK_MAJOR_VERSION && blk_1.major_version == HF1_BLOCK_MAJOR_VERSION, false, "hardfork did not happen as expected");
DO_CALLBACK_PARAMS(events, "check_hardfork_active", static_cast<size_t>(1));
REWIND_BLOCKS_N_WITH_TIME(events, blk_1r, blk_1, miner_acc, CURRENCY_MINED_MONEY_UNLOCK_WINDOW + 1);
@ -751,7 +758,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());
@ -796,7 +803,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());

View file

@ -24,7 +24,7 @@ void pos_block_builder::step1_init_header(size_t block_height, crypto::hash& pre
{
CHECK_AND_ASSERT_THROW_MES(m_step == 0, "pos_block_builder: incorrect step sequence");
m_block.minor_version = CURRENT_BLOCK_MINOR_VERSION;
m_block.major_version = BLOCK_MAJOR_VERSION_INITAL;
m_block.major_version = BLOCK_MAJOR_VERSION_INITIAL;
m_block.timestamp = 0; // to be set at step 3
m_block.prev_id = prev_block_hash;
m_block.flags = CURRENCY_BLOCK_FLAG_POS_BLOCK;

View file

@ -46,7 +46,7 @@ typedef std::vector<std::shared_ptr<tools::wallet2>> cct_wallets_t;
bool create_block_template_manually(const currency::block& prev_block, boost::multiprecision::uint128_t already_generated_coins, const std::vector<const currency::transaction*>& txs, const currency::account_public_address& miner_addr, currency::block& result)
{
result.flags = 0;
result.major_version = BLOCK_MAJOR_VERSION_INITAL;
result.major_version = BLOCK_MAJOR_VERSION_INITIAL;
result.minor_version = CURRENT_BLOCK_MINOR_VERSION;
result.nonce = 0;
result.prev_id = get_block_hash(prev_block);

View file

@ -80,56 +80,208 @@ sc_sqmul(unsigned char s[32], const int n, const unsigned char a[32])
sc_mul(s, s, a);
}
void sc_invert2(unsigned char* recip, const unsigned char* s)
// out = z ^ -1 (= z ^ (L - 2) according to Fermat little theorem)
void sc_invert2(unsigned char* out, const unsigned char* z)
{
unsigned char _10[32], _100[32], _1000[32], _10000[32], _100000[32],
_1000000[32], _10010011[32], _10010111[32], _100110[32], _1010[32],
_1010000[32], _1010011[32], _1011[32], _10110[32], _10111101[32],
_11[32], _1100011[32], _1100111[32], _11010011[32], _1101011[32],
_11100111[32], _11101011[32], _11110101[32];
sc_mul(_10, s, s);
sc_mul(_11, s, _10);
sc_mul(_100, s, _11);
sc_mul(_1000, _100, _100);
sc_mul(_1010, _10, _1000);
sc_mul(_1011, s, _1010);
sc_mul(_10000, _1000, _1000);
sc_mul(_10110, _1011, _1011);
sc_mul(_100000, _1010, _10110);
sc_mul(_100110, _10000, _10110);
sc_mul(_1000000, _100000, _100000);
sc_mul(_1010000, _10000, _1000000);
sc_mul(_1010011, _11, _1010000);
sc_mul(_1100011, _10000, _1010011);
sc_mul(_1100111, _100, _1100011);
sc_mul(_1101011, _100, _1100111);
sc_mul(_10010011, _1000000, _1010011);
sc_mul(_10010111, _100, _10010011);
sc_mul(_10111101, _100110, _10010111);
sc_mul(_11010011, _10110, _10111101);
sc_mul(_11100111, _1010000, _10010111);
sc_mul(_11101011, _100, _11100111);
sc_mul(_11110101, _1010, _11101011);
sc_mul(recip, _1011, _11110101);
sc_sqmul(recip, 126, _1010011);
sc_sqmul(recip, 9, _10);
sc_mul(recip, recip, _11110101);
sc_sqmul(recip, 7, _1100111);
sc_sqmul(recip, 9, _11110101);
sc_sqmul(recip, 11, _10111101);
sc_sqmul(recip, 8, _11100111);
sc_sqmul(recip, 9, _1101011);
sc_sqmul(recip, 6, _1011);
sc_sqmul(recip, 14, _10010011);
sc_sqmul(recip, 10, _1100011);
sc_sqmul(recip, 9, _10010111);
sc_sqmul(recip, 10, _11110101);
sc_sqmul(recip, 8, _11010011);
sc_sqmul(recip, 8, _11101011);
memcpy(out, z, 32);
for (size_t i = 0; i < 128; ++i)
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, out);
sc_mul(out, out, z);
sc_mul(out, out, out);
sc_mul(out, out, z);
}
extern void *sha3(const void *in, size_t inlen, void *md, int mdlen);

View file

@ -3,12 +3,11 @@ curr_path=${BASH_SOURCE%/*}
version_file_path=../src/version.h.in
pushd $curr_path
# clear old local changes if any
git checkout -- ../src/*
git pull --ff-only
if [ $? -ne 0 ]; then
echo "Failed to pull"
popd
exit $?
fi
build_no_before=`cat $version_file_path | grep 'PROJECT_VERSION_BUILD_NO ' | awk {'print $3'}`
@ -19,15 +18,11 @@ build_no_after=`cat $version_file_path | grep 'PROJECT_VERSION_BUILD_NO ' | awk
echo "$build_no_before -> $build_no_after"
echo $(pwd -P)
git status
git commit -a -m"=== build number: $build_no_before -> $build_no_after ==="
git push
if [ $? -ne 0 ]; then
echo "Failed to push"
popd
exit $?
fi
echo "Build number was succesefully incremented."
popd