Skip to content

Commit

Permalink
Merge pull request #278 from chainbound/jonas/feat/registry-updates
Browse files Browse the repository at this point in the history
feat(contracts): registry updates
  • Loading branch information
mempirate authored Oct 16, 2024
2 parents 960dfaa + 2515d31 commit c2df22e
Show file tree
Hide file tree
Showing 35 changed files with 1,381 additions and 659 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*_dump.log
logs/
target/
.DS_Store
.env
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
[submodule "bolt-contracts/lib/eigenlayer-contracts"]
path = bolt-contracts/lib/eigenlayer-contracts
url = https://github.com/layr-labs/eigenlayer-contracts
[submodule "bolt-contracts/lib/openzeppelin-contracts-upgradeable"]
path = bolt-contracts/lib/openzeppelin-contracts-upgradeable
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
[submodule "bolt-contracts/lib/openzeppelin-foundry-upgrades"]
path = bolt-contracts/lib/openzeppelin-foundry-upgrades
url = https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades
57 changes: 29 additions & 28 deletions bolt-contracts/.gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
BoltChallengerTest:testCannotResolveChallengeBeforeExpiration() (gas: 434902)
BoltChallengerTest:testCommitmentDigestAndSignature() (gas: 4626)
BoltChallengerTest:testCommitmentSignature() (gas: 6754)
BoltChallengerTest:testOpenAlreadyExistingChallenge() (gas: 112649)
BoltChallengerTest:testOpenChallengeInvalidSignature() (gas: 25461)
BoltChallengerTest:testOpenChallengeSingleTx() (gas: 407773)
BoltChallengerTest:testOpenChallengeWithIncorrectBond() (gas: 17130)
BoltChallengerTest:testOpenChallengeWithLargebond() (gas: 17141)
BoltChallengerTest:testOpenChallengeWithSlotInTheFuture() (gas: 17517)
BoltChallengerTest:testCommitmentSignature() (gas: 6761)
BoltChallengerTest:testOpenAlreadyExistingChallenge() (gas: 13688)
BoltChallengerTest:testOpenChallengeInvalidSignature() (gas: 45916)
BoltChallengerTest:testOpenChallengeSingleTx() (gas: 424427)
BoltChallengerTest:testOpenChallengeWithIncorrectBond() (gas: 24909)
BoltChallengerTest:testOpenChallengeWithLargebond() (gas: 24920)
BoltChallengerTest:testOpenChallengeWithSlotInTheFuture() (gas: 25008)
BoltChallengerTest:testProveAccountData() (gas: 355542)
BoltChallengerTest:testProveHeaderData() (gas: 46228)
BoltChallengerTest:testProveHeaderData() (gas: 46360)
BoltChallengerTest:testProveTransactionInclusion() (gas: 176543)
BoltChallengerTest:testResolveChallengeFullDefenseSingleTx() (gas: 697131)
BoltChallengerTest:testResolveChallengeFullDefenseStackedTxs() (gas: 1166625)
BoltManagerEigenLayerTest:testGetNonExistentProposerStatus() (gas: 921620)
BoltManagerEigenLayerTest:testGetWhitelistedCollaterals() (gas: 99988)
BoltManagerEigenLayerTest:testNonWhitelistedCollateral() (gas: 103013)
BoltManagerEigenLayerTest:testProposersLookaheadStatus() (gas: 2142632)
BoltManagerEigenLayerTest:test_deregisterEigenLayerOperatorFromAVS() (gas: 898067)
BoltManagerEigenLayerTest:test_getEigenLayerOperatorStake() (gas: 935483)
BoltManagerEigenLayerTest:test_getEigenLayerProposerStatus() (gas: 938074)
BoltManagerTest:testGetNonExistentProposerStatus() (gas: 1197534)
BoltManagerTest:testGetProposerStatus() (gas: 1431371)
BoltManagerTest:testGetWhitelistedCollaterals() (gas: 16818)
BoltManagerTest:testNonWhitelistedCollateral() (gas: 41889)
BoltManagerTest:testProposersLookaheadStatus() (gas: 2421869)
BoltManagerTest:testReadOperatorStake() (gas: 1520048)
BoltValidatorsTest:testUnsafeRegistration() (gas: 145625)
BoltValidatorsTest:testUnsafeRegistrationFailsIfAlreadyRegistered() (gas: 143729)
BoltValidatorsTest:testUnsafeRegistrationInvalidCollateralProvider() (gas: 18821)
BoltValidatorsTest:testUnsafeRegistrationInvalidOperator() (gas: 19050)
BoltValidatorsTest:testUnsafeRegistrationWhenNotAllowed() (gas: 22565)
BoltChallengerTest:testResolveChallengeFullDefenseSingleTx() (gas: 562694)
BoltChallengerTest:testResolveChallengeFullDefenseStackedTxs() (gas: 939716)
BoltChallengerTest:testResolveExpiredChallenge() (gas: 426457)
BoltManagerEigenLayerTest:testDeregisterOperatorFromAVS() (gas: 834106)
BoltManagerEigenLayerTest:testGetOperatorStake() (gas: 998169)
BoltManagerEigenLayerTest:testNonExistentProposerStatus() (gas: 980157)
BoltManagerEigenLayerTest:testNonWhitelistedCollateral() (gas: 103778)
BoltManagerEigenLayerTest:testProposerStatus() (gas: 1007174)
BoltManagerEigenLayerTest:testProposersLookaheadStatus() (gas: 2302759)
BoltManagerEigenLayerTest:testWhitelistedCollaterals() (gas: 99260)
BoltManagerSymbioticTest:testGetNonExistentProposerStatus() (gas: 1265832)
BoltManagerSymbioticTest:testGetProposerStatus() (gas: 1508557)
BoltManagerSymbioticTest:testGetWhitelistedCollaterals() (gas: 17213)
BoltManagerSymbioticTest:testNonWhitelistedCollateral() (gas: 43806)
BoltManagerSymbioticTest:testProposersLookaheadStatus() (gas: 2582043)
BoltManagerSymbioticTest:testReadOperatorStake() (gas: 1541503)
BoltValidatorsTest:testUnsafeRegistration() (gas: 149361)
BoltValidatorsTest:testUnsafeRegistrationFailsIfAlreadyRegistered() (gas: 148862)
BoltValidatorsTest:testUnsafeRegistrationInvalidOperator() (gas: 22820)
BoltValidatorsTest:testUnsafeRegistrationWhenNotAllowed() (gas: 33183)
TransactionDecoderTest:testDecodeAllTestCases() (gas: 0)
TransactionDecoderTest:testDecodeGasUsage() (gas: 53281)
1 change: 1 addition & 0 deletions bolt-contracts/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cache/
out/
broadcast/
logs/

