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.

30 lines
819 B

  1. package bn128
  2. import (
  3. "math/big"
  4. "testing"
  5. "github.com/arnaucube/cryptofun/utils"
  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)
  16. r1r2 := bn128.Fq1.Add(r1, r2)
  17. grsum2 := bn128.G1.MulScalar(bn128.G1.G, r1r2)
  18. a := bn128.G1.Affine(grsum1)
  19. b := bn128.G1.Affine(grsum2)
  20. assert.Equal(t, a, b)
  21. assert.Equal(t, "0x2f978c0ab89ebaa576866706b14787f360c4d6c3869efe5a72f7c3651a72ff00", utils.BytesToHex(a[0].Bytes()))
  22. assert.Equal(t, "0x12e4ba7f0edca8b4fa668fe153aebd908d322dc26ad964d4cd314795844b62b2", utils.BytesToHex(a[1].Bytes()))
  23. }