← Back

Blockchain Applied to Digital Voting (Chamber of Deputies)

Prototype of a blockchain-based digital voting system, developed and awarded at a hackathon held at the Chamber of Deputies.

June 2024...8 min read
Blockchain • Governance • Digital Voting • zK • Smart Contracts • Substrate

Problem

Traditional voting systems face critical challenges in terms of transparency, trust, and verifiability. In political and governmental contexts, any failure — technical or perceptual — can compromise the legitimacy of results and public trust.

Moreover, many digital voting proposals fail to balance three key factors: security, anonymity, and public auditability, especially in politically sensitive environments.

Solution

A decentralized digital voting prototype was designed based on a conceptual architecture integrating blockchain, Zero-Knowledge Proofs (zk), and Smart Contracts, guaranteeing:

  • Immutability of cast votes
  • Voter anonymity
  • Traceability and public auditability of results
  • Reduction of intermediaries and single points of failure
  • Portability across different blockchain ecosystems

The project was developed and presented during a hackathon held at the Chamber of Deputies, where it won after more than 30 continuous hours of work, validating both its technical soundness and institutional viability.

Conceptual Model: Layer Separation

The system's central premise is to strictly separate voter identity, vote casting, and process governance, achieving a balance between security, anonymity, and public auditability.

In this model:

  • The blockchain does not "know" people, it only verifies rules
  • Zero-Knowledge Proofs enable proving legitimacy without exposing sensitive information
  • Smart Contracts act as neutral arbiters of the process
  • The architecture is blockchain-agnostic, allowing implementations in EVM and Substrate

Technical Approach

1. Identity and Eligibility (zk Layer – Off-Chain)

All sensitive information occurs off the blockchain. Before casting a vote, the citizen generates a Zero-Knowledge cryptographic proof demonstrating that:

  • They belong to the electoral registry
  • They are eligible to vote
  • They have not voted previously

This proof is constructed against an authorized set (e.g., a Merkle Tree of the registry), but without revealing identity, name, blockchain address, or personal data. The result is a verifiable statement like: "I meet the system's rules" without saying who is meeting them.

Here, trust is not placed in a central authority, but in the mathematical validity of the proof.

2. Vote Casting (Blockchain Layer – Smart Contract)

The VotingSystem smart contract acts as the neutral arbiter of the electoral process. Its responsibility is not to identify voters, but to execute immutable rules.

The architecture was implemented in two different blockchain ecosystems, demonstrating the design's portability:

EVM Implementation (Solidity)

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract VotingSystem {
    // Vote structure
    struct Vote {
        uint256 folio;           // Unique institutional identifier
        uint256 candidateId;     // Selected candidate ID
        bool isCoalition;        // Indicates coalition vote
        address voter;           // Technical address (not civil identity)
        uint256 timestamp;       // Time of casting
    }

    // System state
    mapping(uint256 => Vote) public votes;              // Vote record
    mapping(uint256 => bool) public usedFolios;         // Used folio tracking
    mapping(uint256 => uint256) public voteCounts;      // Count per candidate
    mapping(address => bool) public validators;         // Authorized validators
    
    uint256 public totalVotes;                          // Total votes cast
    bool public votingOpen;                             // Voting state
    uint256 public validatorCount;                      // Number of validators
    uint256 public closeConfirmations;                  // Confirmations for closure

    address public admin;

    // Public immutable events
    event VoteCast(uint256 indexed folio, uint256 candidateId, bool isCoalition);
    event VotingClosed(uint256 totalVotes);
    event ValidatorAdded(address validator);

    modifier onlyAdmin() {
        require(msg.sender == admin, "Only admin");
        _;
    }

    modifier onlyValidator() {
        require(validators[msg.sender], "Only validators");
        _;
    }

    modifier votingIsOpen() {
        require(votingOpen, "Voting closed");
        _;
    }

    constructor() {
        admin = msg.sender;
        votingOpen = true;
    }

    function addValidator(address _validator) external onlyAdmin {
        require(!validators[_validator], "Already a validator");
        validators[_validator] = true;
        validatorCount++;
        emit ValidatorAdded(_validator);
    }

    function castVote(
        uint256 _folio,
        uint256 _candidateId,
        bool _isCoalition
    ) external votingIsOpen {
        require(!usedFolios[_folio], "Folio already used");
        require(_candidateId > 0, "Invalid candidate");

        votes[totalVotes] = Vote({
            folio: _folio,
            candidateId: _candidateId,
            isCoalition: _isCoalition,
            voter: msg.sender,
            timestamp: block.timestamp
        });

        usedFolios[_folio] = true;
        voteCounts[_candidateId]++;
        totalVotes++;

        emit VoteCast(_folio, _candidateId, _isCoalition);
    }

    function confirmClose() external onlyValidator {
        require(votingOpen, "Already closed");
        closeConfirmations++;

        if (closeConfirmations >= validatorCount) {
            votingOpen = false;
            emit VotingClosed(totalVotes);
        }
    }

    function getResults(uint256 _candidateId) external view returns (uint256) {
        return voteCounts[_candidateId];
    }

    function isFolioUsed(uint256 _folio) external view returns (bool) {
        return usedFolios[_folio];
    }
}

