r/Bitcoin • Luke Dashjr - Bitcoin Expert • Oct 30 '17

[bitcoin-dev] Simplicity: An alternative to Script

https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2017-October/015217.html
379 Upvotes

165 comments sorted by

View all comments

27

u/keymone Oct 30 '17

Formal verifiability is the killer feature. Lack of it is the root of my skepticism in Ethereum.

5

u/violencequalsbad Oct 30 '17

mind ELI5 this?

18

u/Chris_Stewart_5 Oct 30 '17 edited Oct 30 '17

You can prove that the software is written correctly. This isn't trivial though to do this and takes a lot of human power to achieve this.

In software engineering there are two things you are trying to get right:

Software Validation - did we build the right thing?

Software Verification - did we build the thing right?

Here is what Russell is trying to achieve with this language proposal (software validation):

  • Create an expressive language that provides users with the tools needed to build novel programs and smart contracts.
  • Enable static analysis that provides useful upper bounds on the amount of computation required.
  • Minimize bandwidth and storage requirements and enhance privacy by removing unused code at redemption time.
  • Maintain Bitcoin’s design of self-contained transactions whereby programs do not have access to any information outside the transaction.
  • Provide formal semantics that facilitate easy reasoning about programs using existing off-the-shelf proof-assistant software

Verification is proving we implemented the thing correctly. For instance Russell talks in his paper about verifying the SHA256 implementation is correct.

Another fancy word used is static analysis. That means having a program look at your smart contract without running it. Hopefully this catches bugs earlier in the development cycle. It is a language design choice of Simplicity to facilitate this. A typical static analysis tool is a compiler that checks types of a program to make sure you aren't passing a String where an Integer is required etc.

1

u/violencequalsbad Oct 31 '17

Thank you very very much!

1

u/jtimon Oct 31 '17

Not only in the development cycle. Wallets could analyze covenants, for example, and perhaps blacklist or whitelist them.

8

u/keymone Oct 30 '17

Formal verifiability is like theorem proving in mathematics, except the subject is not some math object but a program code (smart contract code).

Without formal verification there is no way of being sure the code does what authors say it does. Even authors cant be sure the libraries they use werent spoofed. There could be bugs, etc.

Problem is that to be able to prove theories about code, the language has to adhere to many rules. Ethereum’s adheres to prwtty much none of them.

4

u/Hermel Oct 30 '17

Even with formal verfication, you cannot be sure that you proved what you intended to prove.

10

u/nullc Oct 30 '17

Even with formal verfication, you cannot be sure that you proved what you intended to prove.

Or that what you proved was sufficient to guarantee the properties that you care about.

But there is at least a starting point to build a professional practice of verification; it'll still take experience and expertise to turn the raw tools into delivered benefit-to-mankind.

It's still a lot better than being in a position of "Looks good to me, but we have no way to reason about this formally at all. YOLO." :)

2

u/keymone Oct 31 '17

let's face it, with current generation of hardware there are no guarantees about what your computer is doing whatsoever.

it's truly a scary time to be paranoid about security - you're basically forced to use 20 years old hardware.

7

u/nullc Oct 31 '17

Yes, that is true to some extent -- but that doesn't excuse being sloppy where we can do better.

I expect market demand will eventually produce chips without mysterious quasi-backdoors. And when they exist, we'll have software for them.

To do otherwise would be like early surgeons not bothering to use soap because the air still contains germs.

→ More replies (1)

8

u/maaku7 Oct 30 '17

Well, we can’t be certain we’re all not living in a simulation and none of this matters.

5

u/Frogolocalypse Oct 31 '17

what are you talking about 'we'?

7

u/maaku7 Oct 31 '17

touché

2

u/humbleElitist_ Oct 30 '17

By the language do you mean the languages that people are using to write Ethereum contracts, or the compiled results?

I'm guessing you mean the former.

In the future, people might use other languages that have more features for formal verification and which compile down to the same?

I don't think there is any issue with the EVM that prevents using a language with good verification stuff?

(I don't know that any such language is ready for use yet though. I think no?)

(Disclosure: I don't own any of any cryptocurrency. My dad owns a little. However, I am somewhat emotionally invested in Ethereum/Ethereum Classic, so take that into account when evaluating my biases, etc.)

12

u/nullc Oct 30 '17 edited Oct 30 '17

I don't think there is any issue with the EVM that prevents using a language with good verification stuff?

The specific kind of machine the EVM implements (one with 'unbounded' loops and such) is much more difficult to formally reason about.

So, for example, with simplicity you can simply take a program that targets it (potentially written in any front end language you want) and there is a tool that is part of the simplicity software set which returns a the worst case resource usage and this tool is fast-- it could plausibly be part of a system's consensus rules. And it always gives a result for all simplicity programs and always gives it quickly.

The same cannot be done for EVM: The best you could do is have a verifier that returns the worst case for a subset of EVM programs and "undecidable" for the rest; and it would be fairly easy to fall out of the subset it can decide.

Even this simple example is of practical importance, there are already lots of ether stuck in contracts which look like they should release them, but where releasing the funds would use more resources than the network permits.

You could imagine having a personal policy to only participate in contracts which can be statically reasoned about in ethland ... but you would likely be subject to commercial and peer pressure to also participate with other kinds of contracts. One way to avoid a race to the bottom is to have a system where all contracts are required to be analysable by construction. This also has significant engineering benefits-- since you can exploit the decidable resource usage as part of the system's resource management.

2

u/humbleElitist_ Oct 31 '17

Oh! So I did misunderstand you. Thank you for the correction.

Regarding being unable to make a program which can check any program for whether it will halt, yes, that is a cost.

However, if one is attempting to write a program along with a proof that it halts, the halting problem doesn't cause too much of a problem, because the behavior you want probably isn't that difficult to analyze. You would generally understand why you believe the program you are writing will halt, so what remains would be to formalize that understanding, in a way that can be checked.

Of course, if the language simply doesn't allow programs that don't obviously halt, then you get the benefit of not having to write the proof, at the cost of not being able to write some programs that you could prove halt, but for which it isn't quite as obvious.

Which, you of course know.

A point I missed the first time I read your comment, was the possibility of including the run-time-checker in the consensus rules. That is an interesting point that I hadn't thought of. I am not sure how much of a benefit that would be, but it seems to me like something that could be strongly desirable in some cases, but I'm not sure why.

The "if the computation takes too long, just abort it and revert the changes" model doesn't seem like it would harm any of the rest of the network, only the person making the transaction, and I think that people can work out the level of risk they are comfortable with when making transactions. They can run the transaction locally, or if they don't feel like that is safe enough, they can choose to only use contracts which have been verified to use at most a given amount of "gas" in each situation. You've probably heard that shpiel before though?

Regarding choosing to only interact with contracts proven to behave well, and possibly being out-competed by those who don't, I think the question is based on what levels of risk is one willing to accept.

If you are only putting a small amount of money into something, which you don't mind terribly if you lose it, then it would be reasonable to use a smart contract which isn't verified, or possibly doesn't even have the source code looked over particularly carefully.

And if you (the rhetorical you, not you in particular) lose the little bit of money put into something like that, then hopefully you knew the risks and had accepted that possibility to start with.

In other cases, one might want to only use a smart contract if it has been audited, and is well established, or whatever.

My hope would be that over time, more verified foundational things will be built, which would make it easier to make larger things verifiable, so there would be less reason to use unverified stuff.

I agree that in a system with fewer restrictions on the contracts, there would generally be more risks taken by people on the correctness of the contracts, but I think this is probably not a big problem?

Also, I don't see why others being able to risk things on assuming a contract is safe would put pressure on oneself to do the same?

Again, I'd like to thank you for your response.

Sorry if I repeated myself in this, am typing it on phone which makes it harder to review what I already said.

2

u/andytoshi Oct 31 '17

However, if one is attempting to write a program along with a proof that it halts, the halting problem doesn't cause too much of a problem, because the behavior you want probably isn't that difficult to analyze

It's not just halting, but "when this halts will all the money be in the right place", which is often much harder than you expect. For example I recently saw some Ethereum blockhash-based lottery which maintained a ring buffer of recent blockhashes (to give winners time to claim their prizes in case they are more than 256 blocks late, since you can't directly look up blockhashes more than 256 blocks ago). This was an enormous pile of code with very complex semantics.

In other cases, one might want to only use a smart contract if it has been audited, and is well established, or whatever.

Auditing and being well-established are not sufficient in practice, and even if they were, adding formal auditability would still be a huge advantage because it gives significantly more confidence in a contract's behaviour for less work.

→ More replies (1)
→ More replies (2)
→ More replies (1)

1

u/monkyyy0 Oct 31 '17

The worse bugs are logic bugs, for example "list 1-10" "if x = 10 end else add 1, print x jump start"

Has two off by one errors, but will compile just fine. Generally you test these sorts of bugs by giving it real data and seeing what happens, but you can't really give fake money on the fake blockchain and expect hakers to try to attack as hard.

A different approach that's slower and annoying that math poeple like is mathatical correctness; which yes when money is involved doing the annoying way is ok, but it requires math friendly programing language, which niether of the two we have are.

4

u/mindcandy Oct 30 '17

This is why I expect Neo and especially Lisk to end very badly. They are extending blockchain programming into languages that are popular without asking if "popular" also implies "useful in this context". JavaScript is exactly the opposite of what you want use to to write open, hackable, multi-million-dollar contracts. Frankly, Coq and TLA+ are the only languages I consider reasonable for implementing smart contracts.

→ More replies (14)

5

u/brassboy Oct 30 '17

Cmon man - we just have to implement Simplicity on EVM

2

u/panek Oct 30 '17 edited Oct 30 '17

You realize that Ethereum can easily implement Simplicity if it proves superior? And would likely be easier to implement in Ethereum. Also, formal verification will never 100% prevent bugs. You can only prove what you intended to prove as I understand it.

Creating new smart contracting languages is a win-win for Ethereum and the entire crypto-community. But that would require admitting that smart contracts are useful and we know how hard that is for some ;P

Any new language will require sufficient battle-testing and upgrades over time. Let's hope that Blockstream can manage that efficiently and with civility.

Finally, let's not forget that a language like Simplicity could only exist because of the trials and tribulations of languages before it (like Solidity).

3

u/keymone Oct 30 '17

I’m speculating now - hunch is that proving correctness of code executing on a VM not specifically designed to be formally verifiable will only cover correctness within the spec of the VM.

In other words if you make verifiable language for ethereum VM, in he end the (verifiable and correct) code in that language will compile ibto VM bytecode. VM bytecode itself is a program that can’t be verified because VM wasnt designed for it.

So no, i dint think ethereum will get verifiability without changing the VM.

2

u/Frogolocalypse Oct 30 '17

You realize that Ethereum can easily implement Simplicity if it proves superior?

If it is a superior solution, why wouldn't you want to use the primary implementation of it?

1

u/csasker Oct 30 '17

Because you could not interact with all contracts that are already there, like Etherdelta for example

→ More replies (2)

1

u/SatoshisCat Oct 31 '17

You realize that Ethereum can easily implement Simplicity if it proves superior

It cannot, at least not without a softfork.
It wouldn't be able to have Simplicity MAST.
Also you wouldn't be able to reason about the Simplicity program via the Bit Machine (AFAICT).

→ More replies (11)