Skip to content

Commit 5318545

Browse files
authored
TestEcdsa: fix flaky "tampering" of public key (#3282)
## Summary This test (TestEcdsa) tests the ecdsa_pk_decompress opcode and intentionally "tampers" with the public key by setting the first byte to zero. Occasionally this test is failing, likely because the first byte was already zero. (The test failures are for the cases where failure is expected, `pass=false`) ## Test Plan Existing test should pass, occasional flakiness should go away.
1 parent 02f6cac commit 5318545

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

data/transactions/logic/evalCrypto_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ byte 0x%s
212212
&&`
213213
pkTampered1 := make([]byte, len(pk))
214214
copy(pkTampered1, pk)
215-
pkTampered1[0] = 0
216-
pkTampered2 := make([]byte, len(pk))
217-
copy(pkTampered2, pk[1:])
215+
pkTampered1[0] = 0 // first byte is a prefix of either 0x02 or 0x03
216+
pkTampered2 := make([]byte, len(pk)-1) // must be 33 bytes length
217+
copy(pkTampered2, pk)
218218

219219
var decompressTests = []struct {
220220
key []byte
@@ -224,8 +224,9 @@ byte 0x%s
224224
{pkTampered1, false},
225225
{pkTampered2, false},
226226
}
227-
for _, test := range decompressTests {
227+
for i, test := range decompressTests {
228228
t.Run(fmt.Sprintf("decompress/pass=%v", test.pass), func(t *testing.T) {
229+
t.Log("decompressTests i", i)
229230
src := fmt.Sprintf(source, hex.EncodeToString(test.key), hex.EncodeToString(x), hex.EncodeToString(y))
230231
if test.pass {
231232
testAccepts(t, src, 5)
@@ -255,8 +256,8 @@ ecdsa_verify Secp256k1
255256
v := int(sign[64])
256257

257258
rTampered := make([]byte, len(r))
258-
copy(rTampered, pk)
259-
rTampered[0] = 0
259+
copy(rTampered, r)
260+
rTampered[0] += byte(1) // intentional overflow
260261

261262
var verifyTests = []struct {
262263
data string

0 commit comments

Comments
 (0)