0

Basically what I am doing is I am passing ownership of contract A to contract B.

The function below is only in contract A. I do not give contract B any code to call this function.

  function setOwner(address _owner) onlyOwner {
    pause();
    balances[owner] = initial_supply - public supply;
    owner = _owner;
    balances[owner] = public_supply;
  }

So I want to know, once I pass ownerhsip of A to B, is it impossible for it to change hands again? I want it to lock the ownership so I am hoping this is true! Thanks!

  • If you feel your question has been answered, could you please mark it so other users know :) – Malone Nov 19 '17 at 0:25
1

If there is nothing stopping the setOwner function from being invoked again then it is possible to change the owner (but only by contract B if that's the new owner).

I'd suggest placing some code within the setOwner function so that it is only able to be executed once. For example:

bool isOwnerSet = false;
function setOwner(address _owner) onlyOwner {
    if(!isOwnerSet) {
        pause();
        balances[owner] = initial_supply - public supply;
        owner = _owner;
        balances[owner] = public_supply;
        isOwnerSet = true;
  }
}

This will mean that the new owner will not be able to invoke setOwner in the future.

| improve this answer | |
  • So if Contract B is the owner, and contract B has no way to call setOwner, is it effectively locked forever that contract B is the owner? – dave kajpust Nov 9 '17 at 17:01
  • If you want contract B to be the new owner and never change, then make sure that the owner = contractBAddress. Yes, contract B will be the owner forever if that is the case, provided there is no way to revert isOwnerSet back to false i.e. private variable without a setter. – Malone Nov 9 '17 at 17:06
  • @davekajpust fyi – Malone Nov 9 '17 at 18:57

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.