Пример #1
0
        public static AttesterSlashing[] DecodeAttesterSlashings(Span <byte> span)
        {
            if (span.Length == 0)
            {
                return(Array.Empty <AttesterSlashing>());
            }

            int offset        = 0;
            int dynamicOffset = BinaryPrimitives.ReadInt32LittleEndian(span.Slice(0, VarOffsetSize));

            offset += 4;

            int itemsCount = dynamicOffset / VarOffsetSize;

            AttesterSlashing[] containers = new AttesterSlashing[itemsCount];
            for (int i = 0; i < itemsCount; i++)
            {
                int nextDynamicOffset      = i == itemsCount - 1 ? span.Length : BinaryPrimitives.ReadInt32LittleEndian(span.Slice(offset, VarOffsetSize));
                int length                 = nextDynamicOffset - dynamicOffset;
                AttesterSlashing container = DecodeAttesterSlashing(span.Slice(dynamicOffset, length));
                containers[i] = container;
                dynamicOffset = nextDynamicOffset;
                offset       += VarOffsetSize;
            }

            return(containers);
        }
Пример #2
0
        public void Attester_slashing_there_and_back()
        {
            AttestationData data = new AttestationData(
                new Slot(1),
                new CommitteeIndex(2),
                Sha256.RootOfAnEmptyString,
                new Checkpoint(new Epoch(1), Sha256.RootOfAnEmptyString),
                new Checkpoint(new Epoch(2), Sha256.RootOfAnEmptyString));

            IndexedAttestation indexedAttestation1 = new IndexedAttestation(
                new ValidatorIndex[3],
                data,
                TestSig1);

            IndexedAttestation indexedAttestation2 = new IndexedAttestation(
                new ValidatorIndex[5],
                data,
                TestSig1);

            AttesterSlashing container = new AttesterSlashing(indexedAttestation1, indexedAttestation2);

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

            Ssz.Encode(encoded, container);
            AttesterSlashing?decoded = Ssz.DecodeAttesterSlashing(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
Пример #3
0
        public static AttesterSlashing GetValidAttesterSlashing(IServiceProvider testServiceProvider, BeaconState state, bool signed1, bool signed2)
        {
            TimeParameters      timeParameters      = testServiceProvider.GetService <IOptions <TimeParameters> >().Value;
            BeaconStateAccessor beaconStateAccessor = testServiceProvider.GetService <BeaconStateAccessor>();

            Attestation attestation1 = TestAttestation.GetValidAttestation(testServiceProvider, state, Slot.None, CommitteeIndex.None, signed1);

            Hash32      targetRoot2  = new Hash32(Enumerable.Repeat((byte)0x01, 32).ToArray());
            Attestation attestation2 = new Attestation(
                attestation1.AggregationBits,
                new AttestationData(attestation1.Data.Slot,
                                    attestation1.Data.Index,
                                    attestation1.Data.BeaconBlockRoot,
                                    attestation1.Data.Source,
                                    new Checkpoint(
                                        attestation1.Data.Target.Epoch,
                                        targetRoot2
                                        )),
                BlsSignature.Empty
                );

            if (signed2)
            {
                TestAttestation.SignAttestation(testServiceProvider, state, attestation2);
            }

            IndexedAttestation indexedAttestation1 = beaconStateAccessor.GetIndexedAttestation(state, attestation1);
            IndexedAttestation indexedAttestation2 = beaconStateAccessor.GetIndexedAttestation(state, attestation2);

            AttesterSlashing attesterSlashing = new AttesterSlashing(indexedAttestation1, indexedAttestation2);

            return(attesterSlashing);
        }
Пример #4
0
        public void ProcessAttesterSlashing(BeaconState state, AttesterSlashing attesterSlashing)
        {
            _logger.LogInformation(Event.ProcessAttesterSlashing, "Process block operation attester slashing {AttesterSlashing}", attesterSlashing);
            var attestation1 = attesterSlashing.Attestation1;
            var attestation2 = attesterSlashing.Attestation2;

            var isSlashableAttestationData = _beaconChainUtility.IsSlashableAttestationData(attestation1.Data, attestation2.Data);

            if (!isSlashableAttestationData)
            {
                throw new Exception("Attestation data must be slashable.");
            }

            var signatureDomains = _signatureDomainOptions.CurrentValue;

            var epoch1            = attestation1.Data.Target.Epoch;
            var domain1           = _beaconStateAccessor.GetDomain(state, signatureDomains.BeaconAttester, epoch1);
            var attestation1Valid = _beaconChainUtility.IsValidIndexedAttestation(state, attestation1, domain1);

            if (!attestation1Valid)
            {
                throw new Exception("Attestation 1 must be valid.");
            }

            var epoch2            = attestation2.Data.Target.Epoch;
            var domain2           = _beaconStateAccessor.GetDomain(state, signatureDomains.BeaconAttester, epoch2);
            var attestation2Valid = _beaconChainUtility.IsValidIndexedAttestation(state, attestation2, domain2);

            if (!attestation2Valid)
            {
                throw new Exception("Attestation 2 must be valid.");
            }

            var slashedAny        = false;
            var attestingIndices1 = attestation1.CustodyBit0Indices.Union(attestation1.CustodyBit1Indices);
            var attestingIndices2 = attestation2.CustodyBit0Indices.Union(attestation2.CustodyBit1Indices);

            var intersection = attestingIndices1.Intersect(attestingIndices2);
            var currentEpoch = _beaconStateAccessor.GetCurrentEpoch(state);

            foreach (var index in intersection.OrderBy(x => x))
            {
                var validator            = state.Validators[(int)(ulong)index];
                var isSlashableValidator = _beaconChainUtility.IsSlashableValidator(validator, currentEpoch);
                if (isSlashableValidator)
                {
                    _beaconStateMutator.SlashValidator(state, index, ValidatorIndex.None);
                    slashedAny = true;
                }
            }

            if (!slashedAny)
            {
                throw new Exception("Attester slashing should have slashed at least one validator.");
            }
        }
        public void InvalidSignature1()
        {
            // Arrange
            IServiceProvider testServiceProvider = TestSystem.BuildTestServiceProvider();
            BeaconState      state = TestState.PrepareTestState(testServiceProvider);

            AttesterSlashing attesterSlashing = TestAttesterSlashing.GetValidAttesterSlashing(testServiceProvider, state, signed1: false, signed2: true);

            RunAttesterSlashingProcessing(testServiceProvider, state, attesterSlashing, expectValid: false);
        }
Пример #6
0
        private static void TestAttesterSlashingSsz(byte[] serialized, UInt256 expectedMerkleRoot, string testCaseDir)
        {
            AttesterSlashing container = Nethermind.Ssz.Ssz.DecodeAttesterSlashing(serialized);

            byte[] again = new byte[serialized.Length];
            Nethermind.Ssz.Ssz.Encode(again, container);
            Assert.AreEqual(serialized.ToHexString(), again.ToHexString(), testCaseDir);

            Merkle.Ize(out UInt256 root, container);
            Assert.AreEqual(expectedMerkleRoot, root);
        }
Пример #7
0
        public static void Encode(Span <byte> span, AttesterSlashing[] containers)
        {
            int offset        = 0;
            int dynamicOffset = containers.Length * VarOffsetSize;

            for (int i = 0; i < containers.Length; i++)
            {
                int currentLength = AttesterSlashing.SszLength(containers[i]);
                Encode(span.Slice(offset, VarOffsetSize), dynamicOffset);
                Encode(span.Slice(dynamicOffset, currentLength), containers[i]);
                offset        += VarOffsetSize;
                dynamicOffset += currentLength;
            }
        }
Пример #8
0
        private static void Encode(Span <byte> span, AttesterSlashing[] containers, ref int offset, ref int dynamicOffset)
        {
            int length = containers.Length * VarOffsetSize;

            for (int i = 0; i < containers.Length; i++)
            {
                length += AttesterSlashing.SszLength(containers[i]);
            }

            Encode(span.Slice(offset, VarOffsetSize), dynamicOffset);
            Encode(span.Slice(dynamicOffset, length), containers);
            dynamicOffset += length;
            offset        += VarOffsetSize;
        }
Пример #9
0
        public static void Ize(out UInt256 root, AttesterSlashing container)
        {
            if (container == null)
            {
                root = RootOfNull;
                return;
            }

            Merkleizer merkleizer = new Merkleizer(1);

            merkleizer.Feed(container.Attestation1);
            merkleizer.Feed(container.Attestation2);
            merkleizer.CalculateRoot(out root);
        }
Пример #10
0
        public static AttesterSlashing DecodeAttesterSlashing(ReadOnlySpan <byte> span)
        {
            int offset1 = (int)DecodeUInt(span.Slice(0, VarOffsetSize));
            int offset2 = (int)DecodeUInt(span.Slice(VarOffsetSize, VarOffsetSize));

            int length1 = offset2 - offset1;
            int length2 = span.Length - offset2;

            IndexedAttestation attestation1 = DecodeIndexedAttestation(span.Slice(offset1, length1));
            IndexedAttestation attestation2 = DecodeIndexedAttestation(span.Slice(offset2, length2));

            AttesterSlashing attesterSlashing = new AttesterSlashing(attestation1, attestation2);

            return(attesterSlashing);
        }
Пример #11
0
        public static AttesterSlashing?DecodeAttesterSlashing(Span <byte> span)
        {
            if (span.Length == 0)
            {
                return(null);
            }

            AttesterSlashing attesterSlashing = new AttesterSlashing();
            int offset1 = (int)DecodeUInt(span.Slice(0, VarOffsetSize));
            int offset2 = (int)DecodeUInt(span.Slice(VarOffsetSize, VarOffsetSize));

            int length1 = offset2 - offset1;
            int length2 = span.Length - offset2;

            attesterSlashing.Attestation1 = DecodeIndexedAttestation(span.Slice(offset1, length1));
            attesterSlashing.Attestation2 = DecodeIndexedAttestation(span.Slice(offset2, length2));

            return(attesterSlashing);
        }
Пример #12
0
        public static AttesterSlashing GetValidAttesterSlashing(IServiceProvider testServiceProvider, BeaconState state, bool signed1, bool signed2)
        {
            var timeParameters      = testServiceProvider.GetService <IOptions <TimeParameters> >().Value;
            var beaconStateAccessor = testServiceProvider.GetService <BeaconStateAccessor>();

            var attestation1 = TestAttestation.GetValidAttestation(testServiceProvider, state, Slot.None, CommitteeIndex.None, signed1);

            var attestation2 = TestAttestation.GetValidAttestation(testServiceProvider, state, Slot.None, CommitteeIndex.None, signed: false);

            attestation2.Data.Target.SetRoot(new Hash32(Enumerable.Repeat((byte)0x01, 32).ToArray()));
            if (signed2)
            {
                TestAttestation.SignAttestation(testServiceProvider, state, attestation2);
            }

            var indexedAttestation1 = beaconStateAccessor.GetIndexedAttestation(state, attestation1);
            var indexedAttestation2 = beaconStateAccessor.GetIndexedAttestation(state, attestation2);

            var attesterSlashing = new AttesterSlashing(indexedAttestation1, indexedAttestation2);

            return(attesterSlashing);
        }
Пример #13
0
        public static void Encode(Span <byte> span, AttesterSlashing?container)
        {
            if (span.Length != AttesterSlashing.SszLength(container))
            {
                ThrowTargetLength <AttesterSlashing>(span.Length, AttesterSlashing.SszLength(container));
            }

            if (container == null)
            {
                return;
            }

            int dynamicOffset = 2 * VarOffsetSize;
            int length1       = IndexedAttestation.SszLength(container.Attestation1);

            Encode(span.Slice(0, VarOffsetSize), dynamicOffset);
            Encode(span.Slice(dynamicOffset, length1), container.Attestation1);

            dynamicOffset += IndexedAttestation.SszLength(container.Attestation1);
            int length2 = IndexedAttestation.SszLength(container.Attestation2);

            Encode(span.Slice(VarOffsetSize, VarOffsetSize), dynamicOffset);
            Encode(span.Slice(dynamicOffset, length2), container.Attestation2);
        }
Пример #14
0
        public void Attester_slashing_there_and_back()
        {
            AttestationData data = new AttestationData();

            data.Slot            = new Slot(1);
            data.CommitteeIndex  = new CommitteeIndex(2);
            data.BeaconBlockRoot = Sha256.OfAnEmptyString;
            data.Source          = new Checkpoint(new Epoch(1), Sha256.OfAnEmptyString);
            data.Target          = new Checkpoint(new Epoch(2), Sha256.OfAnEmptyString);

            IndexedAttestation indexedAttestation1 = new IndexedAttestation();

            indexedAttestation1.AttestingIndices = new ValidatorIndex[3];
            indexedAttestation1.Data             = data;
            indexedAttestation1.Signature        = BlsSignature.TestSig1;

            IndexedAttestation indexedAttestation2 = new IndexedAttestation();

            indexedAttestation2.AttestingIndices = new ValidatorIndex[5];
            indexedAttestation2.Data             = data;
            indexedAttestation2.Signature        = BlsSignature.TestSig1;

            AttesterSlashing container = new AttesterSlashing();

            container.Attestation1 = indexedAttestation1;
            container.Attestation2 = indexedAttestation2;

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

            Ssz.Encode(encoded, container);
            AttesterSlashing?decoded = Ssz.DecodeAttesterSlashing(encoded);

            Assert.AreEqual(container, decoded);

            Merkle.Ize(out UInt256 root, container);
        }
        //    Run ``process_attester_slashing``, yielding:
        //  - pre-state('pre')
        //  - attester_slashing('attester_slashing')
        //  - post-state('post').
        //If ``valid == False``, run expecting ``AssertionError``
        private void RunAttesterSlashingProcessing(IServiceProvider testServiceProvider, BeaconState state, AttesterSlashing attesterSlashing, bool expectValid)
        {
            ChainConstants      chainConstants      = testServiceProvider.GetService <ChainConstants>();
            StateListLengths    stateListLengths    = testServiceProvider.GetService <IOptions <StateListLengths> >().Value;
            RewardsAndPenalties rewardsAndPenalties = testServiceProvider.GetService <IOptions <RewardsAndPenalties> >().Value;

            BeaconStateAccessor   beaconStateAccessor   = testServiceProvider.GetService <BeaconStateAccessor>();
            BeaconStateTransition beaconStateTransition = testServiceProvider.GetService <BeaconStateTransition>();

            if (!expectValid)
            {
                Should.Throw <Exception>(() =>
                {
                    beaconStateTransition.ProcessAttesterSlashing(state, attesterSlashing);
                });
                return;
            }

            var slashedIndices = attesterSlashing.Attestation1.CustodyBit0Indices
                                 .Union(attesterSlashing.Attestation1.CustodyBit1Indices)
                                 .ToList();

            ValidatorIndex proposerIndex         = beaconStateAccessor.GetBeaconProposerIndex(state);
            Gwei           preProposerBalance    = TestState.GetBalance(state, proposerIndex);
            var            preSlashings          = slashedIndices.ToDictionary(x => x, x => TestState.GetBalance(state, x));
            var            preWithdrawableEpochs = slashedIndices.ToDictionary(x => x, x => state.Validators[(int)(ulong)x].WithdrawableEpoch);

            Gwei totalProposerRewards = preSlashings.Values.Aggregate(Gwei.Zero, (sum, x) => sum + x / rewardsAndPenalties.WhistleblowerRewardQuotient);

            // Process slashing
            beaconStateTransition.ProcessAttesterSlashing(state, attesterSlashing);

            foreach (ValidatorIndex slashedIndex in slashedIndices)
            {
                Console.WriteLine($"Checking index {slashedIndex}");
                Epoch     preWithdrawableEpoch = preWithdrawableEpochs[slashedIndex];
                Validator slashedValidator     = state.Validators[(int)(ulong)slashedIndex];

                // Check Slashing
                slashedValidator.IsSlashed.ShouldBeTrue();
                slashedValidator.ExitEpoch.ShouldBeLessThan(chainConstants.FarFutureEpoch);
                if (preWithdrawableEpoch < chainConstants.FarFutureEpoch)
                {
                    ulong slashingsEpoch            = beaconStateAccessor.GetCurrentEpoch(state) + stateListLengths.EpochsPerSlashingsVector;
                    Epoch expectedWithdrawableEpoch = Epoch.Max(preWithdrawableEpoch, (Epoch)slashingsEpoch);
                    slashedValidator.WithdrawableEpoch.ShouldBe(expectedWithdrawableEpoch);
                }
                else
                {
                    slashedValidator.WithdrawableEpoch.ShouldBeLessThan(chainConstants.FarFutureEpoch);
                }

                Gwei preSlashing    = preSlashings[slashedIndex];
                Gwei slashedBalance = TestState.GetBalance(state, slashedIndex);
                slashedBalance.ShouldBeLessThan(preSlashing);
            }

            if (!slashedIndices.Contains(proposerIndex))
            {
                // gained whistleblower reward
                Gwei expectedProposerBalance = preProposerBalance + totalProposerRewards;
                Gwei proposerBalance         = TestState.GetBalance(state, proposerIndex);
                proposerBalance.ShouldBe(expectedProposerBalance);
            }
            else
            {
                // gained rewards for all slashings, which may include others. And only lost that of themselves.
                Gwei expectedProposerBalance = preProposerBalance + totalProposerRewards
                                               - (preSlashings[proposerIndex] / rewardsAndPenalties.MinimumSlashingPenaltyQuotient);
                Gwei proposerBalance = TestState.GetBalance(state, proposerIndex);
                proposerBalance.ShouldBe(expectedProposerBalance);
            }
        }
Пример #16
0
        public void Beacon_block_body_more_detailed()
        {
            AttestationData data = new AttestationData(
                new Slot(1),
                new CommitteeIndex(4),
                Sha256.OfAnEmptyString,
                new Checkpoint(new Epoch(2), Sha256.OfAnEmptyString),
                new Checkpoint(new Epoch(3), Sha256.OfAnEmptyString));

            Attestation attestation = new Attestation(
                new BitArray(new byte[5]),
                data,
                SszTest.TestSig1);

            DepositData depositData = new DepositData(
                SszTest.TestKey1,
                Sha256.OfAnEmptyString,
                new Gwei(7),
                SszTest.TestSig1);

            Deposit deposit = new Deposit(new Hash32[Ssz.DepositContractTreeDepth + 1], depositData);

            IndexedAttestation indexedAttestation1 = new IndexedAttestation(
                new ValidatorIndex[8],
                data,
                SszTest.TestSig1);

            IndexedAttestation indexedAttestation2 = new IndexedAttestation(
                new ValidatorIndex[8],
                data,
                SszTest.TestSig1);

            AttesterSlashing slashing = new AttesterSlashing(indexedAttestation1, indexedAttestation2);

            Eth1Data eth1Data = new Eth1Data(
                Sha256.OfAnEmptyString,
                9,
                Sha256.OfAnEmptyString);

            Attestation[] attestations = new Attestation[3];
            attestations[1] = attestation;

            Deposit[] deposits = new Deposit[3];
            deposits[2] = deposit;

            Bytes32 graffiti = new Bytes32(new byte[32]);

            AttesterSlashing[] attesterSlashings = new AttesterSlashing[3];
            attesterSlashings[0] = slashing;

            ProposerSlashing[] proposerSlashings = new ProposerSlashing[10];
            VoluntaryExit[]    voluntaryExits    = new VoluntaryExit[11];

            BeaconBlockBody body = new BeaconBlockBody(
                SszTest.TestSig1,
                eth1Data,
                graffiti,
                proposerSlashings,
                attesterSlashings,
                attestations,
                deposits,
                voluntaryExits
                );

            byte[] encoded = new byte[Ssz.BeaconBlockBodyLength(body)];
            Ssz.Encode(encoded, body);
        }
Пример #17
0
        private static IEnumerable <SszElement> GetValues(AttesterSlashing item, MiscellaneousParameters miscellaneousParameters)
        {
            yield return(item.Attestation1.ToSszContainer(miscellaneousParameters));

            yield return(item.Attestation2.ToSszContainer(miscellaneousParameters));
        }
Пример #18
0
 public static SszContainer ToSszContainer(this AttesterSlashing item, MiscellaneousParameters miscellaneousParameters)
 {
     return(new SszContainer(GetValues(item, miscellaneousParameters)));
 }
Пример #19
0
        public void Beacon_block_body_more_detailed()
        {
            AttestationData data = new AttestationData(
                new Slot(1),
                new CommitteeIndex(4),
                Sha256.RootOfAnEmptyString,
                new Checkpoint(new Epoch(2), Sha256.RootOfAnEmptyString),
                new Checkpoint(new Epoch(3), Sha256.RootOfAnEmptyString));

            Attestation attestation = new Attestation(
                new BitArray(new byte[5]),
                data,
                TestSig1);

            DepositData depositData = new DepositData(
                TestKey1,
                Sha256.Bytes32OfAnEmptyString,
                new Gwei(7),
                TestSig1);

            Deposit deposit = new Deposit(Enumerable.Repeat(Bytes32.Zero, Ssz.DepositContractTreeDepth + 1), depositData);

            IndexedAttestation indexedAttestation1 = new IndexedAttestation(
                new ValidatorIndex[8],
                data,
                TestSig1);

            IndexedAttestation indexedAttestation2 = new IndexedAttestation(
                new ValidatorIndex[8],
                data,
                TestSig1);

            AttesterSlashing slashing = new AttesterSlashing(indexedAttestation1, indexedAttestation2);

            Eth1Data eth1Data = new Eth1Data(
                Sha256.RootOfAnEmptyString,
                9,
                Sha256.Bytes32OfAnEmptyString);

            Attestation[] attestations = Enumerable.Repeat(Attestation.Zero, 3).ToArray();
            attestations[1] = attestation;

            Deposit zeroDeposit = new Deposit(Enumerable.Repeat(Bytes32.Zero, Ssz.DepositContractTreeDepth + 1), DepositData.Zero);

            Deposit[] deposits = Enumerable.Repeat(zeroDeposit, 3).ToArray();
            deposits[2] = deposit;

            Bytes32 graffiti = new Bytes32(new byte[32]);

            AttesterSlashing[] attesterSlashings = Enumerable.Repeat(AttesterSlashing.Zero, 3).ToArray();
            attesterSlashings[0] = slashing;

            ProposerSlashing[] proposerSlashings = Enumerable.Repeat(ProposerSlashing.Zero, 10).ToArray();

            SignedVoluntaryExit[] signedVoluntaryExits = Enumerable.Repeat(SignedVoluntaryExit.Zero, 11).ToArray();

            BeaconBlockBody body = new BeaconBlockBody(
                TestSig1,
                eth1Data,
                graffiti,
                proposerSlashings,
                attesterSlashings,
                attestations,
                deposits,
                signedVoluntaryExits
                );

            byte[] encoded = new byte[Ssz.BeaconBlockBodyLength(body)];
            Ssz.Encode(encoded, body);
        }
Пример #20
0
        public SszBeaconBlockBodyBenchmark()
        {
            AttestationData data = new AttestationData(
                new Slot(1),
                new CommitteeIndex(4),
                Sha256.RootOfAnEmptyString,
                new Checkpoint(new Epoch(2), Sha256.RootOfAnEmptyString),
                new Checkpoint(new Epoch(3), Sha256.RootOfAnEmptyString));

            Attestation attestation = new Attestation(
                new BitArray(new byte[5]),
                data,
                TestSig1
                );

            DepositData depositData = new DepositData(
                TestKey1,
                Sha256.Bytes32OfAnEmptyString,
                new Gwei(7),
                TestSig1);

            Deposit deposit = new Deposit(
                new Bytes32[Ssz.DepositContractTreeDepth + 1],
                depositData);

            IndexedAttestation indexedAttestation1 = new IndexedAttestation(
                new ValidatorIndex[8],
                data,
                TestSig1);

            IndexedAttestation indexedAttestation2 = new IndexedAttestation(
                new ValidatorIndex[8],
                data,
                TestSig1);

            AttesterSlashing slashing = new AttesterSlashing(indexedAttestation1, indexedAttestation2);

            Eth1Data eth1Data = new Eth1Data(
                Sha256.RootOfAnEmptyString,
                9,
                Sha256.Bytes32OfAnEmptyString);

            Attestation[] attestations = new Attestation[3];
            attestations[1] = attestation;

            Deposit[] deposits = new Deposit[3];
            deposits[2] = deposit;

            Bytes32 graffiti = new Bytes32(new byte[32]);

            AttesterSlashing[] attesterSlashings = new AttesterSlashing[3];
            attesterSlashings[0] = slashing;

            ProposerSlashing[] proposerSlashings = new ProposerSlashing[10];

            BlsSignature randaoReveal = TestSig1;

            SignedVoluntaryExit[] signedVoluntaryExits = new SignedVoluntaryExit[11];

            _body = new BeaconBlockBody(randaoReveal,
                                        eth1Data,
                                        graffiti,
                                        proposerSlashings,
                                        attesterSlashings,
                                        attestations,
                                        deposits,
                                        signedVoluntaryExits);

            _encoded = new byte[Ssz.BeaconBlockBodyLength(_body)];
        }
Пример #21
0
        public void Beacon_block_body_more_detailed()
        {
            BeaconBlockBody body = new BeaconBlockBody();

            AttestationData data = new AttestationData();

            data.Slot            = new Slot(1);
            data.Source          = new Checkpoint(new Epoch(2), Sha256.OfAnEmptyString);
            data.Target          = new Checkpoint(new Epoch(3), Sha256.OfAnEmptyString);
            data.CommitteeIndex  = new CommitteeIndex(4);
            data.BeaconBlockRoot = Sha256.OfAnEmptyString;

            Attestation attestation = new Attestation();

            attestation.Data            = data;
            attestation.Signature       = BlsSignature.TestSig1;
            attestation.AggregationBits = new byte[5];

            DepositData depositData = new DepositData();

            depositData.Amount                = new Gwei(7);
            depositData.Signature             = BlsSignature.TestSig1;
            depositData.PublicKey             = BlsPublicKey.TestKey1;
            depositData.WithdrawalCredentials = Sha256.OfAnEmptyString;

            Deposit deposit = new Deposit();

            deposit.Data  = depositData;
            deposit.Proof = new Hash32[Deposit.ContractTreeDepth + 1];

            IndexedAttestation indexedAttestation1 = new IndexedAttestation();

            indexedAttestation1.Data             = data;
            indexedAttestation1.Signature        = BlsSignature.TestSig1;
            indexedAttestation1.AttestingIndices = new ValidatorIndex[8];

            IndexedAttestation indexedAttestation2 = new IndexedAttestation();

            indexedAttestation2.Data             = data;
            indexedAttestation2.Signature        = BlsSignature.TestSig1;
            indexedAttestation2.AttestingIndices = new ValidatorIndex[8];

            AttesterSlashing slashing = new AttesterSlashing();

            slashing.Attestation1 = indexedAttestation1;
            slashing.Attestation2 = indexedAttestation2;

            Eth1Data eth1Data = new Eth1Data();

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

            body.Attestations    = new Attestation[3];
            body.Attestations[1] = attestation;

            body.Deposits    = new Deposit[3];
            body.Deposits[2] = deposit;

            body.Graffiti             = new byte[32];
            body.AttesterSlashings    = new AttesterSlashing[3];
            body.AttesterSlashings[0] = slashing;
            body.Eth1Data             = eth1Data;
            body.ProposerSlashings    = new ProposerSlashing[10];
            body.RandaoReversal       = BlsSignature.TestSig1;
            body.VoluntaryExits       = new VoluntaryExit[11];

            byte[] encoded = new byte[BeaconBlockBody.SszLength(body)];
            Ssz.Encode(encoded, body);
        }
Пример #22
0
 public static SszContainer ToSszContainer(this AttesterSlashing item, ulong maximumValidatorsPerCommittee)
 {
     return(new SszContainer(GetValues(item, maximumValidatorsPerCommittee)));
 }
Пример #23
0
        private static IEnumerable <SszElement> GetValues(AttesterSlashing item, ulong maximumValidatorsPerCommittee)
        {
            yield return(item.Attestation1.ToSszContainer(maximumValidatorsPerCommittee));

            yield return(item.Attestation2.ToSszContainer(maximumValidatorsPerCommittee));
        }