Beispiel #1
0
        public void Can_merkleize_attestion_data()
        {
            // arrange
            AttestationData attestationData = new AttestationData(
                Slot.One,
                new CommitteeIndex(2),
                new Root(Enumerable.Repeat((byte)0x12, 32).ToArray()),
                new Checkpoint(
                    new Epoch(3),
                    new Root(Enumerable.Repeat((byte)0x34, 32).ToArray())
                    ),
                new Checkpoint(
                    new Epoch(4),
                    new Root(Enumerable.Repeat((byte)0x56, 32).ToArray())
                    )
                );

            // act
            Merkleizer merklezier = new Merkleizer(0);

            merklezier.Feed(attestationData);
            UInt256     root  = merklezier.CalculateRoot();
            Span <byte> bytes = MemoryMarshal.Cast <UInt256, byte>(MemoryMarshal.CreateSpan(ref root, 1));

            // assert
            byte[] expected = HashUtility.Hash(
                HashUtility.Hash(
                    HashUtility.Hash(
                        HashUtility.Chunk(new byte[] { 0x01 }), // slot
                        HashUtility.Chunk(new byte[] { 0x02 })  // committee
                        ),
                    HashUtility.Hash(
                        Enumerable.Repeat((byte)0x12, 32).ToArray(), // beacon block root
                        HashUtility.Hash(                            // source
                            HashUtility.Chunk(new byte[] { 0x03 }),
                            Enumerable.Repeat((byte)0x34, 32).ToArray()
                            )
                        )
                    ),
                HashUtility.Merge(
                    HashUtility.Hash( // target
                        HashUtility.Chunk(new byte[] { 0x04 }),
                        Enumerable.Repeat((byte)0x56, 32).ToArray()
                        ),
                    HashUtility.ZeroHashes(0, 2)
                    )
                ).ToArray();
            bytes.ToArray().ShouldBe(expected);
        }
Beispiel #2
0
        public void Can_merkleize_epoch_1()
        {
            // arrange
            Epoch epoch = Epoch.One;

            // act
            Merkleizer merklezier = new Merkleizer(0);

            merklezier.Feed(epoch);
            UInt256     root  = merklezier.CalculateRoot();
            Span <byte> bytes = MemoryMarshal.Cast <UInt256, byte>(MemoryMarshal.CreateSpan(ref root, 1));

            // assert
            byte[] expected = HashUtility.Chunk(new byte[] { 0x1 }).ToArray();
            bytes.ToArray().ShouldBe(expected);
        }