-
Notifications
You must be signed in to change notification settings - Fork 75
improve: [L02] validate function inputs #91
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
728d009
improve: validate function inputs
nicholaspai f0fa065
Update Polygon_SpokePool.sol
nicholaspai f89200b
add validation for setProtocolFeeCapture and spokePool address
nicholaspai 4fe9607
remove noActiveRequests from setProtocolFeeCapture
nicholaspai 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,6 @@ import "./MerkleLib.sol"; | |
| import "./HubPoolInterface.sol"; | ||
| import "./Lockable.sol"; | ||
|
|
||
| import "./interfaces/AdapterInterface.sol"; | ||
| import "./interfaces/LpTokenFactoryInterface.sol"; | ||
| import "./interfaces/WETH9.sol"; | ||
|
|
||
|
|
@@ -99,7 +98,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { | |
|
|
||
| // Heler contracts to facilitate cross chain actions between HubPool and SpokePool for a specific network. | ||
| struct CrossChainContract { | ||
| AdapterInterface adapter; | ||
| address adapter; | ||
| address spokePool; | ||
| } | ||
| // Mapping of chainId to the associated adapter and spokePool contracts. | ||
|
|
@@ -301,6 +300,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { | |
| onlyOwner | ||
| { | ||
| require(newProtocolFeeCapturePct <= 1e18, "Bad protocolFeeCapturePct"); | ||
| require(newProtocolFeeCaptureAddress != address(0), "Bad protocolFeeCaptureAddress"); | ||
| protocolFeeCaptureAddress = newProtocolFeeCaptureAddress; | ||
| protocolFeeCapturePct = newProtocolFeeCapturePct; | ||
| emit ProtocolFeeCaptureSet(newProtocolFeeCaptureAddress, newProtocolFeeCapturePct); | ||
|
|
@@ -365,7 +365,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { | |
| address adapter, | ||
| address spokePool | ||
| ) public override onlyOwner { | ||
| crossChainContracts[l2ChainId] = CrossChainContract(AdapterInterface(adapter), spokePool); | ||
| crossChainContracts[l2ChainId] = CrossChainContract(adapter, spokePool); | ||
| emit CrossChainContractsSet(l2ChainId, adapter, spokePool); | ||
| } | ||
|
|
||
|
|
@@ -632,9 +632,6 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { | |
| "Bad Proof" | ||
| ); | ||
|
|
||
| // Before interacting with a particular chain's adapter, ensure that the adapter is set. | ||
| require(address(crossChainContracts[chainId].adapter) != address(0), "No adapter for chain"); | ||
|
|
||
| // Make sure SpokePool address is initialized since _sendTokensToChainAndUpdatePooledTokenTrackers() will not | ||
| // revert if its accidentally set to address(0). We don't make the same check on the adapter for this | ||
| // chainId because the internal method's delegatecall() to the adapter will revert if its address is set | ||
|
|
@@ -648,8 +645,33 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { | |
| // Decrement the unclaimedPoolRebalanceLeafCount. | ||
| rootBundleProposal.unclaimedPoolRebalanceLeafCount--; | ||
|
|
||
| _sendTokensToChainAndUpdatePooledTokenTrackers(spokePool, chainId, l1Tokens, netSendAmounts, bundleLpFees); | ||
| _relayRootBundleToSpokePool(spokePool, chainId); | ||
| // Relay each L1 token to destination chain. | ||
| // Note: We don't check that the adapter is initialized since if its the zero address or invalid otherwise, | ||
| // then the delegate call should revert. | ||
| address adapter = crossChainContracts[chainId].adapter; | ||
| _sendTokensToChainAndUpdatePooledTokenTrackers( | ||
| adapter, | ||
| spokePool, | ||
| chainId, | ||
| l1Tokens, | ||
| netSendAmounts, | ||
| bundleLpFees | ||
| ); | ||
|
|
||
| // Relay root bundles to spoke pool on destination chain by | ||
| // performing delegatecall to use the adapter's code with this contract's context. | ||
| (bool success, ) = adapter.delegatecall( | ||
| abi.encodeWithSignature( | ||
| "relayMessage(address,bytes)", | ||
| spokePool, // target. This should be the spokePool on the L2. | ||
| abi.encodeWithSignature( | ||
| "relayRootBundle(bytes32,bytes32)", | ||
| rootBundleProposal.relayerRefundRoot, | ||
| rootBundleProposal.slowRelayRoot | ||
| ) // message | ||
| ) | ||
| ); | ||
| require(success, "delegatecall failed"); | ||
|
|
||
| // Transfer the bondAmount to back to the proposer, if this the last executed leaf. Only sending this once all | ||
| // leafs have been executed acts to force the data worker to execute all bundles or they wont receive their bond. | ||
|
|
@@ -851,14 +873,13 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { | |
| // Note this method does a lot and wraps together the sending of tokens and updating the pooled token trackers. This | ||
| // is done as a gas saving so we don't need to iterate over the l1Tokens multiple times. | ||
| function _sendTokensToChainAndUpdatePooledTokenTrackers( | ||
| address adapter, | ||
| address spokePool, | ||
| uint256 chainId, | ||
| address[] memory l1Tokens, | ||
| int256[] memory netSendAmounts, | ||
| uint256[] memory bundleLpFees | ||
| ) internal { | ||
| AdapterInterface adapter = crossChainContracts[chainId].adapter; | ||
|
Member
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. Save an SLOAD |
||
|
|
||
| for (uint32 i = 0; i < l1Tokens.length; i++) { | ||
| address l1Token = l1Tokens[i]; | ||
| // Validate the L1 -> L2 token route is whitelisted. If it is not then the output of the bridging action | ||
|
|
@@ -871,7 +892,7 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { | |
| if (netSendAmounts[i] > 0) { | ||
| // Perform delegatecall to use the adapter's code with this contract's context. Opt for delegatecall's | ||
| // complexity in exchange for lower gas costs. | ||
| (bool success, ) = address(adapter).delegatecall( | ||
| (bool success, ) = adapter.delegatecall( | ||
| abi.encodeWithSignature( | ||
| "relayTokens(address,address,uint256,address)", | ||
| l1Token, // l1Token. | ||
|
|
@@ -892,24 +913,6 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { | |
| } | ||
| } | ||
|
|
||
| function _relayRootBundleToSpokePool(address spokePool, uint256 chainId) internal { | ||
| AdapterInterface adapter = crossChainContracts[chainId].adapter; | ||
|
|
||
| // Perform delegatecall to use the adapter's code with this contract's context. | ||
| (bool success, ) = address(adapter).delegatecall( | ||
| abi.encodeWithSignature( | ||
| "relayMessage(address,bytes)", | ||
| spokePool, // target. This should be the spokePool on the L2. | ||
| abi.encodeWithSignature( | ||
| "relayRootBundle(bytes32,bytes32)", | ||
| rootBundleProposal.relayerRefundRoot, | ||
| rootBundleProposal.slowRelayRoot | ||
| ) // message | ||
| ) | ||
| ); | ||
| require(success, "delegatecall failed"); | ||
| } | ||
|
|
||
| function _exchangeRateCurrent(address l1Token) internal returns (uint256) { | ||
| PooledToken storage pooledToken = pooledTokens[l1Token]; // Note this is storage so the state can be modified. | ||
| uint256 lpTokenTotalSupply = IERC20(pooledToken.lpToken).totalSupply(); | ||
|
|
@@ -1002,14 +1005,15 @@ contract HubPool is HubPoolInterface, Testable, Lockable, MultiCaller, Ownable { | |
| } | ||
|
|
||
| function _relaySpokePoolAdminFunction(uint256 chainId, bytes memory functionData) internal { | ||
| AdapterInterface adapter = crossChainContracts[chainId].adapter; | ||
| require(address(adapter) != address(0), "Adapter not initialized"); | ||
|
Member
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. If adapter is 0x0 the delegateCalls should revert, but we do need to check the spokepool address is non zero |
||
| address adapter = crossChainContracts[chainId].adapter; | ||
| address spokePool = crossChainContracts[chainId].spokePool; | ||
| require(spokePool != address(0), "SpokePool not initialized"); | ||
|
|
||
| // Perform delegatecall to use the adapter's code with this contract's context. | ||
| (bool success, ) = address(adapter).delegatecall( | ||
| (bool success, ) = adapter.delegatecall( | ||
| abi.encodeWithSignature( | ||
| "relayMessage(address,bytes)", | ||
| crossChainContracts[chainId].spokePool, // target. This should be the spokePool on the L2. | ||
| spokePool, // target. This should be the spokePool on the L2. | ||
| functionData | ||
| ) | ||
| ); | ||
|
|
||
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
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
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
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.
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.
I think adding this inline is a bit clearer since we validate the
spokePooladdress in this method and we should put logic and its validation together