I have seen many posts around the division operation in Solidity e.g. Cant' do any integer division. Firstly, the error I am facing is different. Secondly, I am ensuring that, all numbers in division operation are set to uint256. So, I am not sure, what this error means and how to fix this.

This is with Ethereum testrpc.

Solidity function

function getQuotient() returns (uint256) {

    uint256 numMembers = uint256(someStruct.someArray.length);
    uint256 sampleSum = someSameplSum; //set to uint256 elsewhere
    uint256 avgNum = sampleSum / numMembers;

    return avgNum;


Error: Error: VM Exception while executing eth_call: invalid opcode
    at /home/ubuntu/node_modules/ethereumjs-testrpc/build/cli.node.js:59368:17
    at /home/ubuntu/node_modules/ethereumjs-testrpc/build/cli.node.js:69306:5
    at /home/ubuntu/node_modules/ethereumjs-testrpc/build/cli.node.js:11335:9
    at /home/ubuntu/node_modules/ethereumjs-testrpc/build/cli.node.js:7895:16
    at replenish (/home/ubuntu/node_modules/ethereumjs-testrpc/build/cli.node.js:8415:25)
    at iterateeCallback (/home/ubuntu/node_modules/ethereumjs-testrpc/build/cli.node.js:8405:17)
    at /home/ubuntu/node_modules/ethereumjs-testrpc/build/cli.node.js:8380:16
    at /home/ubuntu/node_modules/ethereumjs-testrpc/build/cli.node.js:11332:13
    at /home/ubuntu/node_modules/ethereumjs-testrpc/build/cli.node.js:69302:9
    at /home/ubuntu/node_modules/ethereumjs-testrpc/build/cli.node.js:63982:7
    at Object.InvalidResponse (/Users/nsubrahm/node_modules/web3/lib/web3/errors.js:38:16)
    at /Users/nsubrahm/node_modules/web3/lib/web3/requestmanager.js:86:36
  • 1
    If numMembers is zero, the division will throw an exception. Exceptions are reported as invalid opcode. – Ismael Aug 27 '17 at 9:43
  • I think, I am running into that case numMembers=0. Thanks for the hint! – cogitoergosum Aug 27 '17 at 10:36

Your Answer

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

Browse other questions tagged or ask your own question.