Commit 95cb2e6
authored
WalletRegistry Bytecode Optimization for EIP-170 Compliance (#3837)
## Summary
Optimized WalletRegistry to fit within Ethereum's 24KB contract size
limit while adding dual-mode authorization for beta staker
consolidation.
**Final Bytecode**: 23.824 KB
## Context
After adding the allowlist feature for beta staker consolidation (18 → 3
operators, 83% cost reduction per TIP-92/TIP-100), WalletRegistry
exceeded the 24KB contract size limit and could not be deployed. These
changes reduce bytecode while maintaining security properties and adding
required dual-mode authorization.
## Changes
### 1. Silent Slashing (Commit 73dbec6)
- **What**: Removed `DkgMaliciousResultSlashingFailed` event
- **Impact**: Slashing failures no longer emit events (detection via
event correlation)
- **Security**: Challenge completion still guaranteed; slashing success
still emitted
### 2. EIP-7702 Compatibility (Commit e2a35bc)
- **What**: Removed EOA-only restriction from `challengeDkgResult()`
- **Why**: Future-proof for account abstraction; gas protection via
inline `gasleft()` check
- **Impact**: Smart contract wallets can now challenge DKG results
- **Security**: Reentrancy and gas manipulation vectors expanded;
EIP-150 protection retained
### 3. Bytecode Optimizations (Commit e655538)
- **What**: Inlined `requireChallengeExtraGas()`, consolidated DKG state
checks, shortened error messages
- **Why**: Function call overhead and redundant state checks
- **Impact**: Pure optimization, no behavioral changes
### 4. Dual-Mode Authorization (Commit d2ddcb3)
- **What**: Added `Allowlist` state variable and modified
`onlyStakingContract` modifier
- **Why**: Enable migration from TokenStaking to weight-based Allowlist
- **Impact**:
- Starts in legacy mode (`allowlist = 0x0` → TokenStaking authorized)
- Calling `initializeV2(allowlist_address)` switches to allowlist mode
(irreversible)
- **Migration**: Controlled by governance multi-sig; testnet validated
before mainnet
### 5-6. Custom Error Migration (Commits 04ebe63, 357328b)
- **What**: Migrated 15 `require()` statements to custom errors
- **Impact**:
- ABI breaking change
- Go bindings require regeneration
- Test assertions need updating (`.revertedWith()` →
`.revertedWithCustomError()`)
## Trade-offs
**Prioritized**:
- Protocol security (DKG validation intact)
- Deployment capability (bytecode under 24KB)
- Future compatibility (EIP-7702, dual-mode authorization)
**Traded**:
- Direct observability (silent slashing failures)
- Simplicity (dual-mode authorization complexity)
- Client compatibility (ABI changes)
**Preserved**:
- Economic deterrents
- Validation logic
- Access controls
## Review Focus
### Critical
1. **Silent Slashing Economic Model**: Does economic security hold with
occasional undetectable slashing failures?
2. **Dual-Mode Authorization**: Edge cases in mode switching;
irreversibility implications
3. **EIP-7702 Attack Vectors**: Reentrancy with contract callers; gas
manipulation via proxies
### Important
4. **Custom Error Logical Equivalence**: All 15 conversions maintain
correctness
5. **Storage Layout Safety**: Proxy upgrade compatibility; no storage
collisions
6. **Allowlist Single Point of Failure**: Post-upgrade dependency on
Allowlist contract
### Operational
7. **Deployment Order**: Allowlist → WalletRegistry V2 → Proxy upgrade
with `initializeV2()`
8. **Rollback Strategy**: Irreversible mode switch; contingency if
Allowlist has critical bug
9. **Testnet Validation**: Storage preservation, dual-mode
authorization, edge cases
## Known Issues
- **Observability Gap**: Slashing failures not directly observable
(mitigation: event correlation)
- **Irreversible Mode Switch**: Cannot revert to legacy after
`initializeV2()` (mitigation: Allowlist upgradeability, testnet
validation)
- **ABI Breaking Changes**: Client updates required (mitigation: Go
bindings regeneration)
## Test Status
- **Current**: 758/772 passing (98.2%)
- **Pending**: 14 test assertions need custom error updates
## Files Changed
- `solidity/ecdsa/contracts/WalletRegistry.sol`
- `solidity/ecdsa/contracts/libraries/EcdsaDkg.sol`
- `solidity/ecdsa/test/WalletRegistry.CustomErrors.test.ts` (NEW)
- Multiple test files updated for custom errors
## External Dependencies
- **No Changes**: SortitionPool, RandomBeacon, TokenStaking
- **New Dependency**: Allowlist (separately audited)File tree
25 files changed
+7616
-3080
lines changed- .github/workflows
- solidity/ecdsa
- contracts
- libraries
- test/upgrades
- deploy
- docs
- test
- fixtures
- utils
25 files changed
+7616
-3080
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | | - | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
123 | 124 | | |
124 | 125 | | |
125 | 126 | | |
126 | | - | |
| 127 | + | |
127 | 128 | | |
128 | 129 | | |
129 | 130 | | |
| |||
189 | 190 | | |
190 | 191 | | |
191 | 192 | | |
192 | | - | |
| 193 | + | |
193 | 194 | | |
194 | 195 | | |
195 | 196 | | |
| |||
309 | 310 | | |
310 | 311 | | |
311 | 312 | | |
312 | | - | |
| 313 | + | |
313 | 314 | | |
314 | 315 | | |
315 | 316 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
361 | | - | |
| 361 | + | |
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
| |||
447 | 447 | | |
448 | 448 | | |
449 | 449 | | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | 450 | | |
469 | 451 | | |
470 | 452 | | |
| |||
480 | 462 | | |
481 | 463 | | |
482 | 464 | | |
| 465 | + | |
| 466 | + | |
483 | 467 | | |
484 | 468 | | |
485 | 469 | | |
486 | | - | |
487 | | - | |
488 | | - | |
| 470 | + | |
489 | 471 | | |
490 | 472 | | |
491 | 473 | | |
492 | 474 | | |
493 | 475 | | |
| 476 | + | |
| 477 | + | |
494 | 478 | | |
495 | 479 | | |
496 | 480 | | |
497 | 481 | | |
498 | | - | |
499 | | - | |
500 | 482 | | |
501 | 483 | | |
502 | | - | |
| 484 | + | |
503 | 485 | | |
504 | 486 | | |
505 | 487 | | |
| |||
508 | 490 | | |
509 | 491 | | |
510 | 492 | | |
| 493 | + | |
| 494 | + | |
511 | 495 | | |
512 | 496 | | |
513 | 497 | | |
514 | 498 | | |
515 | | - | |
516 | | - | |
517 | 499 | | |
518 | 500 | | |
519 | 501 | | |
520 | 502 | | |
| 503 | + | |
| 504 | + | |
521 | 505 | | |
522 | 506 | | |
523 | 507 | | |
524 | 508 | | |
525 | | - | |
526 | | - | |
527 | 509 | | |
528 | 510 | | |
529 | | - | |
| 511 | + | |
530 | 512 | | |
531 | 513 | | |
532 | 514 | | |
533 | 515 | | |
534 | 516 | | |
535 | 517 | | |
| 518 | + | |
| 519 | + | |
536 | 520 | | |
537 | 521 | | |
538 | 522 | | |
| |||
542 | 526 | | |
543 | 527 | | |
544 | 528 | | |
545 | | - | |
| 529 | + | |
546 | 530 | | |
547 | 531 | | |
548 | 532 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
775 | 775 | | |
776 | 776 | | |
777 | 777 | | |
778 | | - | |
779 | | - | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
780 | 784 | | |
781 | 785 | | |
782 | 786 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
790 | 790 | | |
791 | 791 | | |
792 | 792 | | |
793 | | - | |
794 | | - | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
795 | 799 | | |
796 | 800 | | |
797 | 801 | | |
| |||
Lines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
789 | 789 | | |
790 | 790 | | |
791 | 791 | | |
792 | | - | |
793 | | - | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
794 | 798 | | |
795 | 799 | | |
796 | 800 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
| 51 | + | |
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| |||
0 commit comments