def eval(self, script): # check script size if (cached_serialized_size(script) > 10000): raise Exception("Serialized script size > 10000") # check disable opcodes disabled = [i.opcode for i in script.instructions if i.opcode in self.disabled_opcodes] if disabled: raise Exception("opcodes disabled: " + ",".join(OPCODE_NAMES[op] for op in disabled)) self.current_script = script for i in script.instructions: op = is_pushdata_with_param(i.opcode) and OP_PUSHDATA or i.opcode executed = all(self.cond_stack) if executed or is_conditionnal(op): if op in self.disabled_opcodes: print OPCODE_NAMES[op] OPCODE_FUNCTIONS[op](self, i) #print "stack:", [hexstr(elm)[:10] for elm in self.stack] if self.cond_stack: raise Exception("Conditionals not matching")
def __str__(self): if is_pushdata_with_param(self.opcode): return self.__pushdata__str__() if (self.opcode in OPCODE_NAMES): return OPCODE_NAMES[self.opcode] return ("UNKNOWN(%d)" % self.opcode)
def __hash__(self): if is_pushdata_with_param(self.opcode): return hash(self.data) return self.opcode
def deserialize(self, data, cursor=0): op = ord(data[cursor]) if is_pushdata_with_param(op): return (self._deserialize_pushdata(data, cursor)) return (Instruction(op), cursor + 1)
def __init__(self, opcode, data=None): self.opcode = opcode #value defined in opcodes.py self.data = data #optional (bytestring for pushdata) if is_pushdata_with_param(self.opcode) and len(self.data) > 520: raise Exception("PUSH_DATA with >520 bytes")
def get_size(self, instr): if is_pushdata_with_param(instr.opcode): return self._get_size_pushdata(instr) return 1
def serialize(self, instr): if is_pushdata_with_param(instr.opcode): return self.serialize_pushdata(instr) return chr(instr.opcode)
def __str__(self): if is_pushdata_with_param(self.opcode): return self.__pushdata__str__() if self.opcode in OPCODE_NAMES: return OPCODE_NAMES[self.opcode] return "UNKNOWN(%d)" % self.opcode
def __init__(self, opcode, data=None): self.opcode = opcode # value defined in opcodes.py self.data = data # optional (bytestring for pushdata) if is_pushdata_with_param(self.opcode) and len(self.data) > 520: raise Exception("PUSH_DATA with >520 bytes")