Nested modules Permutation and Hash + missing stubs for Hades
Still requires some thoughts. The idea is to have submodules:
-
Bls12_381.Permutation.Hades
implementing the Hades permutation -
Bls12_381.Permutation.Rescue
implementing the Rescue permutation
To follow some implementations (Zcash in Orchard and Dusk)
-
Bls12_381.Hash.Poseidon128
: instantiation of Poseidon128 (note the index for the partial rounds is the first element) -
Bls12_381.Hash.Poseidon252
: instantiation of Poseidon252 (note the index for the partial rounds if the last element)
I think about providing a fixed and variable length instance (for padding). The hash must be functorize. We can have something like
module Bls12_381.Hash.MakeFixedLengthPoseidon (S : Hades) (sig val length : int end) : sig
val hash : Fr.t array -> Fr.t
end
However, we instantiate a module for only one function. Which does not really make sense. And this functor must be duplicated. We can have instead:
module Hash : sig
module MakePoseidon : sig
val fixed_length_hash : (module S : Hades) -> int -> (Fr.t array -> Fr.t)
val variable_length_hash : (module S : Hades) -> (Fr.t array -> Fr.t)
end
end
We can have get a hash function with:
let hash inputs = Bls12_381.Hash.MakePoseidon.fixed_length_hash (module Hades128 : Bls12_381.Permutation.Hades) 3 inputs
For Poseidon128 and Poseidon252, we can have:
module Hash : sig
module Poseidon128 : sig
val fixed_length_hash : int -> (Fr.t array -> Fr.t)
val variable_length_hash : (Fr.t array -> Fr.t)
end
end
and the user chooses the hash function depending on the usecase:
let hash inputs = Bls12_381.Hash.Poseidon128.fixed_length_hash 3 inputs
Edited by Danny Willems