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
13 changes: 11 additions & 2 deletions examples/CRISP/contracts/CRISPInputValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ 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 their own slot
/// to store their vote.
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.
Expand Down Expand Up @@ -81,13 +85,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;
}
}
7 changes: 5 additions & 2 deletions examples/CRISP/server/src/server/routes/voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -141,4 +144,4 @@ async fn handle_vote_error(
tx_hash: None,
message: Some("Failed to broadcast vote".to_string()),
})
}
}
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading