Coder Social home page Coder Social logo

Comments (2)

mratsim avatar mratsim commented on August 27, 2024

The bug was that somehow the RNG was able to create a random point that was not on the curve.

Point config

import
  # Internals
  ../constantine/config/[common, curves],
  ../constantine/arithmetic,
  ../constantine/io/[io_bigints, io_ec],
  ../constantine/elliptic/[ec_weierstrass_affine, ec_weierstrass_projective]

proc test() =

  var a: ECP_SWei_Proj[Fp[BLS12_381]]
  var b: ECP_SWei_Proj[Fp[BLS12_381]]
  var c: ECP_SWei_Proj[Fp[BLS12_381]]

  doAssert a.fromHex( # This is not on the curve
    x = "0x0426d6f73952e652c229561b9718b76593b60cd9e44aa1f83b4531bb9e6b20a8a959735ac483dbd92dfe48b2ce937987",
    y = "0x025366df8ed339c3e3f8f0a826a24c04343f78c0ec865d56ff1d4718206749a5e07dcb9785520d0f85d4ef209493b41b"
  )
  doAssert b.fromHex(
    x = "0x0d544f56919ea56b16eef9066713331ea54f43ee0d8853d5952847a15694a17d5f21eb9f067e39b3701bebc649ba518a",
    y = "0x0b877f4a58dc1ce70ce9c9d56a536b5cfdff5460b0df60849c9155de252ea25f103f98ac3f9789ffb3d813fe31c3097c",
  )
  doAssert c.fromHex(
    x = "0x065a5dd4ca6a8aba7dc41c8747a99632d6de2f0f3e53899dba906013b3cf2e29a64d7706137b9cf540780235e27035fb",
    y = "0x034c4bd6e37c275f2f7237af190c87e445f624c44b60d0d583c906b2756875e739fd3cc545719b4731577724730571e5"
  )

  var tmp1{.noInit.}, tmp2{.noInit.}: ECP_SWei_Proj[Fp[BLS12_381]]

  # r0 = (a + b) + c
  tmp1.sum(a, b)
  tmp2.sum(tmp1, c)
  let r0 = tmp2

  # r1 = a + (b + c)
  tmp1.sum(b, c)
  tmp2.sum(a, tmp1)
  let r1 = tmp2

  # r2 = (a + c) + b
  tmp1.sum(a, c)
  tmp2.sum(tmp1, b)
  let r2 = tmp2

  # r3 = a + (c + b)
  tmp1.sum(c, b)
  tmp2.sum(a, tmp1)
  let r3 = tmp2

  # r4 = (c + a) + b
  tmp1.sum(c, a)
  tmp2.sum(tmp1, b)
  let r4 = tmp2

  # ...

  doAssert bool(r0 == r1)
  doAssert bool(r0 == r2)
  doAssert bool(r0 == r3)
  doAssert bool(r0 == r4)

test()

from constantine.

mratsim avatar mratsim commented on August 27, 2024

The isSquare and sqrt_if_square are returning different results:

import
  # Internals
  ../constantine/config/[common, curves],
  ../constantine/arithmetic,
  ../constantine/io/[io_bigints, io_fields, io_ec],
  ../constantine/elliptic/[ec_weierstrass_affine, ec_weierstrass_projective]

var f: Fp[BLS12_381]

f.fromHex("0x184d02ce4f24d5e59b4150a57a31b202fd40a4b41d7518c22b84bee475fbcb7763100448ef6b17a6ea603cf062e5db51")

echo bool(f.isSquare()) # false
let wasSquare = f.sqrt_if_square_p3mod4()
echo bool(wasSquare) # true <--- only in 32-bit, carry bug?
echo "f sqrt: ", f.toHex()

from constantine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.