1

This is my Contract code :

pragma solidity ^0.4.15;

contract D {
  uint public n;
  address public sender;
  event CallStatus(bool);

  function callSetN(address _e, uint _n) {
    if (!_e.call.gas(500000)(bytes4(sha3("setN(uint256)")), _n)) {
        CallStatus(false);
    } else {
        CallStatus(true);
    }// E's storage is set, D is not modified
  }
  function callSetN2(address _e, uint _n) {
      _e.call.gas(500000)(bytes4(sha3("setN(uint256)")), _n);
  }

  function callcodeSetN(address _e, uint _n) {
    if (!_e.callcode.gas(500000)(bytes4(sha3("setN(uint256)")), _n)) {
        CallStatus(false);
    } else {
        CallStatus(true);
    }// D's storage is set, E is not modified
  }

  function delegatecallSetN(address _e, uint _n) {
    if (!_e.delegatecall.gas(500000)(bytes4(sha3("setN(uint256)")), _n)) {
        CallStatus(false);
    } else {
        CallStatus(true);
    }// D's storage is set, E is not modified
  }
}

contract E {
  uint public n;
  address public sender;

  function setN(uint _n) {
    n = _n;
    sender = msg.sender;
    // msg.sender is D if invoked by D's callcodeSetN. None of E's storage is updated
    // msg.sender is C if invoked by C.foo(). None of E's storage is updated
  }
}

the execute environment is web3 provider connected to my geth private chain, when I use the default environment javascript VM, callsetN2 works fine.

when i call callSetN function using parameter ("0xe143a6ecbe6374463485664aecda3d0f0a6590d6", 10), I can get right number n from E contract. then I call callSetN2 function using parameter ("0xe143a6ecbe6374463485664aecda3d0f0a6590d6", 11), I can't get right number n from E, it's still 10 not 11. why does this happen? I tried to debug the callSetN2 function,

debug1

it should execute sstore opcode, but when I step on, the pc goes to D's contract, instead 257 of E's code.

enter image description here

this confuses me. Can someone tell me why?

0

I can't reproduce this. It behaves as expected in Remix as both callSetN and callSetN2 correctly set the n property on E.

  • when I connect to web3 provider in the remix environment, deploy and call contract in the remix, I can produce this problem. when I directly deploy and call contract in the geth console, there is no problem. so I think maybe remix has a bug. – likang Oct 28 '17 at 11:56
  • I know why. Because in the remix environment, the gasLimit setting doesn't work, so even if I set gasLimit to 500000, the transaction's real gasLimit is 25673 which is not enough to execute. – likang Oct 28 '17 at 13:41

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.