Giter Club home page Giter Club logo

Comments (1)

mratsim avatar mratsim commented on June 1, 2024

Similar to #30 and #43 another square root bug:

import
  # Standard library
  std/[unittest, times],
  # Internals
  ../constantine/config/[common, curves],
  ../constantine/arithmetic,
  ../constantine/io/[io_bigints, io_fields],
  ../constantine/elliptic/[ec_weierstrass_affine, ec_weierstrass_projective]

proc trySetFromCoordX_debug*[F](P: var ECP_SWei_Proj[F], x: F): SecretBool =
  ## Try to create a point the elliptic curve
  ## y² = x³ + a x + b     (affine coordinate)
  ##
  ## The `Z` coordinates is set to 1
  ##
  ## return true and update `P` if `x` leads to a valid point
  ## return false otherwise, in that case `P` is undefined.
  ##
  ## Note: Dedicated robust procedures for hashing-to-curve
  ##       will be provided, this is intended for testing purposes.
  P.y.curve_eq_rhs(x)
  # TODO: supports non p ≡ 3 (mod 4) modulus like BLS12-377

  echo "P.y: ", P.y.toHex()
  echo "P.y.isSquare: ", bool P.y.isSquare
  result = sqrt_if_square_p3mod4(P.y)
  echo "P.y.wasSquare: ", bool result
  P.x = x
  P.z.setOne()

var a: ECP_SWei_Proj[Fp[BLS12_381]]

var x: Fp[BLS12_381]
x.fromHex("0x1494859e30da25337d020ccf8629c81df7ddab3185acee7a5712c47e2192bc71d6bf74db134d3c7f7f21e43b59242ff3")

let ok = a.trySetFromCoordX_debug(x)

echo "ok: ", bool ok
echo "a.x: ", a.x.toHex()
echo "a.y: ", a.y.toHex()

doAssert bool isOnCurve(a.x, a.y)

var r0{.noInit.}, r1{.noInit.}: ECP_SWei_Proj[Fp[BLS12_381]]

r0.double(a)
r1.sum(a, a)

doAssert bool(r0 == r1)
P.y: 0x0f16d7854229d8804bcadd889f70411d6a482bde840d238033bf868e89558d39d52f9df60b2d745e02584375f16c34a3
P.y.isSquare: false
P.y.wasSquare: true
ok: true
a.x: 0x1494859e30da25337d020ccf8629c81df7ddab3185acee7a5712c47e2192bc71d6bf74db134d3c7f7f21e43b59242ff3
a.y: 0x0aad1bf39cd801cc5b917b70205bac4706e330eb8b5bac50967780f9db6025149b60fe93402bdea86f4b403807d3f4ea
...../Programming/Nim/constantine/build/debug_double_add.nim(43) debug_double_add
...../.choosenim/toolchains/nim-#devel/lib/system/assertions.nim(29) failedAssertImpl
...../.choosenim/toolchains/nim-#devel/lib/system/assertions.nim(22) raiseAssert
...../.choosenim/toolchains/nim-#devel/lib/system/fatal.nim(49) sysFatal
Error: unhandled exception: /home/beta/Programming/Nim/constantine/build/debug_double_add.nim(43, 10) `bool isOnCurve(a.x, a.y)`  [AssertionDefect]

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.