first draft of blog post

This commit is contained in:
waalge 2023-08-07 21:02:15 +00:00
parent 9496deea93
commit dece937665
5 changed files with 59 additions and 39 deletions

View File

@ -9,3 +9,8 @@ build, serve and watch
```sh ```sh
cabal run site -- watch cabal run site -- watch
``` ```
deploy
```sh
rsync -r --delete ./_site/* genesis:/var/www/kompactio-landing/
```

View File

@ -22,22 +22,22 @@ This post is borne out of a best effort of how far "zk on Cardano" can be pushed
There is no shortage of explanations describing what zk is There is no shortage of explanations describing what zk is
( _eg_ [by Vitalik](https://vitalik.ca/general/2021/01/26/snarks.html) or [a full mooc](https://zk-learning.org/) ). ( _eg_ [by Vitalik](https://vitalik.ca/general/2021/01/26/snarks.html) or [a full mooc](https://zk-learning.org/) ).
There is also a reasonable breath to the field of zk that includes things like distributed compute. There is also a reasonable breath to the field of zk that includes things like distributed compute.
Zk involves some really neat maths that lets you do some seemingly magical feats, Zk involves some really neat maths that lets you do some seemingly magical feats
and pairs well with blockchain in extending what is functionally possible. and pairs well with blockchain in extending what is functionally possible.
Let's stick to a simple and prototypical example. Let's stick to a simple and prototypical example.
Suppose Alice and Bob are playing battleships. Suppose Alice and Bob are playing battleships.
The game begins with Alice and Bob placing their ships within their own coordinate grid. The game begins with Alice and Bob placing their ships within their own coordinate grid.
They then take in terms picking coordinates to "bomb". They then take in turns picking coordinates to "strike".
If they hit nothing, then their turn ends, but if they hit a ship then they guess again. If they hit nothing then their turn ends, but if they hit a ship then they strike again.
The winner is the first to sink all their opponent's ships. The winner is the first to strike all coordinates containing their opponent's ships.
Alice knows Bob has a reputation of being a notorious liar; how can she enjoy the game? Alice knows Bob as being a notorious liar; how can she enjoy the game?
Each guess she makes, Bob says gleefully shouts "Miss!". Each guess she makes, Bob gleefully shouts "Miss!".
She can't ask Bob to show he's not lying by revealing the actual locations of the ships. She can't ask Bob to show he's not lying by revealing the actual locations of the ships.
She could ask Charlie to independently verify Bob's not lying, She could ask Charlie to independently verify Bob's not lying,
but then what if Charlie is actually on team Bob and also lies. but then what if Charlie is actually on team Bob and also lies.
Or Bob might suspect Charlie is actually on team Alice, slyly brought in to give could Alice some hints. Or Bob might suspect Charlie is actually on team Alice, slyly brought in to give Alice some hints.
Is there a way that Bob can prove to Alice that each guess is a miss, Is there a way that Bob can prove to Alice that each guess is a miss,
but without revealing the locations of the ships either to Alice or anyone else? but without revealing the locations of the ships either to Alice or anyone else?
@ -48,62 +48,77 @@ Alice can inspect each proof and verify Bob's response.
Alice can interrogate the proof as much as she wants, but she won't learn anything more than Alice can interrogate the proof as much as she wants, but she won't learn anything more than
her guess was a miss. her guess was a miss.
There are multitude of different ways to do this, There are a multitude of different ways to do this,
but essentially it involves modeling the problem as a bunch of algebra but essentially it involves modeling the problem as a bunch of algebra
over finite fields - like a lot of cryptography. over finite fields - like a lot of cryptography.
What's the snark of zk-snark? What's the _snark_ of zk-snark?
Snark stands for _Succinct Non-Interactive Argument of Knowledge_. Snark stands for _Succinct Non-Interactive Argument of Knowledge_.
And without saying anything more: it means that Alice has to do way less algebra than Bob. And without saying anything more, it means that Alice has to do way less algebra than Bob.
In applications this is important, because Bob might not be able to lie anymore, In applications this is important because Bob might not be able to lie anymore but he could still waste Alice's time.
but he could still waste Alice's time.
## Sudoku snark ## Sudoku snark
Sudoku snark was the entrant to Emurgo hackathon. Sudoku snark was the entrant to Emurgo's hackathon.
The summary/ pitch/ story deck is [here](https://pub.kompact.io/sudoku-snark). The summary-pitch-story deck is [here](https://pub.kompact.io/sudoku-snark).
Links to associated repos [plutus-zk](https://github.com/waalge/plutus-zk) and [sudoku-snark](https://github.com/waalge/sudoku-snark). Links to the associated repos: [plutus-zk](https://github.com/waalge/plutus-zk) and [sudoku-snark](https://github.com/waalge/sudoku-snark).
Just after the hackathon got underway there was a large PR merged into the main branch of plutus. Just after the hackathon got underway there was a [large PR merged](https://github.com/input-output-hk/plutus/pull/5231)
It's a mammoth PR that is the culmination of many many months of work. into the main branch of plutus.
In it were some fundamental primitives needed for running zk algos. It's a mammoth culmination of many many months of work.
In it were some fundamental primitives needed for running zk algorithms.
The idea of the project was as follows: The idea of the project was as follows:
- write a validator implementing a zk algorithm with the new primitives - write a validator implementing a zk algorithm with the new primitives
- write a program to generate the setup and proofs - write a program to generate the setup and proofs
- try to get a version of hydra running this newest version of plutus. - try to get a version of hydra running this newest version of plutus
- wrap up in a gui
Unsurprisingly to anyone who's hung around the Cardano repos long enough, Unsurprisingly to anyone who's hung around the Cardano ecosystem long enough,
this final part is where things got stuck. this third part is where things got stuck.
Things got as far as running a cluster of nodes in the Conway era supposedly with the latest plutus We did get as far as running a cluster of nodes in the Conway era with the latest version of plutus
but some unrelated changes seemed to thwart any chance of building transactions. but unrelated changes seemed to thwart any chance of building transactions here.
The validator uses [groth16](https://eprint.iacr.org/2016/260.pdf). A quick shout-out to the [modulo-p.io](https://modulo-p.io/) team.
They had a different approach and managed to implement a zk algorithm with the existing plutus primitives.
This spared the need to play the foolhardy dependency bumping game with the Cardano node.
However, because zk is so arithmetically intense,
the app wont run outside a hydra head and with very generous max unit budgets (afaics).
This approach won't be necessary when we have the new version of plutus available.
Nonetheless, it's very neat to see it done and they packaged it very nicely.
The validator in Sudoku snark uses [groth16](https://eprint.iacr.org/2016/260.pdf).
In part because this was already mostly available from the plutus repo itself. In part because this was already mostly available from the plutus repo itself.
It is also the most obvious candidate to begin with. It is also the most obvious candidate to begin with.
It's relatively mature, relatively simple, can be implemented from the new primitives, It's relatively mature, relatively simple, can be implemented from the new primitives,
and, importantly in Cardano land, has small proof size. and, importantly in Cardano land, has small proof size.
(As far as I know, the smallest of comparable algos.) (As far as I know, the smallest of comparable algorithms.)
The program to generate the setup and proofs uses the arkworks framework. The program to generate the setup and proofs uses the Arkworks framework.
Again this was initially inspired by a script from the IOG team. Again this choice was initially inspired by a script from the IOG team,
but again it seems like a smart choice.
Arkworks is a well conceived, highly modular framework for zk,
which makes it easy to pull in the bits we need to perform our off-chain logic.
The choice of game, sudoku, was in turn inspired by an arkworks example. The choice of game, sudoku, was in turn inspired by an arkworks example.
It's not the most compelling of choices, but it did for now. It's not the most compelling of choices, but it's simple and it did for now.
Battleships would have been more compelling or mastermind as the modulo-p team used.
The intended game play involved locking Ada at a utxo The intended game play involved locking Ada at a utxo correspondinig to a sudoku puzzle,
spendable only if a player could provide proof you knew the solution. and spendable only if a player could provide proof they knew the solution.
And through the magic of zk, not disclosing to the competition the solution itself. Through the magic of zk they'd not disclose to the other competitors the solution itself.
Other details were TBC: is it first and second prizes? are players whitelisted? Other details were TBC: is it first and second prizes? are players whitelisted? _etc_.
## So are we zk-Cardano yet? ## So are we zk-Cardano yet?
We're close. We're close.
There is potentially still quite a stretch between being in the plutus repo and being run on-chain. There is potentially still quite a while before these new primitives in plutus reach mainnet.
The word on the street is that it might happen before the end of 2023. The word on the street is that it might happen before the end of 2023.
Before it's available on mainnet there will be versions the Cardano node available, Even sooner, there will be versions of the Cardano node available with the new primitives,
and so possibly plumb-able into hydra without causing oneself an aneurysm. and so possibly plumb-able into hydra without causing oneself an aneurysm.
In development time that's not so long: we can start thinking about what to build with zk on Cardano.

View File

@ -6,11 +6,11 @@
"systems": "systems" "systems": "systems"
}, },
"locked": { "locked": {
"lastModified": 1683635384, "lastModified": 1688380630,
"narHash": "sha256-9goJTd05yOyD/McaMqZ4BUB8JW+mZMnZQJZ7VQ6C/Lw=", "narHash": "sha256-8ilApWVb1mAi4439zS3iFeIT0ODlbrifm/fegWwgHjA=",
"owner": "numtide", "owner": "numtide",
"repo": "devshell", "repo": "devshell",
"rev": "5143ea68647c4cf5227e4ad2100db6671fc4c369", "rev": "f9238ec3d75cefbb2b42a44948c4e8fb1ae9a205",
"type": "github" "type": "github"
}, },
"original": { "original": {

View File

@ -63,6 +63,7 @@
programs.prettier.enable = true; programs.prettier.enable = true;
}; };
# Equivalent to inputs'.nixpkgs.legacyPackages.hello; # Equivalent to inputs'.nixpkgs.legacyPackages.hello;
devShells.default = pkgs.mkShell { devShells.default = pkgs.mkShell {
inputsFrom = [ inputsFrom = [

View File

@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/x-icon" href="/favicon.png"> <link rel="icon" type="image/x-icon" href="/favicon.png">
<link href="/css/mini.css" rel="stylesheet"> <link href="/css/mini.css" rel="stylesheet">
<title>$title$</title>
</head> </head>
<body> <body>
@ -18,7 +18,6 @@
<hr /> <hr />
$partial("templates/footer.html")$ $partial("templates/footer.html")$
</div> </div>
</body> </body>
</html> </html>