Closed code423n4 closed 1 year ago
minhquanym marked the issue as duplicate of #661
minhquanym marked the issue as duplicate of #146
dmvt changed the severity to 3 (High Risk)
dmvt marked the issue as satisfactory
dmvt marked the issue as not a duplicate
dmvt marked the issue as unsatisfactory: Invalid
Lines of code
https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/markets/singularity/Singularity.sol#L618-L629 https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/usd0/BaseUSDO.sol#L361-L373 https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/usd0/modules/USDOLeverageModule.sol#L133-L188 https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/usd0/modules/USDOMarketModule.sol#L134-L189 https://github.com/Tapioca-DAO/tapioca-bar-audit/blob/master/contracts/usd0/modules/USDOOptionsModule.sol#L138-L204
Vulnerability details
Impact
The Singularity, BaseUSDO, USDOLeverageModule, USDOMarketModule, and USDOOptionsModule contracts all use the delegatecall function to call a function in another contract. However, the function id of the function to be called is controlled by the caller. This means that an attacker could call the delegatecall function with a function id that they control, which could allow them to execute arbitrary code in the calling contract.
Proof of Concept
If exploited, this vulnerability could allow an attacker to steal funds from the Singularity, BaseUSDO, USDOLeverageModule, USDOMarketModule, and USDOOptionsModule contracts. It could also allow the attacker to take control of the contracts or execute other malicious code.
The following is a proof of concept for the controlled delegatecall vulnerability in the Singularity, BaseUSDO, USDOLeverageModule, USDOMarketModule, and USDOOptionsModule contracts:
pragma solidity ^0.8.0;
import "contracts/markets/singularity/Singularity.sol"; import "contracts/usd0/BaseUSDO.sol"; import "contracts/usd0/modules/USDOLeverageModule.sol"; import "contracts/usd0/modules/USDOMarketModule.sol"; import "contracts/usd0/modules/USDOOptionsModule.sol";
contract Attacker {
function exploit() public { // Create a new Singularity contract. address singularity = address(new Singularity());
} }
Tools Used
VScode
Recommended Mitigation Steps
The Singularity, BaseUSDO, USDOLeverageModule, USDOMarketModule, and USDOOptionsModule contracts should be updated to use the safecall function instead of the delegatecall function. The safecall function does not allow the caller to control the function id of the function to be called, which makes it more secure.
Recommendation:
The Singularity, BaseUSDO, USDOLeverageModule, USDOMarketModule, and USDOOptionsModule contracts should be updated to use the safecall function instead of the delegatecall function. This will make the contracts more secure and prevent attackers from exploiting the controlled delegatecall vulnerability.
Assessed type
call/delegatecall