Assessment reports>Orderly Network>Discussion>The `tokenHash` is not a hash from `tokenAddress`

It is not guaranteed that the tokenHash is a hash from the tokenAddress

The Vault contract owner can set the address of the tokens associated with the token hash using the changeTokenAddressAndAllow function. But this function gets the hash and the address of the token directly from the owner, instead of calculating the hash value using the address of the token. It allows the owner of the contract to change the address associated with the hash. This can lead to unexpected behavior if the user has made a deposit using tokenA, but tokenB will be used during the withdrawal of funds.

Also, the changeTokenAddressAndAllow function allows owner to set the same tokenAddress for different tokenHash hashes. This is due to the fact that the result of the allowedTokenSet.add(_tokenHash) function is ignored. The add function returns true if the element was successfully added and false if it was already added before. So even if the hash has already been added, the function will not be reverted.

function changeTokenAddressAndAllow(bytes32 _tokenHash, address _tokenAddress) public override onlyOwner {
    if (_tokenAddress == address(0)) revert AddressZero();
    allowedToken[_tokenHash] = _tokenAddress;
    allowedTokenSet.add(_tokenHash); // ignore returns here
    emit ChangeTokenAddressAndAllow(_tokenHash, _tokenAddress);
}
Zellic © 2024Back to top ↑