I mentioned last time that I was working on a big integer library.

After some work, I have managed get 512-bit arithmetic kinda working!!!!

Credits to /u/benjaminion for the modSmall function.

Here are the 16-bit and 512-bit versions. I develop in uint8 then port it to uint256 by replacing all the uint8.

Some issues I am currently facing and would like some help for:

  • The modulo function is really slow for small modulus & large dividend
  • The modular multiplication function is slow
  • No division yet, should follow closely to modulo
  • Gas costs are really high!

I am looking into other algorithms for modulo and modular arithmetic. I am not too knowledgeable in this area so help would be much appreciated!

Also, I was wondering how to get gas costs from Testrpc. The emulated VM in Remix(online compiler) tells me the gas costs, but it's too slow.

I may also have also messed up something when I was prettying up the code for Reddit or missed a few edge cases. Any feedback is welcome!

P.S. I posted this in Reddit too

  • 1
    I see you didn't implement division yet. Are you looking to implement it without using division? – nergall Jan 21 '17 at 10:32
  • My use case right now doesn't need division. I plan on adding it later with similar method to the modulo function – Metaception Jan 21 '17 at 17:17
  • 1
    I asked because it's easy to implement mod() if you have div() – nergall Jan 21 '17 at 18:29
  • Yeah, I have a general idea of how to adapt the mod function to div. It's just that I am still optimizing the mod function and I am a little short on time. – Metaception Jan 22 '17 at 21:11
  • Oh, I misread your post. I thought you said that it was easy to implement div() once you have mod(), but you said the opposite. – Metaception Jan 23 '17 at 2:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.