static byte[] ForgeTxRollupDispatchTickets(TxRollupDispatchTicketsContent operation)
 {
     return(Bytes.Concat(
                ForgeTag(OperationTag.TxRollupDispatchTickets),
                ForgeTzAddress(operation.Source),
                ForgeMicheNat(operation.Fee),
                ForgeMicheNat(operation.Counter),
                ForgeMicheNat(operation.GasLimit),
                ForgeMicheNat(operation.StorageLimit),
                Base58.Parse(operation.Rollup, Prefix.txr1),
                ForgeInt32(operation.Level),
                Base58.Parse(operation.ContextHash, Prefix.Co),
                ForgeInt32(operation.MessageIndex),
                ForgeArray(operation.MessageResultPath
                           .Select(x => Base58.Parse(x, Prefix.txM))
                           .SelectMany(x => x)
                           .ToArray()),
                ForgeArray(operation.TicketsInfo.SelectMany(ti => Bytes.Concat(
                                                                ForgeArray(ForgeMicheline(ti.Contents)),
                                                                ForgeArray(ForgeMicheline(ti.Type)),
                                                                ForgeAddress(ti.Ticketer),
                                                                ForgeVarLong(ti.Amount),
                                                                ForgeTzAddress(ti.Claimer)))
                           .ToArray())));
 }
Esempio n. 2
0
        public Task <byte[]> ForgeOperationGroupAsync(string branch, IEnumerable <ManagerOperationContent> contents)
        {
            var branchBytes  = Base58.Parse(branch, Prefix.B.Length);
            var contentBytes = Bytes.Concat(contents.Select(ForgeOperation).ToArray());

            return(Task.FromResult(branchBytes.Concat(contentBytes)));
        }
 static byte[] ForgeActivation(ActivationContent operation)
 {
     return(Bytes.Concat(
                ForgeTag(OperationTag.Activation),
                ForgePkh(operation.Address),
                Hex.Parse(operation.Secret)));
 }
Esempio n. 4
0
 static byte[] ForgeParameters(Parameters param)
 {
     return(param == null?ForgeBool(false) : Bytes.Concat(
                    ForgeBool(true),
                    ForgeEntrypoint(param.Entrypoint),
                    ForgeArray(ForgeMicheline(param.Value).ToArray())));
 }
Esempio n. 5
0
 static byte[] ForgeActivation(ActivationContent operation)
 {
     return(Bytes.Concat(
                ForgeMicheNat((int)OperationTag.Activation),
                ForgeTz1Address(operation.Address),
                Hex.Parse(operation.Secret)));
 }
 static byte[] ForgeVdfRevelaion(VdfRevelationContent operation)
 {
     return(Bytes.Concat(
                ForgeTag(OperationTag.VdfRevelation),
                Hex.Parse(operation.Solution[0]),
                Hex.Parse(operation.Solution[1])));
 }
Esempio n. 7
0
 static byte[] ForgeDoubleBaking(DoubleBakingContent operation)
 {
     return(Bytes.Concat(
                ForgeMicheNat((int)OperationTag.DoubleBaking),
                ForgeArray(ForgeBlockHeader(operation.BlockHeader1)),
                ForgeArray(ForgeBlockHeader(operation.BlockHeader2))));
 }
Esempio n. 8
0
 static byte[] ForgeInlinedPreendorsement(InlinedPreendorsement op)
 {
     return(Bytes.Concat(
                Base58.Parse(op.Branch, 2),
                ForgePreendorsement(op.Operations),
                Base58.Parse(op.Signature, 3)));
 }
Esempio n. 9
0
 static byte[] ForgeDoublePreendorsement(DoublePreendorsementContent operation)
 {
     return(Bytes.Concat(
                ForgeMicheNat((int)OperationTag.DoublePreendorsement),
                ForgeArray(ForgeInlinedPreendorsement(operation.Op1)),
                ForgeArray(ForgeInlinedPreendorsement(operation.Op2))));
 }
