The LibMuon library provides essential cryptographic functions for the SYMM ecosystem. Its primary responsibility is to verify signed data used by SYMM contracts. This includes validating uPNL calculations, price data, liquidation events, and settlement data. It relies on trusted Muon signatures (via a TSS mechanism) and gateway signature verification to ensure that all data is authentic and has not been tampered with.
Core Functions
getChainId
Description:
Retrieves the unique chain ID of the blockchain on which the contract is executing. This value is used to ensure that data is tied to the correct network context.
Implementation:
function getChainId() internal view returns (uint256 id) {
assembly {
id := chainid()
}
}
TSS Verification:
Uses the Muon TSS (via LibMuonV04ClientBase.muonVerify) to verify that the data’s hash is signed by the correct Muon public key.
Gateway Signature Verification:
Converts the hash to an Ethereum signed message hash and recovers the signer’s address. This address must match the valid gateway address stored in MuonStorage.
Parameters:
hash: The hash of the data to verify.
sign: A SchnorrSign structure containing the TSS signature.
gatewaySignature: The gateway signature as a byte array.
Description:
Verifies the uPNL data for Party B. This function checks that the provided signature has not expired, constructs a hash from key parameters (including Party B’s nonce, the uPNL value, and the current chain ID), and then calls verifyTSSAndGateway for final verification.
Parameters:
upnlSig: A SingleUpnlSig structure containing uPNL data and signature details.
Description:
Verifies the uPNL data for Party A. Constructs a hash using Party A’s nonce and uPNL value, then validates it using the TSS and gateway verification.
Description:
Verifies that the provided high, low, current, and average price data (contained in a HighLowPriceSig structure) are authentic and within valid time limits. It constructs a hash that includes nonces and market price data and verifies the signature.
Description:
Verifies the pair uPNL data used for funding rate calculations by constructing a hash that includes both Party B and Party A's uPNL values along with their nonces and verifying the signature.
Description:
Validates the liquidation signal for Party A by ensuring that the prices and symbol IDs arrays have matching lengths, then constructing a hash from key liquidation parameters (including the liquidation ID, uPNL values, and nonce) and verifying it.
Description:
Verifies a deferred liquidation signature by including additional parameters (e.g. liquidation block number, timestamp, and allocated balance) in the hash. This ensures that deferred liquidation data is valid and securely signed.
Parameters:
liquidationSig: A DeferredLiquidationSig structure.
Description:
Ensures the integrity of quote price data by verifying that the prices array matches the quote IDs array, constructing a corresponding hash, and then validating the signatures.
Parameters:
priceSig: A QuotePriceSig structure containing arrays of quote IDs and their prices.
Description:
Verifies combined uPNL data and price information for both Party B and Party A for a specific symbol. It constructs a hash using the nonces, uPNL values, and the price, then validates the signatures.
Description:
Validates the settlement data for a set of quotes by constructing a hash that aggregates critical settlement details (including quote settlement data, nonces, and uPNL values) and then verifying the signature with the TSS and gateway mechanisms.
Parameters:
settleSig: A SettlementSig structure containing:
reqId, an array of quotesSettlementsData, upnlPartyBs, upnlPartyA, timestamp, and signature data.