core/vm, crypto/bn256: fix bn256 use and pairing corner case

This commit is contained in:
Péter Szilágyi
2017-08-17 16:46:46 +03:00
parent 0b978f91b6
commit 1335a6cc8c
4 changed files with 81 additions and 16 deletions

View File

@ -307,8 +307,9 @@ func (c *bn256Add) Run(input []byte) ([]byte, error) {
if err != nil {
return nil, err
}
x.Add(x, y)
return x.Marshal(), nil
res := new(bn256.G1)
res.Add(x, y)
return res.Marshal(), nil
}
// bn256ScalarMul implements a native elliptic curve scalar multiplication.
@ -324,8 +325,9 @@ func (c *bn256ScalarMul) Run(input []byte) ([]byte, error) {
if err != nil {
return nil, err
}
p.ScalarMult(p, new(big.Int).SetBytes(getData(input, 64, 32)))
return p.Marshal(), nil
res := new(bn256.G1)
res.ScalarMult(p, new(big.Int).SetBytes(getData(input, 64, 32)))
return res.Marshal(), nil
}
var (
@ -370,8 +372,7 @@ func (c *bn256Pairing) Run(input []byte) ([]byte, error) {
ts = append(ts, t)
}
// Execute the pairing checks and return the results
ok := bn256.PairingCheck(cs, ts)
if ok {
if bn256.PairingCheck(cs, ts) {
return true32Byte, nil
}
return false32Byte, nil