Esempio n. 10
0
        public ReceiptTrie(IReleaseSpec releaseSpec, TxReceipt?[] txReceipts, bool allowProofs = false)
            : base(allowProofs ? (IDb) new MemDb() : NullDb.Instance, EmptyTreeHash, false, false, NullLogManager.Instance)
        {
            _allowProofs = allowProofs;
            if (txReceipts.Length == 0)
            {
                return;
            }

            // 3% allocations (2GB) on a Goerli 3M blocks fast sync due to calling receipt encoder hee
            // avoiding it would require pooling byte arrays and passing them as Spans to temporary trees
            // a temporary trie would be a trie that exists to create a state root only and then be disposed of
            for (int i = 0; i < txReceipts.Length; i++)
            {
                TxReceipt?currentReceipt = txReceipts[i];
                byte[]    receiptRlp     = Decoder.EncodeNew(currentReceipt,
                                                             releaseSpec.IsEip658Enabled
                        ? RlpBehaviors.Eip658Receipts
                        : RlpBehaviors.None);

                if (currentReceipt is not null && currentReceipt.TxType != TxType.Legacy)
                {
                    receiptRlp = Bytes.Concat((byte)currentReceipt.TxType, receiptRlp);
                }

                Set(Rlp.Encode(i).Bytes, receiptRlp);
            }

            // additional 3% 2GB is used here for trie nodes creation and root calculation
            UpdateRootHash();
        }
Esempio n. 11
0
 static byte[] ForgeSeedNonceRevelaion(SeedNonceRevelationContent operation)
 {
     return(Bytes.Concat(
                ForgeMicheNat((int)OperationTag.SeedNonceRevelation),
                ForgeInt32(operation.Level),
                Hex.Parse(operation.Nonce)));
 }
Esempio n. 12
0
        /// <summary>
        /// test
        /// <c>Text</c>
        /// readFields/write operations
        /// </summary>
        public virtual void TestReadWriteOperations()
        {
            string line = "adsawseeeeegqewgasddga";

            byte[] inputBytes = Runtime.GetBytesForString(line);
            inputBytes = Bytes.Concat(new byte[] { unchecked ((byte)22) }, inputBytes);
            DataInputBuffer  @in  = new DataInputBuffer();
            DataOutputBuffer @out = new DataOutputBuffer();

            Org.Apache.Hadoop.IO.Text text = new Org.Apache.Hadoop.IO.Text(line);
            try
            {
                @in.Reset(inputBytes, inputBytes.Length);
                text.ReadFields(@in);
            }
            catch (Exception)
            {
                Fail("testReadFields error !!!");
            }
            try
            {
                text.Write(@out);
            }
            catch (IOException)
            {
            }
            catch (Exception)
            {
                Fail("testReadWriteOperations error !!!");
            }
        }
Esempio n. 13
0
        public Packet Auth(PublicKey remoteNodeId, EncryptionHandshake handshake)
        {
            handshake.RemoteNodeId        = remoteNodeId;
            handshake.InitiatorNonce      = _cryptoRandom.GenerateRandomBytes(32);
            handshake.EphemeralPrivateKey = _ephemeralGenerator.Generate();

            byte[] staticSharedSecret = Proxy.EcdhSerialized(remoteNodeId.Bytes, _privateKey.KeyBytes);
            byte[] forSigning         = staticSharedSecret.Xor(handshake.InitiatorNonce);

            AuthEip8Message authMessage = new AuthEip8Message();

            authMessage.Nonce     = handshake.InitiatorNonce;
            authMessage.PublicKey = _privateKey.PublicKey;
            authMessage.Signature = _ecdsa.Sign(handshake.EphemeralPrivateKey, new Keccak(forSigning));

            byte[] authData = _messageSerializationService.Serialize(authMessage);
            int    size     = authData.Length + 32 + 16 + 65; // data + MAC + IV + pub

            byte[] sizeBytes  = size.ToBigEndianByteArray().Slice(2, 2);
            byte[] packetData = _eciesCipher.Encrypt(
                remoteNodeId,
                authData,
                sizeBytes);

            handshake.AuthPacket = new Packet(Bytes.Concat(sizeBytes, packetData));
            return(handshake.AuthPacket);
        }
Esempio n. 14
0
        /// <summary>
        /// Calculates merkleized SSZ root
        /// </summary>
        /// <param name="blsPublicKey"></param>
        /// <param name="withdrawalCredentials"></param>
        /// <param name="blsSignature"></param>
        /// <returns></returns>
        private static byte[] CalculateDepositDataRoot(
            byte[] blsPublicKey,
            byte[] withdrawalCredentials,
            byte[] blsSignature)
        {
            byte[] amount = new byte[8];
            BinaryPrimitives.WriteUInt64LittleEndian(amount, (ulong)((BigInteger)32.Ether() / (BigInteger)1.GWei()));

            var sha256 = SHA256.Create();

            byte[] zeroBytes32 = new byte[32];
            byte[] pubKeyInput = new byte[64];
            blsPublicKey.AsSpan().CopyTo(pubKeyInput.AsSpan(0, 48));
            byte[] pubKeyRoot    = sha256.ComputeHash(pubKeyInput);
            byte[] signatureRoot =
                sha256.ComputeHash(
                    Bytes.Concat(
                        sha256.ComputeHash(blsSignature.Slice(0, 64)),
                        sha256.ComputeHash(
                            Bytes.Concat(
                                blsSignature.Slice(64, 32),
                                zeroBytes32))));

            byte[] depositDataRoot = sha256.ComputeHash(
                Bytes.Concat(
                    sha256.ComputeHash(Bytes.Concat(pubKeyRoot, withdrawalCredentials)),
                    sha256.ComputeHash(Bytes.Concat(amount.PadRight(32), signatureRoot))));
            return(depositDataRoot);
        }
 static byte[] ForgeDoubleEndorsement(DoubleEndorsementContent operation)
 {
     return(Bytes.Concat(
                ForgeTag(OperationTag.DoubleEndorsement),
                ForgeArray(ForgeInlinedEndorsement(operation.Op1)),
                ForgeArray(ForgeInlinedEndorsement(operation.Op2))));
 }
