Attcker can trick monero wallet into reporting it recived twice as much with alternative tx_keypubs
An attacker can craft a Monero transaction with a dummy primary public key and an array of alternative public keys that match the legitimate key, causing the receiving wallet to report double the amount received via the get_transfers RPC call. This can be exploited against automated wallets like exchanges to steal funds by depositing and withdrawing the inflated balance.
- Triaged in 13 hours
- Fixed in 19 days
- Disclosed after 20 days
Summary: multiple identical tx_pub_keys were patched, but you can still use alternative tx_pub_keys to get the same result.
Description: An attacker can craft an XMR transaction which causes the receiving wallet to report that it received twice as much XMR as the attacker actually sent.
The balance of the wallet isn't effected, so a personal user probably won't be ticked, however the doubled amount is reported over the get_transfers RPC call.
This is especially devastating for automated wallets, such as cryptocurrency exchanges that rely on RPC calls returning the correct result.
This attack is a slight modification of the previous flaw that was patched in pull request 3985. That flaw allows unlimited multiplication of funds, instead of just a 2x multiplication that this attack allows.
This attack leverages the alternative tx_pub_keys feature introduced with subaddresses. extra data is arranged so it contains:
- A dummy tx_pub_key
- An array of alternative tx_pub_keys entries all containing the legitimate txkey for each output.
- The legitimate tx_pub_key
The process_new_transaction function will:
- Grab the dummy tx_pub_key
- Grab the array of alternative tx_pub_keys
- Scan all the outputs with both the dummy and alternative tx_pub_keys. Which will match on the legitimate tx_pub_keys.
- Loop back to the start, grab the legitimate tx_pub_key
- Since the alternative keys were not added into the public_keys_seen set, it scans all the outputs again.
- Hacked.
Releases Affected:
- Monero master ebf2818ab5f42b10745cb99d07920f3197c3d914
- Monero 0.12.3.0 release tag
- Probably any Monero release since subaddresses were introduced
Steps To Reproduce:
- On the attacking wallet, Patch cryptonote_tx_utils.cpp
diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp
index 071ce591..3835690a 100644
--- a/src/cryptonote_core/cryptonote_tx_utils.cpp
+++ b/src/cryptonote_core/cryptonote_tx_utils.cpp
@@ -351,9 +351,15 @@ namespace cryptonote
txkey_pub = rct::rct2pk(hwdev.scalarmultBase(rct::sk2rct(tx_key)));
}
remove_field_from_tx_extra(tx.extra, typeid(tx_extra_pub_key));
- add_tx_pub_key_to_extra(tx, txkey_pub);
+ crypto::public_key dummy_key;
+ add_tx_pub_key_to_extra(tx, dummy_key);
std::vector<crypto::public_key> additional_tx_public_keys;
+ for (size_t i = 0; i < destinations.size(); i++)
+ additional_tx_public_keys.push_back(txkey_pub); // One for each output.
+
+ add_additional_tx_pub_keys_to_extra(tx.extra, additional_tx_public_keys);
+ add_tx_pub_key_to_extra(tx, txkey_pub);
// we don't need to include additional tx keys if:
// - all the destinations are standard addresses
@@ -421,9 +427,9 @@ namespace cryptonote
output_index++;
summary_outs_money += dst_entr.amount;
}
- CHECK_AND_ASSERT_MES(additional_tx_public_keys.size() == additional_tx_keys.size(), false, "Internal error creating additional public keys");
+ //CHECK_AND_ASSERT_MES(additional_tx_public_keys.size() == additional_tx_keys.size(), false, "Internal error creating additional public keys");
- remove_field_from_tx_extra(tx.extra, typeid(tx_extra_additional_pub_keys));
+ //remove_field_from_tx_extra(tx.extra, typeid(tx_extra_additional_pub_keys));
LOG_PRINT_L2("tx pubkey: " << txkey_pub);
if (need_additional_txkeys)
2\. Compile wallet
3\. Do a regular transfer to an exchange wallet.
4\. Profit.
## Impact
By depositing and withdrawing the same coins, doubling each time; The attacker could eventually steal all XMR from an exchange hotwallet.
Context
Monero is a privacy-focused cryptocurrency. A wallet receives funds by scanning the blockchain for outputs addressed to it. Each transaction carries a public key, the tx_pub_key, in its extra field, and the receiver derives a one-time output key from that public key and its own view key. With the introduction of subaddresses, Monero added a second mechanism: a transaction can carry an array of alternative tx_pub_key entries, one per output, so that outputs to different subaddresses can each be scanned with their own key.
The feature at issue is the wallet's transaction scanning logic, specifically process_new_transaction, and the way it reports incoming transfers over the get_transfers RPC call. That RPC call is what automated systems, such as cryptocurrency exchanges, use to credit deposits.
Setup
The report lists the affected releases:
- Monero master
[redacted] - Monero
[redacted]release tag - Probably any Monero release since subaddresses were introduced
The researcher needed a Monero wallet they controlled on the sending side, which they patched and recompiled, and a receiving wallet, in the described scenario an exchange wallet. The attack is a modification of an earlier flaw that was patched in pull request 3985, where multiple identical tx_pub_keys could be used. That earlier flaw allowed unlimited multiplication of funds; this one allows a 2x multiplication.
Finding it
The patch for the earlier issue handled identical tx_pub_keys. The alternative tx_pub_key mechanism introduced with subaddresses gives an attacker a way to present the same legitimate key through a different path, and the scanning code does not treat the two paths as the same key.
The result is that a crafted transaction makes the receiving wallet report that it received twice as much XMR as the attacker actually sent. The wallet balance itself is not affected, so a personal user is unlikely to notice. The doubled amount is what appears over the get_transfers RPC call, which is exactly what automated wallets and exchanges rely on.
Exploitation
The attacker arranges the transaction's extra data so that it contains, in order:
- A dummy
tx_pub_key - An array of alternative
tx_pub_keyentries, all containing the legitimate tx key for each output - The legitimate
tx_pub_key
When the receiving wallet processes the transaction, process_new_transaction does the following:
- Grab the dummy
tx_pub_key - Grab the array of alternative
tx_pub_keyentries - Scan all the outputs with both the dummy and the alternative
tx_pub_keys, which will match on the legitimatetx_pub_keys - Loop back to the start and grab the legitimate
tx_pub_key - Since the alternative keys were not added into the
public_keys_seenset, it scans all the outputs again - The outputs are counted twice
Step 1: Patch the attacking wallet
On the attacking wallet, patch cryptonote_tx_utils.cpp:
diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp
index 071ce591..3835690a 100644
--- a/src/cryptonote_core/cryptonote_tx_utils.cpp
+++ b/src/cryptonote_core/cryptonote_tx_utils.cpp
@@ -351,9 +351,15 @@ namespace cryptonote
txkey_pub = rct::rct2pk(hwdev.scalarmultBase(rct::sk2rct(tx_key)));
}
remove_field_from_tx_extra(tx.extra, typeid(tx_extra_pub_key));
- add_tx_pub_key_to_extra(tx, txkey_pub);
+ crypto::public_key dummy_key;
+ add_tx_pub_key_to_extra(tx, dummy_key);
std::vector<crypto::public_key> additional_tx_public_keys;
+ for (size_t i = 0; i < destinations.size(); i++)
+ additional_tx_public_keys.push_back(txkey_pub); // One for each output.
+
+ add_additional_tx_pub_keys_to_extra(tx.extra, additional_tx_public_keys);
+ add_tx_pub_key_to_extra(tx, txkey_pub);
// we don't need to include additional tx keys if:
// - all the destinations are standard addresses
@@ -421,9 +427,9 @@ namespace cryptonote
output_index++;
summary_outs_money += dst_entr.amount;
}
- CHECK_AND_ASSERT_MES(additional_tx_public_keys.size() == additional_tx_keys.size(), false, "Internal error creating additional public keys");
+ //CHECK_AND_ASSERT_MES(additional_tx_public_keys.size() == additional_tx_keys.size(), false, "Internal error creating additional public keys");
- remove_field_from_tx_extra(tx.extra, typeid(tx_extra_additional_pub_keys));
+ //remove_field_from_tx_extra(tx.extra, typeid(tx_extra_additional_pub_keys));
LOG_PRINT_L2("tx pubkey: " << txkey_pub);
if (need_additional_txkeys)
The patch changes how the transaction extra is built. Instead of writing only the legitimate txkey_pub, it first writes a dummy_key as the main tx_pub_key. It then pushes the legitimate txkey_pub into additional_tx_public_keys once for every destination, and writes that array into the extra field. Finally it appends the legitimate txkey_pub again as a main tx_pub_key. The two commented-out lines disable the consistency check between the additional public keys and the additional tx keys, and disable the removal of the additional pub keys field, so the crafted extra data survives into the final transaction.
Step 2: Compile the wallet
Compile the patched wallet.
Step 3: Send a regular transfer
Do a regular transfer to an exchange wallet. The transaction now carries the dummy key, the array of alternative keys holding the legitimate key, and the legitimate key itself.
Step 4: Profit
The receiving wallet scans the outputs once using the dummy and alternative keys, matching on the legitimate key, and then scans them again using the legitimate main key, because the alternative keys were never recorded in public_keys_seen. The same outputs are credited twice in the get_transfers result.
Root cause
The scanning logic in process_new_transaction tracks keys it has already seen in a public_keys_seen set, but the alternative tx_pub_key entries are not added to that set. When the same legitimate key later appears as the main tx_pub_key, it is not recognised as already processed, and every output is scanned and counted a second time. The earlier fix for identical tx_pub_keys did not cover this second route to the same key, so the defence was incomplete.
Impact
An attacker can make a receiving wallet report twice the amount actually sent. The wallet balance is not affected, so a personal user is unlikely to notice, but the doubled figure is returned by the get_transfers RPC call. Automated wallets, such as cryptocurrency exchanges that credit deposits based on RPC results, are the main target. By depositing and withdrawing the same coins and doubling each time, the attacker could eventually steal all XMR from an exchange hot wallet.
Fix
The report does not describe the fix that was applied.
Variants to test
- Duplicate keys through different fields. Where a protocol lets the same key be supplied through more than one field, try supplying it through each route in turn and check whether the receiver processes the same data twice. A positive result is a doubled amount in the receiver's reported transfers while the balance stays correct.
- Ordering of extra data. Try placing the dummy key, the alternative key array and the legitimate key in different orders, and check whether any ordering still produces a double count. A positive result is the same doubling in
get_transfers. - Multiple outputs. Send a transaction with several outputs and one alternative key per output, as in the patch, and check whether each output is counted twice. A positive result is a reported total of twice the sent amount across all outputs.
- Other clients and versions. Test wallets built from releases since subaddresses were introduced, and any client that consumes
get_transfers, to see whether the same crafted transaction is credited twice. A positive result is a credit based on the doubled figure.
What happened, in plain words
Monero is a digital currency built for privacy. When someone sends Monero to a wallet, the wallet does not receive a message saying "you got 5 XMR". Instead, the wallet reads the public record of all transactions (called the blockchain) and looks for entries that were addressed to it. If it finds one, it counts that money as received.
A security researcher found a way to build a transaction that makes the receiving wallet count the same money twice. The wallet's real balance stays correct, but the number it reports to whoever asks "how much did I receive?" is doubled. That matters most for automated systems, such as cryptocurrency exchanges, which credit a customer's account based on that reported number. If an exchange is told it received twice what was actually sent, the attacker can deposit, withdraw, and repeat, doubling the coins each round until the exchange's hot wallet is empty.
CVSS is a standard scoring system for how serious a security flaw is; 8.2 out of 10 is in the high range.
Background you need first
Before the details make sense, here are the ideas the report relies on.
- Cryptocurrency: digital money recorded on a shared public list rather than in a bank's private database. Monero is one such currency, designed so that the amounts and the people involved are hidden from casual observers.
- Wallet: the software that holds your Monero keys and talks to the network. It sends transactions and, importantly here, scans the blockchain to work out what it has received.
- Blockchain: the public, append-only record of every transaction ever made. Anyone can read it; nobody can quietly rewrite it.
- Transaction: a single transfer of coins from one wallet to another, recorded on the blockchain.
- Output: the part of a transaction that actually carries money to a recipient. One transaction can have several outputs, for example when you pay several people at once.
- Key: a long string of characters used in cryptography. A public key can be shared; a private key must be kept secret. Monero uses keys to hide who is paying whom.
tx_pub_key: a public key that a transaction carries so the receiver can work out which outputs are theirs. The receiver combines this key with its own secret view key to derive a one-time key for each output. Think of it as a label on a parcel: only the right recipient can read the label and open the box.- Subaddress: a secondary address that belongs to the same wallet. People use subaddresses to keep different payments separate without creating a whole new wallet. To support them, Monero added a feature: a transaction can carry an array (a list) of alternative
tx_pub_keyentries, one per output, so each output to a different subaddress can be scanned with its own key. - Extra field: a free-form area inside a transaction where the sender can put additional data, including these keys.
- RPC: Remote Procedure Call, a way for one program to ask another program to do something and return a result. Here, the
get_transfersRPC call is how an exchange's software asks a Monero wallet "what transfers have you received?". If you have ever used a website that quietly fetches data from a server in the background, that is the same idea. process_new_transaction: the function inside the wallet that examines a new transaction and decides which outputs belong to it.public_keys_seen: a set (a list that does not allow duplicates) in which the wallet records keys it has already used while scanning. Its purpose is to avoid scanning the same outputs twice.- Business logic error: a flaw not in the cryptography itself but in the rules the software follows. The maths is fine; the sequence of decisions is wrong. A shop that gives you a refund without checking you paid in the first place has a business logic error.
- Hot wallet: a wallet connected to the internet and used for day-to-day operations, as opposed to a cold wallet kept offline. Exchanges keep hot wallets to process customer withdrawals, which makes them attractive targets.
The setup
The report lists the affected releases:
- Monero master
[redacted] - Monero
[redacted]release tag - Probably any Monero release since subaddresses were introduced
A release tag is a label marking a specific published version of the software. The long string of letters and digits is a commit identifier, a unique fingerprint for one exact state of the source code.
To test the idea, the researcher needed two things: a Monero wallet they controlled on the sending side, which they modified and recompiled (rebuilt from source after editing), and a receiving wallet, in the scenario described an exchange's wallet. In the scenario described, the receiving wallet is an exchange's wallet.
This attack is a variation on an earlier flaw that had already been patched in pull request 3985. A pull request is a proposed change to a codebase, reviewed before it is merged. The earlier flaw let an attacker multiply funds without limit by repeating identical tx_pub_key values. The patch stopped that, but only for keys that were exactly identical. This new attack reaches the same result through a different route and allows a 2x multiplication.
How the researcher found it
The earlier fix only handled identical tx_pub_keys. The alternative tx_pub_key mechanism, added for subaddresses, gives an attacker a second way to present the same legitimate key. The scanning code does not treat the two routes as the same key, so it processes the outputs twice.
The effect: a crafted transaction makes the receiving wallet report that it received twice as much XMR as was actually sent. The wallet's balance is not affected, so an ordinary person using the wallet is unlikely to notice anything wrong. The doubled amount is what appears over the get_transfers RPC call, which is exactly what automated wallets and exchanges depend on.
How the attack works
The attacker arranges the transaction's extra data so that it contains, in this order:
- A dummy
tx_pub_key - An array of alternative
tx_pub_keyentries, all containing the legitimate tx key for each output - The legitimate
tx_pub_key
When the receiving wallet processes the transaction, process_new_transaction does the following:
- Grab the dummy
tx_pub_key - Grab the array of alternative
tx_pub_keyentries - Scan all the outputs with both the dummy and the alternative
tx_pub_keys, which will match on the legitimatetx_pub_keys - Loop back to the start and grab the legitimate
tx_pub_key - Since the alternative keys were not added into the
public_keys_seenset, it scans all the outputs again - The outputs are counted twice
In everyday terms: imagine a cloakroom attendant who writes down each coat as it is handed in. The rule is that once a ticket number has been recorded, the same coat is not counted again. The attacker hands in one coat but attaches two tickets, one of which the attendant does not recognise as already seen. The attendant counts the coat twice, and the tally says two coats were handed in.
Step 1: Patch the attacking wallet
On the attacking wallet, patch cryptonote_tx_utils.cpp. This is a source file in the Monero codebase that builds the extra data of a transaction. The block below is a diff: a standard way of showing changes to a file. Lines starting with - are removed, lines starting with + are added, and lines with no marker are unchanged context.
diff --git a/src/cryptonote_core/cryptonote_tx_utils.cpp b/src/cryptonote_core/cryptonote_tx_utils.cpp
index 071ce591..3835690a 100644
--- a/src/cryptonote_core/cryptonote_tx_utils.cpp
+++ b/src/cryptonote_core/cryptonote_tx_utils.cpp
@@ -351,9 +351,15 @@ namespace cryptonote
txkey_pub = rct::rct2pk(hwdev.scalarmultBase(rct::sk2rct(tx_key)));
}
remove_field_from_tx_extra(tx.extra, typeid(tx_extra_pub_key));
- add_tx_pub_key_to_extra(tx, txkey_pub);
+ crypto::public_key dummy_key;
+ add_tx_pub_key_to_extra(tx, dummy_key);
std::vector<crypto::public_key> additional_tx_public_keys;
+ for (size_t i = 0; i < destinations.size(); i++)
+ additional_tx_public_keys.push_back(txkey_pub); // One for each output.
+
+ add_additional_tx_pub_keys_to_extra(tx.extra, additional_tx_public_keys);
+ add_tx_pub_key_to_extra(tx, txkey_pub);
// we don't need to include additional tx keys if:
// - all the destinations are standard addresses
@@ -421,9 +427,9 @@ namespace cryptonote
output_index++;
summary_outs_money += dst_entr.amount;
}
- CHECK_AND_ASSERT_MES(additional_tx_public_keys.size() == additional_tx_keys.size(), false, "Internal error creating additional public keys");
+ //CHECK_AND_ASSERT_MES(additional_tx_public_keys.size() == additional_tx_keys.size(), false, "Internal error creating additional public keys");
- remove_field_from_tx_extra(tx.extra, typeid(tx_extra_additional_pub_keys));
+ //remove_field_from_tx_extra(tx.extra, typeid(tx_extra_additional_pub_keys));
LOG_PRINT_L2("tx pubkey: " << txkey_pub);
if (need_additional_txkeys)
Line by line, in plain words:
- The first lines identify the file being changed and give the before and after fingerprints of the file's contents.
remove_field_from_tx_extra(tx.extra, typeid(tx_extra_pub_key));clears out any existing main public key from the extra field, so the code can write a fresh one.- The removed line
add_tx_pub_key_to_extra(tx, txkey_pub);used to write the legitimate key as the main key. That is what the patch takes away. crypto::public_key dummy_key;creates a new, empty public key. This is the decoy that will be written first.add_tx_pub_key_to_extra(tx, dummy_key);writes that decoy into the transaction as the maintx_pub_key.std::vector<crypto::public_key> additional_tx_public_keys;creates an empty list to hold alternative keys.- The
forloop runs once for every destination (every output) and pushes the legitimatetxkey_pubinto that list, so the list ends up holding the legitimate key once per output. add_additional_tx_pub_keys_to_extra(tx.extra, additional_tx_public_keys);writes that list into the extra field as the array of alternative keys.add_tx_pub_key_to_extra(tx, txkey_pub);then appends the legitimate key again, this time as a maintx_pub_key.- The two lines that were commented out (turned into comments by putting
//in front) are the safety checks. The first used to verify that the number of additional public keys matched the number of additional tx keys; commenting it out stops the wallet from refusing to build the transaction. The second used to remove the additional pub keys field from the extra data; commenting it out keeps that field in the final transaction.
In short, the patch changes how the transaction extra is built. Instead of writing only the legitimate txkey_pub, it first writes a dummy_key as the main tx_pub_key. It then pushes the legitimate txkey_pub into additional_tx_public_keys once for every destination, and writes that array into the extra field. Finally it appends the legitimate txkey_pub again as a main tx_pub_key. The two commented-out lines disable the consistency check between the additional public keys and the additional tx keys, and disable the removal of the additional pub keys field, so the crafted extra data survives into the final transaction.
Step 2: Compile the wallet
Compile the patched wallet. Compiling means turning human-readable source code into a program the computer can run. The attacker now has a wallet that builds the special transaction.
Step 3: Send a regular transfer
Do a regular transfer to an exchange wallet. The transaction now carries the dummy key, the array of alternative keys holding the legitimate key, and the legitimate key itself.
Step 4: Profit
The receiving wallet scans the outputs once using the dummy and alternative keys, matching on the legitimate key, and then scans them again using the legitimate main key, because the alternative keys were never recorded in public_keys_seen. The same outputs are credited twice in the get_transfers result.
Root cause
The scanning logic in process_new_transaction tracks keys it has already seen in a public_keys_seen set, but the alternative tx_pub_key entries are not added to that set. When the same legitimate key later appears as the main tx_pub_key, it is not recognised as already processed, and every output is scanned and counted a second time. The earlier fix for identical tx_pub_keys did not cover this second route to the same key, so the defence was incomplete.
Impact
An attacker can make a receiving wallet report twice the amount actually sent. The wallet balance is not affected, so a personal user is unlikely to notice, but the doubled figure is returned by the get_transfers RPC call. Automated wallets, such as cryptocurrency exchanges that credit deposits based on RPC results, are the main target. By depositing and withdrawing the same coins and doubling each time, the attacker could eventually steal all XMR from an exchange hot wallet.
Fix
The report does not describe the fix that was applied.
Variants to test
These are follow-up checks a tester could run to see whether the same weakness appears elsewhere. Each one describes what to try and what a positive result looks like.
- Duplicate keys through different fields. Where a protocol lets the same key be supplied through more than one field, try supplying it through each route in turn and check whether the receiver processes the same data twice. A positive result is a doubled amount in the receiver's reported transfers while the balance stays correct.
- Ordering of extra data. Try placing the dummy key, the alternative key array and the legitimate key in different orders, and check whether any ordering still produces a double count. A positive result is the same doubling in
get_transfers. - Multiple outputs. Send a transaction with several outputs and one alternative key per output, as in the patch, and check whether each output is counted twice. A positive result is a reported total of twice the sent amount across all outputs.
- Other clients and versions. Test wallets built from releases since subaddresses were introduced, and any client that consumes
get_transfers, to see whether the same crafted transaction is credited twice. A positive result is a credit based on the doubled figure.
Glossary
- Blockchain: the public, append-only record of every transaction in a cryptocurrency.
- Business logic error: a flaw in the rules or sequence of decisions a program follows, rather than in its cryptography.
- Commit identifier: a unique fingerprint for one exact state of a source code repository.
- Compile: turn source code into a program the computer can run.
- Cryptocurrency: digital money recorded on a shared public list instead of a bank's private database.
- CVSS: a standard scoring system for the severity of a security flaw, from 0 to 10.
- Diff: a standard format for showing changes to a file, with
-for removed lines and+for added lines. - Extra field: a free-form area inside a transaction where the sender can put additional data, including keys.
- Hot wallet: an internet-connected wallet used for day-to-day operations, such as processing customer withdrawals.
- Key: a long string of characters used in cryptography; a public key can be shared, a private key must stay secret.
- Output: the part of a transaction that carries money to a recipient; one transaction can have several.
process_new_transaction: the function inside a Monero wallet that examines a new transaction and decides which outputs belong to it.public_keys_seen: a set in which the wallet records keys it has already used while scanning, to avoid counting the same outputs twice.- Pull request: a proposed change to a codebase, reviewed before it is merged.
- Release tag: a label marking a specific published version of software.
get_transfers: the RPC call through which software asks a Monero wallet what transfers it has received.- Subaddress: a secondary address belonging to the same wallet, used to keep different payments separate.
tx_pub_key: a public key carried in a transaction so the receiver can work out which outputs are theirs.- View key: a secret key a wallet combines with a transaction's public key to derive the one-time key for each output.
- Wallet: the software that holds your Monero keys, sends transactions and scans the blockchain for incoming funds.
- XMR: the ticker symbol for Monero.