From c384f4ab4226e6330cedf9dab0b79be2b16c4239 Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Mon, 13 Oct 2025 12:02:23 +0100 Subject: [PATCH 1/2] feat: assign voter slot --- examples/CRISP/contracts/CRISPInputValidator.sol | 12 ++++++++++-- examples/CRISP/server/src/server/routes/voting.rs | 7 +++++-- pnpm-lock.yaml | 12 ++++++------ 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/examples/CRISP/contracts/CRISPInputValidator.sol b/examples/CRISP/contracts/CRISPInputValidator.sol index 50c8b099f1..885ac28e71 100644 --- a/examples/CRISP/contracts/CRISPInputValidator.sol +++ b/examples/CRISP/contracts/CRISPInputValidator.sol @@ -29,6 +29,9 @@ contract CRISPInputValidator is IInputValidator, Clone, Ownable(msg.sender) { /// @notice Indicates if the the round data has been set. bool public isDataSet; + /// @notice Mapping to store votes. Each elegible voter has + mapping (address => bytes) public voteSlots; + /// @notice The error emitted when the input data is empty. error EmptyInputData(); /// @notice The error emitted when the input data is invalid. @@ -81,13 +84,18 @@ contract CRISPInputValidator is IInputValidator, Clone, Ownable(msg.sender) { ( bytes memory noirProof, bytes32[] memory noirPublicInputs, - bytes memory vote - ) = abi.decode(data, (bytes, bytes32[], bytes)); + bytes memory vote, + address slot + ) = abi.decode(data, (bytes, bytes32[], bytes, address)); // Check if the ciphertext was encrypted correctly if (!noirVerifier.verify(noirProof, noirPublicInputs)) revert InvalidNoirProof(); + /// @notice Store the vote in the correct slot. + voteSlots[slot] = vote; + + // return the vote so that it can be stored in Enclave's input merkle tree input = vote; } } diff --git a/examples/CRISP/server/src/server/routes/voting.rs b/examples/CRISP/server/src/server/routes/voting.rs index bcf1ee7ee8..15692b61cf 100644 --- a/examples/CRISP/server/src/server/routes/voting.rs +++ b/examples/CRISP/server/src/server/routes/voting.rs @@ -14,7 +14,7 @@ use crate::server::{ use actix_web::{web, HttpResponse, Responder}; use alloy::{ dyn_abi::DynSolValue, - primitives::{Bytes, U256}, + primitives::{Bytes, U256, Address}, }; use e3_sdk::evm_helpers::contracts::{EnclaveContract, EnclaveWrite}; use eyre::Error; @@ -81,11 +81,14 @@ async fn broadcast_encrypted_vote( ) }; + let address: Address = vote.address.parse().expect("Invalid address"); + let e3_id = U256::from(vote.round_id); let params_value = DynSolValue::Tuple(vec![ DynSolValue::Bytes(vote.proof), public_inputs_array, DynSolValue::Bytes(vote.enc_vote_bytes), + DynSolValue::Address(address), ]); let encoded_params = Bytes::from(params_value.abi_encode_params()); @@ -141,4 +144,4 @@ async fn handle_vote_error( tx_hash: None, message: Some("Failed to broadcast vote".to_string()), }) -} \ No newline at end of file +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 24d3296028..901b6994d4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -622,7 +622,7 @@ importers: version: 5.3.0 '@risc0/ethereum': specifier: file:lib/risc0-ethereum - version: risc0-ethereum@file:templates/default/lib/risc0-ethereum + version: file:templates/default/lib/risc0-ethereum '@types/chai': specifier: ^4.2.0 version: 4.3.20 @@ -2968,6 +2968,9 @@ packages: '@reown/appkit@1.7.8': resolution: {integrity: sha512-51kTleozhA618T1UvMghkhKfaPcc9JlKwLJ5uV+riHyvSoWPKPRIa5A6M1Wano5puNyW0s3fwywhyqTHSilkaA==} + '@risc0/ethereum@file:templates/default/lib/risc0-ethereum': + resolution: {directory: templates/default/lib/risc0-ethereum, type: directory} + '@rolldown/pluginutils@1.0.0-beta.27': resolution: {integrity: sha512-+d0F4MKMCbeVUJwG96uQ4SgAznZNSq93I3V+9NHA4OpvqG8mRCpGdKmK8l/dl02h2CCDHwW2FqilnTyDcAnqjA==} @@ -8084,9 +8087,6 @@ packages: ripemd160@2.0.2: resolution: {integrity: sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==} - risc0-ethereum@file:templates/default/lib/risc0-ethereum: - resolution: {directory: templates/default/lib/risc0-ethereum, type: directory} - robust-predicates@3.0.2: resolution: {integrity: sha512-IXgzBWvWQwE6PrDI05OvmXUIruQTcoMDzRsOd5CDvHCVLcLHMTSYvOK5Cm46kWqlV3yAbuSpBZdJ5oP5OUoStg==} @@ -12485,6 +12485,8 @@ snapshots: - utf-8-validate - zod + '@risc0/ethereum@file:templates/default/lib/risc0-ethereum': {} + '@rolldown/pluginutils@1.0.0-beta.27': {} '@rollup/plugin-inject@5.0.5(rollup@4.49.0)': @@ -19242,8 +19244,6 @@ snapshots: hash-base: 3.1.0 inherits: 2.0.4 - risc0-ethereum@file:templates/default/lib/risc0-ethereum: {} - robust-predicates@3.0.2: {} rollup@4.49.0: From b63ccde2b3ab96a681374e095b8a5f9ade3fdfed Mon Sep 17 00:00:00 2001 From: ctrlc03 <93448202+ctrlc03@users.noreply.github.com> Date: Mon, 13 Oct 2025 14:54:33 +0100 Subject: [PATCH 2/2] chore: update comment --- examples/CRISP/contracts/CRISPInputValidator.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/CRISP/contracts/CRISPInputValidator.sol b/examples/CRISP/contracts/CRISPInputValidator.sol index 885ac28e71..b23029bc89 100644 --- a/examples/CRISP/contracts/CRISPInputValidator.sol +++ b/examples/CRISP/contracts/CRISPInputValidator.sol @@ -29,7 +29,8 @@ contract CRISPInputValidator is IInputValidator, Clone, Ownable(msg.sender) { /// @notice Indicates if the the round data has been set. bool public isDataSet; - /// @notice Mapping to store votes. Each elegible voter has + /// @notice Mapping to store votes. Each elegible voter has their own slot + /// to store their vote. mapping (address => bytes) public voteSlots; /// @notice The error emitted when the input data is empty.