Esempio n. 16
0
 static byte[] ForgeInlinedEndorsement(InlinedEndorsement op)
 {
     return(Bytes.Concat(
                Base58.Parse(op.Branch, 2),
                ForgeMicheNat((int)OperationTag.Endorsement),
                ForgeInt32(op.Operations.Level),
                Base58.Parse(op.Signature, 3)));
 }
Esempio n. 17
0
    private Bytes selectCombination(int c0, int c1, int c2, int c3, int c4, int c5, int c6, sbyte comb)
    {
        Bytes select = Bytes.EMPTY;

        if (hasFlag(comb, 1))
        {
            select = select.Concat(new Bytes(Convert.ToSByte(c0)));
        }
        if (hasFlag(comb, 2))
        {
            select = select.Concat(new Bytes(Convert.ToSByte(c1)));
        }
        if (hasFlag(comb, 4))
        {
            select = select.Concat(new Bytes(Convert.ToSByte(c2)));
        }
        if (hasFlag(comb, 8))
        {
            select = select.Concat(new Bytes(Convert.ToSByte(c3)));
        }
        if (hasFlag(comb, 16))
        {
            select = select.Concat(new Bytes(Convert.ToSByte(c4)));
        }
        if (hasFlag(comb, 32))
        {
            select = select.Concat(new Bytes(Convert.ToSByte(c5)));
        }
        if (hasFlag(comb, 64))
        {
            select = select.Concat(new Bytes(Convert.ToSByte(c6)));
        }

        return(select);
    }
 static byte[] ForgeEndorsement(EndorsementContent operation)
 {
     return(Bytes.Concat(
                ForgeTag(OperationTag.Endorsement),
                ForgeInt32(operation.Slot, 2),
                ForgeInt32(operation.Level),
                ForgeInt32(operation.Round),
                Base58.Parse(operation.PayloadHash, Prefix.vh)));
 }
Esempio n. 19
0
 static byte[] ForgeBallot(BallotContent operation)
 {
     return(Bytes.Concat(
                ForgeMicheNat((int)OperationTag.Ballot),
                ForgeTzAddress(operation.Source),
                ForgeInt32(operation.Period),
                Base58.Parse(operation.Proposal, 2),
                new[] { (byte)operation.Ballot }));
 }
Esempio n. 20
0
 static byte[] ForgePreendorsement(PreendorsementContent operation)
 {
     return(Bytes.Concat(
                ForgeMicheNat((int)OperationTag.Preendorsement),
                ForgeInt32(operation.Slot, 2),
                ForgeInt32(operation.Level),
                ForgeInt32(operation.Round),
                Base58.Parse(operation.PayloadHash, Prefix.vh)));
 }
        protected byte[] Serialize(byte[] type, byte[] data)
        {
            byte[]    payload   = Bytes.Concat(type[0], data);
            Keccak    toSign    = Keccak.Compute(payload);
            Signature signature = _signer.Sign(_privateKey, toSign);

            byte[] signatureBytes = Bytes.Concat(signature.Bytes, signature.RecoveryId);
            byte[] mdc            = Keccak.Compute(Bytes.Concat(signatureBytes, type, data)).Bytes;
            return(Bytes.Concat(mdc, signatureBytes, type, data));
        }
