Conversation
…nd cancellation safety ### Description This PR hardens the TypeScript SDK core order builder and cancellation paths against predictable order identifiers, implicit non-null assertions, and missing signer contracts[cite: 37]. It introduces cryptographic randomness for order salts, ensures fail-fast error handling for unassigned signers, and preserves zero-salt semantics[cite: 37]. ### Key Changes * **Cryptographic Order Salts (`sdk/src/OrderBuilder.ts`, `sdk-python/...`):** - Replaced non-cryptographic pseudo-random number generators (`Math.random()` / `random.randint`) with cryptographically secure random bytes and rejection sampling to completely eliminate modulo bias[cite: 37]. * **Explicit Signer Resolution (`sdk/src/OrderBuilder.ts`):** - Replaced unsafe non-null assertions (`this.signer!.address`) with strict typed failure handling, ensuring `MissingSignerError` is thrown predictably before any property dereference[cite: 37]. * **Predict-Account & Maker/Signer Semantics (`sdk/tests/OrderBuilder.test.ts`):** - Added robust test coverage confirming correct maker/signer precedence and fallback behaviors when utilizing Predict accounts[cite: 37]. ### Validation & Testing * **TypeScript Quality Gates:** Successfully passed `yarn typecheck`, `yarn lint`, and the full TypeScript regression suite (`yarn test` / Jest on-chain/unit tests).
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.
Description
This PR hardens the TypeScript SDK core order builder and cancellation paths against predictable order identifiers, implicit non-null assertions, and missing signer contracts[cite: 37]. It introduces cryptographic randomness for order salts, ensures fail-fast error handling for unassigned signers, and preserves zero-salt semantics[cite: 37].
Key Changes
sdk/src/OrderBuilder.ts,sdk-python/...):Math.random()/random.randint) with cryptographically secure random bytes and rejection sampling to completely eliminate modulo bias[cite: 37].sdk/src/OrderBuilder.ts):this.signer!.address) with strict typed failure handling, ensuringMissingSignerErroris thrown predictably before any property dereference[cite: 37].sdk/tests/OrderBuilder.test.ts):Validation & Testing
yarn typecheck,yarn lint, and the full TypeScript regression suite (yarn test/ Jest on-chain/unit tests).Note
Medium Risk
Changes affect how every default order gets its salt and how maker/signer are chosen before signing; incorrect resolution could break order submission, but scope is limited to
buildOrderandgenerateOrderSalt.Overview
Default order salts now come from
ethersrandomByteswith rejection sampling into[0, MAX_SALT], replacingMath.random()so salts are unpredictable and not modulo-biased.buildOrderresolves the signing identity asdata.signer→ connected wallet address →predictAccount, and throwsMissingSignerErrorwhen none exist instead of usingthis.signer!.address. Maker/signer mismatch is enforced only for non–Predict-account builders; Predict-account mode still forces maker and signer to the predict account.Tests add coverage for missing-signer failure and Predict-account maker/signer fields.
Reviewed by Cursor Bugbot for commit 404fa59. Bugbot is set up for automated code reviews on this repo. Configure here.