Coder Social home page Coder Social logo

FP256BN Plus and math.MaxInt64 about amcl HOT 7 OPEN

miracl avatar miracl commented on August 16, 2024
FP256BN Plus and math.MaxInt64

from amcl.

Comments (7)

ale-linux avatar ale-linux commented on August 16, 2024

This is actually related to miracl/core#44 and in fact, the git revision refers to that repo. The issue can be reproduced against both libraries

from amcl.

mcarrickscott avatar mcarrickscott commented on August 16, 2024

from amcl.

ale-linux avatar ale-linux commented on August 16, 2024

Thanks @mcarrickscott. We were testing various ECC math/crypto libraries (e.g. miracl/core, https://github.com/ConsenSys/gnark-crypto etc) trying to develop tests asserting basic behaviour across all of them, which is how we stumbled upon this issue.
What are the restrictions on the BIG and its constructors? We were expecting that something like

func TestMaxInt(t *testing.T) {
	i := FP256BN.NewBIGint(1)
	for j := 0; j < 64; j++ {
		i = i.Plus(i)
	}
	zero := FP256BN.NewBIGint(0)
	assert.NotEqual(t, zero, i)
}

would work.
Let us know how we're misusing the library - thanks!

from amcl.

mcarrickscott avatar mcarrickscott commented on August 16, 2024

from amcl.

ale-linux avatar ale-linux commented on August 16, 2024

Thanks a lot! So, without the explicit call to normalization the correctness of the result of Plus invocations is not guaranteed?

from amcl.

mcarrickscott avatar mcarrickscott commented on August 16, 2024

from amcl.

ale-linux avatar ale-linux commented on August 16, 2024

It is probably best if we implement the norm() inside of Plus() since
Plus() is public and likely to be used as you have used it. So thanks for
bringing this to my attention.

Thank you

But note that this is not a bignum library, and is not expected to be used
as one.

Fair enough; but.. computations over the exponents (e.g. g^{\sum{a_i} mod Q}) are commonplace, and one might chain multiple +'s before calling Mod(q) (which iiuc calls norm()). So for example

func TestMaxInt(t *testing.T) {
	i := FP256BN.NewBIGint(1)
	q := FP256BN.NewBIGints(FP256BN.CURVE_Order)

	for j := 0; j < 64; j++ {
		i = i.Plus(i)
	}

	i.Mod(q)
	zero := FP256BN.NewBIGint(0)
	assert.NotEqual(t, zero, i)
}

one might assume this would work (I did notice that calling mod after every Plus seems to produce the right result).

from amcl.

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.