We (@aribo and @seliestel) have been discussing an idea to make some functions self executable. This would allow the deployment of contracts that execute in the future without an explicit call/send by an external agent. The objective is to create the potential for autonomous code running on the EVM. Of course, this would need to come with a cost and some limitations, in order to protect the network from potential complications and abuses.
The proposal is to create a new opcode ‘SELFCALL’ with four arguments:
p (position to mem where the bytecode to be executed is located),
initial block (set when the contract is created),
interval (number of blocks between executions, set in the contract code), and
gas price (price of gas to be paid at execution, set in contract code).
The EVM would need to calculate the difference between the current block number and the initial block. If this difference modulo interval is 0, the SELF bytecode located in p would be executed.
This opcode could be translated as a specific type of function modifier in Solidity, e.g. self. This modifier could be added to any function we want to self execute in the future.
SELF functions will be executed by the EVM every time a new block is mined, only if they have enough ether available. SELF functions would need to pay a set amount of gas every time they are called regardless of the computations they perform - basically the cost of the opcode. Moreover, the EVM would execute the SELF function as long as there is enough ether to pay the gas spent by its execution.
Some SELF functions would never be called because they have run out of allocated ether. Others might be called and pay the set amount of gas, but then result in no computation or change of state (for example, an alarm clock that begins with a require statement and only runs when a certain time has been reached). Finally, some SELF functions would incur an additional cost in ether as they are executed by the EVM when called.
An example of a SELF function in solidity:
function wakeUp self(uint 5, uint 10000) {
require (now == wakeUpTime);
doSomething();
}
The SELF function wakeUp would be called by the EVM every 5 blocks since the contract was first constructed. It would pay 10,000 wei per gas for its execution. The cost in gas of calling the SELF function would be standarized. If the time now is less or more than wakeUpTime the function would do nothing and it would only have to pay in ether the set amount for being called. If wakeUpTime has been reached, it would need to pay in addition the cost in gas of running the function doSomething().
This has been opened as an issue in EIP github repo: https://github.com/ethereum/EIPs/issues/1230