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 var overrideConfiguration = new Dictionary <string, string> { ["QuickStart:GenesisTime"] = "1578009600", ["QuickStart:ValidatorCount"] = "64" }; IServiceCollection testServiceCollection = TestSystem.BuildTestServiceCollection(overrideConfiguration); ServiceProvider testServiceProvider = testServiceCollection.BuildServiceProvider(); // Act QuickStartMockEth1GenesisProvider quickStartMockEth1GenesisProvider = (QuickStartMockEth1GenesisProvider)testServiceProvider.GetService <IEth1GenesisProvider>(); byte[] privateKey = quickStartMockEth1GenesisProvider.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 BasicNewBlock() { // Arrange int numberOfValidators = 64; int genesisTime = 1578009600; IServiceCollection testServiceCollection = TestSystem.BuildTestServiceCollection(useStore: true); IConfigurationRoot configuration = new ConfigurationBuilder() .AddInMemoryCollection(new Dictionary <string, string> { ["QuickStart:ValidatorCount"] = $"{numberOfValidators}", ["QuickStart:GenesisTime"] = $"{genesisTime}" }) .Build(); testServiceCollection.AddBeaconNodeQuickStart(configuration); testServiceCollection.AddBeaconNodeEth1Bridge(configuration); testServiceCollection.AddSingleton <IHostEnvironment>(Substitute.For <IHostEnvironment>()); ServiceProvider testServiceProvider = testServiceCollection.BuildServiceProvider(); Eth1BridgeWorker eth1BridgeWorker = testServiceProvider.GetServices <IHostedService>().OfType <Eth1BridgeWorker>().First(); await eth1BridgeWorker.ExecuteEth1GenesisAsync(CancellationToken.None); IBeaconNodeApi beaconNode = testServiceProvider.GetService <IBeaconNodeApi>(); ApiResponse <Fork> forkResponse = await beaconNode.GetNodeForkAsync(CancellationToken.None); Fork fork = forkResponse.Content; fork.CurrentVersion.ShouldBe(new ForkVersion(new byte[4] { 0x00, 0x00, 0x00, 0x01 })); // Act BlockProducer blockProducer = testServiceProvider.GetService <BlockProducer>(); Slot targetSlot = new Slot(1); // With QuickStart64, proposer for Slot 1 is validator index 29, 0xa98ed496... QuickStartMockEth1GenesisProvider quickStartMockEth1GenesisProvider = (QuickStartMockEth1GenesisProvider)testServiceProvider.GetService <IEth1GenesisProvider>(); byte[] privateKey = quickStartMockEth1GenesisProvider.GeneratePrivateKey(29); BlsSignature randaoReveal = GetEpochSignature(testServiceProvider, privateKey, fork.CurrentVersion, targetSlot); // value for quickstart 20/64, fork 0, slot 1 randaoReveal.ToString().StartsWith("0x932f8730"); BeaconBlock newBlock = await blockProducer.NewBlockAsync(targetSlot, randaoReveal, CancellationToken.None); // Assert newBlock.Slot.ShouldBe(targetSlot); newBlock.Body.RandaoReveal.ShouldBe(randaoReveal); newBlock.ParentRoot.ToString().ShouldStartWith("0x4d4e9a16"); newBlock.Body.Eth1Data.DepositCount.ShouldBe((ulong)numberOfValidators); newBlock.Body.Eth1Data.DepositRoot.ToString().ShouldStartWith("0x66687aad"); newBlock.StateRoot.ToString().ShouldStartWith("0x0138b69f"); newBlock.Body.Attestations.Count.ShouldBe(0); newBlock.Body.Deposits.Count.ShouldBe(0); }