What changed, and why it matters
This update puts hard caps on transaction fee values that a Monero wallet will accept from a connected daemon (node). Before this change, a malicious or compromised node could tell the wallet to use extremely high fees, potentially draining a user's balance through excessive transaction costs. After the change, the wallet clamps any daemon-supplied fee parameter to safe maximums and logs a warning when it does so. The change also fixes a related bug where the wallet sometimes asked for the wrong fee type (per-byte vs per-kilobyte).
Users should upgrade to a wallet release containing this commit, especially when connecting to untrusted or third-party daemons. Until upgraded, avoid using remote nodes you do not control for fee-sensitive operations, and review transaction fees before signing.
Security signals we found
Daemon-supplied fee parameters are now clamped to wallet-side maxima
New clamp_fee_parameter helper logs when daemon values exceed safe bounds
Fee quantization mask is bounded to a hardcoded power-of-ten constant
Per-byte vs per-kB fee path is correctly propagated to get_base_fee
NodeRPCProxy now caches the full fee vector for later clamped lookups
Evidence from the diff
The patch adds upper-bound clamps to daemon-provided fee parameters in the Monero wallet. It introduces MAX_2021_FEES_PER_BYTE and FEE_QUANTIZATION_MASK constants, plus a clamp_fee_parameter helper, and applies them in calculate_fee, calculate_fee_from_weight, wallet2::get_base_fee, wallet2::get_fee_quantization_mask, and NodeRPCProxy fee caching. It also threads a use_per_byte_fee flag into get_base_fee overloads so the wallet selects the correct per-byte or per-kB limit when clamping. The fix is defensive: it prevents a rogue daemon from setting abusive fees or an oversized quantization mask.
Changed components
src/wallet/wallet2.cppsrc/wallet/wallet2.hsrc/wallet/api/wallet.cppsrc/wallet/node_rpc_proxy.cppInspect captured patch +45 / −14
### src/wallet/api/wallet.cpp
@@ -2002,9 +2002,10 @@ uint64_t WalletImpl::estimateTransactionFee(const std::vector<std::pair<std::str
const size_t pubkey_size = 33;
const size_t encrypted_paymentid_size = 11;
const size_t extra_size = pubkey_size + encrypted_paymentid_size;
+ const bool use_per_byte_fee = m_wallet->use_fork_rules(HF_VERSION_PER_BYTE_FEE, 0);
return m_wallet->estimate_fee(
- m_wallet->use_fork_rules(HF_VERSION_PER_BYTE_FEE, 0),
+ use_per_byte_fee,
m_wallet->use_fork_rules(4, 0),
1,
std::max<uint64_t>(m_wallet->get_min_ring_size(), 1) - 1,
@@ -2014,7 +2015,7 @@ uint64_t WalletImpl::estimateTransactionFee(const std::vector<std::pair<std::str
m_wallet->use_fork_rules(HF_VERSION_CLSAG, 0),
m_wallet->use_fork_rules(HF_VERSION_BULLETPROOF_PLUS, 0),
m_wallet->use_fork_rules(HF_VERSION_VIEW_TAGS, 0),
- m_wallet->get_base_fee(static_cast<uint32_t>(priority)),
+ m_wallet->get_base_fee(static_cast<uint32_t>(priority), use_per_byte_fee),
m_wallet->get_fee_quantization_mask());
}
### src/wallet/node_rpc_proxy.cpp
@@ -290,6 +290,7 @@ boost::optional<std::string> NodeRPCProxy::get_fee_quantization_mask(uint64_t &f
m_dynamic_base_fee_estimate = resp_t.fee;
m_dynamic_base_fee_estimate_cached_height = height;
+ m_dynamic_base_fee_estimate_vector = !resp_t.fees.empty() ? std::move(resp_t.fees) : std::vector<uint64_t>{m_dynamic_base_fee_estimate};
m_fee_quantization_mask = resp_t.quantization_mask;
}
### src/wallet/wallet2.cpp
@@ -88,6 +88,7 @@ using namespace epee;
#include "common/dns_utils.h"
#include "common/notify.h"
#include "common/perf_timer.h"
+#include "common/powerof.h"
#include "ringct/rctSigs.h"
#include "ringdb.h"
#include "device/device_cold.hpp"
@@ -301,14 +302,33 @@ void do_prepare_file_names(const std::string& file_path, std::string& keys_file,
mms_file = file_path + ".mms";
}
+// 2021 fee maxima at reward MONEY_SUPPLY >> 19 and Mnw = Mlw = 300000,
+// rounded up to two significant digits. Also used to bound older fee paths.
+constexpr std::array<uint64_t, 4> MAX_2021_FEES_PER_BYTE = {1200000, 4700000, 19000000, 240000000};
+constexpr uint64_t FEE_QUANTIZATION_MASK = tools::PowerOf<10, CRYPTONOTE_DISPLAY_DECIMAL_POINT - PER_KB_FEE_QUANTIZATION_DECIMALS>::Value;
+
+uint64_t clamp_fee_parameter(uint64_t value, uint64_t limit, const char *parameter)
+{
+ if (value > limit)
+ {
+ MWARNING(parameter << " " << value
+ << " exceeds wallet fee limit " << limit << ", clamping");
+ return limit;
+ }
+ return value;
+}
+
uint64_t calculate_fee(uint64_t fee_per_kb, size_t bytes)
{
+ fee_per_kb = clamp_fee_parameter(fee_per_kb, MAX_2021_FEES_PER_BYTE.back() * 1024, "fee per kB");
uint64_t kB = (bytes + 1023) / 1024;
return kB * fee_per_kb;
}
uint64_t calculate_fee_from_weight(uint64_t base_fee, uint64_t weight, uint64_t fee_quantization_mask)
{
+ base_fee = clamp_fee_parameter(base_fee, MAX_2021_FEES_PER_BYTE.back(), "fee per byte");
+ fee_quantization_mask = std::max<uint64_t>(1, clamp_fee_parameter(fee_quantization_mask, FEE_QUANTIZATION_MASK, "fee quantization mask"));
THROW_WALLET_EXCEPTION_IF(base_fee != 0 && weight > std::numeric_limits<uint64_t>::max() / base_fee,
tools::error::wallet_internal_error, "Fee calculation overflow");
uint64_t fee = weight * base_fee;
@@ -9102,12 +9122,12 @@ uint64_t wallet2::get_base_fee()
return get_dynamic_base_fee_estimate();
}
//----------------------------------------------------------------------------------------------------
-uint64_t wallet2::get_base_fee(uint32_t priority)
+uint64_t wallet2::get_base_fee(uint32_t priority, boost::optional<bool> use_per_byte_fee)
{
- return get_base_fee(fee_priority_utilities::from_integral(priority));
+ return get_base_fee(fee_priority_utilities::from_integral(priority), use_per_byte_fee);
}
//----------------------------------------------------------------------------------------------------
-uint64_t wallet2::get_base_fee(fee_priority priority)
+uint64_t wallet2::get_base_fee(fee_priority priority, boost::optional<bool> use_per_byte_fee)
{
const bool use_2021_scaling = use_fork_rules(HF_VERSION_2021_SCALING, -30 * 1);
if (use_2021_scaling)
@@ -9130,13 +9150,22 @@ uint64_t wallet2::get_base_fee(fee_priority priority)
MERROR("Failed to determine base fee for priority " << priority_index << ", using default");
return FEE_PER_BYTE;
}
- return fees[priority_index];
+ return clamp_fee_parameter(fees[priority_index], MAX_2021_FEES_PER_BYTE[std::min<size_t>(priority_index, MAX_2021_FEES_PER_BYTE.size() - 1)], "fee estimate");
}
else
{
+ const auto fee_algorithm = get_fee_algorithm();
+ if (priority == fee_priority::Default)
+ priority = m_default_priority;
+ if (priority == fee_priority::Default)
+ priority = fee_algorithm >= fee_algorithm::HardforkV5 ? fee_priority::Normal : fee_priority::Unimportant;
+
const uint64_t base_fee = get_base_fee();
- const uint64_t fee_multiplier = get_fee_multiplier(priority);
- return base_fee * fee_multiplier;
+ const uint64_t fee_multiplier = get_fee_multiplier(priority, fee_algorithm);
+ const auto priority_index = fee_priority_utilities::as_integral(fee_priority_utilities::decrease(fee_priority_utilities::clamp_modified(priority)));
+ const bool per_byte = use_per_byte_fee ? *use_per_byte_fee : use_fork_rules(HF_VERSION_PER_BYTE_FEE, 0);
+ const uint64_t max_fee = MAX_2021_FEES_PER_BYTE[std::min<size_t>(priority_index, MAX_2021_FEES_PER_BYTE.size() - 1)] * (per_byte ? 1 : 1024);
+ return clamp_fee_parameter(base_fee, max_fee / fee_multiplier, per_byte ? "fee per byte" : "fee per kB") * fee_multiplier;
}
}
//----------------------------------------------------------------------------------------------------
@@ -9150,7 +9179,7 @@ uint64_t wallet2::get_fee_quantization_mask()
boost::optional<std::string> result = m_node_rpc_proxy.get_fee_quantization_mask(fee_quantization_mask);
if (result)
return 1;
- return fee_quantization_mask;
+ return clamp_fee_parameter(fee_quantization_mask, FEE_QUANTIZATION_MASK, "fee quantization mask");
}
//----------------------------------------------------------------------------------------------------
fee_algorithm wallet2::get_fee_algorithm()
@@ -10971,7 +11000,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
const bool use_view_tags = use_fork_rules(get_view_tag_fork(), 0);
std::unordered_set<crypto::public_key> valid_public_keys_cache;
- const uint64_t base_fee = get_base_fee(priority);
+ const uint64_t base_fee = get_base_fee(priority, use_per_byte_fee);
const uint64_t fee_quantization_mask = get_fee_quantization_mask();
// throw if attempting a transaction with no destinations
@@ -11618,7 +11647,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_all(uint64_t below
const bool bulletproof_plus = use_fork_rules(get_bulletproof_plus_fork(), 0);
const bool clsag = use_fork_rules(get_clsag_fork(), 0);
const bool use_view_tags = use_fork_rules(get_view_tag_fork(), 0);
- const uint64_t base_fee = get_base_fee(priority);
+ const uint64_t base_fee = get_base_fee(priority, use_per_byte_fee);
const size_t tx_weight_one_ring = estimate_tx_weight(use_rct, 1, fake_outs_count, 2, 0, bulletproof, clsag, bulletproof_plus, use_view_tags);
const size_t tx_weight_two_rings = estimate_tx_weight(use_rct, 2, fake_outs_count, 2, 0, bulletproof, clsag, bulletproof_plus, use_view_tags);
THROW_WALLET_EXCEPTION_IF(tx_weight_one_ring > tx_weight_two_rings, error::wallet_internal_error, "Estimated tx weight with 1 input is larger than with 2 inputs!");
@@ -11735,7 +11764,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_from(const crypton
bulletproof_plus ? 4 : 3
};
const bool use_view_tags = use_fork_rules(get_view_tag_fork(), 0);
- const uint64_t base_fee = get_base_fee(priority);
+ const uint64_t base_fee = get_base_fee(priority, use_per_byte_fee);
const uint64_t fee_quantization_mask = get_fee_quantization_mask();
LOG_PRINT_L2("Starting with " << unused_transfers_indices.size() << " non-dust outputs and " << unused_dust_indices.size() << " dust outputs");
### src/wallet/wallet2.h
@@ -1428,7 +1428,7 @@ namespace tools
static uint64_t estimate_fee(bool use_per_byte_fee, bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof, bool clsag, bool bulletproof_plus, bool use_view_tags, uint64_t base_fee, uint64_t fee_quantization_mask);
uint64_t get_fee_multiplier(fee_priority priority, fee_algorithm fee_algorithm = fee_algorithm::Unset);
- uint64_t get_base_fee(fee_priority priority);
+ uint64_t get_base_fee(fee_priority priority, boost::optional<bool> use_per_byte_fee = boost::none);
uint64_t get_base_fee();
uint64_t get_fee_quantization_mask();
uint64_t get_min_ring_size();
@@ -1442,7 +1442,7 @@ namespace tools
after casting from a type (PendingTransaction::FeePriority) which I don't want to touch.
*/
fee_priority adjust_priority(uint32_t priority);
- uint64_t get_base_fee(uint32_t);
+ uint64_t get_base_fee(uint32_t priority, boost::optional<bool> use_per_byte_fee = boost::none);
bool is_unattended() const { return m_unattended; }
Why this scored 65/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.