Skip to content

Commit

Permalink
fixed a type error
Browse files Browse the repository at this point in the history
  • Loading branch information
yashgo0018 committed Mar 26, 2024
1 parent bcabb37 commit 9f8aaac
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 45 deletions.
2 changes: 1 addition & 1 deletion packages/hardhat/deploy/10_vk_registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const deployContracts: DeployFunction = async function (hre: HardhatRuntimeEnvir
extractVk(processMessagesZkeyPath),
extractVk(tallyVotesZkeyPath),
subsidyZkeyPath ? extractVk(subsidyZkeyPath) : null,
]).then(vks => vks.map(vk => (vk ? VerifyingKey.fromObj(vk) : null)));
]).then(vks => vks.map(vk => (vk ? VerifyingKey.fromObj(vk as any) : null)));

const messageBatchSize = 5 ** messageBatchDepth;
const processVkParam = processVk!.asContractParam() as IVerifyingKeyStruct;
Expand Down
13 changes: 7 additions & 6 deletions packages/hardhat/maci-ts/crypto/babyjub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { randomBytes } from "crypto";
import type { PrivKey } from "./types";

import { SNARK_FIELD_SIZE } from "./constants";
import { IG1ContractParams, IG2ContractParams } from "../domainobjs";

/**
* @notice A class representing a point on the first group (G1)
Expand Down Expand Up @@ -39,10 +40,10 @@ export class G1Point {
* Return the point as a contract param in the form of an object
* @returns the point as a contract param
*/
asContractParam(): { x: string; y: string } {
asContractParam(): IG1ContractParams {
return {
x: this.x.toString(),
y: this.y.toString(),
x: this.x,
y: this.y,
};
}
}
Expand Down Expand Up @@ -83,10 +84,10 @@ export class G2Point {
* Return the point as a contract param in the form of an object
* @returns the point as a contract param
*/
asContractParam(): { x: string[]; y: string[] } {
asContractParam(): IG2ContractParams {
return {
x: this.x.map(n => n.toString()),
y: this.y.map(n => n.toString()),
x: this.x,
y: this.y,
};
}

Expand Down
6 changes: 3 additions & 3 deletions packages/hardhat/maci-ts/domainobjs/ballot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ export class Ballot {
*/
toJSON(): IJsonBallot {
return {
votes: this.votes.map(x => x.toString()),
nonce: this.nonce.toString(),
voteOptionTreeDepth: this.voteOptionTreeDepth.toString(),
votes: this.votes,
nonce: this.nonce,
voteOptionTreeDepth: this.voteOptionTreeDepth,
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat/maci-ts/domainobjs/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Message {
*/
asContractParam = (): IMessageContractParams => ({
msgType: this.msgType.toString(),
data: this.data.map((x: bigint) => x.toString()),
data: this.data,
});

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/hardhat/maci-ts/domainobjs/publicKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class PubKey {
* Create a copy of the public key
* @returns a copy of the public key
*/
copy = (): PubKey => new PubKey([BigInt(this.rawPubKey[0].toString()), BigInt(this.rawPubKey[1].toString())]);
copy = (): PubKey => new PubKey([this.rawPubKey[0], this.rawPubKey[1]]);

/**
* Return this public key as smart contract parameters
Expand All @@ -41,8 +41,8 @@ export class PubKey {
const [x, y] = this.rawPubKey;

return {
x: x.toString(),
y: y.toString(),
x,
y,
};
};

Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat/maci-ts/domainobjs/stateLeaf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export class StateLeaf implements IStateLeaf {
asContractParam(): IStateLeafContractParams {
return {
pubKey: this.pubKey.asContractParam(),
voiceCreditBalance: this.voiceCreditBalance.toString(),
timestamp: this.timestamp.toString(),
voiceCreditBalance: this.voiceCreditBalance,
timestamp: this.timestamp,
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat/maci-ts/domainobjs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export interface IJsonStateLeaf {
timestamp: string;
}

export type BigNumberish = number | string | bigint;
export type BigNumberish = bigint;

export interface IG1ContractParams {
x: BigNumberish;
Expand Down Expand Up @@ -86,5 +86,5 @@ export interface IMessageContractParams {
export interface IJsonBallot {
votes: BigNumberish[];
nonce: BigNumberish;
voteOptionTreeDepth: BigNumberish;
voteOptionTreeDepth: number;
}
3 changes: 1 addition & 2 deletions packages/nextjs/app/_components/RegisterButton.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { useAuthContext } from "~~/contexts/AuthContext";
import { useScaffoldContractWrite } from "~~/hooks/scaffold-eth";
import { keyToParam } from "~~/utils/crypto";

export default function RegisterButton() {
const { keypair, isRegistered } = useAuthContext();

const { writeAsync } = useScaffoldContractWrite({
contractName: "MACI",
functionName: "signUp",
args: [keyToParam(keypair?.pubKey), "0x", "0x"],
args: [keypair?.pubKey.asContractParam(), "0x", "0x"],
});

if (isRegistered) return <div>Thanks for Registration</div>;
Expand Down
4 changes: 1 addition & 3 deletions packages/nextjs/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ export default function AuthContextProvider({ children }: { children: React.Reac
const { data: isRegistered, refetch: refetchIsRegistered } = useScaffoldContractRead({
contractName: "MACI",
functionName: "isPublicKeyRegistered",
args: keypair
? [BigInt(keypair.pubKey.asContractParam().x), BigInt(keypair.pubKey.asContractParam().y)]
: [undefined, undefined],
args: keypair ? keypair.pubKey.rawPubKey : [undefined, undefined],
});

useScaffoldEventSubscriber({
Expand Down
30 changes: 15 additions & 15 deletions packages/nextjs/contracts/deployedContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract";
const deployedContracts = {
31337: {
ConstantInitialVoiceCreditProxy: {
address: "0x99bbA657f2BbC93c02D617f8bA121cB8Fc104Acf",
address: "0x5FbDB2315678afecb367f032d93F642f64180aa3",
abi: [
{
inputs: [
Expand Down Expand Up @@ -50,7 +50,7 @@ const deployedContracts = {
},
},
FreeForAllGatekeeper: {
address: "0x0E801D84Fa97b50751Dbf25036d067dCf18858bF",
address: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
abi: [
{
inputs: [],
Expand Down Expand Up @@ -92,7 +92,7 @@ const deployedContracts = {
inheritedFunctions: {},
},
MACI: {
address: "0x82e01223d51Eb87e16A03E24687EDF0F294da6f1",
address: "0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0",
abi: [
{
inputs: [
Expand Down Expand Up @@ -1084,7 +1084,7 @@ const deployedContracts = {
},
},
MessageProcessorFactory: {
address: "0x5f3f1dBD7B74C6B46e8c44f98792A1dAf8d69154",
address: "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
abi: [
{
inputs: [],
Expand Down Expand Up @@ -1139,7 +1139,7 @@ const deployedContracts = {
},
},
PollFactory: {
address: "0x1291Be112d480055DaFd8a610b7d1e203891C274",
address: "0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6",
abi: [
{
inputs: [],
Expand Down Expand Up @@ -1266,7 +1266,7 @@ const deployedContracts = {
},
},
PollManager: {
address: "0xc351628EB244ec633d5f21fBD6621e1a683B1181",
address: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
abi: [
{
inputs: [
Expand Down Expand Up @@ -1766,7 +1766,7 @@ const deployedContracts = {
},
},
PoseidonT3: {
address: "0x5eb3Bc0a489C5A8288765d2336659EbCA68FCd00",
address: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
abi: [
{
inputs: [
Expand All @@ -1791,7 +1791,7 @@ const deployedContracts = {
inheritedFunctions: {},
},
PoseidonT4: {
address: "0x36C02dA8a0983159322a80FFE9F24b1acfF8B570",
address: "0x5FC8d32690cc91D4c39d9d3abcBD16989F875707",
abi: [
{
inputs: [
Expand All @@ -1816,7 +1816,7 @@ const deployedContracts = {
inheritedFunctions: {},
},
PoseidonT5: {
address: "0x809d550fca64d94Bd9F66E60752A544199cfAC3D",
address: "0x0165878A594ca255338adfa4d48449f69242Eb8F",
abi: [
{
inputs: [
Expand All @@ -1841,7 +1841,7 @@ const deployedContracts = {
inheritedFunctions: {},
},
PoseidonT6: {
address: "0x4c5859f0F772848b2D91F1D83E2Fe57935348029",
address: "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853",
abi: [
{
inputs: [
Expand All @@ -1866,7 +1866,7 @@ const deployedContracts = {
inheritedFunctions: {},
},
SubsidyFactory: {
address: "0xCD8a1C3ba11CF5ECfa6267617243239504a98d90",
address: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
abi: [
{
inputs: [
Expand Down Expand Up @@ -1913,7 +1913,7 @@ const deployedContracts = {
},
},
TallyFactory: {
address: "0xb7278A61aa25c888815aFC32Ad3cC52fF24fE575",
address: "0x610178dA211FEF7D417bC0e6FeD39F05609AD788",
abi: [
{
inputs: [
Expand Down Expand Up @@ -1960,7 +1960,7 @@ const deployedContracts = {
},
},
TopupCredit: {
address: "0x9d4454B023096f34B160D6B654540c56A1F81688",
address: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
abi: [
{
inputs: [],
Expand Down Expand Up @@ -2370,7 +2370,7 @@ const deployedContracts = {
},
},
Verifier: {
address: "0x8f86403A4DE0BB5791fa46B8e795C547942fE4Cf",
address: "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0",
abi: [
{
inputs: [],
Expand Down Expand Up @@ -2532,7 +2532,7 @@ const deployedContracts = {
},
},
VkRegistry: {
address: "0x7969c5eD335650692Bc04293B07F5BF2e7A673C0",
address: "0x9A676e781A523b5d0C0e43731313A708CB607508",
abi: [
{
inputs: [],
Expand Down
8 changes: 1 addition & 7 deletions packages/nextjs/utils/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { Keypair, PrivKey, PubKey } from "@se-2/hardhat/maci-ts/domainobjs";
import { Keypair, PrivKey } from "@se-2/hardhat/maci-ts/domainobjs";
import { decodeAbiParameters } from "viem";

export function fetchOrCreateUserKeyPair(address?: string) {
Expand All @@ -26,9 +26,3 @@ export function fetchOrCreateUserKeyPair(address?: string) {
export function decodeOptions(encodedData: `0x${string}`) {
return decodeAbiParameters([{ type: "string[]" }], encodedData)[0];
}

export function keyToParam(key?: PubKey): { x: bigint; y: bigint } | undefined {
if (!key) return undefined;
const p = key.asContractParam();
return { x: BigInt(p.x), y: BigInt(p.y) };
}

0 comments on commit 9f8aaac

Please sign in to comment.