| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
ZkFold.Symbolic.Data.UInt
Synopsis
- class StrictConv b a where
- strictConv :: b -> a
- class StrictNum a where
- newtype UInt (n :: Natural) (r :: RegisterSize) (context :: (Type -> Type) -> Type) = UInt (context (Vector (NumberOfRegisters (BaseField context) n r)))
- type OrdWord = 16
- toConstant :: ToConstant a => a -> Const a
- toNative :: forall n r c a. (Symbolic c, KnownNat n, KnownRegisterSize r, BaseField c ~ a) => KnownNat (GetRegisterSize a n r) => UInt n r c -> FieldElement c
- asWords :: forall wordSize regSize ctx k. Symbolic ctx => KnownNat (Ceil regSize wordSize) => KnownNat wordSize => ctx (Vector k) -> ctx (Vector (k * Ceil regSize wordSize))
- expMod :: forall c n p m r. Symbolic c => KnownRegisterSize r => KnownNat p => KnownNat n => KnownNat m => KnownNat (2 * m) => KnownRegisters c (2 * m) r => KnownNat (Ceil (GetRegisterSize (BaseField c) (2 * m) r) OrdWord) => NFData (c (Vector (NumberOfRegisters (BaseField c) (2 * m) r))) => UInt n r c -> UInt p r c -> UInt m r c -> UInt m r c
- eea :: forall n c r. Symbolic c => SemiEuclidean (UInt n r c) => KnownNat n => KnownRegisters c n r => AdditiveGroup (UInt n r c) => UInt n r c -> UInt n r c -> (UInt n r c, UInt n r c, UInt n r c)
- natural :: forall c n r i. (Symbolic c, KnownNat n, KnownRegisterSize r, Witness i (WitnessField c)) => Vector (NumberOfRegisters (BaseField c) n r) i -> IntegralOf (WitnessField c)
- register :: forall c n r. (Symbolic c, KnownNat n, KnownRegisterSize r) => IntegralOf (WitnessField c) -> Zp (NumberOfRegisters (BaseField c) n r) -> WitnessField c
- productMod :: forall c n r. Symbolic c => KnownRegisterSize r => KnownNat n => KnownRegisters c n r => KnownNat (Ceil (GetRegisterSize (BaseField c) n r) OrdWord) => UInt n r c -> UInt n r c -> UInt n r c -> (UInt n r c, UInt n r c)
- blueprintGE :: forall r i a w m f. (Arithmetic a, MonadCircuit i a w m, Zip f, Foldable f, KnownNat r) => f i -> f i -> m i
Documentation
class StrictConv b a where Source #
Methods
strictConv :: b -> a Source #
Instances
| (Symbolic c, KnownNat n, KnownRegisterSize rs) => StrictConv Natural (UInt n rs c) Source # | |
Defined in ZkFold.Symbolic.Data.UInt Methods strictConv :: Natural -> UInt n rs c Source # | |
| (Symbolic c, KnownNat n, KnownRegisterSize r) => StrictConv (Zp p) (UInt n r c) Source # | |
Defined in ZkFold.Symbolic.Data.UInt Methods strictConv :: Zp p -> UInt n r c Source # | |
| (Symbolic c, KnownNat n, KnownRegisterSize r) => StrictConv (c Par1) (UInt n r c) Source # | |
Defined in ZkFold.Symbolic.Data.UInt Methods strictConv :: c Par1 -> UInt n r c Source # | |
newtype UInt (n :: Natural) (r :: RegisterSize) (context :: (Type -> Type) -> Type) Source #
Constructors
| UInt (context (Vector (NumberOfRegisters (BaseField context) n r))) |
Instances
toConstant :: ToConstant a => a -> Const a Source #
A way to turn element of a into a .
According to the law of Const a,
has to be right inverse to ToConstant.fromConstant
toNative :: forall n r c a. (Symbolic c, KnownNat n, KnownRegisterSize r, BaseField c ~ a) => KnownNat (GetRegisterSize a n r) => UInt n r c -> FieldElement c Source #
asWords :: forall wordSize regSize ctx k. Symbolic ctx => KnownNat (Ceil regSize wordSize) => KnownNat wordSize => ctx (Vector k) -> ctx (Vector (k * Ceil regSize wordSize)) Source #
expMod :: forall c n p m r. Symbolic c => KnownRegisterSize r => KnownNat p => KnownNat n => KnownNat m => KnownNat (2 * m) => KnownRegisters c (2 * m) r => KnownNat (Ceil (GetRegisterSize (BaseField c) (2 * m) r) OrdWord) => NFData (c (Vector (NumberOfRegisters (BaseField c) (2 * m) r))) => UInt n r c -> UInt p r c -> UInt m r c -> UInt m r c Source #
expMod n pow modulus calculates n^pow % modulus where all values are arithmetised
eea :: forall n c r. Symbolic c => SemiEuclidean (UInt n r c) => KnownNat n => KnownRegisters c n r => AdditiveGroup (UInt n r c) => UInt n r c -> UInt n r c -> (UInt n r c, UInt n r c, UInt n r c) Source #
Extended Euclidean algorithm.
Exploits the fact that s_i and t_i change signs in turns on each iteration, so it adjusts the formulas correspondingly
and never requires signed arithmetic.
(i.e. it calculates x = b - a instead of x = a - b when a - b is negative
and changes y - x to y + x on the following iteration)
This only affects Bezout coefficients, remainders are calculated without changes as they are always non-negative.
If the algorithm is used to calculate Bezout coefficients,
it requires that a and b are coprime, b is not 1 and a is not 0, otherwise the optimisation above is not valid.
If the algorithm is only used to find gcd(a, b) (i.e. s and t will be discarded), a and b can be arbitrary integers.
natural :: forall c n r i. (Symbolic c, KnownNat n, KnownRegisterSize r, Witness i (WitnessField c)) => Vector (NumberOfRegisters (BaseField c) n r) i -> IntegralOf (WitnessField c) Source #
"natural" value from vector of registers.
register :: forall c n r. (Symbolic c, KnownNat n, KnownRegisterSize r) => IntegralOf (WitnessField c) -> Zp (NumberOfRegisters (BaseField c) n r) -> WitnessField c Source #
register n i returns i-th register of n.
productMod :: forall c n r. Symbolic c => KnownRegisterSize r => KnownNat n => KnownRegisters c n r => KnownNat (Ceil (GetRegisterSize (BaseField c) n r) OrdWord) => UInt n r c -> UInt n r c -> UInt n r c -> (UInt n r c, UInt n r c) Source #
Calculate a * b using less constraints than would've been required by these operations used consequentlydivMod m
blueprintGE :: forall r i a w m f. (Arithmetic a, MonadCircuit i a w m, Zip f, Foldable f, KnownNat r) => f i -> f i -> m i Source #