-
Notifications
You must be signed in to change notification settings - Fork 2
[SOV-4416] apply reentrancy guard zero #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from 9 commits
c9079ce
be677f9
55c2b84
8a3e4f5
8749bf1
bd697a6
9c5e883
8b70023
87907c7
a55672a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -36,4 +36,9 @@ contract BorrowerOperationsStorage is Ownable { | |||||||||||||||||||||
|
|
||||||||||||||||||||||
| IMassetManager public massetManager; | ||||||||||||||||||||||
| IFeeDistributor public feeDistributor; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| /* | ||||||||||||||||||||||
| * Store the LoC block number on open/increase when in the Recovery mode | ||||||||||||||||||||||
| */ | ||||||||||||||||||||||
| mapping(address => uint256) public recoveryModeMutex; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+40
to
44
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.6.11; | ||
|
|
||
| import "../Interfaces/IBorrowerOperations.sol"; | ||
|
|
||
| interface IPriceFeedTestnet { | ||
| function setPrice(uint256 price) external returns (bool); | ||
| } | ||
|
|
||
| contract BorrowerOperationsCrossReentrancy { | ||
| IBorrowerOperations public borrowerOperations; | ||
|
|
||
| constructor( | ||
| IBorrowerOperations _borrowerOperations | ||
| ) public { | ||
| borrowerOperations = _borrowerOperations; | ||
| } | ||
|
|
||
| fallback() external payable {} | ||
|
|
||
| function testCrossReentrancyWithoutAffectingDebt( | ||
| uint256 _maxFeePercentage, | ||
| uint256 _ZUSDAmount, | ||
| address _upperHint, | ||
| address _lowerHint, | ||
| address _priceFeed | ||
| ) public payable { | ||
| borrowerOperations.openTrove{value: msg.value / 2}( | ||
| _maxFeePercentage, | ||
| _ZUSDAmount, | ||
| _upperHint, | ||
| _lowerHint | ||
| ); | ||
|
|
||
| // manipulate the price so that the recovery mode will be triggered | ||
| IPriceFeedTestnet(_priceFeed).setPrice(1e8); | ||
|
|
||
| // // should not revert because it's not affecting the debt | ||
| borrowerOperations.addColl{value: msg.value / 2}(_upperHint, _lowerHint); | ||
| } | ||
|
|
||
| function testCrossReentrancyAffectingDebt( | ||
| uint256 _maxFeePercentage, | ||
| uint256 _ZUSDAmount, | ||
| address _upperHint, | ||
| address _lowerHint, | ||
| address _priceFeed | ||
| ) public payable { | ||
| borrowerOperations.openTrove{value: msg.value}( | ||
| _maxFeePercentage, | ||
| _ZUSDAmount, | ||
| _upperHint, | ||
| _lowerHint | ||
| ); | ||
|
|
||
| // manipulate the price so that the recovery mode will be triggered | ||
| IPriceFeedTestnet(_priceFeed).setPrice(1e8); | ||
|
|
||
| // repayZusd will affect(decrease) the debt, should revert due to reentrancy violation | ||
| borrowerOperations.repayZUSD(_ZUSDAmount, _upperHint, _lowerHint); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test covers only one case:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added unit test in this commit |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated