Logan Saether - Ethereum alarm clock : Scheduling transactions for the futur

ETHCC 1 · 9 Mar 2018 · 29:50

Logan Saether, a Solidity developer at Chronologic, presents the Ethereum Alarm Clock, an open source smart contract protocol for scheduling transactions in the future. He explains why Ethereum has no native way to do this, use cases such as timed token purchases, recurring payments and ENS reveals, and the architecture of schedulers, request factory, tracker and transaction requests. Off-chain time nodes execute scheduled transactions in return for a bounty and a gas refund. The talk also covers the JavaScript tooling and ends with questions on gas prices and incentives.

Speakers

Topics

From ETHCC 1, hosted by Ethereum France.

Transcript

so my name is Logan Sayer I'm from chronologic I'm a solidity developer and I'm gonna be talking about what we've been working on for the last few months which is the etherium alarm clock okay so so what is the theorem alarm clock the theorem alarm clock is an open source smart contract protocol I was originally created by Piper Miriam in 2015 Piper is a veteran dev he's now at the foundation and he has a multitude of projects that he works on unfortunately

the alarm clock was one of the projects that fell out of use wasn't priority for awhile for that reason it wasn't working so when chronologic came around and picked it up what we did was we rebuilt it got it functional again built up a ton of JavaScript tooling rewrote the whole test suite using truffle and we've been building a front-end dot that uses it and we're hoping to get a lot more third-party integrations involved so right now we have it deployed on covin

and pending on the main net so here's a picture of Piper doing the first talk on the alarm clock at Def Con 1 in 2015 so what is the reason for the alarm clock so the it's pretty simple what we want to do is be able to schedule transactions and we currently have no native way and aetherium to accomplish this so the reason for this is because all transactions require an external trigger so what we want to do is be able to set the parameters ahead of time say when we want this transaction to happen then have guarantees that that

transaction will go through there's various solutions for this that involve just server-side cron jobs the the big value add of the etherium alarm clock is that it's on chain and trustless and uses incentives to guarantee executions um so I'll go into just a few use cases here the first one of course being buying tokens from an IC o---- if it's if you're in a different time zone from when the ICL launches and you don't want to stay up until 4 a.m. at night you can schedule the transaction it'll buy the tokens for you and you can transfer

those tokens out any kind of routine call can be scheduled using this so if you have a rent payment you can find a wallet for six months a year and then have that wallet similar to a pool transaction if you schedule all those transactions for the first of each month in general it unlocks a lot of possibilities with smart contract integrations the ESC canary is a another tap from Piper and what it does is it schedules to itself every two hours just

to make sure the service is working we're hoping to see a lot of client-side apps use the alarm clock of wallet integrations and a really cool use case is the ENS the etherium name system so right now it involves two transactions I commit and to reveal and the reveal happens two or three days afterward so if you forget to do a reveal you lose your money what you can do now is when you commit also scheduled that reveal transaction and not have to worry about coming back in two days to reveal and then run a time node which is the

execution in client and I'll be more about that so right now what we're focusing on is our partnership with my crypto and we're looking for a lot of a lot more third party involvement here so we're very open to just getting involved with projects that think they might want to use a service so for my crypto what we're doing is we're doing all the code and we're submitting a pull request and if and we we might be interested in doing more things like this if anyone wants to talk to us about it we have a booth just outside and now we'll be going into a little bit about how the

alarm clock works on on a deeper level so the the reason for their alarm clock is that we have two types of accounts on ethereum we have the users and the smart contracts and the smart contracts are unable to call themselves and the you so the users are the only accounts that have to go through this manual process of creating a transaction signing of that transaction and publishing it to the network and what the alarm clock wants to accomplish is to create a smart con to create smart contracts that can execute by themselves so the way we do this is we have so so you so user knows

what's transaction they want scheduled and they talk to the alarm clock protocol they can input these parameters it deploys a new contract and then and then on the other side we have these execution clients called time nodes and these are watching the blockchain for every time a new transaction is created it'll store it and then execute it once the execution window comes along so the architecture can be broken down into like four main pieces we have the schedulers the requestfactory the request tracker

and the transaction requests so the schedulers are the top level of entry point and below that set the request factory which actually deploy the new contracts and the request tracker keeps all of the addresses in storage so this is the way we can keep everything on chain and even though we have off chain execution clients they're always querying the request tracker to see what's stored this is just another way to kind of organize it the schedulers are sitting at the top and all their libraries and requestfactory are sitting

below them here's the dependency chart so the there's about 20 smart contracts in total most of them libraries and they are all interconnected talking to each other so it's arc it's actually a little complex with how it works but most of what is going on here is validations to make sure all the parameters are correct so the scheduler it's a it's a top-level entry point there's two varieties so if you want to use block numbers you can set all the parameters using blocks if

instead you want to use a time stamp we we have we can offer that as well so the parameters that the scheduler take we have the to address which is the recipient that the transaction will be sent to bytes which is the call data so if you want this transaction to go to a smart contract and execute a function you would input the encoded byte data here and then eight unsigned integers which I'll go into right here and these are what actually the parameters that you want your transaction to have so

so these are just the same parameters that any aetherium transaction take you specify the coal gas the the value you're sending the window size so this is when you want this so this is the size of the execution window the window start so when you want the execution window to start gas price and then we have a few parameters that are specific to the alarm clock protocol itself we have the fee which is a way for any kind of integrations to make some money off of integrating the alarm clock protocol into their application and then we have

the bounty which is what is rewarded two time nodes when they execute transactions and they're required deposit which is part of the claiming mechanism when a time node wants to claim a transaction it sends this deposit so let me jump back to this timeline here so the execution windows when you want your transaction to happen because of network properties we can't guarantee a specific block so you set a window and this is a variable you can set it for as long or as short as you like a good minimum would be about 10

blocks and so so before the execution window we had the claim window this is when time notes can send that deposit and say that they're claiming this transaction and that they'll execute it so if they claim it they get a guaranteed exclusivity window at the beginning of the execution when they're expected to execute this and if they fail to execute then it does go into the free the free-for-all window here and the bounty that they had sent to claim that transaction then gets rewarded to whoever executes instead so the requestfactory is what's actually

deploying all of these new transaction request contracts every time someone schedules so so what this contract does is it'll it just deploys the contracts but what's a really cool thing here is that we've recently integrated the clone factory pattern which there might be a lightning talk going on right now about it and what that does is it instead of deploying the full contract it'll deploy this small piece of byte code which then just delegate delegate

calls all calls to a kind of like library contract so this was really cool for us it saved us a ton of gas if if you have something that's deploying a lot of contracts this is a great way to optimize your gas usage so here's the requestfactory interface it's pretty simple this this contract really just creates the requests it also provides some validation on the parameters that's

that are inputted so the so usually you want to use a create validator request when creating a new transaction request if you use the lower-level create request no validation is done so you might end up wasting gas if you input parameters that don't make sense and then just functions to check to make sure that this Factory is aware of transaction requests so the transaction request is what actually stores all the scheduled parameters it stores the funds that you send it the the funds will cover the gas

usage the value you're sending and we we kept everything in this kind of like isolated like per contract environment instead of keeping everything in that centralized place to avoid any kind of vulnerability is about keeping large amount of funds like I mentioned before this contract just takes all the call data it's given and then delegate calls that and we've also included a proxy function here so if you do schedule a transaction to buy assets or buy tokens

those tokens will then be sent to the transaction request contract and you can proxy call that out to make those tokens actually useful so here's the interface of the transaction request there's three actions you can use execute cancel and claim execute and claim are both time node related and cancelling is if the user chooses to cancel the transaction the proxy function I mentioned before and then just a few ways to pull payments and get data from that contract so if anyone's interested here's what

the proxy function does it takes the code to call data and then simply routes that to whichever recipient you want it to go to so to transfer tokens it's as easy as just calculating or encoding the data and then sending that to the token contract and so so that's kind of like the scheduling side of the protocol but on the other end we have the time nodes which are actually executing so the time nodes are client scripts and they do operate off chain but what we have is we're able were able to create

incentives where anybody can run these clients and and then get rewarded and for executing transactions so in this way we kind of encourage people to be running these clients all the time we think that this is going to be really popular people will want to do this so even though it's a client side off chain script we still have this kind of decentralized market that's created over the incentives so the so the execution flow just scheduled and then that'll get

sent so here we see that so when a user scheduled as a transaction they'll they'll get back the address for that transaction they can keep that in case they want to cancel it or check up on it Tom notes we'll be watching for the blockchain for every time a new one's deployed it'll then execute that and get rewarded in the bounty so with this bounty incentive mechanism this is how we can guarantee a crypto economically sound protocol so regardless of whether

that transaction that the time node executes actually is successful or whether reverts doesn't matter to the time node because the time node is gonna be receiving the bounty plus the gas no matter what so it theoretically it's always going to be profitable to run a time node and all although they're off chain we're gonna we should see many different people running these clients now I'll talk a little bit about the JavaScript tooling we have so this is

available for developers and it's a great way to get started with using the alarm clock in your own application so the we have a JavaScript suite that we're calling GAC Jas this includes the command line tool to both schedule transactions and run a time node we also have the time node logic in the es UJS client library and then we have a lower-level library for just interacting with the alarm clock contracts if you're a developer I highly encourage you look into these we try to make tools for you to get started really easily here's an

example of how this looks so if anyone's worked with web 3 before I'm sure you have there's the kind of header you always have to do to instant initiate it then you just pass this web 3 object into the ESU library and right away read some network and it'll create contracts for that network so if you're using covin it will use the latest coving contracts and then it's as easy as just calling the requests so if you want to execute a transaction you just call the requestfactory you get the latest instance you can call get request from a block number and then use that latest one to execute a transaction so this

would be kind of an example logic out of time to client and now I'll give you guys a quick demo of the front and DAP we've been building to kind of make this a lot easier for just your general users so here's the flow to schedule transactions so this would be using timestamps we've made it easier by just putting in a time zone and then converting that to a timestamp on the back end you can specify the execution window the information here so the recipient the gas gas price all the stuff I went

over before the bounty we've made the claim deposit optional and then we have meta mask integration here so after verifying everything is what you set it'll ask you to confirm say yes and then we have this nice summary page we kind of wanted this to be like a block explore for future transactions instead of transactions that are already happen and then from there users can cancel if they would like to if not then they can

look into this transaction scanner here and we've also built a time node into the browser so so to use this you can use a version 3 my crypto wallet decrypt it work for this we're requiring people who use the browser time know to own some of our chronologic token day this isn't something that's in the protocol it's just something we put into the front-end dot sign message there and then this nice dashboard so to start and

stop your time node you can get the lower-level logs these would be what you're getting from a command line client this just shows that you're using these contracts the deployed addresses and it shows the lower-level logic of what this time note is doing so here it's attempting to claim this transaction request but we have kind of a randomness built in so it's it's fate insists you wait until later so we just have so it's just waiting till later there and like I mentioned before we're open to talking to whoever wants

to maybe use this we would love to talk more about integrations and potential partnerships so I think we have a few minutes if anyone has a question increase the the call data or yeah so the call so the call data is as many bytes as you'd like it to be and it's like the encoded call data for on ethereum transaction so if you want to send a function on a smart contract you would calculate that client-side and

then pass it into the scheduled transaction it's but so there's potentially yeah there's potentially that issue so maybe not every time you use the ENS would you want to do this if it's a name that you think might get like might get taken from you maybe for like some names that aren't competitive you'd want to do it but not all yeah yeah so um so the gas the gas price mechanism isn't perfect

yet we're still like fielding ideas there and trying to figure out the best way to do it but right now you said it when you schedule so it's on a front end side we want to kind of tell what the user what to do there that's not really taking into account what the network might be like and that transaction actually gets scheduled so right now the we're saying if you want the transaction to go through you put it with a high gas price and that way you have a better guarantee you it'll go through but it's definitely something we're looking into and trying to find a better solution for yes oh yeah yeah so um so so this whole

thing it tries to target like a standard here of doing this so using this thing like smart contracts or other applications using a cron job would be more gas efficient under certain situations there but what we really want to try to do is get a standard way to do this so we don't have everybody doing cron jobs separately and instead we can have a kind of a one global cron job that's running even if it costs a little bit more gas yeah still have better guarantees that if your server goes down that's or any of that cron job it'll still get executed yeah

yes so we so there's no workaround for that now it's we're really so you'd have to fund those schedules right away it's not a it's not a general solution for your pool payments like that but rather if you had those funds already you can just say when you want those to happen yeah yes-no so if a time note is running and

doesn't it doesn't do anything doesn't execute any transactions it just nothing happens to it it's not it's just not sending transactions so it's just not spending any money or getting any money for just running instead what we do is we say if it's sending transactions and it does an execution that's incentivized so so it was so if a time note sends a transaction it will always get the bounty and the gas back it'll there's never a case for it to lose money did that answer your question uh so so okay the claim deposit okay so

notice yeah so no so the time note is actually just running like a client script there and doesn't have to deposit to become a time note but it sends transactions yeah yep yeah that's completely possible yeah that's that's a use case we've

discussed yeah anything else all right thank you [Applause]

Related talks