Omniscia PolyTrade Finance Audit

PolyTadeToken Code Style Findings

PolyTadeToken Code Style Findings

PTT-01C: Access Gas Optimization

TypeSeverityLocation
Gas OptimizationInformationalPolyTadeToken.sol:L83

Description:

The governance member will be equal to the msg.sender during the invocation of _burn.

Example:

contracts/PolyTadeToken.sol
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 mint
79 burnAllowedAfter = block.timestamp + minimumTime;
80
81 // mint the amount
82 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

TypeSeverityLocation
Gas OptimizationInformationalPolyTadeToken.sol:L46, L57, L75

Description:

The require check of the msg.sender being equal to the governance address is replicated across three functions.

Example:

contracts/PolyTadeToken.sol
41/**
42 * @notice Change the governance address
43 * @param _governance The address of the new governance
44 */
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 tokens
53 * @param receiver The address of the destination account
54 * @param amount The number of tokens to be minted
55 */
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 mint
62 mintAllowedAfter = block.timestamp + minimumTime;
63
64 // mint the amount
65 require(amount <= ((totalSupply() * cap)/100), "exceeded mint cap");
66 _mint(receiver, amount);
67}
68
69/**
70 * @notice Burn tokens
71 * @param amount The number of tokens to be burned
72 * Tokens will be burned from governance account
73 */
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 mint
79 burnAllowedAfter = block.timestamp + minimumTime;
80
81 // mint the amount
82 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

TypeSeverityLocation
Gas OptimizationInformationalPolyTadeToken.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:

contracts/PolyTadeToken.sol
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 mint
79 burnAllowedAfter = block.timestamp + minimumTime;
80
81 // mint the amount
82 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.