As always, thanks a lot for your input Jon
First of all, to answer some of your remarks:
- I mixed up the numbers of the version => of course I am using v0.7.5
- Your comments concerning the multi-level inheritance are well understood and I adjusted my code accordingly
- I also understood your comments regarding the variable declaration (for the variable owner)
- I realized what my mistake was with the modification of my close() function and I adjusted it accordingly by inserting the onlyOwner modifier.
My adjusted solution:
File bankOwnable.sol
pragma solidity 0.7.5;
import "./bankOwnableDestruction.sol";
contract Bank is Destroyable{
...
}
File ownable.sol
pragma solidity 0.7.5;
contract Ownable{
address payable public owner;
modifier onlyOwner{
require(msg.sender == owner);
_;
}
constructor() {
owner = msg.sender;
}
}
File bankOwnableDestruction.sol
pragma solidity 0.7.5;
import "./ownable.sol";
contract Destroyable is Ownable{
function close() public onlyOwner {
selfdestruct(owner);
}
}
I have another question concerning the meaning of msg.sender:
- The mistake with the onlyOwner modifier in my Destroyable contract is actually the result of a misconception about the meaning of msg.sender
- From the tutorial of this academy and also from a written documentation (See “Block and Transaction Properties”), I assumed that msg.sender is equal to the current address that interacts with the contract, or in other words the address of the entity that calls the contract and its functions etc. I think this statement is correct, isn’t it?
- My misunderstanding was that I was mislead by the functionality of the Ownable conctract in the way that I assumed each time another address interacts with the contract, the constructor changes the value of the variable owner to the address of the party currently interacting with the contract. In the moment of writing the Ownable contract, I just missed the important fact that the constructor is executed only once when the contract is deployed. Since I do not change the variable owner somewhere else, it remains equal to the address of the party that deploys the contract.
To sum it up, are the following statements correct?
1.) msg.sender equals the address of the party/entity that currently interacts with the conctract (applies to both, the party that initially deployed the contract and all other parties that interact with the contract after its deployment)
2.) Using the Ownable contract, as shown above, is a best practice to store the address of the party that deployed the contract and can then be used for different purposes (in this case to selfdestruct the contract).
A final point:
I totally agree with the safety aspect related to selfdestruct - in case a smart contract has vulnerable code that is being exploited by an attacker, the designated contract owner can withdraw all remaining funds from the contract and mitigate the financial damage.
However, having one address with the power to withdraw all funds from a contract represents a strong concentration of power. I assume it is common practice that initiating the function to trigger selfdestruct requires the signature of multiple parties, but still the power remains in the hand of e.g. a few members of the developer team. My question actually is, is this a big/hot topic in the crypto space (the good old story about security vs. decentralization) and what is the general perception about this issue (feel free to post your own opinion if you want )