origin-dollar icon indicating copy to clipboard operation
origin-dollar copied to clipboard

Removed drift check from Oracle Router and gas optimizations

Open naddison36 opened this issue 2 years ago • 4 comments

Changes

  • Removed the drift checks from the OracleRouter. Note the OETHOracleRouter does not do drift checks as its already done in the OETHVault.
  • Removed read of Oracle decimals from storage which saves close to 2k gas for stETH, rETH and frxETH. There is a slight increase in gas for WETH as it was not reading the Oracle decimals from storage.

Gas Testing

Before upgrade of OETHOracleRouter

|  Contract           ·  Method              ·  Min        ·  Max        ·  Avg        ·  # calls      ·  eur (avg)  │
······················|······················|·············|·············|·············|···············|··············
|  OETHOracleRouter   ·  price               ·      21935  ·      43431  ·      36034  ·            4  ·          -  │

WETH before

|  OETHOracleRouter   ·  price               ·          -  ·          -  ·      21935  ·            1  ·          -  │

stETH before

|  OETHOracleRouter   ·  price               ·          -  ·          -  ·      43387  ·            1  ·          -  │

After change

|  Contract           ·  Method              ·  Min        ·  Max        ·  Avg        ·  # calls      ·  eur (avg)  │
······················|······················|·············|·············|·············|···············|··············
|  OETHOracleRouter   ·  price               ·      21974  ·      41214  ·      34381  ·            4  ·          -  │

WETH after

|  OETHOracleRouter   ·  price               ·          -  ·          -  ·      21974  ·            1  ·          -  │

stETH after

|  OETHOracleRouter   ·  price               ·          -  ·          -  ·      41170  ·            1  ·          -  │

Review

If you made a contract change, make sure to complete the checklist below before merging it in master.

Refer to our documentation for more details about contract security best practices.

Contract change checklist:

  • [ ] Code reviewed by 2 reviewers.
  • [ ] Copy & paste code review security checklist below this checklist.
  • [ ] Unit tests pass
  • [ ] Slither tests pass with no warning
  • [ ] Echidna tests pass if PR includes changes to OUSD contract (not automated, run manually on local)

naddison36 avatar Nov 27 '23 10:11 naddison36

Warnings
:warning: :eyes: This PR needs at least 2 reviewers

Generated by :no_entry_sign: dangerJS against 4bdf8224d9e8880b62370637891f7d0e8f1e1daf

github-actions[bot] avatar Nov 27 '23 10:11 github-actions[bot]

Seems like a great idea.

Might be good to write some kind of test (even if a one off script) that verifies that the answers are the same before and after the upgraded.

DanielVF avatar Nov 27 '23 12:11 DanielVF

Seems like a great idea.

Might be good to write some kind of test (even if a one off script) that verifies that the answers are the same before and after the upgraded.

I added isDecimalsValid to the OracleRouter that validates the decimals returned from feedMetadata matches the decimals returned from the Oracle feed AggregatorV3Interface(_feed).decimals(). I check isDecimalsValid is true as part of the deploy script and have added checks to the fork tests.

naddison36 avatar Nov 27 '23 12:11 naddison36

There is another issue with these changes. The currently implemented floorPrice of the VaultCore doesn't do any of its own checks of Oracle drift. The potential issue with the current implementation is that 1 underlying asset could de-peg: e.g. rEth to 0.2 worth of ETH, and an Oracle of another asset could be manipulated to return 1.8 ETH still totaling a floorPrice at 1. While in the current master a drift check at the 1.8 ETH price would fail since it exceedes the 1.3 ETH of maximum drift and prevent such situation.

We should probably utilize the _toUnitPrice by calling _toUnitPrice(asset, true) though that function might need changing since we don't want it to perform the require(price >= MINT_MINIMUM_UNIT_PRICE, "Asset price below peg"); part of the check.

sparrowDom avatar Nov 28 '23 22:11 sparrowDom