Skip to content

Commit

Permalink
Merge pull request monero-project#136 from stoffu/aeon-fixed-ring-size
Browse files Browse the repository at this point in the history
Fix ring size to 3 from v8
  • Loading branch information
aeonix authored Aug 29, 2019
2 parents 3f41389 + 789adee commit cbe1b6a
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 51 deletions.
1 change: 1 addition & 0 deletions src/cryptonote_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
#define HF_VERSION_LONG_TERM_BLOCK_SIZE 8

#define HF_VERSION_ALLOW_V1_BORROMEAN 8
#define HF_VERSION_FIXED_RING_SIZE 8

#define PER_KB_FEE_QUANTIZATION_DECIMALS 8

Expand Down
33 changes: 29 additions & 4 deletions src/cryptonote_core/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2516,16 +2516,41 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
return false;
}

if (hf_version >= HF_VERSION_FIXED_RING_SIZE && mixin > min_mixin)
{
MERROR_VER("Tx " << get_transaction_hash(tx) << " has invalid ring size (" << (mixin + 1) << "), it should be 3");
tvc.m_low_mixin = true;
return false;
}

if (mixin < min_mixin)
{
if (n_unmixable >= 1 && n_mixable <= 1)
if (hf_version < HF_VERSION_FIXED_RING_SIZE)
{
// we don't count this case as non-private
if (n_unmixable >= 1 && n_mixable <= 1)
{
// we don't count this case as non-private
}
else
{
MDEBUG("Tx " << get_transaction_hash(tx) << " is non-private");
is_nofake_tx = true;
}
}
else
{
MDEBUG("Tx " << get_transaction_hash(tx) << " is non-private");
is_nofake_tx = true;
if (n_unmixable == 0)
{
MERROR_VER("Tx " << get_transaction_hash(tx) << " has too low ring size (" << (mixin + 1) << "), and no unmixable inputs");
tvc.m_low_mixin = true;
return false;
}
if (n_mixable > 1)
{
MERROR_VER("Tx " << get_transaction_hash(tx) << " has too low ring size (" << (mixin + 1) << "), and more than one mixable input with unmixable inputs");
tvc.m_low_mixin = true;
return false;
}
}
}

