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)
def ptr_to_fresh(spec : Contract, ty : LLVMType, name : Optional[str] = None) -> Tuple[FreshVar, SetupVal]: """Add to``Contract`` ``spec`` an allocation of a pointer of type ``ty`` initialized to an unknown fresh value. :returns A fresh variable bound to the pointers initial value and the newly allocated pointer. (The fresh variable will be assigned ``name`` if provided/available.)""" var = spec.fresh_var(ty, name) ptr = spec.alloc(ty, points_to = var) return (var, ptr)
def y_spec(c: Contract) -> None: ss = c.alloc(alias_ty('struct.s')) z = c.fresh_var(i1, 'z') c.execute_func(ss, z) c.points_to_bitfield(ss, 'y', z) c.returns(void)
def ptr_to_fresh(c: Contract, ty: LLVMType, name: Optional[str] = None, read_only: bool = False) -> Tuple[FreshVar, SetupVal]: """Add to ``Contract`` ``c`` an allocation of a pointer of type ``ty`` initialized to an unknown fresh value. If ``read_only == True`` then the allocated memory is immutable. :returns A fresh variable bound to the pointers initial value and the newly allocated pointer. (The fresh variable will be assigned ``name`` if provided/available.)""" var = c.fresh_var(ty, name) ptr = c.alloc(ty, points_to=var, read_only=read_only) return (var, ptr)
def pre_counter(contract: Contract, counter: GhostVariable): n = contract.fresh_var(i32, "n") contract.precondition_f("{n} < 128") contract.ghost_value(counter, n) return n
def pre_counter(contract: Contract, counter: GhostVariable): n = contract.fresh_var(i32, "n") contract.precondition(n < cryptol("128")) contract.ghost_value(counter, n) return n