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

Ethereum Group PCD #290

Merged
merged 3 commits into from
Jul 26, 2023
Merged

Ethereum Group PCD #290

merged 3 commits into from
Jul 26, 2023

Conversation

djma
Copy link
Contributor

@djma djma commented Jul 4, 2023

Subsumes #287

Comment on lines 156 to 160
/**
* The offset that the hex representation of the public key starts at, without the 0x prefix and without the 04 prefix. That's what the zk-circuit expects.
* https://github.com/indutny/elliptic/issues/86
* https://dev.to/q9/finally-understanding-ethereum-accounts-1kpe
*/
const hexPubkeyOffset = 2 + 2;

function AddEthGroupPCDButton() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good chunk of code here is duplicated in EthereumGroupPCD.spec.ts. I tried to refactor it and put this example code in EthereumGroupPCD.ts but ran into problems in EthereumGroupPCD.init(). I'm leaving it like this for your review.

Comment on lines 115 to 118
const isNode =
typeof process !== "undefined" &&
process.versions != null &&
process.versions.node != null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this is kosher

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend passing a parameter into the init function via EthereumGroupPCDInitArgs called something like proverConfigOverride, which you set only in the browser, so you don't have to do this isNode checking in the PCD package.

Comment on lines 132 to 145
} else {
addrMembershipConfig = {
circuit:
"https://storage.googleapis.com/personae-proving-keys/membership/addr_membership.circuit",
witnessGenWasm:
"https://storage.googleapis.com/personae-proving-keys/membership/addr_membership.wasm",
};

pubkeyMembershipConfig = {
circuit:
"https://storage.googleapis.com/personae-proving-keys/membership/pubkey_membership.circuit",
witnessGenWasm:
"https://storage.googleapis.com/personae-proving-keys/membership/pubkey_membership.wasm",
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning from spartan-ecdsa:


      Spartan-ecdsa default config warning:
      We recommend using defaultPubkeyMembershipPConfig/defaultPubkeyMembershipVConfig only for testing purposes.
      Please host and specify the circuit and witnessGenWasm files on your own server for sovereign control.
      Download files: https://github.com/personaelabs/spartan-ecdsa/blob/main/packages/lib/README.md#circuit-downloads
      

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can host these on our server here to avoid this warning

Comment on lines +127 to +128
- [`@pcd/ethereum-ownership-pcd`](packages/ethereum-ownership-pcd): a pcd that can be used to claim that a Semaphore identity knows the private key of an ethereum address.
- [`@pcd/ethereum-group-pcd`](packages/ethereum-group-pcd): a pcd that can be used to claim that a Semaphore identity knows the private key of an ethereum address or public key that is part of a merkle group of addresses or public keys, without revealing the specific one.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

value: undefined,
userProvided: true,
description:
"The Semaphore Identity which you are signing the message.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"The Semaphore Identity which you are signing the message.",
"The Semaphore Identity with which you are signing the message.",

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the message

on first read, it's confusing to understand what 'the message' is. I'd recommend changing the description to something like

"The Semaphore Identity which you are proving owns the given Ethereum address."

},
groupType: {
argumentType: ArgumentTypeName.String,
value: GroupType.PUBLICKEY,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should probably also have a happy path for the address group type

}

export enum GroupType {
PUBLICKEY = "publickey",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PUBLIC_KEY = "public_key"

@@ -1,18 +1,26 @@
import { EthereumGroupPCDPackage, GroupType } from "@pcd/ethereum-group-pcd";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how this works on your computer, but I needed to add a dependency on this package in the package.json of consumer-client

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should make an equivalent update to apps/passport-server/src/services/provingService.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in startProvingService? what about all the other pcds?

@djma djma requested a review from ichub July 13, 2023 23:23
Comment on lines +118 to +121
addrProver = new MembershipProver(addrMembershipConfig);
pubkeyProver = new MembershipProver(pubkeyMembershipConfig);
addrVerifier = new MembershipVerifier(addrMembershipConfig);
pubkeyVerifier = new MembershipVerifier(pubkeyMembershipConfig);
await Promise.all([
addrProver.initWasm(),
pubkeyProver.initWasm(),
addrVerifier.initWasm(),
pubkeyVerifier.initWasm(),
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*
* https://dev.to/q9/finally-understanding-ethereum-accounts-1kpe
*/
export function getRawPubKeyBuffer(pubKey: string): Buffer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}

if (
[GroupType.ADDRESS, GroupType.PUBLICKEY].includes(args.groupType as any)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[GroupType.ADDRESS, GroupType.PUBLICKEY].includes(args.groupType as any)
![GroupType.ADDRESS, GroupType.PUBLICKEY].includes(args.groupType as any)

you should run all your code :P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah.. it was a double error. Missing the ! and missing the .value, which led to tests passing.

)
);
parsed.claim.publicInput = publicInput;
return parsed;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One issue with this parse function is that it's not invoking the constructor of EthereumGroupPCD, but creating an object that conforms to its type signature. Not a huge deal right now but feels kind of wrong. Checking the way I do this in other packages and it seems that this is a pervasive error. Here's an issue to fix at some point later. #308

newEthGroupPCD.claim.publicInput.circuitPubInput.Uy =
newEthGroupPCD.claim.publicInput.circuitPubInput.Uy - BigInt(1);

assert(await EthereumGroupPCDPackage.verify(newEthGroupPCD));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

assert(await EthereumGroupPCDPackage.verify(ethGroupPCD));
});

it("should work with address (slow ~40s)", async function () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sheesh

@ichub
Copy link
Contributor

ichub commented Jul 18, 2023

I'm getting the following error when I run the code on my computer and open up the passport app:

Screenshot 2023-07-18 at 1 29 29 PM

Copy link
Contributor

@ichub ichub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! last thing left is to resolve the yarn.lock conflicts

djma added 3 commits July 26, 2023 10:57
Onboarding local dev fixes

Fix passport-server:dev

concurrently

concurrently

Ethereum Group PCD

Add test

more test

tests

progress

Ethereum Address Ownership example in add-pcd.tsx

small fix

switch to merkleproof

eth group pcd in add-pcd

smol fix

small rename

Fix ethereum ownership tests and ethereum group ownership tests

remove useNativeBigInt

address PR comments

address pr comments
@ichub ichub merged commit 959b0dd into proofcarryingdata:main Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants