rchain / rchain

Blockchain (smart contract) platform using CBC-Casper proof of stake + Rholang for concurrent execution.
Other
693 stars 217 forks source link

The valid values of type Integer in Rholang #3583

Closed CowSmiles closed 2 years ago

CowSmiles commented 2 years ago

What did you expect to see?

In Rholang, the integer is int64. So I thought the valid values of int is: [-2^63, 2^63-1],which is [-9223372036854775808, 9223372036854775807].

What did you see instead?

But in rholang code, when I ouput -9223372036854775808, it will report:

 message: 'Error: coop.rchain.rholang.interpreter.errors$NormalizerError: For
    input string: "9223372036854775808"'

but -9223372036854775807 - 1 produce -9223372036854775808. So it is strange, maybe the problem occur at the parse of the input?

Steps to reproduce the bug

The following two snippets prove the question:

new stdout(`rho:io:stdout`) in {
    stdout!(("-9223372036854775808", -9223372036854775808))
    |
    stdout!(("9223372036854775807", 9223372036854775807))
    |
    stdout!(("-9223372036854775808 - 1", -9223372036854775808 - 1))
    |
    stdout!(("9223372036854775807 + 1", 9223372036854775807 + 1))
}
new stdout(`rho:io:stdout`) in {
    stdout!(("-9223372036854775807", -9223372036854775807))
    |
    stdout!(("9223372036854775807", 9223372036854775807))
    |
    stdout!(("-9223372036854775807 - 1", -9223372036854775807 - 1))
    |
    stdout!(("9223372036854775807 + 1", 9223372036854775807 + 1))
}

What version of RNode are you using?

v0.12.4

What is your environment?

VSCode Rholang plugin

zsluedem commented 2 years ago

"-9223372036854775807 - 1" is String not Int.

The numeric range of int in Rholang is [-9223372036854775808, 9223372036854775807] [-9223372036854775807, 9223372036854775807]

zsluedem commented 2 years ago

Well.I think you are right there is something wrong with parsing(saying normalizing in rholang is more correct).

The minimum of integer in rholang is -9223372036854775807.

For number like -9223372036854775808 , rholang parser would parse this number by splitting it into - and 9223372036854775808. And the parser consider 9223372036854775808 is Long(Long in scala same like int64) while the maximum of integer is 9223372036854775807 which 9223372036854775808 can not convert to it. That's why the error occurs.

CowSmiles commented 2 years ago

Thanks, I just thought is was a little confused. It's not a big deal.