def VerifyScripts(verifiable): """ Verify the scripts of the provided `verifiable` object. Args: verifiable (neo.IO.Mixins.VerifiableMixin): Returns: bool: True if verification is successful. False otherwise. """ try: hashes = verifiable.GetScriptHashesForVerifying() except Exception as e: logger.debug("couldn't get script hashes %s " % e) return False if len(hashes) != len(verifiable.Scripts): return False blockchain = GetBlockchain() for i in range(0, len(hashes)): verification = verifiable.Scripts[i].VerificationScript if len(verification) == 0: sb = ScriptBuilder() sb.EmitAppCall(hashes[i].Data) verification = sb.ms.getvalue() else: verification_hash = Crypto.ToScriptHash(verification, unhex=False) if hashes[i] != verification_hash: return False state_reader = GetStateReader() script_table = CachedScriptTable( DBCollection(blockchain._db, DBPrefix.ST_Contract, ContractState)) engine = ApplicationEngine(TriggerType.Verification, verifiable, script_table, state_reader, Fixed8.Zero()) engine.LoadScript(verification) invocation = verifiable.Scripts[i].InvocationScript engine.LoadScript(invocation) try: success = engine.Execute() state_reader.ExecutionCompleted(engine, success) except Exception as e: state_reader.ExecutionCompleted(engine, False, e) if engine.ResultStack.Count != 1 or not engine.ResultStack.Pop( ).GetBoolean(): Helper.EmitServiceEvents(state_reader) return False Helper.EmitServiceEvents(state_reader) return True
def VerifyScripts(verifiable): try: hashes = verifiable.GetScriptHashesForVerifying() except Exception as e: logger.error("couldn't get script hashes %s " % e) return False if len(hashes) != len(verifiable.Scripts): return False state_reader = GetStateReader() blockchain = GetBlockchain() for i in range(0, len(hashes)): verification = verifiable.Scripts[i].VerificationScript if len(verification) == 0: # logger.info("VERIFICATION IS 0, EMITTING APP CALL") sb = ScriptBuilder() sb.EmitAppCall(hashes[i].Data) verification = sb.ToArray() else: verification_hash = Crypto.ToScriptHash(verification, unhex=False) if hashes[i] != verification_hash: return False engine = ApplicationEngine(TriggerType.Verification, verifiable, blockchain, state_reader, Fixed8.Zero()) engine.LoadScript(verification, False) invoction = verifiable.Scripts[i].InvocationScript engine.LoadScript(invoction, True) try: success = engine.Execute() state_reader.ExecutionCompleted(engine, success) except Exception as e: state_reader.ExecutionCompleted(engine, False, e) # pdb.set_trace() if engine.EvaluationStack.Count != 1 or not engine.EvaluationStack.Pop( ).GetBoolean(): return False return True
def VerifyScripts(verifiable): try: hashes = verifiable.GetScriptHashesForVerifying() except Exception as e: print("couldng get script hashes %s " % e) return False if len(hashes) != len(verifiable.Scripts): print("hashes not same length as verifiable scripts") return False print("hello!!!! %s " % hashes) for i in range(0, len(hashes)): verification = verifiable.Scripts[i].VerificationScript print("verifying script: %s %s " % (hashes[i], verification)) if len(verification) == 0: sb = ScriptBuilder() sb.EmitAppCall(hashes[i].Data) verification = sb.ToArray() else: if hashes[i] != verification: print("hashes not equal to script hash!") return False engine = ApplicationEngine(TriggerType.Verification, verifiable, GetBlockchain(), GetStateReader(), Fixed8.Zero()) engine.LoadScript(verification, False) engine.LoadScript(verifiable.Scripts[i].InvocationScript, True) res = engine.Execute() if not res: print("engine did not execune") return False else: print("engine did execute!") if engine.EvaluationStack.Count != 1 or not engine.EvaluationStack.Pop( ).GetBoolean(): print("stack not one, or stack false") return False return True