Skip to content

Commit a975a7b

Browse files
authored
Revert last reviews (#7)
1 parent 715885b commit a975a7b

File tree

5 files changed

+29
-79
lines changed

5 files changed

+29
-79
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
*.out
1616

1717
# Dependency directories (remove the comment below to include it)
18-
# vendor/
18+
vendor/
1919

2020
# Go workspace file
2121
go.work
2222
go.work.sum
2323

2424
# env file
2525
.env
26-
vendor

curve/ecgfp5/scalar_field.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/binary"
66
"math/big"
77
"math/rand"
8-
"sync"
98
"time"
109

1110
gFp5 "github.com/elliottech/poseidon_crypto/field/goldilocks_quintic_extension"
@@ -32,12 +31,11 @@ func ScalarElementFromLittleEndianBytes(data []byte) ECgFp5Scalar {
3231
panic("invalid length")
3332
}
3433

35-
var uintArr [5]uint64
34+
var value ECgFp5Scalar
3635
for i := 0; i < 5; i++ {
37-
uintArr[i] = binary.LittleEndian.Uint64(data[i*8:])
36+
value[i] = binary.LittleEndian.Uint64(data[i*8:])
3837
}
39-
40-
return FromNonCanonicalBigInt(BigIntFromArray(uintArr))
38+
return value
4139
}
4240

4341
func (s ECgFp5Scalar) SplitTo4BitLimbs() [80]uint8 {
@@ -270,25 +268,20 @@ func FromGfp5(fp5 gFp5.Element) ECgFp5Scalar {
270268
}))
271269
}
272270

273-
// TODO: use sync.Pool for other places where redundant big.Int initializations are made.
274-
var bigIntPool = sync.Pool{
275-
New: func() interface{} {
276-
return new(big.Int)
277-
},
278-
}
279-
280271
func BigIntFromArray(arr [5]uint64) *big.Int {
281272
result := new(big.Int)
282273
for i := 4; i >= 0; i-- {
283274
result.Lsh(result, 64)
284-
result.Or(result, bigIntPool.Get().(*big.Int).SetUint64(arr[i]))
275+
result.Or(result, new(big.Int).SetUint64(arr[i]))
285276
}
286277
return result
287278
}
288279

289280
func FromNonCanonicalBigInt(val *big.Int) ECgFp5Scalar {
290-
limbs := val.Mod(val, ORDER).Bits()
291-
limbs = append(limbs, make([]big.Word, 5-len(limbs))...)
281+
limbs := new(big.Int).Mod(val, ORDER).Bits()
282+
if len(limbs) < 5 {
283+
limbs = append(limbs, 0)
284+
}
292285
return ECgFp5Scalar{uint64(limbs[0]), uint64(limbs[1]), uint64(limbs[2]), uint64(limbs[3]), uint64(limbs[4])}
293286
}
294287

field/goldilocks/goldilocks.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ func Modulus() uint64 {
121121
}
122122

123123
func Zero() Element {
124-
return Element{0}
124+
return g.NewElement(0)
125125
}
126126

127127
func One() Element {
128-
return Element{4294967295}
128+
return g.NewElement(1)
129129
}
130130

131131
func Neg(e Element) Element {

hash/poseidon2_goldilocks/poseidon2_test.go

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
11
package poseidon2
22

33
import (
4+
"fmt"
45
"testing"
56

67
g "github.com/elliottech/poseidon_crypto/field/goldilocks"
78
)
89

9-
// func TestGetNilTreeLevels(t *testing.T) {
10-
// res := []HashOut{EmptyHashOut()}
11-
// for i := 1; i < 128; i++ {
12-
// res = append(res, HashTwoToOne(res[i-1], res[i-1]))
13-
// }
14-
15-
// fmt.Println()
16-
// for i := 0; i < len(res); i++ {
17-
// fmt.Printf("Level %d: ", i)
18-
// leBytes := res[i].ToLittleEndianBytes()
19-
// for j := 0; j < len(leBytes); j++ {
20-
// fmt.Printf("%d ", leBytes[j])
21-
// }
22-
// fmt.Println()
23-
// }
24-
// fmt.Println()
25-
// }
10+
func TestGetNilTreeLevels(t *testing.T) {
11+
res := []HashOut{EmptyHashOut()}
12+
for i := 1; i < 128; i++ {
13+
res = append(res, HashTwoToOne(res[i-1], res[i-1]))
14+
}
15+
16+
fmt.Println()
17+
for i := 0; i < len(res); i++ {
18+
fmt.Printf("Level %d: ", i)
19+
leBytes := res[i].ToLittleEndianBytes()
20+
for j := 0; j < len(leBytes); j++ {
21+
fmt.Printf("%d ", leBytes[j])
22+
}
23+
fmt.Println()
24+
}
25+
fmt.Println()
26+
}
2627

2728
func TestPermute(t *testing.T) {
2829
inp := [WIDTH]g.Element{

signature/schnorr/schnorr_test.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -46,49 +46,6 @@ func TestSchnorrSignAndVerify(t *testing.T) {
4646
}
4747
}
4848

49-
func TestSchnorrSignAndVerify2(t *testing.T) {
50-
sk := curve.ECgFp5Scalar{
51-
123436789012345,
52-
423456789012345,
53-
623456789012345,
54-
323456789012345,
55-
987654321098765,
56-
}
57-
msg := []g.Element{
58-
g.FromUint64(1234567890),
59-
g.FromUint64(1234567890),
60-
g.FromUint64(1234567890),
61-
g.FromUint64(1234567890),
62-
g.FromUint64(1234567890),
63-
g.FromUint64(1234567890),
64-
g.FromUint64(1234567890),
65-
g.FromUint64(1234567890),
66-
g.FromUint64(9876543210),
67-
}
68-
hashedMsg := p2.HashToQuinticExtension(msg)
69-
70-
sig := Signature{
71-
S: curve.ECgFp5Scalar{
72-
967731567622134384,
73-
14773957602371314426,
74-
5625157264196176680,
75-
4777447573816832589,
76-
2786434001343470261,
77-
},
78-
E: curve.ECgFp5Scalar{
79-
4587639336484623223,
80-
3617268809678375214,
81-
7648030453022535951,
82-
12524273874744280663,
83-
5087864368241658443,
84-
},
85-
}
86-
pk := SchnorrPkFromSk(sk)
87-
if !IsSchnorrSignatureValid(&pk, &hashedMsg, sig) {
88-
t.Fatalf("Signature is invalid")
89-
}
90-
}
91-
9249
func TestComparativeSchnorrSignAndVerify(t *testing.T) {
9350
sks := []curve.ECgFp5Scalar{
9451
curve.ECgFp5Scalar{

0 commit comments

Comments
 (0)