Esempio n. 1
0
        public void UInt16List32()
        {
            // Arrange
            var value = new ushort[] { 0xaabb, 0xc0ad, 0xeeff };
            var tree  = new SszTree(new SszBasicList(value, limit: 32));

            // Act
            var bytes        = tree.Serialize();
            var hashTreeRoot = tree.HashTreeRoot();

            // Assert
            var byteString         = BitConverter.ToString(bytes.ToArray()).Replace("-", "").ToLowerInvariant();
            var expectedByteString = "bbaaadc0ffee";

            byteString.ShouldBe(expectedByteString);

            var contentsRoot = Hash(
                Chunk(new byte[] { 0xbb, 0xaa, 0xad, 0xc0, 0xff, 0xee }),
                Chunk(new byte[0])
                );

            var expectedHashTreeRoot =
                Hash(
                    contentsRoot,
                    Chunk(new byte[] { 0x03, 0x00, 0x00, 0x00 })
                    );
            var expectedHashTreeRootString = BitConverter.ToString(expectedHashTreeRoot).Replace("-", "").ToLowerInvariant();

            var hashTreeRootString = BitConverter.ToString(hashTreeRoot.ToArray()).Replace("-", "").ToLowerInvariant();

            hashTreeRootString.ShouldBe(expectedHashTreeRootString);
        }
Esempio n. 2
0
        public void ByteArray16Serialize()
        {
            // Arrange
            var value = new byte[16];

            value[0]  = 1;
            value[15] = 0xff;
            var tree = new SszTree(new SszBasicVector(value));

            // Act
            var bytes        = tree.Serialize();
            var hashTreeRoot = tree.HashTreeRoot();

            // Assert
            var byteString         = BitConverter.ToString(bytes.ToArray()).Replace("-", "").ToLowerInvariant();
            var expectedByteString = "010000000000000000000000000000ff";

            byteString.ShouldBe(expectedByteString);

            var hashTreeRootString         = BitConverter.ToString(hashTreeRoot.ToArray()).Replace("-", "").ToLowerInvariant();
            var expectedHashTreeRootString = "010000000000000000000000000000ff"
                                             + "00000000000000000000000000000000";

            hashTreeRootString.ShouldBe(expectedHashTreeRootString);
        }
        public void FixedContainer()
        {
            // Arrange
            var container = new FixedTestContainer()
            {
                A = (byte)0xab,
                B = (ulong)0xaabbccdd00112233,
                C = (uint)0x12345678
            };
            var tree = new SszTree(container.ToSszContainer());

            // Act
            var bytes        = tree.Serialize();
            var hashTreeRoot = tree.HashTreeRoot();

            // Assert
            var expectedByteString = "ab33221100ddccbbaa78563412";
            var byteString         = BitConverter.ToString(bytes.ToArray()).Replace("-", "").ToLowerInvariant();

            byteString.ShouldBe(expectedByteString);

            var expectedHashTreeRoot = Hash(
                Hash(Chunk(new byte[] { 0xab }), Chunk(new byte[] { 0x33, 0x22, 0x11, 0x00, 0xdd, 0xcc, 0xbb, 0xaa })),
                Hash(Chunk(new byte[] { 0x78, 0x56, 0x34, 0x12 }), Chunk(new byte[] { }))
                );
            var expectedHashTreeRootString = BitConverter.ToString(expectedHashTreeRoot).Replace("-", "").ToLowerInvariant();

            var hashTreeRootString = BitConverter.ToString(hashTreeRoot.ToArray()).Replace("-", "").ToLowerInvariant();

            hashTreeRootString.ShouldBe(expectedHashTreeRootString);
        }
Esempio n. 4
0
        public void UInt32List128()
        {
            // Arrange
            var value = new uint[] { 0xaabb, 0xc0ad, 0xeeff };
            var tree  = new SszTree(new SszBasicList(value, limit: 128));

            // Act
            var bytes        = tree.Serialize();
            var hashTreeRoot = tree.HashTreeRoot();

            // Assert
            var byteString         = BitConverter.ToString(bytes.ToArray()).Replace("-", "").ToLowerInvariant();
            var expectedByteString = "bbaa0000adc00000ffee0000";

            byteString.ShouldBe(expectedByteString);

            var expectedHashTreeRoot =
                Hash(
                    Merge(
                        Chunk(new byte[] { 0xbb, 0xaa, 0x00, 0x00,
                                           0xad, 0xc0, 0x00, 0x00,
                                           0xff, 0xee, 0x00, 0x00 }),
                        ZeroHashes(0, 4)
                        ),
                    Chunk(new byte[] { 0x03, 0x00, 0x00, 0x00 })
                    );

            var expectedHashTreeRootString = BitConverter.ToString(expectedHashTreeRoot).Replace("-", "").ToLowerInvariant();

            var hashTreeRootString = BitConverter.ToString(hashTreeRoot.ToArray()).Replace("-", "").ToLowerInvariant();

            // TODO: Need to mix in the length
            hashTreeRootString.ShouldBe(expectedHashTreeRootString);
        }
Esempio n. 5
0
        public void ByteArray64Serialize()
        {
            // Arrange
            var value = new byte[64];

            value[0]  = 1;
            value[32] = 2;
            var tree = new SszTree(new SszBasicVector(value));

            // Act
            var bytes        = tree.Serialize();
            var hashTreeRoot = tree.HashTreeRoot();

            // Assert
            var byteString         = BitConverter.ToString(bytes.ToArray()).Replace("-", "").ToLowerInvariant();
            var expectedByteString = "0100000000000000000000000000000000000000000000000000000000000000"
                                     + "0200000000000000000000000000000000000000000000000000000000000000";

            byteString.ShouldBe(expectedByteString);

            var hashTreeRootString = BitConverter.ToString(hashTreeRoot.ToArray()).Replace("-", "").ToLowerInvariant();

            Console.WriteLine(hashTreeRootString);
            //var c1 = new byte[32];
            //c1[0] = 1;
            //var c2 = new byte[32];
            //c2[0] = 2;
            //var expectedHashTreeRoot = Hash(c1, c2);
            var expectedHashTreeRootString = "ff55c97976a840b4ced964ed49e3794594ba3f675238b5fd25d282b60f70a194";

            hashTreeRootString.ShouldBe(expectedHashTreeRootString);
        }
        public void SmallContainer()
        {
            // Arrange
            var container = new SmallTestContainer()
            {
                A = (ushort)0x4567, B = (ushort)0x0123
            };
            var tree = new SszTree(container.ToSszContainer());

            // Act
            var bytes        = tree.Serialize();
            var hashTreeRoot = tree.HashTreeRoot();

            // Assert
            var expectedByteString = "67452301";
            var byteString         = BitConverter.ToString(bytes.ToArray()).Replace("-", "").ToLowerInvariant();

            byteString.ShouldBe(expectedByteString);

            var expectedHashTreeRoot       = Hash(Chunk(new byte[] { 0x67, 0x45 }), Chunk(new byte[] { 0x23, 0x01 }));
            var expectedHashTreeRootString = BitConverter.ToString(expectedHashTreeRoot).Replace("-", "").ToLowerInvariant();
            var hashTreeRootString         = BitConverter.ToString(hashTreeRoot.ToArray()).Replace("-", "").ToLowerInvariant();

            hashTreeRootString.ShouldBe(expectedHashTreeRootString);
        }
Esempio n. 7
0
        public void ByteArray192Serialize()
        {
            // Arrange
            var value = new byte[192];

            value[0]   = 1;
            value[32]  = 2;
            value[64]  = 3;
            value[95]  = 0xff;
            value[96]  = 4;
            value[128] = 5;
            value[160] = 6;
            var tree = new SszTree(new SszBasicVector(value));

            // Act
            var bytes        = tree.Serialize();
            var hashTreeRoot = tree.HashTreeRoot();

            // Assert
            var expectedByteString = "0100000000000000000000000000000000000000000000000000000000000000"
                                     + "0200000000000000000000000000000000000000000000000000000000000000"
                                     + "03000000000000000000000000000000000000000000000000000000000000ff"
                                     + "0400000000000000000000000000000000000000000000000000000000000000"
                                     + "0500000000000000000000000000000000000000000000000000000000000000"
                                     + "0600000000000000000000000000000000000000000000000000000000000000";
            var byteString = BitConverter.ToString(bytes.ToArray()).Replace("-", "").ToLowerInvariant();

            byteString.ShouldBe(expectedByteString);

            var c1 = new byte[32];

            c1[0] = 1;
            var c2 = new byte[32];

            c2[0] = 2;
            var c3 = new byte[32];

            c3[0]  = 3;
            c3[31] = 0xff;
            var c4 = new byte[32];

            c4[0] = 4;
            var c5 = new byte[32];

            c5[0] = 5;
            var c6 = new byte[32];

            c6[0] = 6;
            var cZ = new byte[32];

            var expectedHashTreeRoot = Hash(
                Hash(Hash(c1, c2), Hash(c3, c4)),
                Hash(Hash(c5, c6), Hash(cZ, cZ)));

            hashTreeRoot.ToArray().ShouldBe(expectedHashTreeRoot);
        }
Esempio n. 8
0
        public void SmallTestContainerList16()
        {
            // Arrange
            var value = new SingleFieldTestContainer[] {
                new SingleFieldTestContainer {
                    A = 0x01
                },
                new SingleFieldTestContainer {
                    A = 0x02
                },
                new SingleFieldTestContainer {
                    A = 0x03
                },
            };
            var tree = new SszTree(value.ToSszList(16));

            // Act
            var bytes        = tree.Serialize();
            var hashTreeRoot = tree.HashTreeRoot();

            // Assert
            var byteString         = BitConverter.ToString(bytes.ToArray()).Replace("-", "").ToLowerInvariant();
            var expectedByteString = "010203";

            byteString.ShouldBe(expectedByteString);

            var contentsRoot = Merge(
                Hash(
                    Hash(
                        Chunk(new byte[] { 0x01 }),
                        Chunk(new byte[] { 0x02 })
                        ),
                    Hash(
                        Chunk(new byte[] { 0x03 }),
                        Chunk(new byte[] { 0x00 })
                        )
                    ),
                ZeroHashes(2, 4));
            var expectedHashTreeRoot =
                Hash(
                    contentsRoot,
                    Chunk(new byte[] { 0x03, 0x00, 0x00, 0x00 }) // mix in length
                    );
            var expectedHashTreeRootString = BitConverter.ToString(expectedHashTreeRoot).Replace("-", "").ToLowerInvariant();

            var hashTreeRootString = BitConverter.ToString(hashTreeRoot.ToArray()).Replace("-", "").ToLowerInvariant();

            hashTreeRootString.ShouldBe(expectedHashTreeRootString);
        }
        public void BitvectorSerialize(bool[] value, string expectedByteString, byte[] expectedHashTreeRoot)
        {
            // Arrange
            var tree = new SszTree(new SszBitvector(value));

            // Act
            var bytes        = tree.Serialize();
            var hashTreeRoot = tree.HashTreeRoot();

            // Assert
            var byteString = BitConverter.ToString(bytes.ToArray()).Replace("-", "").ToLowerInvariant();

            byteString.ShouldBe(expectedByteString);
            hashTreeRoot.ToArray().ShouldBe(expectedHashTreeRoot);
        }
        public void ByteUInt32(uint value, string expectedByteString, string expectedHashTreeRoot)
        {
            // Arrange
            var tree = new SszTree(new SszBasicElement(value));

            // Act
            var bytes        = tree.Serialize();
            var hashTreeRoot = tree.HashTreeRoot();

            // Assert
            var byteString = BitConverter.ToString(bytes.ToArray()).Replace("-", "").ToLowerInvariant();

            byteString.ShouldBe(expectedByteString);
            var hashTreeRootString = BitConverter.ToString(hashTreeRoot.ToArray()).Replace("-", "").ToLowerInvariant();

            hashTreeRootString.ShouldBe(expectedHashTreeRoot);
        }
Esempio n. 11
0
        public void VarContainer_Some()
        {
            // Arrange
            var container = new VarTestContainer()
            {
                A = 0xabcd,
                B = new ushort[] { 1, 2, 3 },
                C = 0xff
            };
            var tree = new SszTree(container.ToSszContainer());

            // Act
            var bytes        = tree.Serialize();
            var hashTreeRoot = tree.HashTreeRoot();

            // Assert
            var expectedByteString = "cdab07000000ff010002000300";
            var byteString         = BitConverter.ToString(bytes.ToArray()).Replace("-", "").ToLowerInvariant();

            byteString.ShouldBe(expectedByteString);

            var expectedHashTreeRoot =
                Hash(
                    Hash(
                        Chunk(new byte[] { 0xcd, 0xab }),
                        Hash(
                            Merge(
                                Chunk(new byte[] { 0x01, 0x00, 0x02, 0x00, 0x03, 0x00 }),
                                ZeroHashes(0, 6)
                                ),
                            Chunk(new byte[] { 0x03, 0x00, 0x00, 0x00 }) // Length mix in
                            )
                        ),
                    Hash(Chunk(new byte[] { 0xff }), Chunk(new byte[] { }))
                    );
            var expectedHashTreeRootString = BitConverter.ToString(expectedHashTreeRoot).Replace("-", "").ToLowerInvariant();

            var hashTreeRootString = BitConverter.ToString(hashTreeRoot.ToArray()).Replace("-", "").ToLowerInvariant();

            hashTreeRootString.ShouldBe(expectedHashTreeRootString);
        }
Esempio n. 12
0
        public void ByteArray96Serialize()
        {
            // Arrange
            var value = new byte[96];

            value[0]  = 1;
            value[32] = 2;
            value[64] = 3;
            value[95] = 0xff;
            var tree = new SszTree(new SszBasicVector(value));

            // Act
            var bytes        = tree.Serialize();
            var hashTreeRoot = tree.HashTreeRoot();

            // Assert
            var expectedByteString = "0100000000000000000000000000000000000000000000000000000000000000"
                                     + "0200000000000000000000000000000000000000000000000000000000000000"
                                     + "03000000000000000000000000000000000000000000000000000000000000ff";
            var byteString = BitConverter.ToString(bytes.ToArray()).Replace("-", "").ToLowerInvariant();

            byteString.ShouldBe(expectedByteString);

            var c1 = new byte[32];

            c1[0] = 1;
            var c2 = new byte[32];

            c2[0] = 2;
            var c3 = new byte[32];

            c3[0]  = 3;
            c3[31] = 0xff;
            var cZ = new byte[32];
            var h1 = Hash(c1, c2);
            var expectedHashTreeRoot = Hash(h1, Hash(c3, cZ));

            hashTreeRoot.ToArray().ShouldBe(expectedHashTreeRoot);
        }
Esempio n. 13
0
        public void SingleFieldContainer()
        {
            // Arrange
            var container = new SingleFieldTestContainer()
            {
                A = (byte)0xab
            };
            var tree = new SszTree(container.ToSszContainer());

            // Act
            var bytes        = tree.Serialize();
            var hashTreeRoot = tree.HashTreeRoot();

            // Assert
            var expectedByteString = "ab";
            var byteString         = BitConverter.ToString(bytes.ToArray()).Replace("-", "").ToLowerInvariant();

            byteString.ShouldBe(expectedByteString);
            var expectedHashTreeRootString = "ab00000000000000000000000000000000000000000000000000000000000000";
            var hashTreeRootString         = BitConverter.ToString(hashTreeRoot.ToArray()).Replace("-", "").ToLowerInvariant();

            hashTreeRootString.ShouldBe(expectedHashTreeRootString);
        }
Esempio n. 14
0
        public void UInt16Vector()
        {
            // Arrange
            var value = new ushort[] { 0x4567, 0x0123 };
            var tree  = new SszTree(new SszBasicVector(value));

            // Act
            var bytes        = tree.Serialize();
            var hashTreeRoot = tree.HashTreeRoot();

            // Assert
            var byteString         = BitConverter.ToString(bytes.ToArray()).Replace("-", "").ToLowerInvariant();
            var expectedByteString = "67452301";

            byteString.ShouldBe(expectedByteString);

            var expectedHashTreeRoot       = Chunk(new byte[] { 0x67, 0x45, 0x23, 0x01 }).ToArray();
            var expectedHashTreeRootString = BitConverter.ToString(expectedHashTreeRoot).Replace("-", "").ToLowerInvariant();

            var hashTreeRootString = BitConverter.ToString(hashTreeRoot.ToArray()).Replace("-", "").ToLowerInvariant();

            hashTreeRootString.ShouldBe(expectedHashTreeRootString);
        }
        public static Root HashTreeRoot(this SignedBeaconBlockHeader item)
        {
            var tree = new SszTree(new SszContainer(GetValues(item)));

            return(new Root(tree.HashTreeRoot()));
        }
        public static Root HashTreeRoot(this BeaconBlockBody item, ulong maximumProposerSlashings, ulong maximumAttesterSlashings, ulong maximumAttestations, ulong maximumDeposits, ulong maximumVoluntaryExits, ulong maximumValidatorsPerCommittee)
        {
            var tree = new SszTree(item.ToSszContainer(maximumProposerSlashings, maximumAttesterSlashings, maximumAttestations, maximumDeposits, maximumVoluntaryExits, maximumValidatorsPerCommittee));

            return(new Root(tree.HashTreeRoot()));
        }
Esempio n. 17
0
        public static Hash32 HashTreeRoot(this BeaconBlockBody item, MiscellaneousParameters miscellaneousParameters, MaxOperationsPerBlock maxOperationsPerBlock)
        {
            var tree = new SszTree(item.ToSszContainer(miscellaneousParameters, maxOperationsPerBlock));

            return(new Hash32(tree.HashTreeRoot()));
        }
Esempio n. 18
0
 public static Hash32 HashTreeRoot(this Crosslink item)
 {
     var tree = new SszTree(item.ToSszContainer());
     return new Hash32(tree.HashTreeRoot());
 }
Esempio n. 19
0
        public static Hash32 HashTreeRoot(this Epoch item)
        {
            var tree = new SszTree(item.ToSszBasicElement());

            return(new Hash32(tree.HashTreeRoot()));
        }
Esempio n. 20
0
        public static Hash32 HashTreeRoot(this HistoricalBatch item)
        {
            var tree = new SszTree(item.ToSszContainer());

            return(new Hash32(tree.HashTreeRoot()));
        }
Esempio n. 21
0
        public static Hash32 HashTreeRoot(this IEnumerable <DepositData> list, ulong limit)
        {
            var tree = new SszTree(list.ToSszList(limit));

            return(new Hash32(tree.HashTreeRoot()));
        }
        public static Root HashTreeRoot(this DepositData item)
        {
            var tree = new SszTree(item.ToSszContainer());

            return(new Root(tree.HashTreeRoot()));
        }
Esempio n. 23
0
        public static Hash32 HashTreeRoot(this BeaconState item, ulong historicalRootsLimit, ulong slotsPerEth1VotingPeriod, ulong validatorRegistryLimit, ulong maximumAttestationsPerEpoch, ulong maximumValidatorsPerCommittee)
        {
            var tree = new SszTree(item.ToSszContainer(historicalRootsLimit, slotsPerEth1VotingPeriod, validatorRegistryLimit, maximumAttestationsPerEpoch, maximumValidatorsPerCommittee));

            return(new Hash32(tree.HashTreeRoot()));
        }
Esempio n. 24
0
        public static Hash32 SigningRoot(this BeaconBlock item, ulong maximumProposerSlashings, ulong maximumAttesterSlashings, ulong maximumAttestations, ulong maximumDeposits, ulong maximumVoluntaryExits, ulong maximumValidatorsPerCommittee)
        {
            var tree = new SszTree(new SszContainer(GetValues(item, maximumProposerSlashings, maximumAttesterSlashings, maximumAttestations, maximumDeposits, maximumVoluntaryExits, maximumValidatorsPerCommittee, true)));

            return(new Hash32(tree.HashTreeRoot()));
        }
        public static Hash32 SigningRoot(this VoluntaryExit item)
        {
            var tree = new SszTree(new SszContainer(GetValues(item, true)));

            return(new Hash32(tree.HashTreeRoot()));
        }
Esempio n. 26
0
        public static Hash32 SigningRoot(this BeaconBlockHeader item)
        {
            var tree = new SszTree(new SszContainer(GetValues(item, true)));

            return(new Hash32(tree.HashTreeRoot()));
        }
Esempio n. 27
0
        public static Hash32 HashTreeRoot(this BeaconState item, MiscellaneousParameters miscellaneousParameters, TimeParameters timeParameters, StateListLengths stateListLengths, MaxOperationsPerBlock maxOperationsPerBlock)
        {
            var tree = new SszTree(item.ToSszContainer(miscellaneousParameters, timeParameters, stateListLengths, maxOperationsPerBlock));

            return(new Hash32(tree.HashTreeRoot()));
        }
        public static Root HashTreeRoot(this SignedVoluntaryExit item)
        {
            var tree = new SszTree(new SszContainer(GetValues(item)));

            return(new Root(tree.HashTreeRoot()));
        }
        public static Hash32 HashTreeRoot(this AttestationData item)
        {
            var tree = new SszTree(item.ToSszContainer());

            return(new Hash32(tree.HashTreeRoot()));
        }
Esempio n. 30
0
        public static Hash32 SigningRoot(this BeaconBlock item, MiscellaneousParameters miscellaneousParameters, MaxOperationsPerBlock maxOperationsPerBlock)
        {
            var tree = new SszTree(new SszContainer(GetValues(item, miscellaneousParameters, maxOperationsPerBlock, true)));

            return(new Hash32(tree.HashTreeRoot()));
        }