Expand description
Module for SafeType which enforce value range and realted functions.
Structs§
- FixLen
Bytes - Represents a fixed length byte array in circuit.
- FixLen
Bytes Vec - Represents a fixed length byte array in circuit. Not encouraged to use because
MAX_LEN
cannot be verified at compile time. - Safe
Bool - SafeType for bool (1 bit).
- Safe
Byte - SafeType for byte (8 bits).
- Safe
Type SafeType
’s goal is to avoid out-of-range undefined behavior. When building circuits, it’s common to use multipleAssignedValue<F>
s to represent a logical variable. For example, we might want to represent a hash with 32AssignedValue<F>
where eachAssignedValue
represents 1 byte. However, the range ofAssignedValue<F>
is much larger than 1 byte(0~255). If a circuit takes 32AssignedValue<F>
as inputs and some of them are actually greater than 255, there could be some undefined behaviors.SafeType
gurantees the value range of its ownedAssignedValue<F>
. So circuits don’t need to do any extra value checking if they take SafeType as inputs.- Safe
Type Chip - Chip for SafeType
- VarLen
Bytes - Represents a variable length byte array in circuit.
- VarLen
Bytes Vec - Represents a variable length byte array in circuit. Not encouraged to use because
MAX_LEN
cannot be verified at compile time.
Functions§
- left_
pad_ var_ array_ to_ fixed - Takes a fixed length array
arr
and returns a lengthout_len
array equal to[[0; out_len - len], arr[..len]].concat()
, i.e., we takearr[..len]
and zero pad it on the left.
Type Aliases§
- Safe
Address - SafeType for Address.
- Safe
Bytes32 - SafeType for bytes32.