Skip to content

Commit 406d4d3

Browse files
authored
Allowlist for Wallet Registry (#3826)
The allowlist contract replaces the Threshold `TokenStaking` contract and is as an outcome of TIP-092 and TIP-100 governance decisions. Staking tokens is no longer required to operate nodes. Beta stakers are selected by the DAO and operate the network based on the allowlist maintained by the DAO. The contract will be integrated with the `WalletRegistry` and replace calls to `TokenStaking`. I have been experimenting with various approaches, and the most extreme one was to remove most of the `EcdsaAuthorization` logic as well as all `TokenStaking.seize` calls. This would have cascading effects on tBTC Bridge contracts as they rely on `WalletRegistry.seize`. That would also require implementing weight decrease delays in the `Allowlist,` so essentially doing work that is already done in `WalletRegistry`. Considering the pros and cons, I decided on the least invasive option. The `WalletRegistry` still thinks in terms of stake authorization, but everything is based on the staking provider's weight as set in the `Allowlist`, and weight decrease delays are enforced by the existing mechanism in `EcdsaAuthorization`. The `seize` function does nothing except of emitting an event about detecting beta staker misbehavior. # To be done ## Deployment script We need to capture all existing beta stakers along with their current authorizations and initialize the `Allowlist` contract. We can do it by either replicating the existing weights or giving them all the same weight. ## Integrate with `WalletRegistry` and tests There are two approaches to achieve it. The first one is to get rid of all references to `TokenStaking` from tests and update them to work with `Allowlist`. Another approach is to let them work with `TokenStaking` but introduce another integration test for those two contracts. In this option, we could use in `WalletRegistry` something like: ``` modifier onlyStakingContract() { address _allowlist = address(allowlist); require( // If the allowlist is set, accept calls only from the allowlist. // This is post-TIP-98 scenario. If the allowlist is not set, accept // calls only from the staking contract. This is pre-TIP-98 scenario. (_allowlist != address(0) && msg.sender == _allowlist) || (_allowlist == address(0) && msg.sender == address(staking)), "Caller is not the staking contract" ); _; } /// @notice Initializes V2 version of the WalletRegistry operating with the /// Allowlist contract, as a result of TIP-098 and TIP-100 governance /// decisions. function initializeV2(address _allowlist) external reinitializer(2) { allowlist = Allowlist(_allowlist); } /// @dev Provides the expected IStaking reference. If the allowlist is set, /// it acts as the staking contract. If it is not set, the TokenStaking /// acts as the staking contract. function _staking() internal returns (IStaking) { if (address(allowlist) != address(0)) { return IStaking(allowlist); } return staking; } ``` Note that the `WalletRegistry` is close to the maximum allowed contract size and - surprise! - adding the logic above makes it exceed the allowed size. This could potentially be alleviated by removing some of the functionality. For example, in the `challengeDkgResult` function we have a try catch as well as a call to `dkg.requireChallengeExtraGas()`. This could potentially be eliminated as a no-op `seize` in `Allowlist` is guaranteed to always succeed. Also, post [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702), the `require(msg.sender == tx.origin, "Not EOA")` check is no longer guaranteed to work as expected.
2 parents 138c970 + aac5e7e commit 406d4d3

52 files changed

Lines changed: 42875 additions & 3257 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/client.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ on:
1111
- "docs/**"
1212
- "infrastructure/**"
1313
- "scripts/**"
14+
- "solidity/**"
1415
- "solidity-v1/**"
1516
- "token-stakedrop/**"
1617
pull_request:
@@ -45,7 +46,7 @@ jobs:
4546
with:
4647
filters: |
4748
path-filter:
48-
- './!((docs-v1|docs|infrastructure|scripts|solidity-v1|token-stakedrop)/**)'
49+
- './!((docs-v1|docs|infrastructure|scripts|solidity|solidity-v1|token-stakedrop)/**)'
4950
5051
electrum-integration-detect-changes:
5152
runs-on: ubuntu-latest

.github/workflows/contracts-ecdsa.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ jobs:
109109
# As a workaround for a slither issue https://github.com/crytic/slither/issues/1140
110110
# we disable compilation of dependencies when running slither.
111111
- name: Run Slither
112-
run: SKIP_DEPENDENCY_COMPILER=true slither .
112+
run: SKIP_DEPENDENCY_COMPILER=true slither . --compile-force-framework hardhat
113113

114114
contracts-build-and-test:
115115
needs: contracts-detect-changes

solidity/ecdsa/.env.example

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# =============================================================================
2+
# Environment Configuration for keep-core/solidity/ecdsa
3+
# =============================================================================
4+
# Copy this file to .env and fill in your values.
5+
# NEVER commit .env files with private keys!
6+
# =============================================================================
7+
8+
# -----------------------------------------------------------------------------
9+
# RPC Endpoint (required for Sepolia and Mainnet)
10+
# -----------------------------------------------------------------------------
11+
# Use Alchemy, Infura, or another provider
12+
# Example: https://eth-sepolia.g.alchemy.com/v2/YOUR_API_KEY
13+
# Example: https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY
14+
CHAIN_API_URL=
15+
16+
# -----------------------------------------------------------------------------
17+
# Sepolia Configuration
18+
# -----------------------------------------------------------------------------
19+
# Comma-separated list of private keys (without 0x prefix)
20+
# The first key should correspond to: 0x68ad60CC5e8f3B7cC53beaB321cf0e6036962dBc
21+
ACCOUNTS_PRIVATE_KEYS=
22+
23+
# -----------------------------------------------------------------------------
24+
# Mainnet Configuration
25+
# -----------------------------------------------------------------------------
26+
# Single private key for the deployer account (without 0x prefix)
27+
# Should correspond to: 0x716089154304f22a2F9c8d2f8C45815183BF3532
28+
CONTRACT_OWNER_ACCOUNT_PRIVATE_KEY=
29+
30+
# -----------------------------------------------------------------------------
31+
# Contract Verification (optional but recommended)
32+
# -----------------------------------------------------------------------------
33+
# Get your API key from https://etherscan.io/myapikey
34+
ETHERSCAN_API_KEY=
35+
36+
# -----------------------------------------------------------------------------
37+
# Forking Configuration (optional, for local testing)
38+
# -----------------------------------------------------------------------------
39+
# URL for forking mainnet state (requires archive node access)
40+
# FORKING_URL=https://eth-mainnet.g.alchemy.com/v2/YOUR_API_KEY
41+
# FORKING_BLOCK=
42+
43+
# -----------------------------------------------------------------------------
44+
# External Deployments (optional)
45+
# -----------------------------------------------------------------------------
46+
# Set to "true" to use external contract deployments
47+
# USE_EXTERNAL_DEPLOY=false

solidity/ecdsa/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,13 @@ deployments/*
1313

1414
# OpenZeppelin
1515
.openzeppelin/unknown-*.json
16+
17+
# Environment variables (NEVER commit private keys!)
18+
.env
19+
.env.local
20+
.env.*.local
21+
.env.sepolia
22+
.env.mainnet
23+
24+
# Migration results (may contain sensitive info)
25+
migration-results.json

solidity/ecdsa/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lts/hydrogen

0 commit comments

Comments
 (0)