Commit 6746d32
authored
chore: Reduce gas cost for tally slash proposer (#16617)
Reduce gas cost for executing a slash in the tally slash proposer.
Builds on
[16514](#16514).
## L1 changes
- Votes are represented with fixed-size arrays, so we save a storage
operation by not having to store or load the array length.
- Slash payloads are implemented using EIP1167 clones to reduce
deployment cost.
- Tally matrix is compacted to reduce memory usage, and votes are
processed in batches with early exits (since most vote arrays will be
sparse).
- Add a config option to deploy no slasher.
- Generic improvements like unchecked operations, loop unrolling, using
calldata over memory, etc.
## Other changes
- Add extra checks during deployment to alert if a tx reverted.
- Default tests to deploy no slasher (required to avoid triggering new
validations in the tally slashing proposer contract that failed when
epoch lengths were set to very small values).
## Gas benchmarks
Given the following settings:
```
uint256 constant VALIDATOR_COUNT = 128;
uint256 constant COMMITTEE_SIZE = 48;
uint256 constant ROUND_SIZE_IN_EPOCHS = 6;
uint256 constant EPOCH_DURATION = 32;
```
Gas costs before and after this change:
| How many slashed | Before | After | Reduction |
| -------- | -------- | -------- | -- |
| 1 | 4003168 | 1461217 | 63% |
| 48 | 12299046 | 8362076 | 32% |File tree
23 files changed
+1202
-140
lines changed- l1-contracts
- src
- core
- interfaces
- libraries
- slashing
- periphery
- test
- governance/scenario/slashing
- slashing
- yarn-project
- end-to-end/src
- e2e_epochs
- e2e_p2p
- fixtures
- ethereum/src
- contracts
23 files changed
+1202
-140
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
241 | | - | |
| 241 | + | |
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
200 | 204 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
0 commit comments