Omniscia Tokemak Network Audit
DefiRound Code Style Findings
DefiRound Code Style Findings
DRD-01C: Data Location Optimization
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | DefiRound.sol:L192 |
Description:
The linked function is declared as external
yet possesses a memory
argument.
Example:
192function getRates(address[] memory tokens) external view override returns (RateData[] memory rates) {193 uint256 tokensLength = tokens.length;194 rates = new RateData[](tokensLength);195 for (uint256 i = 0; i < tokensLength; i++) {196 rates[i] = tokenRates[tokens[i]];197 }198}
Recommendation:
We advise it to be set to calldata
greatly optimizing the function's gas cost.
Alleviation:
The tokens
member of getRates
was set to calldata
optimizing the codebase.
DRD-02C: Ineffectual Statement
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | DefiRound.sol:L94-L95, L121-L124, L241 |
Description:
The comment above the tokenAccountData
assignment denotes that updates are not saved if the struct is not assigned to the mapping
which is false as the tokenAccountData
is declared as storage
rather than memory
.
Example:
81AccountData storage tokenAccountData = accountData[msg.sender];82
83if (tokenAccountData.token == address(0)) {84 tokenAccountData.token = token;85}86
87require(tokenAccountData.token == token, "SINGLE_ASSET_DEPOSITS") ;88
89tokenAccountData.initialDeposit = tokenAccountData.initialDeposit.add(tokenAmount);90tokenAccountData.currentBalance = tokenAccountData.currentBalance.add(tokenAmount);91
92require(tokenAccountData.currentBalance <= tokenSettings[token].maxLimit, "MAX_LIMIT_EXCEEDED");93
94// set the data back in the mapping, otherwise updates are not saved95accountData[msg.sender] = tokenAccountData;
Recommendation:
We advise either the struct to be declared as memory
or the assignment to be omitted entirely as changes are reflected to the underlying struct when the storage
attribute is specified in the in-memory declaration.
Alleviation:
The assignment was safely omitted from the codebase along with its accompanying comment.
DRD-03C: Redundant Assignment
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | DefiRound.sol:L222 |
Description:
All variables in Solidity are initialized to a default value which in most cases is equivalent to the "0" of the respective type.
Example:
221function accountBalance(address account) external view override returns (uint256 value) {222 value = 0;223 uint256 tokenBalance = accountData[account].currentBalance;224 value = value.add(getTokenValue(accountData[account].token, tokenBalance)); 225}
Recommendation:
We advise the linked assignment to be omitted from the codebase safely as it is ineffectual.
Alleviation:
The redundant assignment was safely omitted from the codebase.
DRD-04C: Variable Mutability Specifiers
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | DefiRound.sol:L29, L45, L55, L58 |
Description:
The linked variables are assigned to only once during the contract's constructor
.
Example:
48constructor(49 // solhint-disable-next-line50 address _WETH,51 address _treasury,52 uint256 _maxTotalValue53) public {54 WETH = _WETH;55 treasury = _treasury;56 currentStage = STAGES.STAGE_1;57 58 maxTotalValue = _maxTotalValue;59}
Recommendation:
We advise them to be set as immutable
greatly optimizing their gas cost.
Alleviation:
Both variables were properly set to immutable
greatly optimizing the codebase.