Mochi contest - gzeon's results

Next-Gen Decentralized Digital Currency Backed By Long-Tail Cryptoassets.

General Information

Platform: Code4rena

Start Date: 21/10/2021

Pot Size: $80,000 ETH

Total HM: 28

Participants: 15

Period: 7 days

Judge: ghoulsol

Total Solo HM: 19

Id: 42

League: ETH

Mochi

Findings Distribution

Researcher Performance

Rank: 6/15

Findings: 6

Award: $6,788.49

🌟 Selected for report: 6

🚀 Solo Findings: 2

Findings Information

🌟 Selected for report: gzeon

Labels

bug
3 (High Risk)
sponsor confirmed

Awards

0.9718 ETH - $4,045.16

External Links

Handle

gzeon

Vulnerability details

Impact

function claimRewardAsMochi in ReferralFeePoolV0.sol did not reduce user reward balance, allowing referrer to claim the same reward repeatedly and thus draining the fee pool.

Proof of Concept

https://github.com/code-423n4/2021-10-mochi/blob/main/projects/mochi-core/contracts/feePool/ReferralFeePoolV0.sol L28-47 did not reduce user reward balance

Tools Used

None

Add the following lines

rewards -= reward[msg.sender]; reward[msg.sender] = 0;

Findings Information

🌟 Selected for report: cmichel

Also found by: gzeon

Labels

bug
duplicate
2 (Med Risk)

Awards

0.1312 ETH - $546.10

External Links

Handle

gzeon

Vulnerability details

Impact

liquidationFactor(.40) < maxCollateralFactor(.45) for AssetClass.Sigma, which would lead to instant liquidation when user try to borrow max cf.

Proof of Concept

https://github.com/code-423n4/2021-10-mochi/blob/main/projects/mochi-core/contracts/profile/MochiProfileV0.sol L123 and L166

Tools Used

None

Make sure maxCollateralFactor > liquidationFactor, either by governance or enforce it in the smart contract.

#0 - r2moon

2021-10-29T16:39:14Z

Findings Information

🌟 Selected for report: loop

Also found by: WatchPug, cmichel, defsec, gzeon, leastwood, nikitastupin, pants

Labels

bug
duplicate
2 (Med Risk)

Awards

0.0174 ETH - $72.55

External Links

Handle

gzeon

Vulnerability details

Impact

ERC20 transfer in function settleLiquidation of DutchAuctionLiquidator.sol is unchecked, which may lead to liquidator unable to receive liquidated collateral since some ERC20 return false instead of revert when transfer fail.

Proof of Concept

https://github.com/code-423n4/2021-10-mochi/blob/main/projects/mochi-core/contracts/liquidator/DutchAuctionLiquidator.sol L107

Tools Used

None

use the checked cheapTransfer in CheapERC20 library

#0 - r2moon

2021-10-27T14:32:09Z

Findings Information

🌟 Selected for report: gzeon

Labels

bug
2 (Med Risk)
sponsor acknowledged

Awards

0.2915 ETH - $1,213.55

External Links

Handle

gzeon

Vulnerability details

Impact

Borrow function in MochiVault will borrow to max cf when trying to borrow > cf instead of revert with ">cf" as specified in the supplied test. The difference in behavior may cause user to borrow at dangerous collateral level, and receive less than the amount requested.

Proof of Concept

https://github.com/code-423n4/2021-10-mochi/blob/main/projects/mochi-core/contracts/vault/MochiVault.sol L229

Tools Used

None

Revert if details[_id].debt + _amount > maxMinted with ">cf"

Findings Information

🌟 Selected for report: loop

Also found by: WatchPug, defsec, gzeon, harleythedog

Labels

bug
duplicate
G (Gas Optimization)

Awards

0.0101 ETH - $41.93

External Links

Handle

gzeon

Vulnerability details

Impact

The uint256 public liquidated in MochiVault.sol is never used.

Proof of Concept

https://github.com/code-423n4/2021-10-mochi/blob/main/projects/mochi-core/contracts/vault/MochiVault.sol L37: uint256 public liquidated;

Tools Used

None

Remove the variable declaration

#0 - r2moon

2021-10-27T14:31:23Z

Findings Information

🌟 Selected for report: gzeon

Also found by: harleythedog

Labels

bug
G (Gas Optimization)
sponsor confirmed

Awards

0.0345 ETH - $143.80

External Links

Handle

gzeon

Vulnerability details

Impact

Some of the require statements in MochiVault.sol can be placed earlier to reduce gas usage on revert

Proof of Concept

https://github.com/code-423n4/2021-10-mochi/blob/main/projects/mochi-core/contracts/vault/MochiVault.sol L226-227: can be placed at the very top of the function to avoid the expensive cssr call L237: can be placed before initialization of increasingDebt

Tools Used

None

Relocate the said require statements

Findings Information

🌟 Selected for report: gzeon

Also found by: pauliax, ye0lde

Labels

bug
G (Gas Optimization)
sponsor confirmed

Awards

0.0207 ETH - $86.28

External Links

Handle

gzeon

Vulnerability details

Impact

Some of the variable can be cached to slightly reduce gas usage

Proof of Concept

https://github.com/code-423n4/2021-10-mochi/blob/main/projects/mochi-core/contracts/vault/MochiVault.sol L158-178: details[_id].status can be cached L181-211: details[_id].collateral can be cached L213-250: details[_id].debt and details[_id].collateral can be cached L254-275: details[_id].debt can be cached

Tools Used

None

Consider caching those variable for read and make sure write back to storage

Findings Information

🌟 Selected for report: gzeon

Labels

bug
G (Gas Optimization)
sponsor confirmed

Awards

0.0768 ETH - $319.56

External Links

Handle

gzeon

Vulnerability details

Impact

Detailed description of the impact of this finding.

Proof of Concept

https://github.com/code-423n4/2021-10-mochi/blob/main/projects/mochi-core/contracts/interfaces/IMochiVault.sol L6-L12: the struct can be reordered into struct Detail { Status status; address referrer; uint256 collateral; uint256 debt; uint256 debtIndex; }

such that status and referrer are put into the same slot, should save ~2000 gas per borrow

Tools Used

None

Reorder the struct as suggested, and modify impacted code at IMochiVault.sol L28-L34 DutchAuctionLiquidator.sol L77

Extra

Realistically, the range of debtIndex (start at 1e18 and increase by fee per year) probably fit in a uint88(11bytes) so you can pack (status(1byte), referrer(20bytes), debtIndex(11bytes)) all in 32 bytes, saving another storage slot.

Findings Information

🌟 Selected for report: gzeon

Labels

bug
G (Gas Optimization)
sponsor confirmed

Awards

0.0768 ETH - $319.56

External Links

Handle

gzeon

Vulnerability details

Impact

Auction struct in DutchAuctionLiquidator.sol can be optimized to reduce 2 storage slot

Proof of Concept

https://github.com/code-423n4/2021-10-mochi/blob/main/projects/mochi-core/contracts/liquidator/DutchAuctionLiquidator.sol L18-L25: the struct can changed into struct Auction { uint256 nftId; address vault; uint48 startedAt; uint48 boughtAt; uint256 collateral; uint256 debt; } startedAt and boughtAt store block numbers, and 2^48 is be enough for a very long time.

Tools Used

None

Change the struct as suggested above, also need to cast whenever startedAt and boughtAt is used.

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