-
Notifications
You must be signed in to change notification settings - Fork 1
Gas optimization #6
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: main
Are you sure you want to change the base?
Changes from all commits
9dfb3ef
4fe8c0c
0656d67
40a079c
41da6b6
47c121b
fadaf1a
9aeda15
e0f3423
7e09d66
03b74b3
2885f4b
a9f95d0
9376d32
6b9a6ed
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 |
|---|---|---|
|
|
@@ -25,56 +25,53 @@ contract GrtOffer is GrtOfferUtils { | |
| ); | ||
| event LogSetStatusOffer(bytes32 indexed _idOffer, bool indexed _isActive); | ||
|
|
||
| function setChainIdOffer(bytes32 offerId, uint256 chainId) external { | ||
| modifier isOwner(Offer memory offer) { | ||
| require( | ||
| msg.sender == _offers[offerId].user, | ||
| msg.sender == offer.user, | ||
| "Grindery offer: you are not allowed to modify this offer." | ||
| ); | ||
| _offers[offerId].chainId = chainId; | ||
| _; | ||
| } | ||
|
|
||
| function setChainIdOffer(bytes32 offerId, uint256 chainId) external isOwner(_offers[offerId]) { | ||
| Offer storage offer = _offers[offerId]; | ||
| offer.chainId = chainId; | ||
| emit LogSetChainIdOffer(offerId, chainId); | ||
| } | ||
|
|
||
| function setTokenOffer(bytes32 offerId, address token) external { | ||
| function setTokenOffer(bytes32 offerId, address token) external isOwner(_offers[offerId]) { | ||
| require( | ||
|
Collaborator
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. @juniormp If we have the |
||
| msg.sender == _offers[offerId].user, | ||
| "Grindery offer: you are not allowed to modify this offer." | ||
| ); | ||
| _offers[offerId].token = token; | ||
| Offer storage offer = _offers[offerId]; | ||
| offer.token = token; | ||
| emit LogSetTokenOffer(offerId, token); | ||
| } | ||
|
|
||
| function setMinPriceLimit( | ||
| bytes32 offerId, | ||
| bytes calldata minPriceLimit | ||
| ) external { | ||
| require( | ||
| msg.sender == _offers[offerId].user, | ||
| "Grindery offer: you are not allowed to modify this offer." | ||
| ); | ||
| ) external isOwner(_offers[offerId]) { | ||
| Offer storage offer = _offers[offerId]; | ||
| bytes32 priceLimit = keccak256(abi.encodePacked(minPriceLimit)); | ||
| _offers[offerId].minPriceLimit = priceLimit; | ||
| offer.minPriceLimit = priceLimit; | ||
| emit LogSetMinPriceLimit(offerId, priceLimit); | ||
| } | ||
|
|
||
| function setMaxPriceLimit( | ||
| bytes32 offerId, | ||
| bytes calldata maxPriceLimit | ||
| ) external { | ||
| require( | ||
| msg.sender == _offers[offerId].user, | ||
| "Grindery offer: you are not allowed to modify this offer." | ||
| ); | ||
| ) external isOwner(_offers[offerId]) { | ||
| Offer storage offer = _offers[offerId]; | ||
| bytes32 priceLimit = keccak256(abi.encodePacked(maxPriceLimit)); | ||
| _offers[offerId].maxPriceLimit = priceLimit; | ||
| offer.maxPriceLimit = priceLimit; | ||
| emit LogSetMaxPriceLimit(offerId, priceLimit); | ||
| } | ||
|
|
||
| function setIsActive(bytes32 offerId, bool isActive) external { | ||
| require( | ||
| msg.sender == _offers[offerId].user, | ||
| "Grindery offer: you are not allowed to modify this offer." | ||
| ); | ||
| _offers[offerId].isActive = isActive; | ||
| function setIsActive(bytes32 offerId, bool isActive) external isOwner(_offers[offerId]) { | ||
| Offer storage offer = _offers[offerId]; | ||
| offer.isActive = isActive; | ||
| emit LogSetStatusOffer(offerId, isActive); | ||
| } | ||
|
|
||
|
|
@@ -91,14 +88,15 @@ contract GrtOffer is GrtOfferUtils { | |
| bytes32 offerId = keccak256( | ||
| abi.encodePacked(msg.sender, _noncesOffer[msg.sender]) | ||
| ); | ||
| _offers[offerId].user = msg.sender; | ||
| _offers[offerId].isActive = true; | ||
| _offers[offerId].chainId = chainId; | ||
| _offers[offerId].token = token; | ||
| _offers[offerId].minPriceLimit = keccak256( | ||
| Offer storage offer = _offers[offerId]; | ||
| offer.user = msg.sender; | ||
| offer.isActive = true; | ||
| offer.chainId = chainId; | ||
| offer.token = token; | ||
| offer.minPriceLimit = keccak256( | ||
| abi.encodePacked(minPriceLimit) | ||
| ); | ||
| _offers[offerId].maxPriceLimit = keccak256( | ||
| offer.maxPriceLimit = keccak256( | ||
| abi.encodePacked(maxPriceLimit) | ||
| ); | ||
| emit LogNewOffer(offerId, token, chainId); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,8 +36,6 @@ contract GrtPool is OwnableUpgradeable, GrtOffer, UUPSUpgradeable { | |
|
|
||
| function _authorizeUpgrade(address) internal override onlyOwner onlyProxy {} | ||
|
|
||
| receive() external payable {} | ||
|
|
||
| function depositETHAndAcceptOffer( | ||
| bytes32 offerId, | ||
| address destAddr | ||
|
|
@@ -54,7 +52,6 @@ contract GrtPool is OwnableUpgradeable, GrtOffer, UUPSUpgradeable { | |
| _offers[offerId].isActive, | ||
| "Grindery Pool: the offer is inactive." | ||
| ); | ||
|
|
||
| (bool sent, ) = address(this).call{value: msg.value}(""); | ||
|
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. Maybe we can move this call to the bottom of the function to protect against reentrancy ?
Collaborator
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. @juniormp I understand your point here but I don't think it applies in this case. You point to the fact that an attacker could call this function recursively and since the rest of the calculations would not yet be finished, he could then call the function ten times.
@SAPikachu Maybe you have a better opinion here? |
||
| require(sent, "Grindery Pool: failed to send native tokens."); | ||
| bytes32 tradeId = keccak256( | ||
|
|
@@ -63,7 +60,7 @@ contract GrtPool is OwnableUpgradeable, GrtOffer, UUPSUpgradeable { | |
| Trade storage trade = _trades[tradeId]; | ||
| trade.userAddr = msg.sender; | ||
| trade.destAddr = destAddr; | ||
| trade.deposit = setTokenInfo(address(0), msg.value, block.chainid); | ||
| trade.deposit = TokenInfo(address(0), msg.value, block.chainid); | ||
| trade.offerId = offerId; | ||
| _noncesDeposit[msg.sender]++; | ||
| emit LogTrade(tradeId, address(0), msg.value, offerId); | ||
|
|
@@ -100,11 +97,5 @@ contract GrtPool is OwnableUpgradeable, GrtOffer, UUPSUpgradeable { | |
| return _trades[tradeId].deposit.chainId; | ||
| } | ||
|
|
||
| function setTokenInfo( | ||
| address token, | ||
| uint256 amount, | ||
| uint256 chainId | ||
| ) internal pure returns (TokenInfo memory) { | ||
| return TokenInfo(token, amount, chainId); | ||
| } | ||
| receive() external payable {} | ||
| } | ||
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.
@juniormp A comment for detail but can you just change the name of this function to make it more explicit?
Owneris already associated with a condition of the contractownableand so this can be confusing when reading :)