Skip to content

Commit

Permalink
Merge pull request #2 from ZkNoid/one_round_contract
Browse files Browse the repository at this point in the history
One round contract
  • Loading branch information
aii23 authored Oct 9, 2024
2 parents e985f1f + d56737f commit 023a9d0
Show file tree
Hide file tree
Showing 35 changed files with 2,610 additions and 2,743 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ coverage
# System
.DS_Store

# Deploy info. Consist private keys and other sensitive data.
deployV2

# Never commit keys to Git!
keys

Expand Down
2 changes: 1 addition & 1 deletion random_request_cid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bafkreif2ett25ddjcevhnmaxmimkjdoigtsaj6bfyfil5gu65l2r6luxqm
bafkreicnannsz4gqqk3ccfwfd3z2hfzonr63z3hgsplefgrmz37psay23y
6 changes: 3 additions & 3 deletions random_request_file

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions scripts/analyze.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { getPLottery } from '../src/PLottery.js';
import { DistributionProgram } from '../src/Proofs/DistributionProof.js';
import { writeFileSync } from 'fs';
import { PublicKey } from 'o1js';
import { findPlottery } from './utils.js';
// import { getPLottery } from '../src/PLottery.js';
// import { DistributionProgram } from '../src/Proofs/DistributionProof.js';
// import { writeFileSync } from 'fs';
// import { PublicKey } from 'o1js';
// import { findPlottery } from './utils.js';

let { PLottery } = findPlottery();
// let { PLottery } = findPlottery();

const lotteryResult = await PLottery.analyzeMethods();
const distributionResult = await DistributionProgram.analyzeMethods();
// const lotteryResult = await PLottery.analyzeMethods();
// const distributionResult = await DistributionProgram.analyzeMethods();

if (!PLottery._methods) {
console.log("Can't find methods for Lottery");
throw new Error("Can't find methods for Lottery");
}
// if (!PLottery._methods) {
// console.log("Can't find methods for Lottery");
// throw new Error("Can't find methods for Lottery");
// }

let result: { [name: string]: number } = {};
// let result: { [name: string]: number } = {};

for (const method of PLottery._methods) {
result[`Lottery_${method.methodName}`] =
lotteryResult[method.methodName].rows;
}
// for (const method of PLottery._methods) {
// result[`Lottery_${method.methodName}`] =
// lotteryResult[method.methodName].rows;
// }

result[`DistributionProof_init`] = distributionResult.init.rows;
result[`DistibutionProof_addTicket`] = distributionResult.addTicket.rows;
// result[`DistributionProof_init`] = distributionResult.init.rows;
// result[`DistibutionProof_addTicket`] = distributionResult.addTicket.rows;

console.log(result);
// console.log(result);

writeFileSync('analyze_result.json', JSON.stringify(result, null, 2));
// writeFileSync('analyze_result.json', JSON.stringify(result, null, 2));
44 changes: 22 additions & 22 deletions scripts/call_zkon.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
import { Field, Mina, Poseidon } from 'o1js';
import { RandomManagerManager } from '../src/StateManager/RandomManagerManager';
import {
compileRandomManager,
configDefaultInstance,
findPlottery,
findRandomManager,
getDeployer,
getRMStoreManager,
storeRMStoreManager,
} from './utils';
import { CommitValue } from '../src/Random/RandomManager';
// import { Field, Mina, Poseidon } from 'o1js';
// import { RandomManagerManager } from '../src/StateManager/RandomManagerManager';
// import {
// compileRandomManager,
// configDefaultInstance,
// findPlottery,
// findRandomManager,
// getDeployer,
// getRMStoreManager,
// storeRMStoreManager,
// } from './utils';
// import { CommitValue } from '../src/Random/RandomManager';

configDefaultInstance();
// configDefaultInstance();

let deploy_epoch = process.argv[2] ? process.argv[2] : 'current';
// let deploy_epoch = process.argv[2] ? process.argv[2] : 'current';

let { deployer, deployerKey } = getDeployer();
// let { deployer, deployerKey } = getDeployer();

let { randomManager } = findRandomManager(deploy_epoch);
// let { randomManager } = findRandomManager(deploy_epoch);

await compileRandomManager(deploy_epoch);
// await compileRandomManager(deploy_epoch);

let tx = await Mina.transaction(deployer, async () => {
await randomManager.callZkon();
});
// let tx = await Mina.transaction(deployer, async () => {
// await randomManager.callZkon();
// });

await tx.prove();
await tx.sign([deployerKey]).send();
// await tx.prove();
// await tx.sign([deployerKey]).send();
66 changes: 33 additions & 33 deletions scripts/commit_value.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,47 @@
import { Field, Mina } from 'o1js';
import { RandomManagerManager } from '../src/StateManager/RandomManagerManager';
import {
compileRandomManager,
configDefaultInstance,
findPlottery,
findRandomManager,
getDeployer,
getRMStoreManager,
storeRMStoreManager,
} from './utils';
import { CommitValue } from '../src/Random/RandomManager';
// import { Field, Mina } from 'o1js';
// import { RandomManagerManager } from '../src/StateManager/RandomManagerManager';
// import {
// compileRandomManager,
// configDefaultInstance,
// findPlottery,
// findRandomManager,
// getDeployer,
// getRMStoreManager,
// storeRMStoreManager,
// } from './utils';
// import { CommitValue } from '../src/Random/RandomManager';

configDefaultInstance();
// configDefaultInstance();

let round = process.argv[2];
// let round = process.argv[2];

if (!round) {
throw Error(`You should specify round`);
}
// if (!round) {
// throw Error(`You should specify round`);
// }

let deploy_epoch = process.argv[3] ? process.argv[3] : 'current';
// let deploy_epoch = process.argv[3] ? process.argv[3] : 'current';

let { deployer, deployerKey } = getDeployer();
// let { deployer, deployerKey } = getDeployer();

let { randomManager } = findRandomManager(deploy_epoch);
// let { randomManager } = findRandomManager(deploy_epoch);

await compileRandomManager(deploy_epoch);
// await compileRandomManager(deploy_epoch);

let rmStoreManager: RandomManagerManager = getRMStoreManager(deploy_epoch);
// let rmStoreManager: RandomManagerManager = getRMStoreManager(deploy_epoch);

let value = Field.random();
let salt = Field.random();
let commitValue = new CommitValue({ value, salt });
// let value = Field.random();
// let salt = Field.random();
// let commitValue = new CommitValue({ value, salt });

const { witness: commitRoundWitness } = rmStoreManager.getCommitWitness(+round);
// const { witness: commitRoundWitness } = rmStoreManager.getCommitWitness(+round);

let tx = await Mina.transaction(deployer, async () => {
await randomManager.commit(commitValue, commitRoundWitness);
});
// let tx = await Mina.transaction(deployer, async () => {
// await randomManager.commit(commitValue, commitRoundWitness);
// });

await tx.prove();
await tx.sign([deployerKey]).send();
// await tx.prove();
// await tx.sign([deployerKey]).send();

rmStoreManager.addCommit(+round, commitValue);
// rmStoreManager.addCommit(+round, commitValue);

storeRMStoreManager(rmStoreManager, deploy_epoch);
// storeRMStoreManager(rmStoreManager, deploy_epoch);
Loading

0 comments on commit 023a9d0

Please sign in to comment.