J_11 cache storage value to stack or memory [gas optimization]
usgeeus opened this issue · 2 comments
usgeeus commented
Configuration
- severity : low
- confidence : medium
Lines of Codes
L2FastWithdraw.sol:cancelFW
L2FastWithdraw.sol:claimFW
... etc...
Description
Caching storage value to stack or memory saves gas
Demo
example of cancelFW
function cancelFW(
address _msgSender,
uint256 _salecount
)
external
payable
checkL1
providerCheck(_salecount)
{
require(dealData[_salecount].requester == _msgSender, "your not seller");
dealData[_salecount].provider = _msgSender;
uint256 totalAmount = dealData[_salecount].totalAmount;
if (dealData[_salecount].l2token == legacyERC20ETH) {
(bool sent, ) = payable(_msgSender).call{value: totalAmount}("");
require(sent, "cancel refund fail");
} else {
IERC20(dealData[_salecount].l2token).transfer(_msgSender,totalAmount);
}
emit CancelFW(
_msgSender,
totalAmount,
_salecount
);
}
example of claimFW
function claimFW(
address _from,
uint256 _amount,
uint256 _saleCount,
bytes32 _hash
)
external
payable
checkL1
providerCheck(_saleCount)
{
require(dealData[_saleCount].hashValue == _hash, "Hash values do not match");
require(dealData[_saleCount].fwAmount == _amount, "not match the fwAmount");
// require(dealData[_saleCount].requester == _to, "not match the seller");
// require(dealData[_saleCount].l1token == _l1token, "need same l1token");
// chainID = _getChainID();
dealData[_saleCount].provider = _from;
address l2token = dealData[_saleCount].l2token;
uint256 totalAmount = dealData[_saleCount].totalAmount;
if(l2token == legacyERC20ETH) {
(bool sent, ) = payable(_from).call{value: totalAmount}("");
require(sent, "claim fail");
} else {
IERC20(l2token).transfer(_from,totalAmount);
}
emit ProviderClaimFW(
dealData[_saleCount].l1token,
l2token,
dealData[_saleCount].requester,
_from,
totalAmount,
_amount,
_saleCount
);
}
usgeeus commented
Solved, closing this issue. We'll see if we can do this with other functions in the second audit.