#15716·go-ethereum

int256 incorrectly converted to BigNumber

Author: 3sGgpQ8HCreated Dec 20, 2017Updated Sep 27, 2026
Labelsweb3js

Hi there,

System information

Geth version: 1.7.3-stable-4bb3c89d OS & Version: Darwin MacBookPro 17.3.0

Expected behaviour

Constant method of smart contract has result type int256. It returns value: 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF (valid positive value for int256 type). When called via JS wrapper generated by geth based on contract ABI, return value is converted to BigNumber javascript object with value 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF.

Actual behaviour

When called via JS wrapper generated by geth based on contract ABI, return value is converted to BigNumber javascript object with value -0x8000000000000000000000000000000000000000000000000000000000000001 (negative value that is actually not valid for int256 type)

Steps to reproduce the behaviour

Compile the following smart contract using Solidity 0.4.16:

pragma solidity ^0.4.16;
contract Bug {
  function x () pure returns (int256) {
    return 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
  }
}

Deploy contract, call function z() on it, convert returned BigNumber to string using .toString(16) and print it. The following will be printed:

-8000000000000000000000000000000000000000000000000000000000000001