Using the wrong domain (name, version, or
verifyingContract) produces
a signature that recovers a different address than your signer. For
orders, the backend rejects the request with bad_signature, and the
exchange contract would reject the same signature with
InvalidSignature(). For withdrawals, POST /api/withdrawals/request
rejects it with HTTP 400 invalid_signature before anything is sent
on-chain. For split / merge / convert, the backend co-signs without
seeing your signature. If you relay the op through
POST /api/me/positions/op-submit with an API key, it is rejected with
HTTP 403 op_signer_mismatch; if you broadcast the vault call
yourself, the vault contract rejects it with InvalidOwnerSignature().
Order-signing domain
Generation 1 vs Generation 2 markets:
- On Generation 2 markets (
contractGeneration: 2onGET /api/markets/{symbol}),verifyingContractismarket.exchangeAddress, andmakermust be your generation-2 vault (fromGET /api/me/vaultvaults[]). - On Generation 1 (legacy) markets (
contractGeneration: 1),verifyingContractismarket.exchangeAddresswhen it is set, otherwise eitherCTFExchangeorNegRiskCtfExchangebased onmarket.negRiskEligible, andmakeris your generation-1 vault (VaultFactory.vaultOf(signer)). - Submitting an order with a vault of the wrong generation fails with
409 vault_generation_mismatch(details: { vaultAddress, marketGeneration, exchangeAddress, vaults }). If you have no vault deployed for that generation, placement fails with409 vault_generation_missing. See Detect a market’s generation.
Order struct
Field semantics
Signature type: always VAULT (1)
PredictStreet is vault-only. Every order (retail, integrator and market
maker) must be signed with signatureType: 1 (VAULT):
signer= your wallet EOA (the wallet you authenticate as)maker= your vault of the market’s generation- Funds source: your vault contract
- On-chain check:
ecrecover(digest, signature) == signerandvaultOf(signer) == makeron the vault factory of that generation.
Canonical 65-byte (r, s, v) signature encoding
Order placement (POST /api/orders/place and POST /api/orders/place-batch)
enforces the exact 65-byte ECDSA encoding verified on chain by OpenZeppelin 4.8
ECDSA.recover (RND-2432):
0x+ 130 hex characters (r ‖ s ‖ v, 65 bytes).vin{27, 28}(0x1bor0x1c).- Non-zero
rands, with lows <= secp256k1n / 2(0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0, EIP-2).
ethers wallet.signTypedData(...) and Python eth_account
Account.sign_typed_data(...) emit this canonical form natively. Non-canonical
encodings (such as 64-byte EIP-2098 compact signatures, v = 0 or 1,
EIP-155 v >= 35, zero r or s, or high s) are rejected before curve
recovery with code: "bad_signature" and details: { expected_signer, signature_form }.
What the platform rebuilds
POST /api/orders/place (and each entry of /api/orders/place-batch)
does not carry the signed struct. The platform rebuilds the Order from
the REST body and your authenticated wallet, hashes it under the
market’s domain (exchangeAddress, or binary / neg-risk per
negRiskEligible when it is null), and checks
that the signature recovers to your wallet. Every field you sign must
match what it rebuilds:
The REST body
maker field is only an authorization check. It must be
your wallet EOA or one of your vaults; any other value is rejected with
maker_mismatch (HTTP 401 on /api/orders/place; on
/api/orders/place-batch only that entry is rejected). Your vault of the other generation is
refused with 409 vault_generation_mismatch. Your wallet or your vault
of the market’s generation leaves the digest unchanged: the platform
verifies with that vault as maker and stores the order with it.
For SELL, the position lookup is keyed by the vault address, since the
ERC-1155 tokens live there. This is automatic.
Amount semantics
BothmakerAmount and takerAmount are 6-decimal wei (USDC-scale).
tokenId-denominated quantities use the same scale: 1 outcome token =
1_000_000 wei.
For
BUY at price 0.42 and qty 2.0: makerAmount = 840_000,
takerAmount = 2_000_000. (Clean-cent tuple — CEIL and FLOOR
coincide. See the next section for the boundary cases that matter.)
Rounding rule: CEIL on BUY, FLOOR on SELL notional
The on-chain CTFExchange recomputes each side’s price by an INDEPENDENT floor-div, scaled to 18 decimals (ONE = 1e18):
- BUY — round the USDC notional UP (
CEIL). Adds at most 1 wei extra USDC (sub-cent), guarantees the chain-sidecalculatePrice(BUY)is at least your limit price and gives the matcher’s CEIL’d per-fill math the +1 wei of headroom it needs against your signed cap. FLOOR-signed BUY orders are rejected at placement withorder_signed_with_floor_notional— they sit on the book with ZERO headroom and overflow the chain invariantMakingGtRemainingon the closing tail fill, which forces a different taker to absorb the revert. - SELL — round the USDC notional DOWN (
FLOOR). CEIL’ing the SELL would pushcalculatePrice(SELL)above your limit price and trip the BURN-boundarypriceA + priceB <= ONEcheck. makerAmountitself on SELL is the exact outcome-token quantity — no rounding (makerAmount = qtyWei).
MakingGtRemaining). It is the correct shape, not a bug.
Worked example — boundary tuple
BUY at price 0.52, qty 67.307692:
notionalCeil
for BUY.makerAmount.
Signing example — TypeScript
Signing example — Python
Order ID
TheorderId is a server-assigned UUID returned in the
POST /api/orders/place response. It is an empty string when the order
was rejected before it was recorded (validation, signature, fee or
funds checks). An order the matching engine rejects after it was
recorded (for example self_cross_blocked) comes back as REJECTED
with its real orderId, so branch on status, not on orderId. You
can’t derive it from the signature or the signed
struct on the client. Use it for POST /api/orders/cancel and
GET /api/orders/{id}. To match a response to your request, set
clientOrderId on the place request. The response echoes it back on
every outcome, including rejections and idempotent replays.
Order hash
TheorderHash is the EIP-712 digest of the Order you signed, the
same value the exchange contract emits in OrderFilled. You can compute
it before sending, for example with ethers:
TypedDataEncoder.hash(domain, types, orderStruct). It comes back
lowercase as orderHash on every order read and on the order_placed
WebSocket frame, and GET /api/orders/lookup?orderHash= finds the order
by it, which helps when a place request timed out before you saw the
orderId.
Split / merge / convert-positions — different domain
Vault position operations (splitPosition, mergePositions,
convertPositions) sign under the vault’s own EIP-712 domain, not
the exchange’s. The domain name changes (PredictStreetVault) and
verifyingContract is the user’s own vault address — NOT the
factory, NOT an exchange.
SplitPosition, MergePositions
or ConvertPositions. Split and merge carry a kind field (0 = binary,
1 = neg-risk); ConvertPositions(bytes32 marketId,uint256 indexSet,uint256 amount,uint256 salt,uint256 deadline)
has none. The struct layouts and the full dual-signature flow (owner +
backend co-sig) are documented on
Contracts → Vaults → EIP-712 domain.
Common signing mistakes
- Wrong
verifyingContractfor the market — binary vs neg-risk. Both exchanges sharename+versionbut have distinct addresses, so the domain separators are distinct. ReadnegRiskEligibleoffGET /api/markets/{symbol}to pick. - Using the Order domain for split / merge / convertPositions —
those operations sign under the
PredictStreetVaultdomain withverifyingContract= the user’s vault, not the exchange. See the section above. - Signing with a key other than the wallet you authenticate as —
the platform sets
signerto your authenticated wallet: the API key’sassociatedWallet, or theX-User-Walletheader value formulti_walletkeys. You don’t sendsignerin the request body. If the bodymakeris neither that wallet nor one of its vaults, the request is rejected withmaker_mismatch. Otherwise, a signature from any other key fails withbad_signature, anddetails.expected_signeris your authenticated wallet.details.recoveredshows the key you signed with only if the struct you signed matchesdetails.platform_canonical_structfield for field (includingsigner) and you used the market’s domain; otherwiserecoveredis an unrelated address, so compare the struct first. - Signed
maker= your EOA, orsignatureType: 0— the signedmakermust be your vault of the market’s generation (GET /api/me/vaultvaults[]), andsignatureTypemust be1. There is no EOA-direct mode. The request-bodymakermay be your EOA or your vault, but the signature is always checked against that vault asmaker. The platform deploys vaults automatically (see Backend auto-deploy). Until yours is deployed, placement is rejected withvault_not_deployedbefore the signature is checked. feeRateBps≠ livemarket.feeTakerBps— the platform rebuilds the struct with the market’s current taker fee at placement time. Hard-coding0or keeping a stale value across fee-period transitions is the usual cause. Re-fetchGET /api/markets/{symbol}.feeTakerBpsright before you build the digest, sign with that exact integer, and echo it asfeeRateBpsin the request body. With the echo, a stale fee is rejected clearly asstale_fee_quoteinstead of a genericbad_signature.expiration > 0with a tight TTL — onPOST /api/orders/placeandplace-batch, any non-zeroexpirationmust be more than 60 seconds in the future relative to server time (the 30s settlement safety window plus a 30s placement margin). An order expiring sooner is refused with400 order_expiry_too_soon(details.minExpirationgives the earliest accepted Unix timestamp; onplace-batchthe entry isREJECTEDin its slot). Furthermore, settlement is async, so even if an order passes placement with a short TTL, it can expire between off-chain match and on-chain submit, surfacing asMatchFailed(OrderExpired)(selector0xc56873ba). Use0unless you specifically need a hard TTL well above worst-case settlement latency (~30s in production).- Reused
salt— every order’s hash is single-use on-chain. nonce≠ signedsalt— the body’snonceis the struct’ssalt. Generate the salt once, sign with it, and sendsalt.toString()(base 10, not hex) asnonce. Two independently generated random values always fail withbad_signature.- FLOOR-rounded BUY
makerAmount—(priceWei * qtyWei) / 1_000_000nin JS / Python uses integer FLOOR division. For boundary tuples (e.g.0.52 × 67.307692) FLOOR produces34_999_999, CEIL produces35_000_000. The platform rejects FLOOR-signed BUY orders at placement withorder_signed_with_floor_notionalso they never poison the book. Fix: use the CEIL formula(product + 999_999n) / 1_000_000n. See the Rounding rule section above. The reject envelope’sdetailscarries the exactexpectedCeilMakerAmountWeiyou should re-sign with, so you don’t need to recompute the formula client-side.
Debugging bad_signature
bad_signature is a business reject: POST /api/orders/place answers
HTTP 201 with status: "REJECTED" and code: "bad_signature" (and
POST /api/orders/place-batch answers success: false, status: "REJECTED"
in that entry’s slot). The details block takes one of two shapes (RND-2432):
- Non-canonical signature encoding (
message: "EIP-712 signature invalid: expected 65 bytes (r, s, v) with v = 27 or 28 and a low s"):expected_signer: your authenticated wallet.signature_form: why the byte encoding was refused (not_hexfor an odd hex length,length_<bytes>such aslength_64,v_<hex>such asv_00/v_01/ EIP-155v >= 35,zero_r_or_s,high_s, orhigh_s_top_bit).recoveredandplatform_canonical_structare omitted on this trigger. Serialize the full 65-byte(r, s, v)signature withv = 27or28and lows. (Replays of orders committed before this gate under previously admitted forms —length_64,v_00,v_01,v >= 35,high_s— that recover the signer still run the duplicate probe and returnorder_already_placed.)
- Canonical 65-byte signature recovering the wrong address (
message: "EIP-712 signature invalid"):recovered: the address your signature recovers to against the platform’s struct (nullif curve recovery fails on the 65-byte tuple).expected_signer: your authenticated wallet.platform_canonical_struct: the exactOrderstruct the platform hashed (see What the platform rebuilds).
platform_canonical_struct,
so when platform_canonical_struct is present, compare it with the struct you signed,
field by field:
- A difference in
maker,signer,taker,feeRateBpsorsignatureTypemeans you signed the wrong value: sign the platform’s value (your vault, your authenticated wallet, the zero address, the market’sfeeTakerBps,1). - A difference in
salt,tokenId,makerAmount/takerAmount,expirationorsidemeans the struct you signed and the body you sent disagree (nonce,outcome,price/quantity,expiry,side), or your amounts were rounded differently (see the Rounding rule). Make them describe the same order, then re-sign. - If every field matches, check the domain, which the struct does not
include:
market.exchangeAddresson generation-2 markets, or the binary vs neg-riskverifyingContractfor the market’snegRiskEligibleon generation-1 markets. Then check that you signed with your authenticated wallet’s key (mistake 3 above).
expected_signer,
but the order had an expired or too-soon expiration (within the 60s
safety window), the gateway returns 400 order_expiry_too_soon rather than
bad_signature. Therefore, a bad_signature response always indicates an
actual cryptographic verification mismatch (wrong key, mismatched struct
field, or incorrect domain separator / verifyingContract). See also
bad_signature diagnostic hints.