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

refactor: user sdk #2064

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

refactor: user sdk #2064

wants to merge 2 commits into from

Conversation

ctrlc03
Copy link
Collaborator

@ctrlc03 ctrlc03 commented Jan 23, 2025

Description

Refactor user functions from the SDK

Confirmation

Important

We do not accept minor grammatical fixes (e.g., correcting typos, rewording sentences) unless they significantly improve clarity in technical documentation. These contributions, while appreciated, are not a priority for merging. If there is a grammatical error feel free to message the team.

@ctrlc03 ctrlc03 self-assigned this Jan 23, 2025
Copy link

vercel bot commented Jan 23, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
maci-website ❌ Failed (Inspect) Jan 23, 2025 4:55pm

@ctrlc03 ctrlc03 changed the title Refactor/user sdk refactor: user sdk Jan 23, 2025
Copy link
Collaborator

@0xmad 0xmad left a comment

Choose a reason for hiding this comment

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

@ctrlc03 thanks, just few comments.
And is this PR supposed to move tests?
It will be nice to have tests for sdk.

"dependencies": {
"@commander-js/extra-typings": "^12.1.0",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
"commander": "^12.1.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need these (commander, @commander-js/extra-typings) dependencies for sdk?


const userMaciPubKey = PubKey.deserialize(maciPubKey);

if (!(await contractExists(signer.provider!, maciAddress))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's move await call to a constant

Comment on lines +4 to +7
export /**
* Parse the poll joining events from the Poll contract
*/
const parsePollJoinEvents = async ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
export /**
* Parse the poll joining events from the Poll contract
*/
const parsePollJoinEvents = async ({
/**
* Parse the poll joining events from the Poll contract
*/
export const parsePollJoinEvents = async ({

Comment on lines +43 to +46
export /**
* Parse the signup events from the MACI contract
*/
const parseSignupEvents = async ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
export /**
* Parse the signup events from the MACI contract
*/
const parseSignupEvents = async ({
/**
* Parse the signup events from the MACI contract
*/
export const parseSignupEvents = async ({

publicKey,
}: IParseSignupEventsArgs): Promise<{ stateIndex?: string }> => {
// 1000 blocks at a time
for (let block = startBlock; block <= currentBlock; block += 1000) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's use constant for blocks increment.

Comment on lines +41 to +44
);
if (!isValid) {
failedIndices.push(i);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
);
if (!isValid) {
failedIndices.push(i);
}
);
if (!isValid) {
failedIndices.push(i);
}

const useQv = tallyData.isQuadratic;
const maciContractAddress = tallyData.maci;

if (!(await contractExists(signer.provider!, maciContractAddress))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's move await call to a constant

Comment on lines +61 to +66
!(await tallyContract.verifySpentVoiceCredits(
tallyData.totalSpentVoiceCredits.spent,
tallyData.totalSpentVoiceCredits.salt,
newResultsCommitment,
newPerVOSpentVoiceCreditsCommitment ?? 0n,
))
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same here with moving to constant

Comment on lines +88 to +108
if (useQv) {
if (tallyData.perVOSpentVoiceCredits?.tally.length !== numVoteOptions) {
throw new Error("Wrong number of vote options.");
}
// verify per vote option voice credits on-chain
const failedSpentCredits = await verifyPerVOSpentVoiceCredits(
tallyContract,
tallyData,
voteOptionTreeDepth,
newSpentVoiceCreditsCommitment,
newResultsCommitment,
);

if (failedSpentCredits.length > 0) {
throw new Error(
`At least one tally result failed the on-chain verification. Please check your Tally data at these indexes: ${failedSpentCredits.join(
", ",
)}`,
);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (useQv) {
if (tallyData.perVOSpentVoiceCredits?.tally.length !== numVoteOptions) {
throw new Error("Wrong number of vote options.");
}
// verify per vote option voice credits on-chain
const failedSpentCredits = await verifyPerVOSpentVoiceCredits(
tallyContract,
tallyData,
voteOptionTreeDepth,
newSpentVoiceCreditsCommitment,
newResultsCommitment,
);
if (failedSpentCredits.length > 0) {
throw new Error(
`At least one tally result failed the on-chain verification. Please check your Tally data at these indexes: ${failedSpentCredits.join(
", ",
)}`,
);
}
}
if (!useQv) {
return true;
}
if (tallyData.perVOSpentVoiceCredits?.tally.length !== numVoteOptions) {
throw new Error("Wrong number of vote options.");
}
// verify per vote option voice credits on-chain
const failedSpentCredits = await verifyPerVOSpentVoiceCredits(
tallyContract,
tallyData,
voteOptionTreeDepth,
newSpentVoiceCreditsCommitment,
newResultsCommitment,
);
if (failedSpentCredits.length > 0) {
throw new Error(
`At least one tally result failed the on-chain verification. Please check your Tally data at these indexes: ${failedSpentCredits.join(
", ",
)}`,
);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

2 participants