Omniscia DAFI Protocol Audit
standardtoken Code Style Findings
standardtoken Code Style Findings
STA-01C: Redundant require
Checks
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | standardtoken.sol:L16, L17, L18, L20 |
Description:
The transferFrom
function redundantly evaluates whether the _from
address has sufficient balance to transfer as well as whether they have provided msg.sender
with sufficient allowance. These checks are redundant as safe arithmetic subtractions are performed in the ensuing lines.
Example:
contracts/standardtoken.sol
9function transferFrom(10 address _from,11 address _to,12 uint256 _value13) public returns (bool) {14 require(_to != address(0),"To cannot be ZERO ADDRESS");15 require(_from != address(0),"From cannot be Address 0");16 require(_value <= balances[_from],"Insufficient Balance");17 require(_value <= allowed[_from][msg.sender],"msg sender not approved of this amount");18 balances[_from] = balances[_from] - _value;19 balances[_to] = balances[_to] + _value;20 allowed[_from][msg.sender] = allowed[_from][msg.sender] - _value;21
22 emit Transfer(_from, _to, _value);23 return true;24}
Recommendation:
We advise either the require
checks to be omitted or the subtractions to be performed in unchecked
code blocks to ensure the code is gas optimal.
Alleviation:
Both subtractions are now optimally performed within an unchecked
block.
STA-02C: Suboptimal Code
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | standardtoken.sol:L50 |
Description:
The linked subtraction is guaranteed to not underflow by the surrounding if
block.
Example:
contracts/standardtoken.sol
47if (_subtractedValue > oldValue) {48 allowed[msg.sender][_spender] = 0;49} else {50 allowed[msg.sender][_spender] = oldValue - _subtractedValue;51}
Recommendation:
We advise the subtraction to be set within an unchecked
code block.
Alleviation:
The subtraction is now optimally performed in an unchecked
block.