Marginswap contest - pauliax's results

Bringing margin trading to on-chain assets

General Information

Platform: Code4rena

Start Date: 02/04/2021

Pot Size: $50,000 USDC

Total HM: 20

Participants: 5

Period: 6 days

Judge: Zak Cole

Total Solo HM: 19

Id: 3

League: ETH

Marginswap

Findings Distribution

Researcher Performance

Rank: 2/5

Findings: 7

Award: $18,227.61

🌟 Selected for report: 16

🚀 Solo Findings: 5

Findings Information

🌟 Selected for report: pauliax

Labels

bug
3 (High Risk)

Awards

2616.0889 USDC - $2,616.09

External Links

Email address

pauliax6@gmail.com

Handle

paulius.eth

Eth address

0x523B5b2Cc58A818667C22c862930B141f85d49DD

Vulnerability details

It is unclear if the function applyInterest is supposed to return a new balance with the interest applied or only the accrued interest? There are various usages of it, some calls add the return value to the old amount: return bond.amount + applyInterest(bond.amount, cumulativeYield, yieldQuotientFP); and some not:

balanceWithInterest = applyInterest( balance, yA.accumulatorFP, yieldQuotientFP );

Impact

This makes the code misbehave and return the wrong values for the balance and accrued interest.

Recommended mitigation steps

Make it consistent in all cases when calling this function.

#0 - werg

2021-04-08T21:21:44Z

This is correct and has been fixed in the core repo

Findings Information

🌟 Selected for report: pauliax

Labels

bug
3 (High Risk)

Awards

2616.0889 USDC - $2,616.09

External Links

Email address

pauliax6@gmail.com

Handle

paulius.eth

Eth address

0x523B5b2Cc58A818667C22c862930B141f85d49DD

Vulnerability details

function buyBond transfers amount from msg.sender twice: Fund(fund()).depositFor(msg.sender, issuer, amount); ... collectToken(issuer, msg.sender, amount);

Impact

This makes the msg.sender pay twice for the same bond.

Recommended mitigation steps

Charge poor man only once.

Findings Information

🌟 Selected for report: pauliax

Labels

bug
2 (Med Risk)

Awards

784.8267 USDC - $784.83

External Links

Email address

pauliax6@gmail.com

Handle

paulius.eth

Eth address

0x523B5b2Cc58A818667C22c862930B141f85d49DD

Vulnerability details

uint256 public diffMaxMinRuntime; This variable is never set nor updated so it gets a default value of 0.

Impact

diffMaxMinRuntime with 0 value is making the calculations that use it either always return 0 (when multiplying) or fail (when dividing) when calculating bucket indexes or sizes.

Recommended mitigation steps

Set the appropriate value for diffMaxMinRuntime and update it whenever min or max runtime variables change.

Findings Information

🌟 Selected for report: pauliax

Labels

bug
2 (Med Risk)

Awards

784.8267 USDC - $784.83

External Links

Vulnerability details

getPriceFromAMM relies on values returned from getAmountsOut which can be manipulated (e.g. with the large capital or the help of flash loans). The impact is reduced with UPDATE_MIN_PEG_AMOUNT and UPDATE_MAX_PEG_AMOUNT, however, it is not entirely eliminated.

Impact

Email address

pauliax6@gmail.com

Handle

paulius.eth

Eth address

0x523B5b2Cc58A818667C22c862930B141f85d49DD

Recommended mitigation steps

Uniswap v2 recommends using their TWAP oracle: https://uniswap.org/docs/v2/core-concepts/oracles/

Findings Information

🌟 Selected for report: pauliax

Labels

bug
2 (Med Risk)

Awards

784.8267 USDC - $784.83

External Links

Email address

pauliax6@gmail.com

Handle

paulius.eth

Eth address

0x523B5b2Cc58A818667C22c862930B141f85d49DD

Vulnerability details

CrossMarginTrading sets value of liquidationThresholdPercent in the constructor: liquidationThresholdPercent = 110; Isolated margin contracts declare but do not set the value of liquidationThresholdPercent.

Recommended mitigation steps

Set the initial value for the liquidationThresholdPercent in Isolated margin contracts.

Impact

This makes function belowMaintenanceThreshold to always return true unless a value is set via function setLiquidationThresholdPercent. Comments indicate that the value should also be set to 110:

// The following should hold: // holdings / loan >= 1.1 // => holdings >= loan * 1.1

Findings Information

🌟 Selected for report: pauliax

Also found by: s1m0

Labels

bug
1 (Low Risk)

Awards

117.724 USDC - $117.72

External Links

Impact

only admin can call this so highly unlikely to happen yet it would be better if code prevents that.

Recommended mitigation steps

require share to be greater than 0.

Tools used

Email address

pauliax6@gmail.com

Handle

paulius.eth

Eth address

0x523B5b2Cc58A818667C22c862930B141f85d49DD

Vulnerability details

function initTranche should check that the "share" parameter is > 0, otherwise, it may be possible to initialize the same tranche again.

Findings Information

🌟 Selected for report: pauliax

Labels

bug
1 (Low Risk)

Awards

261.6089 USDC - $261.61

External Links

Email address

pauliax6@gmail.com

Handle

paulius.eth

Eth address

0x523B5b2Cc58A818667C22c862930B141f85d49DD

Vulnerability details

Here, the revert message says that the value needs to be at least 1 hour, however, the code allows value only above the 1 hour (> instead of >=): require(runtime > 1 hours, "Min runtime needs to be at least 1 hour");

Impact

no impact on security, just a discrepancy between the check and message.

Recommended mitigation steps

Replace > with >= or update the error message to reflect that.

Findings Information

🌟 Selected for report: pauliax

Labels

bug
1 (Low Risk)

Awards

261.6089 USDC - $261.61

External Links

Email address

pauliax6@gmail.com

Handle

paulius.eth

Eth address

0x523B5b2Cc58A818667C22c862930B141f85d49DD

Vulnerability details

function setLeveragePercent should check that the _leveragePercent >= 100 so that this calculation will not fail later: (leveragePercent - 100)

Impact

This variable can only be set by admin so as long as he sets the appropriate value it should be fine.

Recommended mitigation steps

It is always nice to enforce such things via code. Code is law they say.

#0 - werg

2021-04-09T02:06:52Z

thanks, but in this case that would be governance's job to check

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