Skip to content

Commit

Permalink
refactor: fix ESLint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
baumstern committed Nov 21, 2023
1 parent c0b5afb commit 6c0ed97
Show file tree
Hide file tree
Showing 18 changed files with 68 additions and 104 deletions.
2 changes: 1 addition & 1 deletion circuits/ts/__tests__/Hasher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ describe('Poseidon hash circuits', function() {
genRandomSalt(),
)

const { privKey, pubKey } = new Keypair()
const { privKey } = new Keypair()
const ecdhSharedKey = Keypair.genEcdhSharedKey(privKey, k.pubKey)
const signature = command.sign(privKey)
const message = command.encrypt(signature, ecdhSharedKey)
Expand Down
2 changes: 1 addition & 1 deletion circuits/ts/__tests__/MessageToCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('MessageToCommand circuit', () => {
circuit = await tester(circuitPath)
})
it('Should decrypt a Message and output the fields of a Command', async () => {
const { privKey, pubKey } = new Keypair()
const { privKey } = new Keypair()
const k = new Keypair()

const pubKey1 = k.pubKey
Expand Down
1 change: 0 additions & 1 deletion circuits/ts/__tests__/ProcessMessages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ describe('ProcessMessage circuit', function() {
describe('1 user, key-change', () => {
const maciState = new MaciState(STATE_TREE_DEPTH)
const voteWeight = BigInt(9)
const voteOptionIndex = BigInt(0)
let stateIndex
let pollId
let poll
Expand Down
7 changes: 0 additions & 7 deletions circuits/ts/__tests__/TallyVotes.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
STATE_TREE_DEPTH,
getSignal,
} from './utils'

import {
Expand All @@ -11,14 +10,8 @@ import {
Keypair,
PCommand,
Message,
VerifyingKey,
} from 'maci-domainobjs'

import {
G1Point,
G2Point,
} from 'maci-crypto'

import * as path from 'path'
import { expect } from 'chai'
import { beforeEach } from 'mocha'
Expand Down
2 changes: 1 addition & 1 deletion contracts/tests/HasherBenchmarks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Hasher', () => {

console.log('Deploying Hasher')
hasherContract = await hasherContractFactory.deploy()
await hasherContract.deployTransaction.wait()
await hasherContract.deployTransaction.wait()
})

it('hashLeftRight', async () => {
Expand Down
11 changes: 0 additions & 11 deletions contracts/tests/MACI.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,17 +618,6 @@ describe('MACI', () => {
})

describe('Tally votes', () => {
let pollContract

before(async () => {
const pollContractAddress = await maciContract.getPoll(pollId)
pollContract = new Contract(
pollContractAddress,
pollAbi,
signer,
)
})

it('genTallyVotesPackedVals() should generate the correct value', async () => {
const onChainPackedVals = BigInt(
await tallyContract.genTallyVotesPackedVals(
Expand Down
15 changes: 2 additions & 13 deletions contracts/tests/MACI_overflow.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { utils, Contract, Signer } from 'ethers'
import { parseArtifact, getDefaultSigner } from '../ts/deploy'
import { utils, Contract } from 'ethers'
import { deployTestContracts } from '../ts/utils'
import {
Keypair,
Expand All @@ -18,7 +17,6 @@ const users = [
]

const STATE_TREE_DEPTH = 10
const STATE_TREE_ARITY = 5
const MESSAGE_TREE_DEPTH = 4
const MESSAGE_TREE_SUBDEPTH = 2

Expand All @@ -37,27 +35,18 @@ const treeDepths: TreeDepths = {
}

const initialVoiceCreditBalance = 100
let signer: Signer
const [ pollAbi ] = parseArtifact('Poll')


describe('Overflow testing', () => {
let maciContract: Contract
let stateAqContract: Contract
let vkRegistryContract: Contract
let mpContract: Contract
let pollId: number

beforeEach(async () => {
signer = await getDefaultSigner()
const r = await deployTestContracts(
initialVoiceCreditBalance,
STATE_TREE_DEPTH,
true
)
maciContract = r.maciContract
stateAqContract = r.stateAqContract
vkRegistryContract = r.vkRegistryContract
mpContract = r.mpContract
})

it('MACI.stateTreeDepth should be correct', async () => {
Expand Down
28 changes: 10 additions & 18 deletions contracts/ts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const parseArtifact = (filename: string) => {
}

const contractArtifact = JSON.parse(
readFileSync(join(abiDir, filePath, `${filename}.json`)).toString()
readFileSync(join(abiDir, filePath, `${filename}.json`)).toString()
)

return [ contractArtifact.abi, contractArtifact.bytecode ]
Expand Down Expand Up @@ -69,14 +69,6 @@ export class JSONRPCDeployer {
}
}

class HardhatDeployer extends JSONRPCDeployer {

constructor(privateKey: string, port: number, options?: any) {
const url = `http://localhost:${port}/`
super(privateKey, url, options)
}
}

const genJsonRpcDeployer = (
privateKey: string,
url: string,
Expand All @@ -100,7 +92,7 @@ const linkPoseidonLibraries = async (
poseidonT4Address: string,
poseidonT5Address: string,
poseidonT6Address: string,
quiet: boolean = false,
quiet = false,
) => {
const signer = await getDefaultSigner()

Expand Down Expand Up @@ -181,7 +173,7 @@ const deployPollFactory = async (quiet = false) => {
}

// Deploy a contract given a name and args
const deployContract = async (contractName: string, quiet: boolean = false, ...args: any) : Promise<Contract> => {
const deployContract = async (contractName: string, quiet = false, ...args: any): Promise<Contract> => {
log(`Deploying ${contractName}`, quiet)
const signer = await getDefaultSigner()
const contractFactory = await ethers.getContractFactory(contractName, signer)
Expand All @@ -194,7 +186,7 @@ const deployContract = async (contractName: string, quiet: boolean = false, ...a
}

// deploy a contract with linked libraries
const deployContractWithLinkedLibraries = async (contractFactory: ContractFactory, name: string, quiet: boolean = false, ...args: any) : Promise<Contract> => {
const deployContractWithLinkedLibraries = async (contractFactory: ContractFactory, name: string, quiet = false, ...args: any): Promise<Contract> => {
log(`Deploying ${name}`, quiet)
const contract = await contractFactory.deploy(...args, {
maxFeePerGas: await getFeeData['maxFeePerGas']
Expand All @@ -204,14 +196,14 @@ const deployContractWithLinkedLibraries = async (contractFactory: ContractFactor
}


const transferOwnership = async (contract: Contract, newOwner: string, quiet: boolean = false) => {
const transferOwnership = async (contract: Contract, newOwner: string, quiet = false) => {
log(`Transferring ownership of ${contract.address} to ${newOwner}`, quiet)
await (await (contract.transferOwnership(newOwner, {
maxFeePerGas: await getFeeData['maxFeePerGas'],
}))).wait()
}

const initMaci = async (contract: Contract, quiet: boolean = false, ...args: any) => {
const initMaci = async (contract: Contract, quiet = false, ...args: any) => {
log('Initializing MACI', quiet)
await (await contract.init(...args, {
maxFeePerGas: await getFeeData['maxFeePerGas']
Expand All @@ -231,7 +223,7 @@ const deployMessageProcessor = async (
poseidonT4Address: string,
poseidonT5Address: string,
poseidonT6Address: string,
quiet: boolean = false
quiet = false
) => {
// Link Poseidon contracts to MessageProcessor
const mpFactory = await linkPoseidonLibraries(
Expand All @@ -257,7 +249,7 @@ const deployTally = async (
poseidonT4Address: string,
poseidonT5Address: string,
poseidonT6Address: string,
quiet: boolean = false
quiet = false
) => {
// Link Poseidon contracts to Tally
const tallyFactory = await linkPoseidonLibraries(
Expand All @@ -283,7 +275,7 @@ const deploySubsidy = async (
poseidonT4Address: string,
poseidonT5Address: string,
poseidonT6Address: string,
quiet: boolean = false
quiet = false
) => {
// Link Poseidon contracts to Subsidy
const subsidyFactory = await linkPoseidonLibraries(
Expand All @@ -309,7 +301,7 @@ const deployMaci = async (
verifierContractAddress: string,
vkRegistryContractAddress: string,
topupCreditContractAddress: string,
stateTreeDepth: number = 10,
stateTreeDepth = 10,
quiet = false,
) => {

Expand Down
2 changes: 1 addition & 1 deletion contracts/ts/genMaciState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const genMaciStateFromContract = async (
address: string,
coordinatorKeypair: Keypair,
pollId: number,
fromBlock: number = 0,
fromBlock = 0,
): Promise<MaciState> => {
pollId = Number(pollId)
// Verify and sort pollIds
Expand Down
4 changes: 2 additions & 2 deletions contracts/ts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const formatProofForVerifierContract = (
const deployTestContracts = async (
initialVoiceCreditBalance: number,
stateTreeDepth: number,
quiet: boolean = false,
quiet = false,
gatekeeperContract?: any
) => {
const mockVerifierContract = await deployMockVerifier(true)
Expand All @@ -54,7 +54,7 @@ const deployTestContracts = async (
const vkRegistryContract = await deployVkRegistry(true)
const topupCreditContract = await deployTopupCredit(true)

const {maciContract,stateAqContract,pollFactoryContract,poseidonAddrs} = await deployMaci(
const {maciContract,stateAqContract, poseidonAddrs} = await deployMaci(
gatekeeperContract.address,
constantIntialVoiceCreditProxyContract.address,
mockVerifierContract.address,
Expand Down
23 changes: 12 additions & 11 deletions core/ts/MaciState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Poll {
public perVOSpentVoiceCredits: bigint[] = []
public numBatchesTallied = 0

public totalSpentVoiceCredits: bigint = BigInt(0)
public totalSpentVoiceCredits = BigInt(0)

// For coefficient and subsidy calculation
public subsidy: bigint[] = [] // size: M, M is number of vote options
Expand Down Expand Up @@ -193,7 +193,7 @@ class Poll {
assert(d as bigint < SNARK_FIELD_SIZE)
}
this.messages.push(_message)
let padKey = new PubKey([
const padKey = new PubKey([
BigInt('10457101036533406547632367118273992217979173478358440826365724437999023779287'),
BigInt('19824078218392094440610104313265183977899662750282163392862422243483260492317'),
])
Expand Down Expand Up @@ -237,12 +237,12 @@ class Poll {
_encPubKey,
)
try {
let {command, signature} = PCommand.decrypt(_message, sharedKey)
const { command } = PCommand.decrypt(_message, sharedKey)
this.commands.push(command)
} catch(e) {
//console.log(`error cannot decrypt: ${e.message}`)
let keyPair = new Keypair()
let command = new PCommand(BigInt(0), keyPair.pubKey,BigInt(0),BigInt(0),BigInt(0),BigInt(0),BigInt(0))
const keyPair = new Keypair()
const command = new PCommand(BigInt(0), keyPair.pubKey,BigInt(0),BigInt(0),BigInt(0),BigInt(0),BigInt(0))
this.commands.push(command)
}
}
Expand Down Expand Up @@ -471,7 +471,7 @@ class Poll {
this.stateTree.update(Number(stateIndex), newStateLeaf.hash())

// we still need them as placeholder for vote command
let currentBallot = this.ballots[Number(stateIndex)].copy()
const currentBallot = this.ballots[Number(stateIndex)].copy()
currentBallots.unshift(currentBallot)
currentBallotsPathElements.unshift(
this.ballotTree.genMerklePath(Number(stateIndex)).pathElements
Expand All @@ -493,6 +493,7 @@ class Poll {
)

} catch(e) {
console.error("An error occurred: ", e.message);
throw e
}
break
Expand Down Expand Up @@ -900,7 +901,7 @@ class Poll {
return
}

public previousSubsidyIndexToString = ():string => {
public previousSubsidyIndexToString = (): string => {
const batchSize = this.batchSizes.subsidyBatchSize
const numBatches = Math.ceil(this.ballots.length/batchSize)
let cbi = this.cbi
Expand All @@ -922,14 +923,14 @@ class Poll {
for (let p = 0; p < this.maxValues.maxVoteOptions; p++) {
sum += BigInt(rowBallot.votes[p].valueOf()) * BigInt(colBallot.votes[p].valueOf())
}
let res = BigInt(this.MM * (10 ** this.WW))/(BigInt(this.MM)+BigInt(sum))
const res = BigInt(this.MM * (10 ** this.WW))/(BigInt(this.MM)+BigInt(sum))
return res
}

public subsidyCalculation = (rowStartIndex:number, colStartIndex:number): Ballot[][] => {
public subsidyCalculation = (rowStartIndex: number, colStartIndex: number): Ballot[][] => {
const batchSize = this.batchSizes.subsidyBatchSize
let ballots1: Ballot[] = []
let ballots2: Ballot[] = []
const ballots1: Ballot[] = []
const ballots2: Ballot[] = []
const emptyBallot = new Ballot(
this.maxValues.maxVoteOptions,
this.treeDepths.voteOptionTreeDepth,
Expand Down
1 change: 1 addition & 0 deletions core/ts/__tests__/ProcessMessage.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
describe('Message processing', () => {
describe('Process a batch of messages', () => {
let maciState
Expand Down
2 changes: 1 addition & 1 deletion crypto/ts/AccQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class AccQueue {

// For merging subtrees into the smallest tree
public nextSRindexToQueue = 0
public smallSRTroot: bigint = BigInt(0)
public smallSRTroot = BigInt(0)
public subRootQueue: Queue = {
levels: [],
indices: []
Expand Down
6 changes: 3 additions & 3 deletions crypto/ts/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export const genRandomBabyJubValue = (): bigint => {
let privKey: PrivKey = SNARK_FIELD_SIZE

do {
let rand: bigint = BigInt('0x' + randomBytes(32).toString('hex'))
const rand = BigInt('0x' + randomBytes(32).toString('hex'))
if (rand >= min) {
privKey = rand % SNARK_FIELD_SIZE
}
Expand Down Expand Up @@ -336,9 +336,9 @@ export const genKeypair = (): Keypair => {
const privKey = genPrivKey()
const pubKey = genPubKey(privKey)

const Keypair: Keypair = { privKey, pubKey }
const keypair: Keypair = { privKey, pubKey }

return Keypair
return keypair
}

/**
Expand Down
Loading

0 comments on commit 6c0ed97

Please sign in to comment.