The following pattern is something that recurs a lot in the contracts I am develping and when I run an analyser over it I get a couple of warning.

Say I have two contracts as follows:

pragma solidity ^0.4.18;

contract Candy {
    address public owner;

    function Candy() public {
        owner = msg.sender;


pragma solidity ^0.4.18;

import './Candy.sol';

contract Wrapper {

    Candy private candy;
    address public owner;

    function linkTest(Candy _candy) public {
        require(address(_candy) != 0x0);
        address candyOwner = _candy.owner();
        require(candyOwner != 0x0);
        owner = candyOwner;
        candy = _candy;

The first warning is that linkTest includes a potential violation of the Checks-Effects-Interaction pattern.

My understanding of that is that if _candy was some unknown incoming address and not something explicitly castable to Candy then this might be an issue, but the two contracts are quite tightly coupled.

To mitigate this I ensure that any update to state is done after any require but the warning still shows and I am not sure how I'd refactor this to elimiate that.

The second warning is that the Gas requirement of linkTest is unknown or not constant. This is because of the call to _candy.owner().

How would I refactor this to elminate both warnings? Is there a way I can proscribe an upper bound to the gas requirement for _candy.owner()?

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.