Skip to content

Commit

Permalink
Merge pull request #89 from ConsenSys/fix/eddsa
Browse files Browse the repository at this point in the history
docs: added comments for the splitting of S in eddsa
  • Loading branch information
gbotrel authored Apr 16, 2021
2 parents 3fb0507 + 92451b3 commit 7b065e2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
6 changes: 5 additions & 1 deletion std/signature/eddsa/eddsa.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ type PublicKey struct {
}

// Signature stores a signature (to be used in gnark circuit)
// An EdDSA signature is a tuple (R,S) where R is a point on the twisted Edwards curve
// and S a scalar. S can be greater than r, the size of the zk snark field, and must
// not be reduced modulo r. Therefore it is split in S1 and S2, such that if r is n-bits long,
// S = 2^(n/2)*S1 + S2. In other words, S is written S1S2 in basis 2^(n/2).
type Signature struct {
R twistededwards.Point
S1, S2 frontend.Variable // S = S1*basis + S2, where basis if 1/2 log r (ex 128 in case of bn256)
S1, S2 frontend.Variable
}

// Verify verifies an eddsa signature
Expand Down
26 changes: 13 additions & 13 deletions std/signature/eddsa/eddsa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,27 @@ func parseSignature(id ecc.ID, buf []byte) ([]byte, []byte, []byte, []byte) {
case ecc.BN254:
pointbn254.SetBytes(buf[:32])
a, b := parsePoint(id, buf)
c1 := buf[32:48]
c2 := buf[48:]
return a[:], b[:], c1, c2
s1 := buf[32:48] // r is 256 bits, so s = 2^128*s1 + s2
s2 := buf[48:]
return a[:], b[:], s1, s2
case ecc.BLS12_381:
pointbls12381.SetBytes(buf[:32])
a, b := parsePoint(id, buf)
c1 := buf[32:48]
c2 := buf[48:]
return a[:], b[:], c1, c2
s1 := buf[32:48]
s2 := buf[48:]
return a[:], b[:], s1, s2
case ecc.BLS12_377:
pointbls12377.SetBytes(buf[:32])
a, b := parsePoint(id, buf)
c1 := buf[32:48]
c2 := buf[48:]
return a[:], b[:], c1, c2
s1 := buf[32:48]
s2 := buf[48:]
return a[:], b[:], s1, s2
case ecc.BW6_761:
pointbw6761.SetBytes(buf[:48])
pointbw6761.SetBytes(buf[:48]) // r is 384 bits, so s = 2^192*s1 + s2
a, b := parsePoint(id, buf)
c1 := buf[48:72]
c2 := buf[72:]
return a[:], b[:], c1, c2
s1 := buf[48:72]
s2 := buf[72:]
return a[:], b[:], s1, s2
default:
return buf, buf, buf, buf
}
Expand Down

0 comments on commit 7b065e2

Please sign in to comment.