0

I'm trying different random algorithms on smart contracts. I have an array where I can push accounts, then I use the random algorithm to select one.

When I have ~ 20-50 entries everything works fine however if I push 300-500 accounts in the array and I use the random algorithm Remix crashes and returns me to browser/ballot.sol

Is it a problem with Remix? Will I have the same issue if I will use an Ethereum network (Rinkeby, Main, etc.)

EDIT: For everyone who wants to have a go:

pragma solidity ^0.4.17;
contract TestingRandom{
address public theCreator;
address[] public participants;
uint public Secretkey1;
string public Secretkey2;

constructor() public {theCreator = msg.sender;}

function enterArray() public payable{
if (msg.value == 1 ether){
participants.push(msg.sender);}

else {if(msg.value == 2 ether){
for(int i; i<150; i++)
participants.push(msg.sender);
}}}

function key1(uint anInput) public {
Secretkey1 = anInput; }

function key2(string anInput) public {
Secretkey2 = anInput;}

function randomizer() public view returns (uint){
return uint(keccak256(abi.encodePacked(Secretkey1, Secretkey2, participants)));}

function selectParticipant() public {
 randomizer() % participants.length;   
 participants = new address[](0);
}
}

Instructions of use: 1) After you deployed the contract, use each account offered by remix to enter the array by sending 2 Ethereum (make sure ETH is selected instead of wei). Each entry with 2 ether means 150 entries in the array. Do this process three times, meaning that you will have 450 'participants' in the array. If you have problems when sending 2 ether, select 4000000 gas

2) now pass a uint for secretkey1 (function key1) and a string for secretkey2 (function key2)

3)You are ready. Click on 'selectParticipant' function. Remix will crash and you will lose the code.

EDIT2: I Created a new function which accesses players array. It seems that it's exactly when it comes to access the array with all addresses that Remix crashes.

  • You need to share you code and the exact error message for us to help you. – Shawn Tabrizi Sep 19 '18 at 18:01
  • Doing that right now. No error message by the way – Cristian Sep 19 '18 at 18:06
  • Not even in your JavaScript console? – Shawn Tabrizi Sep 19 '18 at 18:09
  • Hi Shawn, I added a new comment with the code. Have a go ;) – Cristian Sep 19 '18 at 18:29
  • You should file an issue at the remix github repository – Henk Sep 19 '18 at 18:56
1

HERE THE ANSWER TO MY ERRORS:

When I was using remix, I was running in JavaScript VM Environment. The reason Remix was crashing is because any web browser I was using would enter into a "script is taking too long to load" kind of error due overload of many transactions being called (it never showed this issue so took me a while to realize). In good old days, Internet Explorer used to give this kind of warnings then tell you that if you continue, something may go wrong. For me, both Chrome and Microsoft Edge would just refresh their state and make me lose my progress.

The only way I could solve this issue is by creating a front-end to run my tests on Rinkeby. From the front end, I have different buttons to call the different functions etc.

If you don't want to build a front end you can still load your contract on Remix using Rinkeby network however I don't guarantee that it will work at full potential. The good thing is that even if it crashes, your progress gets saved.
I can now access arrays with > 2k elements inside without problems

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.