LibMuon (0.8.4)
LibMuon Library (0.8.4)
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()
}
}verifyTSSAndGateway
Description: Performs dual signature verification:
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: ASchnorrSignstructure containing the TSS signature.gatewaySignature: The gateway signature as a byte array.
Implementation:
verifyPartyBUpnl
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: ASingleUpnlSigstructure containing uPNL data and signature details.partyB: Address of Party B.partyA: Address of Party A.
Implementation:
LibMuonAccount
verifyPartyAUpnl
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.
Parameters:
upnlSig: ASingleUpnlSigstructure.partyA: Address of Party A.
Implementation:
verifyPartyBUpnl (in LibMuonAccount)
Description:
Delegates to the core verifyPartyBUpnl function from LibMuon to validate Party B’s uPNL data.
LibMuonForceActions
verifyHighLowPrice
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.
Parameters:
sig: AHighLowPriceSigstructure.partyB: Address of Party B.partyA: Address of Party A.symbolId: Identifier of the trading symbol.
Implementation:
LibMuonFundingRate
verifyPairUpnl
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.
Parameters:
upnlSig: APairUpnlSigstructure.partyB: Address of Party B.partyA: Address of Party A.
Implementation:
LibMuonLiquidation
verifyLiquidationSig
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.
Parameters:
liquidationSig: ALiquidationSigstructure.partyA: Address of Party A.
Implementation:
verifyDeferredLiquidationSig
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: ADeferredLiquidationSigstructure.partyA: Address of Party A.
Implementation:
verifyQuotePrices
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: AQuotePriceSigstructure containing arrays of quote IDs and their prices.
Implementation:
LibMuonPartyB
verifyPairUpnlAndPrice
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.
Parameters:
upnlSig: APairUpnlAndPriceSigstructure.partyB: Address of Party B.partyA: Address of Party A.symbolId: Identifier of the trading symbol.
Implementation:
verifyPartyBUpnl (LibMuonPartyB)
Description: Delegates to the core LibMuon function to verify Party B’s uPNL data.
Implementation:
LibMuonSettlement
verifySettlement
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: ASettlementSigstructure containing:reqId, an array ofquotesSettlementsData,upnlPartyBs,upnlPartyA,timestamp, and signature data.
partyA: Address of Party A.
Implementation:
Last updated
