It's possible to create a Factory-type Contract that can spit out other contracts:
contract Greeter {
string greeting;
address public creator;
function Greeter(string _greeting) {
creator = msg.sender;
greeting = _greeting;
}
function greet() constant returns (string) {
return greeting;
}
}
contract GreeterFactory {
function makeGreeter(string greeting) returns (address) {
return new Greeter(greeting);
}
function verify(address child) returns (bool) {
Greeter child = Greeter(child);
// Do something amazing here...
}
}
But how to verify that a Greeter at a given address is one that came from a trusted GreeterFactory? In other words, how to complete that verify()
function on the parent Factory?
Eve could create a contract with a static creator
property that imitates a known GreeterFactory fairly easily:
contract BadGreeter {
address public creator;
function BadGreeter() {
creator = 0x1010101010; // Address of a known GreeterFactory contract
}
function greet() constant returns (string) {
return "Trust me...";
}
}
A user could easily look at the blockchain to grab the bytecode for a contract and see the difference between BadGreeter and Greeter. But how could we build it so a separate contract could do it (via a call to a verify(address)
method of some sort that's trustless)?