Skip to content

Commit

Permalink
Revert unnecessary comment modifications
Browse files Browse the repository at this point in the history
  • Loading branch information
mdehoog committed Feb 29, 2024
1 parent 7387bd5 commit 71ec48a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func MatMul[E Element[E]](a, b Matrix[E]) (Matrix[E], error) {
return res, nil
}

// left Matrix multiplication, denote by m*V, where m is the matrix, and V is the vector.
// left Matrix multiplication, denote by M*V, where M is the matrix, and V is the vector.
func LeftMatMul[E Element[E]](m Matrix[E], v Vector[E]) (Vector[E], error) {
if !IsSquareMatrix(m) {
panic("matrix is not square!")
Expand All @@ -185,7 +185,7 @@ func LeftMatMul[E Element[E]](m Matrix[E], v Vector[E]) (Vector[E], error) {
return res, nil
}

// right Matrix multiplication, denote by V*m, where V is the vector, and m is the matrix.
// right Matrix multiplication, denote by V*M, where V is the vector, and M is the matrix.
func RightMatMul[E Element[E]](v Vector[E], m Matrix[E]) (Vector[E], error) {
if !IsSquareMatrix(m) {
return nil, errors.New("matrix is not square")
Expand Down
16 changes: 8 additions & 8 deletions mds.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ type mdsMatrices[E Element[E]] struct {
mPrime Matrix[E]
// mDoublePrime is the matrix m'' in the paper, and it holds m = m'*m''.
// mDoublePrime consists of:
// m_00 | V
// m_00 | v
// w_hat | I
// where M_00 is the first element of the mds matrix,
// w_hat and V are t-1 length vectors,
// w_hat and v are t-1 length vectors,
// I is the (t-1)*(t-1) identity matrix.
mDoublePrime Matrix[E]
}

// SparseMatrix is specifically one of the form of m.
// 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.
// For simplicity, we omit the identity matrix in m''.
type SparseMatrix[E Element[E]] struct {
// WHat is the first column of the m'' matrix, this is a little different with the WHat in the paper because
// we add M_00 to the beginning of the WHat.
Expand Down Expand Up @@ -108,7 +108,7 @@ func deriveMatrices[E Element[E]](m Matrix[E]) (*mdsMatrices[E], error) {
return &mdsMatrices[E]{m, mInv, mHat, mHatInv, mPrime, mDoublePrime}, nil
}

// generate the matrix m', where m = m'*m.
// generate the matrix m', where m = m'*m''.
func genPrime[E Element[E]](m Matrix[E]) Matrix[E] {
prime := make([][]E, row(m))
prime[0] = append(prime[0], one[E]())
Expand All @@ -126,7 +126,7 @@ func genPrime[E Element[E]](m Matrix[E]) Matrix[E] {
return prime
}

// generate the matrix m, where m = m'*m.
// generate the matrix m'', where m = m'*m''.
func genDoublePrime[E Element[E]](m, mHatInv Matrix[E]) (Matrix[E], error) {
w, v := genPreVectors(m)

Expand Down Expand Up @@ -195,8 +195,8 @@ func parseSparseMatrix[E Element[E]](m Matrix[E]) (*SparseMatrix[E], error) {
// we refer to the paper https://eprint.iacr.org/2019/458.pdf page 20 and
// the implementation in https://github.com/filecoin-project/neptune.
// at each partial round, use a sparse matrix instead of a dense matrix.
// to do this, we have to factored into two components, such that m' x m = m,
// use the sparse matrix m as the mds matrix,
// to do this, we have to factored into two components, such that m' x m'' = m,
// use the sparse matrix m'' as the mds matrix,
// then the previous layer's m is replaced by m x m' = m*.
// from the last partial round, do the same work to the first partial round.
func genSparseMatrix[E Element[E]](m Matrix[E], rp int) ([]*SparseMatrix[E], Matrix[E], error) {
Expand Down
18 changes: 9 additions & 9 deletions poseidon.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func sbox[E Element[E]](e E, pre, post *E) {
}
}

// staticPartialRounds computes arc->sbox->m, which has partial sbox layers,
// staticPartialRounds computes arc->sbox->M, which has partial sbox layers,
// see https://eprint.iacr.org/2019/458.pdf page 6.
// The partial round is the same as the full round, with the difference
// that we apply the S-Box only to the first element.
Expand All @@ -231,7 +231,7 @@ func staticPartialRounds[E Element[E]](state []E, offset int, pdsConsts *Poseido
return state
}

// staticFullRounds computes arc->sbox->m, which has full sbox layers,
// staticFullRounds computes arc->sbox->M, which has full sbox layers,
// see https://eprint.iacr.org/2019/458.pdf page 6.
func staticFullRounds[E Element[E]](state []E, lastRound bool, offset int, pdsConsts *PoseidonConst[E]) []E {
// in the last round, there is no need to add round constants because
Expand All @@ -249,7 +249,7 @@ func staticFullRounds[E Element[E]](state []E, lastRound bool, offset int, pdsCo
}

// in the fourth full round, we should compute the product between the elements
// and the pre-sparse matrix (m*m'), see https://eprint.iacr.org/2019/458.pdf page 20.
// and the pre-sparse matrix (M*M'), see https://eprint.iacr.org/2019/458.pdf page 20.
if offset == 4*len(state) {
state = productPreSparseMatrix(state, pdsConsts.PreSparse)
} else {
Expand Down Expand Up @@ -289,7 +289,7 @@ func dynamicFullRounds[E Element[E]](state []E, current, next bool, offset int,
copy(postVec, pdsContants.RoundConsts[offset:offset+t])
}

// m^-1(s)
// M^-1(s)
inv, err := RightMatMul(postVec, pdsContants.Mds.mInv)
if err != nil {
panic(err)
Expand Down Expand Up @@ -386,18 +386,18 @@ func productPreSparseMatrix[E Element[E]](state []E, preSparseMatrix Matrix[E])
// productSparseMatrix computes the product between the elements and the sparse matrix.
func productSparseMatrix[E Element[E]](state []E, offset int, sparse []*SparseMatrix[E]) []E {
// this part is described in https://eprint.iacr.org/2019/458.pdf page 20.
// the sparse matrix m'' consists of:
// the sparse matrix M'' consists of:
//
// M_00 | V
// M_00 | v
// w_hat | I
//
// where M_00 is the first element of the mds matrix,
// w_hat and V are t-1 length vectors,
// w_hat and v are t-1 length vectors,
// I is the (t-1)*(t-1) identity matrix.
// to compute ret = state * m'',
// to compute ret = state * M'',
// we can first compute ret[0] = state * [M_00, w_hat],
// then for 1 <= i < t,
// compute ret[i] = state[0] * V[i-1] + state[i].
// compute ret[i] = state[0] * v[i-1] + state[i].
res := make([]E, len(state))
res[0] = NewElement[E]()
for i := 0; i < len(state); i++ {
Expand Down

0 comments on commit 71ec48a

Please sign in to comment.