On my implementation, only the owner of the contract's function was able to call some important functions that I defined. I changed the implementation as by removing onlyOwner
, and adding cluster_constract[msg.sender].deleteAll()
that will allow only the message sender to call that important function, if their address mapped to a list. cluster_constract[<my_address>] = list
.
[Q] If an attacker knows the address of the msg.sender, can he calls deleteAll()
function (cluster_constract["<valid_address>"].deleteAll();
) from an external contract? Is my approach safe to use?
contract owned {
address public owner;
function owned() {
owner = msg.sender;
}
function ownerOnly() {
if (msg.sender != owner) throw;
}
modifier onlyOwner {
if (msg.sender != owner) throw;
_
}
function transferOwnership(address newOwner) onlyOwner {
owner = newOwner;
}
}
Before:
LinkedList.data list;
function deleteAll() onlyOwner {
list.deleteAll();
}
After:
mapping(address => LinkedList.data) cluster_constract;
function add_cluster() {
cluster_constract[msg.sender] = list;
}
function deleteAll() { //if cluster_constract[msg.sender] exits deleteAll() can be called.
cluster_constract[msg.sender].deleteAll();
}