Commit 172d9b0
authored
Advance XMSS key preparation window before signing (#261)
## Summary
- Expose `is_prepared_for(slot)` and `advance_preparation()` on
`ValidatorSecretKey`, delegating to the leansig
`SignatureSchemeSecretKey` trait
- Before signing in `KeyManager::sign_message()`, check if the target
slot is within the prepared window and advance if needed
- Return a descriptive error if the key's activation interval is fully
exhausted
- Add a timing test for `advance_preparation()` (526ms in release mode
on Apple Silicon)
## Root Cause
XMSS keys use a Top-Bottom Tree Traversal scheme where only two
consecutive bottom trees are loaded in memory at any time. Each bottom
tree covers `sqrt(LIFETIME) = 2^16 = 65,536` slots, so the prepared
window spans `131,072` slots (~6 days at 4s/slot).
The leansig library provides `advance_preparation()` to slide this
window forward by computing the next bottom tree, but ethlambda's
`KeyManager` never called it. When the devnet at `admin@ethlambda-1`
reached slot 131,072, all 4 nodes panicked simultaneously:
```
Signing: key not yet prepared for this epoch, try calling sk.advance_preparation.
```
The fix checks the prepared interval before every sign operation and
advances the window on demand. This is a lazy approach —
`advance_preparation` is called at signing time rather than proactively
in the tick loop — because:
- It happens once every ~3 days (65,536 slots)
- The computation (one bottom tree of hash leaves) takes ~526ms in
release mode
- It keeps the change minimal and avoids tick-loop complexity
## Test plan
- [x] `make fmt` clean
- [x] `make lint` clean
- [x] `make test` passes (existing tests use small lifetimes or skip
verification)
- [x] `test_advance_preparation_duration` passes (`cargo test -p
ethlambda-types test_advance_preparation_duration --release -- --ignored
--nocapture`)
- [ ] Deploy to devnet with fresh genesis and verify it runs past slot
131,072 without panic1 parent 1345286 commit 172d9b0
4 files changed
Lines changed: 105 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
105 | 123 | | |
106 | 124 | | |
107 | 125 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
1 | 3 | | |
2 | 4 | | |
3 | | - | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
| |||
97 | 99 | | |
98 | 100 | | |
99 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
100 | 184 | | |
0 commit comments