-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
auto-10161: replicate v2_3 to v2_3_zksync #14035
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a076b9b
auto-10161: replicate v2_3 to v2_3_zksync
FelixFan1992 1fd964e
update
FelixFan1992 ceafc31
small fixes
FelixFan1992 eb12a38
Merge branch 'develop' into auto-10161-replication
FelixFan1992 c9e8a61
Merge branch 'develop' into auto-10161-replication
FelixFan1992 3bda15b
add an zksync automation forwarder
FelixFan1992 b6cb804
fix linter
FelixFan1992 6d8a7c5
update
FelixFan1992 732c43d
update
FelixFan1992 2f43aad
lint
FelixFan1992 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 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,5 @@ | ||
--- | ||
'@chainlink/contracts': patch | ||
--- | ||
|
||
auto: create a replication from v2_3 to v2_3_zksync |
This file contains 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 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
92 changes: 92 additions & 0 deletions
92
contracts/src/v0.8/automation/ZKSyncAutomationForwarder.sol
This file contains 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,92 @@ | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
pragma solidity ^0.8.16; | ||
|
||
import {IAutomationRegistryConsumer} from "./interfaces/IAutomationRegistryConsumer.sol"; | ||
|
||
uint256 constant PERFORM_GAS_CUSHION = 5_000; | ||
|
||
/** | ||
* @title AutomationForwarder is a relayer that sits between the registry and the customer's target contract | ||
* @dev The purpose of the forwarder is to give customers a consistent address to authorize against, | ||
* which stays consistent between migrations. The Forwarder also exposes the registry address, so that users who | ||
* want to programmatically interact with the registry (ie top up funds) can do so. | ||
*/ | ||
contract ZKSyncAutomationForwarder { | ||
/// @notice the user's target contract address | ||
address private immutable i_target; | ||
|
||
/// @notice the shared logic address | ||
address private immutable i_logic; | ||
|
||
IAutomationRegistryConsumer private s_registry; | ||
|
||
constructor(address target, address registry, address logic) { | ||
s_registry = IAutomationRegistryConsumer(registry); | ||
i_target = target; | ||
i_logic = logic; | ||
} | ||
|
||
/** | ||
* @notice forward is called by the registry and forwards the call to the target | ||
* @param gasAmount is the amount of gas to use in the call | ||
* @param data is the 4 bytes function selector + arbitrary function data | ||
* @return success indicating whether the target call succeeded or failed | ||
*/ | ||
function forward(uint256 gasAmount, bytes memory data) external returns (bool success, uint256 gasUsed) { | ||
if (msg.sender != address(s_registry)) revert(); | ||
address target = i_target; | ||
gasUsed = gasleft(); | ||
assembly { | ||
let g := gas() | ||
// Compute g -= PERFORM_GAS_CUSHION and check for underflow | ||
if lt(g, PERFORM_GAS_CUSHION) { | ||
revert(0, 0) | ||
} | ||
g := sub(g, PERFORM_GAS_CUSHION) | ||
// if g - g//64 <= gasAmount, revert | ||
// (we subtract g//64 because of EIP-150) | ||
if iszero(gt(sub(g, div(g, 64)), gasAmount)) { | ||
revert(0, 0) | ||
} | ||
// solidity calls check that a contract actually exists at the destination, so we do the same | ||
if iszero(extcodesize(target)) { | ||
revert(0, 0) | ||
} | ||
// call with exact gas | ||
success := call(gasAmount, target, 0, add(data, 0x20), mload(data), 0, 0) | ||
} | ||
gasUsed = gasUsed - gasleft(); | ||
return (success, gasUsed); | ||
} | ||
|
||
function getTarget() external view returns (address) { | ||
return i_target; | ||
} | ||
|
||
fallback() external { | ||
// copy to memory for assembly access | ||
address logic = i_logic; | ||
// copied directly from OZ's Proxy contract | ||
assembly { | ||
// Copy msg.data. We take full control of memory in this inline assembly | ||
// block because it will not return to Solidity code. We overwrite the | ||
// Solidity scratch pad at memory position 0. | ||
calldatacopy(0, 0, calldatasize()) | ||
|
||
// out and outsize are 0 because we don't know the size yet. | ||
let result := delegatecall(gas(), logic, 0, calldatasize(), 0, 0) | ||
|
||
// Copy the returned data. | ||
returndatacopy(0, 0, returndatasize()) | ||
|
||
switch result | ||
// delegatecall returns 0 on error. | ||
case 0 { | ||
revert(0, returndatasize()) | ||
} | ||
default { | ||
return(0, returndatasize()) | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains 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.
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.
unlocked pragma?