1

I have a node running from geth --testnet --rpc --rpcapi "eth,web3,personal" --rpcport=8545 --rpccorsdomain "*" .

The contract is

pragma solidity ^0.4.15;
contract SimpleMultiSig {

  uint public nonce;                // (only) mutable state
  uint public threshold;            // immutable state
  mapping (address => bool) isOwner; // immutable state
  address[] public ownersArr;        // immutable state

  function SimpleMultiSig(uint threshold_, address[] owners_) {
    require(owners_.length <= 10 && threshold_ <= owners_.length && threshold_ != 0);

    address lastAdd = address(0); 
    for (uint i=0; i<owners_.length; i++) {
      require(owners_[i] > lastAdd);
      isOwner[owners_[i]] = true;
      lastAdd = owners_[i];
    }
    ownersArr = owners_;
    threshold = threshold_;
  }

  // Note that address recovered from signatures must be strictly increasing
  function execute(uint8[] sigV, bytes32[] sigR, bytes32[] sigS, address destination, uint value, bytes data) {
    require(sigR.length == threshold);
    require(sigR.length == sigS.length && sigR.length == sigV.length);

    // Follows ERC191 signature scheme: https://github.com/ethereum/EIPs/issues/191
    bytes32 txHash = keccak256(byte(0x19), byte(0), this, destination, value, data, nonce);

    address lastAdd = address(0); // cannot have address(0) as an owner
    for (uint i = 0; i < threshold; i++) {
        address recovered = ecrecover(txHash, sigV[i], sigR[i], sigS[i]);
        require(recovered > lastAdd && isOwner[recovered]);
        lastAdd = recovered;
    }

    // If we make it here all signatures are accounted for
    nonce = nonce + 1;
    require(destination.call.value(value)(data));
  }

  function () payable {}
} 

Deploy code is

const fs = require("fs");
const Web3 = require('web3');
const solc = require('solc')

const ethereumUri = 'http://localhost:8545';
const web3 = new Web3(new Web3.providers.HttpProvider(ethereumUri));

let account = web3.personal.unlockAccount(web3.eth.accounts[0], 'password');
let source = fs.readFileSync('SimpleMultiSig.sol', 'utf8');
let compiledContract = solc.compile(source, 1);
let abi = compiledContract.contracts[':SimpleMultiSig'].interface;
console.log('Abi: ', abi);

let bytecode = compiledContract.contracts[':SimpleMultiSig'].bytecode;
let gasEstimate = web3.eth.estimateGas({data: '0x'+bytecode});
let contract = web3.eth.contract(JSON.parse(abi));
console.log('gasEstimate', gasEstimate)

const addresses = [
  "0xa90a595e286a992b575b9f2858a6725bc176c3f6", 
  "0x1a2eec7053a246c6ed8a75cf0f47fbed2bd7b211", 
  "0x03852aadab1794dbd472ae9ac772e79801d3bc3b", 
  "0x2349e11f56413ac91cc05a46341e4ea7992bedd3"
]
contract.new(2, addresses,  {from:web3.eth.accounts[0], data:'0x'+bytecode, value:0, gas:gasEstimate}, (err, myContract) => {
  if(!err) {
     if(!myContract.address) {
         console.log("Hash: ", myContract.transactionHash);
     } else {
         console.log("Address: ", myContract.address);
     }
  }
  else {
    console.log(err);
  }
});

Here is the strange thing:

When I run node deploy.js , it throw an error 'Error: exceeds block gas limit'. So I try to subtract the gasEstimate to gasEstimate-5000, then run deploy.js again, but the new error is Error: The contract code couldn't be stored, please check your gas amount. The transaction id is 0x4cb91d82c110a6bd198aa97691ae9844938a7dc7c8629468b39b704a688acbc1. You can check it out on etherscan.io

Is there something wrong with my contract or deploy code?

0

Debugging with Remix shows the cause is probably this line:

require(owners_[i] > lastAdd);

Comment it out and the deployment appears to work.

|improve this answer|||||
  • I try to comment it out and find it still doesn't work. 悲伤... – Peili Liang Oct 31 '17 at 13:10
  • Possibly try testing on remix.ethereum.org first and see what's the complaint? – Linmao Song Oct 31 '17 at 13:38
  • I comment the require(owners_.length <= 10 && threshold_ <= owners_.length && threshold_ != 0);and it works. Still don't know the reason. – Peili Liang Oct 31 '17 at 13:49

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.