From b4b0552e857b09feed7835f2d6f5282156ef55cd Mon Sep 17 00:00:00 2001 From: Elo <104064497+Metachaser24@users.noreply.github.com> Date: Tue, 12 Mar 2024 21:49:27 +0300 Subject: [PATCH 1/8] add simplification flags to usage guide --- docs/zk-email-docs/UsageGuide/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/zk-email-docs/UsageGuide/README.md b/docs/zk-email-docs/UsageGuide/README.md index 6858c0764..4c7a366cc 100644 --- a/docs/zk-email-docs/UsageGuide/README.md +++ b/docs/zk-email-docs/UsageGuide/README.md @@ -106,10 +106,12 @@ To compile the circuit locally, you need to have Rust and Circom installed first ```bash -circom MyCircuit.circom -o --r1cs --wasm --sym --c +circom MyCircuit.circom -o --r1cs --wasm --sym --c --O0 ``` *Note: You can add `-l` to specify the directory where the directive `include` should look for the circuits indicated. For our repo, use `circom -l node_modules` instead of `circom`. Additionally, we generally recommend using the `--O0` flag for optimization during compilation for beginners. However, if you're more experienced with Circom, feel free to use the `--O1` flag instead. It's important to avoid using the `--O2` flag as that is the default setting and it may lead to the deletion of additional constraints.* +We generally recommend using the --O0 flag, but if you're more experienced with circom feel free to use --O1 instead. + After running this command, the circuit will be compiled into a `.r1cs` file, a `.wasm` file, and a `.sym` file. These files are used in the next steps to generate the proving and verifying keys, and to compute the witness. From 9c508ff820b1c036a46ecc66be033593204a586b Mon Sep 17 00:00:00 2001 From: Divide-By-0 Date: Mon, 1 Apr 2024 15:45:09 -0700 Subject: [PATCH 2/8] merged --- docs/zk-email-docs/UsageGuide/README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/docs/zk-email-docs/UsageGuide/README.md b/docs/zk-email-docs/UsageGuide/README.md index 4c7a366cc..a16c0a0cd 100644 --- a/docs/zk-email-docs/UsageGuide/README.md +++ b/docs/zk-email-docs/UsageGuide/README.md @@ -108,14 +108,12 @@ To compile the circuit locally, you need to have Rust and Circom installed first ```bash circom MyCircuit.circom -o --r1cs --wasm --sym --c --O0 ``` -*Note: You can add `-l` to specify the directory where the directive `include` should look for the circuits indicated. For our repo, use `circom -l node_modules` instead of `circom`. Additionally, we generally recommend using the `--O0` flag for optimization during compilation for beginners. However, if you're more experienced with Circom, feel free to use the `--O1` flag instead. It's important to avoid using the `--O2` flag as that is the default setting and it may lead to the deletion of additional constraints.* +*Note: You can add `-l` to specify the directory where the directive `include` should look for the circuits indicated. For our repo, if you are having errors, we recommend to use `circom -l node_modules` instead of `circom`.* -We generally recommend using the --O0 flag, but if you're more experienced with circom feel free to use --O1 instead. +We generally recommend using the --O0 flag for ensuring there are no unintended underconstraints, but if you need to optimize constraints and understand what is being changed in circom, feel free to use --O1 instead. It's important to avoid using the `--O2` flag as that is the default setting and it may lead to the deletion of addition constraints. After running this command, the circuit will be compiled into a `.r1cs` file, a `.wasm` file, and a `.sym` file. These files are used in the next steps to generate the proving and verifying keys, and to compute the witness. - - ## Step 5: Compute the Witness The process of creating a proof involves ensuring that all signals in the file adhere to the existing constraints. This is achieved by computing the witness using the Wasm file generated during compilation. From cef5b0cf09440192ebcf599eccd78a564fc2afcd Mon Sep 17 00:00:00 2001 From: Elo <104064497+Metachaser24@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:33:37 +0300 Subject: [PATCH 3/8] Add constraint discussion links --- docs/zk-email-docs/UsageGuide/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/zk-email-docs/UsageGuide/README.md b/docs/zk-email-docs/UsageGuide/README.md index a16c0a0cd..2f3d7e306 100644 --- a/docs/zk-email-docs/UsageGuide/README.md +++ b/docs/zk-email-docs/UsageGuide/README.md @@ -106,12 +106,16 @@ To compile the circuit locally, you need to have Rust and Circom installed first ```bash -circom MyCircuit.circom -o --r1cs --wasm --sym --c --O0 +circom -l node_modules MyCircuit.circom -o --r1cs --wasm --sym --c --O0 ``` *Note: You can add `-l` to specify the directory where the directive `include` should look for the circuits indicated. For our repo, if you are having errors, we recommend to use `circom -l node_modules` instead of `circom`.* We generally recommend using the --O0 flag for ensuring there are no unintended underconstraints, but if you need to optimize constraints and understand what is being changed in circom, feel free to use --O1 instead. It's important to avoid using the `--O2` flag as that is the default setting and it may lead to the deletion of addition constraints. +Refer to these discussions for more information on constraint deletion. +https://stackoverflow.com/questions/78136647/circom-does-not-create-a-constraint-for-addition/78177349#78177349 +https://stackoverflow.com/questions/77688466/circom-compiler-removes-crucial-constraint-after-simplication/78177354?noredirect=1#comment137833229_78177354 + After running this command, the circuit will be compiled into a `.r1cs` file, a `.wasm` file, and a `.sym` file. These files are used in the next steps to generate the proving and verifying keys, and to compute the witness. ## Step 5: Compute the Witness From d9b8dd5d39ad681cedd2262bd899f2af3a10bf08 Mon Sep 17 00:00:00 2001 From: Divide-By-0 Date: Mon, 1 Apr 2024 15:46:35 -0700 Subject: [PATCH 4/8] made links hyperlinks --- docs/zk-email-docs/UsageGuide/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/zk-email-docs/UsageGuide/README.md b/docs/zk-email-docs/UsageGuide/README.md index 2f3d7e306..7d5e6c153 100644 --- a/docs/zk-email-docs/UsageGuide/README.md +++ b/docs/zk-email-docs/UsageGuide/README.md @@ -112,9 +112,7 @@ circom -l node_modules MyCircuit.circom -o --r1cs --wasm --sym --c --O0 We generally recommend using the --O0 flag for ensuring there are no unintended underconstraints, but if you need to optimize constraints and understand what is being changed in circom, feel free to use --O1 instead. It's important to avoid using the `--O2` flag as that is the default setting and it may lead to the deletion of addition constraints. -Refer to these discussions for more information on constraint deletion. -https://stackoverflow.com/questions/78136647/circom-does-not-create-a-constraint-for-addition/78177349#78177349 -https://stackoverflow.com/questions/77688466/circom-compiler-removes-crucial-constraint-after-simplication/78177354?noredirect=1#comment137833229_78177354 +Refer to these discussions on StackOverflow ([1](https://stackoverflow.com/questions/78136647/circom-does-not-create-a-constraint-for-addition/78177349#78177349), [2](https://stackoverflow.com/questions/77688466/circom-compiler-removes-crucial-constraint-after-simplication/78177354?noredirect=1#comment137833229_78177354)) for more information on constraint deletion. After running this command, the circuit will be compiled into a `.r1cs` file, a `.wasm` file, and a `.sym` file. These files are used in the next steps to generate the proving and verifying keys, and to compute the witness. From 13b41c2f3c4682ee16e6210999a649e8d6bfef18 Mon Sep 17 00:00:00 2001 From: Divide-By-0 Date: Wed, 3 Apr 2024 10:33:40 -0700 Subject: [PATCH 5/8] bump oz to 5.0.0 and make dkim registry accept a _signer address constructor arg --- packages/contracts/DKIMRegistry.sol | 2 ++ packages/contracts/foundry.toml | 3 ++- packages/contracts/package.json | 2 +- packages/contracts/remappings.txt | 3 +-- yarn.lock | 10 +++++----- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/contracts/DKIMRegistry.sol b/packages/contracts/DKIMRegistry.sol index db27a2976..356f244c1 100644 --- a/packages/contracts/DKIMRegistry.sol +++ b/packages/contracts/DKIMRegistry.sol @@ -13,6 +13,8 @@ import "./interfaces/IDKIMRegistry.sol"; Input is DKIM pub key split into 17 chunks of 121 bits. You can use `helpers` package to fetch/split DKIM keys */ contract DKIMRegistry is IDKIMRegistry, Ownable { + constructor(address _signer) Ownable(_signer) { } + event DKIMPublicKeyHashRegistered(string domainName, bytes32 publicKeyHash); event DKIMPublicKeyHashRevoked(bytes32 publicKeyHash); diff --git a/packages/contracts/foundry.toml b/packages/contracts/foundry.toml index f4e0b94fa..0fcf08be4 100644 --- a/packages/contracts/foundry.toml +++ b/packages/contracts/foundry.toml @@ -2,4 +2,5 @@ src = './' out = 'out' allow_paths = ['../../node_modules'] -solc_version = '0.8.21' \ No newline at end of file +libs = ['../../node_modules'] +solc_version = '0.8.21' diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 4fdf0310e..8a1c4f878 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -6,7 +6,7 @@ "publish": "yarn npm publish --access=public" }, "dependencies": { - "@openzeppelin/contracts": "^4.9.3", + "@openzeppelin/contracts": "^5.0.0", "dotenv": "^16.3.1" } } diff --git a/packages/contracts/remappings.txt b/packages/contracts/remappings.txt index 5abcb1beb..a04e5ade4 100644 --- a/packages/contracts/remappings.txt +++ b/packages/contracts/remappings.txt @@ -1,3 +1,2 @@ -@openzeppelin=../../node_modules/@openzeppelin/contracts @openzeppelin/contracts=../../node_modules/@openzeppelin/contracts -@openzeppelin/contracts-upgradeable=../../node_modules/@openzeppelin/contracts-upgradeable \ No newline at end of file +@openzeppelin=../../node_modules/@openzeppelin/contracts \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 2e043d8a2..41f8061b8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2446,10 +2446,10 @@ __metadata: languageName: node linkType: hard -"@openzeppelin/contracts@npm:^4.9.3": - version: 4.9.3 - resolution: "@openzeppelin/contracts@npm:4.9.3" - checksum: 4932063e733b35fa7669b9fe2053f69b062366c5c208b0c6cfa1ac451712100c78acff98120c3a4b88d94154c802be05d160d71f37e7d74cadbe150964458838 +"@openzeppelin/contracts@npm:^5.0.0": + version: 5.0.2 + resolution: "@openzeppelin/contracts@npm:5.0.2" + checksum: 0cce6fc284bd1d89e2a447027832a62f1356b44ee31088899453e10349a63a62df2f07da63d76e4c41aad9c86b96b650b2b6fc85439ef276850dda1170a047fd languageName: node linkType: hard @@ -2771,7 +2771,7 @@ __metadata: version: 0.0.0-use.local resolution: "@zk-email/contracts@workspace:packages/contracts" dependencies: - "@openzeppelin/contracts": ^4.9.3 + "@openzeppelin/contracts": ^5.0.0 dotenv: ^16.3.1 languageName: unknown linkType: soft From 77ab2dc628645efd30541fd70a61f879da497e06 Mon Sep 17 00:00:00 2001 From: Divide-By-0 Date: Wed, 3 Apr 2024 10:54:29 -0700 Subject: [PATCH 6/8] add test --- packages/contracts/package.json | 3 +++ packages/contracts/remappings.txt | 4 +++- packages/contracts/test/DKIMRegistry.t.sol | 23 ++++++++++++++++++++++ yarn.lock | 8 ++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 packages/contracts/test/DKIMRegistry.t.sol diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 8a1c4f878..17f6303a7 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -8,5 +8,8 @@ "dependencies": { "@openzeppelin/contracts": "^5.0.0", "dotenv": "^16.3.1" + }, + "devDependencies": { + "forge-std": "https://github.com/foundry-rs/forge-std" } } diff --git a/packages/contracts/remappings.txt b/packages/contracts/remappings.txt index a04e5ade4..8e456fa02 100644 --- a/packages/contracts/remappings.txt +++ b/packages/contracts/remappings.txt @@ -1,2 +1,4 @@ @openzeppelin/contracts=../../node_modules/@openzeppelin/contracts -@openzeppelin=../../node_modules/@openzeppelin/contracts \ No newline at end of file +@openzeppelin=../../node_modules/@openzeppelin/contracts +forge-std=../../node_modules/forge-std + diff --git a/packages/contracts/test/DKIMRegistry.t.sol b/packages/contracts/test/DKIMRegistry.t.sol new file mode 100644 index 000000000..70acccd12 --- /dev/null +++ b/packages/contracts/test/DKIMRegistry.t.sol @@ -0,0 +1,23 @@ + +import "@openzeppelin/contracts/utils/Strings.sol"; +import "forge-std/src/Test.sol"; +import "forge-std/src/console.sol"; +import "../interfaces/IDKIMRegistry.sol"; +import "../DKIMRegistry.sol"; + +/// @title ECDSAOwnedDKIMRegistry +/// @notice A DKIM Registry that could be updated by predefined ECDSA signer +contract TestDKIMRegistry is Test { + DKIMRegistry public dkimRegistry; + address public signer; + + constructor() { + dkimRegistry = new DKIMRegistry(msg.sender); + signer = msg.sender; + } + + function test_setDKIM() public { + dkimRegistry.setDKIMPublicKeyHash("test.com", "a81273981273bce922"); + } +} + diff --git a/yarn.lock b/yarn.lock index 41f8061b8..4b733a69a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2773,6 +2773,7 @@ __metadata: dependencies: "@openzeppelin/contracts": ^5.0.0 dotenv: ^16.3.1 + forge-std: "https://github.com/foundry-rs/forge-std" languageName: unknown linkType: soft @@ -4195,6 +4196,13 @@ __metadata: languageName: node linkType: hard +"forge-std@https://github.com/foundry-rs/forge-std": + version: 1.7.6 + resolution: "forge-std@https://github.com/foundry-rs/forge-std.git#commit=e4aef94c1768803a16fe19f7ce8b65defd027cfd" + checksum: 6fab51b92a24c97384f55dcb1b9eba29ce5043b67930b4179a9f9f4f8da85e8315163db60bec2ffbe7334135755630ba549b246db9e503e59ec93ba2f11931cc + languageName: node + linkType: hard + "fs-minipass@npm:^2.0.0, fs-minipass@npm:^2.1.0": version: 2.1.0 resolution: "fs-minipass@npm:2.1.0" From e9780dda3288585f7e78b82c66d7ab8f75cd3a43 Mon Sep 17 00:00:00 2001 From: wshino Date: Thu, 4 Apr 2024 08:24:09 +0900 Subject: [PATCH 7/8] Fix failed test case in DKIMRegistry.t.sol. --- packages/contracts/README.md | 6 ++++++ packages/contracts/test/DKIMRegistry.t.sol | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/packages/contracts/README.md b/packages/contracts/README.md index 66b0a491b..feeb986e6 100644 --- a/packages/contracts/README.md +++ b/packages/contracts/README.md @@ -1,3 +1,9 @@ +## Set up + +```bash +yarn install +``` + ## DKIMRegistry.sol The `DKIMRegistry.sol` is a Solidity contract that serves as a registry for storing the hash of the DomainKeys Identified Mail (DKIM) public key for each domain. This contract is part of the `@zk-email/contracts` package. diff --git a/packages/contracts/test/DKIMRegistry.t.sol b/packages/contracts/test/DKIMRegistry.t.sol index 70acccd12..71c5e8cb9 100644 --- a/packages/contracts/test/DKIMRegistry.t.sol +++ b/packages/contracts/test/DKIMRegistry.t.sol @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.12; import "@openzeppelin/contracts/utils/Strings.sol"; import "forge-std/src/Test.sol"; @@ -17,7 +19,9 @@ contract TestDKIMRegistry is Test { } function test_setDKIM() public { + vm.prank(signer); dkimRegistry.setDKIMPublicKeyHash("test.com", "a81273981273bce922"); + vm.stopPrank(); } } From 1cca593038f4fcbbea9b18af9d4a12c56a3d6c1d Mon Sep 17 00:00:00 2001 From: Divide-By-0 Date: Wed, 3 Apr 2024 16:48:18 -0700 Subject: [PATCH 8/8] breaking bump --- packages/contracts/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contracts/package.json b/packages/contracts/package.json index 17f6303a7..5c6868241 100644 --- a/packages/contracts/package.json +++ b/packages/contracts/package.json @@ -1,6 +1,6 @@ { "name": "@zk-email/contracts", - "version": "5.0.2", + "version": "6.0.0", "scripts": { "build": "forge build", "publish": "yarn npm publish --access=public"