Пример #1
0
 internal static bool VerifyScripts(this IVerifiable verifiable)
 {
     UInt160[] hashes;
     try
     {
         hashes = verifiable.GetScriptHashesForVerifying();
     }
     catch (InvalidOperationException)
     {
         return(false);
     }
     if (hashes.Length != verifiable.Scripts.Length)
     {
         return(false);
     }
     for (int i = 0; i < hashes.Length; i++)
     {
         byte[] verification = verifiable.Scripts[i].VerificationScript;
         if (verification.Length == 0)
         {
             using (ScriptBuilder sb = new ScriptBuilder())
             {
                 sb.EmitAppCall(hashes[i].ToArray());
                 verification = sb.ToArray();
             }
         }
         else
         {
             if (hashes[i] != verifiable.Scripts[i].ScriptHash)
             {
                 return(false);
             }
         }
         using (StateReader service = new StateReader(verifiable))
         {
             ApplicationEngine engine = new ApplicationEngine(TriggerType.Verification, verifiable,
                                                              BlockchainBase.GetBlockchain(verifiable.ChainHash), service, Fixed8.Zero);
             engine.LoadScript(verification, false);
             engine.LoadScript(verifiable.Scripts[i].InvocationScript, true);
             if (!engine.Execute())
             {
                 return(false);
             }
             if (engine.EvaluationStack.Count != 1 || !engine.EvaluationStack.Pop().GetBoolean())
             {
                 return(false);
             }
         }
     }
     return(true);
 }
Пример #2
0
        private bool VerifyAccountState(UInt256 ChainHash)
        {
            switch (Field)
            {
            case "Votes":
                BlockchainBase chain = BlockchainBase.GetBlockchain(ChainHash);
                if (chain == null)
                {
                    return(false);
                }
                ECPoint[] pubkeys;
                try
                {
                    pubkeys = Value.AsSerializableArray <ECPoint>((int)BlockchainBase.MaxValidators);
                }
                catch (FormatException)
                {
                    return(false);
                }
                UInt160      hash    = new UInt160(Key);
                AccountState account = chain.GetAccountState(hash);
                if (account?.IsFrozen != false)
                {
                    return(false);
                }
                if (pubkeys.Length > 0)
                {
                    if (account.GetBalance(BlockchainBase.GetStaticAttr().GoverningToken.Hash).Equals(Fixed8.Zero))
                    {
                        return(false);
                    }
                    HashSet <ECPoint> sv = new HashSet <ECPoint>(chain.StandbyValidators);
                    DataCache <ECPoint, ValidatorState> validators = chain.GetStates <ECPoint, ValidatorState>();
                    foreach (ECPoint pubkey in pubkeys)
                    {
                        if (!sv.Contains(pubkey) && validators.TryGet(pubkey)?.Registered != true)
                        {
                            return(false);
                        }
                    }
                }
                return(true);

            default:
                return(false);
            }
        }