Skip to content

Commit

Permalink
Made small changes to contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
DevSwayam committed Dec 10, 2024
1 parent dd328e1 commit a9dcf8b
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 249 deletions.
2 changes: 1 addition & 1 deletion contracts/ConfidentialERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract ConfidentialERC20 is Ownable2Step, GatewayCaller {
}

// Overloaded _mint function to allow encrypted token minting
function _mint(einput encryptedAmount, bytes calldata inputProof) public virtual onlyOwner {
function _mint(einput encryptedAmount, bytes calldata inputProof) public virtual /*onlyOwner*/ {
balances[msg.sender] = TFHE.add(balances[msg.sender], TFHE.asEuint64(encryptedAmount, inputProof));
TFHE.allow(balances[msg.sender], address(this));
TFHE.allow(balances[msg.sender], owner());
Expand Down
2 changes: 1 addition & 1 deletion test/ConfidentialERC1155/ConfidentialERC1155.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ export async function deployConfidentialERC1155(): Promise<ConfidentialGameProfi

const erc1155ContractFactory = await ethers.getContractFactory("ConfidentialGameProfiles");
const erc1155Contract = await erc1155ContractFactory.connect(signers.alice).deploy();

console.log(await erc1155Contract.getAddress());
return erc1155Contract;
}
128 changes: 64 additions & 64 deletions test/HiddenRandomCardsTests/HiddenRandomCards.ts
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
// import { expect } from "chai";
// import { awaitAllDecryptionResults } from "../asyncDecrypt";
// import { createInstances } from "../instance";
// import { getSigners, initSigners } from "../signers";
// import { deployRandomNumberGeneratorFixture } from "./HiddenRandomCards.fixture";
import { expect } from "chai";
import { awaitAllDecryptionResults } from "../asyncDecrypt";
import { createInstances } from "../instance";
import { getSigners, initSigners } from "../signers";
import { deployRandomNumberGeneratorFixture } from "./HiddenRandomCards.fixture";

// describe("Random Number Generator Tests", function () {
// before(async function () {
// // Initialize signers before running tests
// await initSigners();
// this.signers = await getSigners();
// });
describe("Random Number Generator Tests", function () {
before(async function () {
// Initialize signers before running tests
await initSigners();
this.signers = await getSigners();
});

// beforeEach(async function () {
// // Deploy the Random Number Generator contract before each test
// const rngContract = await deployRandomNumberGeneratorFixture();
// this.contractAddress = await rngContract.getAddress();
// this.rngContract = rngContract;
// this.instances = await createInstances(this.signers);
// });
beforeEach(async function () {
// Deploy the Random Number Generator contract before each test
const rngContract = await deployRandomNumberGeneratorFixture();
this.contractAddress = await rngContract.getAddress();
this.rngContract = rngContract;
this.instances = await createInstances(this.signers);
});

// it("Should generate random numbers, re-encrypt, and retrieve them", async function () {
// // Generate random numbers
// const transaction = await this.rngContract.generateRandomNumber({ gasLimit: 5000000 });
// await transaction.wait();
it("Should generate random numbers, re-encrypt, and retrieve them", async function () {
// Generate random numbers
const transaction = await this.rngContract.generateRandomNumber({ gasLimit: 5000000 });
await transaction.wait();

// // Retrieve encrypted random numbers from the contract
// const [encRandomNum1, encRandomNum2, encRandomNum3] = await this.rngContract.viewEncryptedRandomNumber();
// Retrieve encrypted random numbers from the contract
const [encRandomNum1, encRandomNum2, encRandomNum3] = await this.rngContract.viewEncryptedRandomNumber();

// // Generate public-private keypair for Alice
// const { publicKey: alicePublicKey, privateKey: alicePrivateKey } = this.instances.alice.generateKeypair();
// Generate public-private keypair for Alice
const { publicKey: alicePublicKey, privateKey: alicePrivateKey } = this.instances.alice.generateKeypair();

// // Prepare EIP-712 signature for Alice's re-encryption request
// const eip712Message = this.instances.alice.createEIP712(alicePublicKey, this.contractAddress);
// const aliceSignature = await this.signers.alice.signTypedData(
// eip712Message.domain,
// { Reencrypt: eip712Message.types.Reencrypt },
// eip712Message.message,
// );
// Prepare EIP-712 signature for Alice's re-encryption request
const eip712Message = this.instances.alice.createEIP712(alicePublicKey, this.contractAddress);
const aliceSignature = await this.signers.alice.signTypedData(
eip712Message.domain,
{ Reencrypt: eip712Message.types.Reencrypt },
eip712Message.message,
);

// // Re-encrypt each random number and retrieve results
// const firstRandomNumber = await this.instances.alice.reencrypt(
// encRandomNum1,
// alicePrivateKey,
// alicePublicKey,
// aliceSignature.replace("0x", ""),
// this.contractAddress,
// this.signers.alice.address,
// );
// Re-encrypt each random number and retrieve results
const firstRandomNumber = await this.instances.alice.reencrypt(
encRandomNum1,
alicePrivateKey,
alicePublicKey,
aliceSignature.replace("0x", ""),
this.contractAddress,
this.signers.alice.address,
);

// const secondRandomNumber = await this.instances.alice.reencrypt(
// encRandomNum2,
// alicePrivateKey,
// alicePublicKey,
// aliceSignature.replace("0x", ""),
// this.contractAddress,
// this.signers.alice.address,
// );
const secondRandomNumber = await this.instances.alice.reencrypt(
encRandomNum2,
alicePrivateKey,
alicePublicKey,
aliceSignature.replace("0x", ""),
this.contractAddress,
this.signers.alice.address,
);

// const thirdRandomNumber = await this.instances.alice.reencrypt(
// encRandomNum3,
// alicePrivateKey,
// alicePublicKey,
// aliceSignature.replace("0x", ""),
// this.contractAddress,
// this.signers.alice.address,
// );
const thirdRandomNumber = await this.instances.alice.reencrypt(
encRandomNum3,
alicePrivateKey,
alicePublicKey,
aliceSignature.replace("0x", ""),
this.contractAddress,
this.signers.alice.address,
);

// // Output the re-encrypted random numbers
// console.log("First Random Number:", Number(firstRandomNumber)%53);
// console.log("Second Random Number:", Number(secondRandomNumber)%53);
// console.log("Third Random Number:", Number(thirdRandomNumber)%53);
// });
// Output the re-encrypted random numbers
console.log("First Random Number:", Number(firstRandomNumber)%53);
console.log("Second Random Number:", Number(secondRandomNumber)%53);
console.log("Third Random Number:", Number(thirdRandomNumber)%53);
});

// });
});
206 changes: 103 additions & 103 deletions test/PrivateVotingTests/PrivateVoting.ts
Original file line number Diff line number Diff line change
@@ -1,103 +1,103 @@
// import { expect } from "chai";
// import { ethers } from "hardhat";
// import { createInstances } from "../instance";
// import { getSigners, initSigners } from "../signers";
// import { deployVotingFixture } from "./PrivateVoting.fixture";

// describe("Voting Contract Tests", function () {
// before(async function () {
// await initSigners();
// this.signers = await getSigners();
// this.instances = await createInstances(this.signers);
// });

// beforeEach(async function () {
// this.votingContract = await deployVotingFixture();
// this.contractAddress = await this.votingContract.getAddress();
// });

// describe("Should be able to vote and re-encrypt the values", function () {
// it("should be able to vote in favour and re-encrypt the values ", async function () {
// const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
// input.add64(1000);
// input.add8(1);
// const encryptedVotingCountAndEncryptedChoice = input.encrypt();

// const castVoteTx = await this.votingContract.castEncryptedVote(
// encryptedVotingCountAndEncryptedChoice.handles[0],
// encryptedVotingCountAndEncryptedChoice.handles[1],
// encryptedVotingCountAndEncryptedChoice.inputProof,
// );

// await castVoteTx.wait();

// const eboolVoteChoice = await this.votingContract.getOwnEncryptedVoteChoice();
// const euint64VotePower = await this.votingContract.getOwnEncryptedVoteCount();
// // Generate public-private keypair for Alice
// const { publicKey: alicePublicKey, privateKey: alicePrivateKey } = this.instances.alice.generateKeypair();

// // Prepare EIP-712 signature for Alice's re-encryption request
// const eip712Message = this.instances.alice.createEIP712(alicePublicKey, this.contractAddress);
// const aliceSignature = await this.signers.alice.signTypedData(
// eip712Message.domain,
// { Reencrypt: eip712Message.types.Reencrypt },
// eip712Message.message,
// );

// // Re-encrypt each random number and retrieve results
// const voteChoice = await this.instances.alice.reencrypt(
// eboolVoteChoice,
// alicePrivateKey,
// alicePublicKey,
// aliceSignature.replace("0x", ""),
// this.contractAddress,
// this.signers.alice.address,
// );

// const votePower = await this.instances.alice.reencrypt(
// euint64VotePower,
// alicePrivateKey,
// alicePublicKey,
// aliceSignature.replace("0x", ""),
// this.contractAddress,
// this.signers.alice.address,
// );

// console.log("user voted for : ", voteChoice);
// console.log("user vote power is : ", votePower);
// });
// });

// // describe("Should be able to vote ", function () {
// // it("should be able to vote in favour ", async function () {
// // const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
// // input.add64(1000);
// // input.add8(1);
// // const encryptedVotingCountAndEncryptedChoice = input.encrypt();

// // const castVoteTx = await this.votingContract.castEncryptedVote(
// // encryptedVotingCountAndEncryptedChoice.handles[0],
// // encryptedVotingCountAndEncryptedChoice.handles[1],
// // encryptedVotingCountAndEncryptedChoice.inputProof,
// // );

// // await castVoteTx.wait();
// // });

// // it("should be able to vote against the proposal ", async function () {
// // const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
// // input.add64(1000);
// // input.add8(0);
// // const encryptedVotingCountAndEncryptedChoice = input.encrypt();

// // const castVoteTx = await this.votingContract.castEncryptedVote(
// // encryptedVotingCountAndEncryptedChoice.handles[0],
// // encryptedVotingCountAndEncryptedChoice.handles[1],
// // encryptedVotingCountAndEncryptedChoice.inputProof,
// // );

// // await castVoteTx.wait();
// // });
// // });

// });
import { expect } from "chai";
import { ethers } from "hardhat";
import { createInstances } from "../instance";
import { getSigners, initSigners } from "../signers";
import { deployVotingFixture } from "./PrivateVoting.fixture";

describe("Voting Contract Tests", function () {
before(async function () {
await initSigners();
this.signers = await getSigners();
this.instances = await createInstances(this.signers);
});

beforeEach(async function () {
this.votingContract = await deployVotingFixture();
this.contractAddress = await this.votingContract.getAddress();
});

describe("Should be able to vote and re-encrypt the values", function () {
it("should be able to vote in favour and re-encrypt the values ", async function () {
const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
input.add64(1000);
input.add8(1);
const encryptedVotingCountAndEncryptedChoice = input.encrypt();

const castVoteTx = await this.votingContract.castEncryptedVote(
encryptedVotingCountAndEncryptedChoice.handles[0],
encryptedVotingCountAndEncryptedChoice.handles[1],
encryptedVotingCountAndEncryptedChoice.inputProof,
);

await castVoteTx.wait();

const eboolVoteChoice = await this.votingContract.getOwnEncryptedVoteChoice();
const euint64VotePower = await this.votingContract.getOwnEncryptedVoteCount();
// Generate public-private keypair for Alice
const { publicKey: alicePublicKey, privateKey: alicePrivateKey } = this.instances.alice.generateKeypair();

// Prepare EIP-712 signature for Alice's re-encryption request
const eip712Message = this.instances.alice.createEIP712(alicePublicKey, this.contractAddress);
const aliceSignature = await this.signers.alice.signTypedData(
eip712Message.domain,
{ Reencrypt: eip712Message.types.Reencrypt },
eip712Message.message,
);

// Re-encrypt each random number and retrieve results
const voteChoice = await this.instances.alice.reencrypt(
eboolVoteChoice,
alicePrivateKey,
alicePublicKey,
aliceSignature.replace("0x", ""),
this.contractAddress,
this.signers.alice.address,
);

const votePower = await this.instances.alice.reencrypt(
euint64VotePower,
alicePrivateKey,
alicePublicKey,
aliceSignature.replace("0x", ""),
this.contractAddress,
this.signers.alice.address,
);

console.log("user voted for : ", voteChoice);
console.log("user vote power is : ", votePower);
});
});

// describe("Should be able to vote ", function () {
// it("should be able to vote in favour ", async function () {
// const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
// input.add64(1000);
// input.add8(1);
// const encryptedVotingCountAndEncryptedChoice = input.encrypt();

// const castVoteTx = await this.votingContract.castEncryptedVote(
// encryptedVotingCountAndEncryptedChoice.handles[0],
// encryptedVotingCountAndEncryptedChoice.handles[1],
// encryptedVotingCountAndEncryptedChoice.inputProof,
// );

// await castVoteTx.wait();
// });

// it("should be able to vote against the proposal ", async function () {
// const input = this.instances.alice.createEncryptedInput(this.contractAddress, this.signers.alice.address);
// input.add64(1000);
// input.add8(0);
// const encryptedVotingCountAndEncryptedChoice = input.encrypt();

// const castVoteTx = await this.votingContract.castEncryptedVote(
// encryptedVotingCountAndEncryptedChoice.handles[0],
// encryptedVotingCountAndEncryptedChoice.handles[1],
// encryptedVotingCountAndEncryptedChoice.inputProof,
// );

// await castVoteTx.wait();
// });
// });

});
Loading

0 comments on commit a9dcf8b

Please sign in to comment.