-
Notifications
You must be signed in to change notification settings - Fork 75
Call adapters using delegatecall to save gas #52
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
8 commits
Select commit
Hold shift + click to select a range
c8a8887
WIP
mrice32 dd88310
WIP
mrice32 727f175
WIP
mrice32 4abe1c4
Delegatecall experiment
mrice32 fdfa0fc
Merge branch 'master' into delegatecall
mrice32 cc6b28f
Merge branch 'master' into delegatecall
mrice32 017e329
WIP
mrice32 43467cb
Update contracts/HubPool.sol
mrice32 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
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 was deleted.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity >0.5.0 <0.9.0; | ||
|
|
||
| /* Interface Imports */ | ||
| import { ICrossDomainMessenger } from "@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol"; | ||
|
|
||
| /** | ||
| * @title CrossDomainEnabled | ||
| * @dev Helper contract for contracts performing cross-domain communications | ||
| * | ||
| * Compiler used: defined by inheriting contract | ||
| */ | ||
| contract CrossDomainEnabled { | ||
|
Member
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. |
||
| /************* | ||
| * Variables * | ||
| *************/ | ||
|
|
||
| // Messenger contract used to send and recieve messages from the other domain. | ||
| address public immutable messenger; | ||
|
|
||
| /*************** | ||
| * Constructor * | ||
| ***************/ | ||
|
|
||
| /** | ||
| * @param _messenger Address of the CrossDomainMessenger on the current layer. | ||
| */ | ||
| constructor(address _messenger) { | ||
| messenger = _messenger; | ||
| } | ||
|
|
||
| /********************** | ||
| * Function Modifiers * | ||
| **********************/ | ||
|
|
||
| /** | ||
| * Enforces that the modified function is only callable by a specific cross-domain account. | ||
| * @param _sourceDomainAccount The only account on the originating domain which is | ||
| * authenticated to call this function. | ||
| */ | ||
| modifier onlyFromCrossDomainAccount(address _sourceDomainAccount) { | ||
| require(msg.sender == address(getCrossDomainMessenger()), "OVM_XCHAIN: messenger contract unauthenticated"); | ||
|
|
||
| require( | ||
| getCrossDomainMessenger().xDomainMessageSender() == _sourceDomainAccount, | ||
| "OVM_XCHAIN: wrong sender of cross-domain message" | ||
| ); | ||
|
|
||
| _; | ||
| } | ||
|
|
||
| /********************** | ||
| * Internal Functions * | ||
| **********************/ | ||
|
|
||
| /** | ||
| * Gets the messenger, usually from storage. This function is exposed in case a child contract | ||
| * needs to override. | ||
| * @return The address of the cross-domain messenger contract which should be used. | ||
| */ | ||
| function getCrossDomainMessenger() internal virtual returns (ICrossDomainMessenger) { | ||
| return ICrossDomainMessenger(messenger); | ||
| } | ||
|
|
||
| /**q | ||
| * Sends a message to an account on another domain | ||
| * @param _crossDomainTarget The intended recipient on the destination domain | ||
| * @param _message The data to send to the target (usually calldata to a function with | ||
| * `onlyFromCrossDomainAccount()`) | ||
| * @param _gasLimit The gasLimit for the receipt of the message on the target domain. | ||
| */ | ||
| function sendCrossDomainMessage( | ||
| address _crossDomainTarget, | ||
| uint32 _gasLimit, | ||
| bytes memory _message | ||
| ) internal { | ||
| // slither-disable-next-line reentrancy-events, reentrancy-benign | ||
| getCrossDomainMessenger().sendMessage(_crossDomainTarget, _message, _gasLimit); | ||
| } | ||
| } | ||
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
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.
so ugly, but neccessary. Alternatively, why not make the functions that need to pay ETH for arbitrum messages
payable? I'm guessing its only the functions that calladapter.relayMessage?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.
As discussed IRL, we can decide if we want to address this in a follow-up, but not a super high priority, as doing it this way may end up being more complicated.