Repository navigation
fix: warn at compile time when a method uses network.timestamp - #2937
Open
Tyagiquamar wants to merge 2 commits into
Open
Tyagiquamar wants to merge 2 commits into
Tyagiquamar wants to merge 2 commits into
Conversation
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
force-pushed
the
fix/timestamp-precondition-warning
branch
from
December 5, 2026 07:19
c02f4fc to
608bee6
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Using
this.network.timestampinside a proved zkApp method now emits a one-time compile-time warning that points developers tothis.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. Thetimestampprecondition type and thecurrentSlotgetter are also documented with the caveat.Closes #2931.
Root Cause
network.timestamppreconditions convert a timestamp bound into a global slot usinggenesisTimestampandslotTimefromMina.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 withProtocol_state_precondition_unsatisfiedwhile the fee is still paid.currentSlot.requireBetweenworks because it constrains the global slot directly, which is counted from the network's original genesis and stays correct across slot-time changes.Solution
warnTimestampPrecondition()insrc/lib/mina/v1/precondition.ts, called from allnetwork.timestampmethods (get,getAndRequireEquals,requireEquals,requireEqualsIf,requireBetween). It warns once per process and only in compile/analyze mode (inCompileMode()fromprovable-context), so off-chain execution and proof generation stay silent.timestampfield of theNetworkprecondition type and on theSmartContract.currentSlotgetter, recommendingcurrentSlot.requireBetween(...)for time checks in circuits.Test Plan
src/lib/mina/v1/precondition.test.ts: analyzes a contract whose method usescurrentSlot.requireBetween(expects no warning), then a contract usingnetwork.timestamp(expects exactly one warning mentioningcurrentSlot).node:22-bookworm):npm run buildpasses,oxlintclean,prettier --checkclean, and an equivalent Node script againstdist/nodeconfirms 0 warnings forcurrentSlotand exactly 1 warning fornetwork.timestamp.npx jest src/lib/mina/v1/precondition.test.tsrun 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.