Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/CRISP/client/src/hooks/generic/useMintToken.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
14 changes: 13 additions & 1 deletion examples/CRISP/client/src/hooks/voting/useVoteCasting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 2 additions & 3 deletions examples/CRISP/packages/crisp-contracts/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -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=
# Whether to use mock verifier and deploy a new mock token contract
USE_MOCKS=
Original file line number Diff line number Diff line change
@@ -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;
}
}
23 changes: 19 additions & 4 deletions examples/CRISP/packages/crisp-contracts/deploy/crisp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -94,13 +92,30 @@ 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:
----------------------------------------------------------------------
Enclave: ${enclaveAddress}
Risc0Verifier: ${verifier}
HonkVerifier: ${honkVerifierAddress}
CRISPProgram: ${crispAddress}
TokenAddress: ${tokenAddress}
`)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@
"MockRISC0Verifier": {
"address": "0x51D31a22cBe13dE01C4c1CD8cEd3955fa58a4aC3",
"blockNumber": 10043288
},
"MockCRISPToken": {
"address": "0x77da6521A1A22e81Df08E98b4Af41D71413EA354",
"blockNumber": 10073653
}
}
}
3 changes: 2 additions & 1 deletion examples/CRISP/packages/crisp-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/CRISP/scripts/crisp_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading