Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/Polymarket/ctf-exchange/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The Signatures mixin provides comprehensive signature validation for orders. It supports multiple signature types to accommodate different wallet architectures used on Polymarket, including EOA wallets, Polymarket Proxy wallets, Polymarket Gnosis Safes, and EIP-1271 compatible smart contracts. Source: src/exchange/mixins/Signatures.sol

Supported Signature Types

The CTF Exchange supports four distinct signature types:
  • EOA: ECDSA EIP712 signatures signed by externally owned accounts
  • POLY_PROXY: EIP712 signatures signed by EOAs that own Polymarket Proxy wallets
  • POLY_GNOSIS_SAFE: EIP712 signatures signed by EOAs that own Polymarket Gnosis Safes
  • POLY_1271: Signatures from EIP-1271 compatible smart contracts

Constructor

constructor(address _proxyFactory, address _safeFactory) PolyFactoryHelper(_proxyFactory, _safeFactory)
Initializes the Signatures mixin by calling the parent PolyFactoryHelper constructor with factory addresses.

Parameters

  • _proxyFactory (address): The address of the Polymarket proxy factory
  • _safeFactory (address): The address of the Polymarket Gnosis Safe factory

Functions

validateOrderSignature

function validateOrderSignature(bytes32 orderHash, Order memory order) public view override
Validates the signature of an order. Calls isValidSignature and reverts if the signature is invalid.

Parameters

  • orderHash (bytes32): The hash of the order
  • order (Order): The order object containing the signature and signature type

Reverts

  • InvalidSignature() if the signature validation fails

isValidSignature

function isValidSignature(
    address signer,
    address associated,
    bytes32 structHash,
    bytes memory signature,
    SignatureType signatureType
) internal view returns (bool)
Verifies a signature for signed Order structs. Routes to the appropriate verification function based on the signature type.

Parameters

  • signer (address): Address of the signer
  • associated (address): Address associated with the signer
    • For EOA: Must be the same as the signer address
    • For POLY_PROXY and POLY_GNOSIS_SAFE: The address of the proxy or safe
    • For POLY_1271: The address of the smart contract
  • structHash (bytes32): The hash of the struct being verified
  • signature (bytes): The signature to be verified
  • signatureType (SignatureType): The type of signature

Returns

  • bool: true if the signature is valid, false otherwise

verifyEOASignature

function verifyEOASignature(
    address signer,
    address maker,
    bytes32 structHash,
    bytes memory signature
) internal pure returns (bool)
Verifies an EOA ECDSA signature.

Verification Checks

  1. The signature is a valid ECDSA signature
  2. The signer and maker addresses are the same

Parameters

  • signer (address): The address of the signer
  • maker (address): The address of the maker
  • structHash (bytes32): The hash of the struct being verified
  • signature (bytes): The signature to be verified

Returns

  • bool: true if valid, false otherwise

verifyECDSASignature

function verifyECDSASignature(
    address signer,
    bytes32 structHash,
    bytes memory signature
) internal pure returns (bool)
Verifies an ECDSA signature by recovering the signer from the signature and comparing it to the expected signer address.

Parameters

  • signer (address): The expected signer address
  • structHash (bytes32): The hash of the struct being verified
  • signature (bytes): The signature to be verified

Returns

  • bool: true if the recovered signer matches the expected signer

verifyPolyProxySignature

function verifyPolyProxySignature(
    address signer,
    address proxyWallet,
    bytes32 structHash,
    bytes memory signature
) internal view returns (bool)
Verifies a signature signed by the owner of a Polymarket proxy wallet.

Verification Checks

  1. The ECDSA signature is valid
  2. The proxy wallet is owned by the signer

Parameters

  • signer (address): Address of the signer
  • proxyWallet (address): Address of the Polymarket proxy wallet
  • structHash (bytes32): Hash of the struct being verified
  • signature (bytes): Signature to be verified

Returns

  • bool: true if valid, false otherwise

verifyPolySafeSignature

function verifyPolySafeSignature(
    address signer,
    address safeAddress,
    bytes32 hash,
    bytes memory signature
) internal view returns (bool)
Verifies a signature signed by the owner of a Polymarket Gnosis Safe.

Verification Checks

  1. The ECDSA signature is valid
  2. The Safe is owned by the signer

Parameters

  • signer (address): Address of the signer
  • safeAddress (address): Address of the Gnosis Safe
  • hash (bytes32): Hash of the struct being verified
  • signature (bytes): Signature to be verified

Returns

  • bool: true if valid, false otherwise

verifyPoly1271Signature

function verifyPoly1271Signature(
    address signer,
    address maker,
    bytes32 hash,
    bytes memory signature
) internal view returns (bool)
Verifies a signature signed by an EIP-1271 compatible smart contract.

Verification Checks

  1. The signer and maker addresses are the same
  2. The maker address has contract code deployed
  3. The contract’s isValidSignature function returns success

Parameters

  • signer (address): Address of the smart contract signer
  • maker (address): Address of the smart contract maker
  • hash (bytes32): Hash of the struct being verified
  • signature (bytes): Signature to be verified

Returns

  • bool: true if valid, false otherwise

Errors

InvalidSignature

error InvalidSignature()
Thrown when signature validation fails.

Implementation Details

The signature validation flow:
  1. validateOrderSignature is called with an order hash and order
  2. It calls isValidSignature with the order’s signature details
  3. isValidSignature routes to the appropriate verification function based on signatureType
  4. The specific verification function performs validation checks and returns a boolean
  5. If validation fails, InvalidSignature() error is thrown
This modular approach allows the exchange to support multiple wallet types while maintaining clean, testable code for each signature type.

Build docs developers (and LLMs) love