prePO contest - TerrierLover's results

Gain exposure to pre-IPO companies & pre-token projects.

General Information

Platform: Code4rena

Start Date: 17/03/2022

Pot Size: $30,000 USDC

Total HM: 8

Participants: 43

Period: 3 days

Judge: gzeon

Total Solo HM: 5

Id: 100

League: ETH

prePO

Findings Distribution

Researcher Performance

Rank: 16/43

Findings: 2

Award: $217.87

🌟 Selected for report: 0

πŸš€ Solo Findings: 0

Awards

51.8842 USDC - $51.88

Labels

bug
QA (Quality Assurance)
disagree with severity

External Links

No need to wrap with parenthesis

Target codebase

_valueBefore variable is wrapped by parenthesis but this is not needed.

https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/Collateral.sol#L89

_shares = (_amountToDeposit * totalSupply()) / (_valueBefore);

Proposed change

_shares = (_amountToDeposit * totalSupply()) / _valueBefore;

#0 - ramenforbreakfast

2022-03-22T22:40:15Z

Valid claim, but lower severity to 0. Does not affect functionality and is a code style nit.

#1 - ramenforbreakfast

2022-03-23T02:43:20Z

Ignore mentions, accidentally referred to issue 19 when i meant 18 for duplicate issues.

Awards

165.9874 USDC - $165.99

Labels

bug
G (Gas Optimization)

External Links

unchecked direction can be used at mintLongShortTokens function in PrePOMarket.sol

Target codebase

mintLongShortTokens function in PrePOMarket.sol can use unchecked directory.

https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/PrePOMarket.sol#L122

require(_amount > _fee, "Minting amount too small"); _collateral.transferFrom(msg.sender, _treasury, _fee); _amount -= _fee;

It is obvious that _amount - _fee will not be underflown since it has require(_amount > _fee, ...). Hence, can use unchecked directory,

Proposed change

require(_amount > _fee, "Minting amount too small"); _collateral.transferFrom(msg.sender, _treasury, _fee); unchecked { _amount -= _fee; }

Gas changes with the proposed changes

Methods - average gas change

ContractMethodsBeforeAfterChange
PrePOMarketmintLongShortTokens198115198055-60

Deployments - average gas change

ContractBeforeAfterChange
PrePOMarketFactory41820114180271-1740

unchecked direction can be used at redeem function in PrePOMarket.sol

Target codebase

redeem function in PrePOMarket.sol can use unchecked directory.

https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/PrePOMarket.sol#L169

require(_collateralOwed > _fee, "Redemption amount too small"); _collateral.transfer(_treasury, _fee); _collateralOwed -= _fee;

It is obvious that _collateralOwed - _fee will not be underflown since it has require(_collateralOwed > _fee, ...). Hence, can use unchecked directory,

Proposed change

require(_collateralOwed > _fee, "Redemption amount too small"); _collateral.transfer(_treasury, _fee); unchecked { _collateralOwed -= _fee; }

Gas changes with the proposed changes

Methods - average gas change

ContractMethodsBeforeAfterChange
PrePOMarketmintLongShortTokens100708100653-55

Deployments - average gas change

ContractBeforeAfterChange
PrePOMarketFactory41820114180271-1740

Target codebase

Proposed change

Gas changes with the proposed changes

Methods - average gas change

ContractMethodsBeforeAfterChange
PrePOMarketextractRewards135652131459-4193

Deployments - average gas change

ContractBeforeAfterChange
ExecutorManager548814536945-11869

Unchecked can be used at deposit function in Collateral.sol

Target codebase

https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/Collateral.sol#L73

require(_amountToDeposit > _fee, "Deposit amount too small"); _baseToken.safeTransfer(_treasury, _fee); _amountToDeposit -= _fee;

_amountToDeposit - _fee will not be underflown since require(_amountToDeposit > _fee, ...).

Proposed change

require(_amountToDeposit > _fee, "Deposit amount too small"); _baseToken.safeTransfer(_treasury, _fee); unchecked { _amountToDeposit -= _fee; }

Gas changes with the proposed changes

Methods - average gas change

ContractMethodsBeforeAfterChange
PrePOMarketextractRewards135652131459-4193

Deployments - average gas change

ContractBeforeAfterChange
ExecutorManager548814536945-11869

uint256 _shares does not need to be initialized with 0 at deposit function in Collateral.sol

Target codebase

https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/Collateral.sol#L81

uint256 _shares = 0;

Proposed change

uint256 _shares;

Gas changes with the proposed changes

Methods - average gas change

ContractMethodsBeforeAfterChange
Collateraldeposit273176273117-59

Deployments - average gas change

ContractBeforeAfterChange
TestCollateral33839403382344-1596

unchecked can be used at withdraw function at Collateral.sol

Target codebase

https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/Collateral.sol#L171

require(_amountWithdrawn > _fee, "Withdrawal amount too small"); _baseToken.safeTransfer(_treasury, _fee); _amountWithdrawn -= _fee;

It is obvious that _amountWithdrawn - _fee will not be underflown since it has require(_amountWithdrawn > _fee, ...).

Proposed change

require(_amountWithdrawn > _fee, "Withdrawal amount too small"); _baseToken.safeTransfer(_treasury, _fee); unchecked { _amountWithdrawn -= _fee; }

Gas changes with the proposed changes

Methods - average gas change

ContractMethodsBeforeAfterChange
Collateralwithdraw162848162788-60

Deployments - average gas change

ContractBeforeAfterChange
TestCollateral33839403382200-1740

Unchecked can be used at recordDeposit function in CollateralDepositRecord.sol

Target codebase

https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/CollateralDepositRecord.sol#L37-L38

require( _amount + _globalDepositAmount <= _globalDepositCap, "Global deposit cap exceeded" ); require( _amount + _accountToNetDeposit[_sender] <= _accountDepositCap, "Account deposit cap exceeded" ); _globalDepositAmount += _amount; _accountToNetDeposit[_sender] += _amount;

Both _globalDepositAmount + _amount and _accountToNetDeposit[_sender] + _amount will not be overflown because it checks _amount + _globalDepositAmount <= _globalDepositCap and _amount + _accountToNetDeposit[_sender] <= _accountDepositCap before.

Proposed change

require( _amount + _globalDepositAmount <= _globalDepositCap, "Global deposit cap exceeded" ); require( _amount + _accountToNetDeposit[_sender] <= _accountDepositCap, "Account deposit cap exceeded" ); unchecked { _globalDepositAmount += _amount; _accountToNetDeposit[_sender] += _amount; }

Gas changes with the proposed changes

Methods - average gas change

ContractMethodsBeforeAfterChange
CollateralDepositRecordrecordDeposit6602265298-724

Deployments - average gas change

ContractBeforeAfterChange
CollateralDepositRecord750519744047-6472

Unchecked can be used at recordWithdrawal function in CollateralDepositRecord.sol

Target codebase

https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/CollateralDepositRecord.sol#L47 https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/CollateralDepositRecord.sol#L52

if (_globalDepositAmount > _amount) { _globalDepositAmount -= _amount; } else { _globalDepositAmount = 0; } if (_accountToNetDeposit[_sender] > _amount) { _accountToNetDeposit[_sender] -= _amount; } else { _accountToNetDeposit[_sender] = 0; }

_globalDepositAmount - _amount and _accountToNetDeposit[_sender] - _amount will not be underflown since they are wrapped by the if statement _globalDepositAmount > _amount or _accountToNetDeposit[_sender] > _amount.

Proposed change

if (_globalDepositAmount > _amount) { unchecked { _globalDepositAmount -= _amount; } } else { _globalDepositAmount = 0; } if (_accountToNetDeposit[_sender] > _amount) { unchecked { _accountToNetDeposit[_sender] -= _amount; } } else { _accountToNetDeposit[_sender] = 0; }

Gas changes with the proposed changes

Methods - average gas change

ContractMethodsBeforeAfterChange
CollateralDepositRecordrecordWithdrawal3302332895-128

Deployments - average gas change

ContractBeforeAfterChange
CollateralDepositRecord750519736492-14027

Unchecked can be used at allowAccounts function in AccountAccessController.sol

Target codebase

https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/AccountAccessController.sol#L44

for (uint256 _i = 0; _i < _accounts.length; _i++) { _allowedAccounts[_allowedAccountsIndex][_accounts[_i]] = true; emit AccountAllowed(_accounts[_i]); }

Proposed change

for (uint256 _i = 0; _i < _accounts.length; ) { _allowedAccounts[_allowedAccountsIndex][_accounts[_i]] = true; emit AccountAllowed(_accounts[_i]); unchecked { _i++; } }

Gas changes with the proposed changes

Methods - average gas change

ContractMethodsBeforeAfterChange
MockAccountAccessControllerallowAccounts115094114786-308

Deployments - average gas change

ContractBeforeAfterChange
MockAccountAccessController948869946721-2148

Unchecked can be used at blockAccounts function in AccountAccessController.sol

Target codebase

https://github.com/code-423n4/2022-03-prepo/blob/main/contracts/core/AccountAccessController.sol#L55-L58

for (uint256 _i = 0; _i < _accounts.length; _i++) { _blockedAccounts[_blockedAccountsIndex][_accounts[_i]] = true; emit AccountBlocked(_accounts[_i]); }

Proposed change

for (uint256 _i = 0; _i < _accounts.length; ) { _blockedAccounts[_blockedAccountsIndex][_accounts[_i]] = true; emit AccountBlocked(_accounts[_i]); unchecked { _i++; } }

Gas changes with the proposed changes

Methods - average gas change

ContractMethodsBeforeAfterChange
MockAccountAccessControllerblockAccounts115120114812-308

Deployments - average gas change

ContractBeforeAfterChange
MockAccountAccessController948869946721-2148

#0 - ramenforbreakfast

2022-03-22T22:39:33Z

Excellent submission, well documented and clearly outlines gas savings. This report and #5 will be referenced as the source submissions for common optimization duplicates.

AuditHub

A portfolio for auditors, a security profile for protocols, a hub for web3 security.

Built bymalatrax Β© 2024

Auditors

Browse

Contests

Browse

Get in touch

ContactTwitter