Skip to main content
Back to Blog
ArchitectureOctober 28, 20266 min read

Sub-15ms Physical Presence: Inside Our Dynamic TOTP, Atomic Replay Shield & Haversine Pipeline

How we engineered an atomic verification hot path that evaluates RFC 6238 drift windows, distributed replay locks, and float64 spherical geometry in 3.2 milliseconds.

setsig Core Systems•Core Engine Architecture

Constant-Time RFC 6238 Drift Windows Without Timing Leaks

Physical turnstiles and kiosk tablets rarely share sub-millisecond NTP synchronization with attendee smartphones. Instead of widening static token lifetimes and inviting screenshot forwarding, our verification engine signs short 30-to-60-second step payloads and evaluates a strict ±1 step grace window.

Every candidate signature is compared strictly via constant-time byte evaluation, ensuring attackers cannot infer partial HMAC digests across high-throughput stadium gates.

dynamic-totp-verifier.go
func VerifyDynamicToken(parsed *DynamicTokenPayload, venueID uuid.UUID, secretKey string, ttlSeconds int) (bool, bool) {
nowUnix := time.Now().UTC().Unix()
currentStep := nowUnix / int64(ttlSeconds)
tokenStep := parsed.Timestamp / int64(ttlSeconds)
 
for _, stepCandidate := range []int64{tokenStep, currentStep, currentStep - 1, currentStep + 1} {
signPayload := fmt.Sprintf("%s:%s:%d", parsed.TokenID, venueID.String(), stepCandidate)
expectedSig := SignHMACSHA256(signPayload, secretKey)[:16]
if ConstantTimeCompareStrings(parsed.Signature, expectedSig) {
isExpired := (nowUnix - parsed.Timestamp) > int64(ttlSeconds*2)
return true, isExpired
}
}
return false, false
}

Two-Tier Double-Spend Immunity at the Edge

When two devices scan the same optical challenge simultaneously, naive database reads create a classic time-of-check to time-of-use race condition. Before running Haversine math or enclave checks, setsig acquires a distributed atomic single-use lock at the edge.

Once verified, the session is persisted into an immutable append-only verification ledger with a strict per-workspace uniqueness guarantee, reducing replay surface to zero.

replay-protection-response.json
// Duplicate or concurrent scan rejected atomically at the edge
// POST https://api.setsig.com/v1/sessions/verify -> 409 Conflict
{
"error_code": "ERR_REPLAY_DETECTED",
"message": "This token has already been consumed (replay attack detected)",
"localized_message": "This token has already been consumed.",
"locale": "en"
}

Further Engineering Dispatches

Deploy non-repudiable physical presence today

Start with free sandbox credits and integrate any of our 8 official SDKs in minutes.

Control which cookie categories are active during your visit. You can update your choices at any time from the footer.

Strictly NecessaryAlways Active

Required for language selection, security headers, and storing your consent preferences. Cannot be disabled.

Analytics & Performance

Helps us understand page visits, latency, and navigation patterns through Google Analytics and Tag Manager.

Campaign Measurement

Measures referral attribution and campaign effectiveness across external marketing channels.