This repository has been archived by the owner on Jul 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 465
Revert to old ReentrancyGuard implementation + random cleanup #2101
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b1c2f66
Update variable names in IAssetData
abandeali1 020e760
Add assetProxyId param to AssetProxyExistsError
abandeali1 793e338
Revert to old ReentrancyGuard implementation
abandeali1 1400ceb
Fix Exchange reentrancy tests
abandeali1 71acf2b
Remove hard coded gas limits in all tests
abandeali1 df8419c
Add back comment on isReentrant function
abandeali1 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 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 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 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 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 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 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 |
---|---|---|
|
@@ -44,12 +44,15 @@ contract ReentrancyTester is | |
{} | ||
|
||
/// @dev Calls a public function to check if it is reentrant. | ||
/// Because this function uses the `nonReentrant` modifier, if | ||
/// the function being called is also guarded by the `nonReentrant` modifier, | ||
/// it will revert when it returns. | ||
function isReentrant(bytes calldata fnCallData) | ||
external | ||
nonReentrant | ||
returns (bool isReentrant) | ||
{ | ||
bytes memory callData = abi.encodeWithSelector(this.testReentrantFunction.selector, fnCallData); | ||
(bool didSucceed, bytes memory resultData) = address(this).delegatecall(callData); | ||
(bool didSucceed, bytes memory resultData) = address(this).delegatecall(fnCallData); | ||
if (didSucceed) { | ||
isReentrant = true; | ||
} else { | ||
|
@@ -61,18 +64,36 @@ contract ReentrancyTester is | |
} | ||
} | ||
|
||
/// @dev Calls a public function to check if it is reentrant. | ||
/// Because this function uses the `nonReentrant` modifier, if | ||
/// the function being called is also guarded by the `nonReentrant` modifier, | ||
/// it will revert when it returns. | ||
function testReentrantFunction(bytes calldata fnCallData) | ||
external | ||
nonReentrant | ||
/// @dev Overridden to revert on unsuccessful fillOrder call. | ||
function fillOrderNoThrow( | ||
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 almost feels not worth testing since it's bascially rewriting |
||
LibOrder.Order memory order, | ||
uint256 takerAssetFillAmount, | ||
bytes memory signature | ||
) | ||
public | ||
returns (LibFillResults.FillResults memory fillResults) | ||
{ | ||
address(this).delegatecall(fnCallData); | ||
// ABI encode calldata for `fillOrder` | ||
bytes memory fillOrderCalldata = abi.encodeWithSelector( | ||
IExchangeCore(address(0)).fillOrder.selector, | ||
order, | ||
takerAssetFillAmount, | ||
signature | ||
); | ||
|
||
(bool didSucceed, bytes memory returnData) = address(this).delegatecall(fillOrderCalldata); | ||
if (didSucceed) { | ||
assert(returnData.length == 128); | ||
fillResults = abi.decode(returnData, (LibFillResults.FillResults)); | ||
return fillResults; | ||
} | ||
// Revert and rethrow error if unsuccessful | ||
assembly { | ||
revert(add(returnData, 32), mload(returnData)) | ||
} | ||
} | ||
|
||
/// @dev Overriden to always succeed. | ||
/// @dev Overridden to always succeed. | ||
function _fillOrder( | ||
LibOrder.Order memory order, | ||
uint256 takerAssetFillAmount, | ||
|
@@ -87,7 +108,7 @@ contract ReentrancyTester is | |
fillResults.takerFeePaid = order.takerFee; | ||
} | ||
|
||
/// @dev Overriden to always succeed. | ||
/// @dev Overridden to always succeed. | ||
function _fillOrKillOrder( | ||
LibOrder.Order memory order, | ||
uint256 takerAssetFillAmount, | ||
|
@@ -114,7 +135,7 @@ contract ReentrancyTester is | |
return resultData; | ||
} | ||
|
||
/// @dev Overriden to always succeed. | ||
/// @dev Overridden to always succeed. | ||
function _batchMatchOrders( | ||
LibOrder.Order[] memory leftOrders, | ||
LibOrder.Order[] memory rightOrders, | ||
|
@@ -144,7 +165,7 @@ contract ReentrancyTester is | |
} | ||
} | ||
|
||
/// @dev Overriden to always succeed. | ||
/// @dev Overridden to always succeed. | ||
function _matchOrders( | ||
LibOrder.Order memory leftOrder, | ||
LibOrder.Order memory rightOrder, | ||
|
@@ -169,7 +190,7 @@ contract ReentrancyTester is | |
}); | ||
} | ||
|
||
/// @dev Overriden to do nothing. | ||
/// @dev Overridden to do nothing. | ||
function _cancelOrder(LibOrder.Order memory order) | ||
internal | ||
{} | ||
|
This file contains 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 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 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 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
Oops, something went wrong.
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.
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.
Let's move this comment up to
isReentrant
now that it has thenonReentrant
modifier