How to Handle Timestamp Manipulation in Solidity Interviews?
Got stumped in a Solidity interview today—and could really use some advice.
The question was: How do you prevent miners from manipulating block.timestamp
in a Solidity auction where timing matters?
I was building a smart contract where auctions start and end based on timestamps. The interviewer pointed out that miners can tweak timestamps slightly, which could unfairly extend or shorten auctions. Using block.number
wasn’t ideal either—since blocks aren’t mined at fixed intervals—and relying on oracles would spike gas costs.
I suggested averaging block times or combining timestamps with block numbers, but they said both approaches were either still vulnerable or overly complex.
So now I’m wondering:
What’s the best way to mitigate timestamp manipulation in Solidity?
Are there simple, production-tested patterns for this?
How do you balance gas efficiency and fairness in time-sensitive smart contracts?
If you've faced this in interviews or real-world projects, I’d love to hear your take. 🙌