def test_swap(self): if __name__ == "__main__": saw.view(saw.LogResults()) swap_bc = str(Path('tests','saw','test-files', 'swap.bc')) mod = saw.llvm_load_module(swap_bc) result = saw.llvm_verify(mod, 'swap', Swap()) self.assertIs(result.is_success(), True)
self.returns(void) class SignalTypeRefSpec(Contract): def specification(self) -> None: ref_count = self.fresh_var(i32, "ref_count") self.precondition(cryptol(f"{ref_count.name()} > 0")) instance = self.alloc(alias_ty("struct.signal_type_base")) self.points_to(field(instance, "ref_count"), ref_count) self.execute_func(instance) self.points_to(field(instance, "ref_count"), cryptol(f"{ref_count.name()} + 1")) self.returns(void) buffer_alloc_ov = llvm_verify(mod, "signal_buffer_alloc", BufferAllocSpec(64)) buffer_create_ov = llvm_verify(mod, "signal_buffer_create", BufferCreateSpec(64)) buffer_copy_ov = llvm_verify(mod, "signal_buffer_copy", BufferCopySpec(63)) buffer_copy_n_ov = llvm_verify(mod, "signal_buffer_n_copy", BufferCopyNSpec(64, 31)) buffer_append_ov = llvm_verify(mod, "signal_buffer_append", BufferAppendSpec(63, 31)) constant_memcmp_ov = llvm_verify(mod, "signal_constant_memcmp", ConstantMemcmpSpec(63)) signal_type_init_ov = llvm_verify(mod, "signal_type_init", SignalTypeInitSpec()) signal_type_ref_ov = llvm_verify(mod, "signal_type_ref", SignalTypeRefSpec())
uninterps = ["hmac_init", "hmac_update", "hmac_final"] signal_hmac_sha256_init_ov = llvm_assume( mod, "signal_hmac_sha256_init", SignalHmacSha256InitSpec(RATCHET_MAC_KEY_LENGTH)) signal_hmac_sha256_update_djb_key_ov = llvm_assume( mod, "signal_hmac_sha256_update", SignalHmacSha256UpdateSpec(DJB_KEY_LEN + 1)) signal_hmac_sha256_update_serialized_ov = llvm_assume( mod, "signal_hmac_sha256_update", SignalHmacSha256UpdateSpec(SERIALIZED_LENGTH)) signal_hmac_sha256_final_ov = llvm_assume(mod, "signal_hmac_sha256_final", SignalHmacSha256FinalSpec()) signal_hmac_sha256_cleanup_ov = llvm_verify(mod, "signal_hmac_sha256_cleanup", SignalHmacSha256CleanupSpec()) signal_message_get_mac_ov = llvm_verify( mod, "signal_message_get_mac", SignalMessageGetMacSpec(RATCHET_MAC_KEY_LENGTH, SERIALIZED_LENGTH), lemmas=[ signal_hmac_sha256_init_ov, signal_hmac_sha256_update_djb_key_ov, signal_hmac_sha256_update_serialized_ov, signal_hmac_sha256_final_ov ], script=ProofScript([z3(uninterps)])) signal_message_verify_mac_ov = llvm_verify( mod, "signal_message_verify_mac", SignalMessageVerifyMacSpec(RATCHET_MAC_KEY_LENGTH, SERIALIZED_LENGTH + SIGNAL_MESSAGE_MAC_LENGTH), lemmas=[signal_message_get_mac_ov],
from buffer_helpers import * from load import mod from saw_helpers import * DJB_TYPE = 0x05 DJB_KEY_LEN = 32 def alloc_ec_public_key(spec: Contract) -> Tuple[FreshVar, FreshVar, SetupVal]: signal_type_base_ty = alias_ty("struct.signal_type_base") djb_array_ty = array_ty(DJB_KEY_LEN, i8) key_base = spec.fresh_var(signal_type_base_ty, "key_base") key_data = spec.fresh_var(djb_array_ty, "key_data") key = spec.alloc(struct_ty(signal_type_base_ty, djb_array_ty), points_to = struct(key_base, key_data)) return (key_base, key_data, key) class ECPublicKeySerializeSpec(Contract): def specification(self) -> None: length = DJB_KEY_LEN + 1 buffer_ = self.alloc(ptr_ty(buffer_type(length))) (_, key_data, key) = alloc_ec_public_key(self) self.execute_func(buffer_, key) buf = alloc_pointsto_buffer(self, length, cryptol(f"[`({DJB_TYPE})] # {key_data.name()} : [{length}][8]")) self.points_to(buffer_, buf) self.returns(int_to_32_cryptol(0)) ec_public_key_serialize_ov = llvm_verify(mod, "ec_public_key_serialize", ECPublicKeySerializeSpec())