fix(python): use nanosecond nonces on every signed HTTP endpoint - #8
Open
Dusk1e wants to merge 1 commit into
Open
fix(python): use nanosecond nonces on every signed HTTP endpoint#8Dusk1e wants to merge 1 commit into
Dusk1e wants to merge 1 commit into
Conversation
update_leverage divided time.time_ns() by 1e5, and manage_agent_wallet, whitelist_faucet and request_faucet divided it by 1e6. place_orders, the WebSocket client and the Rust SDK's make_nonce() all use plain nanoseconds, so those four endpoints put a nonce on the wire 100000x-1000000x smaller than every other signed call from the same account. Dividing also quantises the nonce: at 1 ms granularity two calls inside the same millisecond reuse one nonce.
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
The Rust SDK has one nonce source,
make_nonce()incrates/api-rust/src/api/parts/mod.rs, and every signed method uses it:BulkHttpClient.place_ordersandBulkWebSocketClientagree — both usetime.time_ns(). But four other signed endpoints on the same client divide it:place_orderstime.time_ns()update_leverageint(time.time_ns() / 100000)manage_agent_walletint(time.time_ns() / 1000000)whitelist_faucetint(time.time_ns() / 1000000)request_faucetint(time.time_ns() / 1000000)Two consequences:
The nonce jumps backwards. Sampled at one frozen instant, the four divided endpoints emit a value 100000x–1000000x below what every other signed call from the same account emits. Any account that has placed an order is then sending leverage, agent-wallet and faucet transactions far below its own high-water mark.
Dividing quantises the nonce.
int(ns / 1000000)is millisecond-granular by construction, so two calls inside the same millisecond produce the same nonce — which is the one thing a nonce has to avoid.Changes
Use
time.time_ns()in all four, matchingplace_orders, the WebSocket client andmake_nonce(). Explicitnonce=arguments are untouched, and the two stale "in milliseconds" comments are corrected.Verification
Loading
bulk_http.pywith the stubs the repo's own tests use, freezing the clock and reading the nonce each endpoint puts on the wire:tests/test_history_http.pyandtests/test_wire_serialization.pyare unchanged by this (20 passed either way; the history failures onmainare #7).