Calling ExpiringMarket.stop and ExpiringMarket.isClosed functions cannot pause any functionlities of the market
The market's stop and isClosed functions do not actually pause or close the market because the stopped flag is never used and isClosed always returns false. An attacker could continue to create offers and buy even after the owner tries to stop the market, potentially allowing funds to be lost during an emergency.
Submitted by rbserver, also found by halden, McToady, JC, karanctf, tnevler, hunter_w3b, dec3ntraliz3d, Viktor_Cortess, lukris02, Udsen, Ace-30, Ocean_Sky, AlexCzm, R2, darksnow, fs0c, ktg, carrotsmuggler, MatricksDeCoder, whoismatthewmc1, Juntao, Kaysoft, tallo, Banditx0x, mrpathfindr, bearonbike, mrpathfindr, descharre, Shubham, said, ljmanini, MalfurionWhitehat, btk, Dug, sces60107, ginlee, iliyaniliev, dacian, koxuan, pavankv and ravikiranweb3.
Although the following ExpiringMarket.stop function can be called by the RubiconMarket contract’s owner, calling it does not stop the market because stopped is not used at all in the protocol for pausing any of the market’s functionalities.
https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/RubiconMarket.sol#L628-L630
function stop() external auth {
stopped = true;
}
Moreover, the following ExpiringMarket.isClosed function always returns false. This means that the market cannot be closed. Since this ExpiringMarket.isClosed function is called in the ExpiringMarket.can_offer and ExpiringMarket.can_buy modifiers below, these modifiers’ require(!isClosed()) will always pass, and new offers and buys are always allowed. Similarly, the below RubiconMarket.can_cancel modifier’s require statement’s isClosed() check is always false so the situation, where the user wants to cancel an offer when the market is closed, does not exist at all.
https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/RubiconMarket.sol#L620-L622
function isClosed() public pure returns (bool closed) {
return false;
}
https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/RubiconMarket.sol#L596-L607
/// @dev After close_time has been reached, no new offers are allowed.
modifier can_offer() override {
require(!isClosed());
_;
}
/// @dev After close, no new buys are allowed.
modifier can_buy(uint256 id) override {
require(isActive(id));
require(!isClosed());
_;
}
https://github.com/code-423n4/2023-04-rubicon/blob/main/contracts/RubiconMarket.sol#L718-L729
// // After close, anyone can cancel an offer
modifier can_cancel(uint256 id) override {
require(isActive(id), "Offer was deleted or taken, or never existed.");
require(
isClosed() ||
msg.sender == getOwner(id) ||
id == dustId ||
(msg.sender == getRecipient(id) && getOwner(id) == address(0)),
"Offer can not be cancelled because user is not owner, and market is open, and offer sells required amount of tokens."
);
_;
}
Since calling the ExpiringMarket.stop and ExpiringMarket.isClosed functions cannot close or stop the market, the RubiconMarket contract’s owner is unable to pause any functionlities of the market and prevented any unintended outflow and loss of user funds when an emergency occurs, such as if the protocol gets attacked and hacked.
Proof of Concept
The following steps can occur for the described scenario.
- The protocol is hacked so the
RubiconMarketcontract’s owner calls theExpiringMarket.stopfunction as an attempt to pause the functionalities of the market. - After the
ExpiringMarket.stopfunction is called, none of the market’s functionalities are paused becausestoppedis not used at all in the protocol for pausing any of the market’s functionalities and theExpiringMarket.isClosedfunction always returnsfalse. - As a result, the attacker can transfer user funds out from the protocol, and such user funds are lost.
Tools Used
VSCode
Recommended Mitigation Steps
The ExpiringMarket.stop function can be updated to set stopped to true or false by the RubiconMarket contract’s owner. The ExpiringMarket.isClosed function can then be updated to return stopped. This enables the RubiconMarket contract’s owner to pause and unpause the market’s functionalities when needed.
daoio (Rubicon) acknowledged and commented:
We will remove this
ExpiringMarketstuff, keeping onlystoppedstorage var.
Best written up report regarding impact.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The stopped state variable is set but never checked, and the isClosed function is hardcoded to return false, so the pause logic is effectively disabled.
Impact
The owner cannot pause the market in an emergency, so an attacker could continue to drain user funds even after stop is called.
What the attacker needed
Owner calls stop during an attack; attacker already has a way to move funds
The fix
The stop function should toggle the stopped flag and isClosed should return that flag so the owner can pause and unpause the market.
How it was found
- The protocol is hacked and the owner calls the stop function to pause the market.
- The stop function sets stopped to true but no functionality checks it, and isClosed still returns false.
- The attacker can continue to transfer user funds out of the protocol.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract has a switch meant to pause trading in an emergency, but the switch is not connected to anything. The owner can flip it, but the market keeps working as normal, so if there is an attack the owner cannot stop it.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.