Skip to content

Commit

Permalink
Adds new genesis state root from Bellatrix fork
Browse files Browse the repository at this point in the history
Apparently this is what should have been used all along, but
deposits hard code an empty root because they preceeded Bellatrix
  • Loading branch information
alex-miller-0 committed Mar 4, 2023
1 parent f2656d4 commit 9107cd6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
13 changes: 11 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@ export const NETWORKS = {
MAINNET_GENESIS: {
networkName: 'mainnet',
forkVersion: Buffer.alloc(4),
// Empty root because there were no validators at genesis
validatorsRoot: Buffer.alloc(32),
// Validators root is fixed for the life of the chain. See reference:
// https://eth2book.info/bellatrix/part3/containers/state/
// And reference test:
// https://github.com/ethereum/consensus-specs/blob/
// 496e1d86c9e251a1b1d5b0eb785b0381ce553751/tests/core/pyspec/eth2spec/
// test/capella/block_processing/test_process_bls_to_execution_change.py#L231
// NOTE: This is replaced with an empty buffer when generating deposit data.
validatorsRoot: Buffer.from(
'4b363db94e286120d76eb905340fdd4e54bfe9f06bf33ff6cf5ad27f511bfe95',
'hex'
),
},
};

Expand Down
12 changes: 6 additions & 6 deletions src/depositData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export async function generate(
if (amountGwei < 0 || new BN(amountGwei).gte(new BN(2).pow(new BN(64)))) {
throw new Error('`amountGwei` must be >0 and <UINT64_MAX')
}
const { networkName, forkVersion, validatorsRoot } = networkInfo;
const { networkName, forkVersion } = networkInfo;
if (!networkName) {
throw new Error('No `networkName` value found in `networkInfo`.');
}
Expand All @@ -53,11 +53,11 @@ export async function generate(
} else if (forkVersion.length !== 4) {
throw new Error('`forkVersion` must be a 4 byte Buffer.')
}
if (!validatorsRoot) {
throw new Error('No `validatorsRoot` value found in `networkInfo`.');
} else if (validatorsRoot.length !== 32) {
throw new Error('`validatorsRoot` must be a 32 byte Buffer.');
}
// Validators root is always empty for deposits. See reference:
// https://github.com/ethereum/staking-deposit-cli/blob/
// ef89710443814331aa2f592067dc4d6995cc4f6e/staking_deposit/utils/ssz.py#L49
networkInfo.validatorsRoot = Buffer.alloc(32);

// Start building data. Items should be strings. Some can be copied directly.
// ---
// Get the depositor pubkey
Expand Down

0 comments on commit 9107cd6

Please sign in to comment.