Esempio n. 1
0
        public void EmptyBeaconBlockDecode()
        {
            // Arrange
            string hex =
                // 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

            byte[] bytes = Bytes.FromHexString(hex);

            // Act
            BeaconBlock beaconBlock = Ssz.DecodeBeaconBlock(bytes);

            // Assert
            beaconBlock.Slot.ShouldBe(Slot.One);
            beaconBlock.ParentRoot.AsSpan().ToArray().ShouldBe(Enumerable.Repeat((byte)0x9a, 32).ToArray());
            beaconBlock.StateRoot.AsSpan().ToArray().ShouldBe(Enumerable.Repeat((byte)0xbc, 32).ToArray());
            beaconBlock.Body.RandaoReveal.AsSpan().ToArray().ShouldBe(Enumerable.Repeat((byte)0x56, 96).ToArray());
            beaconBlock.Body.Eth1Data.DepositRoot.AsSpan().ToArray().ShouldBe(Enumerable.Repeat((byte)0x12, 32).ToArray());
            beaconBlock.Body.Eth1Data.DepositCount.ShouldBe(64uL);
            beaconBlock.Body.Eth1Data.BlockHash.AsSpan().ToArray().ShouldBe(Enumerable.Repeat((byte)0x34, 32).ToArray());
            beaconBlock.Body.Graffiti.AsSpan().ToArray().ShouldBe(Enumerable.Repeat((byte)0x78, 32).ToArray());
            beaconBlock.Body.ProposerSlashings.Count.ShouldBe(0);
            beaconBlock.Body.AttesterSlashings.Count.ShouldBe(0);
            beaconBlock.Body.Attestations.Count.ShouldBe(0);
            beaconBlock.Body.Deposits.Count.ShouldBe(0);
            beaconBlock.Body.VoluntaryExits.Count.ShouldBe(0);
        }
Esempio n. 2
0
        public void Beacon_block_there_and_back()
        {
            Eth1Data eth1Data = new Eth1Data();

            eth1Data.BlockHash    = Sha256.OfAnEmptyString;
            eth1Data.DepositCount = 1;
            eth1Data.DepositRoot  = Sha256.OfAnEmptyString;

            BeaconBlockBody beaconBlockBody = new BeaconBlockBody();

            beaconBlockBody.RandaoReversal    = BlsSignature.TestSig1;
            beaconBlockBody.Eth1Data          = eth1Data;
            beaconBlockBody.Graffiti          = new byte[32];
            beaconBlockBody.ProposerSlashings = new ProposerSlashing[2];
            beaconBlockBody.AttesterSlashings = new AttesterSlashing[3];
            beaconBlockBody.Attestations      = new Attestation[4];
            beaconBlockBody.Deposits          = new Deposit[5];
            beaconBlockBody.VoluntaryExits    = new VoluntaryExit[6];

            BeaconBlock container = new BeaconBlock();

            container.Body       = beaconBlockBody;
            container.Signature  = BlsSignature.TestSig1;
            container.Slot       = new Slot(1);
            container.ParentRoot = Sha256.OfAnEmptyString;
            container.StateRoot  = Sha256.OfAnEmptyString;

            Span <byte> encoded = new byte[BeaconBlock.SszLength(container)];

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

            Assert.AreEqual(container, decoded);

            Span <byte> encodedAgain = new byte[BeaconBlock.SszLength(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.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. 4
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);
        }