Skip to content

Commit 35bb5fc

Browse files
authored
Merge pull request #18 from DLC-link/feat/compaction
Pre-audit cleanup
2 parents 67a8ed7 + 1bf020e commit 35bb5fc

File tree

5 files changed

+80
-82
lines changed

5 files changed

+80
-82
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 DLC.Link
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 12 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
1-
# dlc-symbiotic
2-
3-
Repository for the dlc-link Symbiotic integration.
4-
5-
### Slashing
6-
7-
<img src="./assets/slash_flow.png" alt="slash_flow" width="100%" />
8-
9-
## Usage
10-
11-
You can start a local Sepolia fork using:
12-
13-
```shell
14-
anvil --fork-url https://eth-sepolia.g.alchemy.com/v2/your-api-key
15-
```
16-
17-
And deploy the NetworkMiddleware contract using:
18-
19-
```shell
20-
forge script SetupNetworkMiddleware --rpc-url http://localhost:8545 --broadcast -vvvv --private-key 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
21-
```
22-
23-
24-
## Workflow and Dependencies
1+
[![Tests](https://github.com/DLC-link/dlc-symbiotic/actions/workflows/test.yml/badge.svg)](https://github.com/DLC-link/dlc-symbiotic/actions/workflows/test.yml)
252

26-
<img src="./assets/workflow_and_dependencies.png" alt="workflow_and_dependencies" width="100%" />
3+
# dlc-symbiotic
274

5+
Repository for iBTC Network's Symbiotic integration.
286

297
## Development
308

@@ -40,40 +18,24 @@ $ forge build
4018
$ forge test
4119
```
4220

43-
### Format
44-
45-
```shell
46-
$ forge fmt
47-
```
48-
49-
### Gas Snapshots
50-
51-
```shell
52-
$ forge snapshot
53-
```
21+
## Usage
5422

55-
### Anvil
23+
You can start a local Sepolia fork using:
5624

5725
```shell
58-
$ anvil
26+
anvil --fork-url https://eth-sepolia.g.alchemy.com/v2/your-api-key
5927
```
6028

61-
### Deploy
29+
And deploy a standard configuration of a Vault and the NetworkMiddleware contract using:
6230

6331
```shell
64-
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
32+
forge script DeployAll 11155111 --rpc-url http://localhost:8545 --broadcast -vvvv --private-key 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d --sig 'run(uint256)'
6533
```
6634

67-
### Cast
35+
## Workflow and Dependencies
6836

69-
```shell
70-
$ cast <subcommand>
71-
```
37+
<img src="./assets/workflow_and_dependencies.png" alt="workflow_and_dependencies" width="100%" />
7238

73-
### Help
39+
### Slashing
7440

75-
```shell
76-
$ forge --help
77-
$ anvil --help
78-
$ cast --help
79-
```
41+
<img src="./assets/slash_flow.png" alt="slash_flow" width="100%" />

foundry.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ ast = true
33
build_info = true
44
extra_output = ["storageLayout"]
55
ffi = true
6-
fs_permissions = [{access = "read", path = "script/addresses"}]
6+
fs_permissions = [{ access = "read", path = "script/addresses" }]
77
libs = ["lib"]
88
out = "out"
99
solc = "0.8.25"
1010
src = "src"
1111
via_ir = true
12+
optimizer = true
13+
optimizer-runs = 200
1214

1315
[fmt]
1416
bracket_spacing = false

script/0.Deploy_All.s.sol

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ contract DeployAll is Script {
4646
address VAULT_FACTORY;
4747
address DELEGATOR_FACTORY;
4848
address SLASHER_FACTORY;
49-
address NEWTORK_OPTIN_SERVICE;
49+
address NETWORK_OPTIN_SERVICE;
5050
address VAULT_OPTIN_SERVICE;
5151
address DEFAULT_STAKER_REWARDS_FACTORY;
5252
address DEFAULT_OPERATOR_REWARDS_FACTORY;
@@ -96,6 +96,7 @@ contract DeployAll is Script {
9696

9797
ProxyAdmin public proxyAdmin;
9898
TransparentUpgradeableProxy public proxy;
99+
TransparentUpgradeableProxy private gr_proxy;
99100

100101
function run(
101102
uint256 _chainId
@@ -104,11 +105,11 @@ contract DeployAll is Script {
104105
NETWORK_MIDDLEWARE_SERVICE = readFile.readInput(_chainId, "symbiotic", "NETWORK_MIDDLEWARE_SERVICE");
105106
NETWORK_REGISTRY = readFile.readInput(_chainId, "symbiotic", "NETWORK_REGISTRY");
106107
OPERATOR_REGISTRY = readFile.readInput(_chainId, "symbiotic", "OPERATOR_REGISTRY");
107-
COLLATERAL = readFile.readInput(_chainId, "symbiotic", "COLLATERAL");
108+
COLLATERAL = readFile.readInput(_chainId, "iBTC", "COLLATERAL");
108109
VAULT_FACTORY = readFile.readInput(_chainId, "symbiotic", "VAULT_FACTORY");
109110
DELEGATOR_FACTORY = readFile.readInput(_chainId, "symbiotic", "DELEGATOR_FACTORY");
110111
SLASHER_FACTORY = readFile.readInput(_chainId, "symbiotic", "SLASHER_FACTORY");
111-
NEWTORK_OPTIN_SERVICE = readFile.readInput(_chainId, "symbiotic", "NEWTORK_OPTIN_SERVICE");
112+
NETWORK_OPTIN_SERVICE = readFile.readInput(_chainId, "symbiotic", "NETWORK_OPTIN_SERVICE");
112113
VAULT_OPTIN_SERVICE = readFile.readInput(_chainId, "symbiotic", "VAULT_OPTIN_SERVICE");
113114
DEFAULT_STAKER_REWARDS_FACTORY = readFile.readInput(_chainId, "symbiotic", "DEFAULT_STAKER_REWARDS_FACTORY");
114115
DEFAULT_OPERATOR_REWARDS_FACTORY = readFile.readInput(_chainId, "symbiotic", "DEFAULT_OPERATOR_REWARDS_FACTORY");
@@ -124,8 +125,14 @@ contract DeployAll is Script {
124125
// ---------------------------------- Start Vault Deployment ----------------------------------
125126

126127
// ------------------------------- Start Global Receiver Deployment -------------------------------
127-
iBTC_globalReceiver = new iBTC_GlobalReceiver();
128-
iBTC_globalReceiver.initialize(COLLATERAL, OWNER);
128+
iBTC_GlobalReceiver grImplementation = new iBTC_GlobalReceiver();
129+
gr_proxy = new TransparentUpgradeableProxy(
130+
address(grImplementation),
131+
OWNER,
132+
abi.encodeWithSelector(iBTC_GlobalReceiver.initialize.selector, COLLATERAL, OWNER)
133+
);
134+
proxyAdmin = ProxyAdmin(_getAdminAddress(address(gr_proxy)));
135+
iBTC_globalReceiver = iBTC_GlobalReceiver(address(gr_proxy));
129136
// ------------------------------- End Global Receiver Deployment -------------------------------
130137

131138
// ------------------------------- Start Vault Configurator Deployment -------------------------------
@@ -234,7 +241,7 @@ contract DeployAll is Script {
234241
NETWORK,
235242
OPERATOR_REGISTRY,
236243
VAULT_FACTORY,
237-
NEWTORK_OPTIN_SERVICE,
244+
NETWORK_OPTIN_SERVICE,
238245
OWNER,
239246
STAKER_REWARDS,
240247
OPERATOR_REWARDS,

src/iBTC_NetworkMiddleware.sol

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ contract NetworkMiddleware is Initializable, SimpleKeyRegistry32, OwnableUpgrade
4141
error ZeroRewardToken();
4242
error ZeroEpochDuration();
4343
error ZeroSlashingWindow();
44+
error ZeroStakerReward();
45+
error ZeroOperatorNetOptin();
4446

4547
error NotOperator();
4648
error NotVault();
@@ -61,9 +63,7 @@ contract NetworkMiddleware is Initializable, SimpleKeyRegistry32, OwnableUpgrade
6163
error InvalidEpoch();
6264

6365
error SlashingWindowTooShort();
64-
error TooBigSlashAmount();
6566
error UnknownSlasherType();
66-
error NotVetoSlasher();
6767

6868
error ZeroTotalStake();
6969
error ZeroRewardAmount();
@@ -77,13 +77,6 @@ contract NetworkMiddleware is Initializable, SimpleKeyRegistry32, OwnableUpgrade
7777
bytes32 key;
7878
}
7979

80-
struct SlashedInfo {
81-
uint48 epoch;
82-
address operator;
83-
uint256 slashedAmount;
84-
uint256 timeStamp;
85-
}
86-
8780
address public NETWORK;
8881
address public OPERATOR_REGISTRY;
8982
address public VAULT_REGISTRY;
@@ -96,14 +89,13 @@ contract NetworkMiddleware is Initializable, SimpleKeyRegistry32, OwnableUpgrade
9689
uint48 public EPOCH_DURATION;
9790
uint48 public SLASHING_WINDOW;
9891
uint48 public START_TIME;
99-
bytes32 public constant REWARD_DISTRIBUTION_ROLE = keccak256("REWARD_DISTRIBUTION_ROLE");
92+
bytes32 public constant REWARD_DISTRIBUTION_ROLE =
93+
0x9f89a45310bee56665a077229020c3130eedbd18bff771c3dc399fb850b2e12f; // keccak256("REWARD_DISTRIBUTION_ROLE");
10094

10195
uint48 private constant INSTANT_SLASHER_TYPE = 0;
10296
uint48 private constant VETO_SLASHER_TYPE = 1;
10397

104-
uint256 public slashIndex;
10598
uint256 public subnetworksCnt;
106-
mapping(uint256 slashIndex => SlashedInfo) slashedInfos;
10799
mapping(uint48 => uint256) public totalStakeCache;
108100
mapping(uint48 => bool) public totalStakeCached;
109101
mapping(uint48 epoch => mapping(address operator => uint256 amounts)) public operatorStakeCache;
@@ -151,13 +143,33 @@ contract NetworkMiddleware is Initializable, SimpleKeyRegistry32, OwnableUpgrade
151143
__Ownable_init(_owner);
152144
MultisigValidated.initialize(_owner, _minimumThreshold, _threshold);
153145

154-
_checkNonZeroAddress(_network, "ZeroNetwork");
155-
_checkNonZeroAddress(_operatorRegistry, "ZeroOperatorRegistry");
156-
_checkNonZeroAddress(_vaultRegistry, "ZeroVaultRegistry");
157-
_checkNonZeroAddress(_operatorNetOptin, "ZeroOperatorNetOptin");
158-
_checkNonZeroAddress(_owner, "ZeroOwner");
159-
_checkNonZeroAddress(_stakerReward, "ZeroStakerReward");
160-
_checkNonZeroAddress(_operatorReward, "ZeroOperatorReward");
146+
if (_network == address(0)) {
147+
revert ZeroNetwork();
148+
}
149+
150+
if (_operatorRegistry == address(0)) {
151+
revert ZeroOperatorRegistry();
152+
}
153+
154+
if (_vaultRegistry == address(0)) {
155+
revert ZeroVaultRegistry();
156+
}
157+
158+
if (_operatorNetOptin == address(0)) {
159+
revert ZeroOperatorNetOptin();
160+
}
161+
162+
if (_owner == address(0)) {
163+
revert ZeroOwner();
164+
}
165+
166+
if (_stakerReward == address(0)) {
167+
revert ZeroStakerReward();
168+
}
169+
170+
if (_operatorReward == address(0)) {
171+
revert ZeroOperatorReward();
172+
}
161173

162174
if (_slashingWindow < _epochDuration) {
163175
revert SlashingWindowTooShort();
@@ -520,12 +532,6 @@ contract NetworkMiddleware is Initializable, SimpleKeyRegistry32, OwnableUpgrade
520532
return enabledTime != 0 && enabledTime <= timestamp && (disabledTime == 0 || disabledTime >= timestamp);
521533
}
522534

523-
function _checkNonZeroAddress(address addr, string memory errorMessage) private pure {
524-
if (addr == address(0)) {
525-
revert(errorMessage);
526-
}
527-
}
528-
529535
function _slashVault(
530536
uint48 timestamp,
531537
address vault,

0 commit comments

Comments
 (0)