OrderBook

First Flight #43
Beginner FriendlySolidity
100 EXP
View results
Submission Details
Impact: low
Likelihood: high
Invalid

non-retrieveable details for dynamically added tokens

Root Cause

The getOrderDetailsString(uint256 _orderId) function only maps token addresses to symbols using static conditional logic:

if (order.tokenToSell == address(iWETH)) tokenSymbol = "wETH";
else if (order.tokenToSell == address(iWBTC)) tokenSymbol = "wBTC";
else if (order.tokenToSell == address(iWSOL)) tokenSymbol = "wSOL";

This logic does not scale to support tokens added dynamically via setAllowedSellToken().

Description

The getOrderDetailsString(uint256 _orderId) function fails to display token symbols for tokens dynamically added via setAllowedSellToken(). This is due to the use of hardcoded token address checks, which only recognize three specific tokens (iWETH, iWBTC, and iWSOL). All other tokens will display an empty token symbol, making the returned order details incomplete or misleading.

Risk

Likelihood: High

Severity: Low

Impact:

  • Sell orders for dynamically added tokens will return empty "Selling" fields.

  • Users or interfaces relying on getOrderDetailsString() will not know which token is involved.


Recommended Mitigation

Use IERC20Metadata.symbol()

Fetch the symbol dynamically from the token contract:

import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
tokenSymbol = IERC20Metadata(order.tokenToSell).symbol();

Note: Ensure the token contract implements symbol() (standard for most ERC-20 tokens).

Alternative Fix: Store symbol on setAllowedSellToken

Modify the allowlist function to store symbols:

mapping(address => string) public tokenSymbols;
function setAllowedSellToken(address _token, bool _isAllowed, string memory symbol) external onlyOwner {
...
if (_isAllowed) tokenSymbols[_token] = symbol;
else delete tokenSymbols[_token];
}

Then access it in getOrderDetailsString:

tokenSymbol = tokenSymbols[order.tokenToSell];

Updates

Lead Judging Commences

yeahchibyke Lead Judge about 1 month ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.