コード例 #1
0
        protected internal byte[] Sha256(StackItem item)
        {
            ReadOnlySpan <byte> value = item switch
            {
                InteropInterface _interface => _interface.GetInterface <IVerifiable>().GetHashData(),
                Null _ => ScriptContainer.GetHashData(),
                _ => item.GetSpan()
            };

            return(value.Sha256());
        }
コード例 #2
0
        private bool VerifyWithECDsa(StackItem item, byte[] pubkey, byte[] signature, ECCurve curve)
        {
            ReadOnlySpan <byte> message = item switch
            {
                InteropInterface _interface => _interface.GetInterface <IVerifiable>().GetHashData(),
                Null _ => ScriptContainer.GetHashData(),
                _ => item.GetSpan()
            };

            try
            {
                return(Crypto.VerifySignature(message, signature, pubkey, curve));
            }
            catch (ArgumentException)
            {
                return(false);
            }
        }
コード例 #3
0
            private static bool Crypto_ECDsaVerify(ApplicationEngine engine)
            {
                StackItem           item0   = engine.CurrentContext.EvaluationStack.Pop();
                ReadOnlySpan <byte> message = item0 switch
                {
                    InteropInterface _interface => _interface.GetInterface <IVerifiable>().GetHashData(),
                    Null _ => engine.ScriptContainer.GetHashData(),
                    _ => item0.GetSpan()
                };
                ReadOnlySpan <byte> pubkey    = engine.CurrentContext.EvaluationStack.Pop().GetSpan();
                ReadOnlySpan <byte> signature = engine.CurrentContext.EvaluationStack.Pop().GetSpan();

                try
                {
                    engine.CurrentContext.EvaluationStack.Push(Cryptography.Crypto.VerifySignature(message, signature, pubkey));
                }
                catch (ArgumentException)
                {
                    engine.CurrentContext.EvaluationStack.Push(false);
                }
                return(true);
            }
コード例 #4
0
        private bool CheckMultiSigWithECDsa(StackItem item0, byte[][] pubkeys, byte[][] signatures, ECCurve curve)
        {
            int m = signatures.Length, n = pubkeys.Length;
            ReadOnlySpan <byte> message = item0 switch
            {
                InteropInterface _interface => _interface.GetInterface <IVerifiable>().GetHashData(),
                Null _ => ScriptContainer.GetHashData(),
                _ => item0.GetSpan()
            };

            if (n == 0 || m == 0 || m > n)
            {
                throw new ArgumentException();
            }
            AddGas(ECDsaVerifyPrice * n * exec_fee_factor);
            try
            {
                for (int i = 0, j = 0; i < m && j < n;)
                {
                    if (Crypto.VerifySignature(message, signatures[i], pubkeys[j], curve))
                    {
                        i++;
                    }
                    j++;
                    if (m - i > n - j)
                    {
                        return(false);
                    }
                }
            }
            catch (ArgumentException)
            {
                return(false);
            }
            return(true);
        }
    }
コード例 #5
0
 public InteropInterfaceReturn(InteropInterface item)
 {
     this.value  = item.GetInterface <dynamic>();
     this.IsNull = item.IsNull;
 }
コード例 #6
0
            private static bool Crypto_ECDsaCheckMultiSig(ApplicationEngine engine)
            {
                StackItem           item0   = engine.CurrentContext.EvaluationStack.Pop();
                ReadOnlySpan <byte> message = item0 switch
                {
                    InteropInterface _interface => _interface.GetInterface <IVerifiable>().GetHashData(),
                    Null _ => engine.ScriptContainer.GetHashData(),
                    _ => item0.GetSpan()
                };
                int n;

                byte[][]  pubkeys;
                StackItem item = engine.CurrentContext.EvaluationStack.Pop();

                if (item is Array array1)
                {
                    pubkeys = array1.Select(p => p.GetSpan().ToArray()).ToArray();
                    n       = pubkeys.Length;
                    if (n == 0)
                    {
                        return(false);
                    }
                }
                else
                {
                    n = (int)item.GetBigInteger();
                    if (n < 1 || n > engine.CurrentContext.EvaluationStack.Count)
                    {
                        return(false);
                    }
                    pubkeys = new byte[n][];
                    for (int i = 0; i < n; i++)
                    {
                        pubkeys[i] = engine.CurrentContext.EvaluationStack.Pop().GetSpan().ToArray();
                    }
                }
                int m;

                byte[][] signatures;
                item = engine.CurrentContext.EvaluationStack.Pop();
                if (item is Array array2)
                {
                    signatures = array2.Select(p => p.GetSpan().ToArray()).ToArray();
                    m          = signatures.Length;
                    if (m == 0 || m > n)
                    {
                        return(false);
                    }
                }
                else
                {
                    m = (int)item.GetBigInteger();
                    if (m < 1 || m > n || m > engine.CurrentContext.EvaluationStack.Count)
                    {
                        return(false);
                    }
                    signatures = new byte[m][];
                    for (int i = 0; i < m; i++)
                    {
                        signatures[i] = engine.CurrentContext.EvaluationStack.Pop().GetSpan().ToArray();
                    }
                }
                bool fSuccess = true;

                try
                {
                    for (int i = 0, j = 0; fSuccess && i < m && j < n;)
                    {
                        if (Cryptography.Crypto.VerifySignature(message, signatures[i], pubkeys[j]))
                        {
                            i++;
                        }
                        j++;
                        if (m - i > n - j)
                        {
                            fSuccess = false;
                        }
                    }
                }
                catch (ArgumentException)
                {
                    fSuccess = false;
                }
                engine.CurrentContext.EvaluationStack.Push(fSuccess);
                return(true);
            }
        }