Esempio n. 22
0
        public void Uses_same_compression_as_py_zero()
        {
            byte[] bytesPy           = Bytes.FromHexString(File.ReadAllText(Path.Combine(TestContext.CurrentContext.WorkDirectory, "Rlpx", _pythonCompressedTestFileName)));
            byte[] bytesUncompressed = Bytes.FromHexString(File.ReadAllText(Path.Combine(TestContext.CurrentContext.WorkDirectory, "Rlpx", _uncompressedTestFileName)));

            ZeroSnappyEncoderForTest encoder = new ZeroSnappyEncoderForTest();

            byte[] compressed = encoder.TestEncode(Bytes.Concat(1, bytesUncompressed));
            Assert.AreEqual(bytesPy, compressed.Skip(1).ToArray());
        }
Esempio n. 23
0
        public void Roundtrip_zero()
        {
            SnappyDecoderForTest     decoder = new SnappyDecoderForTest();
            ZeroSnappyEncoderForTest encoder = new ZeroSnappyEncoderForTest();

            byte[] expectedUncompressed = Bytes.FromHexString(File.ReadAllText(Path.Combine(TestContext.CurrentContext.WorkDirectory, "Rlpx", _uncompressedTestFileName)));
            byte[] compressed           = encoder.TestEncode(Bytes.Concat(1, expectedUncompressed));
            byte[] uncompressedResult   = decoder.TestDecode(compressed.Skip(1).ToArray());
            Assert.AreEqual(expectedUncompressed, uncompressedResult);
        }
 static byte[] ForgeTxRollupOrigination(TxRollupOriginationContent operation)
 {
     return(Bytes.Concat(
                ForgeTag(OperationTag.TxRollupOrigination),
                ForgeTzAddress(operation.Source),
                ForgeMicheNat(operation.Fee),
                ForgeMicheNat(operation.Counter),
                ForgeMicheNat(operation.GasLimit),
                ForgeMicheNat(operation.StorageLimit)));
 }
Esempio n. 25
0
 static byte[] ForgeProposals(ProposalsContent operation)
 {
     return(Bytes.Concat(
                ForgeMicheNat((int)OperationTag.Proposals),
                ForgeTzAddress(operation.Source),
                ForgeInt32(operation.Period),
                ForgeArray(operation.Proposals
                           .Select(x => Base58.Parse(x, 2))
                           .SelectMany(x => x)
                           .ToArray())));
 }
        public byte[] Serialize(AuthEip8Message msg)
        {
            byte[] data = Rlp.Encode(
                Rlp.Encode(Bytes.Concat(msg.Signature.Bytes, msg.Signature.RecoveryId)),
                Rlp.Encode(msg.PublicKey.Bytes),
                Rlp.Encode(msg.Nonce),
                Rlp.Encode(msg.Version)
                ).Bytes;

            return(_messagePad?.Pad(data) ?? data);
        }
 static byte[] ForgeTxRollupReturnBond(TxRollupReturnBondContent operation)
 {
     return(Bytes.Concat(
                ForgeTag(OperationTag.TxRollupReturnBond),
                ForgeTzAddress(operation.Source),
                ForgeMicheNat(operation.Fee),
                ForgeMicheNat(operation.Counter),
                ForgeMicheNat(operation.GasLimit),
                ForgeMicheNat(operation.StorageLimit),
                Base58.Parse(operation.Rollup, Prefix.txr1)));
 }
Esempio n. 28
0
 static byte[] ForgeDelegation(DelegationContent operation)
 {
     return(Bytes.Concat(
                ForgeMicheNat((int)OperationTag.Delegation),
                ForgeTzAddress(operation.Source),
                ForgeMicheNat(operation.Fee),
                ForgeMicheNat(operation.Counter),
                ForgeMicheNat(operation.GasLimit),
                ForgeMicheNat(operation.StorageLimit),
                ForgeDelegate(operation.Delegate)));
 }
Esempio n. 29
0
 static byte[] ForgeReveal(RevealContent operation)
 {
     return(Bytes.Concat(
                ForgeMicheNat((int)OperationTag.Reveal),
                ForgeTzAddress(operation.Source),
                ForgeMicheNat(operation.Fee),
                ForgeMicheNat(operation.Counter),
                ForgeMicheNat(operation.GasLimit),
                ForgeMicheNat(operation.StorageLimit),
                ForgePublicKey(operation.PublicKey)));
 }
Esempio n. 30
0
 static byte[] ForgeRegisterConstant(RegisterConstantContent operation)
 {
     return(Bytes.Concat(
                ForgeMicheNat((int)OperationTag.RegisterConstant),
                ForgeTzAddress(operation.Source),
                ForgeMicheNat(operation.Fee),
                ForgeMicheNat(operation.Counter),
                ForgeMicheNat(operation.GasLimit),
                ForgeMicheNat(operation.StorageLimit),
                ForgeArray(ForgeMicheline(operation.Value))));
 }