You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
915 B

  1. package bn128
  2. import (
  3. "encoding/hex"
  4. "math/big"
  5. "testing"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestG1(t *testing.T) {
  9. bn128, err := NewBn128()
  10. assert.Nil(t, err)
  11. r1 := big.NewInt(int64(33))
  12. r2 := big.NewInt(int64(44))
  13. gr1 := bn128.G1.MulScalar(bn128.G1.G, bn128.Fq1.Copy(r1))
  14. gr2 := bn128.G1.MulScalar(bn128.G1.G, bn128.Fq1.Copy(r2))
  15. grsum1 := bn128.G1.Add(gr1, gr2) // g*33 + g*44
  16. r1r2 := bn128.Fq1.Add(r1, r2) // 33 + 44
  17. grsum2 := bn128.G1.MulScalar(bn128.G1.G, r1r2) // g * (33+44)
  18. assert.True(t, bn128.G1.Equal(grsum1, grsum2))
  19. a := bn128.G1.Affine(grsum1)
  20. b := bn128.G1.Affine(grsum2)
  21. assert.Equal(t, a, b)
  22. assert.Equal(t, "2f978c0ab89ebaa576866706b14787f360c4d6c3869efe5a72f7c3651a72ff00", hex.EncodeToString(a[0].Bytes()))
  23. assert.Equal(t, "12e4ba7f0edca8b4fa668fe153aebd908d322dc26ad964d4cd314795844b62b2", hex.EncodeToString(a[1].Bytes()))
  24. }