We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Miscellaneous beacon chain changes—take 4
(See #128, #218, #322 for takes 1, 2, 3.)

Below is a list of miscellaneous suggestions for phase 0, most of which were discussed on the researcher's call on Feb 19. This issue keeps track of some of the phase 0 work remaining.

- [x] 1. **Friendlier GENESIS_SLOT**: Implemented in #655.
- [x] 2. **Granular state roots**: Expose state roots at every slot. Implemented in #649.
- [x] 3. **Previous block root reconstruction**: Provide enough information in `state` to reconstruct the current block's `previous_block_root`. Implemented in #649.
- [x] 4. **Define genesis Eth1 data**: Implemented in #649.
- [x] 5. **Mandatory deposits**: Mandatory processing of pending deposits.
- [x] 6. **Transfers during pre-activation**: Allow not-yet-activated validators to make transfers.
- [x] 7. **LMD GHOST tie breaker**: Compare block hashes to tie-break LMD GHOST.
- [ ] 8. **Maximum reversions**: Enshrine dynamic weak subjectivity revert period. See #577.
- [x] 9. **Double justifications**: Specify fork choice rule when there are two justified blocks at the same height. (Possible solution: ignore both and fallback to the previous highest justified block.)
- [x] 10. **Move to SHA256**: See #612.
- [ ] 11. **Standardise BLS12-381**: See #605.
- [ ] 12. **Performance parameters tuning**: Fine-tune `SECONDS_PER_SLOT`, `SHARD_COUNT`, etc. based on benchmarks.
- [ ] 13a. **Increase proposer rewards**: See #621. Need to check incentive compatibility with inclusion distance reward.
- [x] 13b. **Incentive-compatible proposer rewards**: Make proposer rewards proportional to balance. 
- [ ] 14. **Increase rewards in general**: Calculate theoretical max issuance rate and work backwards to expected issuance.
- [x] 15. **Reduce SSZ_CHUNK_SIZE to 32**: See #603 and #696.
- [x] 16. **SSZ tuples**: See #665 and #696.
- [x] <s>17. **Immediately withdrawable if bad proof of possession**: See #657.</s>
- [x] 18. **4-byte working balance**: See #685.
- [x] 19. **Merkleisation-friendly pending attestations**: See #697.
- [ ] 20. **Fine-tune container field ordering**: To do with constants fine-tuning.
- [x] 21. **Minimum activation period**: See [here](https://github.com/ethereum/eth2.0-specs/issues/675#issuecomment-468159678) and [here](https://github.com/ethereum/eth2.0-specs/pull/746).
- [x] 22. **Milder ejections**: Replace `exit_validator` by `initiate_validator_exit` in `process_ejections`.
- [x] 23. **Improved rate limiting**: Change the rate limiting logic (for entry/exit/withdrawal) based on [this Ethresear.ch post](https://ethresear.ch/t/rate-limiting-entry-exits-not-withdrawals/4942).
- [x] 24. **Epoch transitions at start of epoch**: Instead of at the very end of the epoch.
- [x] 25. **Epoch-based proposer slashing**: As opposed to slot-based.
- [x] 26. **Genesis epochs**: Use `GENESIS_EPOCH - 1` for `previous_shuffling_epoch` and maybe `previous_shuffling_epoch`.
- [x] <s>27. **No backfilling of latest_active_index_roots**: Only set the active index root for the first slot.</s>
- [x] 28. <s>**`start_shard` offsets**: For fairer crosslinking latency across shards.</s>
- [x] 29. **Remove deposit timestamps and `DepositData`**: See #760.
- [x] 30. **Fair proposer sampling**: See #733.
- [ ] 31. **Slashed validators and LMD GHOST**: Should attestations from slashed validators be ignored in LMD GHOST?
- [x] 32. **Incentives simplification**: Simplification of the rewards and penalties.
- [ ] 33. **Exit fee**: See [here](https://github.com/ethereum/eth2.0-specs/pull/850#issuecomment-478068655).
- [x] 34. **GENESIS_SLOT == 0**: From Danny.
- [ ] 35. **Incentive-compatible crosslink rewards**: Proportional to amount of crosslink data.
- [ ] 36. **No phase 0 transfers**: Push transfers to phase 1 so that no economically meaningful activity happens during phase 0. This allows for phase 0 (a "testnet") to be rebooted if things go horribly wrong.
- [ ] 37. **Explicit genesis deposits**: Put genesis deposits in `block.body.deposits`.
- [x] 38. **Remove serialization from consensus**: See #924.
- [ ] 39. **Do not store withdrawal credentials**: See #937.
- [ ] 40. **Increase SECONDS_PER_SLOT and remove MIN_ATTESTATION_INCLUSION_DELAY**: The idea is to set different `SECONDS_PER_BEACON_SLOT`and `SECONDS_PER_SHARD_SLOT`, e.g. to 8/4, 12/3 or 16/4.
- [ ] 41. **The slotering**: Remove various unnecessary slots and replace by epochs where appropriate. (Justin surprise cleanup.)
- [x] 42. **Graffiti**: 32-byte arbitrary data in blocks
- [ ] 43. **Merge historical stats**: In particular, merge constants under "State list lengths".
- [ ] 44. **Improve epoch processing**: See #1043.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `utils/phase0/state_transition.py`
Content:
```
1 from . import spec
2 
3 
4 from typing import (  # noqa: F401
5     Any,
6     Callable,
7     List,
8     NewType,
9     Tuple,
10 )
11 
12 from .spec import (
13     BeaconState,
14     BeaconBlock,
15 )
16 
17 
18 def process_transaction_type(state: BeaconState,
19                              transactions: List[Any],
20                              max_transactions: int,
21                              tx_fn: Callable[[BeaconState, Any], None]) -> None:
22     assert len(transactions) <= max_transactions
23     for transaction in transactions:
24         tx_fn(state, transaction)
25 
26 
27 def process_transactions(state: BeaconState, block: BeaconBlock) -> None:
28     process_transaction_type(
29         state,
30         block.body.proposer_slashings,
31         spec.MAX_PROPOSER_SLASHINGS,
32         spec.process_proposer_slashing,
33     )
34     process_transaction_type(
35         state,
36         block.body.attester_slashings,
37         spec.MAX_ATTESTER_SLASHINGS,
38         spec.process_attester_slashing,
39     )
40     process_transaction_type(
41         state,
42         block.body.attestations,
43         spec.MAX_ATTESTATIONS,
44         spec.process_attestation,
45     )
46     process_transaction_type(
47         state,
48         block.body.deposits,
49         spec.MAX_DEPOSITS,
50         spec.process_deposit,
51     )
52     process_transaction_type(
53         state,
54         block.body.voluntary_exits,
55         spec.MAX_VOLUNTARY_EXITS,
56         spec.process_voluntary_exit,
57     )
58     assert len(block.body.transfers) == len(set(block.body.transfers))
59     process_transaction_type(
60         state,
61         block.body.transfers,
62         spec.MAX_TRANSFERS,
63         spec.process_transfer,
64     )
65 
66 
67 def process_block(state: BeaconState,
68                   block: BeaconBlock,
69                   verify_state_root: bool=False) -> None:
70     spec.process_block_header(state, block)
71     spec.process_randao(state, block)
72     spec.process_eth1_data(state, block)
73 
74     process_transactions(state, block)
75     if verify_state_root:
76         spec.verify_block_state_root(state, block)
77 
78 
79 def process_epoch_transition(state: BeaconState) -> None:
80     spec.update_justification_and_finalization(state)
81     spec.process_crosslinks(state)
82     spec.maybe_reset_eth1_period(state)
83     spec.apply_rewards(state)
84     spec.process_ejections(state)
85     spec.update_registry_and_shuffling_data(state)
86     spec.process_slashings(state)
87     spec.process_exit_queue(state)
88     spec.finish_epoch_update(state)
89 
90 
91 def state_transition(state: BeaconState,
92                      block: BeaconBlock,
93                      verify_state_root: bool=False) -> BeaconState:
94     while state.slot < block.slot:
95         spec.cache_state(state)
96         if (state.slot + 1) % spec.SLOTS_PER_EPOCH == 0:
97             process_epoch_transition(state)
98         spec.advance_slot(state)
99         if block.slot == state.slot:
100             process_block(state, block, verify_state_root)
101
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/utils/phase0/state_transition.py b/utils/phase0/state_transition.py
--- a/utils/phase0/state_transition.py
+++ b/utils/phase0/state_transition.py
@@ -15,6 +15,13 @@
 )
 
 
+def expected_deposit_count(state: BeaconState) -> int:
+    return min(
+        spec.MAX_DEPOSITS,
+        state.latest_eth1_data.deposit_count - state.deposit_index
+    )
+
+
 def process_transaction_type(state: BeaconState,
                              transactions: List[Any],
                              max_transactions: int,
@@ -31,30 +38,36 @@
         spec.MAX_PROPOSER_SLASHINGS,
         spec.process_proposer_slashing,
     )
+
     process_transaction_type(
         state,
         block.body.attester_slashings,
         spec.MAX_ATTESTER_SLASHINGS,
         spec.process_attester_slashing,
     )
+
     process_transaction_type(
         state,
         block.body.attestations,
         spec.MAX_ATTESTATIONS,
         spec.process_attestation,
     )
+
+    assert len(block.body.deposits) == expected_deposit_count(state)
     process_transaction_type(
         state,
         block.body.deposits,
         spec.MAX_DEPOSITS,
         spec.process_deposit,
     )
+
     process_transaction_type(
         state,
         block.body.voluntary_exits,
         spec.MAX_VOLUNTARY_EXITS,
         spec.process_voluntary_exit,
     )
+
     assert len(block.body.transfers) == len(set(block.body.transfers))
     process_transaction_type(
         state,

{"golden_diff": "diff --git a/utils/phase0/state_transition.py b/utils/phase0/state_transition.py\n--- a/utils/phase0/state_transition.py\n+++ b/utils/phase0/state_transition.py\n@@ -15,6 +15,13 @@\n )\n \n \n+def expected_deposit_count(state: BeaconState) -> int:\n+    return min(\n+        spec.MAX_DEPOSITS,\n+        state.latest_eth1_data.deposit_count - state.deposit_index\n+    )\n+\n+\n def process_transaction_type(state: BeaconState,\n                              transactions: List[Any],\n                              max_transactions: int,\n@@ -31,30 +38,36 @@\n         spec.MAX_PROPOSER_SLASHINGS,\n         spec.process_proposer_slashing,\n     )\n+\n     process_transaction_type(\n         state,\n         block.body.attester_slashings,\n         spec.MAX_ATTESTER_SLASHINGS,\n         spec.process_attester_slashing,\n     )\n+\n     process_transaction_type(\n         state,\n         block.body.attestations,\n         spec.MAX_ATTESTATIONS,\n         spec.process_attestation,\n     )\n+\n+    assert len(block.body.deposits) == expected_deposit_count(state)\n     process_transaction_type(\n         state,\n         block.body.deposits,\n         spec.MAX_DEPOSITS,\n         spec.process_deposit,\n     )\n+\n     process_transaction_type(\n         state,\n         block.body.voluntary_exits,\n         spec.MAX_VOLUNTARY_EXITS,\n         spec.process_voluntary_exit,\n     )\n+\n     assert len(block.body.transfers) == len(set(block.body.transfers))\n     process_transaction_type(\n         state,\n", "issue": "Miscellaneous beacon chain changes\u2014take 4\n(See #128, #218, #322 for takes 1, 2, 3.)\r\n\r\nBelow is a list of miscellaneous suggestions for phase 0, most of which were discussed on the researcher's call on Feb 19. This issue keeps track of some of the phase 0 work remaining.\r\n\r\n- [x] 1. **Friendlier GENESIS_SLOT**: Implemented in #655.\r\n- [x] 2. **Granular state roots**: Expose state roots at every slot. Implemented in #649.\r\n- [x] 3. **Previous block root reconstruction**: Provide enough information in `state` to reconstruct the current block's `previous_block_root`. Implemented in #649.\r\n- [x] 4. **Define genesis Eth1 data**: Implemented in #649.\r\n- [x] 5. **Mandatory deposits**: Mandatory processing of pending deposits.\r\n- [x] 6. **Transfers during pre-activation**: Allow not-yet-activated validators to make transfers.\r\n- [x] 7. **LMD GHOST tie breaker**: Compare block hashes to tie-break LMD GHOST.\r\n- [ ] 8. **Maximum reversions**: Enshrine dynamic weak subjectivity revert period. See #577.\r\n- [x] 9. **Double justifications**: Specify fork choice rule when there are two justified blocks at the same height. (Possible solution: ignore both and fallback to the previous highest justified block.)\r\n- [x] 10. **Move to SHA256**: See #612.\r\n- [ ] 11. **Standardise BLS12-381**: See #605.\r\n- [ ] 12. **Performance parameters tuning**: Fine-tune `SECONDS_PER_SLOT`, `SHARD_COUNT`, etc. based on benchmarks.\r\n- [ ] 13a. **Increase proposer rewards**: See #621. Need to check incentive compatibility with inclusion distance reward.\r\n- [x] 13b. **Incentive-compatible proposer rewards**: Make proposer rewards proportional to balance. \r\n- [ ] 14. **Increase rewards in general**: Calculate theoretical max issuance rate and work backwards to expected issuance.\r\n- [x] 15. **Reduce SSZ_CHUNK_SIZE to 32**: See #603 and #696.\r\n- [x] 16. **SSZ tuples**: See #665 and #696.\r\n- [x] <s>17. **Immediately withdrawable if bad proof of possession**: See #657.</s>\r\n- [x] 18. **4-byte working balance**: See #685.\r\n- [x] 19. **Merkleisation-friendly pending attestations**: See #697.\r\n- [ ] 20. **Fine-tune container field ordering**: To do with constants fine-tuning.\r\n- [x] 21. **Minimum activation period**: See [here](https://github.com/ethereum/eth2.0-specs/issues/675#issuecomment-468159678) and [here](https://github.com/ethereum/eth2.0-specs/pull/746).\r\n- [x] 22. **Milder ejections**: Replace `exit_validator` by `initiate_validator_exit` in `process_ejections`.\r\n- [x] 23. **Improved rate limiting**: Change the rate limiting logic (for entry/exit/withdrawal) based on [this Ethresear.ch post](https://ethresear.ch/t/rate-limiting-entry-exits-not-withdrawals/4942).\r\n- [x] 24. **Epoch transitions at start of epoch**: Instead of at the very end of the epoch.\r\n- [x] 25. **Epoch-based proposer slashing**: As opposed to slot-based.\r\n- [x] 26. **Genesis epochs**: Use `GENESIS_EPOCH - 1` for `previous_shuffling_epoch` and maybe `previous_shuffling_epoch`.\r\n- [x] <s>27. **No backfilling of latest_active_index_roots**: Only set the active index root for the first slot.</s>\r\n- [x] 28. <s>**`start_shard` offsets**: For fairer crosslinking latency across shards.</s>\r\n- [x] 29. **Remove deposit timestamps and `DepositData`**: See #760.\r\n- [x] 30. **Fair proposer sampling**: See #733.\r\n- [ ] 31. **Slashed validators and LMD GHOST**: Should attestations from slashed validators be ignored in LMD GHOST?\r\n- [x] 32. **Incentives simplification**: Simplification of the rewards and penalties.\r\n- [ ] 33. **Exit fee**: See [here](https://github.com/ethereum/eth2.0-specs/pull/850#issuecomment-478068655).\r\n- [x] 34. **GENESIS_SLOT == 0**: From Danny.\r\n- [ ] 35. **Incentive-compatible crosslink rewards**: Proportional to amount of crosslink data.\r\n- [ ] 36. **No phase 0 transfers**: Push transfers to phase 1 so that no economically meaningful activity happens during phase 0. This allows for phase 0 (a \"testnet\") to be rebooted if things go horribly wrong.\r\n- [ ] 37. **Explicit genesis deposits**: Put genesis deposits in `block.body.deposits`.\r\n- [x] 38. **Remove serialization from consensus**: See #924.\r\n- [ ] 39. **Do not store withdrawal credentials**: See #937.\r\n- [ ] 40. **Increase SECONDS_PER_SLOT and remove MIN_ATTESTATION_INCLUSION_DELAY**: The idea is to set different `SECONDS_PER_BEACON_SLOT`and `SECONDS_PER_SHARD_SLOT`, e.g. to 8/4, 12/3 or 16/4.\r\n- [ ] 41. **The slotering**: Remove various unnecessary slots and replace by epochs where appropriate. (Justin surprise cleanup.)\r\n- [x] 42. **Graffiti**: 32-byte arbitrary data in blocks\r\n- [ ] 43. **Merge historical stats**: In particular, merge constants under \"State list lengths\".\r\n- [ ] 44. **Improve epoch processing**: See #1043.\n", "before_files": [{"content": "from . import spec\n\n\nfrom typing import (  # noqa: F401\n    Any,\n    Callable,\n    List,\n    NewType,\n    Tuple,\n)\n\nfrom .spec import (\n    BeaconState,\n    BeaconBlock,\n)\n\n\ndef process_transaction_type(state: BeaconState,\n                             transactions: List[Any],\n                             max_transactions: int,\n                             tx_fn: Callable[[BeaconState, Any], None]) -> None:\n    assert len(transactions) <= max_transactions\n    for transaction in transactions:\n        tx_fn(state, transaction)\n\n\ndef process_transactions(state: BeaconState, block: BeaconBlock) -> None:\n    process_transaction_type(\n        state,\n        block.body.proposer_slashings,\n        spec.MAX_PROPOSER_SLASHINGS,\n        spec.process_proposer_slashing,\n    )\n    process_transaction_type(\n        state,\n        block.body.attester_slashings,\n        spec.MAX_ATTESTER_SLASHINGS,\n        spec.process_attester_slashing,\n    )\n    process_transaction_type(\n        state,\n        block.body.attestations,\n        spec.MAX_ATTESTATIONS,\n        spec.process_attestation,\n    )\n    process_transaction_type(\n        state,\n        block.body.deposits,\n        spec.MAX_DEPOSITS,\n        spec.process_deposit,\n    )\n    process_transaction_type(\n        state,\n        block.body.voluntary_exits,\n        spec.MAX_VOLUNTARY_EXITS,\n        spec.process_voluntary_exit,\n    )\n    assert len(block.body.transfers) == len(set(block.body.transfers))\n    process_transaction_type(\n        state,\n        block.body.transfers,\n        spec.MAX_TRANSFERS,\n        spec.process_transfer,\n    )\n\n\ndef process_block(state: BeaconState,\n                  block: BeaconBlock,\n                  verify_state_root: bool=False) -> None:\n    spec.process_block_header(state, block)\n    spec.process_randao(state, block)\n    spec.process_eth1_data(state, block)\n\n    process_transactions(state, block)\n    if verify_state_root:\n        spec.verify_block_state_root(state, block)\n\n\ndef process_epoch_transition(state: BeaconState) -> None:\n    spec.update_justification_and_finalization(state)\n    spec.process_crosslinks(state)\n    spec.maybe_reset_eth1_period(state)\n    spec.apply_rewards(state)\n    spec.process_ejections(state)\n    spec.update_registry_and_shuffling_data(state)\n    spec.process_slashings(state)\n    spec.process_exit_queue(state)\n    spec.finish_epoch_update(state)\n\n\ndef state_transition(state: BeaconState,\n                     block: BeaconBlock,\n                     verify_state_root: bool=False) -> BeaconState:\n    while state.slot < block.slot:\n        spec.cache_state(state)\n        if (state.slot + 1) % spec.SLOTS_PER_EPOCH == 0:\n            process_epoch_transition(state)\n        spec.advance_slot(state)\n        if block.slot == state.slot:\n            process_block(state, block, verify_state_root)\n", "path": "utils/phase0/state_transition.py"}], "after_files": [{"content": "from . import spec\n\n\nfrom typing import (  # noqa: F401\n    Any,\n    Callable,\n    List,\n    NewType,\n    Tuple,\n)\n\nfrom .spec import (\n    BeaconState,\n    BeaconBlock,\n)\n\n\ndef expected_deposit_count(state: BeaconState) -> int:\n    return min(\n        spec.MAX_DEPOSITS,\n        state.latest_eth1_data.deposit_count - state.deposit_index\n    )\n\n\ndef process_transaction_type(state: BeaconState,\n                             transactions: List[Any],\n                             max_transactions: int,\n                             tx_fn: Callable[[BeaconState, Any], None]) -> None:\n    assert len(transactions) <= max_transactions\n    for transaction in transactions:\n        tx_fn(state, transaction)\n\n\ndef process_transactions(state: BeaconState, block: BeaconBlock) -> None:\n    process_transaction_type(\n        state,\n        block.body.proposer_slashings,\n        spec.MAX_PROPOSER_SLASHINGS,\n        spec.process_proposer_slashing,\n    )\n\n    process_transaction_type(\n        state,\n        block.body.attester_slashings,\n        spec.MAX_ATTESTER_SLASHINGS,\n        spec.process_attester_slashing,\n    )\n\n    process_transaction_type(\n        state,\n        block.body.attestations,\n        spec.MAX_ATTESTATIONS,\n        spec.process_attestation,\n    )\n\n    assert len(block.body.deposits) == expected_deposit_count(state)\n    process_transaction_type(\n        state,\n        block.body.deposits,\n        spec.MAX_DEPOSITS,\n        spec.process_deposit,\n    )\n\n    process_transaction_type(\n        state,\n        block.body.voluntary_exits,\n        spec.MAX_VOLUNTARY_EXITS,\n        spec.process_voluntary_exit,\n    )\n\n    assert len(block.body.transfers) == len(set(block.body.transfers))\n    process_transaction_type(\n        state,\n        block.body.transfers,\n        spec.MAX_TRANSFERS,\n        spec.process_transfer,\n    )\n\n\ndef process_block(state: BeaconState,\n                  block: BeaconBlock,\n                  verify_state_root: bool=False) -> None:\n    spec.process_block_header(state, block)\n    spec.process_randao(state, block)\n    spec.process_eth1_data(state, block)\n\n    process_transactions(state, block)\n    if verify_state_root:\n        spec.verify_block_state_root(state, block)\n\n\ndef process_epoch_transition(state: BeaconState) -> None:\n    spec.update_justification_and_finalization(state)\n    spec.process_crosslinks(state)\n    spec.maybe_reset_eth1_period(state)\n    spec.apply_rewards(state)\n    spec.process_ejections(state)\n    spec.update_registry_and_shuffling_data(state)\n    spec.process_slashings(state)\n    spec.process_exit_queue(state)\n    spec.finish_epoch_update(state)\n\n\ndef state_transition(state: BeaconState,\n                     block: BeaconBlock,\n                     verify_state_root: bool=False) -> BeaconState:\n    while state.slot < block.slot:\n        spec.cache_state(state)\n        if (state.slot + 1) % spec.SLOTS_PER_EPOCH == 0:\n            process_epoch_transition(state)\n        spec.advance_slot(state)\n        if block.slot == state.slot:\n            process_block(state, block, verify_state_root)\n", "path": "utils/phase0/state_transition.py"}]}