Substrate Implementation (Rust)

use frame_support::{
    decl_module, decl_storage, decl_event, decl_error, dispatch,
    traits::Get,
};
use frame_system::ensure_signed;
use sp_std::prelude::*;

#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};

pub trait Config: frame_system::Config {
    type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;
}

// Equivalent structure to the Solidity version
#[derive(Encode, Decode, Clone, PartialEq, Eq, RuntimeDebug)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct Vote<AccountId> {
    folio: u32,
    candidate_id: u32,
    voter: AccountId,
    is_coalition: bool,
}

// Storage: equivalent to Solidity mappings
decl_storage! {
    trait Store for Module<T: Config> as VotingSystem {
        // Used folio tracking
        FolioUsed get(fn folio_used): map hasher(blake2_128_concat) u32 => bool;
        
        // Vote record by folio
        Votes get(fn votes): map hasher(blake2_128_concat) u32 => Vote<T::AccountId>;
        
        // Voter tracking (address already voted)
        HasVoted get(fn has_voted): map hasher(blake2_128_concat) T::AccountId => bool;
        
        // Authorized validators list
        Validators get(fn validators): Vec<T::AccountId>;
        
        // Confirmation counter for closure
        ValidatorCount get(fn validator_count): u32;
        
        // Voting state
        VotingClosed get(fn voting_closed): bool;
        
        // Start time (additional in Substrate)
        VotingStartTime get(fn voting_start_time): T::BlockNumber;
    }
}

// Events equivalent to Solidity's
decl_event!(
    pub enum Event<T> where AccountId = <T as frame_system::Config>::AccountId {
        VoteCast(u32, u32, AccountId, bool),
        VotingClosed(),
    }
);

// Typed error handling
decl_error! {
    pub enum Error for Module<T: Config> {
        NotValidator,
        VotingIsClosed,
        FolioAlreadyUsed,
        AlreadyVoted,
        InvalidCandidateId,
    }
}

// Extrinsic functions (equivalent to public functions)
decl_module! {
    pub struct Module<T: Config> for enum Call where origin: T::Origin {
        type Error = Error<T>;
        fn deposit_event() = default;

        // Cast vote (equivalent to castVote in Solidity)
        #[weight = 10_000]
        pub fn cast_vote(
            origin, 
            folio: u32, 
            candidate_id: u32, 
            is_coalition: bool
        ) -> dispatch::DispatchResult {
            let sender = ensure_signed(origin)?;

            // Validations equivalent to Solidity's require()
            ensure!(!Self::voting_closed(), Error::<T>::VotingIsClosed);
            ensure!(!Self::folio_used(folio), Error::<T>::FolioAlreadyUsed);
            ensure!(!Self::has_voted(&sender), Error::<T>::AlreadyVoted);
            ensure!(candidate_id > 0, Error::<T>::InvalidCandidateId);

            // Create vote structure
            let vote = Vote {
                folio,
                candidate_id,
                voter: sender.clone(),
                is_coalition,
            };

            // Update state
            <FolioUsed>::insert(folio, true);
            <Votes<T>>::insert(folio, vote);
            <HasVoted<T>>::insert(&sender, true);

            // Emit event
            Self::deposit_event(RawEvent::VoteCast(folio, candidate_id, sender, is_coalition));

            Ok(())
        }

        // Close voting with distributed governance
        #[weight = 10_000]
        pub fn close_voting(origin) -> dispatch::DispatchResult {
            let sender = ensure_signed(origin)?;
            
            // Only validators can confirm closure
            ensure!(Self::is_validator(&sender), Error::<T>::NotValidator);

            // Increment confirmation counter
            let count = Self::validator_count().saturating_add(1);
            ValidatorCount::put(count);

            // Close only when all validators confirm
            if count == Self::validators().len() as u32 {
                VotingClosed::put(true);
                Self::deposit_event(RawEvent::VotingClosed());
            }

            Ok(())
        }
    }
}

// Helper functions
impl<T: Config> Module<T> {
    fn is_validator(address: &T::AccountId) -> bool {
        Self::validators().contains(address)
    }
}

Implementation Comparison

| Aspect            | Solidity (EVM)                 | Rust (Substrate)             |
| ----------------- | ------------------------------ | ---------------------------- |
|   Ecosystem       | Ethereum, Polygon, BSC         | Polkadot, Kusama, parachains |
|   Data type       | `address` (on-chain identity)  | `AccountId` (generic type)   |
|   Storage         | `mapping` (key → value)        | `StorageMap` (with hasher)   |
|   Validation      | `require()` (condition)        | `ensure!()` (macro)          |
|   Security        | Gas, reentrancy guards         | Weight, strong typing        |
|   Events          | `emit Event()`                 | `deposit_event()`            |
|   Modifiers       | `modifier` (pre/post logic)    | Direct function logic        |
|   Errors          | `revert` (string)              | Typed `enum`                 |

