Yield Witch v2 contest - ElKu's results

Fixed-rate borrowing and lending on Ethereum

General Information

Platform: Code4rena

Start Date: 14/07/2022

Pot Size: $25,000 USDC

Total HM: 2

Participants: 63

Period: 3 days

Judge: PierrickGT

Total Solo HM: 1

Id: 147

League: ETH

Yield

Findings Distribution

Researcher Performance

Rank: 23/63

Findings: 2

Award: $56.53

🌟 Selected for report: 0

🚀 Solo Findings: 0

Awards

39.0407 USDC - $39.04

Labels

bug
QA (Quality Assurance)

External Links

1) Bidding functions doesn't check if vault is still Undercollateralized

The bidding functions ( payBase and payFYToken ) should check if the vault is still Undercollateralized before proceeding with the Auction.

Currently, the auction can only be cancelled via the cancel function. This external function has to be called manually for checking if the vault is not Undercollateralized and cancel the auction.

Mitigation:

Make the cancel function public and call it from the two bidding functions.

2) Inconsistencies caused by updating Governance variables during an Ongoing Auction

The Governance variables such as lines, limit, auctioneerReward etc.. can be changed during an ongoing Auction. Even though this cannot be misused by a malicious user, it will cause inconsistencies in the calculation of variables like liquidatorCut and auctioneerCut (Calculated in _calcPayout function ).

Mitigation:

Store the line mapping and auctioneerReward in the Auction structure and use it in the bidding functions ( payBase and payFYToken ).

3) Spelling mistakes in natspec comments:

  1. overriden
  2. repayed
  3. overriden
  4. differente
  5. overriden
  6. quoutes hoy

#0 - alcueca

2022-07-22T14:22:50Z

Thanks for the typos, regarding the other suggestions, no thank you.

Rearranging equation to save gas:

  1. Equation uint256 inkAtEnd = uint256(artIn).wdiv(auction_.art).wmul(auction_.ink); can be rearranged as follows. Link
inkAtEnd = uint256(artIn).wdiv(auction_.art).wmul(auction_.ink) = ( ( (artIn * 1e18) / auction_.art ) * auction_.ink ) / 1e18; = (artIn * auction_.ink) / auction_.art;

There is no need to use WMul and Wdiv in this specific case.

So final equation will be:

uint256 inkAtEnd = (artIn * auction_.ink) / auction_.art;

  1. Equation uint256(1e18 - initialProportion).wmul(elapsed.wdiv(duration)) can be rearranged as follows.
uint256(1e18 - initialProportion).wmul(elapsed.wdiv(duration)) = ( uint256(1e18 - initialProportion) * ((elapsed * 1e18) / duration) ) / 1e18 = ( uint256(1e18 - initialProportion) * elapsed) / duration

Since the above multiplication can never overflow we can safely put them in an unchecked block.

So 3 lines of equation here can be re-written as follows:

unchecked { proportionNow = uint256(initialProportion) + ( uint256(1e18 - initialProportion) * elapsed) / duration }

GAS Savings from the above Changes:

Function NameOriginal Cost(A)Optmized Code cost(B)Gas Saved(A-B)
Deployment Cost307639830711905208
calcPayout104209806614
payBase2043119890541
payFYToken1921918678541
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