@@ -42,6 +42,47 @@ func (circuit *eddsaCircuit) Define(api frontend.API) error {
42
42
return Verify (curve , circuit .Signature , circuit .Message , circuit .PublicKey , & mimc )
43
43
}
44
44
45
+ // Forge signature: S → S + order
46
+ func forge (id tedwards.ID , sig []byte ) ([]byte , error ) {
47
+
48
+ forged := make ([]byte , len (sig ))
49
+ copy (forged , sig )
50
+
51
+ var offset int
52
+ switch id {
53
+ case tedwards .BN254 :
54
+ offset = 32
55
+ case tedwards .BLS12_381 :
56
+ offset = 32
57
+ case tedwards .BLS12_377 :
58
+ offset = 32
59
+ case tedwards .BW6_761 :
60
+ offset = 48
61
+ case tedwards .BLS24_317 :
62
+ offset = 32
63
+ case tedwards .BLS24_315 :
64
+ offset = 32
65
+ case tedwards .BW6_633 :
66
+ offset = 40
67
+ default :
68
+ panic ("not implemented" )
69
+ }
70
+
71
+ s := new (big.Int ).SetBytes (sig [offset :])
72
+ params , err := twistededwards .GetCurveParams (id )
73
+ if err != nil {
74
+ return nil , err
75
+ }
76
+ s .Add (s , params .Order )
77
+
78
+ sizeS := len (sig ) - offset
79
+ buf := make ([]byte , sizeS )
80
+ copy (buf [sizeS - len (s .Bytes ()):], s .Bytes ())
81
+
82
+ copy (forged [offset :], buf )
83
+ return forged , nil
84
+ }
85
+
45
86
func TestEddsa (t * testing.T ) {
46
87
47
88
assert := test .NewAssert (t )
@@ -110,9 +151,17 @@ func TestEddsa(t *testing.T) {
110
151
invalidWitness .PublicKey .Assign (conf .curve , pubKey .Bytes ())
111
152
invalidWitness .Signature .Assign (conf .curve , signature )
112
153
154
+ var invalidWitnessOverflow eddsaCircuit
155
+ invalidWitnessOverflow .Message = msg
156
+ invalidWitnessOverflow .PublicKey .Assign (conf .curve , pubKey .Bytes ())
157
+ forgedSig , err := forge (conf .curve , signature )
158
+ assert .NoError (err , "forging signature" )
159
+ invalidWitnessOverflow .Signature .Assign (conf .curve , forgedSig )
160
+
113
161
assert .CheckCircuit (& circuit ,
114
162
test .WithValidAssignment (& validWitness ),
115
163
test .WithInvalidAssignment (& invalidWitness ),
164
+ test .WithInvalidAssignment (& invalidWitnessOverflow ),
116
165
test .WithCurves (snarkCurve ))
117
166
118
167
}
0 commit comments