Skip to content

Latest commit

 

History

History
77 lines (61 loc) · 3.8 KB

Spectra.md

File metadata and controls

77 lines (61 loc) · 3.8 KB

Gas Report : Spectra Audit

Executive summary

Spectra is a permissionless interest rate derivatives protocol for DeFi. The protocol allows to split the yield generated by an Interest Bearing Token (IBT) from the principal asset. The IBT is deposited in the protocol and the user receives Principal Tokens (PT) and Yield Tokens (YT) in return. The PT represents the principal asset and the YT represents the yield generated by the IBT. Holders of the yield token for a specific IBT can claim the yield generated by the corresponding deposited IBTs during the time they hold the YT.

Overview

Project Name Spectra
Repository Github
Website Spectra
X(Twitter) 𝕏
Total SLoC 976 over 7 contracts

List of Findings

ID Title
G-01 storeRatesAtExpiry() performs redundant check on ratesAtExpiryStored state variable invoking SLOAD opcode


[G-01] storeRatesAtExpiry() performs redundant check on ratesAtExpiryStored state variable invoking SLOAD opcode

Description:

Whenever we make a function call to storeRatesAtExpiry(), we check beforehand if the value of the variable is false. If it is false, then only we make a call to this function. Having an extra check in the function itself appears to be redundant check, that doesn't make any difference when interacting with the core logic of the contract(s). This redundant check consumes extra gas incurred by reading storage.

 function storeRatesAtExpiry() public override afterExpiry {
        if (ratesAtExpiryStored) {   //performing check once again inside the function
            revert RatesAtExpiryAlreadyStored();
        }
        ratesAtExpiryStored = true;
        // PT rate not rounded up here
        (ptRate, ibtRate) = _getCurrentPTandIBTRates(false);
        emit RatesStoredAtExpiry(ibtRate, ptRate);
    }

Code Snippets:

1._beforeRedeem()

if (block.timestamp >= expiry) {
      if (!ratesAtExpiryStored) {   //check
          storeRatesAtExpiry();
      }
 }
  1. _beforeWithdraw()
if (block.timestamp >= expiry) {
      if (!ratesAtExpiryStored) {    //check
          storeRatesAtExpiry();
      }
 }
  1. _updatePTandIBTRates()
if (block.timestamp >= expiry) {
      if (!ratesAtExpiryStored) {   //check
          storeRatesAtExpiry();
      }
 }

Recommendation:

Either we can remove the check that we are making before calling this function (better), or removing the if statement from the function itself, that checks for the value of the bool variable and reverts if the value of variable is true. This makes sure that, we invoke SLOAD opcode only once based on our use case.