Skip to content

Commit

Permalink
[SHIP-3004] ZKSync: implement uptime feed validator (#14245)
Browse files Browse the repository at this point in the history
* intial commit

* cleanup

* Update ZKSyncValidator.sol

* Update ZKSyncValidator.sol

* initial commit

* address feedback

* Update ZKSyncSequencerUptimeFeed.sol

* Update ZKSyncSequencerUptimeFeed.sol

* Update ZKSyncSequencerUptimeFeed.sol

* Update ZKSyncValidator.sol

* Update ZKSyncValidator.sol

* tmp

* Add ZKSync L2EP validator contract

* Update smart-peas-brake.md

* cleanup

* combine branches into a single one

* Update ZKSyncValidator.sol

* fix zksync contracts version

* Revert "fix zksync contracts version"

This reverts commit 9503a31.

* cleanup

* Update ZKSyncSequencerUptimeFeed.sol

* cleanup

* [Bot] Update changeset file with jira issue

* test update foundry solc version

* try again!

* cleanup unused params

* l2ep auto detect solc

* Fixes l2 tx request logic and adds payable

* address feedback

* lint

* Fix zksync contracts verision

* Update package.json

* Update pnpm-lock.yaml

* Address more feedback

* Update ZKSyncValidator.sol

* temp adding tests

* add zksync l2ep tests

* update foundry.toml

* update llo-feeds gas snapshot

* share interface

* interface starts with I

* more interfaces start with I

* extract base BaseSequencerUptimeFeed

* let scroll use the BaseSequencerUptimeFeed

* golf base impl

* let opt use base

* reduce custom version to minimum

* extract BaseValidator

* enforce ITypeAndVersion at BaseSequencerUptimeFeed level

* improve compile script

* address feedback

* Update BaseSequencerUptimeFeed.sol

* cleaning up solidity versions

* Update .gas-snapshot

* temporarily adding tolerance

* Adds new gas snapshot and removing tolerance

* L2EP gas snapshot

* Modify gas-snapshot

* Modifies gas snapshot

* Reverting some change

* refer to internal addressaliashelper

* Update l2ep.gas-snapshot

* Update hardhat.config.ts

* Updates gas snapshot

* Updates gas snapshot

* bump to 0.8.24

* rm zksync npm

* Revert "rm zksync npm"

This reverts commit b680be0.

* fix versions

---------

Co-authored-by: app-token-issuer-infra-releng[bot] <120227048+app-token-issuer-infra-releng[bot]@users.noreply.github.com>
Co-authored-by: Mohamed Mehany <[email protected]>
Co-authored-by: Chris De Leon <[email protected]>
Co-authored-by: Chris De Leon <[email protected]>
Co-authored-by: Rens Rooimans <[email protected]>
  • Loading branch information
6 people authored Sep 3, 2024
1 parent 2a21b17 commit 39a6f91
Show file tree
Hide file tree
Showing 58 changed files with 1,466 additions and 962 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/solidity-foundry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
{ "name": "ccip", "setup": { "run-coverage": true, "min-coverage": 97.6, "run-gas-snapshot": true, "run-forge-fmt": true }},
{ "name": "functions", "setup": { "run-coverage": false, "min-coverage": 98.5, "run-gas-snapshot": true, "run-forge-fmt": false }},
{ "name": "keystone", "setup": { "run-coverage": true, "min-coverage": 72.8, "run-gas-snapshot": false, "run-forge-fmt": false }},
{ "name": "l2ep", "setup": { "run-coverage": true, "min-coverage": 63.4, "run-gas-snapshot": true, "run-forge-fmt": false }},
{ "name": "l2ep", "setup": { "run-coverage": true, "min-coverage": 61.0, "run-gas-snapshot": true, "run-forge-fmt": false }},
{ "name": "liquiditymanager", "setup": { "run-coverage": true, "min-coverage": 46.3, "run-gas-snapshot": true, "run-forge-fmt": false }},
{ "name": "llo-feeds", "setup": { "run-coverage": true, "min-coverage": 49.3, "run-gas-snapshot": true, "run-forge-fmt": false }},
{ "name": "operatorforwarder", "setup": { "run-coverage": true, "min-coverage": 55.7, "run-gas-snapshot": true, "run-forge-fmt": false }},
Expand Down
9 changes: 9 additions & 0 deletions contracts/.changeset/heavy-balloons-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"chainlink": patch
---

#added Add ZKSync L2EP SequencerUptimeFeed contract
#added Add ZKSync L2EP Validator contract


SHIP-3004
254 changes: 142 additions & 112 deletions contracts/.gas-snapshot

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ src = 'src/v0.8/automation'
test = 'src/v0.8/automation/test'

[profile.l2ep]
solc_version = '0.8.24'
optimizer_runs = 1_000_000
src = 'src/v0.8/l2ep'
test = 'src/v0.8/l2ep/test'
solc_version = '0.8.19'

[profile.llo-feeds]
optimizer_runs = 1_000_000
Expand Down
206 changes: 113 additions & 93 deletions contracts/gas-snapshots/l2ep.gas-snapshot

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"@openzeppelin/contracts": "4.9.3",
"@openzeppelin/contracts-upgradeable": "4.9.3",
"@scroll-tech/contracts": "0.1.0",
"@zksync/contracts": "git+https://github.com/matter-labs/era-contracts.git#446d391d34bdb48255d5f8fef8a8248925fc98b9",
"semver": "^7.6.3"
}
}
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/
39 changes: 9 additions & 30 deletions contracts/scripts/native_solc_compile_all_l2ep
Original file line number Diff line number Diff line change
@@ -1,59 +1,38 @@
#!/usr/bin/env bash

###########
# Logging #
###########

set -e

echo " ┌──────────────────────────────────────────────┐"
echo " │ Compiling L2EP contracts... │"
echo " └──────────────────────────────────────────────┘"

######################
# Helper Variable(s) #
######################

export SOLC_VERSION="0.8.19"
SOLC_VERSION="0.8.24"
OPTIMIZE_RUNS=1000000

SCRIPTPATH="$(
cd "$(dirname "$0")" >/dev/null 2>&1
pwd -P
)"
SCRIPTPATH="$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
python3 -m pip install --require-hashes -r $SCRIPTPATH/requirements.txt
solc-select install $SOLC_VERSION
solc-select use $SOLC_VERSION

ROOT="$(
cd "$(dirname "$0")" >/dev/null 2>&1
cd ../ && pwd -P
)"

######################
# Helper Function(s) #
######################

compileContract() {
local optimize_runs=1000000
local version="$1"
local srcpath="$2"
solc \
@openzeppelin/=$ROOT/node_modules/@openzeppelin/ \
@eth-optimism/=$ROOT/node_modules/@eth-optimism/ \
@scroll-tech/=$ROOT/node_modules/@scroll-tech/ \
--overwrite --optimize --optimize-runs $optimize_runs --metadata-hash none \
--overwrite --optimize --optimize-runs $OPTIMIZE_RUNS --metadata-hash none \
-o $ROOT/solc/v$SOLC_VERSION/l2ep/"$version" \
--abi --bin \
--allow-paths $ROOT/src/v0.8,$ROOT/node_modules \
--abi --bin --allow-paths $ROOT/src/v0.8,$ROOT/node_modules \
--evm-version paris \
$ROOT/src/v0.8/l2ep/"$srcpath"
}

#################
# Version 1.0.0 #
#################

python3 -m pip install --require-hashes -r $SCRIPTPATH/requirements.txt

solc-select install $SOLC_VERSION
solc-select use $SOLC_VERSION

compileContract v1_0_0 dev/arbitrum/ArbitrumValidator.sol
compileContract v1_0_0 dev/arbitrum/ArbitrumSequencerUptimeFeed.sol
compileContract v1_0_0 dev/arbitrum/ArbitrumCrossDomainForwarder.sol
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/v0.8/l2ep/dev/CrossDomainDelegateForwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
pragma solidity ^0.8.0;

import {CrossDomainOwnable} from "./CrossDomainOwnable.sol";
import {DelegateForwarderInterface} from "./interfaces/DelegateForwarderInterface.sol";
import {IDelegateForwarder} from "./interfaces/IDelegateForwarder.sol";

/**
* @title CrossDomainDelegateForwarder - L1 xDomain account representation (with delegatecall support)
* @notice L2 Contract which receives messages from a specific L1 address and transparently forwards them to the destination.
* @dev Any other L2 contract which uses this contract's address as a privileged position,
* can consider that position to be held by the `l1Owner`
*/
abstract contract CrossDomainDelegateForwarder is DelegateForwarderInterface, CrossDomainOwnable {}
abstract contract CrossDomainDelegateForwarder is IDelegateForwarder, CrossDomainOwnable {}
4 changes: 2 additions & 2 deletions contracts/src/v0.8/l2ep/dev/CrossDomainForwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
pragma solidity ^0.8.0;

import {CrossDomainOwnable} from "./CrossDomainOwnable.sol";
import {ForwarderInterface} from "./interfaces/ForwarderInterface.sol";
import {IForwarder} from "./interfaces/IForwarder.sol";

/**
* @title CrossDomainForwarder - L1 xDomain account representation
* @notice L2 Contract which receives messages from a specific L1 address and transparently forwards them to the destination.
* @dev Any other L2 contract which uses this contract's address as a privileged position,
* can consider that position to be held by the `l1Owner`
*/
abstract contract CrossDomainForwarder is ForwarderInterface, CrossDomainOwnable {}
abstract contract CrossDomainForwarder is IForwarder, CrossDomainOwnable {}
4 changes: 2 additions & 2 deletions contracts/src/v0.8/l2ep/dev/CrossDomainOwnable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
pragma solidity ^0.8.0;

import {ConfirmedOwner} from "../../shared/access/ConfirmedOwner.sol";
import {CrossDomainOwnableInterface} from "./interfaces/CrossDomainOwnableInterface.sol";
import {ICrossDomainOwnable} from "./interfaces/ICrossDomainOwnable.sol";

