Git Product home page Git Product logo

Comments (5)

drlecks avatar drlecks commented on August 11, 2024

Hi,

Big numbers are true pain. Doesn't handle decimals. When transforming to bigger units, where divisions can produce decimals, big number returns an array of [quotient, remainder], not a "simple" big number.

Transforming toEther and fromWei is very delicate for this reason. That's why I added the xxxString versions, that return a "human readable" amount. All math involving BigNumbers has to be done in weis. Transformation to bigger units are only for user's I/O.

As for your example:

40432342326000000000000 transforms to 0x88FD777A5C42D216000 in hex (online hex converter)

This code:

$bn1 = Utils::hexToBn("0x88FD777A5C42D216000");  
echo $bn1 . " ";
echo Utils::fromWeiToString($bn1, "ether") . " "; 
echo Utils::toEtherString($bn1, "wei") . " ";

Prints as expected:
40432342326000000000000 40432.342326000000000000 40432.342326000000000000

from simple-web3-php.

Sigri44 avatar Sigri44 commented on August 11, 2024

Thanks for the clarification but I think that's not exactly the point.

When I use the explorer, the contract tells me :
int256: 40371499598000000000000
Which is the real expected answer.

But when I call from SWeb3 the contract, the raw answer given is :
0x88c8b1adb02476ae0000

Which would give us according to your conversion table :
645943993568000000000000

By doing $sweb3->utils->hexToBn("0x88c8b1adb02476ae0000"), I get :
0x0088c8b1adb02476ae0000

Which would also give us according to your conversion table:
645943993568000000000000

Concerning the toString function $sweb3->utils->toEtherString("0x88c8b1adb02476ae0000", "wei") :
645943.993568000000000000

So I don't understand how to find the expected result, indeed I want to find the same value as int256 from the retrieved GN, not the other way around.

from simple-web3-php.

drlecks avatar drlecks commented on August 11, 2024

Ok,

Then the problem is at the decoding step of the call function.

Can you paste here an example contract where this happens? I would help a lot.

Btw, I'm testing it on the main-dev branch. It has some improvements in the ABI decoder... So the example code can help me to find the problem.

from simple-web3-php.

Sigri44 avatar Sigri44 commented on August 11, 2024

Ok,

Then the problem is at the decoding step of the call function.

Can you paste here an example contract where this happens? I would help a lot.

Btw, I'm testing it on the main-dev branch. It has some improvements in the ABI decoder... So the example code can help me to find the problem.

https://optimistic.etherscan.io/address/0x82ac2CE43e33683c58BE4cDc40975E73aA50f459#readProxyContract#F3

from simple-web3-php.

drlecks avatar drlecks commented on August 11, 2024

Thanks for pointing me in the right direction.

There was a bug in the ABI decoder, when decoding signed integers. When the left hex character was >= 8 (most significant bit was 1), the ABI decoder treated it as a negative number.

It should be fixed on the next update (main-dev branch).

For the record, I used this test contract to test some cases:

pragma solidity >=0.7.0 <0.9.0;
 
contract Test 
{ 
    int256 public a;
    uint256 public a_unsigned; 

    int256 public b;
    int256 public c;

    //CONSTRUCTOR
    constructor() 
    { 
        a = 40371499598000000000000;
        a_unsigned = 40371499598000000000000;

        b = -1;
        c = 4503599627370495;
    }
 
    //CALL  (GETTERS)
    function  getValue_a() public view returns (int256)
    {
        return a;
    } 

    function  getValue_a_unsigned() public view returns (uint256)
    {
        return a_unsigned;
    } 

    function  getValue_b() public view returns (int256)
    {
        return b;
    } 

    function  getValue_c() public view returns (int256)
    {
        return c;
    }  
}

from simple-web3-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.