Sublime contest - Funen's results

Democratizing credit via Web3.

General Information

Platform: Code4rena

Start Date: 29/03/2022

Pot Size: $30,000 USDC

Total HM: 6

Participants: 24

Period: 3 days

Judge: HardlyDifficult

Total Solo HM: 4

Id: 101

League: ETH

Sublime

Findings Distribution

Researcher Performance

Rank: 21/24

Findings: 1

Award: $45.87

🌟 Selected for report: 0

🚀 Solo Findings: 0

Findings Information

Awards

45.8731 USDC - $45.87

Labels

bug
G (Gas Optimization)

External Links

  1. Upgrade pragma compiler at least ^0.8.* or 0.8.4



This known issue was set before at :


https://github.com/code-423n4/2021-12-sublime-findings/issues/39



using new compiler will set Optimizer improvement for Safemath, Custom error, etc. it would be saving more gas by using it.



##Occurance


PooledCreditLine.sol LenderPool.sol
 twitterVerifier.sol


  1. Better way of using SafeERC20 to saving more gas



https://github.com/sublime-finance/sublimev1/blob/46536a6d25df4264c1b217bd3232af30355dcb95/contracts/PooledCreditLine/LenderPool.sol#L295

This implementation can be saving more gas 



##POC



by not declaring :

using SafeErc20 for IERC20
;



 and change into

SafeERC20.safeTransferFrom(IERC20(_borrowAsset), msg.sender, address(this), _amountToLend);




3. Rewrite struct order for saving more gas



this implementation below can be used for saving more gas



##Tool Used Manual Review

##POC

struct PooledCreditLineConstants { uint128 borrowLimit; uint128 borrowRate; uint256 startsAt; uint256 endsAt; uint256 defaultsAt; uint256 gracePenaltyRate; uint256 idealCollateralRatio; address borrower; address borrowAsset; address collateralAsset; address borrowAssetStrategy; address collateralAssetStrategy; }
  1. change if else statement for saving more gas

https://github.com/sublime-finance/sublime-v1/blob/46536a6d25df4264c1b217bd3232af30355dcb95/contracts/PooledCreditLine/PooledCreditLine.sol#L373

this implementation with the same logic, can be used for saving more gas (+- 12 gas)

##Tool Used Remix

##POC

// SPDX-License-Identifier: MIT pragma solidity 0.7.6; pragma abicoder v2; contract foo{ function isWithinLimits( uint256 _value, uint256 _min, uint256 _max ) internal pure returns (bool) { if (_min != 0 && _max != 0) { // If both min and max limits exist return (_value >= _min && _value <= _max); } else if (_min != 0) { // if only min limit exists return (_value >= _min); } else if (_max != 0) { // if only max limit exists return (_value <= _max); } else { // if both min and max limits don't exist return true; } } } // 67066

change to

// SPDX-License-Identifier: MIT pragma solidity 0.7.6; pragma abicoder v2; contract foo{ function isWithinLimits( uint256 _value, uint256 _min, uint256 _max ) internal pure returns (bool) { if (_min != 0 && _max != 0) { return (_value >= _min && _value <= _max); } else if ( _min != 0 || _max != 0 ) { return (_value >= _min || _value <= _max); } else { // if both min and max limits don't exist return true; } } } // 67054
  1. Variable can be set as immutable

https://github.com/sublime-finance/sublime-v1/blob/46536a6d25df4264c1b217bd3232af30355dcb95/contracts/Verification/twitterVerifier.sol#L16

##POC

IVerification public immutable verification;

#0 - ritik99

2022-04-12T19:11:51Z

All except the first suggestions are valid. The first suggestion isn't valid for us because one of our dependencies is currently not compatible with v0.8 (see #67 )

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