1

I have a smart contract a little bit like this:

pragma solidity ^0.5.10;

contract sc {

    struct element {
        uint96 firstKey;
        uint96 secondKey;
        bytes32 firstData;
        bytes32 secondData;
    }

    mapping (uint96 => mapping(uint96 => element)) elements;

    function add(uint96 _firstKey, uint96 _secondKey, string memory _firstData, string memory _secondData) public {
        element memory newElement = elements[_firstKey][_secondKey];
        if (newElement.firstKey == 0){
            newElement.firstKey = _firstKey;
            newElement.secondKey = _secondKey;
            newElement.firstData = keccak256(abi.encodePacked(_firstData));
            newElement.secondData = keccak256(abi.encodePacked(_secondData));

            elements[_firstKey][_secondKey] = newElement;
        }
    }

    function validate(uint96 _firstKey, uint96 _secondKey, string memory _firstData, string memory _secondData) public view returns (bool){
        element memory retElement = elements[_firstKey][_secondKey];
        if (retElement.firstKey != 0){
            if ((retElement.firstData == keccak256(abi.encodePacked(_firstData))) && (retElement.secondData == keccak256(abi.encodePacked(_secondData)))){
                return true;
            } else {
                return false;
            }
        }
    }
}

It's designed to use huge numbers as keys (because bytes32 is not even close to enough).

I compile and test it on Remix VM and Truffle develop and works perfect.

But when I deploy it on my private network, it fails all the time. In fact, Truffle won't let me migrate and deploy Migrations.sol for starters.

Here's the error when I try to deploy with Truffle to our private network:

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.


Starting migrations...
======================
> Network name:    'privETH'
> Network id:      4660
> Block gas limit: 0x55d4a80


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > transaction hash:    0xaba670d9e92b559d92280476a4ba775180ce267d7927e59254020f9a5a978dc2
Error: Error: Error:  *** Deployment Failed ***

"Migrations" hit a require or revert statement somewhere in its constructor. Try:
   * Verifying that your constructor params satisfy all require conditions.
   * Adding reason strings to your require statements.

    at Object.run (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-migrate/index.js:92:1)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.0.30 (core: 5.0.30)
Node v10.16.0

With Remix, I get to deploy it, but whenever I try to call the add function I get this error:

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? The execution failed due to an exception.

The ethereum private network is configured like this (parts ommited):

"params": {
        "gasLimitBoundDivisor": "0x400",
        "maximumExtraDataSize": "0xF4240",
        "minGasLimit": "0x1388"
    },
    "genesis": {
        "seal": {
            "authorityRound": {
                "step": "0x0",
                "signature": "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
            }
        },
        "difficulty": "0x20000",
        "gasLimit": "0x5B8D80"
    },

And the parameters when starting the network are (parts omitted again):

 --gas-floor-target 900000000 --tx-gas-limit 500000000 --usd-per-tx 0 --force-sealing

Does anyone have any idea what could be the problem?

UPDATE

This is my 1_initial_migrations.js file:

const Migrations = artifacts.require("Migrations");

module.exports = function(deployer) {
  deployer.deploy(Migrations);
};

This is my 2_contracts.js migration for my smart contract:

const sc = artifacts.require("sc");

module.exports = function(deployer) {
  deployer.deploy(sc);
};

And this is the default Migrations.sol contract:

pragma solidity >=0.4.21 <0.6.0;

contract Migrations {
  address public owner;
  uint public last_completed_migration;

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

  modifier restricted() {
    if (msg.sender == owner) _;
  }

  function setCompleted(uint completed) public restricted {
    last_completed_migration = completed;
  }

  function upgrade(address new_address) public restricted {
    Migrations upgraded = Migrations(new_address);
    upgraded.setCompleted(last_completed_migration);
  }
}
  • Have you enabled constantinople (and petersburg) opcodes in your private network? – Ismael Aug 9 at 17:01
  • Not sure what you mean. The private network is version 2.5.5 which, I assume, should already have Constantinople in. – mdlapla Aug 12 at 6:28
  • Which client are you using? Usually in private blockchains you have to explicitly enable opcodes in the genesis file, see this for geth ethereum.stackexchange.com/questions/67794/…. – Ismael Aug 12 at 14:00
  • I'm using Parity version 2.5.5 but it is a private network, do I need to add this anyway? – mdlapla Aug 12 at 14:01

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.