Expand Down
36 changes: 25 additions & 11 deletions src/simplewallet/simplewallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1841,7 +1841,12 @@ bool simple_wallet::set_default_ring_size(const std::vector<std::string> &args/*
}

if (ring_size != 0 && ring_size != DEFAULT_RING_SIZE)
message_writer() << tr("WARNING: this is a non default ring size, which may harm your privacy. Default is recommended.");
{
if (m_wallet->use_fork_rules(8, 0))
message_writer() << tr("WARNING: from v8, ring size will be fixed and this setting will be ignored.");
else
message_writer() << tr("WARNING: this is a non default ring size, which may harm your privacy. Default is recommended.");
}

const auto pwd_container = get_and_verify_password();
if (pwd_container)
Expand Down Expand Up @@ -2387,7 +2392,7 @@ simple_wallet::simple_wallet()
"store-tx-info <1|0>\n "
" Whether to store outgoing tx info (destination address, payment ID, tx secret key) for future reference.\n "
"default-ring-size <n>\n "
" Set the default ring size (default and minimum is 5).\n "
" Set the default ring size (obsolete).\n "
"auto-refresh <1|0>\n "
" Whether to automatically synchronize new blocks from the daemon.\n "
"refresh-type <full|optimize-coinbase|no-coinbase|default>\n "
Expand Down Expand Up @@ -4715,7 +4720,7 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
if (local_args.size() > 0 && parse_priority(local_args[0], priority))
local_args.erase(local_args.begin());

size_t ring_size = 0;
size_t ring_size = DEFAULT_RING_SIZE;
if(local_args.size() > 0) {
if(!epee::string_tools::get_xtype_from_string(ring_size, local_args[0]))
{
Expand All @@ -4730,14 +4735,17 @@ bool simple_wallet::transfer_main(int transfer_type, const std::vector<std::stri
local_args.erase(local_args.begin());
}
}
if (ring_size == 0)
ring_size = m_wallet->default_ring_size();
uint64_t adjusted_ring_size = m_wallet->adjust_ring_size(ring_size);
if (ring_size != 0 && adjusted_ring_size > ring_size)
{
fail_msg_writer() << (boost::format(tr("ring size %u is too small, minimum is %u")) % ring_size % adjusted_ring_size).str();
return true;
}
if (ring_size != 0 && adjusted_ring_size < ring_size)
{
fail_msg_writer() << (boost::format(tr("ring size %u is too large, maximum is %u")) % ring_size % adjusted_ring_size).str();
return true;
}

if (ring_size != 1)
priority = m_wallet->adjust_priority(priority);
Expand Down Expand Up @@ -5229,7 +5237,7 @@ bool simple_wallet::sweep_main(uint64_t below, bool locked, const std::vector<st
if (local_args.size() > 0 && parse_priority(local_args[0], priority))
local_args.erase(local_args.begin());

size_t ring_size = 0;
size_t ring_size = DEFAULT_RING_SIZE;
if(local_args.size() > 0) {
if(!epee::string_tools::get_xtype_from_string(ring_size, local_args[0]))
{
Expand All @@ -5244,14 +5252,17 @@ bool simple_wallet::sweep_main(uint64_t below, bool locked, const std::vector<st
local_args.erase(local_args.begin());
}
}
if (ring_size == 0)
ring_size = m_wallet->default_ring_size();
uint64_t adjusted_ring_size = m_wallet->adjust_ring_size(ring_size);
if (ring_size != 0 && adjusted_ring_size > ring_size)
{
fail_msg_writer() << (boost::format(tr("ring size %u is too small, minimum is %u")) % ring_size % adjusted_ring_size).str();
return true;
}
if (ring_size != 0 && adjusted_ring_size < ring_size)
{
fail_msg_writer() << (boost::format(tr("ring size %u is too large, maximum is %u")) % ring_size % adjusted_ring_size).str();
return true;
}

if (ring_size != 1)
priority = m_wallet->adjust_priority(priority);
Expand Down Expand Up @@ -5482,7 +5493,7 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
if (local_args.size() > 0 && parse_priority(local_args[0], priority))
local_args.erase(local_args.begin());

size_t ring_size = 0;
size_t ring_size = DEFAULT_RING_SIZE;
if(local_args.size() > 0) {
if(!epee::string_tools::get_xtype_from_string(ring_size, local_args[0]))
{
Expand All @@ -5497,14 +5508,17 @@ bool simple_wallet::sweep_single(const std::vector<std::string> &args_)
local_args.erase(local_args.begin());
}
}
if (ring_size == 0)
ring_size = m_wallet->default_ring_size();
uint64_t adjusted_ring_size = m_wallet->adjust_ring_size(ring_size);
if (ring_size != 0 && adjusted_ring_size > ring_size)
{
fail_msg_writer() << (boost::format(tr("ring size %u is too small, minimum is %u")) % ring_size % adjusted_ring_size).str();
return true;
}
if (ring_size != 0 && adjusted_ring_size < ring_size)
{
fail_msg_writer() << (boost::format(tr("ring size %u is too large, maximum is %u")) % ring_size % adjusted_ring_size).str();
return true;
}

if (ring_size != 1)
priority = m_wallet->adjust_priority(priority);
Expand Down
49 changes: 40 additions & 9 deletions src/wallet/wallet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5835,11 +5835,44 @@ int wallet2::get_fee_algorithm() const
return 0;
}
//------------------------------------------------------------------------------------------------------------------------------
uint64_t wallet2::get_min_ring_size() const
{
if (use_fork_rules(8, 10))
return 3;
return 0;
}
//------------------------------------------------------------------------------------------------------------------------------
uint64_t wallet2::get_max_ring_size() const
{
if (use_fork_rules(8, 10))
return 3;
return 0;
}
//------------------------------------------------------------------------------------------------------------------------------
uint64_t wallet2::adjust_ring_size(uint64_t ring_size) const
{
if (ring_size == 2 && use_fork_rules(2, 10)) {
MWARNING("Requested ring size 2 is too low for hard fork 2, using 3");
ring_size = 3;
if (use_fork_rules(8, 10))
{
const uint64_t min_ring_size = get_min_ring_size();
if (ring_size < min_ring_size)
{
MWARNING("Requested ring size " << ring_size << " too low, using " << min_ring_size);
ring_size = min_ring_size;
}
const uint64_t max_ring_size = get_max_ring_size();
if (max_ring_size && ring_size > max_ring_size)
{
MWARNING("Requested ring size " << ring_size << " too high, using " << max_ring_size);
ring_size = max_ring_size;
}
}
else
{
if (ring_size == 2)
{
MWARNING("Requested ring size 2 is too low for hard fork 2, using 3");
ring_size = 3;
}
}
return ring_size;
}
Expand Down Expand Up @@ -8753,16 +8786,14 @@ const wallet2::transfer_details &wallet2::get_transfer_details(size_t idx) const
//----------------------------------------------------------------------------------------------------
std::vector<size_t> wallet2::select_available_unmixable_outputs()
{
// request all outputs with less than 3 instances
const size_t min_mixin = 2;
return select_available_outputs_from_histogram(min_mixin + 1, false, true, false);
// request all outputs with less instances than the min ring size
return select_available_outputs_from_histogram(get_min_ring_size(), false, true, false);
}
//----------------------------------------------------------------------------------------------------
std::vector<size_t> wallet2::select_available_mixable_outputs()
{
// request all outputs with at least 3 instances, so we can use mixin 2 with
const size_t min_mixin = 2;
return select_available_outputs_from_histogram(min_mixin + 1, true, true, true);
// request all outputs with at least as many instances as the min ring size
return select_available_outputs_from_histogram(get_min_ring_size(), true, true, true);
}
//----------------------------------------------------------------------------------------------------
std::vector<wallet2::pending_tx> wallet2::create_unmixable_sweep_transactions()
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/wallet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,8 @@ namespace tools

uint64_t get_fee_multiplier(uint32_t priority, int fee_algorithm = -1) const;
uint64_t get_per_kb_fee() const;
uint64_t get_min_ring_size() const;
uint64_t get_max_ring_size() const;
uint64_t adjust_ring_size(uint64_t ring_size) const;
uint32_t adjust_priority(uint32_t priority);

Expand Down
Loading

0 comments on commit cbe1b6a

Please sign in to comment.