darwinia-network / darwinia-messages-sol

Darwinia cross-chain messages gateway and protocol for EVM developers 💌
MIT License
29 stars 8 forks source link

How to limit the gas of the message on source chain and target chain? #171

Open hackfisher opened 2 years ago

hackfisher commented 2 years ago

To open the message service to smart contracts, the message user will be able to customize the target dispatch contract call, and the source callback call etc.

And all the messages in one lane must be delivered in order, so if some dispatch/callback call consume too much gas and exceed the block max limit, then the block producers on target/source chain might refuse to include those relay transactions, and relayers can do nothing in this situation, following messages will be blocked by this message(nonce) too.

To avoid this potential attack, the dispatch/callback call must give an MESSAGE_MAX_DISPATCH_GAS/ MESSAGE_MAX_CALLBACK_GAS to limit the dispatch_gas_limit/callback_gas_limit encoded in the message.

The dispatch_gas_limit/callback_gas_limit encoded in the message has two functions:

  1. To limit the largest consumable gas for the smart contract(programmable + context_dynamic), and will be set as the gas limit in evm transactions. With the gas limited settings, these two value can be used to limit the gas, and for system level MESSAGE_MAX_DISPATCH_GAS/ MESSAGE_MAX_CALLBACK_GAS comparison.
  2. To give an extra message fee estimation prepaid by the user in addition to the relayer market fee, this is different compared to current, but is better because it simply the fee model for the relayers, they do not to consider the gas.

But there are extra factors need to detail and research further for 2, because, the fee prepaid are in source chain's token, but the dispatch_gas_limit might be in target chain's token, to calculate the prepaid fee, there might require an extra conversion between source token and target token here, and simple way will require introduce price feed by oracle.

cc @xiaoch05

hackfisher commented 2 years ago

Duplicate with https://github.com/darwinia-network/darwinia-messages-substrate/issues/107 for s2s

for evm to evm bridges, we might need to check we have same design.

hujw77 commented 2 years ago
hackfisher commented 2 years ago

@wuminzhe Will require SDK docs for this.

hujw77 commented 1 year ago

@wuminzhe Does SDK docs adopt the requires?

wuminzhe commented 1 year ago

@wuminzhe Does SDK docs adopt the requires?

No.

Does this need oracle? @hackfisher