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

chore: update unirep version #490

Merged
merged 3 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/circuits/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@types/snarkjs": "^0.7.7",
"@unirep/core": "2.0.0",
"@unirep/core": "2.1.3",
"poseidon-lite": "^0.2.0"
}
}
2 changes: 1 addition & 1 deletion packages/contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@typechain/hardhat": "^6.1.5",
"@types/node": "^18.15.11",
"@unirep-app/circuits": "^1.1.0",
"@unirep/contracts": "2.0.0",
"@unirep/contracts": "2.1.3",
"envfile": "^6.18.0",
"hardhat": "^2.17.1",
"ts-node": "^10.9.1",
Expand Down
7 changes: 4 additions & 3 deletions packages/contracts/test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@ts-ignore
import { ethers } from 'hardhat'
import { Identity } from '@semaphore-protocol/identity'
import {
defaultProver,
Expand All @@ -11,13 +10,15 @@ import {
EpochKeyLiteProof,
EpochKeyProof,
} from '@unirep/circuits'
import { UserState, schema } from '@unirep/core'
import { UserState, userSchema as schema } from '@unirep/core'
import { IncrementalMerkleTree, stringifyBigInts } from '@unirep/utils'
import { SQLiteConnector } from 'anondb/node'
import crypto from 'crypto'
import { ethers } from 'hardhat'

import { poseidon1, poseidon2 } from 'poseidon-lite'
import { IdentityObject } from './types'
import { ProofGenerationError } from './error'
import { IdentityObject } from './types'

const { FIELD_COUNT, SUM_FIELD_COUNT } = CircuitConfig.default

Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@tanstack/react-table": "^8.17.3",
"@uidotdev/usehooks": "^2.4.1",
"@unirep-app/circuits": "^1.1.0",
"@unirep/core": "^2.0.1",
"@unirep/core": "2.1.3",
"anondb": "^0.0.21",
"axios": "^1.7.2",
"boring-avatars": "^1.10.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/utils/schema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { schema as syncSchema } from '@unirep/core'
import { userSchema as syncSchema } from '@unirep/core'
import { TableData } from 'anondb'

const _schema = [
Expand Down
2 changes: 1 addition & 1 deletion packages/relay/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@typechain/hardhat": "^9.1.0",
"@types/crypto-js": "^4.1.1",
"@unirep-app/contracts": "^1.0.0",
"@unirep/core": "2.0.0",
"@unirep/core": "2.1.3",
"cors": "^2.8.5",
"dotenv": "^16.0.3",
"express": "^4.18.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/relay/test/checkReputation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('CheckReputation', function () {
})

