From 303f41e650b72f506164dd2441459fdc4a7e6ffc Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Fri, 28 May 2021 00:17:42 -0400 Subject: [PATCH 1/3] Added an initial 0x02 credential description --- specs/phase0/beacon-chain.md | 1 + specs/phase0/deposit-contract.md | 2 +- specs/phase0/validator.md | 20 ++++++++++++++++ .../block_processing/test_process_deposit.py | 24 ++++++++++++++++++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/specs/phase0/beacon-chain.md b/specs/phase0/beacon-chain.md index 0169e27250..0ba4311a0e 100644 --- a/specs/phase0/beacon-chain.md +++ b/specs/phase0/beacon-chain.md @@ -192,6 +192,7 @@ The following values are (non-configurable) constants used throughout the specif | - | - | | `BLS_WITHDRAWAL_PREFIX` | `Bytes1('0x00')` | | `ETH1_ADDRESS_WITHDRAWAL_PREFIX` | `Bytes1('0x01')` | +| `ETH1_ADDRESS_WITHDRAWAL_AND_COINBASE_PREFIX` | `Bytes1('0x02')` | ### Domain types diff --git a/specs/phase0/deposit-contract.md b/specs/phase0/deposit-contract.md index 02e762daef..53838c11e3 100644 --- a/specs/phase0/deposit-contract.md +++ b/specs/phase0/deposit-contract.md @@ -60,7 +60,7 @@ The amount of ETH (rounded down to the closest Gwei) sent to the deposit contrac One of the `DepositData` fields is `withdrawal_credentials` which constrains validator withdrawals. The first byte of this 32-byte field is a withdrawal prefix which defines the semantics of the remaining 31 bytes. -The withdrawal prefixes currently supported are `BLS_WITHDRAWAL_PREFIX` and `ETH1_ADDRESS_WITHDRAWAL_PREFIX`. +The withdrawal prefixes currently supported are `BLS_WITHDRAWAL_PREFIX`, `ETH1_ADDRESS_WITHDRAWAL_PREFIX`, and `ETH1_ADDRESS_WITHDRAWAL_AND_COINBASE_PREFIX`. Read more in the [validator guide](./validator.md#withdrawal-credentials). *Note*: The deposit contract does not validate the `withdrawal_credentials` field. diff --git a/specs/phase0/validator.md b/specs/phase0/validator.md index a548003e1b..4b500847bf 100644 --- a/specs/phase0/validator.md +++ b/specs/phase0/validator.md @@ -168,6 +168,26 @@ triggered by a user transaction that will set the gas price and gas limit as wel As long as the account or contract with address `eth1_withdrawal_address` can receive ETH transfers, the future withdrawal protocol is agnostic to all other implementation details. +##### `ETH1_ADDRESS_WITHDRAWAL_AND_COINBASE_PREFIX` + +This is an extension of `ETH1_ADDRESS_WITHDRAWAL_PREFIX`. +As with that prefix, this specifies a 20-byte Eth1 address `eth1_withdrawal_address`, which can be the address of either an externally owned account or of a contract. +This address will be the recipient for all withdrawals. +Additionally, blocks proposed by validators using this prefix **will be invalid** if the `coinbase` for those blocks is not equal to `eth1_withdrawal_address`. + +The `withdrawal_credentials` field must be such that: + +* `withdrawal_credentials[:1] == ETH1_ADDRESS_WITHDRAWAL_AND_COINBASE_PREFIX` +* `withdrawal_credentials[1:12] == b'\x00' * 11` +* `withdrawal_credentials[12:] == eth1_withdrawal_address` + +After the merge of the current Ethereum application layer (Eth1) into the Beacon Chain (Eth2), +withdrawals to `eth1_withdrawal_address` will be normal ETH transfers (with no payload other than the validator's ETH) +triggered by a user transaction that will set the gas price and gas limit as well pay fees. +As long as the account or contract with address `eth1_withdrawal_address` can receive ETH transfers, +the future withdrawal protocol is agnostic to all other implementation details. + + ### Submit deposit In Phase 0, all incoming validator deposits originate from the Ethereum 1.0 chain defined by `DEPOSIT_CHAIN_ID` and `DEPOSIT_NETWORK_ID`. Deposits are made to the [deposit contract](./deposit-contract.md) located at `DEPOSIT_CONTRACT_ADDRESS`. diff --git a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_deposit.py b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_deposit.py index 36e76f46c8..016e48ec54 100644 --- a/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_deposit.py +++ b/tests/core/pyspec/eth2spec/test/phase0/block_processing/test_process_deposit.py @@ -116,6 +116,28 @@ def test_new_deposit_eth1_withdrawal_credentials(spec, state): yield from run_deposit_processing(spec, state, deposit, validator_index) +@with_all_phases +@spec_state_test +def test_new_deposit_eth1_withdrawal_and_coinbase_credentials(spec, state): + # fresh deposit = next validator index = validator appended to registry + validator_index = len(state.validators) + withdrawal_credentials = ( + spec.ETH1_ADDRESS_WITHDRAWAL_AND_COINBASE_PREFIX + + b'\x00' * 11 # specified 0s + + b'\x59' * 20 # a 20-byte eth1 address + ) + amount = spec.MAX_EFFECTIVE_BALANCE + deposit = prepare_state_and_deposit( + spec, state, + validator_index, + amount, + withdrawal_credentials=withdrawal_credentials, + signed=True, + ) + + yield from run_deposit_processing(spec, state, deposit, validator_index) + + @with_all_phases @spec_state_test def test_new_deposit_non_versioned_withdrawal_credentials(spec, state): @@ -123,7 +145,7 @@ def test_new_deposit_non_versioned_withdrawal_credentials(spec, state): validator_index = len(state.validators) withdrawal_credentials = ( b'\xFF' # Non specified withdrawal credentials version - + b'\x02' * 31 # Garabage bytes + + b'\x02' * 31 # Garbage bytes ) amount = spec.MAX_EFFECTIVE_BALANCE deposit = prepare_state_and_deposit( From d7ccdf1234ffbe6a5e21e9efc959fda1798019c4 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Fri, 28 May 2021 00:22:21 -0400 Subject: [PATCH 2/3] Added a link to the 0x02 description in validator.md's TOC --- specs/phase0/validator.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/phase0/validator.md b/specs/phase0/validator.md index 4b500847bf..3aa6ae2c17 100644 --- a/specs/phase0/validator.md +++ b/specs/phase0/validator.md @@ -22,6 +22,7 @@ This is an accompanying document to [Ethereum 2.0 Phase 0 -- The Beacon Chain](. - [Withdrawal credentials](#withdrawal-credentials) - [`BLS_WITHDRAWAL_PREFIX`](#bls_withdrawal_prefix) - [`ETH1_ADDRESS_WITHDRAWAL_PREFIX`](#eth1_address_withdrawal_prefix) + - [`ETH1_ADDRESS_WITHDRAWAL_AND_COINBASE_PREFIX`](#eth1_address_withdrawal_and_coinbase_prefix) - [Submit deposit](#submit-deposit) - [Process deposit](#process-deposit) - [Validator index](#validator-index) From 6bd336d0638f62801e1d264160eae2adab0a7c27 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Wed, 2 Jun 2021 09:41:06 -0400 Subject: [PATCH 3/3] Update specs/phase0/validator.md Co-authored-by: Mikhail Kalinin --- specs/phase0/validator.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/phase0/validator.md b/specs/phase0/validator.md index 3aa6ae2c17..bbd36b5ba6 100644 --- a/specs/phase0/validator.md +++ b/specs/phase0/validator.md @@ -182,7 +182,7 @@ The `withdrawal_credentials` field must be such that: * `withdrawal_credentials[1:12] == b'\x00' * 11` * `withdrawal_credentials[12:] == eth1_withdrawal_address` -After the merge of the current Ethereum application layer (Eth1) into the Beacon Chain (Eth2), +After the merge of the current Ethereum execution layer (Eth1) into the Beacon Chain (Eth2), withdrawals to `eth1_withdrawal_address` will be normal ETH transfers (with no payload other than the validator's ETH) triggered by a user transaction that will set the gas price and gas limit as well pay fees. As long as the account or contract with address `eth1_withdrawal_address` can receive ETH transfers,