-
Notifications
You must be signed in to change notification settings - Fork 14
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
Contracts minor audit by 0xHattoriHanzo #24
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -63,6 +63,9 @@ contract Distribution is IDistribution, OwnableUpgradeable, UUPSUpgradeable { | |
createPool(poolsInfo_[i]); | ||
} | ||
|
||
require(depositToken_ != address(0), "DS: invalid depositToken_ value"); | ||
require(l1Sender_ != address(0), "DS: invalid l1Sender_ value"); | ||
|
||
depositToken = depositToken_; | ||
l1Sender = l1Sender_; | ||
} | ||
|
@@ -172,10 +175,10 @@ contract Distribution is IDistribution, OwnableUpgradeable, UUPSUpgradeable { | |
userData.rate = currentPoolRate_; | ||
userData.pendingRewards = 0; | ||
|
||
emit UserClaimed(poolId_, user_, receiver_, pendingRewards_); | ||
|
||
// Transfer rewards | ||
L1Sender(l1Sender).sendMintMessage{value: msg.value}(receiver_, pendingRewards_, user_); | ||
|
||
emit UserClaimed(poolId_, user_, receiver_, pendingRewards_); | ||
} | ||
|
||
function withdraw(uint256 poolId_, uint256 amount_) external poolExists(poolId_) poolPublic(poolId_) { | ||
|
@@ -257,7 +260,7 @@ contract Distribution is IDistribution, OwnableUpgradeable, UUPSUpgradeable { | |
newDeposited_ = deposited_ - amount_; | ||
|
||
require(amount_ > 0, "DS: nothing to withdraw"); | ||
require(newDeposited_ >= pool.minimalStake || newDeposited_ == 0, "DS: invalid withdraw amount"); | ||
require(newDeposited_ >= pool.minimalStake || newDeposited_ <= 0, "DS: invalid withdraw amount"); | ||
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.
|
||
} else { | ||
newDeposited_ = deposited_ - amount_; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,7 @@ contract L1Sender is IL1Sender, OwnableUpgradeable, UUPSUpgradeable { | |
} | ||
|
||
function setDistribution(address distribution_) public onlyOwner { | ||
require(distribution_ != address(0), "L1S: invalid distribution"); | ||
distribution = distribution_; | ||
} | ||
|
||
|
@@ -56,27 +57,27 @@ contract L1Sender is IL1Sender, OwnableUpgradeable, UUPSUpgradeable { | |
function setDepositTokenConfig(DepositTokenConfig calldata newConfig_) public onlyOwner { | ||
require(newConfig_.receiver != address(0), "L1S: invalid receiver"); | ||
|
||
DepositTokenConfig storage oldConfig = depositTokenConfig; | ||
DepositTokenConfig memory oldConfig = depositTokenConfig; | ||
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. Why you replace storage -> memory? We don't use |
||
|
||
depositTokenConfig = newConfig_; | ||
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. Why you change storage here? |
||
|
||
_replaceDepositToken(oldConfig.token, newConfig_.token); | ||
_replaceDepositTokenGateway(oldConfig.gateway, newConfig_.gateway, oldConfig.token, newConfig_.token); | ||
|
||
depositTokenConfig = newConfig_; | ||
} | ||
|
||
function _replaceDepositToken(address oldToken_, address newToken_) private { | ||
bool isTokenChanged_ = oldToken_ != newToken_; | ||
|
||
if (oldToken_ != address(0) && isTokenChanged_) { | ||
// Remove allowance from stETH to wstETH | ||
IERC20(unwrappedDepositToken).approve(oldToken_, 0); | ||
require(IERC20(unwrappedDepositToken).approve(oldToken_, 0), "L1S: remove old token allowance failed"); | ||
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. Could you add a test that throws this exception? I'd love to see it. |
||
} | ||
|
||
if (isTokenChanged_) { | ||
// Get stETH from wstETH | ||
address unwrappedToken_ = IWStETH(newToken_).stETH(); | ||
// Increase allowance from stETH to wstETH. To exchange stETH for wstETH | ||
IERC20(unwrappedToken_).approve(newToken_, type(uint256).max); | ||
require(IERC20(unwrappedToken_).approve(newToken_, type(uint256).max), "L1S: new token allowance failed"); | ||
|
||
unwrappedDepositToken = unwrappedToken_; | ||
} | ||
|
@@ -91,11 +92,17 @@ contract L1Sender is IL1Sender, OwnableUpgradeable, UUPSUpgradeable { | |
bool isAllowedChanged_ = (oldToken_ != newToken_) || (oldGateway_ != newGateway_); | ||
|
||
if (oldGateway_ != address(0) && isAllowedChanged_) { | ||
IERC20(oldToken_).approve(IGatewayRouter(oldGateway_).getGateway(oldToken_), 0); | ||
require( | ||
IERC20(oldToken_).approve(IGatewayRouter(oldGateway_).getGateway(oldToken_), 0), | ||
"L1S: remove old gateway allowance failed" | ||
); | ||
} | ||
|
||
if (isAllowedChanged_) { | ||
IERC20(newToken_).approve(IGatewayRouter(newGateway_).getGateway(newToken_), type(uint256).max); | ||
require( | ||
IERC20(newToken_).approve(IGatewayRouter(newGateway_).getGateway(newToken_), type(uint256).max), | ||
"L1S: new gateway allowance failed" | ||
); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ contract L2MessageReceiver is IL2MessageReceiver, OwnableUpgradeable, UUPSUpgrad | |
} | ||
|
||
function setParams(address rewardToken_, Config calldata config_) external onlyOwner { | ||
require(rewardToken_ != address(0), "L2MR: invalid reward token"); | ||
rewardToken = rewardToken_; | ||
config = config_; | ||
} | ||
|
@@ -59,11 +60,11 @@ contract L2MessageReceiver is IL2MessageReceiver, OwnableUpgradeable, UUPSUpgrad | |
require(payloadHash_ != bytes32(0), "L2MR: no stored message"); | ||
require(keccak256(payload_) == payloadHash_, "L2MR: invalid payload"); | ||
|
||
_nonblockingLzReceive(senderChainId_, senderAndReceiverAddresses_, payload_); | ||
|
||
delete failedMessages[senderChainId_][senderAndReceiverAddresses_][nonce_]; | ||
|
||
emit RetryMessageSuccess(senderChainId_, senderAndReceiverAddresses_, nonce_, payload_); | ||
|
||
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. The same here, why we mint tokens before clearing failed message storage? |
||
_nonblockingLzReceive(senderChainId_, senderAndReceiverAddresses_, payload_); | ||
} | ||
|
||
function _blockingLzReceive( | ||
|
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.
What is the purpose of replacing the emit location?