Omniscia PolyTrade Finance Audit
PolyTadeToken Code Style Findings
PolyTadeToken Code Style Findings
PTT-01C: Access Gas Optimization
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | PolyTadeToken.sol:L83 |
Description:
The governance
member will be equal to the msg.sender
during the invocation of _burn
.
Example:
74function burn(uint amount) external {75 require(msg.sender == governance, "Unauthorized access");76 require(block.timestamp >= burnAllowedAfter, "burning not allowed yet");77
78 // record the mint79 burnAllowedAfter = block.timestamp + minimumTime;80
81 // mint the amount82 require(amount <= ((totalSupply() * cap)/100), "exceeded burn cap");83 _burn(governance, amount);84}
Recommendation:
We advise the msg.sender
to be used directly as it will cost roughly x20 less gas than a read of the state.
PTT-02C: Check Bytecode Size Optimization
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | PolyTadeToken.sol:L46, L57, L75 |
Description:
The require
check of the msg.sender
being equal to the governance
address is replicated across three functions.
Example:
41/**42 * @notice Change the governance address43 * @param _governance The address of the new governance44 */45function setGovernance(address _governance) external {46 require(msg.sender == governance, "Unauthorised access");47 emit GovernanceChanged(governance, _governance);48 governance = _governance;49}50
51/**52 * @notice Mint new tokens53 * @param receiver The address of the destination account54 * @param amount The number of tokens to be minted55 */56function mint(address receiver, uint amount) external {57 require(msg.sender == governance, "Unauthorized access");58 require(block.timestamp >= mintAllowedAfter, "minting not allowed yet");59 require(receiver != address(0), "cannot transfer to the zero address");60
61 // record the mint62 mintAllowedAfter = block.timestamp + minimumTime;63
64 // mint the amount65 require(amount <= ((totalSupply() * cap)/100), "exceeded mint cap");66 _mint(receiver, amount);67}68
69/**70 * @notice Burn tokens71 * @param amount The number of tokens to be burned72 * Tokens will be burned from governance account73 */74function burn(uint amount) external {75 require(msg.sender == governance, "Unauthorized access");76 require(block.timestamp >= burnAllowedAfter, "burning not allowed yet");77
78 // record the mint79 burnAllowedAfter = block.timestamp + minimumTime;80
81 // mint the amount82 require(amount <= ((totalSupply() * cap)/100), "exceeded burn cap");83 _burn(governance, amount);84}
Recommendation:
We advise a modifier
to be coded that in-turn invokes a single internal
function that performs the required check, thus ensuring that the require
message will only exist once in the bytecode.
PTT-03C: Check Ordering Optimization
Type | Severity | Location |
---|---|---|
Gas Optimization | Informational | PolyTadeToken.sol:L65, L82 |
Description:
A state change is performed in the linked functions before a require
check is evaluated that is unaffected by the state change.
Example:
74function burn(uint amount) external {75 require(msg.sender == governance, "Unauthorized access");76 require(block.timestamp >= burnAllowedAfter, "burning not allowed yet");77
78 // record the mint79 burnAllowedAfter = block.timestamp + minimumTime;80
81 // mint the amount82 require(amount <= ((totalSupply() * cap)/100), "exceeded burn cap");83 _burn(governance, amount);84}
Recommendation:
We advise the require
check to be evaluated before the state change to ensure that less gas will be consumed on an unsuccessful invocation.