0
votes

I'm working on zk-proofs , but my solidity code returned an error as the title tell .

I have no idea about this situation , does anyone have some ideas?

this is my solidity function code

    function stringToUint256(string memory s) internal pure 
    returns (uint256, bool) {
    bool hasError = false;
    bytes memory b = bytes(s);
    uint256 result = 0;
    uint256 oldResult = 0;
    for (uint i = 0; i < b.length; i++) { // c = b[i] was not needed
        if (b[i] >= 48 && b[i] <= 57) {
            // store old value so we can check for overflows
            oldResult = result;
            result = result * 10 + (uint256(bytes(b[i]) - 48) ; 
            // prevent overflows
            if(oldResult > result ) {
                // we can only get here if the result overflowed and is smaller than last stored value
                hasError = true;
            }
        } else {
            hasError = true;
        }
    }
    return (result, hasError); 
}
1

1 Answers

1
votes

I’m not familiar with solidity, but from just looking at the code, I think you’re missing a bracket in the following line:

result = result * 10 + (uint256(bytes(b[i]) - 48) ;

The brackets around the (uint...) part are incomplete. This might be what’s causing the syntax error; the program isn’t expecting a semicolon before the closing bracket.