def execute_zero_compare(prim: str, stack: MichelsonStack, stdout: List[str], compare: Callable[[int], bool]): a = cast(IntType, stack.pop1()) a.assert_type_equal(IntType) res = BoolType(compare(int(a))) stack.push(res) stdout.append(format_stdout(prim, [a], [res]))
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): key, src = cast(Tuple[MichelsonType, Union[SetType, MapType, BigMapType]], stack.pop2()) src.assert_type_in(MapType, BigMapType, SetType) res = BoolType.from_value(src.contains(key)) stack.push(res) stdout.append(format_stdout(cls.prim, [key, src], [res])) return cls()
def execute(cls, stack: MichelsonStack, stdout: List[str], context: AbstractContext): pk, sig, msg = cast(Tuple[KeyType, SignatureType, BytesType], stack.pop3()) pk.assert_type_equal(KeyType) sig.assert_type_equal(SignatureType) msg.assert_type_equal(BytesType) key = Key.from_encoded_key(str(pk)) try: key.verify(signature=str(sig), message=bytes(msg)) except ValueError: res = BoolType(False) else: res = BoolType(True) stack.push(res) stdout.append(format_stdout(cls.prim, [pk, sig, msg], [res])) return cls()
def execute(cls, stack: 'MichelsonStack', stdout: List[str], context: AbstractContext): points = cast(ListType, stack.pop1()) points.assert_type_equal( ListType.create_type(args=[ PairType.create_type(args=[BLS12_381_G1Type, BLS12_381_G2Type]) ])) prod = FQ12.one() for pair in points: g1, g2 = tuple( iter(pair)) # type: BLS12_381_G1Type, BLS12_381_G2Type prod = prod * bls12_381.pairing(g2.to_point(), g1.to_point()) res = BoolType.from_value(FQ12.one() == prod) stack.push(res) stdout.append(format_stdout(cls.prim, [points], [res])) return cls()