as-bignum icon indicating copy to clipboard operation
as-bignum copied to clipboard

Implement 128-bit types necessary for NEAR blockchain runtime

Open vgrichina opened this issue 4 years ago ā€¢ 9 comments

Currently different types in the library are in various stages of implementation completeness.

NEAR uses 128-bit numbers internally, therefore we need following types fully implemented:

  • [ ] u128
  • [ ] i128
  • [ ] safe.u128
  • [ ] safe.i128

Acceptance criteria:

  • [ ] All types listed above implement all operations currently supported by u128
  • [ ] safe. types also implement overflow check for all operations which can result in overflow
  • [ ] Code has 100% branch coverage in tests

vgrichina avatar Jun 09 '20 20:06 vgrichina

@MaxGraey we plan to post bounty for this on http://gitcoin.co/

vgrichina avatar Jun 09 '20 20:06 vgrichina

I'm just wondering what operations not implemented for u128? safe.u128 also should be fully implement. Only required full test coverage.

MaxGraey avatar Jun 09 '20 20:06 MaxGraey

I'm just wondering what operations not implemented for u128

yeah, I think this one is fully implemented (or very close), that's why I'm suggesting to use it as reference for other types

safe.u128 also should be fully implement.

There seems to be some stuff which looks like missing: https://github.com/MaxGraey/as-bignum/blob/c2c70bce55af6085d9455ca08378f07f8b04a992/assembly/integer/safe/u128.ts#L151

Only required full test coverage.

Yeah, that's the main part.

vgrichina avatar Jun 09 '20 20:06 vgrichina

There seems to be some stuff which looks like missing:

Ah, that's could be implemented really fast. Will check this tomorrow. Iā€™m just not sure if anyone even uses safe.u128

MaxGraey avatar Jun 09 '20 20:06 MaxGraey

u128 and safe.u128 should be fully implemented. But not 100% tests coverage yet

MaxGraey avatar Jun 11 '20 18:06 MaxGraey

Hi! @vgrichina, @MaxGraey Regarding functionality required by NEAR, I'm creating the AssemblyScript version of one of the core contracts: staking-pool. In order to complete the task, I need to be able to multiply two u128 getting the result as u256, something like: mul(u128,u128)->u256. Also I need to divide two u256, something like div(u256,u256)->u256. operator * and / seem to be missing from type u256

Also I'm good if you @MaxGraey can complete #46, I can use that too. The formula I need to apply is exactly that: u128 * u128 / u128 -> u128

luciotato avatar Oct 11 '20 03:10 luciotato

@luciotato I started implementation for u128.muldiv here #49

MaxGraey avatar Oct 23 '20 15:10 MaxGraey

@MaxGraey can we make a bounty to get this done faster (together with division problem)?

Does 3000K NEAR sound good? How long would it take? Maybe you have different estimate as you have better context.

Blockchain is live already, token traded here https://coinmarketcap.com/currencies/near-protocol/.

vgrichina avatar Dec 03 '20 07:12 vgrichina

This already should be fixed. Check 0.2.7 version

MaxGraey avatar Dec 03 '20 21:12 MaxGraey