Anyone who is approving `BlueprintV5` contract to spend ERC20 can get drained because `Payment::payWithERC20`
The `payWithERC20` function in the `Payment` contract is public, allowing anyone to call it and transfer tokens from any address that has approved the `BlueprintV5` contract to spend them. An attacker can drain the approved tokens of any victim who has granted such allowance.
0x180db Follow with 0x73696d616f, 0xAadi and 47 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2025-03-crestal-network-judging/issues/260
Found by
0x180db, 0x73696d616f, 0xAadi, 0xDemon, 0xEkko, 0xGondar, 0xGutzzz, 0xYjs, 0xadarum, 0xaudron, 0xc0ffEE, 0xhiros, 0xjarix, 0xlucky, 0xpetern, Anirruth, Arav, Artur, Buggx0, CasinoCompiler, Chaindecompiler, ChaosSR, Cybrid, Edoscoba, FalseGenius, GODSPEED, Harry_cryptodev, Harsh, HolyHak, IzuMan, JasonBPMIASN, Kodyvim, KungFuPanda, Kwesi, MSK, Matic68, OlaHamid, OpaBatyo, Oxpreacher, Pelz, Pihu, Praise03, Ryonen, Trepid, ZOL, ZafiN, abhishek_thakur, anchabadze, auditism, bube, c3phas, dennis, dreamcoder, eLSeR17, farismaulana, gegul, ggbond, gxh191, hirugohan, ihtishamsudo, ilyadruzh, j3x, jacopod, jprod15, krot-0025, lom_ack, makeWeb3safe, patitonar, ph, phrax, princekay, radcipher, redtrama, resosiloris, roccomania, sa9933, sabanaku77, seeques, shady4, skid0016, skipper, tachida2k, thimthor, vivekd, w33kEd, x0rc1ph3r, y4y, yaioxy, zxriptor
Summary
payWithERC20 is supposed to be used inside BlueprintV5 contract to handle payment. But this function also can be used to drain anyone who is interact with BlueprintV5 and using it to approve payment token when creating an agent.
Root Cause
@> function payWithERC20(address erc20TokenAddress, uint256 amount, address fromAddress, address toAddress) public {
// check from and to address
require(fromAddress != toAddress, "Cannot transfer to self address");
require(toAddress != address(0), "Invalid to address");
require(amount > 0, "Amount must be greater than 0");
IERC20 token = IERC20(erc20TokenAddress);
token.safeTransferFrom(fromAddress, toAddress, amount);
}
the root cause simply because this function is public function, meaning anyone can call this and supply valid token address, then fill fromAddress with any address that still have allowance/approving the payment token to be spend by BlueprintV5 contract
Internal Pre-conditions
- admin enable usdc or any erc20 token as payment by calling
Blueprint::addPaymentAddress
External Pre-conditions
- victim approve the spending of usdc or any erc20 token set in last step for
BlueprintV5contract address proxy - the amount approved should be greater than the amount used for creating agent with token cost
- victim call the function to create agent (optional)
Attack Path
- attacker call
payWithERC20supplying the parameter with usdc address, victim address and sufficient amount to be sent into attacker address
Impact
user/victim who interacted would lose their funds drained by attacker
PoC
No response
Mitigation
make the Payment::payWithERC20 internal
Discussion
spidemen2024
Got it
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/crestalnetwork/crestal-omni-contracts/pull/16
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
The `payWithERC20` function is declared public, allowing any caller to specify an arbitrary `fromAddress` and transfer tokens from that address if it has approved the contract.
Impact
Any user who has approved the `BlueprintV5` contract to spend their tokens could have their funds drained by an attacker.
What the attacker needed
Admin enables a token as payment; victim approves BlueprintV5 to spend that token; approved amount exceeds agent creation cost
The fix
The function was made internal, preventing arbitrary external calls.
How it was found
- Admin enables a token as payment by calling `Blueprint::addPaymentAddress`.
- Victim approves the `BlueprintV5` contract to spend that token.
- Attacker calls `payWithERC20` with the token address, the victim's address as `fromAddress`, and the attacker's address as `toAddress`.
- The function transfers the approved amount from the victim to the attacker.
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.
When you approve a smart contract to spend your tokens, you are giving it permission to move those tokens on your behalf. In this case, the contract had a function that anyone could call to move tokens from any address that had given such permission. So an attacker could simply call that function and steal the tokens from anyone who had approved the contract.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.