Omniscia Tren Finance Audit

LockedTREN Code Style Findings

LockedTREN Code Style Findings

LTR-01C: Inefficient Data Pointer

Description:

The referenced data pointer is set as memory even though only two out of its five variables are read rendering it inefficient.

Example:

contracts/TREN/LockedTREN.sol
90Rule memory vestingRule = entitiesVesting[_entity];
91
92assignedTRENTokens = assignedTRENTokens - (vestingRule.totalSupply - vestingRule.claimed);

Recommendation:

We advise its data location to be set to storage, optimizing the function's gas cost.

Alleviation (f6f1ad0b8f24a96ade345db1dd05a1878eb0f761):

The referenced data pointer has been set to storage as advised, optimizing the code's gas cost.

LTR-02C: Inefficient Storage Reads

Description:

The referenced statements will read the startVestingDate and endVestingDate of the vesting entry from storage redundantly instead of using the same expressions as their assignment.

Example:

contracts/TREN/LockedTREN.sol
52entitiesVesting[_entity] = Rule(
53 block.timestamp,
54 _totalSupply,
55 block.timestamp + SIX_MONTHS,
56 block.timestamp + TWO_YEARS,
57 0
58);
59
60trenToken.safeTransferFrom(msg.sender, address(this), _totalSupply);
61
62emit AddEntityVesting(
63 _entity,
64 _totalSupply,
65 entitiesVesting[_entity].startVestingDate,
66 entitiesVesting[_entity].endVestingDate
67);

Recommendation:

We advise the expressions to be utilized instead, optimizing the code's gas cost.

Alleviation (f6f1ad0b8f24a96ade345db1dd05a1878eb0f761):

The event emission's storage-referenced arguments were replaced with their in-memory calculation counterparts optimizing the code's gas cost.

LTR-03C: Mislabelled Variable

TypeSeverityLocation
Code StyleLockedTREN.sol:L41, L50, L60

Description:

The _totalSupply variable of the LockedTREN::addEntityVesting function does not match what it implies.

Example:

contracts/TREN/LockedTREN.sol
50assignedTRENTokens += _totalSupply;

Recommendation:

We advise it to be aptly renamed to _vestedTokenAmount or a similar naming convention, increasing the legibility of the codebase.

Alleviation (f6f1ad0b8f24a96ade345db1dd05a1878eb0f761):

The variable was aptly renamed to _vestedTokenAmount properly indicating its purpose.

LTR-04C: Non-Standard Overlap of Modifier

Description:

The LockedTREN::setAddresses function has the same Initializable modifier as the LockedTREN::initialize function which is ill-advised.

Example:

contracts/TREN/LockedTREN.sol
31function initialize() public initializer {
32 address initialOwner = _msgSender();
33
34 __Ownable_init(initialOwner);
35}
36
37function setAddresses(address _trenAddress) public initializer onlyOwner {
38 trenToken = IERC20(_trenAddress);
39}

Recommendation:

While the functions can both be successfully invoked when the contract is deployed, it is strongly advised to use a one-off configuration restriction in the LockedTREN::setAddresses function rather than the Initializable::initializer as the modifier is expected to be applied to a single external / public function.

Alleviation (f6f1ad0b8f):

The Tren Finance team opted to remove the Initializable::initializer modifier from the LockedTREN::initialize function, however, no other restriction was set in its place which would permit the contract to become owned by any party.

In-line with our original recommendation, we advise the Initializable::initializer to remain in the LockedTREN::initialize function and the LockedTREN::setAddresses function to use a one-off restriction (i.e. if (trenToken != IERC20(address(0))) revert) instead.

Alleviation (73b9546eb9):

The code was updated to apply our original recommendation, ensuring that the contract's initialization is properly protected and that the LockedTREN::setAddresses function cannot be re-invoked arbitrarily.

LTR-05C: Suboptimal Struct Declaration Style

Description:

The linked declaration style of a struct is using index-based argument initialization.

Example:

contracts/TREN/LockedTREN.sol
52entitiesVesting[_entity] = Rule(
53 block.timestamp,
54 _totalSupply,
55 block.timestamp + SIX_MONTHS,
56 block.timestamp + TWO_YEARS,
57 0
58);

Recommendation:

We advise the key-value declaration format to be utilized instead, greatly increasing the legibility of the codebase.

Alleviation (f6f1ad0b8f24a96ade345db1dd05a1878eb0f761):

The key-value declaration style has been properly used in the referenced assignment addressing this exhibit.