SetProtocol / set-protocol-v2

Set Protocol V2
118 stars 94 forks source link

fix(PerpV2BasisTradingModule): External audit fixes for low-risk findings and Internal audit fixes #232

Closed 0xSachinK closed 2 years ago

0xSachinK commented 2 years ago

External Audit Report

Fixes

Low Risk

Explained: Subtraction underflow when calling deposit

I was not able to recreate the bug even after depositing the entire withdrawn amount for >500 times consecutively. But as bernard pointed out in our chat, he was able to recreate the issue without any withdrawing and just depositing airdropped tokens.

In this script that bernard shared, he

Proposed Solution

Rather than modifying the PositionV2#calculateDefaultEditPositionUnit, we fix the PerpV2LeverageModuleV2#deposit unit to check that the deposit position units is <= current position unit.

Internal Audit Report

All changes added in 90b0276 and 56bfe82.

PerpV2LeverageModuleV2

PerpV2BasisTradingModule

Imports

constructor

initialize(setToken, feeState)

tradeAndTrackFunding

withdrawFundingAndAccrueFees

moduleRedeemHook

updatePerformanceFee

getRedemptionAdjustments

_handleFees

0xSachinK commented 2 years ago

Rebase to master to pull in the latest integration tests merged to master.

cgewecke commented 2 years ago

:tada: This PR is included in version 0.9.2-hhat.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: