github.com/klaytn/klaytn@v1.12.1/crypto/secp256k1/curve_test.go (about) 1 // Copyright 2018 The klaytn Authors 2 // 3 // This file is part of the klaytn library. 4 // 5 // The klaytn library is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Lesser General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // The klaytn library is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Lesser General Public License for more details. 14 // 15 // You should have received a copy of the GNU Lesser General Public License 16 // along with the klaytn library. If not, see <http://www.gnu.org/licenses/>. 17 18 package secp256k1 19 20 import ( 21 "encoding/hex" 22 "fmt" 23 "testing" 24 ) 25 26 func TestAddSamePoint(t *testing.T) { 27 /* 28 This test is intended to highlight the bug in klaytn/crypto/secp256k1/curve.go#affineFromJacobian. 29 When passed with same points, BitCurve.Add invokes affineFromJacobian(0, 0, 0) which then invokes 30 (big.Int).Mul(nil, nil). 31 32 Although executing (big.Int).Mul(nil, nil) is not problematic in Go 1.10.3, it has been found invoking the same 33 is fatal in Go 1.11 (causing SIGSEGV; terminating the program). 34 35 */ 36 x0, _ := hex.DecodeString("4f52e337ad8bf1ce10cbb72ab91d9954474cea39811040df5558297df3e3c1bf") // Alice 37 x1, _ := hex.DecodeString("4f52e337ad8bf1ce10cbb72ab91d9954474cea39811040df5558297df3e3c1bf") // Alice 38 39 G := S256() 40 P0x, P0y := G.ScalarBaseMult(x0) 41 P1x, P1y := G.ScalarBaseMult(x1) 42 43 Qx, Qy := G.Add(P0x, P0y, P1x, P1y) 44 45 fmt.Println(Qx, Qy) // should print 0 0 with no fatal error 46 }