Smart Contracts on STEEM

in #steemdev7 years ago

steem-contract.png

One of the things that attracted me to cryptocurrencies was the possiblity of smart-contracts: automated agreements that cannot be broken. Smart-contracts offer the possibility of dealing with complete strangers in a trustless way and of disintermediating most of the current businesses that require a trusted third-party (think Uber and AirBnB). This is why Ethereum is so popular: it is highly tailored to deploy these smart-contracts. However, Ethereum suffers from a number of problems:

  • transaction fees: Transactions, as well as computations on the Ethereum network, necessarily cost Ether (the currency of Ethereum).
  • transaction throughput: At the moment, the ethereum network can at best handle on the order of tens of transations per second which, even though much higher than the bitcoin blockchain, is still a pretty low throughput.
  • accessibility: In order to interact with smart contracts, you need either a specialized browser or an extension of your existing browser (e.g. Mist or Metamask). This makes it pretty opaque to normal users.

The situation is improving in all of these points but it is still pretty far from being usable.

Because it is meant for the general public, as a social network of sorts, Steem was made from the ground up to be as easy as possible to onboard users. This means it possesses a number of advantages over ethereum:

  • (virtually) no account creation fees
  • simplified key management
  • fast transactions
  • no transsaction fees

However, because it is tailored to deal with blogs and posts, steem is specialized to store JSON data, and not to run any kind of user-code. Or is it?

What are smart-contracts for, really?

If you think about it, smart-contracts are like vending machines: you insert a coin, and out comes a chocolate bar. It is an automated and predictable sequence of events that you can trust. And this is the important function of smart-contracts: to generate trust.

Ethereum smart-contracts perform this function by making the contract run on every computer of the network, and making sure all these nodes reach a consensus about the outcome of this computation. But is this the only way of generating trust?

POCKET: a smart-contract running on STEEM

Underlying any contract is the notion of state and the set of rules that can affect that state. For example, a cryptocurrency is a simple contract, in which the state is the balance of a every user and the rules are simply the transaction rules:

  1. transations are conservative, i.e., amounts that go out of an user's balance must go to some other user's balance,
  2. transactions from a user must be signed by that user and
  3. a user cannot have a negative balance (transfers that lead to a negative balance are not allowed).

This last rule is sensitive to the order of transactions. So, as long as we can be certain that a certain transfer was ordered by the owner of the account and we can establish an order to these transfer orders, we could just annouce transactions and anyone could verify that those transactions were valid or not.

This is exactly what @biophil built with Pocket: a cryptocurrency built on top of Steem. He coded a bot that trawls through every post on the steem blockchain looking for transaction orders (which are simply text in a special format: send:xxx@user), making sure they are valid and announcing it to the world. Internally, the bot keeps a ledger of everyone's balances. In addition, anyone can run their own bot, either @biophil's or their own implementation of the protocol, for additional confirmations of the transactions, earning a fee (in POCKET) in the process.

The cool thing is that the hard parts of the process (verifying identity, establishing an order for the transactions, and the whole networking infrastructure) are taken care by Steem. Simply by posting a message to Steem, we prevent anyone else from stealing our POCKET (by signing the message) and prevent a malicious actor from double-spending his POCKET (by time-stamping the transaction). The rest is simply book-keeping.

If you think about it, what the POCKET protocol is doing is building a trusted, distributed ledger on top of the Steem blockchain. POCKET is posting instructions to the blockchain that can have meaning under a set of rules and anyone interested in the POCKET protocol can just verify every transaction and assert anyone's balance. So, the "code" is not really executed in the blockchain, but can be executed and verified by anyone. As both @biophil and @dantheman point out, nothing stops us from coming up with more complicated sets of instructions and "running" those on the Steem blockchain.

But what happens if anyone decides to not abide by the rules of the POCKET protocol? Imagine for example that someone decides that there is a maximum value for one transaction. In this version of the rules, some transactions would not be valid, since they would be above the maximum transaction. Well, as long as not everyone switches to these new rules, the two ledgers would co-exist: people would have a certain account balance according to some rules, and another, potentially different, balance according to the other set of rules. This would constitute a fork in the ledger and illustrated the social component of the consensus that blockchains impose. I find that this goes very well with the social focus of the Steem blockchain.

I am extremely excited about this, not just because it's cool™ , but also because it opens the door to more complex smart-contracts on steem. Expect news in that direction...


If you enjoyed this piece, please upvote, resteem, and follow me.

Sort:  

Good news and premium content rated with A+++. I hope there will be soon more informations on the smart contract possibilities on the steem blockchain.

Very nicely presented and does a wonderful job of explaining the potential for Smart Contracts / SMT. This something that will certainly enhance the value of the Steemit blockchain as more proof of concepts and creative use of these contracts begins to grow. Pocket is simply one token that exhibits many uses, which is just one of many to come in 2018.

Expect news in that direction...

Absolutely!

Reading this post was such an educational experiece for me. The content is of the highest quality and I am pleased to have found and curated it via the Pocket discord. Expecting big news soon!

Oh, was it promoted at the discord? Didn't realize that... Thanks for the kind words.

I find the use of the term 'contract' quite different to what I am familiar with in the real world. Of course we can determine via a set of algorithms how a transaction is processed, but this is just the outcome of an agreement on a contract between two people about the conditions on which this transaction will be valid. I am not sure how this would be written or integrated into SMTs, so I am interested in whether there will be a need for dispute resolution services in the blockchain space...