Submitted by 0xTheC0der, also found by Ack and dirk_y
When calling MagnetarV2._permit() through invoking a permit (or permit all) action via MagnetarV2.burst(), one can also execute other calls than ERC20.permit(...) due to the following reasons / under the following constraints:
Given this information, an attacker can easily craft calls to give him approval for any assets held by the MagnetarV2 contract or directly invoke a transfer. There are potentially other malicious calls that can be crafted and executed via the permit action, therefore the mentioned approve/transfer calls are only an example.
In order for this to cause loss of funds for the DAO, the MagnetarV2 contract needs to hold (be the owner of) assets in the first place which seems likely since it is a main entry point and interacts with other important parts of the protocol like Singularity, BigBang, TapiocaOptionBroker and MagnetarMarketModule (trough delegatecall in some cases).
The following PoC is based on an existing test case and demonstrates that an attacker can give himself the approval of the MagnetarV2 contract for an ERC20 token.
Just apply the diff below in tapioca-periph-audit and run the test case with npx hardhat test test/magnetar.test.ts:
VS Code, Hardhat
Require the function selector (first 4 bytes of actionCalldata) to match an ERC*.permit(...) call in MagnetarV2._permit().
0xRektora (Tapioca) confirmed
