2

Here's my Test Code

pragma solidity ^0.4.20;

// StandardToken is from zepplin-solidity.
import "./StandardToken.sol";

contract Callee {

    address public caller_;

    function setCaller() public {
        caller_ = msg.sender;
    }
}

contract DirectCaller is Callee, StandardToken {

}

contract IndirectCaller {

    function call() public {
        // "0xb87..cfa" is the address of DirectCaller contract
        Callee(0xb87213121fb89cbd8b877cb1bb3ff84dd2869cfa).setCaller();
    } 
}

DirectCaller inherits two parent contracts, Calle and StandardToken. Since StandardToken of zepplin-solidity is pretty big, DirectCaller's compiled bytecodes are also big.

IndirectCaller calls Callee.setCaller() function using DirectCaller contract with its parent Contract. In my Remix, DirectCaller.setCaller() consumes 20394 gas and IndirectCaller.call() only consumes 7056 gas.

Is the reason that IndirectCaller.call() loads less byte codes that is related with its Parent(in this case, Callee) Contract?

Then, why don't all of us use small sized abstract interface for saving gas consumption?

  • Your question mentions abstract interfaces, but I don't see any in your code. I'm also not sure what the significance of the address is. Does that point to an instance of one of the contracts in the code you've shared? – smarx Feb 21 '18 at 10:39
  • 1
    Without StandardToken, if I use an instance of DirectCaller and an instance of IndirectCaller where call uses the address of DirectCaller, I find IndirectCaller.call takes just a little more gas than DirectCaller.setCaller. (29778 vs. 26666) One thing to be careful of: the first call to setCaller (however you make it) will cost more because it's setting a zero value in storage to non-zero. Subsequent calls will be cheaper because they're updating an already non-zero value. So when testing this out, just ignore the first call that updates caller_. – smarx Feb 21 '18 at 10:46
  • Thanks smarx, sorry for the unclear part. I've just edited my question. Could you see it again please? – santony Feb 22 '18 at 0:32
  • You haven't addressed my comment, which claims the opposite findings as you and hypothesizes as to why your measurement may be flawed. – smarx Feb 22 '18 at 1:10
  • I missed your point. Now I can see DirectCaller.setCaller() costs less. It was the issue of first call. Thanks for your kind reply! – santony Feb 22 '18 at 1:45

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.