534 points · by mjfl · 9y ago · 125 comments
As one of the 'killer apps' for ethereum is smart contracts, I'd like to see this explained in a 'for dummies' high level way, then decomposed into the finer technical chunks needed to make it happen.
a "smart contract" is a script that runs on a blockchain to execute terms and manage funds.
the problem is that the tools that you use to make these are basically garbage. you don't write fin-tech in what amounts to javascript y'know?
And I think that even beginners know that you can't trust users' input - you have to sanitize it. And under no circumstances you want to execute it!
But here it is the opposite, isn't it? You basically give users ability to run any code within your application (blockchain). And you give them very insecure, confusing and badly designed language.
To me it is an epitome of insecurity. It is like giving a shotgun to a child!
If there is > 1,000 Ether in this contract address before timestamp x then send the Ether to the project lead, else refund all the users.
The (non-fintec) example I often hear about often is a voting system. (See: https://github.com/stonecoldpat/anonymousvoting , here zk-snarks algorithm is introduced to ensure privacy)
Essentially anything that requires co-ordination between parties that don't trust each other over a piece of data (a balance of money, the tally of a ballot) is a perfect use case for smart contracts. But since there is cost to running it on these secure networks it is important that they remain O(1) or at most O(n) time complexity, which for these kinds of applications is often totally enough. (eg. if (the message is signed by the 'owner') { send the funds } else { throw })
A poorly written smart contract that handles real money, on the other hand...
100% bug free software is impossible! As long as they are written by humans? Their will always be bugs. Matter who is writting them.
You don't need to prevent all bad behaviors, just slow attackers down.
Of course sometimes they can get through the review process too, but you start having probabilities you can multiply to decrease the likelihood of losses.
Over time we'll start to have good defaults for how those checks work. For now it's the wild west.
For example, maybe you like to quickly reimburse each other for dinner, but you won't or can't use Facebook Messenger payments, perhaps because some of you aren't on Facebook, or you're not in the US.
So you want to make your own little payments system. You might start with just setting up a simple server that tracks your debts, with a simple web app to log in and send funds. Suddenly it's much easier for you to pay each other!
Once that works, you realize it would be really neat to have group payments, where you can automatically split a dinner bill, for example. And then maybe you'll even want to kind of crowdfund your dinners, so that any of you can put up a request that says "please send me 5$ each until tomorrow at 4 and I'll order food." You can see this becoming more and more complex.
This is kind of the evolution of blockchain going from simple transactions towards arbitrary smart contracts.
A contract on Ethereum is basically just an address that's associated with a little script in a stack machine bytecode. When you send a message to such a contract, you're actually signing a transaction that says "I hereby perform the instructions of this contract with these given parameters."
For example, the bytecode of contract X might be:
VALUE 2 DIV DUP <address-1> SEND <address-2> SEND
(The SEND instruction doesn't actually exist; you'd use the CALL instruction, but it takes some parameters that would make the example less clear.)So this contract, when transacted with, would split the ETH value sent to it in half and send to "address 1" and "address 2".
The neat thing about this blockchain thing, compared to a Messenger-style central server, is that you can federate the service in a P2P way, so several of the friends can run a node that verifies all the history, and nobody needs to be trusted with an admin password that can change history.
The neat thing about having those smart contracts on the blockchain instead of as proprietary code is that each participant can (in principle) look at the contract's definition and know for sure what it does, and the contract can't be changed arbitrarily.
Let's think about your example and what it entails.
So you're going to a pizza party with your friends, and instead of saying to your buddy Mike who you're about to see in person and share some pizza with, "Hey Mike, here's 5 bucks, thanks!"
Instead you fire up the ol' ethereum whizbang machine, and "pay" Mike. The payment then rattles around the ol' globally distributed whizbang machine, at the SPEED of Light! powered by electricity through countless microscopic electronic gating mechanisms before finally settling into the storage media of thousands of computers around the world, where it will stay, forever.
That seems needlessly wasteful of resources and expensive.
What it boils down to, is what is this good for?
While some may have been, not everyone was confounded by the introduction of the web. Many could see obvious avenues of potential and development.
Even back in the 60s or 70s people were envisioning computer network enabled home shopping. Not sure many were envisioning a global distributed turing complete whatchamacallit with ever expanding resource needs because of no garbage collection by design.
So simply, what's the point? What do you do with it besides buy pizzas with your friends? How is it better than existing methods for doing whatever you envision doing with it?
What if anything, does it enable that would otherwise be impossible?
I mean, like, within three years you'll probably be having a virtual reality pizza party with your friends on the other side of the world. That's less wasteful of resources than flying, you know! And how will the money work? Maybe with a blockchain.
Let's try to stretch the imagination even more! Imagine you are involved with an open source project. You want to be able to receive some donations, collectively. So you briefly consider setting up a PayPal account, then giggle. "Ha-ha! Why would I use PayPal when these smart contract blockchains technologies have been working well for many years?"
So instead you go to one of the future's several competing smart contract platforms, and you click "Set up budgeted donation contract." It asks you to input the parameters for your donation contract. Maybe you end up configuring something like "Every week, this account's balance will be allocated as follows: 25% to GitHub; 50% split among these N core developers; 25% to the fund; and 25% to the EFF."
Your fans and users can then verify the behavior of this donation contract and easily contribute to your project! Wow! So much cooler than PayPal!
Assorted banking use cases, trade settlements, payments to notaries, voting systems, vehicle registrations, wire fees, gun checks, academic records, cataloging ownership of works of art.
The Ethereum alliance contains many big name companies such as Mastercard as Cisco [1]. They all believe there is real use in Ethereum
[0] http://www.goldmansachs.com/our-thinking/pages/macroeconomic...
Smart contracts fit really well for generally managing securities, developping auto hedging portfolios.
Hey, that was an example meant to explain difficult concepts through terms most people will be familiar with. You can't judge it like this.
Somewhat related, and maybe I'm revealing my stupidity here, but I wish someone explained securities to me in a simple way.
What about another use case that's also fairly mundane but is date/time triggered and has a slightly different result/outcome?
Say someone wants to use ethereum to manage the sending of a bunch of birthday cards to friends.
Is it possible for an ethereum script be set up to trigger an event on a specific day to send a pre-composed email along with some funds (e.g. bitcoin or ethereum).
So, for example, with crowdfund contracts that have an expiration time, you would typically just make it so that after the expiration time, if the crowdfund didn't succeed, then everyone can reclaim their funds. They aren't refunded automatically; you need some user action to trigger anything.
It would be possible to have a single "refundEveryone" method which would send all the funds to everyone when anyone called it. But if there were thousands of participants, this function would be expensive to call, and possibly even too expensive for the network's limits.
The standard solution to this limitation is that you just have to incentivize people to call your contract at the right time. So you can for example make it so that whoever is the first to call the contract after the deadline gets a reward. Then you publish that and hope someone will do it.
(A simpler solution is to just run a cronjob on your own computer...)
How big can be the parameters? Megabytes is possible?
The problem is trust. It's helpful to remember that all the participants in an Ethereum network are adversarial. It doesn't matter how many bad actors there are as long as >50% of participants agree on the outcome. (This is a simplified explanation -- the real system is transitioning to proof of stake rather than proof of work.)
If you allow solidity to access the internet or the system compilers, you can't guarantee determinism anymore. For example, if you increment a counter by the result of accessing https://some-value.com (which returns a JSON value), you could program it to return a different result for everyone who accesses it. None of the nodes would agree what the true value of the counter should be. It'd also result in a central point of failure.
These same problems exist if you let Solidity access the system software. You could program it to give different results, so no one would agree.
The innovation of Solidity is that it's a set of operations where no matter what you do, the majority of nodes will converge to the same answer.
Moreover, a point that was not made clear to me when I first read about Ethereum, the programs are inherently limited in the number of steps that can be run, and the VM monitors this and terminates the program prematurely if it exceeds the limit. Moreover, longer programs cost the caller (the person or other contract asking the network to run this program) more money.
If the connection to the third party service is cryptographically secure, the Oracle can even provide proof the results were not tampered with, and if multiple data sources are used it can provide a consensus answer based on them.
Otherwise, the smart contract only has access to what is in the blockchain, but Oracles are pretty easy to write and use.
So far a few states (US) have passed laws regarding "blockchains", "smart contracts" and the like. For example, seeking to avoid any legal uncertainty surrounding blockchain transactions and smart contracts relating to certain digital assets, Arizona passed HB 2417, the following on point:
- A very specific definition of “blockchain technology” as a “distributed, decentralized, shared and replicated ledger, which may be public or private, permissioned or permissionless, or driven by tokenized crypto economics or tokenless” and provides that the “data on the ledger is protected with cryptography, is immutable and auditable and provides an uncensored truth.”
-A definition of “smart contracts” as an “event driven program, with state, that runs on a distributed, decentralized, shared and replicated ledger that can take custody over and instruct transfer of assets on that ledger.”
Other states in various stages of legislation on point include: Maine, Illinois, Nevada, Delaware and Vermont.
interesting notes: Arizona also passed a seperate law restricting the use of blockchain as "fire arm tracking technology", likely a pro gun rights lobbying effort. Delaware will likely be codifying by statute the right to issue stock on blockchains. Courts have begun accepting blockchain entries as business records under the rules of evidence.
If you could program money, you might not really need insurers anymore. You could just program insuree's money so it redistributed appropriately in case of flooding (for eg). No need to give you money to an entity and have a conflict of interest with your insurer.
Smart contracts are ways to program money by sending it to special addresses. These addresses contain a script that will decide how to redistribute the money. It's like if you insurance was a program.
That's an interesting way to think about it, but how do you communicate to the program that a tree fell on your car and you need it to give you money for a new one?
Basically what's the mechanism for communicating certain cases or conditions to the program, how does the program verify the claims you make to it, and how many of the scenarios where that works are practical for any real world applications?
IMO Smart contracts are a good way to model and trade securities, options or futures instead, leaving the underlying assets to be managed by real world humans who can make things happen out of the blockchain.
The incentives could be set up such that the cost of being caught straying from protocol would be higher than the fraud opportunity.
Or you could just reply on network-of-trust. Brand loyalty, etc. Choose Aetna claim investigators! We Follow Protocol
https://steemit.com/ethereum/@decentralised/hello-world-revi...
Hope you enjoy the post. If you have any constructive criticism you'd like to give regarding either the post or the website, let me know!
Unless you're a seed user (first 1000 people who sign up), then you don't have to subscribe to view non-free posts.
https://github.com/Roxxik/ping_ether/blob/master/src/main.rs
Looking into ethereum related stuff I often get the feeling that one already needs to know half of ethereum quite decent to learn something new, which makes it hard to even get started.
Reading your guide (am not finished yet) gives me a better picture of the things I actually need to do, to start discovering some nodes, so I'm really thankful for that and hope for more beginner targeted ethereum content.
See "OWASP top 10" for getting started with web security.
I tried to signup but ended up with a 500 error.
Too bad.
Edit2: You should be able to log in now.
- [ ] add edit view
- [ ] add autosave
- [ ] add comments
- [ ] add subscribe button
Which includes a few trillion dollar industries.
[1] http://www.javamagazine.mozaicreader.com/JanFeb2017#&pageSet...
This caught my attention: "In the EndPoint specification, it demands the "BE encoded 4-byte" address, which is exactly what's outputted by self.address.packed."
Does this mean that Ethereum only supports IPv4?
I searched around and only found this, dating back to 2014: https://github.com/ethereum/wiki/wiki/IPv6
It seems that the user registration emails are causing a 500 server error and I'm working on a fix.
Edit: I'm bypassing the email confirmations for now, if you got a 500 error, please try to login using the account you signed up with. It should work, otherwise email me at mflynn210 <at> gmail.com.
Basically, there were a lot of blind spots in the official documentation and it took me a while to figure out things like how to make a proper key recovery id or which endianness to use where in the messages.
How far have you been able to get to? I still can't quite wedge into the mainnet - the nodes keep disconnecting me for unknown reasons some time after, and finding a new node to connect to takes a while.
My node does works rather well on the ropsten testnet, however.
Ah, I knew someone was going to get me on that. They actually give you the encode function in the specification. It's pretty straightforward and if I was to write it, would end up the same, so I decided to just import the library. But I agree it does go against the "from scratch" title a little bit.
> there were a lot of blind spots in the official documentation
Totally agree.
> How far have you been able to get to?
I'm actually trying to get the mainnet nodes to talk to me as well.
Bitcoin and Ethereum have very different intended use cases, as this article demonstrates. You could argue that Ethereum could be a threat to Bitcoin, or coexist, depending on your perspective.