Trusting heavily on "appData" enables infinite SHM duplication through double-spend exploit
A malicious node can manipulate the appData memory pattern to disable account locking, allowing parallel processing of transactions from the same account. This enables double-spending and unlimited duplication of SHM coins.
Originally disclosed on Immunefi
- Disclosed after under an hour
#39364 [BC-Critical] Trusting heavily on "appData" enables infinite SHM duplication through double-spend exploit
Submitted on Jan 28th 2025 at 15:09:46 UTC by @bountyhunter2048 for Audit Comp | Shardeum: Core III
- Report ID: #39364
- Report Type: Blockchain/DLT
- Report severity: Critical
- Target: https://github.com/shardeum/shardeum/tree/bugbounty
- Impacts:
- Direct loss of funds
Description
Brief/Intro
Over dependence on the appData and memory pattern which are created by a single node leads to double-spending and unlimited duplication of SHM coins by disabling the account-locking mechanism of the processing queue.
Vulnerability Details
Shardeum network performs upfront pre-processing and basic validation on the first node at which the transaction is injected by the client. The name of the function that does that job is called txPreCrackData. Among other things, a memory pattern definition is created in this function on the injected node. Later, that memory pattern is used by all executing nodes to lock accounts in the queue and ensure transactions from the same accounts are processed synchronously. If the injected node is malicious, it can manipulate the appData.memoryPattern object to completely disable the locking mechanism and cause nodes to process the transactions from the same account in parallel. The attacker node just needs to mark the sender's account as ro (which I believe is read-only).
Here is the vulnerable code in the crack() which is run by all nodes processing the transaction:
if (ShardeumFlags.autoGenerateAccessList && appData.accessList) {
shardusMemoryPatterns = appData.shardusMemoryPatterns // should not trust it
...
}
https://github.com/shardeum/shardeum/blob/bugbounty/src/index.ts#L5623
In my opinion, I don't think the queue locking mechanism and memory patterns are at fault, but all the nodes in the execute group blindly trusting the appData from a single node is the real issue. It would be better if more than one node were involved in the txPreCrackData function.
Impact Details
The impact of any double-spending bug in a blockchain is always massive. It is a critical problem because now the attacker has a way to create (or duplicate) SHM without any limit (as far as I can think of). They can steal SHM, move it to an exchange and sell it while inflating the SHM supply and causing the SHM price to go down.
Link to Proof of Concept
https://gist.github.com/bountyhunter2048/442bb6be2d65eeaedda480e3916c2e67
Proof of Concept
Proof of Concept
To exploit this vulnerability, I prepared a script that sends 5 SHM to 2 different accounts using the same nonce very quickly. In a normal network, one of these 2 transactions should fail no matter how quickly they are injected because they should be processed sequentially and the EVM will throw an error for nonce mismatch. But, if an attacker can get their malicious node into the network by modifying the txPreCrackData as provided in the GitHub gist below, he can inject coin transfer transactions to his malicious node and double-spend his coins. If he sends 5 SHM to 2 new addresses he controls, both of the transactions will be successful and they will get 5 SHM each. This means that there is an extra 5 SHM created out of nowhere.
I demonstrated this exploit from start to finish in this video:
https://youtu.be/GkmmNvExCgY?si=HM7XGBA6zI4P4xRA
GitHub gist for exploit code:
https://gist.github.com/bountyhunter2048/442bb6be2d65eeaedda480e3916c2e67
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
All nodes blindly trust the appData memory pattern created by a single node, allowing a malicious node to disable account locking.
Impact
An attacker could double-spend SHM and create unlimited SHM, leading to direct loss of funds and inflation of the SHM supply.
What the attacker needed
Malicious node in the network; ability to modify txPreCrackData
The fix
The text suggests involving more than one node in the txPreCrackData function to avoid trusting a single node's appData.
How it was found
- Attacker modifies txPreCrackData to set the sender's account as read-only in the memory pattern.
- Attacker injects two transactions with the same nonce to the malicious node.
- Both transactions are processed in parallel and succeed, double-spending the coins.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In a blockchain, each transaction must be processed one at a time per account to prevent spending the same coins twice. Here, a single node can trick other nodes into skipping that order, so two transactions spending the same coins can both succeed, creating new coins out of thin air.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.