maci icon indicating copy to clipboard operation
maci copied to clipboard

Test TallyVotes.test.ts fails

Open Subway2023 opened this issue 1 year ago • 12 comments

Steps to Reproduce

cd circuits
npm install
npx jest __tests__/TallyVotes.test.ts

Failure Logs


    /mnt/sdd1/sbw/circom/ZKAP_docker/sbwTest/benchmarks/maci-4892ada0dc7bcc2f7710aea917e309f1553317c5/circuits/node_modules/@zk-kit/poseidon-cipher/dist/index.js:9
    import { Fr, r } from '@zk-kit/baby-jubjub';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
      at Object.<anonymous> (node_modules/maci-crypto/ts/hashing.ts:1:1)

Subway2023 avatar Sep 29 '24 16:09 Subway2023

Steps to Reproduce

cd circuits
npm install
npx jest __tests__/TallyVotes.test.ts

Failure Logs


    /mnt/sdd1/sbw/circom/ZKAP_docker/sbwTest/benchmarks/maci-4892ada0dc7bcc2f7710aea917e309f1553317c5/circuits/node_modules/@zk-kit/poseidon-cipher/dist/index.js:9
    import { Fr, r } from '@zk-kit/baby-jubjub';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
      at Object.<anonymous> (node_modules/maci-crypto/ts/hashing.ts:1:1)

So those tests are not meant to be run with Jest, you can run that particular one using pnpm test:tallyVotes - lmk if that works @Subway2023

Also make sure you are using pnpm and installing and building before running tests. In the monorepo root: pnpm install && pnpm build

ctrlc03 avatar Sep 30 '24 20:09 ctrlc03

Steps to Reproduce

cd circuits
npm install
npx jest __tests__/TallyVotes.test.ts

Failure Logs


    /mnt/sdd1/sbw/circom/ZKAP_docker/sbwTest/benchmarks/maci-4892ada0dc7bcc2f7710aea917e309f1553317c5/circuits/node_modules/@zk-kit/poseidon-cipher/dist/index.js:9
    import { Fr, r } from '@zk-kit/baby-jubjub';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
      at Object.<anonymous> (node_modules/maci-crypto/ts/hashing.ts:1:1)

So those tests are not meant to be run with Jest, you can run that particular one using pnpm test:tallyVotes - lmk if that works @Subway2023

Also make sure you are using pnpm and installing and building before running tests. In the monorepo root: pnpm install && pnpm build

According to your method, I still cannot run it, and the above error persists. I am running an older version of the project, which has a bug: Initial Conditions Are Not Properly Enforced so I want to conduct tests. The old version includes a jest.config.js file, so I suspect it uses the Jest framework. However, I still haven't successfully run TallyVotes.test.ts.

Subway2023 avatar Oct 01 '24 04:10 Subway2023

Steps to Reproduce

cd circuits
npm install
npx jest __tests__/TallyVotes.test.ts

Failure Logs


    /mnt/sdd1/sbw/circom/ZKAP_docker/sbwTest/benchmarks/maci-4892ada0dc7bcc2f7710aea917e309f1553317c5/circuits/node_modules/@zk-kit/poseidon-cipher/dist/index.js:9
    import { Fr, r } from '@zk-kit/baby-jubjub';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1350:14)
      at Object.<anonymous> (node_modules/maci-crypto/ts/hashing.ts:1:1)

So those tests are not meant to be run with Jest, you can run that particular one using pnpm test:tallyVotes - lmk if that works @Subway2023 Also make sure you are using pnpm and installing and building before running tests. In the monorepo root: pnpm install && pnpm build

According to your method, I still cannot run it, and the above error persists. I am running an older version of the project, which has a bug: Initial Conditions Are Not Properly Enforced so I want to conduct tests. The old version includes a jest.config.js file, so I suspect it uses the Jest framework. However, I still haven't successfully run TallyVotes.test.ts.

@Subway2023 I see, but based on the stack trace it doesn't look like you are running that old version, at the time the project was not using @zk-kit/baby-jubjub so it could not error out there. Could you share the full instructions on how to reproduce it please?

ctrlc03 avatar Oct 01 '24 07:10 ctrlc03

cd circuits
npm install

npx jest TallyVotes.test.ts
1727767797569

commad (npx jest TallyVotes.test.ts) comes from the testing program in the project.

Subway2023 avatar Oct 01 '24 07:10 Subway2023

cd circuits
npm install