Advantages of Rust/Substrate implementation:

  1. Type safety: The Rust compiler prevents entire classes of bugs
  2. Weight system: More granular control over computational resources
  3. Typed errors: Better error handling and debugging
  4. Parachain-ready: Compatible with Polkadot ecosystem
  5. No variable gas: More predictable transaction costs

Advantages of Solidity/EVM implementation:

  1. Mature ecosystem: More tools and audits available
  2. Wider adoption: More developers familiar with EVM
  3. Interoperability: Compatible with multiple EVM chains
  4. Established tooling: Hardhat, Truffle, OpenZeppelin

Common Architectural Analysis

Both implementations respect the same fundamental principles:

Minimal Data Structure:

// Solidity
struct Vote {
    uint256 folio;
    uint256 candidateId;
    bool isCoalition;
    address voter;
    uint256 timestamp;
}
// Rust
pub struct Vote<AccountId> {
    folio: u32,
    candidate_id: u32,
    voter: AccountId,
    is_coalition: bool,
}

Immutable Constraints:

Both versions implement the same critical validations:

  • A folio cannot be reused
  • A voter cannot vote twice
  • Voting must be open
  • The candidate must be valid

Distributed Governance:

Both implement the same multi-signature closure mechanism:

  • Confirmation from all validators is required
  • No single actor can close unilaterally
  • The process is transparent and auditable

3. The Folio as an Institutional Bridge

The use of a folio plays a key role in real governmental and electoral contexts:

  • It can exist previously in physical or digital systems
  • It can be validated within the zk proof
  • It enables institutional traceability without compromising anonymity

Complete flow with zk (blockchain-agnostic):

  1. The citizen presents their folio + voter credential
  2. Off-chain system generates a zk proof validating:
    • Folio belongs to the registry
    • Citizen is eligible
    • Folio has not been used
  3. A cryptographic nullifier (irreversible hash) is generated
  4. The contract (EVM or Substrate) verifies the nullifier
  5. Vote is registered without revealing identity

This connects the decentralized system with traditional electoral processes, facilitating adoption, auditing, and public trust.

4. Portability and Scalability

The existence of both implementations demonstrates that the architecture is blockchain-agnostic:

  • EVM: Ideal for rapid deployment in mature ecosystems
  • Substrate: Ideal for purpose-specific government blockchains

This portability enables:

  • Comparative cost and performance evaluation
  • Migration between ecosystems based on institutional needs
  • Resilience against technological changes

Model Synthesis

  • Zero-Knowledge protects the voter (off-chain identity)
  • Blockchain protects the vote (immutability)
  • Smart Contract protects the rules (automatic execution)
  • Validators protect the process (distributed governance)
  • Portability protects against technological obsolescence

The system does not need to trust people, institutions, or intermediaries. It trusts cryptography, consensus, and immutable code. The legitimacy of the vote is not declared: it is cryptographically demonstrated.

Results

  • Winning project at hackathon held in the Chamber of Deputies
  • Validation of the technical approach in a politically sensitive environment
  • Functional demonstration of immutable and auditable voting
  • Recognition for the balance between security, anonymity, and transparency
  • Dual implementation (EVM + Substrate) demonstrating architectural portability
  • Smart Contracts deployed and tested during the 30+ hour event
  • Positive evaluation on legal aspects and physical vulnerabilities

Tech Stack

Blockchain Platforms

  • EVM: Ethereum / Polygon / BSC compatible
  • Substrate: Polkadot ecosystem ready

Smart Contracts

  • Solidity: ^0.8.0 (EVM implementation)
  • Rust: frame_support + sp_std (Substrate pallet)

Security & Privacy

  • Zero-Knowledge Proofs: zk-SNARKs (conceptual layer)
  • Cryptographic Primitives: Blake2, nullifiers, Merkle Trees

Architecture

  • Layered Design: Off-chain identity + on-chain voting
  • Multi-validator Governance: Distributed consensus mechanism
  • Cross-chain Compatible: Blockchain-agnostic logic

Development

  • Methodology: Rapid prototyping with production-grade security
  • Focus: Social impact + institutional viability

Key Takeaways

The experience of more than 30 continuous hours not only validated the technical architecture, but exposed the complexity of designing voting systems that must comply with:

  • Legal requirements (legal validity of electronic voting)
  • Physical security (protection of devices and infrastructure)
  • Social trust (citizen and institutional acceptance)
  • Technical scalability (processing millions of votes)
  • Technological portability (independence from specific platforms)

The dual implementation in Solidity and Rust demonstrates that architectural principles transcend specific technologies. The real challenge is not just writing correct code, but designing systems that society can trust, regardless of the underlying blockchain.

Portability Lessons

  • Solid conceptual design enables implementations across multiple ecosystems
  • Layer separation (zk off-chain + smart contract on-chain) is universal
  • Distributed governance principles are platform-independent
  • Architecture should prioritize concepts over specific technologies
Blockchain Applied to Digital Voting (Chamber of Deputies) · Irwing Duran