Skip to content

Ballot creation timestamp verification #71

Description

@Just-Bamford

Summary

The contract stores ballot creation time but does not verify it matches the backend database. If the contract timestamp diverges from the backend timestamp, voting logic based on time (deadlines, open/closed status) can become inconsistent. The contract should verify that ballots registered on-chain have matching timestamps.

This is a Milestone 2 reliability issue. Timestamp consistency is important for vote validity.

Background

When a ballot is created on the backend, a record is written to the database and simultaneously (or later) to the contract. There is no guarantee the timestamps match. If they diverge, a vote could be accepted by the contract but rejected by the backend, or vice versa, causing confusion and incorrect vote tallies.

Scope

Contract

  • When a ballot is created, store the creation timestamp in contract storage
  • Add a function verify_ballot_timestamp(ballot_id: String, expected_timestamp: u64): Result<(), Error>
  • Function compares the stored timestamp with the expected timestamp
  • Returns OK if within a 60-second tolerance
  • Returns TIMESTAMP_MISMATCH if they diverge more than 60 seconds
  • Logs discrepancy for audit trail

Backend Integration

  • After creating a ballot on-chain, call verify_ballot_timestamp with the backend timestamp
  • Store the verification result in ballotResults or a new ballotVerification table
  • If verification fails, log a warning and alert admins

Tests

  • Timestamp verification passes when times match
  • Verification fails when times diverge more than 60 seconds
  • 60-second tolerance is enforced
  • Error message includes the time delta

Relevant Files

  • contracts/anonvote/src/lib.rs
  • backend/src/services/sorobanService.ts
  • backend/prisma/schema.prisma

Acceptance Criteria

  • Contract stores and verifies timestamps
  • Backend calls verification function
  • Results logged and stored
  • Tests pass
  • Tolerance is documented

Out of Scope

  • Automatic timestamp correction — detection only
  • Blockchain time synchronization — use system time as-is

Note for Contributors

Use a 60-second tolerance to account for network latency and clock skew between systems. Do not block operations on timestamp mismatch — log it for audit trail and let operations continue. This is for transparency, not enforcement.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions