Skip to content

Commit eb185e5

Browse files
Ho Nguyen PhamHo Nguyen Pham
authored andcommitted
refactor and add dynamic array
1 parent 00f3b41 commit eb185e5

File tree

8 files changed

+620
-419
lines changed

8 files changed

+620
-419
lines changed

.prettierrc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"semi": true,
3-
"singleQuote": true,
4-
"tabWidth": 4,
5-
"trailingComma": "es5"
2+
"semi": true,
3+
"singleQuote": true,
4+
"tabWidth": 2,
5+
"trailingComma": "es5"
66
}

src/Add.test.ts

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,58 +10,58 @@ import { Field, Mina, PrivateKey, PublicKey, AccountUpdate } from 'o1js';
1010

1111
let proofsEnabled = false;
1212

13-
describe('Add', () => {
14-
let deployerAccount: PublicKey,
15-
deployerKey: PrivateKey,
16-
senderAccount: PublicKey,
17-
senderKey: PrivateKey,
18-
zkAppAddress: PublicKey,
19-
zkAppPrivateKey: PrivateKey,
20-
zkApp: Add;
13+
// describe('Add', () => {
14+
// let deployerAccount: PublicKey,
15+
// deployerKey: PrivateKey,
16+
// senderAccount: PublicKey,
17+
// senderKey: PrivateKey,
18+
// zkAppAddress: PublicKey,
19+
// zkAppPrivateKey: PrivateKey,
20+
// zkApp: Add;
2121

22-
beforeAll(async () => {
23-
if (proofsEnabled) await Add.compile();
24-
});
22+
// beforeAll(async () => {
23+
// if (proofsEnabled) await Add.compile();
24+
// });
2525

26-
beforeEach(() => {
27-
const Local = Mina.LocalBlockchain({ proofsEnabled });
28-
Mina.setActiveInstance(Local);
29-
({ privateKey: deployerKey, publicKey: deployerAccount } =
30-
Local.testAccounts[0]);
31-
({ privateKey: senderKey, publicKey: senderAccount } =
32-
Local.testAccounts[1]);
33-
zkAppPrivateKey = PrivateKey.random();
34-
zkAppAddress = zkAppPrivateKey.toPublicKey();
35-
zkApp = new Add(zkAppAddress);
36-
});
26+
// beforeEach(() => {
27+
// const Local = Mina.LocalBlockchain({ proofsEnabled });
28+
// Mina.setActiveInstance(Local);
29+
// ({ privateKey: deployerKey, publicKey: deployerAccount } =
30+
// Local.testAccounts[0]);
31+
// ({ privateKey: senderKey, publicKey: senderAccount } =
32+
// Local.testAccounts[1]);
33+
// zkAppPrivateKey = PrivateKey.random();
34+
// zkAppAddress = zkAppPrivateKey.toPublicKey();
35+
// zkApp = new Add(zkAppAddress);
36+
// });
3737

38-
async function localDeploy() {
39-
const txn = await Mina.transaction(deployerAccount, () => {
40-
AccountUpdate.fundNewAccount(deployerAccount);
41-
zkApp.deploy();
42-
});
43-
await txn.prove();
44-
// this tx needs .sign(), because `deploy()` adds an account update that requires signature authorization
45-
await txn.sign([deployerKey, zkAppPrivateKey]).send();
46-
}
38+
// async function localDeploy() {
39+
// const txn = await Mina.transaction(deployerAccount, () => {
40+
// AccountUpdate.fundNewAccount(deployerAccount);
41+
// zkApp.deploy();
42+
// });
43+
// await txn.prove();
44+
// // this tx needs .sign(), because `deploy()` adds an account update that requires signature authorization
45+
// await txn.sign([deployerKey, zkAppPrivateKey]).send();
46+
// }
4747

48-
it('generates and deploys the `Add` smart contract', async () => {
49-
await localDeploy();
50-
const num = zkApp.num.get();
51-
expect(num).toEqual(Field(1));
52-
});
48+
// it('generates and deploys the `Add` smart contract', async () => {
49+
// await localDeploy();
50+
// const num = zkApp.num.get();
51+
// expect(num).toEqual(Field(1));
52+
// });
5353

54-
it('correctly updates the num state on the `Add` smart contract', async () => {
55-
await localDeploy();
54+
// it('correctly updates the num state on the `Add` smart contract', async () => {
55+
// await localDeploy();
5656

57-
// update transaction
58-
const txn = await Mina.transaction(senderAccount, () => {
59-
zkApp.update();
60-
});
61-
await txn.prove();
62-
await txn.sign([senderKey]).send();
57+
// // update transaction
58+
// const txn = await Mina.transaction(senderAccount, () => {
59+
// zkApp.update();
60+
// });
61+
// await txn.prove();
62+
// await txn.sign([senderKey]).send();
6363

64-
const updatedNum = zkApp.num.get();
65-
expect(updatedNum).toEqual(Field(3));
66-
});
67-
});
64+
// const updatedNum = zkApp.num.get();
65+
// expect(updatedNum).toEqual(Field(3));
66+
// });
67+
// });

src/CommitteeMember.test.ts

Lines changed: 72 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,77 @@
11
import { Field, Group, PrivateKey, PublicKey } from 'o1js';
22
import {
3-
CommitteeMember,
4-
Round1Contribution,
5-
Round2Contribution,
6-
SecretPolynomial,
7-
getMerkleWitnessType,
3+
Round1Contribution,
4+
Round2Contribution,
5+
SecretPolynomial,
86
} from './CommitteeMember';
9-
import { emptyWitness } from 'o1js/dist/node/lib/proof_system';
107

11-
describe('CommitteeMember', () => {
12-
let T = 3;
13-
let N = 5;
14-
let keyId = Field(0);
15-
let committees: {
16-
privateKey: PrivateKey;
17-
committeeMember: CommitteeMember;
18-
secretPolynomial: SecretPolynomial;
19-
round1Contribution: Round1Contribution | any;
20-
round2Contribution: Round2Contribution | any;
21-
}[] = [];
22-
let round1Contributions: Round1Contribution[] = [];
23-
let publicKey: PublicKey;
24-
let w = {
25-
isLeft: false,
26-
sibling: Field(0),
27-
};
28-
let dummyWitness = Array.from(Array(10).keys()).map(() => w);
29-
beforeAll(async () => {
30-
for (let i = 0; i < N; i++) {
31-
let privateKey = PrivateKey.random();
32-
let committeeMember = new CommitteeMember({
33-
publicKey: privateKey.toPublicKey(),
34-
index: i + 1,
35-
T: T,
36-
N: N,
37-
witness: new (getMerkleWitnessType(10))(dummyWitness),
38-
});
39-
let secretPolynomial = committeeMember.getRandomPolynomial();
40-
let round1Contribution = committeeMember.getRound1Contribution(
41-
secretPolynomial,
42-
keyId
43-
);
44-
round1Contributions.push(round1Contribution);
45-
committees.push({
46-
privateKey: privateKey,
47-
committeeMember: committeeMember,
48-
secretPolynomial: secretPolynomial,
49-
round1Contribution: round1Contribution,
50-
round2Contribution: null,
51-
});
52-
}
8+
// describe('CommitteeMember', () => {
9+
// let T = 3;
10+
// let N = 5;
11+
// let keyId = Field(0);
12+
// let committees: {
13+
// privateKey: PrivateKey;
14+
// committeeMember: CommitteeMember;
15+
// secretPolynomial: SecretPolynomial;
16+
// round1Contribution: Round1Contribution | any;
17+
// round2Contribution: Round2Contribution | any;
18+
// }[] = [];
19+
// let round1Contributions: Round1Contribution[] = [];
20+
// let publicKey: PublicKey;
21+
// let w = {
22+
// isLeft: false,
23+
// sibling: Field(0),
24+
// };
25+
// let dummyWitness = Array.from(Array(10).keys()).map(() => w);
26+
// beforeAll(async () => {
27+
// for (let i = 0; i < N; i++) {
28+
// let privateKey = PrivateKey.random();
29+
// let committeeMember = new CommitteeMember({
30+
// publicKey: privateKey.toPublicKey(),
31+
// index: i + 1,
32+
// T: T,
33+
// N: N,
34+
// witness: new (getMerkleWitnessType(10))(dummyWitness),
35+
// });
36+
// let secretPolynomial = committeeMember.getRandomPolynomial();
37+
// let round1Contribution = committeeMember.getRound1Contribution(
38+
// secretPolynomial,
39+
// keyId
40+
// );
41+
// round1Contributions.push(round1Contribution);
42+
// committees.push({
43+
// privateKey: privateKey,
44+
// committeeMember: committeeMember,
45+
// secretPolynomial: secretPolynomial,
46+
// round1Contribution: round1Contribution,
47+
// round2Contribution: null,
48+
// });
49+
// }
5350

54-
publicKey = CommitteeMember.getPublicKey(round1Contributions);
55-
console.log(publicKey.x.toBigInt());
56-
console.log(publicKey.toJSON());
57-
});
58-
it('Test Key Generation', async () => {
59-
let m = 1;
60-
// for (let i = 0; i < N; i++) {
61-
// let senderIndex = i + 1;
62-
// let publicKeys: Group[] = [];
63-
// for (let j = 0; j < N; j++) {
64-
// let recipientIndex = j + 1;
65-
// if (senderIndex != recipientIndex) {
66-
// publicKeys.push(
67-
// committees[j].privateKey.toPublicKey().toGroup()
68-
// );
69-
// }
70-
// }
71-
// let round2Contribution = committees[
72-
// i
73-
// ].committeeMember.getRound2Contribution(
74-
// committees[i].secretPolynomial,
75-
// publicKeys,
76-
// keyId
77-
// );
78-
// }
79-
});
80-
});
51+
// publicKey = CommitteeMember.getPublicKey(round1Contributions);
52+
// console.log(publicKey.x.toBigInt());
53+
// console.log(publicKey.toJSON());
54+
// });
55+
// it('Test Key Generation', async () => {
56+
// let m = 1;
57+
// // for (let i = 0; i < N; i++) {
58+
// // let senderIndex = i + 1;
59+
// // let publicKeys: Group[] = [];
60+
// // for (let j = 0; j < N; j++) {
61+
// // let recipientIndex = j + 1;
62+
// // if (senderIndex != recipientIndex) {
63+
// // publicKeys.push(
64+
// // committees[j].privateKey.toPublicKey().toGroup()
65+
// // );
66+
// // }
67+
// // }
68+
// // let round2Contribution = committees[
69+
// // i
70+
// // ].committeeMember.getRound2Contribution(
71+
// // committees[i].secretPolynomial,
72+
// // publicKeys,
73+
// // keyId
74+
// // );
75+
// // }
76+
// });
77+
// });

0 commit comments

Comments
 (0)