metacartel / Harbour-MVP

Building a decentralised p2p meta-tx relayer network [MVP] Codename: Harbour ## We solved this problem: https://medium.com/tabookey/1-800-ethereum-gas-stations-network-for-toll-free-transactions-4bbfc03a0a56
https://medium.com/tabookey/1-800-ethereum-gas-stations-network-for-toll-free-transactions-4bbfc03a0a56
MIT License
30 stars 15 forks source link

Conditional execution #11

Open s1na opened 6 years ago

s1na commented 6 years ago

Hey everyone,

Meta txes are supposed to be submitted to the network immediately by relayers. It'd be however possible to delay their execution, and make it conditional, e.g. on time, state or events. This could allow "automating" actions like revealing votes and bids, or claiming rewards, etc.

There are two main questions however:

Kyrrui commented 6 years ago

In addition to this -- I have seen a contract add a execute by date so that a relayer cannot execute a transaction after a certain date. https://github.com/dreamteam-gg/smart-contracts/blob/master/contracts/token/DreamTeamToken.sol#L175

pet3r-pan commented 6 years ago

https://ethresear.ch/t/scheduling-transactions-with-arbitrary-bytecode-on-the-ethereum-network/3647

s1na commented 6 years ago

TL;DR We discuss adding (uint conditionType, bytes condition) to executable signed messages, and employing these fields to enable meta txes conditioned on EVM events.

Note: Conditional execution is costlier in terms of gas, but this shouldn't add much overhead to non-conditional txes.

Modifications to executable signed messages

As there are multiple ways to make transactions conditional, including by time, by checking state or by occurence of events, in addition to the data necessary for specifying the condition, we could add a condition type, which specifies how to parse the condition data.

Condition type

ConditionType Purpose
0x0 Not conditional (default)
0x1 Time-based condition
0x2 EventLog occurence

Condition data

For EventLogs, the condition could be the RLP-encoded concatenation of (address emitter, bytes32 eventTopic).

Relayer

Relayers would store conditional meta txes, and when the event specified by one of the meta txes is emitted, they compute a proof for the receipt that contains the event log, and send it along with the block header and index of log in receipt to the smart contract.

On-chain verification

For an incoming meta transaction which has a conditionType == 0x2:

Example for verifying proof.

Challenges

Meta transactions pre-specify the data field, which determines which function should be called, and what parameters should be used. This means, the arguments of the event can't be used for the transaction as they will be determined in future, and user can't sign it. This severely limits the flexibility of event conditions.

Ideally, users (or dapps) should be able to specify conditions on the event values, and use them in the transaction. E.g. whenever a Transfer(address from, address to, uint256 amount) was emitted, if from == SOME_ADDR compensate them with the same amount.

This could be solved by expecting the callback function to accept bytes eventData parameter, in addition to the fields specified in data, and modifying the identity proxy to append eventData to the parameters, when calling the callback function, if conditionType == 0x2.

jamesray1 commented 6 years ago

This means, the arguments of the event can't be used for the transaction as they will be determined in future, and user can't sign it. This severely limits the flexibility of event conditions.

In Rust you can use asynchronous futures with the Futures and Tokio crates.

Tokio uses the futures crate and has documentation for both here: https://tokio.rs/.

Because conditional execution is costlier, DDOS attacks come to mind, however it could conversely be used to prevent DDOS attacks. For instance, if a relay reward is below some limit that will be acceptable by a relayer, the relayer can choose not to execute that transaction and not relay it, and only do so for txs above this limit. And DDOS attacks on relayers are a poignant problem since meta-txs can be submitted at no cost, so many could be submitted. If a relayer is pseudorandomly assigned to a meta-tx at a given rate, this problem is compounded. An alternative solution to this problem is to make sure that a random beacon conditionally assigns a relayer to a meta-tx, iff the reward is >= the relayer's threshold reward amount. The implementation for the latter should be simpler, although conditional execution still seems generally useful.