0

thanks in advance for your time and intellectual contribution.

I am working on a project in which we have contracts interacting which each other.

More specifically, there is a "father contract", with functions that should be executed only by the "child contracts" therefore, we need a way to authenticate (to identify in fact) the callers before allowing them to do any action. For the case, the first thing anybody would think is to keep a list of the addresses that are allowed, something like this:

  ...
  mapping(address  => bool) allowedAddrs;

  ...

  //adds a new address to the list of allowed contracts
  function addChild(address _child) public onlyOnwner{
       //here code to verify if the addr is a EOA or a contract

       //add the contract to the list
       allowedAddrs[_child] = ture;
  }


  //This is the function that requires authentication/authorazation
  function authenticatedFunc() public payable{
         require(allowedAddrs[msg.sender] ==true, "Back off cheater" );
         // more code here
  }

I wonder however if it is safe! Can the address of a smart contract be faked ( cloned)?

What happens if some miner loads the contract at one of the allowed addresses, but with "some customs" and try to interact with this function of my contract? How does the blockchain guarantee that the address calling the function is not "a clone of one of the contracts that I included in the allowed list?

1
  • I think it is safe enough, because this way of smart contract auth has been used in the upgradeable contracts concept. Feb 26 at 14:17
0

msg.sender is either the account that signed the transaction or the contract that called your contract and it's created automatically. msg.sender cannot be faked and you can rely on it, otherwise Ethereum network won't be secure

1
  • Thank you guys I found my answer, well, I believe I did. It even seems so obvious now... I think the EVM may calculate the hash of the contract as part of the procedures used to validate each transaction. If anyone alters at least one bit on the contracts code the hash will be different than the original. Therefore its easy to distinguish between the original contract and possible clones. Thank you!
    – DarkWinter
    Feb 26 at 16:20

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.