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

small fixes to code and FE text #21

Merged
merged 1 commit into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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 README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Scaffold-ETH Noir

Sandbox project for testing age-restricted contracts using [Noir](https://noir-lang.org/) for writing ZKP-circuits. Also has *basic* dynamic UI for expirimenting with circuits and proof-generation. This was built using Scaffold-ETH 2, [refer to SE2 README for set-up](https://github.com/scaffold-eth/scaffold-eth-2#readme).
Sandbox project for testing age-restricted contracts using [Noir](https://noir-lang.org/) for writing ZKP-circuits. Also has *basic* dynamic UI for experimenting with circuits and proof-generation. This was built using Scaffold-ETH 2, [refer to SE2 README for set-up](https://github.com/scaffold-eth/scaffold-eth-2#readme).

* requires [nargo](https://noir-lang.org/dev/getting_started/nargo_installation) (tested with v0.10.1)

Expand Down
8 changes: 4 additions & 4 deletions packages/hardhat/contracts/BalloonVendor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ contract BalloonVendor is Ownable {
uint256 public tokensPerEth = 100;
uint16 public earliestBirthYear = 2013;
// TODO: better solution for "trusted authorities"
bytes32 public mayorsPublicKeyX = hex"ba5734d8f7091719471e7f7ed6b9df170dc70cc661ca05e688601ad984f068b0";
bytes32 public mayorsPublicKeyY = hex"d67351e5f06073092499336ab0839ef8a521afd334e53807205fa2f08eec74f4";
bytes32 public thirdPartyPublicKeyX = hex"ba5734d8f7091719471e7f7ed6b9df170dc70cc661ca05e688601ad984f068b0";
bytes32 public thirdPartyPublicKeyY = hex"d67351e5f06073092499336ab0839ef8a521afd334e53807205fa2f08eec74f4";

event BuyTokens(address buyer, uint256 amountOfETH, uint256 amountOfTokens);
event SellTokens(address seller, uint256 amountOfTokens, uint256 amountOfETH);
Expand Down Expand Up @@ -41,8 +41,8 @@ contract BalloonVendor is Ownable {
modifier onlyKids(bytes calldata proof) {
bytes32[] memory publicInputs = new bytes32[](85);
publicInputs[0] = bytes32(uint256(earliestBirthYear));
publicInputs = preparePublicInputs(publicInputs, mayorsPublicKeyX, 1, 32);
publicInputs = preparePublicInputs(publicInputs, mayorsPublicKeyY, 33, 32);
publicInputs = preparePublicInputs(publicInputs, thirdPartyPublicKeyX, 1, 32);
publicInputs = preparePublicInputs(publicInputs, thirdPartyPublicKeyY, 33, 32);
publicInputs = preparePublicInputs(publicInputs, bytes32(uint256(uint160(msg.sender))), 65, 20);
require(ageVerifier.verify(proof, publicInputs));
_;
Expand Down
52 changes: 26 additions & 26 deletions packages/nextjs/generated/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,32 +455,6 @@ const contracts = {
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "mayorsPublicKeyX",
outputs: [
{
internalType: "bytes32",
name: "",
type: "bytes32",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "mayorsPublicKeyY",
outputs: [
{
internalType: "bytes32",
name: "",
type: "bytes32",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "owner",
Expand Down Expand Up @@ -527,6 +501,32 @@ const contracts = {
stateMutability: "nonpayable",
type: "function",
},
{
inputs: [],
name: "thirdPartyPublicKeyX",
outputs: [
{
internalType: "bytes32",
name: "",
type: "bytes32",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "thirdPartyPublicKeyY",
outputs: [
{
internalType: "bytes32",
name: "",
type: "bytes32",
},
],
stateMutability: "view",
type: "function",
},
{
inputs: [],
name: "tokensPerEth",
Expand Down
11 changes: 5 additions & 6 deletions packages/nextjs/pages/example-zk/BirthDateSignature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,11 @@ export const BirthDateSignature = ({ aliceDefaultAge }: { aliceDefaultAge: numbe
</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📜.
TTODOTODOTODOTODOTODOTODOTODOTODOTODOODO! In this project the claim construction can be found in{" "}
<CodeText text="packages/nextjs/pages/example-zk/BirthDateSignature.tsx" /> (<CodeText text="signBirthYear" />
) and <CodeText text="packages/noir/circuits/LessThanSignedAge/src/main.nr" /> (
<CodeText text="construct_claim_payload" />
).
same format as the Town Hall for constructing the claim that is being signed📜. In this project the claim
construction can be found in <CodeText text="packages/nextjs/pages/example-zk/BirthDateSignature.tsx" /> (
<CodeText text="signBirthYear" />
) in the FrontEnd and <CodeText text="packages/noir/circuits/LessThanSignedAge/src/main.nr" /> (
<CodeText text="construct_claim_payload" />) when implemented as a Noir circuit.
</p>
<p>
What the Town Hall actually signs is that they confirm that Alice is born on a certain year AND that she has
Expand Down
16 changes: 6 additions & 10 deletions packages/nextjs/pages/example-zk/GenerateProof.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,12 @@ export const GenerateProof = ({ requiredBirthYear }: { requiredBirthYear: number
proof✅ herself locally. This is actually what we are doing in this implementation.
</p>
<p>
TTODOTODOTODOTODOTODO - are these paths correct? - TODOTODOTODOTODOODO! In{" "}
<CodeText text="packages/nextjs/utils/noir/noirBrowser.ts" /> you can see that we are importing from{" "}
<CodeText text="aztec/bb.js" /> and <CodeText text="noir-lang/acvm_js" />, but we could also generate this
proof with{" "}
<CodeText
text="nargo
prove"
/>
. We are also using the predefined circuit-ABI byte code from{" "}
<CodeText text="packages/nextjs/generated/circuits.json" />, but we could re-compile it using{" "}
The proof is generated in the browser in the file{" "}
<CodeText text="packages/nextjs/utils/noir/noirBrowser.ts" />. In this file you can see that the proof is
generated by importing the <CodeText text="aztec/bb.js" /> and <CodeText text="noir-lang/acvm_js" />{" "}
libraries. The proof can also be generated locally, with calling <CodeText text="nargo prove" />. The
predefined circuit ABI code used to generate the proof can be found in{" "}
<CodeText text="packages/nextjs/generated/circuits.json" />, but we could recompile it using{" "}
<CodeText text="nargo compile" />.
</p>
<p>
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/pages/example-zk/ZkStepsIntro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const ZkStepsIntro = ({ setCurrentStep, yearTenYearsAgo }: ZkStepsIntroPr
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
zero knowledge proof solution. This means she can claim her balloon🎈 and only share as little information
as necessary publicly. Here is how she would go about...
as necessary publicly. Here is how she would go about it...
<br />
</p>
<ol className="list-decimal list-inside text-left">
Expand Down
Loading