ethereum / remix-project

Remix is a browser-based compiler and IDE that enables users to build Ethereum contracts with Solidity language and to debug transactions.
https://remix-ide.readthedocs.io
MIT License
2.4k stars 913 forks source link

Debugger hangs than reverts on simple string array assignment #1530

Open grapevinegizmos opened 3 years ago

grapevinegizmos commented 3 years ago

I've tried this both in alpha and production remix ide, I get the same result when I call the function dedupeKeys shown below with the parameter ["a","b","c"]: When I try to debug it, the debugger hangs for 20+ seconds, and then just reverts;

decoded input | { "string[] keys": [ "a", "b", "c" ] } Copy value to clipboard
decoded output | { "error": "Failed to decode output: Error: overflow (fault=\"overflow\", operation=\"toNumber\", value=\"35408467139433450592217433187231851964531694900788300625387963629091585785856\", code=NUMERIC_FAULT, version=bignumber/5.4.1)" }   call to Tester.dedupeKeys errored: VM error: revert.

revert
    The transaction has been reverted to the initial state.
Note: The called function should be payable if you send value and the value you send should be less than your current balance.
Debug the transaction to get more information.</pre></div>

Here's the function am running:

pragma solidity >=0.7.0 <0.9.0;
import "./strings.sol";

contract Tester  {
    using StringsLibrary for string;
    function dedupeKeys(string[] memory keys) public pure returns(string[] memory) {

        string[] memory deduped;
         if (keys.length == 0) return deduped;  
        bool found;
        string memory key;
        key = keys[0];
        deduped[0] = key;   //DEBUGGER HANGS HERE
        for(uint i=1; i<keys.length; i++) {
            found = false;
            key = keys[i];
            for(uint j=0; j<keys.length; j++) {
                if(deduped[j].equals(key)) {
                   found=true; 
                }
            }
            if (!found) {
                deduped[deduped.length]=key;
            }
        }
        return deduped;
    }
}  

Here's a screenshot when it hangs: image

grapevinegizmos commented 3 years ago

I understand now what my error is, but it doesn't seem like that it should hang the debugger, when I attempt to write an array index that doesn't exist. I am surprised I didn't get an error at compile time actually if dynamic arrays can't be allocated in memory.