Documentation ¶
Index ¶
- Constants
- Variables
- func Hash(input []*big.Int, pdsContants *PoseidonConst, hash HashMode) (*big.Int, error)
- func IsEqual(a, b Matrix) bool
- func IsIdentity(m Matrix) bool
- func IsInvertible(m Matrix) bool
- func IsSquareMatrix(m Matrix) bool
- func IsVecEqual(a, b Vector) bool
- func VecMul(a, b Vector) (*ff.Element, error)
- type HashMode
- type Matrix
- type PoseidonConst
- type SparseMatrix
- type Vector
Constants ¶
const Alpha int = 5
for bls12_381 modular p, since p ≠ 1 mod 5, we set Alpha = 5. see https://eprint.iacr.org/2019/458.pdf page 6.
const SecurityLevel int = 128
security level (in bits)
Variables ¶
var PoseidonExp = new(big.Int).SetUint64(5)
exponent used in the sbox.
Functions ¶
func Hash ¶
Hash implements poseidon hash in this paper: https://eprint.iacr.org/2019/458.pdf. we refer the rust implement (OptimizedStatic mode), see https://github.com/filecoin-project/neptune. the input length is a slice of big integers. the output of poseidon hash is a big integer.
func IsInvertible ¶
if delta(m)≠0, m is invertible. so we can transform m to the upper triangular matrix, and if all upper diagonal elements are not zero, then m is invertible.
func IsVecEqual ¶
Types ¶
type PoseidonConst ¶
type PoseidonConst struct { Mds *mdsMatrices RoundConsts []*ff.Element ComRoundConts []*ff.Element PreSparse Matrix Sparse []*SparseMatrix FullRounds int HalfFullRounds int PartialRounds int }
func GenPoseidonConstants ¶
func GenPoseidonConstants(width int) (*PoseidonConst, error)
generate poseidon constants used in the poseidon hash.
type SparseMatrix ¶
type SparseMatrix struct {
// contains filtered or unexported fields
}
SparseMatrix is specifically one of the form of m”. This means its first row and column are each dense, and the interior matrix (minor to the element in both the row and column) is the identity. For simplicity, we omit the identity matrix in m”.
type Vector ¶
func LeftMatMul ¶
left Matrix multiplication, denote by M*V, where M is the matrix, and V is the vector.
func RightMatMul ¶
right Matrix multiplication, denote by V*M, where V is the vector, and M is the matrix.
func ScalarVecMul ¶
for 0 <= i < length, compute v_i*scalar.