What changed, and why it matters
This Monero wallet update fixes a bug where transaction proofs for older 'version 1' transactions could be generated or checked using incomplete (pruned) transaction data. The wallet now automatically re-fetches the full unpruned transaction when it detects a pruned v1 transaction, ensuring proofs are based on complete data. The change also removes duplicated transaction-fetching code by introducing a shared helper function.
Review the new get_tx_for_proof loop to ensure it cannot be induced to loop indefinitely by a malicious or misbehaving daemon, and confirm that error handling covers malformed full-transaction responses. Consider whether the fix should be backported to supported release branches.
Security signals we found
Correctness fix for cryptographic proof generation/verification relying on incomplete transaction data
Refactoring to reduce duplicated daemon RPC transaction-fetching code
Addition of unit test covering v1 pruned-tx fallback and v2 no-fallback behavior
Potential denial-of-service vector: loop re-requests daemon on pruned v1 tx; no explicit retry limit
Evidence from the diff
The commit refactors get_tx_proof and check_tx_proof in wallet2 to use a new helper get_tx_for_proof. The helper requests the pruned transaction from the daemon, parses it, and if the transaction is version 1 and still pruned, re-requests the full unpruned transaction in a loop. This addresses a correctness issue where v1 transactions, which may be stored pruned, lacked data needed for reliable proof generation/verification. A unit test verifies that a v1 transaction triggers both a pruned and a full request, while a v2 transaction only triggers a pruned request.
Changed components
src/wallet/wallet2.cppsrc/wallet/wallet2.htests/unit_tests/wallet_pool.cppInspect captured patch +111 / −33
### src/wallet/wallet2.cpp
@@ -12732,15 +12732,16 @@ bool wallet2::is_out_to_acc(const cryptonote::account_public_address &address, c
return found;
}
-std::string wallet2::get_tx_proof(const crypto::hash &txid, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message)
+COMMAND_RPC_GET_TRANSACTIONS::entry wallet2::get_tx_for_proof(const crypto::hash &txid, cryptonote::transaction &tx)
{
- // fetch tx pubkey from the daemon
- COMMAND_RPC_GET_TRANSACTIONS::request req;
- COMMAND_RPC_GET_TRANSACTIONS::response res;
- req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid));
- req.decode_as_json = false;
- req.prune = true;
+ COMMAND_RPC_GET_TRANSACTIONS::request req;
+ req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid));
+ req.decode_as_json = false;
+ req.prune = true;
+ for (;;)
+ {
+ COMMAND_RPC_GET_TRANSACTIONS::response res;
bool ok;
{
const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex};
@@ -12749,13 +12750,29 @@ std::string wallet2::get_tx_proof(const crypto::hash &txid, const cryptonote::ac
error::wallet_internal_error, "Failed to get transaction from daemon");
}
- cryptonote::transaction tx;
+ cryptonote::transaction fetched_tx;
crypto::hash tx_hash;
- ok = get_pruned_tx(res.txs.front(), tx, tx_hash);
+ ok = get_pruned_tx(res.txs.front(), fetched_tx, tx_hash);
THROW_WALLET_EXCEPTION_IF(!ok, error::wallet_internal_error, "Failed to parse transaction from daemon");
-
THROW_WALLET_EXCEPTION_IF(tx_hash != txid, error::wallet_internal_error, "Failed to get the right transaction from daemon");
+ if (fetched_tx.version == 1 && fetched_tx.pruned)
+ {
+ THROW_WALLET_EXCEPTION_IF(!req.prune, error::wallet_internal_error, "Failed to get full transaction from daemon");
+ req.prune = false;
+ continue;
+ }
+
+ tx = std::move(fetched_tx);
+ return std::move(res.txs.front());
+ }
+}
+
+std::string wallet2::get_tx_proof(const crypto::hash &txid, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message)
+{
+ cryptonote::transaction tx;
+ get_tx_for_proof(txid, tx);
+
// determine if the address is found in the subaddress hash table (i.e. whether the proof is outbound or inbound)
crypto::secret_key tx_key = crypto::null_skey;
std::vector<crypto::secret_key> additional_tx_keys;
@@ -12927,39 +12944,20 @@ std::string wallet2::get_tx_proof(const cryptonote::transaction &tx, const crypt
bool wallet2::check_tx_proof(const crypto::hash &txid, const cryptonote::account_public_address &address, bool is_subaddress, const std::string &message, const std::string &sig_str, uint64_t &received, bool &in_pool, uint64_t &confirmations)
{
- // fetch tx pubkey from the daemon
- COMMAND_RPC_GET_TRANSACTIONS::request req;
- COMMAND_RPC_GET_TRANSACTIONS::response res;
- req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid));
- req.decode_as_json = false;
- req.prune = true;
-
- bool ok;
- {
- const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex};
- ok = net_utils::invoke_http_json("/gettransactions", req, res, *m_http_client);
- THROW_WALLET_EXCEPTION_IF(!ok || res.txs.size() != 1,
- error::wallet_internal_error, "Failed to get transaction from daemon");
- }
-
cryptonote::transaction tx;
- crypto::hash tx_hash;
- ok = get_pruned_tx(res.txs.front(), tx, tx_hash);
- THROW_WALLET_EXCEPTION_IF(!ok, error::wallet_internal_error, "Failed to parse transaction from daemon");
-
- THROW_WALLET_EXCEPTION_IF(tx_hash != txid, error::wallet_internal_error, "Failed to get the right transaction from daemon");
+ const auto tx_entry = get_tx_for_proof(txid, tx);
if (!check_tx_proof(tx, address, is_subaddress, message, sig_str, received))
return false;
- in_pool = res.txs.front().in_pool;
+ in_pool = tx_entry.in_pool;
confirmations = 0;
if (!in_pool)
{
std::string err;
uint64_t bc_height = get_daemon_blockchain_height(err);
- if (err.empty() && bc_height > res.txs.front().block_height)
- confirmations = bc_height - res.txs.front().block_height;
+ if (err.empty() && bc_height > tx_entry.block_height)
+ confirmations = bc_height - tx_entry.block_height;
}
return true;
### src/wallet/wallet2.h
@@ -1582,6 +1582,7 @@ namespace tools
void handle_reorg(uint64_t height, std::map<std::pair<uint64_t, uint64_t>, size_t> *output_tracker_cache = NULL);
void get_short_chain_history(std::list<crypto::hash>& ids, uint64_t granularity = 1) const;
bool clear();
+ cryptonote::COMMAND_RPC_GET_TRANSACTIONS::entry get_tx_for_proof(const crypto::hash &txid, cryptonote::transaction &tx);
void clear_soft(bool keep_key_images=false);
/*
* clear_user_data clears data created by the user, which is mostly data
### tests/unit_tests/wallet_pool.cpp
@@ -399,6 +399,85 @@ namespace
}
}
+TEST(wallet_pool, fetches_full_v1_transaction_for_tx_proof)
+{
+ cryptonote::transaction tx;
+ crypto::hash txid;
+ size_t pruned_requests = 0;
+ size_t full_requests = 0;
+ bool wrong_full_transaction = false;
+ const auto pool_reply = [](const cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::request &,
+ cryptonote::COMMAND_RPC_GET_BLOCKS_FAST::response &) {};
+ const auto tx_reply = [&](const cryptonote::COMMAND_RPC_GET_TRANSACTIONS::request &request,
+ cryptonote::COMMAND_RPC_GET_TRANSACTIONS::response &response)
+ {
+ EXPECT_EQ(1, request.txs_hashes.size());
+ EXPECT_EQ(epee::string_tools::pod_to_hex(txid), request.txs_hashes.front());
+ ++(request.prune ? pruned_requests : full_requests);
+ response.txs.emplace_back();
+ auto &entry = response.txs.back();
+ entry.tx_hash = epee::string_tools::pod_to_hex(txid);
+ entry.prunable_hash = epee::string_tools::pod_to_hex(crypto::null_hash);
+ entry.in_pool = tx.version == 1;
+ auto reply_tx = tx;
+ if (!request.prune && wrong_full_transaction)
+ ++reply_tx.unlock_time;
+ auto blob = cryptonote::tx_to_blob(reply_tx);
+ if (request.prune)
+ {
+ EXPECT_TRUE(cryptonote::prune_transaction_blob(blob));
+ entry.pruned_as_hex = epee::string_tools::buff_to_hex_nodelimer(blob);
+ }
+ else
+ entry.as_hex = epee::string_tools::buff_to_hex_nodelimer(blob);
+ return true;
+ };
+
+ tools::wallet2 wallet(cryptonote::MAINNET, 1, true,
+ std::unique_ptr<epee::net_utils::http::http_client_factory>(new pool_http_client_factory(pool_reply, tx_reply)));
+ wallet.set_offline(true);
+ wallet.generate("", "");
+ wallet.set_offline(false);
+ const auto &address = wallet.get_account().get_keys().m_account_address;
+ tx = make_pool_payment(wallet);
+ tx.signatures.resize(1);
+ tx.signatures[0].resize(1);
+ ASSERT_EQ(1, tx.version);
+ txid = cryptonote::get_transaction_hash(tx);
+ cryptonote::transaction parsed_tx;
+ ASSERT_TRUE(cryptonote::parse_and_validate_tx_from_blob(cryptonote::tx_to_blob(tx), parsed_tx));
+ ASSERT_EQ(txid, cryptonote::get_transaction_hash(parsed_tx));
+
+ const auto proof = wallet.get_tx_proof(txid, address, false, "v1 proof");
+ ASSERT_EQ(0, proof.find("InProofV2"));
+ EXPECT_EQ(1, pruned_requests);
+ EXPECT_EQ(1, full_requests);
+
+ uint64_t received = 0;
+ bool in_pool = false;
+ uint64_t confirmations = 0;
+ EXPECT_TRUE(wallet.check_tx_proof(txid, address, false, "v1 proof", proof, received, in_pool, confirmations));
+ EXPECT_GT(received, 0);
+ EXPECT_TRUE(in_pool);
+ EXPECT_EQ(2, pruned_requests);
+ EXPECT_EQ(2, full_requests);
+
+ wrong_full_transaction = true;
+ EXPECT_ANY_THROW(wallet.check_tx_proof(txid, address, false, "v1 proof", proof, received, in_pool, confirmations));
+ EXPECT_EQ(3, pruned_requests);
+ EXPECT_EQ(3, full_requests);
+
+ wrong_full_transaction = false;
+ ASSERT_TRUE(cryptonote::construct_miner_tx(2, 0, 0, 0, 0, address, tx, {}, 999, HF_VERSION_VIEW_TAGS + 1));
+ ASSERT_EQ(2, tx.version);
+ txid = cryptonote::get_transaction_hash(tx);
+ pruned_requests = full_requests = 0;
+ const auto v2_proof = wallet.get_tx_proof(txid, address, false, "v2 proof");
+ EXPECT_EQ(0, v2_proof.find("InProofV2"));
+ EXPECT_EQ(1, pruned_requests);
+ EXPECT_EQ(0, full_requests);
+}
+
TEST(wallet_pool, advances_cursor_on_successful_refresh)
{
cryptonote::transaction pool_tx;Why this scored 44/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.