diff --git a/examples/CRISP/client/src/hooks/generic/useMintToken.tsx b/examples/CRISP/client/src/hooks/generic/useMintToken.tsx index 70b9e09c01..4fcad7e118 100644 --- a/examples/CRISP/client/src/hooks/generic/useMintToken.tsx +++ b/examples/CRISP/client/src/hooks/generic/useMintToken.tsx @@ -52,7 +52,7 @@ const useToken = () => { abi: iERC20Abi, address: ROUND_TOKEN, functionName: 'mint', - args: [walletClient.account.address, BigInt(1 * 1e18)], + args: [walletClient.account.address, BigInt(1 * 1e9)], chain: getChain(), }) showToast({ diff --git a/examples/CRISP/client/src/hooks/voting/useVoteCasting.ts b/examples/CRISP/client/src/hooks/voting/useVoteCasting.ts index d08e75e18b..23a81ad0d6 100644 --- a/examples/CRISP/client/src/hooks/voting/useVoteCasting.ts +++ b/examples/CRISP/client/src/hooks/voting/useVoteCasting.ts @@ -328,7 +328,19 @@ export const useVoteCasting = (customRoundState?: VoteStateLite | null, customVo setIsMasking(false) } }, - [user, roundState, broadcastVote, setTxUrl, showToast, navigate, handleProofGeneration, markVotedInRound, handleMask, handleVote], + [ + user, + roundState, + broadcastVote, + setTxUrl, + showToast, + navigate, + handleProofGeneration, + markVotedInRound, + handleMask, + handleVote, + getMerkleLeaves, + ], ) return { diff --git a/examples/CRISP/packages/crisp-contracts/.env.example b/examples/CRISP/packages/crisp-contracts/.env.example index 1fe016db7d..6279b65f72 100644 --- a/examples/CRISP/packages/crisp-contracts/.env.example +++ b/examples/CRISP/packages/crisp-contracts/.env.example @@ -4,6 +4,5 @@ MNEMONIC="" PRIVATE_KEY="" # The RPC URL for the Ethereum network (e.g., Infura, Alchemy) RPC_URL="" -# Whether to use mock verifier and input validator contracts -USE_MOCK_VERIFIER= -USE_MOCK_INPUT_VALIDATOR= \ No newline at end of file +# Whether to use mock verifier and deploy a new mock token contract +USE_MOCKS= diff --git a/examples/CRISP/packages/crisp-contracts/contracts/Mocks/MockVotingToken.sol b/examples/CRISP/packages/crisp-contracts/contracts/Mocks/MockVotingToken.sol new file mode 100644 index 0000000000..17693f2bf6 --- /dev/null +++ b/examples/CRISP/packages/crisp-contracts/contracts/Mocks/MockVotingToken.sol @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: LGPL-3.0-only +// +// This file is provided WITHOUT ANY WARRANTY; +// without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. +pragma solidity ^0.8.27; + +import { ERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol"; + +/// @title MockVotingToken +/// @notice A mock voting token for testing purposes +/// @dev Public mint function that allows to keep balances to 1e9. +/// @dev by default CRISP server will scale down voting power by 1e18/2 +/// @dev in this case leaving everyone with a balance of 1 to vote yes or no +contract MockVotingToken is ERC20 { + // half of 10e18 + uint256 public constant MAX_BALANCE = 1e9; + + constructor() ERC20("Mock Voting Token", "MVT") { + _mint(msg.sender, 1e9); + } + + function mint(address to, uint256) external { + if (balanceOf(to) + 1e9 > MAX_BALANCE) { + // silently fail + return; + } + _mint(to, 1e9); + } + + function decimals() public pure override returns (uint8) { + return 18; + } +} diff --git a/examples/CRISP/packages/crisp-contracts/deploy/crisp.ts b/examples/CRISP/packages/crisp-contracts/deploy/crisp.ts index fbefb7eb74..4d44ab1693 100644 --- a/examples/CRISP/packages/crisp-contracts/deploy/crisp.ts +++ b/examples/CRISP/packages/crisp-contracts/deploy/crisp.ts @@ -26,11 +26,9 @@ export const deployCRISPContracts = async () => { const chain = hre.globalOptions.network - const useMockVerifier = Boolean(process.env.USE_MOCK_VERIFIER) + const useMocks = Boolean(process.env.USE_MOCKS) - console.log('useMockVerifier', useMockVerifier) - - const verifier = await deployVerifier(useMockVerifier) + const verifier = await deployVerifier(useMocks) const enclaveAddress = readDeploymentArgs('Enclave', chain)?.address if (!enclaveAddress) { @@ -94,6 +92,22 @@ export const deployCRISPContracts = async () => { const tx = await enclave.enableE3Program(crispAddress) await tx.wait() + let tokenAddress + if (useMocks) { + const token = await ethers.deployContract('MockVotingToken') + await token.waitForDeployment() + tokenAddress = await token.getAddress() + + storeDeploymentArgs( + { + address: tokenAddress, + blockNumber: await ethers.provider.getBlockNumber(), + }, + 'MockCRISPToken', + chain, + ) + } + console.log(` Deployments: ---------------------------------------------------------------------- @@ -101,6 +115,7 @@ export const deployCRISPContracts = async () => { Risc0Verifier: ${verifier} HonkVerifier: ${honkVerifierAddress} CRISPProgram: ${crispAddress} + TokenAddress: ${tokenAddress} `) } diff --git a/examples/CRISP/packages/crisp-contracts/deployed_contracts.json b/examples/CRISP/packages/crisp-contracts/deployed_contracts.json index 0838f59471..9cce2a7d76 100644 --- a/examples/CRISP/packages/crisp-contracts/deployed_contracts.json +++ b/examples/CRISP/packages/crisp-contracts/deployed_contracts.json @@ -127,6 +127,10 @@ "MockRISC0Verifier": { "address": "0x51D31a22cBe13dE01C4c1CD8cEd3955fa58a4aC3", "blockNumber": 10043288 + }, + "MockCRISPToken": { + "address": "0x77da6521A1A22e81Df08E98b4Af41D71413EA354", + "blockNumber": 10073653 } } } \ No newline at end of file diff --git a/examples/CRISP/packages/crisp-contracts/package.json b/examples/CRISP/packages/crisp-contracts/package.json index 2858b82cc8..382d085cb0 100644 --- a/examples/CRISP/packages/crisp-contracts/package.json +++ b/examples/CRISP/packages/crisp-contracts/package.json @@ -33,8 +33,9 @@ "ciphernode:add:self": "hardhat ciphernode:add", "clean:deployments": "hardhat utils:clean-deployments", "deploy:contracts": "hardhat run deploy/deploy.ts", + "deploy:contracts:mock": "export USE_MOCKS=true PRINT_ENV_VARS=true && pnpm deploy:contracts", "deploy:contracts:full": "export DEPLOY_ENCLAVE=true && pnpm deploy:contracts", - "deploy:contracts:full:mock": "export DEPLOY_ENCLAVE=true USE_MOCK_VERIFIER=true PRINT_ENV_VARS=true && pnpm deploy:contracts", + "deploy:contracts:full:mock": "export DEPLOY_ENCLAVE=true USE_MOCKS=true PRINT_ENV_VARS=true && pnpm deploy:contracts", "test": "hardhat test mocha", "verify": "hardhat run deploy/verify.ts", "updateSubmissionWindow": "hardhat ciphernode:window" diff --git a/examples/CRISP/scripts/crisp_deploy.sh b/examples/CRISP/scripts/crisp_deploy.sh index 47670347d0..4022484067 100755 --- a/examples/CRISP/scripts/crisp_deploy.sh +++ b/examples/CRISP/scripts/crisp_deploy.sh @@ -9,4 +9,4 @@ export PRIVATE_KEY="0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4 cd packages/crisp-contracts pnpm clean:deployments --network localhost -USE_MOCK_VERIFIER=true pnpm deploy:contracts:full:mock --network localhost +USE_MOCKS=true pnpm deploy:contracts:full:mock --network localhost