Repository: ethereum/consensus-specs

Issue:
v0.10.0 test generators use incorrect domain for deposits
Consider test [genesis/initialization](https://github.com/ethereum/eth2.0-specs/blob/v0.10.0/tests/generators/genesis/main.py), although this afflicts other tests as well. This uses `minimal` config to generate a load of signed deposits.

In `minimal` config `GENESIS_FORK_VERSION` [is set to](https://github.com/ethereum/eth2.0-specs/blob/v0.10.0/configs/minimal.yaml#L67) `0x00000001`. The test generator correctly generates state with [this fork information](https://media.githubusercontent.com/media/ethereum/eth2.0-spec-tests/v0.10.0/tests/minimal/phase0/genesis/initialization/pyspec_tests/initialize_beacon_state_from_eth1/state.yaml):

    fork: {previous_version: '0x00000001', current_version: '0x00000001', epoch: 0}

However, all of the deposits are signed with `GENESIS_FORK_VERSION = 0x00000000`.

This can be seen by printing some intermediate values in [sign_deposit_data()](https://github.com/ethereum/eth2.0-specs/blob/v0.10.0/tests/core/pyspec/eth2spec/test/helpers/deposits.py#L19):

```python
def sign_deposit_data(spec, deposit_data, privkey):
    deposit_message = spec.DepositMessage(
        pubkey=deposit_data.pubkey,
        withdrawal_credentials=deposit_data.withdrawal_credentials,
        amount=deposit_data.amount)
    domain = spec.compute_domain(spec.DOMAIN_DEPOSIT)
    signing_root = spec.compute_signing_root(deposit_message, domain)
    deposit_data.signature = bls.Sign(privkey, signing_root)
    print("********")
    print(domain.hex())
    print(spec.GENESIS_FORK_VERSION.hex())
    print("********")
```

This prints

```
********
0300000000000000
00000001
********
```

`domain` ought to be `0x0300000000000001` here. I suspect the default value in [compute_domain()](https://github.com/ethereum/eth2.0-specs/blob/v0.10.0/specs/phase0/beacon-chain.md#compute_domain) is not being correctly handled after the spec constants are overwritten by loading the minimal configuration.

```python
def compute_domain(domain_type: DomainType, fork_version: Version=GENESIS_FORK_VERSION) -> Domain:
    """
    Return the domain for the ``domain_type`` and ``fork_version``.
    """
    return Domain(domain_type + fork_version)
```



Discussion:
Ah, looks like it. Thanks for doing the investigative work.

Will move the setting of `fork_version` when nothing is passed in into the function

```python
def compute_domain(domain_type: DomainType, fork_version: Version=None) -> Domain:
    """
    Return the domain for the ``domain_type`` and ``fork_version``.
    """
    if fork_version is None:
        fork_version = GENESIS_FORK_VERSION
    return Domain(domain_type + fork_version)
```

Resolving patch:
diff --git a/scripts/build_spec.py b/scripts/build_spec.py
--- a/scripts/build_spec.py
+++ b/scripts/build_spec.py
@@ -31,7 +31,7 @@
 SSZObject = TypeVar('SSZObject', bound=SSZType)
 '''
 PHASE1_IMPORTS = '''from typing import (
-    Any, Dict, Set, Sequence, MutableSequence, NewType, Tuple, Union, TypeVar
+    Any, Dict, Set, Sequence, MutableSequence, NewType, Optional, Tuple, Union, TypeVar
 )
 from math import (
     log2,


Test patch: