25886 - [SC - Insight] registerToken can be front-run causing token ca...
Description
function registerToken(
ExchangeData.State storage S,
address tokenAddress,
bool isOwnerRegister
)
public
returns (uint32 tokenID)
{
require(!S.isInWithdrawalMode(), "INVALID_MODE");
require(S.tokenToTokenId[tokenAddress] == 0, "TOKEN_ALREADY_EXIST");
if (isOwnerRegister) {
require(S.reservedTokens.length < ExchangeData.MAX_NUM_RESERVED_TOKENS, "TOKEN_REGISTRY_FULL");
} else {
require(S.normalTokens.length < ExchangeData.MAX_NUM_NORMAL_TOKENS, "TOKEN_REGISTRY_FULL");
}
// Check if the deposit contract supports the new token
if (S.depositContract != IDepositContract(0)) {
require(S.depositContract.isTokenSupported(tokenAddress), "UNSUPPORTED_TOKEN");
}
// Assign a tokenID and store the token
ExchangeData.Token memory token = ExchangeData.Token(tokenAddress);
if (isOwnerRegister) {
tokenID = uint32(S.reservedTokens.length);
S.reservedTokens.push(token);
} else {
tokenID = uint32(S.normalTokens.length.add(ExchangeData.MAX_NUM_RESERVED_TOKENS));
S.normalTokens.push(token);
}
S.tokenToTokenId[tokenAddress] = tokenID + 1;
S.tokenIdToToken[tokenID] = tokenAddress;
S.tokenIdToDepositBalance[tokenID] = 0;
emit TokenRegistered(tokenAddress, tokenID);
}Impact
Risk Breakdown
Recommendation
References
Proof of concept
Previous25885 - [SC - Insight] Prevent the operator from submitting blocks to LNext25892 - [SC - Insight] A malicious user can DoS force withdraw request...
Last updated
Was this helpful?