Coder Social home page Coder Social logo

Comments (3)

glarregay-tob avatar glarregay-tob commented on September 14, 2024

Hey, thanks for your submission!
This is an interesting point. I'll test this and the PR locally and get back to you.

from properties.

glarregay-tob avatar glarregay-tob commented on September 14, 2024

Hey @beber89, sorry for the delay. I ran some tests on this issue, thanks again for bringing it up.

The way that the add and sub functions are implemented in ABDKMath64x64 make the add_test_range and sub_test_range tests to be unnecesary, as you stated. This is due to the fact that ABDKMath's implementations of add and sub are using type casting from int256 to int128, and in the case where the result doesn't fit, the implementation just drops the higher order bits. In summary, there is no way it can overflow, as the result will always be in int128 range, and it is exactly the same range as the valid results.

Your PR addresses a condition that we weren't directly checking, that is overflow. I mean "directly" in the sense that if those functions were to overflow, the issue would be quite probably detected by the other failing tests that you mentioned in your report (add_test_values, add_test_maximum_value_plus_one, etc), but there is no specific test for it with fuzzable parameters.

Another point is that even if the math tests are now tailored to ABDKMath64x64, they are meant to be reusable for other libraries too. So we shouldn't assume that all libraries will implement overflow checks the same way, tests should be created for them. I think the overflow test you implemented can be useful in the cases where the valid result range is different than the underlying type range (for example, a 32x32 fixed point lib implemented with int128 as underlying). I am not aware if such libraries exist, though.

So, in summary, I think we can add your suggestions to the repo as a new overflow test. Before defining how it should be implemented, I'd like to read your opinion on this @ggrieco-tob.

from properties.

beber89 avatar beber89 commented on September 14, 2024

Hey @glarregay-tob , sorry for all that time it took me to respond.

I wrote that test based on the fact that the require statement applied on int128 is not actually checking anything and I assumed that testing for overflow/underflow can be seen as checking that the value is confined within the int128 range afterall.

But I got your point now, I understand that the pull request which I am suggesting looks like it tests a different thing. It can be a general overflow/underflow test but not a range test. I had another idea also then but it still contradicts the purpose of the test I think as this one.

I think the overflow test you implemented can be useful in the cases where the valid result range is different than the underlying type range (for example, a 32x32 fixed point lib implemented with int128 as underlying). I am not aware if such libraries exist, though.

I took a look but I could not find a library among the ones I know that does this .

from properties.

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.