From 0699d51c33c2a8e5bfede882ec329ed21998eb20 Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Sat, 11 Oct 2014 10:02:47 +0000 Subject: [PATCH 1/5] tree-hash fix from Monero --- .gitignore | 23 +++++++++++++++ src/crypto/tree-hash.c | 63 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 78 insertions(+), 8 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4f8766a --- /dev/null +++ b/.gitignore @@ -0,0 +1,23 @@ +.DS_Store +/doc +/build +/tags + +# vim swap files +*.swp +*.swo +TAGS +!TAGS/ +tags +!tags/ +gtags.files +GTAGS +GRTAGS +GPATH +cscope.files +cscope.out +cscope.in.out +cscope.po.out + + + diff --git a/src/crypto/tree-hash.c b/src/crypto/tree-hash.c index 342d49f..5a84c86 100644 --- a/src/crypto/tree-hash.c +++ b/src/crypto/tree-hash.c @@ -1,4 +1,4 @@ -// Copyright (c) 2014, AEON, The Monero Project +// Copyright (c) 2014, The Monero Project // // All rights reserved. // @@ -28,14 +28,55 @@ // // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers -#include #include #include #include #include "hash-ops.h" +#ifndef __FreeBSD__ + #include +#else + #include +#endif + +/// Quick check if this is power of two (use on unsigned types; in this case for size_t only) +bool ispowerof2_size_t(size_t x) { + return x && !(x & (x - 1)); +} + +/*** +* Round to power of two, for count>=3 and for count being not too large (as reasonable for tree hash calculations) +*/ +size_t tree_hash_cnt(size_t count) { + assert( count >= 3); // cases for 0,1,2 are handled elsewhere + // Round down the count size: fun(2**n)= 2**(n-1) to round down to power of two + size_t tmp = count - 1; + size_t jj = 1; + for (jj=1 ; tmp != 0 ; ++jj) { + tmp /= 2; // dividing by 2 until to get how many powers of 2 fits size_to tmp + } + size_t cnt = 1 << (jj-2); // cnt is the count, but rounded down to power of two + // printf("count=%zu cnt=%zu jj=%zu tmp=%zu \n" , count,cnt,jj,tmp); + assert( cnt > 0 ); assert( cnt >= count/2 ); assert( cnt <= count ); + assert( ispowerof2_size_t( cnt )); + return cnt; +} + void tree_hash(const char (*hashes)[HASH_SIZE], size_t count, char *root_hash) { +// The blockchain block at height 202612 http://monerochain.info/block/bbd604d2ba11ba27935e006ed39c9bfdd99b76bf4a50654bc1e1e61217962698 +// contained 514 transactions, that triggered bad calculation of variable "cnt" in the original version of this function +// as from CryptoNote code. +// +// This bug applies to all CN altcoins. +// +// Mathematical bug here was first published on 14:45:34 (GMT+2) 2014-09-04 by Rafal Freeman +// https://github.com/rfree2monero/bitmonero/commit/b417abfb7a297d09f1bbb6de29030f8de9952ac8 +// and soon also applied to CryptoNote (15:10 GMT+2), and BoolBerry used not fully correct work around: +// the work around of sizeof(size_t)*8 or <<3 as used before in 2 coins and in BBL later was blocking +// exploitation on normal platforms, how ever we strongly recommend the following fix because it removes +// mistake in mathematical formula. + assert(count > 0); if (count == 1) { memcpy(root_hash, hashes, HASH_SIZE); @@ -43,24 +84,30 @@ void tree_hash(const char (*hashes)[HASH_SIZE], size_t count, char *root_hash) { cn_fast_hash(hashes, 2 * HASH_SIZE, root_hash); } else { size_t i, j; - size_t cnt = count - 1; + + size_t cnt = tree_hash_cnt( count ); + size_t max_size_t = (size_t) -1; // max allowed value of size_t + assert( cnt < max_size_t/2 ); // reasonable size to avoid any overflows. /2 is extra; Anyway should be limited much stronger by logical code + // as we have sane limits on transactions counts in blockchain rules + char (*ints)[HASH_SIZE]; - for (i = 1; i < sizeof(size_t); i <<= 1) { - cnt |= cnt >> i; - } - cnt &= ~(cnt >> 1); - ints = alloca(cnt * HASH_SIZE); + size_t ints_size = cnt * HASH_SIZE; + ints = alloca(ints_size); memset( ints , 0 , ints_size); // allocate, and zero out as extra protection for using uninitialized mem + memcpy(ints, hashes, (2 * cnt - count) * HASH_SIZE); + for (i = 2 * cnt - count, j = 2 * cnt - count; j < cnt; i += 2, ++j) { cn_fast_hash(hashes[i], 64, ints[j]); } assert(i == count); + while (cnt > 2) { cnt >>= 1; for (i = 0, j = 0; j < cnt; i += 2, ++j) { cn_fast_hash(ints[i], 64, ints[j]); } } + cn_fast_hash(ints[0], 64, root_hash); } } From b802f6e510ca719142f3de0ac2020f32c50c1846 Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Sat, 11 Oct 2014 20:42:50 +0000 Subject: [PATCH 2/5] update seed node --- src/p2p/net_node.inl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 070a30c..d4496ac 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -219,7 +219,7 @@ namespace nodetool template bool node_server::init(const boost::program_options::variables_map& vm) { - ADD_HARDCODED_SEED_NODE("seed.aeoncoin.net:11180"); + ADD_HARDCODED_SEED_NODE("195.154.170.196:11180"); bool res = handle_command_line(vm); CHECK_AND_ASSERT_MES(res, false, "Failed to handle command line"); From 7b289d81df7a05e4da8e9082bf080853516fa949 Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Fri, 12 Sep 2014 22:57:32 +0000 Subject: [PATCH 3/5] output rng fix from boolberry --- src/cryptonote_core/blockchain_storage.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cryptonote_core/blockchain_storage.cpp b/src/cryptonote_core/blockchain_storage.cpp index 3f94539..93da8c1 100644 --- a/src/cryptonote_core/blockchain_storage.cpp +++ b/src/cryptonote_core/blockchain_storage.cpp @@ -985,7 +985,6 @@ size_t blockchain_storage::find_end_of_allowed_index(const std::vector(time(NULL))); CRITICAL_REGION_LOCAL(m_blockchain_lock); BOOST_FOREACH(uint64_t amount, req.amounts) { @@ -1008,7 +1007,7 @@ bool blockchain_storage::get_random_outs_for_amounts(const COMMAND_RPC_GET_RANDO size_t try_count = 0; for(uint64_t j = 0; j != req.outs_count && try_count < up_index_limit;) { - size_t i = rand()%up_index_limit; + size_t i = crypto::rand()%up_index_limit; if(used.count(i)) continue; bool added = add_out_to_get_random_outs(amount_outs, result_outs, amount, i); From 4d5d2b6afc3fcdb817bce7363a8efce967f2bf23 Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Sat, 11 Oct 2014 21:00:05 +0000 Subject: [PATCH 4/5] remove obsolete contact information from README --- README | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README b/README index 890e6fc..5e1f569 100644 --- a/README +++ b/README @@ -8,10 +8,10 @@ Copyright (c) 2014, AEON, The Monero Project Development Resources --------------------- -Web: aeoncoin.net -Mail: aeon.coin@gmail.com -Github: https://github.com/aeonix/aeon -IRC: #aeon on Freenode +Web: tbd +Mail: tbd +Github: https://github.com/iamsmooth/aeon +IRC: tbd ------------ Introduction From ac085309f2f1c0e75bb46ea223eca532e094cb1c Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Sun, 12 Oct 2014 16:21:35 +0000 Subject: [PATCH 5/5] update checkpoints --- src/cryptonote_core/checkpoints_create.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index 02adf33..19ed135 100644 --- a/src/cryptonote_core/checkpoints_create.h +++ b/src/cryptonote_core/checkpoints_create.h @@ -38,8 +38,13 @@ namespace cryptonote { inline bool create_checkpoints(cryptonote::checkpoints& checkpoints) { - ADD_CHECKPOINT(10000, "1ac1ebd25baf0d6ec593daa3389f1aa7e860ff2cc29f3cf1be586d245b379da4"); - ADD_CHECKPOINT(15000, "15567af42afc1ed00538f53b5e3822d421e3ed6372ca79f4ea4e3e3bab709a87"); + ADD_CHECKPOINT(1, "1440a20f078bf3264822234b347f8382606577d73d4e9d3cb7296d73889bc421"); + ADD_CHECKPOINT(100, "6dd13aaab16679f49ee6b2b75c7dc99b1fd09ab2282b18cb4b55b73110655742"); + ADD_CHECKPOINT(1000, "bc6458452fd0575a314089bf302f6fd68ebaa2d689c42f3365293b96bbdf1f25"); + ADD_CHECKPOINT(10000, "1ac1ebd25baf0d6ec593daa3389f1aa7e860ff2cc29f3cf1be586d245b379da4"); + ADD_CHECKPOINT(15000, "15567af42afc1ed00538f53b5e3822d421e3ed6372ca79f4ea4e3e3bab709a87"); + ADD_CHECKPOINT(175500, "3f7dd748b3b863b04654d87a387f2b65a365f467188971f3192eab2368e64a35"); + return true; } }