QA Report #334
Labels
bug
Something isn't working
QA (Quality Assurance)
Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax
Overview
Table of Contents
abi.encodePacked()
should not be used with dynamic types when passing the result to a hash function such askeccak256()
constant
instead of duplicating the same stringstring.concat()
orbytes.concat()
return
statement when the function defines a named return variable, is redundantLow Risk Issues
1. Missing address(0) checks
Consider adding an
address(0)
check for immutable variables:55: address public immutable WETH; ... 104: constructor(address _WETH, address _matchExecutor) { ... + 115: require(_WETH != address(0)); 115: WETH = _WETH; ... 117: }
2. Prevent accidentally burning tokens
Transferring tokens to the zero address is usually prohibited to accidentally avoid "burning" tokens by sending them to an unrecoverable zero address.
Consider adding a check to prevent accidentally burning tokens here:
File: InfinityExchange.sol 1220: function rescueTokens( 1221: address destination, 1222: address currency, 1223: uint256 amount 1224: ) external onlyOwner { + 1225: require(destination != address(0)); 1225: IERC20(currency).safeTransfer(destination, amount); 1226: }
3. Add a timelock to critical functions
It is a good practice to give time for users to react and adjust to critical changes. A timelock provides more guarantees and reduces the level of trust required, thus decreasing risk for users. It also indicates that the project is legitimate (less risk of a malicious owner making a sandwich attack on a user).
Consider adding a timelock to:
4.
abi.encodePacked()
should not be used with dynamic types when passing the result to a hash function such askeccak256()
Similar issue in the past: here
Use
abi.encode()
instead which will pad items to 32 bytes, which will prevent hash collisions (e.g.abi.encodePacked(0x123,0x456)
=>0x123456
=>abi.encodePacked(0x1,0x23456)
, butabi.encode(0x123,0x456)
=>0x0...1230...456
). If there is only one argument toabi.encodePacked()
it can often be cast tobytes()
orbytes32()
instead.5. Events not indexed
6. Use a
constant
instead of duplicating the same string7. Use a 2-step ownership transfer pattern
Contracts inheriting from OpenZeppelin's libraries have the default
transferOwnership()
function (a one-step process). It's possible that theonlyOwner
role mistakenly transfers ownership to a wrong address, resulting in a loss of theonlyOwner
role.Consider overriding the default
transferOwnership()
function to first nominate an address as thependingOwner
and implementing anacceptOwnership()
function which is called by thependingOwner
to confirm the transfer.Non-Critical Issues
1. Typos
2. Use scientific notation for readability reasons
100000
should be changed to1e5
1000000
should be changed to1e6
20000
should be changed to2e5
50000
should be changed to5e5
3. Use
string.concat()
orbytes.concat()
Solidity version 0.8.4 introduces
bytes.concat()
(vsabi.encodePacked(<bytes>,<bytes>)
)Solidity version 0.8.12 introduces
string.concat()
(vsabi.encodePacked(<str>,<str>)
)Here, the version is
0.8.14
:4. Adding a
return
statement when the function defines a named return variable, is redundantWhile not consuming more gas with the Optimizer enabled: using both named returns and a return statement isn't necessary. Removing one of those can improve code clarity.
Affected code:
The text was updated successfully, but these errors were encountered: