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

Multi-whitelisted operators [audited] #299

Merged
merged 57 commits into from
Jul 7, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
066d650
update project dependencies
mtabasco Apr 10, 2024
4206206
Merge branch 'main' into update-dependencies
mtabasco Apr 10, 2024
ed84f4c
remove not relevant files
mtabasco Apr 11, 2024
72fc9ae
upgrade github actions
mtabasco Apr 11, 2024
5109ca2
edr dependency
mtabasco Apr 11, 2024
f17d5dc
fix solidity-coverage, slither
mtabasco Apr 12, 2024
d7d6c32
sync with main
mtabasco Apr 16, 2024
4f9f291
update tests viem way
mtabasco Apr 16, 2024
9a348fc
add data structure
mtabasco Apr 16, 2024
34d6a5f
set operators whitelists
mtabasco Apr 17, 2024
f74c429
support for ERC165
mtabasco Apr 19, 2024
03e1937
refactor operators update on cluster registration
mtabasco Apr 19, 2024
1cadb43
add view functions, refactors
mtabasco Apr 23, 2024
cea5938
update validator registration flow
mtabasco Apr 24, 2024
5841234
add operator whitelisting tests
mtabasco Apr 26, 2024
65347ee
set operator public/private, add tests
mtabasco Apr 29, 2024
c61c701
added fork tests
mtabasco Apr 29, 2024
d78a91f
update docs
mtabasco Apr 30, 2024
c140c3c
upgrade to 0.8.24, gas improvements
mtabasco May 3, 2024
21fef78
CI forked tests action
mtabasco May 3, 2024
932fa69
test fix CI
mtabasco May 5, 2024
2e90a0c
explicit imports, add fork test
mtabasco May 5, 2024
38b7165
change whitelist checks priority when registering validators
mtabasco May 6, 2024
11b4e67
add reentrancy tests
mtabasco May 13, 2024
fc18035
omit to make private operator when setting whitelisting contract
mtabasco May 13, 2024
ca4633a
remove privacy setting when whitelisting and removing opertors
mtabasco May 14, 2024
736ca09
sycn with main
mtabasco May 14, 2024
fb0d810
add SSVViews.isAddressWhitelistedInWhitelistingContract
mtabasco May 14, 2024
b7cfe2f
add edge cases, improve contract-helpers
mtabasco May 15, 2024
6827f06
fix CI test
mtabasco May 15, 2024
97860c5
env settings, remove GOERLI config and references
mtabasco May 16, 2024
0ea4626
add tests, update hardhat
mtabasco May 17, 2024
f30749c
add integration tests, fix CI
mtabasco May 20, 2024
e236a8e
remove setOperatorWhitelist
mtabasco May 20, 2024
f7e1554
enhace custom errors
mtabasco May 21, 2024
1dd85de
update errors
mtabasco May 21, 2024
a196ee0
update CHANGELOG
mtabasco May 21, 2024
5e04cd4
add RELEASE_NOTES
mtabasco May 21, 2024
7e9e6ba
deploy holesky stage
mtabasco May 21, 2024
dada02c
rename bulk funcs, move operator privacy funcs
mtabasco Jun 6, 2024
d078a87
registerOperator can set privacy status
mtabasco Jun 6, 2024
632e156
update docs
mtabasco Jun 6, 2024
ed84408
deploy stage
mtabasco Jun 6, 2024
e1009fa
getWhitelistedOperators update
mtabasco Jun 7, 2024
add2434
getWhitelistedOperators legacy whitelist support, fix reduceOperatorFee
mtabasco Jun 8, 2024
c928cf2
fix CI coverage
mtabasco Jun 8, 2024
737a192
stage upgrade
mtabasco Jun 18, 2024
5979ec5
new holesky deployment
mtabasco Jun 21, 2024
2f04029
audit fixes/improvements
mtabasco Jun 24, 2024
9c3b11a
upgrade testnet metadata
mtabasco Jun 24, 2024
9ddafc0
added custom test
mtabasco Jun 24, 2024
9192795
add audit report
mtabasco Jul 1, 2024
453d75b
update CHANGELOG
mtabasco Jul 1, 2024
bac7ff4
refactor whitelist check on validator registration
mtabasco Jul 3, 2024
fe120d7
update audit reports
mtabasco Jul 4, 2024
59abd6b
unlock pragma for interfaces
mtabasco Jul 4, 2024
c71314c
update audit report
mtabasco Jul 5, 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
16 changes: 0 additions & 16 deletions .editorconfig

This file was deleted.

1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ MAINNET_OWNER_PRIVATE_KEY=
GAS_PRICE=
GAS=
ETHERSCAN_KEY=
INFURA_KEY=
MINIMUM_BLOCKS_BEFORE_LIQUIDATION=100800
MINIMUM_LIQUIDATION_COLLATERAL=200000000
OPERATOR_MAX_FEE_INCREASE=3
Expand Down
27 changes: 0 additions & 27 deletions .eslintrc.js

This file was deleted.

13 changes: 6 additions & 7 deletions .github/workflows/code-coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
name: Solidity code coverage

on:
push:
on: [push]

jobs:
ci:
runs-on: ubuntu-latest

name: Solidity code coverage
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '20.x'
- run: npm ci
env:
GH_TOKEN: ${{ secrets.github_token }}
- run: NO_GAS_ENFORCE=1 npx hardhat coverage
- run: SOLIDITY_COVERAGE=true NO_GAS_ENFORCE=1 npx hardhat coverage
7 changes: 4 additions & 3 deletions .github/workflows/linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ on:
jobs:
ci:
runs-on: ubuntu-latest
name: Solidity linter
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '20.x'
- run: npm ci
env:
GH_TOKEN: ${{ secrets.github_token }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v2
uses: actions/setup-node@v3
with:
node-version: '16'
node-version: '20'
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run Slither
uses: crytic/[email protected]
id: slither
with:
node-version: 18
node-version: 20
fail-on: high
slither-args: --exclude controlled-delegatecall,incorrect-return
slither-args: --exclude controlled-delegatecall,incorrect-return
18 changes: 18 additions & 0 deletions .github/workflows/tests-forked.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Run tests

on: [push]

jobs:
ci:
runs-on: ubuntu-latest
name: Hardhat unit test (forked network)
env: # Set environment variables for all steps in this job
GH_TOKEN: ${{ secrets.github_token }}
FORK_TESTING_ENABLED: true
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '20.x'
- run: npm ci
- run: npx hardhat test test-forked/*.ts
11 changes: 5 additions & 6 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
name: Run tests

on:
push:
on: [push]

jobs:
ci:
runs-on: ubuntu-latest

name: Hardhat unit test
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '16.x'
node-version: '20.x'
- run: npm ci
env:
GH_TOKEN: ${{ secrets.github_token }}
Expand Down
23 changes: 14 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
node_modules
.env
.env.prod
.env.stage
abis
cache
coverage
coverage.json
artifacts
typechain-types/
.openzeppelin/*.json

# Hardhat files
/cache
/artifacts

# TypeChain files
/typechain
/typechain-types

# solidity-coverage files
/coverage
/coverage.json

.DS_Store
.history
.dccache
abis
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
}
}
]
}
}
3 changes: 3 additions & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
skipFiles: ['test','deprecated','token','upgrades']
};
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SSV Network Smart Contracts

### Intro | [Architecture](./docs/architecture.md) | [Setup](./docs/setup.md) | [Tasks](./docs/tasks.md) | [Local development](./docs/local-dev.md) | [Roles](./docs/roles.md) | [Publish](./docs/publish.md)
# SSV Network Smart Contracts

### Intro | [Architecture](./docs/architecture.md) | [Setup](./docs/setup.md) | [Tasks](./docs/tasks.md) | [Local development](./docs/local-dev.md) | [Roles](./docs/roles.md) | [Publish](./docs/publish.md) | [Operator owners](./docs/operators.md)

This repository contains the Solidity smart contracts for the SSV Network. The SSV Network is a decentralized network for the operation of Ethereum validators. It allows for secure, scalable, and decentralized staking on the Ethereum blockchain. The key elements of this system are represented through several Ethereum smart contracts, all of which are outlined below.

Expand Down
41 changes: 39 additions & 2 deletions contracts/SSVNetwork.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.18;
pragma solidity 0.8.24;

import "./interfaces/ISSVNetwork.sol";

import "./interfaces/ISSVClusters.sol";
import "./interfaces/ISSVOperators.sol";
import "./interfaces/ISSVOperatorsWhitelist.sol";
import "./interfaces/ISSVDAO.sol";
import "./interfaces/ISSVViews.sol";

import "./interfaces/external/ISSVWhitelistingContract.sol";

import "./libraries/Types.sol";
import "./libraries/CoreLib.sol";
import "./libraries/SSVStorage.sol";
Expand All @@ -26,6 +29,7 @@ contract SSVNetwork is
Ownable2StepUpgradeable,
ISSVNetwork,
ISSVOperators,
ISSVOperatorsWhitelist,
ISSVClusters,
ISSVDAO,
SSVProxy
Expand Down Expand Up @@ -126,7 +130,40 @@ contract SSVNetwork is
}

function setOperatorWhitelist(uint64 operatorId, address whitelisted) external override {
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_OPERATORS]);
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_OPERATORS_WHITELIST]);
}

function setOperatorMultipleWhitelists(
uint64[] calldata operatorIds,
address[] calldata whitelistAddresses
) external override {
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_OPERATORS_WHITELIST]);
}

function removeOperatorMultipleWhitelists(
uint64[] calldata operatorIds,
address[] calldata whitelistAddresses
) external override {
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_OPERATORS_WHITELIST]);
}

function setOperatorsWhitelistingContract(
uint64[] calldata operatorIds,
ISSVWhitelistingContract whitelistingContract
) external override {
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_OPERATORS_WHITELIST]);
}

function setOperatorsPrivateUnchecked(uint64[] calldata operatorIds) external override {
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_OPERATORS_WHITELIST]);
}

function setOperatorsPublicUnchecked(uint64[] calldata operatorIds) external {
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_OPERATORS_WHITELIST]);
}

function removeOperatorsWhitelistingContract(uint64[] calldata operatorIds) external override {
_delegate(SSVStorage.load().ssvContracts[SSVModules.SSV_OPERATORS_WHITELIST]);
}

function declareOperatorFee(uint64 operatorId, uint256 fee) external override {
Expand Down
12 changes: 11 additions & 1 deletion contracts/SSVNetworkViews.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.18;
pragma solidity 0.8.24;

import "./interfaces/ISSVViews.sol";
import "./libraries/Types.sol";
Expand Down Expand Up @@ -61,6 +61,16 @@ contract SSVNetworkViews is UUPSUpgradeable, Ownable2StepUpgradeable, ISSVViews
return ssvNetwork.getOperatorById(operatorId);
}

function getWhitelistedOperators(
uint64[] calldata operatorIds,
address whitelistedAddress
) external view override returns (uint64[] memory whitelistedOperatorIds) {
return ssvNetwork.getWhitelistedOperators(operatorIds, whitelistedAddress);
}
function isWhitelistingContract(address contractAddress) external view returns (bool) {
return ssvNetwork.isWhitelistingContract(contractAddress);
}

/***********************************/
/* Cluster External View Functions */
/***********************************/
Expand Down
3 changes: 1 addition & 2 deletions contracts/SSVProxy.sol
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.18;
pragma solidity 0.8.24;

import {SSVModules, SSVStorage, StorageData} from "./libraries/SSVStorage.sol";

abstract contract SSVProxy {

function _delegate(address implementation) internal {
assembly {
// Copy msg.data. We take full control of memory in this inline assembly
Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/ISSVClusters.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.18;
pragma solidity 0.8.24;

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

interface ISSVClusters is ISSVNetworkCore {
/// @notice Registers a new validator on the SSV Network
Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/ISSVDAO.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.18;
pragma solidity 0.8.24;

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

interface ISSVDAO is ISSVNetworkCore {
/// @notice Updates the network fee
Expand Down
12 changes: 6 additions & 6 deletions contracts/interfaces/ISSVNetwork.sol
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.18;
pragma solidity 0.8.24;

import "./ISSVNetworkCore.sol";
import "./ISSVOperators.sol";
import "./ISSVClusters.sol";
import "./ISSVDAO.sol";
import "./ISSVViews.sol";
import {ISSVNetworkCore} from "./ISSVNetworkCore.sol";
import {ISSVOperators} from "./ISSVOperators.sol";
import {ISSVClusters} from "./ISSVClusters.sol";
import {ISSVDAO} from "./ISSVDAO.sol";
import {ISSVViews} from "./ISSVViews.sol";

import {SSVModules} from "../libraries/SSVStorage.sol";

Expand Down
11 changes: 8 additions & 3 deletions contracts/interfaces/ISSVNetworkCore.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity 0.8.18;
pragma solidity 0.8.24;

interface ISSVNetworkCore {
/***********/
Expand All @@ -24,7 +24,7 @@ interface ISSVNetworkCore {
uint64 fee;
/// @dev The address of the operator's owner
address owner;
/// @dev Whitelisted flag for this operator
/// @dev private flag for this operator
bool whitelisted;
/// @dev The state snapshot of the operator
Snapshot snapshot;
Expand Down Expand Up @@ -59,7 +59,7 @@ interface ISSVNetworkCore {
/**********/

error CallerNotOwner(); // 0x5cd83192
error CallerNotWhitelisted(); // 0x8c6e5d71
error CallerNotWhitelisted(uint64 operatorId); // 0x60d86593
error FeeTooLow(); // 0x732f9413
error FeeExceedsIncreaseLimit(); // 0x958065d9
error NoFeeDeclared(); // 0x1d226c30
Expand Down Expand Up @@ -90,6 +90,11 @@ interface ISSVNetworkCore {
error IncorrectValidatorStateWithData(bytes publicKey); // 0x89307938
error ValidatorAlreadyExistsWithData(bytes publicKey); // 0x388e7999
error EmptyPublicKeysList(); // df83e679
error InvalidContractAddress(); // 0xa710429d
error AddressIsWhitelistingContract(address contractAddress); // 0x71cadba7
error InvalidWhitelistingContract(address contractAddress); // 0x886e6a03
error InvalidWhitelistAddressesLength(); // 0xcbb362dc
error ZeroAddressNotAllowed(); // 0x8579befe

// legacy errors
error ValidatorAlreadyExists(); // 0x8d09a73e
Expand Down
Loading
Loading