Skip to content

Commit 8a3e4f5

Browse files
author
cwsnt
committed
move the mutex check to borrowerOperation only
1 parent 55c2b84 commit 8a3e4f5

13 files changed

Lines changed: 27 additions & 376 deletions

contracts/BorrowerOperations.sol

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// SPDX-License-Identifier: MIT
2-
32
pragma solidity 0.6.11;
43
pragma experimental ABIEncoderV2;
54

@@ -16,14 +15,12 @@ import "./Dependencies/console.sol";
1615
import "./BorrowerOperationsStorage.sol";
1716
import "./Dependencies/Mynt/MyntLib.sol";
1817
import "./Interfaces/IPermit2.sol";
19-
import "./Dependencies/reentrancy/SharedReentrancyGuard.sol";
2018

2119
contract BorrowerOperations is
2220
LiquityBase,
2321
BorrowerOperationsStorage,
2422
CheckContract,
25-
IBorrowerOperations,
26-
SharedReentrancyGuard
23+
IBorrowerOperations
2724
{
2825
/** CONSTANT / IMMUTABLE VARIABLE ONLY */
2926
IPermit2 public immutable permit2;
@@ -161,6 +158,25 @@ contract BorrowerOperations is
161158
emit ZEROStakingAddressChanged(_zeroStakingAddress);
162159
}
163160

161+
/*
162+
* @notice set the user's block number for opening, and do check & reset to 0 for closing
163+
*
164+
* @dev This is the function will be called by the open, close, increase, decrease trove function
165+
*/
166+
function notInTheSameBlockHandler(bool _isOpening) private {
167+
if(_isOpening) {
168+
userBlockNumber[tx.origin] = block.number;
169+
} else {
170+
if(userBlockNumber[tx.origin] > 0) {
171+
if(userBlockNumber[tx.origin] == block.number) {
172+
revert("ZeroProtocolMutex: mutex locked");
173+
}
174+
175+
userBlockNumber[tx.origin] = 0;
176+
}
177+
}
178+
}
179+
164180
function setMassetManagerAddress(address _massetManagerAddress) external onlyOwner {
165181
massetManager = IMassetManager(_massetManagerAddress);
166182
emit MassetManagerAddressChanged(_massetManagerAddress);
@@ -205,7 +221,7 @@ contract BorrowerOperations is
205221
vars.price = priceFeed.fetchPrice();
206222
bool isRecoveryMode = _checkRecoveryMode(vars.price);
207223

208-
if(isRecoveryMode) nonReentrantCheck(true);
224+
if(isRecoveryMode) notInTheSameBlockHandler(true);
209225

210226
_requireValidMaxFeePercentage(_maxFeePercentage, isRecoveryMode);
211227
_requireTroveisNotActive(contractsCache.troveManager, msg.sender);
@@ -590,7 +606,7 @@ contract BorrowerOperations is
590606
vars.isRecoveryMode = _checkRecoveryMode(vars.price);
591607

592608
if(vars.isRecoveryMode) {
593-
nonReentrantCheck(_isDebtIncrease);
609+
notInTheSameBlockHandler(_isDebtIncrease);
594610
}
595611

596612
if (_isDebtIncrease) {

contracts/BorrowerOperationsStorage.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,9 @@ contract BorrowerOperationsStorage is Ownable {
3636

3737
IMassetManager public massetManager;
3838
IFeeDistributor public feeDistributor;
39+
40+
/*
41+
* to store the user's block number
42+
*/
43+
mapping(address => uint256) public userBlockNumber;
3944
}

contracts/Dependencies/reentrancy/SharedReentrancyGuard.sol

Lines changed: 0 additions & 38 deletions
This file was deleted.

contracts/Dependencies/reentrancy/ZeroProtocolMutex.sol

Lines changed: 0 additions & 33 deletions
This file was deleted.

contracts/Interfaces/IZeroProtocolMutex.sol

Lines changed: 0 additions & 6 deletions
This file was deleted.

contracts/TestContracts/TestNonReentrantValueSetter.sol

Lines changed: 0 additions & 27 deletions
This file was deleted.

contracts/TestContracts/TestValueSetter.sol

Lines changed: 0 additions & 14 deletions
This file was deleted.

contracts/TestContracts/TestValueSetterProxy.sol

Lines changed: 0 additions & 9 deletions
This file was deleted.

deployment/deploy/7-DeployZeroProtocolMutex.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

deployment/helpers/reentrancy/utils.js

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)