Card Bug “open salary” for yourself? Analysis of Daoswap attack events

On September 5, 2022, Beijing time, the CertiK audit team detected that Daoswap lost 580,000 USDT in an attack because the mining reward was greater than the fees charged during the exchange process and lack of verification, allowing users to set the inviter address as themselves .

Attack steps

① The attacker contract received a flash loan of $2.18 million from 12 addresses.

② The attacker contract uses DAORouter to exchange all flash-loaned USDT for DAO tokens. During the swap, the attacker contract receives DAO tokens from SwapToEarn as a reward in two ways:

a.  Token Rewards : This is for users who exchange tokens.

b.  Inviter reward : The attacker can arbitrarily set an “inviter” address when calling the function, which is equivalent to the referrer can also get the reward. In this case, the attacker contract sets the inviter address to itself.

③ The attacker contract uses the same method to exchange all DAO tokens back to USDT to get these two rewards again.

④ The attacker contract repeats steps ② and ③ several times. Because the attacker receives DAO tokens as a reward, he gets more USDT each time.

⑤ The attacker contract repays all borrowed funds and transfers the remaining USDT amount to the attacker.

Contract Vulnerability

DAOSwap includes a “swap-mining” reward, which is implemented as follows.


After the swap in function _swap, the function swapCall in SwapToEarn.sol can be called.



In the function swapCall, DAO tokens are transferred to the user and the inviter, both of whose addresses are passed as parameters.


When the function is called in _swap, we can see that the user is set as the message sender msg.sender, and the inviter comes from the input parameters.


The inviter address can be any address, as this address is not checked. The attacker was able to set the inviter as himself, and received an additional reward.

It’s worth noting that the attacker’s reward for being an inviter is about 20% of the total reward . Even if the attacker is not allowed to set the inviter address to himself, the attacker can still profit from the transaction.

The total profit from 6 trades is about 581,254 USDT.

Related transactions

Transaction ①: 

Transaction ②: 

Transaction ③: 

Transaction ④: 

Transaction ⑤: 

Transaction ⑥: 

write at the end

After the attack, CertiK’s Twitter alert account and the official alert system released the news as soon as possible. At the same time, CertiK will continue to publish information related to project warnings (attacks, frauds, running away, etc.) on the official public account.

CertiK’s end-to-end security solutions, from smart contract auditing and KYC project background check services, to blockchain analysis tools such as Skynet dynamic scanning system and SkyTrace, and bug bounty programs, help each project reach its full potential. At the same time, it creates an ecosystem with high participation of users and investors for Web3.0.

Posted by:CoinYuppie,Reprinted with attribution to:
Coinyuppie is an open information publishing platform, all information provided is not related to the views and positions of coinyuppie, and does not constitute any investment and financial advice. Users are expected to carefully screen and prevent risks.

Like (0)
Donate Buy me a coffee Buy me a coffee
Previous 2022-09-07 00:09
Next 2022-09-07 10:27

Related articles