_validateOrder Does Not Allow Anyone To Be A Taker Of An Off-Chain Order
The EIP1271Wallet contract's _validateOrder function does not check that takerAddress and senderAddress are zero, allowing the treasury manager to set them to restrict who can fill off-chain orders. This lets the manager extract value by maximising slippage.
Submitted by leastwood
The EIP1271Wallet contract intends to allow the treasury manager account to sign off-chain orders in 0x on behalf of the TreasuryManager contract, which holds harvested assets/COMP from Notional. While the EIP1271Wallet._validateOrder function mostly prevents the treasury manager from exploiting these orders, it does not ensure that the takerAddress and senderAddress are set to the zero address. As a result, it is possible for the manager to have sole rights to an off-chain order and due to the flexibility in makerPrice, the manager is able to extract value from the treasury by maximising the allowed slippage.
By setting takerAddress to the zero address, any user can be the taker of an off-chain order. By setting senderAddress to the zero address, anyone is allowed to access the exchange methods that interact with the order, including filling the order itself. Hence, these two order addresses can be manipulated by the manager to effectively restrict order trades to themselves.
Proof of Concept
address takerAddress; // Address that is allowed to fill the order. If set to 0, any address is allowed to fill the order.
https://github.com/code-423n4/2022-01-notional/blob/main/contracts/utils/EIP1271Wallet.sol#L147-L188
function _validateOrder(bytes memory order) private view {
(
address makerToken,
address takerToken,
address feeRecipient,
uint256 makerAmount,
uint256 takerAmount
) = _extractOrderInfo(order);
// No fee recipient allowed
require(feeRecipient == address(0), "no fee recipient allowed");
// MakerToken should never be WETH
require(makerToken != address(WETH), "maker token must not be WETH");
// TakerToken (proceeds) should always be WETH
require(takerToken == address(WETH), "taker token must be WETH");
address priceOracle = priceOracles[makerToken];
// Price oracle not defined
require(priceOracle != address(0), "price oracle not defined");
uint256 slippageLimit = slippageLimits[makerToken];
// Slippage limit not defined
require(slippageLimit != 0, "slippage limit not defined");
uint256 oraclePrice = _toUint(
AggregatorV2V3Interface(priceOracle).latestAnswer()
);
uint256 priceFloor = (oraclePrice * slippageLimit) /
SLIPPAGE_LIMIT_PRECISION;
uint256 makerDecimals = 10**ERC20(makerToken).decimals();
// makerPrice = takerAmount / makerAmount
uint256 makerPrice = (takerAmount * makerDecimals) / makerAmount;
require(makerPrice >= priceFloor, "slippage is too high");
}
Tools Used
Manual code review. Discussions with Notional team.
Recommended Mitigation Steps
Consider adding require(takerAddress == address(0), "manager cannot set taker"); and require(senderAddress == address(0), "manager cannot set sender"); statements to _validateOrder. This should allow any user to fill an order and prevent the manager from restricting exchange methods to themselves.
Great find, I like when wardens understand and identify issues with integrated external protocols.
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
Likely the _validateOrder function omitted checks that takerAddress and senderAddress are zero, allowing the manager to set them arbitrarily.
Impact
The manager could restrict order trades to themselves and extract value from the treasury by maximising allowed slippage.
What the attacker needed
Manager role; off-chain order creation
The fix
Add require statements to _validateOrder that takerAddress and senderAddress are zero.
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.
This is about a smart contract that lets a manager sign orders to trade assets. The contract forgot to check two fields that control who can fill the order. Because of that, the manager could set those fields to lock others out and trade at a worse price to steal value.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.