it('should pass the check reputation middleware with positive reputation', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
const epoch = await sync.loadCurrentEpoch()
const minRep = 2
const proveMinRep = 1
Expand Down Expand Up @@ -103,7 +103,7 @@ describe('CheckReputation', function () {
})

it('should fail the check reputation middleware with negative reputation', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
const epoch = await sync.loadCurrentEpoch()
const maxRep = 4
const proveMaxRep = 1
Expand Down Expand Up @@ -155,7 +155,7 @@ describe('CheckReputation', function () {
})

it('should fail the check reputation middleware with wrong reputation proof', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
const epoch = await sync.loadCurrentEpoch()
const minRep = 2
const proveMinRep = 1
Expand Down Expand Up @@ -206,7 +206,7 @@ describe('CheckReputation', function () {
})

it('should fail the check reputation middleware without authentication', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
const testContent = 'test content'

const epochKeyProof = await userState.genEpochKeyProof({
Expand Down
4 changes: 2 additions & 2 deletions packages/relay/test/checkin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('POST /api/checkin', function () {
})

it('should allow users with negative reputation to claim reputation', async function () {
const userState = await genUserState(users[0].id, sync, app, db, prover)
const userState = await genUserState(users[0].id, app, prover)
await airdropReputation(false, 1, userState, unirep, express, provider)

const { publicSignals, _snarkProof: proof } =
Expand Down Expand Up @@ -96,7 +96,7 @@ describe('POST /api/checkin', function () {
})

it('should fail if users with non-negative reputation tries to claim reputation', async function () {
const userState = await genUserState(users[0].id, sync, app, db, prover)
const userState = await genUserState(users[0].id, app, prover)
await airdropReputation(true, 2, userState, unirep, express, provider)
const { publicSignals, _snarkProof: proof } =
await userState.genProveReputationProof({ minRep: 1 })
Expand Down
12 changes: 6 additions & 6 deletions packages/relay/test/comment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('COMMENT /comment', function () {
})

it('should create a comment', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
testContent = 'create comment'
const { createHelia } = await eval("import('helia')")
const helia = await createHelia()
Expand Down Expand Up @@ -166,7 +166,7 @@ describe('COMMENT /comment', function () {
})

it('should comment failed with wrong proof', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
testContent = 'comment with wrong proof'
const epochKeyProof = await userState.genEpochKeyProof({
nonce: 2,
Expand All @@ -193,7 +193,7 @@ describe('COMMENT /comment', function () {
})

it('should comment failed with wrong epoch', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
testContent = 'comment with wrong epoch'
// generating a proof with wrong epoch
const wrongEpoch = 44444
Expand Down Expand Up @@ -236,7 +236,7 @@ describe('COMMENT /comment', function () {
})

it('delete the comment failed with wrong proof', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
const epochKeyLiteProof = await userState.genEpochKeyLiteProof({
nonce: 1,
})
Expand Down Expand Up @@ -264,7 +264,7 @@ describe('COMMENT /comment', function () {
})

it('delete the comment failed with wrong epoch key', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
const epochKeyLiteProof = await userState.genEpochKeyLiteProof({
nonce: 2,
})
Expand All @@ -289,7 +289,7 @@ describe('COMMENT /comment', function () {
})

it('delete the comment success', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
const epochKeyLiteProof = await userState.genEpochKeyLiteProof({
nonce: 1,
})
Expand Down
4 changes: 2 additions & 2 deletions packages/relay/test/counter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('GET /counter', function () {
})

it('should add the counter number increment after the user posted', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
let txHash = await post(express, userState, authentication)
await provider.waitForTransaction(txHash)
await sync.waitForSync()
Expand All @@ -79,7 +79,7 @@ describe('GET /counter', function () {
})

it('should counter failed if number of epks is not 3', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
// one epoch key
const epochKeys = (
userState.getEpochKeys(undefined, 0) as bigint
Expand Down
12 changes: 6 additions & 6 deletions packages/relay/test/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('LOGIN /login', function () {
prepareUserLoginTwitterApiMock(userId, mockCode, 'access-token')
const user = await userService.getLoginUser(db, userId, 'access-token')
const identity = new Identity(user.hashUserId)
const userState = await genUserState(identity, sync, app, db, prover)
const userState = await genUserState(identity, app, prover)
const { publicSignals, _snarkProof: proof } =
await userState.genUserSignUpProof()

Expand All @@ -167,7 +167,7 @@ describe('LOGIN /login', function () {
const userId = users[0].id.toString()
prepareUserLoginTwitterApiMock(userId, mockCode, 'access-token')
const user = await userService.getLoginUser(db, userId, 'access-token')
const userState = await genUserState(users[0].id, sync, app, db, prover)
const userState = await genUserState(users[0].id, app, prover)
const { publicSignals, _snarkProof: proof } =
await userState.genUserSignUpProof()

Expand Down Expand Up @@ -199,7 +199,7 @@ describe('LOGIN /login', function () {
prepareUserLoginTwitterApiMock(userId, mockCode, 'access-token')
const user = await userService.getLoginUser(db, userId, 'access-token')

const userState = await genUserState(users[0].id, sync, app, db, prover)
const userState = await genUserState(users[0].id, app, prover)
const { publicSignals, _snarkProof: proof } =
await userState.genUserSignUpProof()

Expand All @@ -219,7 +219,7 @@ describe('LOGIN /login', function () {
prepareUserLoginTwitterApiMock(userId, mockCode, 'access-token')
const user = await userService.getLoginUser(db, userId, 'access-token')

const userState = await genUserState(users[1].id, sync, app, db, prover)
const userState = await genUserState(users[1].id, app, prover)
const {
publicSignals,
_snarkProof: proof,
Expand Down Expand Up @@ -252,7 +252,7 @@ describe('LOGIN /login', function () {
const userId = users[1].id.toString()
prepareUserLoginTwitterApiMock(userId, mockCode, 'access-token')
const user = await userService.getLoginUser(db, userId, 'access-token')
const userState = await genUserState(users[1].id, sync, app, db, prover)
const userState = await genUserState(users[1].id, app, prover)
const { publicSignals, _snarkProof: proof } =
await userState.genUserSignUpProof()

Expand Down Expand Up @@ -282,7 +282,7 @@ describe('LOGIN /login', function () {
const userId = users[0].id.toString()
prepareUserLoginTwitterApiMock(userId, mockCode, 'access-token')
const user = await userService.getLoginUser(db, userId, 'access-token')
const userState = await genUserState(users[0].id, sync, app, db, prover)
const userState = await genUserState(users[0].id, app, prover)
const { publicSignals, _snarkProof: proof } =
await userState.genUserSignUpProof()

Expand Down
8 changes: 4 additions & 4 deletions packages/relay/test/post.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('POST /post', function () {
})

it('should create a post', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
// FIXME: Look for fuzzer to test content
const testContent = 'test content #0'
// cid of test content
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('POST /post', function () {
})

it('should post failed with wrong proof', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
const testContent = 'test content'

var epochKeyProof = await userState.genEpochKeyProof({
Expand All @@ -176,7 +176,7 @@ describe('POST /post', function () {
})

it('should post failed with wrong epoch', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
const testContent = 'invalid epoch'

// generating a proof with wrong epoch
Expand Down Expand Up @@ -281,7 +281,7 @@ describe('POST /post', function () {
})

it('should fetch posts which are already on-chain', async function () {
const userState = await genUserState(user.id, sync, app, db, prover)
const userState = await genUserState(user.id, app, prover)
// send a post
const txHash = await post(express, userState, authentication)
// update the cache, the amount of posts is still 10
Expand Down
26 changes: 13 additions & 13 deletions packages/relay/test/report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('POST /api/report', function () {

it('should create a report and update post status', async function () {
const postId = '0'
const userState = await genUserState(users[0].id, sync, app, db, prover)
const userState = await genUserState(users[0].id, app, prover)
const reportData: ReportHistory = {
type: ReportType.POST,
objectId: postId,
Expand Down Expand Up @@ -195,7 +195,7 @@ describe('POST /api/report', function () {
})

it('should fail to create a report with invalid proof', async function () {
const userState = await genUserState(users[0].id, sync, app, db, prover)
const userState = await genUserState(users[0].id, app, prover)
const reportData: ReportHistory = {
type: ReportType.COMMENT,
objectId: '0',
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('POST /api/report', function () {

it('should create a report and update comment status', async function () {
const commentId = '0'
const userState = await genUserState(users[0].id, sync, app, db, prover)
const userState = await genUserState(users[0].id, app, prover)
const reportData: ReportHistory = {
type: ReportType.COMMENT,
objectId: commentId,
Expand Down Expand Up @@ -299,7 +299,7 @@ describe('POST /api/report', function () {
})

it('should fail to create a report on the same post / comment', async function () {
const userState = await genUserState(users[0].id, sync, app, db, prover)
const userState = await genUserState(users[0].id, app, prover)
const reportData: ReportHistory = {
type: ReportType.POST,
objectId: '0',
Expand Down Expand Up @@ -332,7 +332,7 @@ describe('POST /api/report', function () {
})

it('should fail to create a report with non-existent post/comment', async function () {
const userState = await genUserState(users[0].id, sync, app, db, prover)
const userState = await genUserState(users[0].id, app, prover)
const reportData: ReportHistory = {
type: ReportType.POST,
objectId: 'non-existent',
Expand Down Expand Up @@ -365,7 +365,7 @@ describe('POST /api/report', function () {
})

it('should get empty report list if reportEpoech is equal to currentEpoch', async function () {
const userState = await genUserState(users[0].id, sync, app, db, prover)
const userState = await genUserState(users[0].id, app, prover)
const { publicSignals, proof } = await userState.genEpochKeyLiteProof({
nonce,
})
Expand Down Expand Up @@ -576,7 +576,7 @@ describe('POST /api/report', function () {
})

it('should vote agree on the report', async function () {
const userState = await genUserState(users[0].id, sync, app, db, prover)
const userState = await genUserState(users[0].id, app, prover)
const report = await db.findOne('ReportHistory', {
where: {
AND: [{ objectId: '0' }, { type: ReportType.COMMENT }],
Expand Down Expand Up @@ -630,7 +630,7 @@ describe('POST /api/report', function () {
})

it('should vote disagree on the report', async function () {
const userState = await genUserState(users[1].id, sync, app, db, prover)
const userState = await genUserState(users[1].id, app, prover)
const report = await db.findOne('ReportHistory', {
where: {
AND: [{ objectId: '0' }, { type: ReportType.COMMENT }],
Expand Down Expand Up @@ -687,7 +687,7 @@ describe('POST /api/report', function () {
})

it('should fail if report identity proof is wrong', async function () {
const userState = await genUserState(users[2].id, sync, app, db, prover)
const userState = await genUserState(users[2].id, app, prover)
const report = await db.findOne('ReportHistory', {
where: {
AND: [{ objectId: '0' }, { type: ReportType.COMMENT }],
Expand Down Expand Up @@ -732,7 +732,7 @@ describe('POST /api/report', function () {
})

it('should fail if report does not exist', async function () {
const userState = await genUserState(users[2].id, sync, app, db, prover)
const userState = await genUserState(users[2].id, app, prover)
const notExistReportId = '444'
const nullifier = genReportNullifier(users[2].id, notExistReportId)
const toEpoch = await userStateTransition(userState, {
Expand Down Expand Up @@ -770,7 +770,7 @@ describe('POST /api/report', function () {
})

it('should fail if vote invalid adjudicate value', async function () {
const userState = await genUserState(users[2].id, sync, app, db, prover)
const userState = await genUserState(users[2].id, app, prover)
const wrongAdjucateValue = 'wrong'

const report = await db.findOne('ReportHistory', {
Expand Down Expand Up @@ -815,7 +815,7 @@ describe('POST /api/report', function () {
})

it('should fail if vote on the report with same nullifier', async function () {
const userState = await genUserState(users[0].id, sync, app, db, prover)
const userState = await genUserState(users[0].id, app, prover)
const report = await db.findOne('ReportHistory', {
where: {
AND: [{ objectId: '0' }, { type: ReportType.COMMENT }],
Expand Down Expand Up @@ -857,7 +857,7 @@ describe('POST /api/report', function () {
})

it('should fail if vote on the report whose status is not VOTING', async function () {
const userState = await genUserState(users[2].id, sync, app, db, prover)
const userState = await genUserState(users[2].id, app, prover)
const watingForTxReport = await db.findOne('ReportHistory', {
where: {
AND: [{ objectId: '0' }, { type: ReportType.POST }],
Expand Down
Loading
Loading