Esempio n. 1
0
        public void EmptyBeaconBlockEncode()
        {
            // Arrange
            Eth1Data eth1Data = new Eth1Data(
                new Root(Enumerable.Repeat((byte)0x12, 32).ToArray()),
                64,
                new Bytes32(Enumerable.Repeat((byte)0x34, 32).ToArray()));
            BeaconBlockBody beaconBlockBody = new BeaconBlockBody(
                new BlsSignature(Enumerable.Repeat((byte)0x56, 96).ToArray()),
                eth1Data,
                new Bytes32(Enumerable.Repeat((byte)0x78, 32).ToArray()),
                new ProposerSlashing[0],
                new AttesterSlashing [0],
                new Attestation[0],
                new Deposit[0],
                new SignedVoluntaryExit[0]
                );
            BeaconBlock beaconBlock = new BeaconBlock(
                Slot.One,
                new Root(Enumerable.Repeat((byte)0x9a, 32).ToArray()),
                new Root(Enumerable.Repeat((byte)0xbc, 32).ToArray()),
                beaconBlockBody
                );

            // Act
            Span <byte> encoded = new byte[Ssz.BeaconBlockLength(beaconBlock)];

            Ssz.Encode(encoded, beaconBlock);

            // Assert
            string expectedHex =
                // static
                "0100000000000000" +
                "9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a9a" +
                "bcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbcbc" +
                "4c000000" + // body dynamic offset 8+32+32+4 = 76 = 0x4c
                // dynamic
                // - body - static
                "565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656565656" +
                "1212121212121212121212121212121212121212121212121212121212121212" +
                "4000000000000000" +
                "3434343434343434343434343434343434343434343434343434343434343434" +
                "7878787878787878787878787878787878787878787878787878787878787878" +
                "dc000000" + // proposer dynamic offset 96+(32+8+32)+32 + 5*4 = 220 = 0xdc
                "dc000000" + // attester slashings & all remaining offsets are the same, as they are empty
                "dc000000" +
                "dc000000" +
                "dc000000"; // body - dynamic part is empty

            encoded.ToHexString().ShouldBe(expectedHex);
        }
Esempio n. 2
0
        public void Beacon_block_there_and_back()
        {
            Eth1Data eth1Data = new Eth1Data(
                Sha256.RootOfAnEmptyString,
                1,
                Sha256.Bytes32OfAnEmptyString);

            Deposit         zeroDeposit     = new Deposit(Enumerable.Repeat(Bytes32.Zero, Ssz.DepositContractTreeDepth + 1), DepositData.Zero);
            BeaconBlockBody beaconBlockBody = new BeaconBlockBody(
                TestSig1,
                eth1Data,
                new Bytes32(new byte[32]),
                Enumerable.Repeat(ProposerSlashing.Zero, 2).ToArray(),
                Enumerable.Repeat(AttesterSlashing.Zero, 3).ToArray(),
                Enumerable.Repeat(Attestation.Zero, 4).ToArray(),
                Enumerable.Repeat(zeroDeposit, 5).ToArray(),
                Enumerable.Repeat(SignedVoluntaryExit.Zero, 6).ToArray()
                );

            BeaconBlock container = new BeaconBlock(
                new Slot(1),
                Sha256.RootOfAnEmptyString,
                Sha256.RootOfAnEmptyString,
                beaconBlockBody);

            Span <byte> encoded = new byte[Ssz.BeaconBlockLength(container)];

            Ssz.Encode(encoded, container);
            BeaconBlock decoded = Ssz.DecodeBeaconBlock(encoded);

            AssertBeaconBlockEqual(container, decoded);

            Span <byte> encodedAgain = new byte[Ssz.BeaconBlockLength(container)];

            Ssz.Encode(encodedAgain, decoded);

            Assert.True(Bytes.AreEqual(encodedAgain, encoded));

            Merkle.Ize(out UInt256 root, container);
        }
Esempio n. 3
0
        public void Beacon_block_there_and_back()
        {
            Eth1Data eth1Data = new Eth1Data(
                Sha256.OfAnEmptyString,
                1,
                Sha256.OfAnEmptyString);

            BeaconBlockBody beaconBlockBody = new BeaconBlockBody(
                SszTest.TestSig1,
                eth1Data,
                new Bytes32(new byte[32]),
                new ProposerSlashing[2],
                new AttesterSlashing[3],
                new Attestation[4],
                new Deposit[5],
                new VoluntaryExit[6]
                );

            BeaconBlock container = new BeaconBlock(
                new Slot(1),
                Sha256.OfAnEmptyString,
                Sha256.OfAnEmptyString,
                beaconBlockBody,
                SszTest.TestSig1);

            Span <byte> encoded = new byte[Ssz.BeaconBlockLength(container)];

            Ssz.Encode(encoded, container);
            BeaconBlock decoded = Ssz.DecodeBeaconBlock(encoded);

            AssertBeaconBlockEqual(container, decoded);

            Span <byte> encodedAgain = new byte[Ssz.BeaconBlockLength(container)];

            Ssz.Encode(encodedAgain, decoded);

            Assert.True(Bytes.AreEqual(encodedAgain, encoded));

            Merkle.Ize(out UInt256 root, container);
        }