Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: invalid solidity type!: safeuint #2

Closed
tpmccallum opened this issue Sep 29, 2018 · 8 comments
Closed

Error: invalid solidity type!: safeuint #2

tpmccallum opened this issue Sep 29, 2018 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@tpmccallum
Copy link
Contributor

I am getting the following error

> deployedSmartTokenContract.c();
Error: invalid solidity type!: safeuint
    at web3-cmt.js:8993:15
    at web3-cmt.js:9179:16
    at map (<native code>)
    at web3-cmt.js:9178:12
    at web3-cmt.js:9151:25
    at web3-cmt.js:12393:18
    at web3-cmt.js:12416:16
    at apply (<native code>)
    at web3-cmt.js:12540:12
    at <anonymous>:1:1

If I compile and deploy the the contract C and then call its function c as per the example at https://lity.readthedocs.io/en/latest/safeuint.html#example

pragma solidity ^0.4.22;

contract C{
    function c() public pure returns (safeuint) {
        safeuint a = 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
        safeuint b = 0x8fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
        return (a*b);
    }
}
@tpmccallum
Copy link
Contributor Author

Seems to compile ok using the following syntax

./lityc/lityc --abi --bin -o output/ c.sol

ABI

var abi = [{"constant":true,"inputs":[],"name":"c","outputs":[{"name":"","type":"safeuint"}],"payable":false,"stateMutability":"pure","type":"function"}]

BYTECODE

var bytecode = "0x608060405234801561001057600080fd5b5061011e806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063c3da42b8146044575b600080fd5b348015604f57600080fd5b506056606c565b6040518082815260200191505060405180910390f35b60008060007f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff91507f8fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90508082801560ea5781817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04101560e957fe5b5b0292505050905600a165627a7a72305820bd1203b65f31ae5e004ade57bc88d3ad40a2ab0fa9bff40db5b889f4447deb9a0029"

@hydai hydai added the bug Something isn't working label Sep 29, 2018
@hydai hydai self-assigned this Sep 29, 2018
@hydai
Copy link
Member

hydai commented Sep 29, 2018

I'll modify the output of ABI from safeuint to uint. Because the type safeuint is the same as uint in the ABI layer.

@tpmccallum
Copy link
Contributor Author

tpmccallum commented Sep 29, 2018

If I change the abi after Lity compilation (replace safeuint with uint) I can deploy the contract and then execute its following two functions.

function useSafeuint

function useSafeuint(safeuint _amountA, safeuint _amountB) public pure returns (safeuint) {
        return _amountA * _amountB;
    }

function c

function c() public pure returns (safeuint) {
        safeuint a = 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
        safeuint b = 0x8fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
        return (a*b);
    }

Issue
Interestingly though this is not producing the desired output. As you can see all of the calls below execute and return zero (0); which is incorrect.

>deployedSmartTokenContract.useSafeuint(0x8000000000000000000000000000000000000000000000000000000000000000, 2,  {from:accountA});

0
>deployedSmartTokenContract.useSafeuint(2, 2,  {from:accountA});

0
>deployedSmartTokenContract.c({from:accountA});

0

@tpmccallum
Copy link
Contributor Author

tpmccallum commented Sep 29, 2018

Just providing some more information here. Passing in plain uint256 and returning uint256 as part of the Solidity code (before compilation) produces the following results.

Also passing in just plain uint and returning uint as part of the Solidity code (before compilation) produces the same result (because the compiler turns uint into uint256).

 function useStandarduint(uint256 _amountA, uint256 _amountB) public pure returns (uint256) {
        return _amountA * _amountB;
    }
>deployedSmartTokenContract.useStandarduint(0x8000000000000000000000000000000000000000000000000000000000000000, 2,  {from:accountA});

0
>deployedSmartTokenContract.useStandarduint(2, 2,  {from:accountA});

4

@hydai
Copy link
Member

hydai commented Oct 2, 2018

Hi @tpmccallum,

Thanks for your test script. We already fixed the issue in the bugfix version v1.2.3.

Because the function selector in bytecode will use the function prototype to generate function signature which is the first (left, high-order in big-endian) four bytes of the Keccak (SHA-3) hash of the function name and types of parameters. If we only modify the abi output will make the function selector get wrong function and make the execution fail.

@tpmccallum
Copy link
Contributor Author

tpmccallum commented Oct 2, 2018

Thank you @hydai

I have updated to v1.2.3 and the safeint is now making its way through from the smart contract's source code to the deployed contract's execution.

I have a question.
What should the output from the example at < https://lity.readthedocs.io/en/latest/safeuint.html?#example > be?

For me, I get the number zero, as apposed to an error. Please see details below.

If I deploy this contract

pragma solidity ^0.4.22;

contract C{
    function c() public pure returns (safeuint) {
        safeuint a = 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
        safeuint b = 0x8fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
        return (a*b);
    }
}

I get this abi

[{"constant":true,"inputs":[],"name":"c","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"pure","type":"function"}]

and this bytecode

608060405234801561001057600080fd5b5061011e806100206000396000f300608060405260043610603f576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063c3da42b8146044575b600080fd5b348015604f57600080fd5b506056606c565b6040518082815260200191505060405180910390f35b60008060007f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff91507f8fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff90508082801560ea5781817fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff04101560e957fe5b5b0292505050905600a165627a7a72305820d7e783832617abff7655cac35f9ee085f25a8d38de22a18e1c4b5c1bc30af45d0029

If I deploy this and call the function called "c" I get the following result

> deployedSmartTokenContract.c()
0

I have written a page < https://github.com/CyberMiles/tim-research/blob/master/integer_overflow/integer_overflow.asciidoc > which elaborates on this, and poses a question.

Great work! Look forward to exploring this with you. I have a few ideas and am really interested in your view on this.

Kind regards
Tim

@hydai
Copy link
Member

hydai commented Oct 2, 2018

Oh, I see. We don't put the deployed example for safeuint. @dm4, can you help me write the example output for safeuint?

@dm4
Copy link
Member

dm4 commented Oct 15, 2018

I've just updated examples of safeuint here at commit b5158b8.

@dm4 dm4 closed this as completed Oct 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants