Skip to content
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

[SHIP-3004] ZKSync: implement uptime feed validator #14245

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
2ff3892
intial commit
jlaveracll Aug 23, 2024
1c75022
cleanup
jlaveracll Aug 26, 2024
f1cdb54
Update ZKSyncValidator.sol
jlaveracll Aug 26, 2024
7f7f942
Update ZKSyncValidator.sol
jlaveracll Aug 27, 2024
3b76e51
Merge branch 'SHIP-3004/develop-sequencer-uptime-feed-contract' of gi…
jlaveracll Aug 27, 2024
f7f93e2
initial commit
jlaveracll Aug 27, 2024
87fe5d1
Merge branch 'develop' of github.com:smartcontractkit/chainlink into …
jlaveracll Aug 27, 2024
13078a8
Merge branch 'SHIP-3004/develop-sequencer-uptime-feed-contract' of gi…
jlaveracll Aug 27, 2024
0b7b769
address feedback
jlaveracll Aug 28, 2024
8927ee6
Update ZKSyncSequencerUptimeFeed.sol
jlaveracll Aug 28, 2024
e93d909
Update ZKSyncSequencerUptimeFeed.sol
jlaveracll Aug 28, 2024
a9c29db
Update ZKSyncSequencerUptimeFeed.sol
jlaveracll Aug 28, 2024
b0acfcb
Merge branch 'develop' of github.com:smartcontractkit/chainlink into …
jlaveracll Aug 28, 2024
57a35aa
Update ZKSyncValidator.sol
jlaveracll Aug 28, 2024
cf3aeb5
Update ZKSyncValidator.sol
jlaveracll Aug 28, 2024
d3b9b81
merge
jlaveracll Aug 28, 2024
becabc3
tmp
jlaveracll Aug 28, 2024
752c8fe
Add ZKSync L2EP validator contract
jlaveracll Aug 29, 2024
1963a67
Update smart-peas-brake.md
jlaveracll Aug 29, 2024
5354c29
Merge branch 'SHIP-3004/develop-sequencer-uptime-feed-contract' of gi…
jlaveracll Aug 29, 2024
201c30b
cleanup
jlaveracll Aug 29, 2024
72eabda
combine branches into a single one
jlaveracll Aug 29, 2024
e241c79
Update ZKSyncValidator.sol
jlaveracll Aug 29, 2024
9503a31
fix zksync contracts version
jlaveracll Aug 29, 2024
ea87262
Revert "fix zksync contracts version"
jlaveracll Aug 29, 2024
7f0b5ec
cleanup
jlaveracll Aug 29, 2024
8844db2
Update ZKSyncSequencerUptimeFeed.sol
jlaveracll Aug 29, 2024
291f874
cleanup
jlaveracll Aug 29, 2024
9e1f05b
[Bot] Update changeset file with jira issue
app-token-issuer-infra-releng[bot] Aug 29, 2024
2bd937c
test update foundry solc version
jlaveracll Aug 29, 2024
8717025
Merge branch 'SHIP-3004/develop-sequencer-uptime-feed-contract' of gi…
jlaveracll Aug 29, 2024
0ea4f71
try again!
jlaveracll Aug 29, 2024
a6f5a41
cleanup unused params
jlaveracll Aug 29, 2024
d2fc894
l2ep auto detect solc
jlaveracll Aug 29, 2024
37fbc7c
Fixes l2 tx request logic and adds payable
mohamed-mehany Aug 30, 2024
7e9b9cd
address feedback
jlaveracll Aug 30, 2024
7343968
lint
jlaveracll Aug 30, 2024
0116933
Fix zksync contracts verision
jlaveracll Aug 30, 2024
1e33010
Update package.json
jlaveracll Aug 30, 2024
1a96644
Update pnpm-lock.yaml
jlaveracll Aug 30, 2024
d27a153
Address more feedback
jlaveracll Aug 30, 2024
7ea3cb0
Update ZKSyncValidator.sol
jlaveracll Aug 30, 2024
43108b2
temp adding tests
jlaveracll Aug 30, 2024
65161a7
add zksync l2ep tests
chris-de-leon-cll Aug 31, 2024
68c3b76
Merge branch 'develop' into SHIP-3004/develop-sequencer-uptime-feed-c…
chris-de-leon-cll Aug 31, 2024
6eaf135
update foundry.toml
chris-de-leon-cll Aug 31, 2024
8ac6b84
update llo-feeds gas snapshot
chris-de-leon-cll Aug 31, 2024
af061f4
share interface
RensR Sep 1, 2024
4cc5042
interface starts with I
RensR Sep 1, 2024
357b033
more interfaces start with I
RensR Sep 1, 2024
3d3f1ea
extract base BaseSequencerUptimeFeed
RensR Sep 1, 2024
427790b
let scroll use the BaseSequencerUptimeFeed
RensR Sep 1, 2024
5d3a3d0
golf base impl
RensR Sep 1, 2024
e08e302
let opt use base
RensR Sep 1, 2024
1f0bcdb
reduce custom version to minimum
RensR Sep 1, 2024
8cfe099
extract BaseValidator
RensR Sep 2, 2024
7e5f62b
enforce ITypeAndVersion at BaseSequencerUptimeFeed level
RensR Sep 2, 2024
e232f0e
improve compile script
RensR Sep 2, 2024
f5b91fd
Merge pull request #14301 from smartcontractkit/create-base-contracts
jlaveracll Sep 2, 2024
25d0431
Merge branch 'develop' of github.com:smartcontractkit/chainlink into …
jlaveracll Sep 2, 2024
4cc96bc
address feedback
jlaveracll Sep 2, 2024
2d054c9
Update BaseSequencerUptimeFeed.sol
jlaveracll Sep 2, 2024
37b8620
cleaning up solidity versions
jlaveracll Sep 2, 2024
c09e699
Update .gas-snapshot
jlaveracll Sep 2, 2024
57644c6
temporarily adding tolerance
jlaveracll Sep 2, 2024
c50bf41
Adds new gas snapshot and removing tolerance
mohamed-mehany Sep 2, 2024
9f1ba0f
L2EP gas snapshot
mohamed-mehany Sep 2, 2024
29bb365
Modify gas-snapshot
mohamed-mehany Sep 2, 2024
3514bb1
Modifies gas snapshot
mohamed-mehany Sep 2, 2024
d319c52
Merge branch 'develop' of github.com:smartcontractkit/chainlink into …
jlaveracll Sep 3, 2024
1058836
Reverting some change
jlaveracll Sep 3, 2024
1ef5442
refer to internal addressaliashelper
jlaveracll Sep 3, 2024
20865f4
Update l2ep.gas-snapshot
jlaveracll Sep 3, 2024
bde8ae6
Update hardhat.config.ts
jlaveracll Sep 3, 2024
e0380d8
Updates gas snapshot
mohamed-mehany Sep 3, 2024
69e93c1
Updates gas snapshot
mohamed-mehany Sep 3, 2024
96b3e2f
bump to 0.8.24
RensR Sep 3, 2024
b680be0
rm zksync npm
RensR Sep 3, 2024
522d4bc
Revert "rm zksync npm"
RensR Sep 3, 2024
28f853e
fix versions
RensR Sep 3, 2024
0b989e3
Merge branch 'develop' of github.com:smartcontractkit/chainlink into …
jlaveracll Sep 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contracts/package.json
chris-de-leon-cll marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"typescript": "^5.5.4"
},
"dependencies": {
"@zksync/contracts": "git+https://github.com/matter-labs/era-contracts.git",
"@arbitrum/nitro-contracts": "1.1.1",
"@arbitrum/token-bridge-contracts": "1.1.2",
"@changesets/changelog-github": "^0.5.0",
Expand Down
9 changes: 9 additions & 0 deletions contracts/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions contracts/remappings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ forge-std/=src/v0.8/vendor/forge-std/src/
hardhat/=node_modules/hardhat/
@eth-optimism/=node_modules/@eth-optimism/
@scroll-tech/=node_modules/@scroll-tech/
@zksync/=node_modules/@zksync/
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// solhint-disable-next-line interface-starts-with-i
interface ZKSyncSequencerUptimeFeedInterface {
function updateStatus(bool status, uint64 timestamp) external;
}
155 changes: 155 additions & 0 deletions contracts/src/v0.8/l2ep/dev/zksync/ZKSyncValidator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Contract generally have a set version, interfaces and libraries usually have free versions like this. 0.8.24 is the latest version in use

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated after merging the refactor


import {AggregatorValidatorInterface} from "../../../shared/interfaces/AggregatorValidatorInterface.sol";
import {TypeAndVersionInterface} from "../../../interfaces/TypeAndVersionInterface.sol";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be time to all of L2EP to swap to the correct ITypeAndVersionInterface over this one. It's in shared

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated after merging the refactor

import {ZKSyncSequencerUptimeFeedInterface} from "./../interfaces/ZKSyncSequencerUptimeFeedInterface.sol";

import {SimpleWriteAccessController} from "../../../shared/access/SimpleWriteAccessController.sol";

import {IBridgehub, L2TransactionRequestDirect} from "@zksync/contracts/l1-contracts/contracts/bridgehub/IBridgehub.sol";

///
chris-de-leon-cll marked this conversation as resolved.
Show resolved Hide resolved
/// @title ZKSyncValidator - makes cross chain call to update the Sequencer Uptime Feed on L2
///
contract ZKSyncValidator is TypeAndVersionInterface, AggregatorValidatorInterface, SimpleWriteAccessController {
int256 private constant ANSWER_SEQ_OFFLINE = 1;
uint32 private s_gasLimit;
uint32 private s_l2GasPerPubdataByteLimit;

// solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i
address public immutable L1_CROSS_DOMAIN_MESSENGER_ADDRESS;
// solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i
address public immutable L2_UPTIME_FEED_ADDR;

uint32 private immutable i_chainId;
uint32 private constant TEST_NET_CHAIN_ID = 300;
uint32 private constant MAIN_NET_CHAIN_ID = 324;

///
/// @notice emitted when gas cost to spend on L2 is updated
/// @param gasLimit updated gas cost
///
event GasLimitUpdated(uint32 gasLimit);

///
/// @param l1CrossDomainMessengerAddress address the Bridgehub contract address
/// @param l2UptimeFeedAddr the address of the ZKSyncSequencerUptimeFeedInterface contract address
/// @param gasLimit the gasLimit to use for sending a message from L1 to L2
///
constructor(
address l1CrossDomainMessengerAddress,
address l2UptimeFeedAddr,
uint32 gasLimit,
uint32 chainId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use block.chainid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the chain id on the receiving layer, meaning zksync L2 mainnet vs test net ids.

I updated the constant names hoping to make it clearer

uint32 l2GasPerPubdataByteLimit
) {
// solhint-disable-next-line gas-custom-errors
chris-de-leon-cll marked this conversation as resolved.
Show resolved Hide resolved
require(l1CrossDomainMessengerAddress != address(0), "Invalid xDomain Messenger address");
// solhint-disable-next-line gas-custom-errors
chris-de-leon-cll marked this conversation as resolved.
Show resolved Hide resolved
require(l2UptimeFeedAddr != address(0), "Invalid ZKSyncSequencerUptimeFeedInterface contract address");
chris-de-leon-cll marked this conversation as resolved.
Show resolved Hide resolved
L1_CROSS_DOMAIN_MESSENGER_ADDRESS = l1CrossDomainMessengerAddress;
L2_UPTIME_FEED_ADDR = l2UptimeFeedAddr;
s_gasLimit = gasLimit;

// Check if the chainId is one of the valid values
require(chainId == TEST_NET_CHAIN_ID || chainId == MAIN_NET_CHAIN_ID, "Invalid chain id");
chris-de-leon-cll marked this conversation as resolved.
Show resolved Hide resolved
i_chainId = chainId;

s_l2GasPerPubdataByteLimit = l2GasPerPubdataByteLimit;
}

///
/// @inheritdoc TypeAndVersionInterface
///
function typeAndVersion() external pure virtual override returns (string memory) {
return "ZKSyncValidator 1.0.0";
}

///
/// @notice sets the new gas cost to spend when sending cross chain message
/// @param gasLimit the updated gas cost
///
function setGasLimit(uint32 gasLimit) external onlyOwner {
s_gasLimit = gasLimit;
emit GasLimitUpdated(gasLimit);
}

///
/// @notice fetches the gas cost of sending a cross chain message
///
function getGasLimit() external view returns (uint32) {
return s_gasLimit;
}

///
/// @notice sets the l2GasPerPubdataByteLimit TODO complete this
chris-de-leon-cll marked this conversation as resolved.
Show resolved Hide resolved
/// @param l2GasPerPubdataByteLimit the updated l2GasPerPubdataByteLimit
///
function setL2GasPerPubdataByteLimit(uint32 l2GasPerPubdataByteLimit) external onlyOwner {
s_l2GasPerPubdataByteLimit = l2GasPerPubdataByteLimit;
// emit GasLimitUpdated(gasLimit); TODO do we need to?
chris-de-leon-cll marked this conversation as resolved.
Show resolved Hide resolved
}

///
/// @notice fetches the l2GasPerPubdataByteLimit // TODO complete this
chris-de-leon-cll marked this conversation as resolved.
Show resolved Hide resolved
///
function getL2GasPerPubdataByteLimit() external view returns (uint32) {
return s_l2GasPerPubdataByteLimit;
}

///
/// @notice fetches the chain id
///
function getChainId() external view returns (uint32) {
return i_chainId;
}

///
/// @notice validate method sends an xDomain L2 tx to update Uptime Feed contract on L2.
/// @dev A message is sent using the Bridgehub. This method is accessed controlled.
/// @param currentAnswer new aggregator answer - value of 1 considers the sequencer offline.
///
function validate(
uint256 /* previousRoundId */,
int256 /* previousAnswer */,
uint256 /* currentRoundId */,
int256 currentAnswer
) external override checkAccess returns (bool) {
// Encode the ZKSyncSequencerUptimeFeedInterface call with `status` and `timestamp`
bytes memory message = abi.encodeWithSelector(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can inline into line 146

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

ZKSyncSequencerUptimeFeedInterface.updateStatus.selector,
currentAnswer == ANSWER_SEQ_OFFLINE,
uint64(block.timestamp)
);

bytes[] memory emptyBytes;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the conventional way to write this is factoryDeps: new bytes[](0), instead of defining empty bytes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


IBridgehub bridgeHub = IBridgehub(L1_CROSS_DOMAIN_MESSENGER_ADDRESS);

uint256 transactionBaseCostEstimate = bridgeHub.l2TransactionBaseCost(
i_chainId,
tx.gasprice,
s_gasLimit,
s_l2GasPerPubdataByteLimit
);

// Create the L2 transaction request
L2TransactionRequestDirect memory l2TransactionRequestDirect = L2TransactionRequestDirect({
chainId: i_chainId,
mintValue: 0,
l2Contract: L2_UPTIME_FEED_ADDR,
l2Value: transactionBaseCostEstimate,
l2Calldata: message,
l2GasLimit: s_gasLimit,
l2GasPerPubdataByteLimit: s_l2GasPerPubdataByteLimit,
factoryDeps: emptyBytes,
refundRecipient: msg.sender
});

// Make the xDomain call
bridgeHub.requestL2TransactionDirect(l2TransactionRequestDirect);

return true;
}
}
Loading