npx jest TallyVotes.test.ts
1727767797569 commad (npx jest TallyVotes.test.ts) comes from the testing program in the project.

Let's take a step back, did you clone the repo and checked out to a specific commit, a pr? did you install the package from npm? Knowing that would allow me to try it out too

ctrlc03 avatar Oct 01 '24 07:10 ctrlc03

i just download this commit and perform above commands.

Subway2023 avatar Oct 01 '24 07:10 Subway2023

i just download this commit and perform above commands.

ok so first you need to install the packages and build the monorepo. Also you'd need to install these libraries https://github.com/privacy-scaling-explorations/maci/blob/4bc217db24f573c1da5e24ad0caca596637c3dc8/.travis.yml#L7

You can see the steps required to make that specific version working in this file https://github.com/privacy-scaling-explorations/maci/blob/4bc217db24f573c1da5e24ad0caca596637c3dc8/.travis.yml

You can https://github.com/privacy-scaling-explorations/maci/blob/4bc217db24f573c1da5e24ad0caca596637c3dc8/.travis.yml#L11-L14 Then https://github.com/privacy-scaling-explorations/maci/blob/4bc217db24f573c1da5e24ad0caca596637c3dc8/circuits/scripts/runTestsInCi.sh#L6 Then ( no need for && ofc) https://github.com/privacy-scaling-explorations/maci/blob/4bc217db24f573c1da5e24ad0caca596637c3dc8/circuits/scripts/runTestsInCi.sh#L10

ctrlc03 avatar Oct 01 '24 07:10 ctrlc03

my commands are as follows:

npm i 
npm run bootstrap 
npm run build 
cd circuits
npm i

npm run circom-helper & npx jest TallyVotes.test.ts

however there is still errors:

    /mnt/sdd1/sbw/circom/ZKAP_docker/sbwTest/benchmarks/maci-4bc217db24f573c1da5e24ad0caca596637c3dc8/circuits/node_modules/@zk-kit/poseidon-cipher/dist/index.js:9
    import { Fr, r } from '@zk-kit/baby-jubjub';
    ^^^^^^

Please try and start from a clean checkout of that branch, make sure to remove any node_modules you might have. Cause that error is coming from a library that was introduced this year, but the code you are trying to run is from years ago so there must be something stored locally. Also do not run run again npm i after you cd circuits

ctrlc03 avatar Oct 01 '24 18:10 ctrlc03

Thank you very much! it works.

Subway2023 avatar Oct 08 '24 15:10 Subway2023

Why can't TallyVotes.test.ts pass the tests?

npx jest TallyVotes.test.ts

 FAIL  ts/__tests__/TallyVotes.test.ts (15.032 s)
  TallyVotes circuit
    1 user, 2 messages
      ✕ should produce the correct result commitments (4263 ms)
    10 users, 10 messages
      ✕ should produce the correct state root and ballot root (8029 ms)

  ● TallyVotes circuit › 1 user, 2 messages › should produce the correct result commitments

    Request failed with status code 503

However, if I get the generatedInputs from TallyVotes.test.ts, generate the witness, and perform the checks, it works successfully. Test is my test script

Subway2023 avatar Oct 09 '24 08:10 Subway2023

Why can't TallyVotes.test.ts pass the tests?

npx jest TallyVotes.test.ts

 FAIL  ts/__tests__/TallyVotes.test.ts (15.032 s)
  TallyVotes circuit
    1 user, 2 messages
      ✕ should produce the correct result commitments (4263 ms)
    10 users, 10 messages
      ✕ should produce the correct state root and ballot root (8029 ms)

  ● TallyVotes circuit › 1 user, 2 messages › should produce the correct result commitments

    Request failed with status code 503

However, if I get the generatedInputs from TallyVotes.test.ts, generate the witness, and perform the checks, it works successfully. Test is my test script

hey sorry just getting back to work today, will try and find some time to run through this. have you got any updates on this since 2 weeks ago?

ctrlc03 avatar Oct 20 '24 09:10 ctrlc03

Thank you for your reply. I currently have no new progress. My goal is to execute TallyVotes.test.ts to obtain the inputs for tallyVotes.circom in order to reproduce the vulnerability of Initial Conditions Are Not Properly Enforced. Please refer to the issue. I would greatly appreciate any help you can provide on this matter.

Subway2023 avatar Oct 20 '24 09:10 Subway2023

Hey sorry to come back to this so late. Have you managed to make any progress?

ctrlc03 avatar Mar 14 '25 16:03 ctrlc03