aionnetwork / AVM

Enabling Java code to run in a blockchain environment
https://theoan.com/
MIT License
49 stars 25 forks source link

BigInteger check should throw not assert #407

Open fulldecent opened 4 years ago

fulldecent commented 4 years ago

https://github.com/aionnetwork/AVM/blob/master/org.aion.avm.userlib/src/org/aion/avm/userlib/AionBuffer.java#L388

Because BigIntegers are possible to get to this point which are large.

It also says

// BigInteger instances can't be larger than 32-bytes, in AVM.

If this is true I'm wrong, please reference proof for that statement

jeff-aion commented 4 years ago

This is a restriction imposed by AVM, specifically: https://github.com/aionnetwork/AVM/blob/764e6195d6131d539eb46333d830d3a1f81edd2f/org.aion.avm.rt/src/s/java/math/BigInteger.java#L392

In standard Java, these are unbounded, but the limit is imposed by the AVM to constrain the effort expended for constant cost.

fulldecent commented 4 years ago

Ah, so the Aion BigInteger implementation shadows java.math.BigInteger.

What is the primary documentation I should cite for that?

Can I get a BigInteger.MAX_VALUE and BigInteger.MIN_VALUE?

Is BigInteger.MAX_VALUE.add(BigInteger.ONE) undefined? Is that documented?

Right now AIP-040 was expecting BigInteger.MAX_VALUE == 2^256 but that is not the case.

This is where I checked for documentation

Screen Shot 2019-08-16 at 21 13 38