/**
* @title The CrossDomainOwnable contract
* @notice A contract with helpers for cross-domain contract ownership.
*/
contract CrossDomainOwnable is CrossDomainOwnableInterface, ConfirmedOwner {
contract CrossDomainOwnable is ICrossDomainOwnable, ConfirmedOwner {
address internal s_l1Owner;
address internal s_l1PendingOwner;

Expand Down
6 changes: 3 additions & 3 deletions contracts/src/v0.8/l2ep/dev/Flags.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;
pragma solidity ^0.8.24;

import {SimpleReadAccessController} from "../../shared/access/SimpleReadAccessController.sol";
import {AccessControllerInterface} from "../../shared/interfaces/AccessControllerInterface.sol";
import {ITypeAndVersion} from "../../shared/interfaces/ITypeAndVersion.sol";

/* dev dependencies - to be re/moved after audit */
import {FlagsInterface} from "./interfaces/FlagsInterface.sol";
import {IFlags} from "./interfaces/IFlags.sol";

/**
* @title The Flags contract
Expand All @@ -18,7 +18,7 @@ import {FlagsInterface} from "./interfaces/FlagsInterface.sol";
* FlagOn events you should filter for addresses you care about.
*/
// solhint-disable gas-custom-errors
contract Flags is ITypeAndVersion, FlagsInterface, SimpleReadAccessController {
contract Flags is ITypeAndVersion, IFlags, SimpleReadAccessController {
AccessControllerInterface public raisingAccessController;
AccessControllerInterface public loweringAccessController;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
pragma solidity ^0.8.24;

import {TypeAndVersionInterface} from "../../../interfaces/TypeAndVersionInterface.sol";
import {ITypeAndVersion} from "../../../shared/interfaces/ITypeAndVersion.sol";
// solhint-disable-next-line no-unused-import
import {ForwarderInterface} from "../interfaces/ForwarderInterface.sol";
import {IForwarder} from "../interfaces/IForwarder.sol";

import {CrossDomainForwarder} from "../CrossDomainForwarder.sol";
import {CrossDomainOwnable} from "../CrossDomainOwnable.sol";
Expand All @@ -17,7 +17,7 @@ import {Address} from "../../../vendor/openzeppelin-solidity/v4.7.3/contracts/ut
* @dev Any other L2 contract which uses this contract's address as a privileged position,
* can be considered to be owned by the `l1Owner`
*/
contract ArbitrumCrossDomainForwarder is TypeAndVersionInterface, CrossDomainForwarder {
contract ArbitrumCrossDomainForwarder is ITypeAndVersion, CrossDomainForwarder {
/**
* @notice creates a new Arbitrum xDomain Forwarder contract
* @param l1OwnerAddr the L1 owner address that will be allowed to call the forward fn
Expand All @@ -31,7 +31,7 @@ contract ArbitrumCrossDomainForwarder is TypeAndVersionInterface, CrossDomainFor
* - ArbitrumCrossDomainForwarder 0.1.0: initial release
* - ArbitrumCrossDomainForwarder 1.0.0: Use OZ Address, CrossDomainOwnable
*
* @inheritdoc TypeAndVersionInterface
* @inheritdoc ITypeAndVersion
*/
function typeAndVersion() external pure virtual override returns (string memory) {
return "ArbitrumCrossDomainForwarder 1.0.0";
Expand All @@ -46,7 +46,7 @@ contract ArbitrumCrossDomainForwarder is TypeAndVersionInterface, CrossDomainFor

/**
* @dev forwarded only if L2 Messenger calls with `xDomainMessageSender` being the L1 owner address
* @inheritdoc ForwarderInterface
* @inheritdoc IForwarder
*/
function forward(address target, bytes memory data) external virtual override onlyL1Owner {
Address.functionCall(target, data, "Forwarder call reverted");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
pragma solidity ^0.8.0;

// solhint-disable-next-line no-unused-import
import {TypeAndVersionInterface} from "../../../interfaces/TypeAndVersionInterface.sol";
import {ITypeAndVersion} from "../../../shared/interfaces/ITypeAndVersion.sol";
// solhint-disable-next-line no-unused-import
import {ForwarderInterface} from "../interfaces/ForwarderInterface.sol";
import {DelegateForwarderInterface} from "../interfaces/DelegateForwarderInterface.sol";
import {IForwarder} from "../interfaces/IForwarder.sol";
import {IDelegateForwarder} from "../interfaces/IDelegateForwarder.sol";

import {ArbitrumCrossDomainForwarder} from "./ArbitrumCrossDomainForwarder.sol";

Expand All @@ -17,7 +17,7 @@ import {Address} from "../../../vendor/openzeppelin-solidity/v4.7.3/contracts/ut
* @dev Any other L2 contract which uses this contract's address as a privileged position,
* can be considered to be simultaneously owned by the `l1Owner` and L2 `owner`
*/
contract ArbitrumCrossDomainGovernor is DelegateForwarderInterface, ArbitrumCrossDomainForwarder {
contract ArbitrumCrossDomainGovernor is IDelegateForwarder, ArbitrumCrossDomainForwarder {
/**
* @notice creates a new Arbitrum xDomain Forwarder contract
* @param l1OwnerAddr the L1 owner address that will be allowed to call the forward fn
Expand All @@ -30,23 +30,23 @@ contract ArbitrumCrossDomainGovernor is DelegateForwarderInterface, ArbitrumCros
*
* - ArbitrumCrossDomainGovernor 1.0.0: initial release
*
* @inheritdoc TypeAndVersionInterface
* @inheritdoc ITypeAndVersion
*/
function typeAndVersion() external pure virtual override returns (string memory) {
return "ArbitrumCrossDomainGovernor 1.0.0";
}

/**
* @dev forwarded only if L2 Messenger calls with `msg.sender` being the L1 owner address, or called by the L2 owner
* @inheritdoc ForwarderInterface
* @inheritdoc IForwarder
*/
function forward(address target, bytes memory data) external override onlyLocalOrCrossDomainOwner {
Address.functionCall(target, data, "Governor call reverted");
}

/**
* @dev forwarded only if L2 Messenger calls with `msg.sender` being the L1 owner address, or called by the L2 owner
* @inheritdoc DelegateForwarderInterface
* @inheritdoc IDelegateForwarder
*/
function forwardDelegate(address target, bytes memory data) external override onlyLocalOrCrossDomainOwner {
Address.functionDelegateCall(target, data, "Governor delegatecall reverted");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity ^0.8.24;

import {AddressAliasHelper} from "../../../vendor/arb-bridge-eth/v0.8.0-custom/contracts/libraries/AddressAliasHelper.sol";
import {AggregatorInterface} from "../../../shared/interfaces/AggregatorInterface.sol";
import {AggregatorV3Interface} from "../../../shared/interfaces/AggregatorV3Interface.sol";
import {AggregatorV2V3Interface} from "../../../shared/interfaces/AggregatorV2V3Interface.sol";
import {TypeAndVersionInterface} from "../../../interfaces/TypeAndVersionInterface.sol";
import {FlagsInterface} from "../interfaces/FlagsInterface.sol";
import {ArbitrumSequencerUptimeFeedInterface} from "../interfaces/ArbitrumSequencerUptimeFeedInterface.sol";
import {ITypeAndVersion} from "../../../shared/interfaces/ITypeAndVersion.sol";
import {IFlags} from "../interfaces/IFlags.sol";
import {ISequencerUptimeFeed} from "../interfaces/ISequencerUptimeFeed.sol";
import {SimpleReadAccessController} from "../../../shared/access/SimpleReadAccessController.sol";

/**
Expand All @@ -18,8 +18,8 @@ import {SimpleReadAccessController} from "../../../shared/access/SimpleReadAcces
*/
contract ArbitrumSequencerUptimeFeed is
AggregatorV2V3Interface,
ArbitrumSequencerUptimeFeedInterface,
TypeAndVersionInterface,
ISequencerUptimeFeed,
ITypeAndVersion,
SimpleReadAccessController
{
/// @dev Round info (for uptime history)
Expand Down Expand Up @@ -62,7 +62,7 @@ contract ArbitrumSequencerUptimeFeed is

/// @dev Flags contract to raise/lower flags on, during status transitions
// solhint-disable-next-line chainlink-solidity/prefix-immutable-variables-with-i
FlagsInterface public immutable FLAGS;
IFlags public immutable FLAGS;
/// @dev L1 address
address private s_l1Sender;
/// @dev s_latestRoundId == 0 means this contract is uninitialized.
Expand All @@ -76,7 +76,7 @@ contract ArbitrumSequencerUptimeFeed is
constructor(address flagsAddress, address l1SenderAddress) {
_setL1Sender(l1SenderAddress);

FLAGS = FlagsInterface(flagsAddress);
FLAGS = IFlags(flagsAddress);
}

/**
Expand Down Expand Up @@ -120,7 +120,7 @@ contract ArbitrumSequencerUptimeFeed is
*
* - ArbitrumSequencerUptimeFeed 1.0.0: initial release
*
* @inheritdoc TypeAndVersionInterface
* @inheritdoc ITypeAndVersion
*/
function typeAndVersion() external pure virtual override returns (string memory) {
return "ArbitrumSequencerUptimeFeed 1.0.0";
Expand Down
Loading

0 comments on commit 39a6f91

Please sign in to comment.