AntelopeIO / leap

C++ implementation of the Antelope protocol
Other
116 stars 68 forks source link

action return incorrect int64_t value #579

Closed quocle108 closed 1 year ago

quocle108 commented 1 year ago

I expected to receive an action value is -90909090909090909. But the action return the value is -90909090909090910

  [[eosio::action]] int64_t getvalue2() {
        int64_t value = -90909090909090909;
        eosio::print("getvalue2: ", value);
        return value;
  }

You can reproduce this issue through this repo https://github.com/quocle108/return-error

heifner commented 1 year ago

Thanks for the excellent bug report.

spoonincode commented 1 year ago

There appears to be an oversight in fc's json conversion that doesn't stringify small values that can't be represented in a javascript number: -90909090909090909 is smaller than -(253 - 1)

https://github.com/AntelopeIO/leap/blob/167bcf781cc07f0111d29a8489b87244f73ff6ce/libraries/libfc/src/io/json.cpp#L620-L627

This would only be a problem when consuming the JSON returned from a trace via javascript though (i.e. cleos is fine); but that's likely what is happening here since using reporter is using qtest

quocle108 commented 1 year ago

This would only be a problem when consuming the JSON returned from a trace via javascript though (i.e. cleos is fine); but that's likely what is happening here since using reporter is using qtest

it might be. Qtest gets the return value from eosjs. And javascript use Number (64-bit Floating Point) to present the number value, so rounding the number might be the issue?

BTW, it should be returned string in both cases even the value i > 0xffffffff or <= 0xffffffff.

spoonincode commented 1 year ago

Right, that number cannot be represented in a javascript primitive type. Just running

let x = -90909090909090909;
console.log(x);

in node,

$ node num.js
-90909090909090910

It would need to be represented as a bigint (or string).