public void GeneratePrivateKey63() { // Hash of the validator index (as little endian bytes), is converted to integer as little endian, // then that integer (after modulus) is used as the big endian private key. // However, Hash(63) is small enough that it only has 31 bytes (not 32), // so when writing we have to ensure the padding is at the correct end. // // i.e. little endian 63 = 0x3f, // Hash(0x3f00000000000000000000000000000000000000000000000000000000000000) // = 0xbdd4daa5482af796206dc02a6780cfb51efe5e16c491c61bd9bf64cfc0da6e00 // Little endian this is 195862955980072989385619164996948568652240008241846978685122117889393611965 // When converted to bytes big endian (as per Eth BLS), this is only 31 bytes: // 0x6edac0cf64bfd91bc691c4165efe1eb5cf80672ac06d2096f72a48a5dad4bd // If written to an array/span it would pad on the right, but needs to pad on the left: // 0x006edac0cf64bfd91bc691c4165efe1eb5cf80672ac06d2096f72a48a5dad4bd // Arrange IServiceCollection testServiceCollection = TestSystem.BuildTestServiceCollection(useStore: true); IConfigurationRoot configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string> { ["QuickStart:ValidatorCount"] = "64" }) .Build(); testServiceCollection.AddBeaconNodeQuickStart(configuration); ServiceProvider testServiceProvider = testServiceCollection.BuildServiceProvider(); // Act QuickStart quickStart = (testServiceProvider.GetService <INodeStart>() as QuickStart) !; byte[] privateKey = quickStart.GeneratePrivateKey(63); // Assert privateKey.Length.ShouldBe(32); privateKey[0].ShouldBe((byte)0x00); privateKey[1].ShouldBe((byte)0x6e); privateKey[31].ShouldBe((byte)0xbd); }
public async Task TestValidatorKeyGeneration64() { // Arrange var overrideConfiguration = new Dictionary <string, string> { ["QuickStart:GenesisTime"] = "1578009600", ["QuickStart:ValidatorCount"] = "64" }; IServiceCollection testServiceCollection = TestSystem.BuildTestServiceCollection(overrideConfiguration); ServiceProvider testServiceProvider = testServiceCollection.BuildServiceProvider(); // Act Eth1BridgeWorker eth1BridgeWorker = testServiceProvider.GetServices <IHostedService>().OfType <Eth1BridgeWorker>().First(); await eth1BridgeWorker.ExecuteEth1GenesisAsync(CancellationToken.None); // Assert testServiceProvider.GetService <IEth1GenesisProvider>().ShouldBeOfType <QuickStartMockEth1GenesisProvider>(); IStore store = testServiceProvider.GetService <IStore>(); BeaconState state = await store.GetBlockStateAsync(store.FinalizedCheckpoint.Root); state.Validators.Count.ShouldBe(64); }