Skip to content

Instantly share code, notes, and snippets.

@svyatonik
Last active March 11, 2024 14:19
Show Gist options
  • Save svyatonik/f10af78da7179e60088369fad70259ba to your computer and use it in GitHub Desktop.
Save svyatonik/f10af78da7179e60088369fad70259ba to your computer and use it in GitHub Desktop.
pk-bridge-fees.md

I've reproduced my tests with latest changes to constants + estimations:

  1. cost of Polkadot -> Kusama message: 2.40 DOT
  2. cost of Kusama -> Polkadot message: 0.40 KSM

Details for Polkadot -> Kusama message:

  1. cost of XCM execution at Polkadot BH: 0.48 DOT
  2. cost of message delivery transaction at Kusama BH: 0.3 DOT (converted from 0.06 KSM)
  3. cost of delivery confirmation transaction at Polkadot BH: 1.62 DOT

Details for Kusama -> Polkadot message:

  1. cost of XCM execution at Kusama BH: 0.02 KSM
  2. cost of message delivery transaction at Polkadot BH: 0.34 KSM (converted from 1.7 DOT)
  3. cost of delivery confirmation transaction at Kusama AH: 0.05 DOT

Every cost from above has 33% reserve. So actual test result is X * 3 / 4.

Details of XCM execution estimations: https://github.com/paritytech/polkadot-sdk/blob/ce1c9a44a79841ee03878be9710ac49401c71aa6/cumulus/parachains/runtimes/bridge-hubs/test-utils/src/test_cases/mod.rs#L570-L673. TLDR: it is an execution cost (WeightToFee(XcmWeight(<program>))) of a regular program that is executed at BH when reserve_asset_transfer is called at AH.

Details of message delivery transaction estimation:

  1. delivered message (XCM) is assumed to be 1K. The storage proof overhead is minimal;
  2. proved parachain head (BH header) is minimal. The storage proof overhead is minimal;
  3. proved relay chain header + justification is assumed to be the max refundable amount that we are paying to relayer in GRANDPA pallet. So it is a AVERAGE_HEADER_SIZE + justification size that is computed assuming two AVERAGE_HEADER_SIZE-byte headers in the ancestry proof + signatures of 838 validators.

Details of delivery confirmation transaction:

  1. delivery proof and storage proof overhead is assumed to be minimal;
  2. proved parachain head (BH header) is minimal. The storage proof overhead is minimal;
  3. proved relay chain header + justification is assumed to be the max refundable amount that we are paying to relayer in GRANDPA pallet. So it is a AVERAGE_HEADER_SIZE + justification size that is computed assuming two AVERAGE_HEADER_SIZE-byte headers in the ancestry proof + signatures of 838 validators.

AVERAGE_HEADER_SIZE is set to 1_024, even though normally it is 327. 838 is the MAX_AUTHORITIES_COUNT * 2/3+1, where MAX_AUTHORITIES_COUNT is set to 1_256. Actual (atm) authorities count at Polkadot is ~300. Actual (atm) authorities count at Kusama is 1000.


First things that catches the eye:

  1. Polkadot BH transactions are much more expensive than Kusama AH. E.g. delivery is 0.3 DOT for Polkadot->Kusama messages and 1.7 DOT for Kusama->Polkadot messages;
  2. the biggest fee share comes from the GRANDPA justification size (i.e. not from the execution weight). If, say, we set justification size to zero, then e.g. cost of Kusama -> Polkadot message delivery transaction drops from 1.27 DOTs to 0.13 DOTs. And within justification, signatures are occupying 99% - they're ~100Kb alone;
  3. maybe we have too many reserves in our constants. E.g. MAX_AUTHORITIES_COUNT is set to 1_256, when actually at Polkadot there are 300 authorities. Then after using this constant to compute cost of delivery transaction, we add another 33%.
@acatangiu
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment