Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(content-details) #41

Merged
merged 3 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/nextjs/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const Header = () => {
<li>
<NavLink href="/age-restricted-example">
<span className="h-4 w-4">🎈</span>
Age restriction with ZK
ZK Age Restriction
</NavLink>
</li>
<li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ export const AgeRestrictedContractExecutor = () => {
<div>
<h1 className="text-3xl font-bold">Step 3: Getting the balloon🎈 NFT</h1>
<p>
The ballon store is using the same <CodeText text="TokenVendor.sol" /> contract as the{" "}
The <strong>Ballon Store</strong> is using the same <CodeText text="TokenVendor.sol" /> contract as the{" "}
<a className="link" href="https://speedrunethereum.com/challenge/token-vendor">
Speedrun Ethereum challange
</a>
, with some additions. They&apos;ve added a function <CodeText text="getFreeToken" />, with the{" "}
<CodeText text="onlyKids" />
-modifier. This implementation can be found in{" "}
-modifier. In this project, the implementation can be found in{" "}
<a href="https://github.com/Kryha/scaffold-eth-2-noir/blob/main/packages/hardhat/contracts/BalloonVendor.sol">
<CodeText text="packages/hardhat/contracts/BalloonVendor.sol" />
</a>{" "}
in our project.
<br />
</a>
</p>
<p>
The modifier constructs the public inputs and calls the proof-verifier in (
<a href="https://github.com/Kryha/scaffold-eth-2-noir/blob/main/packages/hardhat/contracts/verifiers/LessThanSignedAge.sol">
<CodeText text="packages/hardhat/contracts/verifiers/LessThanSignedAge.sol" />
Expand All @@ -40,8 +40,8 @@ export const AgeRestrictedContractExecutor = () => {
what we are actually proving.
</p>
<p>
Now that Alice has received a balloon <strong>token</strong>, she can redeem that digital token at the store
to get the actual ballloon.
Now that <strong>Alice</strong> has received a balloon <strong>token</strong>, she can redeem that digital
token at the store to get the actual balloon.
</p>
</div>
<div>
Expand Down
22 changes: 10 additions & 12 deletions packages/nextjs/pages/age-restricted-example/BirthDateSignature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ export const BirthDateSignature = ({ aliceDefaultAge }: { aliceDefaultAge: numbe
return (
<div className="grid grid-cols-2 gap-6 max-w-7xl">
<div>
<h1 className="text-3xl font-bold">Step 1: Town Hall 🏛 generates the signature 📜</h1>
<h1 className="text-3xl font-bold">Step 1: Town Hall 🏛 signs 📜 the birth date</h1>
<p>
Alice recognizes that, in order for her to not have to share her age with the balloon store, she at least has
to share her age with a trusted third party. In this case, the balloon store has selected the Town Hall to be
the trusted third party🏛. Alice accepts the fact that she has to share her age with the Town Hall.
<strong>Alice</strong> and the <strong>Balloon Store</strong> need to agree on who to trust in order to
certify Alice age. In this example the <strong>Town Hall</strong> acts as a trusted third party, but on a
ramidecodes marked this conversation as resolved.
Show resolved Hide resolved
different scheme the certifying entity could be completely different. The only requirement is that both Alice
ramidecodes marked this conversation as resolved.
Show resolved Hide resolved
& the Ballon Store trust the signature (certification) provided by this third party.
</p>
<p>
When the balloon store implemented their zero knowledge proof solution they made sure that they are using the
same format as the Town Hall for constructing the claim that is being signed. In this project the claim
construction for the Town Hall can be found in{" "}
The Ballon Store has previously decide to use the same claim format as the Town Hall, to facilitate the zk
ramidecodes marked this conversation as resolved.
Show resolved Hide resolved
proof verification on a later step. You can find the construction of this claim here:{" "}
<a href="https://github.com/Kryha/scaffold-eth-2-noir/blob/main/packages/nextjs/pages/age-restricted-example/BirthDateSignature.tsx">
<CodeText text="packages/nextjs/pages/age-restricted-example/BirthDateSignature.tsx" />
</a>{" "}
Expand All @@ -82,11 +82,9 @@ export const BirthDateSignature = ({ aliceDefaultAge }: { aliceDefaultAge: numbe
).
</p>
<p>
What the Town Hall actually signs is that they confirm that Alice is born in a certain year AND that she has
control over a certain Ethereum address. The check of Alice&apos;s Ethereum address is not done in this
example. The code for producing the signature currently includes the Town Hall&apos;s hardcoded private key.
This can be improved in many ways, but at a minimum it should be the Towna Hall eployee that provides it to
the UI.
Using it&apos;s <strong>private key</strong>, the <strong>Town Hall</strong> is actually signing the
confirmation that <strong>Alice</strong> was born in a given year <strong>AND</strong> that she has control
over certain Ethereum <strong>address</strong>.
</p>
</div>
<div>
Expand Down
50 changes: 34 additions & 16 deletions packages/nextjs/pages/age-restricted-example/GenerateProof.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,38 +94,52 @@ export const GenerateProof = ({ requiredBirthYear }: { requiredBirthYear: number
<div>
<h1 className="text-3xl font-bold">Step 2: Generating the proof ✅</h1>
<p>
One of the reasons that Alice knows that she is not sharing her birth year with anyone is that the proof
generation is open source, and she herself can double check the code. Furthermore she can even generate the
proof herself locally. This is actually what we are doing in this implementation.
In order for <strong>Alice</strong> to really know that she&apos;s not sharing any private information with
the <strong>Ballon Store</strong> two things should be possible:
<ol>
<li>
1. The code that generates the the proof should be <strong>open source</strong> for Alice to review
</li>
<li>
2. The proof generation should happen in an environment trusted by<strong>Alice</strong> (ex: locally in
her laptop or phone)
</li>
</ol>
</p>
<p>
The circuit is located in{" "}
A circuit written in <strong>Noir</strong> is used for generating the proof and for generating a
Solidity-verifier. The <strong>Ballon Store</strong> will use the proof as input to execute the verifier
ramidecodes marked this conversation as resolved.
Show resolved Hide resolved
contract on-chain:{" "}
<a href="https://github.com/Kryha/scaffold-eth-2-noir/blob/main/packages/noir/circuits/LessThanSignedAge/src/main.nr">
<CodeText text="packages/noir/circuits/LessThanSignedAge/src/main.nr" />
</a>
. It&apos;s written using Noir. It is the Noir-circuit that is used both for generating the proof and for
generating a Solidity-verifier that can help the balloon store verify the proof on-chain.
</p>
<p>
The proof is generated in the browser from the file{" "}
The proof is generated in the browser using the following libraries:
<ul>
<li>
* <CodeText text="aztec/bb.js" />
ramidecodes marked this conversation as resolved.
Show resolved Hide resolved
</li>
<li>
* <CodeText text="noir-lang/acvm_js" />
ramidecodes marked this conversation as resolved.
Show resolved Hide resolved
</li>
</ul>
Check the implementation here:{" "}
ramidecodes marked this conversation as resolved.
Show resolved Hide resolved
<a href="https://github.com/Kryha/scaffold-eth-2-noir/blob/main/packages/nextjs/utils/noir/noirBrowser.ts">
<CodeText text="packages/nextjs/utils/noir/noirBrowser.ts" />
</a>
. In this file you can see that the proof is generated by using the imported libraries{" "}
<CodeText text="aztec/bb.js" /> and <CodeText text="noir-lang/acvm_js" />. The proof can also be generated
locally, by calling <CodeText text="nargo prove" />. The predefined circuit ABI code used to generate the
proof can be found in{" "}
</p>
<p>
The proof can also be generated locally (outside of a browser), by calling <CodeText text="nargo prove" />.
ramidecodes marked this conversation as resolved.
Show resolved Hide resolved
</p>
<p>
The predefined circuit ABI code used to generate the proof can be found in{" "}
<a href="https://github.com/Kryha/scaffold-eth-2-noir/blob/main/packages/nextjs/generated/circuits.json">
<CodeText text="packages/nextjs/generated/circuits.json" />
</a>
, but we could recompile it using <CodeText text="nargo compile" />. <CodeText text="nargo" /> is the CLI-tool
ramidecodes marked this conversation as resolved.
Show resolved Hide resolved
for Noir.
ramidecodes marked this conversation as resolved.
Show resolved Hide resolved
</p>
<br />
<p>
*Note that the &quot;signed age&quot; and &quot;ethereum address&quot;, must be the same as the ones you used
to generate the signed message.
</p>
</div>
<div>
<div className="card w-full shadow-2xl bg-base-100">
Expand Down Expand Up @@ -200,6 +214,10 @@ export const GenerateProof = ({ requiredBirthYear }: { requiredBirthYear: number
</div>
</div>
</div>
<p>
* Note that the &quot;signed age&quot; and &quot;ethereum address&quot;, must be the same as the ones you used
to generate the signed message.
</p>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const ZkStepsIntro = ({ setCurrentStep, yearTenYearsAgo }: ZkStepsIntroPr
<div className="hero-content text-center">
<div className="max-w-3xl">
<div className="flex flex-col justify-center items-center">
<h1 className="text-5xl font-bold">Hello there</h1>
<h1 className="text-5xl font-bold">ZK Age Restriction</h1>
<p className="py-6">
Alice has heard that balloon store in town is handing out balloons🎈 to anyone who is 10 years old or
younger. However, Alice does not want to share her age with anyone. Lucky for her, the balloon store has a
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/pages/age-restricted-example/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const ExampleZk: NextPage = () => {
return (
<>
<MetaHeader
title="Example UI ZK | Scaffold-ETH 2"
title="ZK Age Restriction| Scaffold-ETH 2 Noir"
description="Example UI ZK, showing how to use ZK circuits in your UI."
></MetaHeader>
<div className="min-h-screen flex items-center flex-col pt-6 lg:pt-20">
Expand Down
Loading