Skip to content

fix: warn at compile time when a method uses network.timestamp - #2937

Open
Tyagiquamar wants to merge 2 commits into
o1-labs:mainfrom
Tyagiquamar:fix/timestamp-precondition-warning
Open

Tyagiquamar wants to merge 2 commits into
o1-labs:mainfrom
Tyagiquamar:fix/timestamp-precondition-warning

Conversation

@Tyagiquamar

Copy link
Copy Markdown

Summary

Using this.network.timestamp inside a proved zkApp method now emits a one-time compile-time warning that points developers to this.currentSlot.requireBetween(...). The warning fires while the circuit is being analyzed/compiled (inCompileMode), so it appears at compile time and not on every proof run. The timestamp precondition type and the currentSlot getter are also documented with the caveat.

Closes #2931.

Root Cause

network.timestamp preconditions convert a timestamp bound into a global slot using genesisTimestamp and slotTime from Mina.getNetworkConstants() (src/lib/mina/v1/precondition.ts). Those constants are fixed into the circuit at compile time, and they assume a single slot time for the whole chain history. After the Mesa hardfork the slot time changed (180 s to 90 s), so the slot is no longer a linear function of the timestamp: every method with a timestamp bound produces an unsatisfiable precondition and transactions fail with Protocol_state_precondition_unsatisfied while the fee is still paid. currentSlot.requireBetween works because it constrains the global slot directly, which is counted from the network's original genesis and stays correct across slot-time changes.

Solution

  • Added warnTimestampPrecondition() in src/lib/mina/v1/precondition.ts, called from all network.timestamp methods (get, getAndRequireEquals, requireEquals, requireEqualsIf, requireBetween). It warns once per process and only in compile/analyze mode (inCompileMode() from provable-context), so off-chain execution and proof generation stay silent.
  • Documented the caveat on the timestamp field of the Network precondition type and on the SmartContract.currentSlot getter, recommending currentSlot.requireBetween(...) for time checks in circuits.

Test Plan

  • New regression test in src/lib/mina/v1/precondition.test.ts: analyzes a contract whose method uses currentSlot.requireBetween (expects no warning), then a contract using network.timestamp (expects exactly one warning mentioning currentSlot).
  • Verified locally in Docker (node:22-bookworm): npm run build passes, oxlint clean, prettier --check clean, and an equivalent Node script against dist/node confirms 0 warnings for currentSlot and exactly 1 warning for network.timestamp.
  • npx jest src/lib/mina/v1/precondition.test.ts run in Docker; the rest of the suite passed in a prior full run (19 passed, 1 skipped) with only the new test failing before the timestamp-bounds fix, which has since been corrected.

Timestamp preconditions cannot be correct after the Mesa hardfork,
which changed the slot time, so the timestamp is no longer a linear
function of the global slot. Using network.timestamp in a proved
method now emits a one-time compile-time warning that points to
currentSlot.requireBetween, which works with global slots since the
network's original genesis. Also documents the caveat on the
timestamp precondition and the currentSlot getter.

Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
Signed-off-by: Tyagiquamar <mohdquamartyagi@gmail.com>
@Tyagiquamar
Tyagiquamar force-pushed the fix/timestamp-precondition-warning branch from c02f4fc to 608bee6 Compare December 5, 2026 07:19

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

network.timestamp preconditions cannot be correct after Mesa changed the slot time; warn and point to currentSlot

1 participant