Skip to content

Optimize Testimonial struct: change timestamp from uint256 to uint64 #38

@Atharva0506

Description

@Atharva0506

Problem

The Testimonial struct uses uint256 for timestamp, burning storage for no reason. To put that in perspective:

Type Max timestamp stores until Size
uint32 February 7, 2106 4 bytes
uint64 July 21, 584,554,051,223 AD 8 bytes
uint256 ~year 3.67 × 10⁶⁹ (post heat-death of universe) 32 bytes

We're paying for uint256 when uint64 already covers timestamps half a trillion years into the future. Because of this the struct unnecessarily occupies 7 storage slots instead of 6.

Fix

  • Change timestamp from uint256uint64 in VouchMe.sol
  • Reorder struct fields so timestamp (8 bytes) + receiver (20 bytes) + verified (1 byte) pack cleanly into one 32-byte slot
  • Update VouchMe.json, VouchMe.ts, and factory files to match the new ABI

No frontend logic changes needed ethers.js maps uint64 to bigint exactly as it did for uint256.

Why it matters

Tighter packing = fewer storage slots = less gas on every write, and the savings compound on array-heavy operations:

  • Basic testimonial creation: ~6% cheaper
  • Large-scale deletion: ~9.8% cheaper (444k gas saved)
  • Fuzz array management (mean over 256 runs): ~14.5% cheaper (652k gas saved)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions