Ejemplo n.º 1
0
        public void InvalidSignature()
        {
            // Arrange
            IServiceProvider testServiceProvider = TestSystem.BuildTestServiceProvider();
            BeaconState      state = TestState.PrepareTestState(testServiceProvider);

            TimeParameters      timeParameters      = testServiceProvider.GetService <IOptions <TimeParameters> >().Value;
            BeaconStateAccessor beaconStateAccessor = testServiceProvider.GetService <BeaconStateAccessor>();

            // move state forward PERSISTENT_COMMITTEE_PERIOD epochs to allow for exit
            ulong move    = timeParameters.SlotsPerEpoch * (ulong)timeParameters.PersistentCommitteePeriod;
            ulong newSlot = state.Slot + move;

            state.SetSlot((Slot)newSlot);

            Epoch          currentEpoch   = beaconStateAccessor.GetCurrentEpoch(state);
            ValidatorIndex validatorIndex = beaconStateAccessor.GetActiveValidatorIndices(state, currentEpoch)[0];
            Validator      validator      = state.Validators[(int)(ulong)validatorIndex];

            byte[] privateKey = TestKeys.PublicKeyToPrivateKey(validator.PublicKey, timeParameters);

            VoluntaryExit       voluntaryExit       = TestVoluntaryExit.BuildVoluntaryExit(testServiceProvider, currentEpoch, validatorIndex);
            SignedVoluntaryExit signedVoluntaryExit = new SignedVoluntaryExit(voluntaryExit, BlsSignature.Zero);

            RunVoluntaryExitProcessing(testServiceProvider, state, signedVoluntaryExit, expectValid: false);
        }
Ejemplo n.º 2
0
        public static void Ize(out UInt256 root, SignedVoluntaryExit container)
        {
            Merkleizer merkleizer = new Merkleizer(1);

            merkleizer.Feed(container.Message);
            merkleizer.Feed(container.Signature);
            merkleizer.CalculateRoot(out root);
        }
Ejemplo n.º 3
0
        public static void Encode(Span <byte> span, SignedVoluntaryExit container)
        {
            if (span.Length != SignedVoluntaryExitLength)
            {
                ThrowTargetLength <SignedVoluntaryExit>(span.Length, SignedVoluntaryExitLength);
            }
            int offset = 0;

            Encode(span, container, ref offset);
        }
Ejemplo n.º 4
0
        private static SignedVoluntaryExit[] DecodeSignedVoluntaryExitVector(ReadOnlySpan <byte> span, ref int offset, int endingOffset)
        {
            int count = (endingOffset - offset) / SignedVoluntaryExitLength;

            SignedVoluntaryExit[] containers = new SignedVoluntaryExit[count];
            for (int i = 0; i < count; i++)
            {
                containers[i] = DecodeSignedVoluntaryExit(span, ref offset);
            }
            return(containers);
        }
Ejemplo n.º 5
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)];
        }
Ejemplo n.º 6
0
        //    Run ``process_voluntary_exit``, yielding:
        //  - pre-state('pre')
        //  - voluntary_exit('voluntary_exit')
        //  - post-state('post').
        //If ``valid == False``, run expecting ``AssertionError``
        private void RunVoluntaryExitProcessing(IServiceProvider testServiceProvider, BeaconState state, SignedVoluntaryExit signedVoluntaryExit, bool expectValid)
        {
            TimeParameters        timeParameters        = testServiceProvider.GetService <IOptions <TimeParameters> >().Value;
            MaxOperationsPerBlock maxOperationsPerBlock = testServiceProvider.GetService <IOptions <MaxOperationsPerBlock> >().Value;

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

            // Act
            if (!expectValid)
            {
                Should.Throw <Exception>(() =>
                {
                    beaconStateTransition.ProcessVoluntaryExit(state, signedVoluntaryExit);
                });
                return;
            }

            ValidatorIndex validatorIndex = signedVoluntaryExit.Message.ValidatorIndex;

            Epoch preExitEpoch = state.Validators[(int)(ulong)validatorIndex].ExitEpoch;

            beaconStateTransition.ProcessVoluntaryExit(state, signedVoluntaryExit);

            // Assert
            preExitEpoch.ShouldBe(chainConstants.FarFutureEpoch);

            Epoch postExitEpoch = state.Validators[(int)(ulong)validatorIndex].ExitEpoch;

            postExitEpoch.ShouldBeLessThan(chainConstants.FarFutureEpoch);
        }
        private static IEnumerable <SszElement> GetValues(SignedVoluntaryExit item)
        {
            yield return(item.Message.ToSszContainer());

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

            return(new Root(tree.HashTreeRoot()));
        }
Ejemplo n.º 10
0
 private static void Encode(Span <byte> span, SignedVoluntaryExit container, ref int offset)
 {
     Encode(span, container.Message, ref offset);
     Encode(span, container.Signature, ref offset);
 }