.env

Expand Down
49 changes: 44 additions & 5 deletions bolt-contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
## Table of Contents

- [Overview](#overview)
- [Architecture](#architecture)
- [Admin Privileges](#admin-privileges)
- [Validator Registration: `BoltValidators`](#validator-registration-boltvalidators)
- [Bolt Network Entrypoint: `BoltManager`](#bolt-network-entrypoint-boltmanager)
- [Symbiotic Integration guide for Staking Pools](#symbiotic-integration-guide-for-staking-pools)
Expand All @@ -18,8 +20,43 @@
The Bolt smart contracts cover the following components:

- Registration and delegation logic for validators to authenticate and opt-in to Bolt
- Flexible restaking integrations for staking pools and node operators
- (WIP) Fault proof challenge and slashing logic for validators
- Operator registration and collateral deposits through flexible restaking protocol integrations (EigenLayer & Symbiotic)
- Fault proof challenges and resolution *without slashing*

### Architecture
A high-level overview of architecture is depicted in the diagram below:

<img src="./docs/erd.png" width="700"/>

**Notes**
- All contracts are upgradeable by implementing [ERC1967Proxy](https://docs.openzeppelin.com/contracts/4.x/api/proxy#erc1967).
- Storage layout safety is maintained with the use of [storage gaps](https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#storage-gaps) and validated with the [OpenZeppelin Foundry Upgrades toolkit](https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades).
- There is a single admin address operated by the Bolt team to facilitate upgrades and update system-wide parameters.

## Admin Privileges

The smart contracts are deployed with a single administrator account operated by the Bolt team. In this testnet deployment, all contracts are upgradeable
and multiple system-wide parameters can be changed by this administrator in the case of bugs, hacks, or other critical events.

## System-wide Parameters: `BoltParameters`

[`BoltParameters`](./src/contracts/BoltParameters.sol) is an upgradeable storage contract that stores system-wide parameters that the other
contracts can read from. An overview is given in the table below:

| Parameter | Initial Value | Mutable after deployment |
| -------------------- | --------------- | ------------------------ |
| `EPOCH_DURATION` | 86400 (1 day) | No |
| `SLASHING_WINDOW` | 604800 (1 week) | No |
| `BLOCKHASH_EVM_LOOKBACK` | 256 | No |
| `ETH2_GENESIS_TIMESTAMP` | 1694786400 | No |
| `SLOT_TIME` | 12 | No |
| `JUSTIFICATION_DELAY` | 32 | Yes (by admin) |
| `MINIMUM_OPERATOR_STAKE` | 1 ether | Yes (by admin) |
| `MAX_CHALLENGE_DURATION` | 604800 (1 week) | Yes (by admin) |
| `CHALLENGE_BOND` | 1 ether | Yes (by admin) |
| `ALLOW_UNSAFE_REGISTRATION` | `true` | Yes (by admin) |

The values of these parameters can also be found in [`config.holesky.json`](./config/config.holesky.json).

## Validator Registration: `BoltValidators`

Expand Down Expand Up @@ -149,7 +186,7 @@ The steps required are the following:
3. Register the EigenLayer strategy you are using for restaking _if it has not been done by someone else already_.
This ensures that your restaked assets are correctly integrated with Bolt’s system.

## Fault Proof Challenge and Slashing: `BoltChallenger`
## Fault Proof Challenge: `BoltChallenger`

The [`BoltChallenger`](./src/contracts/BoltChallenger.sol) contract is the component responsible
for handling fault attribution in the case of a validator failing to meet their commitments.
Expand Down Expand Up @@ -196,7 +233,9 @@ If no arbitrators respond successfully within the challenge time window, the cha
`BREACHED` and anyone can call the `resolveExpiredChallenge()` method. The `BoltChallenger` will keep
track of this information for future reference.

### Slashing of validators
<!-- ### Slashing of validators
TODO: uncomment when slashing is live
If a challenge is `BREACHED` (as per the above definition), the validator's stake should be slashed to cover
the cost of a missed commitment. This is done by calling the `slash` function on the correct staking adapter
Expand All @@ -207,7 +246,7 @@ which will receive a request to slash a validator's stake and will have a last o
the slashing request before it is executed on-chain.
Subscribing to breached challenge events from the `BoltChallenger` is a trustless way to determine if a slashing
request is valid according to Bolt Protocol rules.
request is valid according to Bolt Protocol rules. -->

## Testing

Expand Down
12 changes: 12 additions & 0 deletions bolt-contracts/config/config.holesky.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"epochDuration": 86400,
"slashingWindow": 604800,
"maxChallengeDuration": 604800,
"challengeBond": 1000000000000000000,
"blockhashEvmLookback": 256,
"justificationDelay": 32,
"eth2GenesisTimestamp": 1694786400,
"slotTime": 12,
"allowUnsafeRegistration": true,
"minimumOperatorStake": 1000000000000000000
}
12 changes: 12 additions & 0 deletions bolt-contracts/config/config.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"epochDuration": 86400,
"slashingWindow": 604800,
"maxChallengeDuration": 604800,
"challengeBond": 1000000000000000000,
"blockhashEvmLookback": 256,
"justificationDelay": 32,
"eth2GenesisTimestamp": 1606824023,
"slotTime": 12,
"allowUnsafeRegistration": true,
"minimumOperatorStake": 1000000000000000000
}
Binary file added bolt-contracts/docs/erd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 9 additions & 1 deletion bolt-contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ out = "out"
libs = ["lib"]
fs_permissions = [{ access = "read-write", path = "./" }]
gas_reports = ["*"]
# Required options for the OpenZeppelin Foundry Upgrades toolkit: https://github.com/OpenZeppelin/openzeppelin-foundry-upgrades
ffi = true
ast = true
build_info = true
extra_output = ["storageLayout"]

# silence some warnings during compilation
# https://book.getfoundry.sh/reference/config/solidity-compiler#ignored_error_codes
Expand All @@ -21,7 +26,9 @@ remappings = [
"@relic/=lib/relic-sdk/packages/contracts",
"@symbiotic/=lib/core/src/",
"@eigenlayer/=lib/eigenlayer-contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin-foundry-upgrades/=lib/openzeppelin-foundry-upgrades/",

# Symbiotic remappings contexts
"lib/core/:forge-std/=lib/core/lib/forge-std/src/",
Expand All @@ -41,6 +48,7 @@ remappings = [
"lib/openzeppelin-contracts/:@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
]


[rpc_endpoints]
mainnet = "${ETH_RPC_URL}"
holesky = "${ETH_RPC_URL_HOLESKY}"
Expand Down
1 change: 1 addition & 0 deletions bolt-contracts/lib/openzeppelin-contracts-upgradeable
1 change: 1 addition & 0 deletions bolt-contracts/lib/openzeppelin-foundry-upgrades
47 changes: 0 additions & 47 deletions bolt-contracts/script/Deploy.s.sol

This file was deleted.

Loading

0 comments on commit c2df22e

Please sign in to comment.