Part of CertiK’s series
CertiK reviewed SquidGrow (SGS - DEX) on 14 Feb 2024: 15 findings, 0 critical; none marked fixed.
Report hosted on skynet.certik.com.
Trustblock does not review code.
Statuses are the security firm’s own, from its report.
| Severity | Open | Acknowledged | Fixed |
|---|---|---|---|
| Critical | 0 | 0 | 0 |
| High | 2 | 0 | 0 |
| Medium | 0 | 0 | 0 |
| Low | 13 | 0 | 0 |
In the contract `SGSPair` the role `factory` has authority over the functions shown in the diagram below.  - `initialize(address _token0, address _token1)`: Initializes the contract with the given token addresses. This function is restricted to being called by the current `factory`. Any compromise to the `factory` account may allow the hacker to take advantage of this authority, update the sensitive settings, and execute sensitive functions of the project. ----- In the contract `SGSFactory` the role `feeToSetter` has authority over the functions shown in the diagram below.  - `setFeeTo(address _feeTo)`: Sets the address to which trading fees will be directed. This function is restricted to being called by the current `feeToSetter`. - `setFeeToSetter(address _feeToSetter)`: Updates the address that has the authority to set the feeTo address. This function is restricted to being called by the current `feeToSetter`. Any compromise to the `feeToSetter` account may allow the hacker to take advantage of this authority, update the sensitive settings, and execute sensitive functions of the project.
There is an issue inside the `SGSRouter01` contract: `SGSRouter01.sol` implements the function `_swap` which doesn't support tokens that take fee on transfer. Functions that call `_swap` might revert, including: - `swapExactTokensForTokens` - `swapTokensForExactTokens` - `swapExactETHForTokens` - `swapTokensForExactETH` - `swapExactTokensForETH` - `swapETHForExactTokens` Assuming a scenario for the function `swapExactTokensForTokens`: 1) Alice attempts to swap 1 `aToken` for some `bToken`, `aToken` takes 20% fee on transfer. The liquidity pool has 5 `aToken` and 20 `bToken`. 2) The function `getAmountsOut()` will be used to determine the amount of `bToken` that can be swapped for 1 `aToken`. Based on the calculation, 1 `aToken` can be exchanged for approximately 3.325 `bToken`. 4) Liquidity pool receives 0.8 `aToken` (fee deducted) and optimistically transfers 3.325 `bToken` to Alice. Liquidity Pool now has 5.8 `aToken` and 16.675 `bToken`. 5) The new `K` will approximately be $(5.8*1000-0.8*3)*(16.675*1000) \approx 96,674,980$ which is smaller than the original K $(5*20)*1000^2=100,000,000$ calculated by the reserves. 6) The transaction reverts due to `K` validation failure.
When transferring standard ERC20 deflationary tokens, the input amount may not be equal to the received amount due to the charged transaction fee. As a result, an inconsistency in the amount will occur and the transaction may fail due to the validation checks.
One or more parameters with `memory` data location are never modified in their functions and those functions are never called internally within the contract. Thus, their data location can be changed to `calldata` to avoid the gas consumption copying from calldata to memory. ```solidity=479 function getAmountsOut( ``` `getAmountsOut` has memory location parameters: `path`. --- ```solidity=146 function getAmountsIn( ``` `getAmountsIn` has memory location parameters: `path`.
The functions `approve()`, `permit()` and `transfer()/transferFrom()` allows zero address as destination address. Then if users transfer funds to zero address by mistake, the funds can not be transferred out and are locked up forever. See https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.2/contracts/token/ERC20/ERC20.sol
There should always be events emitted in the sensitive functions that are controlled by centralization roles.
Addresses should be checked before assigning to make sure they are not zero addresses.
Addresses are not validated before assignment or external calls, potentially allowing the use of zero addresses and leading to unexpected behavior or vulnerabilities. For example, transferring tokens to a zero address can result in a permanent loss of those tokens. ```solidity=19 feeToSetter = _feeToSetter; ``` - `_feeToSetter` is not zero-checked before being used. --- ```solidity=45 feeTo = _feeTo; ``` - `_feeTo` is not zero-checked before being used. --- ```solidity=50 feeToSetter = _feeToSetter; ``` - `_feeToSetter` is not zero-checked before being used. --- ```solidity=69 token0 = _token0; ``` - `_token0` is not zero-checked before being used. --- ```solidity=70 token1 = _token1; ``` - `_token1` is not zero-checked before being used.
The `to` parameter in the following functions is missing a check that it is not `address(0)`: 1. **`_transfer()` Function:** Without the `address(0)` check, tokens can be inadvertently transferred to the zero address. Since there's no way to retrieve tokens sent to this address, they would be lost forever, reducing the effective circulating supply while not adjusting the `totalSupply`. 2. **`_mint()` Function:** In the absence of this check, tokens could be minted directly to the zero address. This would increase the `totalSupply` counter without adding to the effective circulating supply, creating a discrepancy between the two. 3. **`_burn()` Function:** If tokens are burnt from the zero address without a corresponding mint having taken place, it could lead to the `totalSupply` being reduced more than the actual tokens being burnt, again leading to a discrepancy between the `totalSupply` and the effective circulating supply.
Performing division by zero would raise an error and revert the transaction. ```solidity=124 liquidity = Math.min(amount0.mul(_totalSupply) / _reserve0, amount1.mul(_totalSupply) / _reserve1); ``` The expression `amount0.mul(_totalSupply) / _reserve0` may divide by zero. Its divisor has has estimated interval [0, 5192296858534827628530496329220095]. --- ```solidity=145 amount0 = liquidity.mul(balance0) / _totalSupply; // using balances ensures pro-rata distribution ``` The expression `liquidity.mul(balance0) / _totalSupply` may divide by zero. Its divisor has has estimated interval [-115792089237316195423570985008687907853269984665640564039457584007913129639935, pinf]. --- ```solidity=146 amount1 = liquidity.mul(balance1) / _totalSupply; // using balances ensures pro-rata distribution ``` The expression `liquidity.mul(balance1) / _totalSupply` may divide by zero. Its divisor has has estimated interval [-115792089237316195423570985008687907853269984665640564039457584007913129639935, pinf]. --- ```solidity=86 amountIn = (numerator / denominator).add(1); ``` The expression `numerator / denominator` may divide by zero. Its divisor has has estimated interval [ninf, pinf]. --- ```solidity=19 z = x / uint224(y); ``` The expression `x / uint224(y)` may divide by zero. Its divisor has has estimated interval [0, 5192296858534827628530496329220095].
The contract is serving as the underlying entity to interact with one or more third party protocols. The scope of the audit treats third party entities as black boxes and assumes their functional correctness. However, in the real world, third parties can be compromised and this may lead to lost or stolen assets. In addition, upgrades of third parties can possibly create severe impacts, such as increasing fees of third parties, migrating to new LP pools, etc. ```solidity=20 address public token0; ``` - The contract `SGSPair` interacts with third party contract with `IERC20` interface via `token0`. --- ```solidity=21 address public token1; ``` - The contract `SGSPair` interacts with third party contract with `IERC20` interface via `token1`. --- ```solidity=160 address to, ``` - The function `SGSPair.swap` interacts with third party contract with `ISGSCallee` interface via `to`.
The return values of the `transfer()` and `transferFrom()` calls in the smart contract are not checked. Some ERC-20 tokens' transfer functions return no values, while others return a bool value, they should be handled with care. If a function returns `false` instead of reverting upon failure, an unchecked failed transfer could be mistakenly considered successful in the contract. ```solidity=137 ISGSPair(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair ``` --- ```solidity=110 ISGSPair(pair).transferFrom(msg.sender, pair, liquidity); // send liquidity to pair ```
The contract has unlocked compiler version. An unlocked compiler version in the source code of the contract permits the user to compile it at or above a particular version. This, in turn, leads to differences in the generated bytecode between compilations due to different compiler versions. This can lead to an ambiguity when debugging as compiler specific bugs may occur in the codebase that would be hard to identify over a span of multiple compiler versions rather than a specific one.
The smart contract does not check or store the return value of an external call in a local or state variable, which may introduce vulnerabilities due to the unhandled outcome. ```solidity=44 ISGSFactory(factory).createPair(tokenA, tokenB); ``` --- ```solidity=139 (address token0, ) = SGSLibrary.sortTokens(tokenA, tokenB); ``` --- ```solidity=253 (address token0, ) = SGSLibrary.sortTokens(input, output); ``` --- ```solidity=375 (address token0, ) = SGSLibrary.sortTokens(input, output); ``` --- ```solidity=381 (uint256 reserve0, uint256 reserve1, ) = pair.getReserves(); ``` --- ```solidity=41 ISGSFactory(factory).createPair(tokenA, tokenB); ``` --- ```solidity=112 (address token0,) = SGSLibrary.sortTokens(tokenA, tokenB); ``` --- ```solidity=173 (address token0,) = SGSLibrary.sortTokens(input, output); ``` --- ```solidity=47 (uint256 reserve0, uint256 reserve1, ) = ISGSPair(pairFor(factory, tokenA, tokenB)).getReserves(); ```
```solidity=19 address public factory; ``` The `factory` variable assigned in the constructor of the `PancakePair` contract can be declared as `immutable`. Immutable state variables can be assigned during contract creation but will remain constant throughout the lifetime of a deployed contract. A big advantage of immutable variables is that reading them is significantly cheaper than reading from regular state variables since they will not be stored in storage.
The report names a repository or files. Open the report to see its scope.
Repository and files the report names (10)
1,045 projects reviewed · 1,376 reports · latest May 2025
See CertiK’s auditsSomething wrong on this page? A missing report, a wrong date, a finding that was fixed since. Tell us and we check it against its source.
Tell us