For the complete documentation index, see llms.txt. This page is also available as Markdown.

LibMuon (0.8.5)

The LibMuon library provides the cryptographic functions that verify signed data for SYMM contracts: uPNL calculations, price data, liquidation events, and settlement data. It relies on trusted Muon signatures (via a TSS mechanism) and gateway signature checks to confirm the data is authentic and unmodified.


Core Functions

getChainId

Returns the chain ID of the network the contract runs on. Used to tie signed data to the correct network.

function getChainId() internal view returns (uint256 id) {
    assembly {
        id := chainid()
    }
}

verifyTSSAndGateway

Runs two signature checks:

  1. TSS verification: calls LibMuonV04ClientBase.muonVerify to confirm the data hash is signed by the Muon public key.

  2. Gateway verification: converts the hash to an Ethereum signed message hash and recovers the signer address, which must match the validGateway address stored in MuonStorage.

Parameters:

  • hash: Hash of the data to verify.

  • sign: SchnorrSign structure holding the TSS signature.

  • gatewaySignature: The gateway signature as a byte array.


verifyPartyBUpnl

Verifies PartyB's uPNL data. Checks the signature has not expired, builds a hash from key parameters (PartyB's nonce, the uPNL value, the current chain ID), then calls verifyTSSAndGateway.

Parameters:

  • upnlSig: SingleUpnlSig structure holding uPNL data and signature details.

  • partyB: PartyB address.

  • partyA: PartyA address.


LibMuonAccount

verifyPartyAUpnl

Verifies PartyA's uPNL data. Builds a hash from PartyA's nonce and uPNL value, then validates it through TSS and gateway verification.

Parameters:

  • upnlSig: SingleUpnlSig structure.

  • partyA: PartyA address.

verifyPartyBUpnl (LibMuonAccount)

Delegates to LibMuon's verifyPartyBUpnl to validate PartyB's uPNL data.


LibMuonForceActions

verifyHighLowPrice

Verifies that the high, low, current, and average price data in a HighLowPriceSig are authentic and within the valid time window. Builds a hash from nonces and market price data, then verifies the signature.

Parameters:

  • sig: HighLowPriceSig structure.

  • partyB: PartyB address.

  • partyA: PartyA address.

  • symbolId: Trading symbol identifier.


LibMuonFundingRate

verifyPairUpnl

Verifies the pair uPNL data used in funding rate calculations. Builds a hash from both PartyB and PartyA uPNL values and their nonces, then verifies the signature.

Parameters:

  • upnlSig: PairUpnlSig structure.

  • partyB: PartyB address.

  • partyA: PartyA address.


LibMuonLiquidation

verifyLiquidationSig

Validates the liquidation signal for PartyA. Requires the prices and symbolIds arrays to have matching lengths, builds a hash from key liquidation parameters (liquidation ID, uPNL values, nonce), then verifies it.

Parameters:

  • liquidationSig: LiquidationSig structure.

  • partyA: PartyA address.

verifyDeferredLiquidationSig

Verifies a deferred liquidation signature. Includes extra parameters in the hash (liquidation block number, timestamp, allocated balance) so the deferred liquidation data is validated and signed.

Parameters:

  • liquidationSig: DeferredLiquidationSig structure.

  • partyA: PartyA address.

verifyQuotePrices

Verifies quote price data. Requires the prices array to match the quoteIds array, builds the corresponding hash, then validates the signatures.

Parameters:

  • priceSig: QuotePriceSig structure holding arrays of quote IDs and their prices.


LibMuonPartyB

verifyPairUpnlAndPrice

Verifies combined uPNL and price data for PartyB and PartyA on a given symbol. Builds a hash from the nonces, uPNL values, and price, then validates the signatures.

Parameters:

  • upnlSig: PairUpnlAndPriceSig structure.

  • partyB: PartyB address.

  • partyA: PartyA address.

  • symbolId: Trading symbol identifier.

verifyPartyBUpnl (LibMuonPartyB)

Delegates to LibMuon's verifyPartyBUpnl to verify PartyB's uPNL data.


LibMuonSettlement

verifySettlement

Validates settlement data for a set of quotes. Builds a hash aggregating settlement details (quote settlement data, nonces, uPNL values), then verifies the signature through the TSS and gateway checks.

Parameters:

  • settleSig: SettlementSig structure containing reqId, an array of quotesSettlementsData, upnlPartyBs, upnlPartyA, timestamp, and signature data.

  • partyA: PartyA address.

Last updated