Submitted by carrotsmuggler, also found by 0xStalin
The Magnetar.sol contract has a lot of useful helper function to carry out operations on user market positions. If a user wishes to use the helper functions, they have to first give approval to the Magnetar contract to manipulate their positions. As an example, for the big bang markets, this is done by calling the updateOperator function.
Since this is a helper function, we can expect users to give this approval in order to use these functions. However the issue is that any attacker can use these approvals to manipulate and drain positions of other users.
As an example, let us look at the withdrawToChain function. Lets assume an attacker is calling this function, and the victims address is passed in the from field. Assume the victim has given all approvals to the Magnetar contracts. The function delegates this to the withdrawToChain in the Market module.
In withdrawToChain function, there are no checks on the msg.sender address. The function interacts with yieldbox and does a crosschain send to the erceiver address passed by the attacker.
This sends the tokens to the receiver address either in the same chain or cross-chain. This lets any user steal tokens from any other user, exploiting the approval given to the magnetar address.
While this report only discusses the issue with this one function, the same issue is present for every function in the magnetar contract. This allows attackers to manipulate bigbang markets and singularity markets as well. Thus this is a high severity issue.
A POC is developed by editing the test present in magnetar.test.ts. Only a single change is made to the test. The last withdrawToChain call is done from the eoa1 address instead of the deployer address.
This test passes, showing that the eoa1 address is able to withdraw tokens belonging to the deployer.
Hardhat
Add approval checks to all functions in the Magnetar contract.
0xRektora (Tapioca) confirmed
