Skip to content

Commit

Permalink
refactor(contracts): update SemaphoreVerifierKeyPts library to be int…
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmychu0807 committed Oct 16, 2024
1 parent 163c9c1 commit 93cd86b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ library SemaphoreVerifierKeyPts {
hex"1ff343732becbc72450b2faedef7112b951edf2ee03bebe4b71365755e6d5518"
hex"10e06fbbc2176bff93433750bcbfec05aea120f193a1e4c5bf5993e098916f96";

function get_pts(uint256 merkleTreeDepth) public pure returns (uint256[SET_SIZE] memory pts) {
function get_pts(uint256 merkleTreeDepth) internal pure returns (uint256[SET_SIZE] memory pts) {
bytes memory pt_bytes = VK_POINT_BYTES;
uint256 byte_offset = 32 + (merkleTreeDepth - 1) * SET_SIZE * 32;

Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { readFileSync, writeFileSync } from "fs"
import { FactoryOptions } from "hardhat/types"

export type NetworkDeployedContracts = {
name: "Semaphore" | "SemaphoreVerifier" | "PoseidonT3" | "SemaphoreVerifierKeyPts"
name: "Semaphore" | "SemaphoreVerifier" | "PoseidonT3"
address: string
startBlock: number
}[]
Expand Down
29 changes: 4 additions & 25 deletions packages/contracts/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,26 @@ import { task, types } from "hardhat/config"
import { deploy, saveDeployedContracts } from "../scripts/utils"

task("deploy", "Deploy a Semaphore contract")
.addOptionalParam<string>("verifierKeyPts", "Verifier key points library address", undefined, types.string)
.addOptionalParam<string>("verifier", "Verifier contract address", undefined, types.string)
.addOptionalParam<string>("poseidon", "Poseidon library address", undefined, types.string)
.addOptionalParam<boolean>("logs", "Print the logs", true, types.boolean)
.setAction(
async (
{
logs,
verifierKeyPts: verifierKeyPtsAddress,
verifier: semaphoreVerifierAddress,
poseidon: poseidonT3Address
},
{ logs, verifier: semaphoreVerifierAddress, poseidon: poseidonT3Address },
{ ethers, hardhatArguments }
): Promise<any> => {
const startBlock = await ethers.provider.getBlockNumber()

if (!verifierKeyPtsAddress) {
verifierKeyPtsAddress = await deploy(ethers, "SemaphoreVerifierKeyPts", hardhatArguments.network)
if (logs) {
console.info(`SemaphoreVerifierKeyPts library has been deployed to: ${verifierKeyPtsAddress}`)
}
}

if (!semaphoreVerifierAddress) {
semaphoreVerifierAddress = await deploy(ethers, "SemaphoreVerifier", hardhatArguments.network, [], {
libraries: {
SemaphoreVerifierKeyPts: verifierKeyPtsAddress
}
})
semaphoreVerifierAddress = await deploy(ethers, "SemaphoreVerifier", hardhatArguments.network)
if (logs) {
console.info(`SemaphoreVerifier contract has been deployed to: ${semaphoreVerifierAddress}`)
}
}

if (!poseidonT3Address) {
poseidonT3Address = await deploy(ethers, "PoseidonT3", hardhatArguments.network)

if (logs) {
console.info(`PoseidonT3 library has been deployed to: ${poseidonT3Address}`)
}
Expand All @@ -55,17 +39,13 @@ task("deploy", "Deploy a Semaphore contract")
}
}
)

if (logs) {
console.info(`Semaphore contract has been deployed to: ${semaphoreAddress}`)
}

saveDeployedContracts(
[
{
name: "SemaphoreVerifierKeyPts",
address: verifierKeyPtsAddress,
startBlock
},
{
name: "SemaphoreVerifier",
address: semaphoreVerifierAddress,
Expand All @@ -88,7 +68,6 @@ task("deploy", "Deploy a Semaphore contract")
return {
semaphore: await ethers.getContractAt("Semaphore", semaphoreAddress),
verifierAddress: semaphoreVerifierAddress,
verifierKeyPtsAddress,
poseidonAddress: poseidonT3Address
}
}
Expand Down

0 comments on commit 93cd86b

Please sign in to comment.