- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1
[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
          
     Open
      
      
            cwsnt
  wants to merge
  10
  commits into
  development
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
sov-4416-apply-reentrancy-guard-zero
  
      
      
   
  
    
  
  
  
 
  
      
    base: development
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +223
        
        
          −4
        
        
          
        
      
    
  
  
     Open
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            10 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      c9079ce
              
                feat: introduce reentrancy zero
              
              
                 be677f9
              
                fix: test case
              
              
                 55c2b84
              
                consider the recovery mode only for the reentrancy
              
              
                 8a3e4f5
              
                move the mutex check to borrowerOperation only
              
              
                 8749bf1
              
                fixing problems of installation as remote dependency
              
              
                 bd697a6
              
                1/ address comment
              
              
                 9c5e883
              
                merge with latest development branch & fix conflict
              
              
                 8b70023
              
                fixing problems of installation as remote dependency
              
              
                 87907c7
              
                fix: unit test
              
              
                 a55672a
              
                add unit test
              
              
                 File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            89 changes: 89 additions & 0 deletions
          
          89 
        
  contracts/TestContracts/BorrowerOperationsCrossReentrancy.sol
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity 0.6.11; | ||
|  | ||
| import "../Interfaces/IBorrowerOperations.sol"; | ||
| import "hardhat/console.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); | ||
| } | ||
|  | ||
| /** | ||
| * @dev open trove and decrease the debt in the same block should revert due to reentrancy | ||
| */ | ||
| 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); | ||
| } | ||
|  | ||
| /** | ||
| * @dev increase the debt, then decrease the debt in the same block should revert due to reentrancy | ||
| * @dev the trove will be opened in the past block | ||
| */ | ||
| function testCrossReentrancyByIncreasingDebt( | ||
| uint256 _maxFeePercentage, | ||
| uint256 _ZUSDAmount, | ||
| address _upperHint, | ||
| address _lowerHint, | ||
| address _priceFeed | ||
| ) public payable { | ||
| // manipulate the price so that the recovery mode will be triggered | ||
| IPriceFeedTestnet(_priceFeed).setPrice(1e17); | ||
| // add coll to the trove so that the TCR will be above CCR | ||
| borrowerOperations.addColl{value: msg.value}(_upperHint, _lowerHint); | ||
|  | ||
| // withdraw ZUSD to increase the debt | ||
| borrowerOperations.withdrawZUSD(_maxFeePercentage, _ZUSDAmount, _upperHint, _lowerHint); | ||
|  | ||
| // repayZusd will affect(decrease) the debt, should revert due to reentrancy violation | ||
| borrowerOperations.repayZUSD(_ZUSDAmount, _upperHint, _lowerHint); | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.
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.
this test covers only one case:
open trove - repay debt.but is missing
increase debt - repay.and
open trove - increase debt - repay debtThere 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.
added unit test in this commit