Omniscia Platypus Finance Audit

Ptp Code Style Findings

Ptp Code Style Findings

PTP-01C: Deprecated Representation Style

TypeSeverityLocation
Code StyleInformationalPtp.sol:L253, L258

Description:

The linked values are meant to represent the maximum values of the respective type yet do so using literals.

Example:

contracts/Ptp.sol
252function safe32(uint256 n, string memory errorMessage) internal pure returns (uint32) {
253 require(n < 2**32, errorMessage);
254 return uint32(n);
255}
256
257function safe96(uint256 n, string memory errorMessage) internal pure returns (uint96) {
258 require(n < 2**96, errorMessage);
259 return uint96(n);
260}

Recommendation:

We advise the built-in type operator to be utilized to replace those instances with their standardized representation.

Alleviation:

The Platypus team considered this exhibit but opted not to apply a remediation for it.

PTP-02C: Inefficient Mutability Type

TypeSeverityLocation
Gas OptimizationInformationalPtp.sol:L40-L41, L44-L45

Description:

The linked statements are meant to represent constant values, however, the constant keyword is also applicable to expressions and as such these constant declarations do not actually optimize the codebase and replace their instances with the costly keccak256 instruction instead of its result.

Example:

contracts/Ptp.sol
39/// @notice The EIP-712 typehash for the contract's domain
40bytes32 public constant DOMAIN_TYPEHASH =
41 keccak256('EIP712Domain(string name,uint256 chainId,address verifyingContract)');
42
43/// @notice The EIP-712 typehash for the permit struct used by the contract
44bytes32 public constant PERMIT_TYPEHASH =
45 keccak256('Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)');

Recommendation:

We advise proper optimization to be applied to the codebase by using the immutable keyword instead. For more information, consult this issue in the Solidity compiler.

Alleviation:

The mutability specifiers of the linked hashes were properly set to immutable optimizing the codebase.

PTP-03C: Memory Usage Optimization

TypeSeverityLocation
Gas OptimizationInformationalPtp.sol:L74

Description:

The linked event emission redundantly reads a newly written to value from storage.

Example:

contracts/Ptp.sol
59/**
60 * @notice Construct a new Ptp token
61 * @param account The initial account to grant all the tokens
62 * @param minter_ The account with minting ability
63 * @param mintingAllowedAfter_ The timestamp after which minting may occur
64 */
65constructor(
66 address account,
67 address minter_,
68 uint256 mintingAllowedAfter_
69) {
70 require(mintingAllowedAfter_ >= block.timestamp, 'Ptp::constructor: minting can only begin after deployment');
71
72 balances[account] = uint96(totalSupply);
73 emit Transfer(address(0), account, totalSupply);
74 minter = minter_;
75 emit MinterChanged(address(0), minter);
76 mintingAllowedAfter = mintingAllowedAfter_;
77}

Recommendation:

We advise the in memory value to be utilized instead.

Alleviation:

The event emission argument was optimized to stem from memory.

PTP-04C: Redundant Usage of SafeMath

TypeSeverityLocation
Gas OptimizationInformationalPtp.sol:L4, L100, L104, L105

Description:

The SafeMath library is no longer necessary in any Solidity version beyond 0.8.X as they all support built-in safe arithmetics.

Example:

contracts/Ptp.sol
102// mint the amount
103uint96 amount = safe96(rawAmount, 'Ptp::mint: amount exceeds 96 bits');
104require(amount <= SafeMath.div(SafeMath.mul(totalSupply, mintCap), 100), 'Ptp::mint: exceeded mint cap');
105totalSupply = safe96(SafeMath.add(totalSupply, amount), 'Ptp::mint: totalSupply exceeds 96 bits');

Recommendation:

We advise its usage to be omitted to significantly reduce the gas cost of the contract.

Alleviation:

The Platypus team considered this exhibit but opted not to apply a remediation for it.