Platform: Code4rena
Start Date: 01/09/2023
Pot Size: $36,500 USDC
Total HM: 4
Participants: 70
Period: 6 days
Judge: kirk-baird
Id: 281
League: ETH
Rank: 46/70
Findings: 1
Award: $9.75
🌟 Selected for report: 0
🚀 Solo Findings: 0
🌟 Selected for report: c3phas
Also found by: 0x11singh99, 0xhex, 0xta, Eurovickk, K42, MohammedRizwan, SAAJ, SAQ, SY_S, adriro, albahaca, castle_chain, jeffy, kaveyjoe, matrix_0wl, naman1778, petrichor, wahedtalash77, ybansal2403, zabihullahazadzoi
9.7506 USDC - $9.75
This report focuses on Ondo-Finance Protocol contest, in context of various improvements that can be made in terms of gas cost.
Some of the opportunities identified for improving gas efficiency throughout the codebase of Ondo-Finance protocol are categorised into 07 main areas; with further multiple instances in each of the category.
[G-01] Increase number of optimisation runs (01 Instances) [G-02] Create less memory variables (08 Instances) [G-03] Revert inside a loop (05 Instances) [G 04] Using private rather than public for immutable saves gas (06 Instances) [G 05] abi.encode() is less efficient than abi.encodepacked()(03 Instances) [G-06] It's cheaper to declare the variable outside the loop (02 Instances) [G-07] Wastage of deployed gas when return is not present for returns function (06 Instances)
Optimisation runs are should be changed to 1000 instead of 100. This helps in removing unused opcodes which are the main element of gas consumption. The gas of contract deployment will be comparably high but will cost less gas when functions are executed multiple times after deployement.
Link to the Code:
Avoid creating lot of memory variables inside a function as they consume more gas. Instead use calldata, as the incoming arguments will be used just during execution.
Link to the Code: 2. https://github.com/code-423n4/2023-09-ondo/blob/main/contracts/bridge/SourceBridge.sol#L66 3. https://github.com/code-423n4/2023-09-ondo/blob/main/contracts/bridge/SourceBridge.sol#L79 4. https://github.com/code-423n4/2023-09-ondo/blob/main/contracts/bridge/DestinationBridge.sol#L133 5. https://github.com/code-423n4/2023-09-ondo/blob/main/contracts/bridge/DestinationBridge.sol#L135 6. https://github.com/code-423n4/2023-09-ondo/blob/main/contracts/rwaOracles/RWADynamicOracle.sol#L112 7. https://github.com/code-423n4/2023-09-ondo/blob/main/contracts/rwaOracles/RWADynamicOracle.sol#L120 8. https://github.com/code-423n4/2023-09-ondo/blob/main/contracts/rwaOracles/RWADynamicOracle.sol#L130
Condition inside for loop will carry on, unless it finds one condition that is not met, it will revert the whole transaction. It is recommended that instead of reverting if condition is not true, to just break the loop. This way we don't need to run again the transaction.
Link to the Code:
Private over public saves around 21,000 for immutable in gas during deployment. Gas consumption also increases with number of variable created with public visibility for both constant and immutable. Link to the code:
Refer to this link.
Link to the Code:
Declaring a variable inside a loop result in variable being redeclared during each loop iteration which consume higher gas. The variable gets reallocated when declared outside loop making it more gas efficient.
Link to the Code:
Wastage of gas during deployment; when return is absent for named variable when function returns.
Link to the Code:
#0 - c4-pre-sort
2023-09-08T14:34:48Z
raymondfam marked the issue as sufficient quality report
#1 - c4-judge
2023-09-24T06:12:49Z
kirk-baird marked the issue as grade-b