Skip to content
Access control Audit finding Beginner

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

Payment.sol#L25-L32

Solidity
@>    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

  1. admin enable usdc or any erc20 token as payment by calling Blueprint::addPaymentAddress

External Pre-conditions

  1. victim approve the spending of usdc or any erc20 token set in last step for BlueprintV5 contract address proxy
  2. the amount approved should be greater than the amount used for creating agent with token cost
  3. victim call the function to create agent (optional)

Attack Path

  1. attacker call payWithERC20 supplying 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

The original report as published on Sherlock, by 0x180db. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

  1. Admin enables a token as payment by calling `Blueprint::addPaymentAddress`.
  2. Victim approves the `BlueprintV5` contract to spend that token.
  3. Attacker calls `payWithERC20` with the token address, the victim's address as `fromAddress`, and the attacker's address as `toAddress`.
  4. 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.

More by 0x180db

View all

2 more disclosed reports, best first.

More from Crestal Network

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.