stableXswap beta Incident Report (Funds are SAFU)
We were investigating an issue with our smart contract which caused the initial fee-collection mechanism to not properly send the 0.048%…
We were investigating an issue with our smart contract which caused the initial fee-collection mechanism to not properly send the 0.048% of fees to the community treasury address, as we noticed a $23K USD swap netted only 5 cents in fees to the community treasury, when in fact it should net about $11 USD in fees.
We were alerted today of a possible bug by the developers of the Qian Stablecoin (QUSD), the leading decentralized stablecoin in terms of total market cap on Binance Smart Chain.
We worked to confirm that the bug existed as reported by the Qian Stablecoin team, and confirmed the typo in our code, which was missing one decimal place for a parameter that was squared.
The implications of this bug were that normally AMM swaps need to check that no swaps leave the pool with less value than what it started with. While the bug was an innocent omission of a 0, it meant that we were checking only if the pool retained at least 1% of its previous value, rendering that check useless.
We then worked to address the severity of the issue and verified that the contract could not be directly breached via front end interfaces or an individual user calling via the interfaces of bscscan.
Since the contract is a public function, it appeared that anyone could call it, so we dropped everything to try to test if there were any ways to breach the contracts instantly.
However, because of the way the contracts are set up, the Router contract is the only way currently, to interact with the individual stablecoin pair pools, and the swap had no other ways for a user to directly call it.
Thus, it was clear that momentarily, there were no ways that any individual users could breach the contract by calling it with existing solutions, so we set up to our next steps for handling this bug.
We then worked on a testing suite for the “rescue operation”, to check if we could in fact get more money than we should from exploiting the typo ourselves, and if we did, we would have to do all the moves in one go for all 6 stablecoin pools, so as to avoid any chance of front-running or being sniped by a generalized “Dark Forest” that we’ve seen on Ethereum. Any false move and we would face losing funds of our users.
We also simultaneously began planning the temporary reduction of our 8 hour timelock so that we can then help migrate users’ LP tokens without needing to wait 8 hours to know that we successfully can migrate (or risk tipping off that we would be doing this to any possible hackers).
At 3:55PM UTC time November 11, 2020, we successfully claimed most of the outstanding tokens within the current vulnerable stableXswap beta pools.
The transaction where we were able to collect virtually all funds held in our stableXswap pools can be viewed and investigated here https://bscscan.com/tx/0x90a06a57dc5590dc9d8d638e88b51fd829251285f980d3101a8ab7887aa4758f
All funds have been successfully sent to the deployer address for the swap. We will work to reimburse these funds back to users in the new upgraded, safe stableXswap pools.
At 9PM UTC time 11–11–2020, our timelock will cease, and we will be able to manually help users migrate over their LP tokens to a new set of upgraded stableXswap pools with patches for the bugs
For the next 5 hours, please DO NOT deposit or withdraw of any of your LP tokens or try to remove liquidity, as you will lose money and not be able to redeem funds. We have taken a snapshot of all the holders of the current LP pools and will migrate over these balances over to the new pools to ensure that all user have the same balances as before.
As a preventative measure, we have turned off the front end access to our old beta swap interface temporarily to prevent any users accidentally withdrawing at this time and losing their LP tokens, as well as access to add or withdraw LP tokens from the staking contract at this time. If you withdraw or add, you will not be included in the migration and could lose money, so please do not touch the contracts!!!
We cannot repeat this enough: if you have not deposited into these contracts, please do not deposit any funds until we migrate to the new contract. Thanks for your patience.
After we have ascertained that the correct LP balances have been handled properly within a few hours after migration, we will then re-add the stablecoins back to the pools, so that any users who do not feel comfortable with us or our new swap may have the option to withdraw safely without losing any funds. Funds are SAFU
In the coming days, we will provide more updates on the entire landscape, token economics, and future incentivization.
We’ve learned the most important lesson now to be overly cautious in our code and will make efforts to set aside a larger portion of our total token supply, and plan to devote at least 10–15% of all total supply towards audits, bug bounties, and rewards for those who help us build a better stableXswap.
Your funds would not have been SAFU without the help of some amazing, good Samaritans. We have to give incredible thanks to the QUSD Qian Stablecoin (and ForTube) teams for disclosing this bug in a responsible manner, the Binance Security Team for advice and monitoring the chain state, and most importantly, the core hero(es) of the day: several other BSC developers & projects, with the core contribution from John, a smart-contract expert, who helped us make sure that we were able to protect user funds at this time.
We will share more details and update this as we get more information.
Thanks, and let’s keep building!