Skip to content

Commit

Permalink
Removed commented lines
Browse files Browse the repository at this point in the history
  • Loading branch information
aii23 committed Sep 26, 2024
1 parent e242f65 commit e10620a
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 64 deletions.
46 changes: 3 additions & 43 deletions src/PLottery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,15 +403,13 @@ export function getPLottery(
resultWitness: MerkleMap20Witness,
bankValue: Field,
bankWitness: MerkleMap20Witness
// nullifierWitness: MerkleMapWitness
) {
// Check that owner trying to claim
ticket.owner.assertEquals(this.sender.getAndRequireSignature());

// Check ticket in merkle map and set ticket to zero
const { ticketId, round } = this.checkAndUpdateTicket(
const { round } = this.checkAndUpdateTicket(
roundWitness,
// null,
roundTicketWitness,
ticket.hash(),
Field(0)
Expand Down Expand Up @@ -488,12 +486,7 @@ export function getPLottery(
ticketId,
roundRoot: roundTicketRoot,
round,
} = this.checkTicket(
roundWitness,
// null,
roundTicketWitness,
ticket.hash()
);
} = this.checkTicket(roundWitness, roundTicketWitness, ticket.hash());

dp.publicOutput.root.assertEquals(
roundTicketRoot,
Expand Down Expand Up @@ -605,12 +598,6 @@ export function getPLottery(
);
}

// public getWiningNumbersForRound(): UInt32[] {
// return mockWinningCombination.map((val) => UInt32.from(val));
// // // Temporary function implementation. Later will be switch with oracle call.
// // return generateNumbersSeed(Field(12345));
// }

/**
* @notice Check validity of merkle map witness for result tree.
*
Expand All @@ -628,21 +615,6 @@ export function getPLottery(
return this.checkMap(this.roundResultRoot, witness, round, curValue);
}

// private checkAndUpdateResult(
// witness: MerkleMap20Witness,
// round: Field,
// curValue: Field,
// newValue: Field
// ): MerkleCheckResult {
// return this.checkAndUpdateMap(
// this.roundResultRoot,
// witness,
// round,
// curValue,
// newValue
// );
// }

/**
* @notice Check validity of merkle map witness for bank tree.
*
Expand Down Expand Up @@ -765,18 +737,11 @@ export function getPLottery(

public checkAndUpdateTicket(
firstWitness: MerkleMap20Witness | MerkleMapWitness,
// key1: Field | null,
secondWitness: MerkleMap20Witness | MerkleMapWitness,
// key2: Field, For know second level key is not checked as later it would transform to merkle map
prevValue: Field,
newValue: Field
): { ticketId: Field; round: Field } {
const res = this.checkTicket(
firstWitness,
// key1,
secondWitness,
prevValue
);
const res = this.checkTicket(firstWitness, secondWitness, prevValue);

const [newRoot2] = secondWitness.computeRootAndKeyV2(newValue);
const [newRoot1] = firstWitness.computeRootAndKeyV2(newRoot2);
Expand All @@ -798,9 +763,7 @@ export function getPLottery(
*/
public checkTicket(
firstWitness: MerkleMap20Witness | MerkleMapWitness,
// key1: Field | null,
secondWitness: MerkleMap20Witness | MerkleMapWitness,
// key2: Field, For know second level key is not checked as later it would transform to merkle map
value: Field
): { ticketId: Field; round: Field; roundRoot: Field } {
const [secondLevelRoot, ticketId] =
Expand All @@ -809,9 +772,6 @@ export function getPLottery(
const [firstLevelRoot, round] =
firstWitness.computeRootAndKeyV2(secondLevelRoot);

// if (key1) {
// round.assertEquals(key1, 'Wrong round');
// }
this.ticketRoot
.getAndRequireEquals()
.assertEquals(firstLevelRoot, 'Wrong 2d witness');
Expand Down
1 change: 0 additions & 1 deletion src/Proofs/DistributionProof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const addTicket = async (
prevProof.verify();

const [initialRoot, key] = input.valueWitness.computeRootAndKeyV2(Field(0));
// key.assertEquals(input.ticket.hash(), 'Wrong key for that ticket');
initialRoot.assertEquals(prevProof.publicOutput.root);

const newValue = input.ticket.hash();
Expand Down
10 changes: 0 additions & 10 deletions src/StateManager/BaseStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ export class BaseStateManager {
resultWitness: MerkleMap20Witness;
bankValue: Field;
bankWitness: MerkleMap20Witness;
// nullifierWitness: MerkleMapWitness;
}> {
const roundWitness = this.ticketMap.getWitness(Field.from(round));

Expand Down Expand Up @@ -308,19 +307,11 @@ export class BaseStateManager {
const bankValue = this.bankMap.get(Field.from(round));
const bankWitness = this.bankMap.getWitness(Field.from(round));

// const nullifierWitness = this.ticketNullifierMap.getWitness(
// getNullifierId(Field.from(round), Field.from(ticketId))
// );

if (this.shouldUpdateState) {
this.roundTicketMap[round].set(Field(ticketId), Field(0));
this.ticketMap.set(Field(round), this.roundTicketMap[round].getRoot());

this.roundTickets[round][ticketId] = undefined;
// this.ticketNullifierMap.set(
// getNullifierId(Field.from(round), Field.from(ticketId)),
// Field(1)
// );
this.bankMap.set(
Field.from(round),
bankValue.sub(ticket.amount.mul(TICKET_PRICE).value)
Expand All @@ -333,7 +324,6 @@ export class BaseStateManager {
resultWitness,
bankValue,
bankWitness,
// nullifierWitness,
};
}
}
3 changes: 0 additions & 3 deletions src/StateManager/PStateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,6 @@ export class PStateManager extends BaseStateManager {
fromActionState: initialState,
});
}
// const actionLists = await this.contract.reducer.fetchActions({
// fromActionState: initialState,
// });

// All this params can be random for init function, because init do not use them
let input = new TicketReduceProofPublicInput({
Expand Down
5 changes: 0 additions & 5 deletions src/Tests/PLottery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ describe('Add', () => {
cache: Cache.FileSystem('./cache'),
});
console.log(`Compiling MockLottery`);
// await PLotteryExample.compile({ cache: Cache.FileSystem('./cache') });
// console.log(`Successfully compiled`);
throw Error('Currently there is no option to compile PLottery');
}
});
Expand Down Expand Up @@ -131,7 +129,6 @@ describe('Add', () => {
);

rmStateManager = new RandomManagerManager();
// rmStateManager = new RandomManagerManager();
mineNBlocks = (n: number) => {
let curAmount = Local.getNetworkState().globalSlotSinceGenesis;
Local.setGlobalSlot(curAmount.add(n));
Expand Down Expand Up @@ -365,7 +362,6 @@ describe('Add', () => {
resultWitness: resultWitness1,
bankValue: bankValue1,
bankWitness: bankWitness1,
// nullifierWitness,
} = await state.getRefund(0, ticket);
const balanceBefore2 = Mina.getBalance(senderAccount);
let tx3 = await Mina.transaction(senderAccount, async () => {
Expand All @@ -376,7 +372,6 @@ describe('Add', () => {
resultWitness1,
bankValue1,
bankWitness1
// nullifierWitness
);
});
await tx3.prove();
Expand Down
1 change: 0 additions & 1 deletion src/Tests/Random.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ describe('Add', () => {
randomManager = new RandomManager(randomManagerAddress);

rmStateManager = new RandomManagerManager();
// rmStateManager = new RandomManagerManager();
mineNBlocks = (n: number) => {
let curAmount = Local.getNetworkState().globalSlotSinceGenesis;
Local.setGlobalSlot(curAmount.add(n));
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { PublicKey, UInt64 } from 'o1js';

export const NUMBERS_IN_TICKET = 6;

export const TICKET_PRICE = UInt64.from(10 * 10 ** 9); // #TODO change to field in smartcontract
export const TICKET_PRICE = UInt64.from(10 * 10 ** 9);
export const BLOCK_PER_ROUND = 480; // Approximate blocks per 24 hours

export const SCORE_COEFFICIENTS = [0, 90, 324, 2187, 26244, 590490, 31886460]; // Should be updated with appropriate probability
Expand Down

0 comments on commit e10620a

Please sign in to comment.