Charged Particles
A malicious NFT creator could set a ransom contract as the royalties receiver, causing the NFT to be locked and unsellable unless a bribe was paid. This griefing attack allowed the creator to hold sold NFTs hostage.
medium.com
Published on medium.com
Charged Particles
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Context
Charged Particles is a decentralized NFT marketplace where users can deposit ERC-20 tokens into any NFT. Within the protocol, a "Proton" is the ERC721 contract for a particle: an NFT that is ready to be energised by adding interest-bearing assets to it. The bug described here lived in Proton.sol, the contract that governs these tokens, and it concerned the royalties mechanism that a Proton creator can configure.
Setup
The report does not describe any particular accounts, tooling or environment beyond the protocol itself. The relevant preconditions are visible from the exploitation steps: the attacker needs to be able to create a Proton for sale with a non-zero royalties percentage, and to be able to set the royalties receiver afterwards. The proof of concept contract is written for Solidity 0.6.12.
Finding it
Whitehat Alejandro Muñoz-McDonald submitted the issue on February 9, and it was classified as "High". The vulnerability was a griefing/denial of service attack against the protocol: a malicious user could create a system in which bribes had to be paid for a user to buy or sell an NFT. In other words, a malicious Proton creator could hold Protons hostage after selling them, by creating a malicious ransom contract and setting it to be the royalties receiver.
Exploitation
Step 1: create a Proton for sale with royalties
Call createProtonForSale with valid parameters and a royaltiesPercent > 0. Move to the next step when the token is sold.
Step 2: create a malicious ransom contract
pragma solidity 0.6.12; contract Ransom { bool internal ransomEnabled = true; constructor() public {} function unlockNFT() public payable { if(msg.value >= 1 ether) { ransomEnabled = false; } } fallback() external payable { require(!ransomEnabled); }}
The contract starts with ransomEnabled set to true. Its unlockNFT function accepts payment and clears the flag only when at least 1 ether is sent. Its fallback function is payable and reverts for as long as the ransom has not been paid, because of the require(!ransomEnabled).
Step 3: point the royalties receiver at the ransom contract
Call setCreatorRoyaltiesReceiver(…) with the energizedParticleId and the address of the malicious contract.
Step 4: the Proton is locked
With setCreatorRoyaltiesReceiver called, the Proton is locked and cannot be sold, because the default payable function of the ransom contract reverts as long as the ransom has not been paid. The Proton is locked and cannot be sold until the ransom is paid.
Root cause
Impact
A malicious Proton creator could hold Protons hostage after selling them. The result is a griefing/denial of service condition: a bribe has to be paid for a user to buy or sell the NFT. The report frames this as an attack against the protocol, and the issue was classified as "High". Charged Particles paid Alejandro Muñoz-McDonald a $5,000 USDC bounty.
Fix
Charged Particles quickly implemented a fix, which the report links to a commit in the charged-particles-universe repository:
https://github.com/Charged-Particles/charged-particles-universe/commit/[redacted]#diff-[redacted]
The report does not describe the contents of the change.
Variants to test
- Look for creator-controlled addresses that the protocol calls into during transfers or sales (royalty receivers, fee recipients, referral addresses). A positive result is a sale path that reverts when that address is a contract with a reverting payable fallback.
- Check whether such an address can be changed after the token has been sold. A positive result is a post-sale setter that lets the creator swap in a hostile contract.
- Test whether the protocol uses a low-level call with ignored return value or a direct call that propagates reverts. A positive result is a revert in the receiver that bubbles up and blocks the transfer.
- Try a receiver contract that consumes all forwarded gas or reverts conditionally on value. A positive result is a transfer that fails or becomes prohibitively expensive for anyone but the attacker.
What happened, in plain words
Charged Particles is a marketplace for NFTs. An NFT is a digital token on a blockchain that proves who owns a particular item, such as a piece of digital art. Charged Particles adds a twist: you can lock other tokens inside an NFT so that the NFT carries value with it. The report calls an NFT of this kind a "particle", and the smart contract that manages particles is called a "Proton".
A smart contract is a small program that lives on a blockchain. It runs automatically when someone sends it a transaction, and nobody can change its behaviour after it is deployed. Think of it as a vending machine: you put money in, it follows its fixed rules, and it either gives you the item or refuses.
A whitehat is a security researcher who looks for bugs in order to report them and get them fixed, rather than to exploit them. On February 9, the whitehat Alejandro Muñoz-McDonald reported a bug in Charged Particles that the project classified as "High" severity. The bug was a griefing attack, which is an attack whose goal is not to steal money but to make life difficult for other people. More specifically it was a denial of service: a way to stop a system from working for its normal users. In this case, a malicious seller could make it impossible to buy or sell an NFT unless a bribe was paid first. Charged Particles fixed the bug and paid the researcher a $5,000 USDC bounty. USDC is a cryptocurrency whose value is designed to stay close to one US dollar, so the bounty was worth about $5,000.
The product and the feature involved
Charged Particles lets users deposit ERC-20 tokens into any NFT. ERC-20 is the common standard for fungible tokens on Ethereum: tokens where every unit is interchangeable with every other unit, like coins in a currency. ERC-721 is the standard for NFTs, where each token is unique. A "Proton" is the ERC721 contract for a particle, meaning the NFT that is ready to be energised by adding interest-bearing assets to it. Interest-bearing assets are tokens that grow in value over time on their own, for example through lending.
The feature at the centre of the bug is royalties. A royalty is a small payment that goes back to the original creator every time the item is resold. In Charged Particles, the creator of a Proton can choose which address receives those royalty payments. An address is the identifier of an account or contract on the blockchain, similar to a bank account number.
The bug lived in Proton.sol, the contract that governs these tokens. The report does not describe any particular accounts, tools or test environment beyond the protocol itself. What the attack needs is visible from its steps: the attacker must be able to create a Proton for sale with a royalties percentage above zero, and must be able to change the royalties receiver afterwards. The proof of concept contract is written for Solidity 0.6.12. Solidity is the programming language used to write smart contracts on Ethereum, and 0.6.12 is the version of the compiler the code targets.
Finding it
Alejandro Muñoz-McDonald submitted the issue on February 9 and it was classified as "High". The vulnerability was a griefing/denial of service attack against the protocol: a malicious user could create a system in which bribes had to be paid for a user to buy or sell an NFT. Put simply, a malicious Proton creator could hold Protons hostage after selling them, by creating a malicious ransom contract and setting it to be the royalties receiver. A ransom contract is a contract written specifically to demand payment before it will cooperate.
How the attack worked, step by step
Step 1: create a Proton for sale with royalties
Call createProtonForSale with valid parameters and a royaltiesPercent > 0. Move to the next step when the token is sold.
Calling a function means asking the smart contract to run one of its named operations. createProtonForSale is the operation that puts a new Proton up for sale. Its parameters are the inputs it needs, such as the price and the royalty settings. Setting royaltiesPercent above zero is what makes the later change of receiver meaningful: the contract that receives royalties is the one that will be invoked when the Proton changes hands.
Step 2: create a malicious ransom contract
The attacker deploys a small contract whose only job is to refuse to accept money until a ransom is paid:
pragma solidity 0.6.12; contract Ransom { bool internal ransomEnabled = true; constructor() public {} function unlockNFT() public payable { if(msg.value >= 1 ether) { ransomEnabled = false; } } fallback() external payable { require(!ransomEnabled); }}
Line by line:
pragma solidity 0.6.12;tells the compiler which version of the Solidity language this file is written for.contract Ransom {starts the definition of a contract namedRansom.bool internal ransomEnabled = true;declares a true/false switch calledransomEnabled, visible only inside this contract, and starts it switched on. While it is on, the ransom is still in force.constructor() public {}is the setup function that runs once when the contract is deployed. Here it does nothing.function unlockNFT() public payable {defines a function anyone can call, andpayablemeans it is allowed to receive cryptocurrency along with the call.if(msg.value >= 1 ether) {checks whether the amount sent with the call,msg.value, is at least 1 ether. Ether is the native currency of Ethereum.ransomEnabled = false;switches the ransom off once that amount has been paid.fallback() external payable {defines the fallback function. This is the code that runs when someone sends money to the contract without naming any function, which is exactly what happens when a plain payment is made to an address.require(!ransomEnabled);is the guard: it insists that the ransom is no longer enabled. If the ransom is still on, the check fails and the whole payment is rejected.
So the contract starts with ransomEnabled set to true. Its unlockNFT function accepts payment and clears the flag only when at least 1 ether is sent. Its fallback function is payable and reverts for as long as the ransom has not been paid, because of the require(!ransomEnabled). To revert means to cancel the transaction and undo everything it did, which is how a smart contract says no.
Step 3: point the royalties receiver at the ransom contract
Call setCreatorRoyaltiesReceiver(…) with the energizedParticleId and the address of the malicious contract.
setCreatorRoyaltiesReceiver is the operation that chooses who receives the royalties. energizedParticleId identifies which Proton is being changed, and the second argument is the address of the ransom contract. The attacker is simply telling the protocol: from now on, pay the royalties to this contract.
Step 4: the Proton is locked
With setCreatorRoyaltiesReceiver called, the Proton is locked and cannot be sold, because the default payable function of the ransom contract reverts as long as the ransom has not been paid. The Proton is locked and cannot be sold until the ransom is paid. The sale cannot complete, so the NFT is stuck.
Why it worked
The protocol did not account for that address being a contract whose payable fallback deliberately reverts.
Impact
A malicious Proton creator could hold Protons hostage after selling them. The result is a griefing/denial of service condition: a bribe has to be paid for a user to buy or sell the NFT. The report frames this as an attack against the protocol, and the issue was classified as "High". Charged Particles paid Alejandro Muñoz-McDonald a $5,000 USDC bounty.
The fix
Charged Particles quickly implemented a fix, which the report links to a commit in the charged-particles-universe repository:
https://github.com/Charged-Particles/charged-particles-universe/commit/[redacted]#diff-[redacted]
A commit is a saved change in a code repository, and the link points to the specific change that fixed the bug. The report does not describe the contents of the change.
What to look for in other projects
These are the same patterns to test elsewhere, written so that a newcomer can follow the reasoning:
- Look for creator-controlled addresses that the protocol calls into during transfers or sales, such as royalty receivers, fee recipients and referral addresses. A positive result is a sale path that reverts when that address is a contract with a reverting payable fallback.
- Check whether such an address can be changed after the token has been sold. A positive result is a post-sale setter that lets the creator swap in a hostile contract.
- Test whether the protocol uses a low-level call with an ignored return value or a direct call that propagates reverts. A positive result is a revert in the receiver that bubbles up and blocks the transfer.
- Try a receiver contract that consumes all forwarded gas or reverts conditionally on value. A positive result is a transfer that fails or becomes prohibitively expensive for anyone but the attacker.
Glossary
- Address: the identifier of an account or contract on a blockchain, similar to a bank account number.
- Bounty: a reward paid to a researcher who reports a valid security bug.
- Call: asking a smart contract to run one of its functions.
- Commit: a saved change in a code repository.
- Constructor: the setup function that runs once when a smart contract is deployed.
- Contract: a program that lives on a blockchain and runs automatically according to fixed rules.
- Denial of service: an attack that stops a system from working for its normal users.
- Deploy: publishing a smart contract to the blockchain so that it can be used.
- ERC-20: the common standard for fungible tokens on Ethereum, where every unit is interchangeable.
- ERC-721: the standard for NFTs on Ethereum, where each token is unique.
- Ether: the native currency of Ethereum.
- Fallback function: the code in a contract that runs when it receives money without a named function being called.
- Fungible: interchangeable, like coins of the same currency.
- Gas: the unit that measures the computational effort a transaction costs.
- Griefing: an attack whose goal is to make life difficult for other users rather than to steal money.
- Interest-bearing assets: tokens that grow in value over time on their own, for example through lending.
- Low-level call: a way for one contract to send a call to another without the usual automatic error handling, so the caller must check the result itself.
- NFT: a digital token on a blockchain that proves who owns a particular unique item.
- Parameter: an input that a function needs in order to run.
- Payable: a property of a function that allows it to receive cryptocurrency along with the call.
- Proof of concept: a small piece of code that demonstrates that a vulnerability is real.
- Proton: in Charged Particles, the ERC721 contract for a particle, an NFT ready to be energised with interest-bearing assets.
- Ransom contract: a contract written specifically to demand payment before it will cooperate.
- Revert: to cancel a transaction and undo everything it did, which is how a smart contract says no.
- Royalty: a small payment that goes back to the original creator every time an item is resold.
- Smart contract: a program that lives on a blockchain and runs automatically when called.
- Solidity: the programming language used to write smart contracts on Ethereum.
- USDC: a cryptocurrency whose value is designed to stay close to one US dollar.
- Whitehat: a security researcher who looks for bugs in order to report them and get them fixed.