L1 to L2 Messaging
Overview
L1 to L2 messaging is implemented by L1 triggered L2 transactions. (Asset transfers are based on this mechanism)
Rooch has the ability of multi-chain asset settlement, for each L1, its L1 to L2 process is the same (note: the contract name and its parameters are slightly different on L1 due to different smart contract languages), it is the light node on Rooch that verifies the event from L1 and then executes the L2 transaction:
L1
L1 needs to generate events for L2 calls that contain all the information needed for the L2 call and the process that took place on L1, which will be parsed by the rooch_node and relayed to L2.
-
The user initiates the L1 to L2 request by calling the
call_remotefunction inl1_stubwith the following parameters.action: the encoded Rooch MoveAction 2.min_gas_amount: the minimum amount of gas allowed on L2, i.e. an estimate of the value of the callaction. Considering the processing overhead that L2 requires before callingaction, the actual overhead will definitely exceed this value. See Gas Fees for details.
l1_stubprovides a more user-friendly interface, where the caller only needs to be concerned with the L2 call information and not with message encapsulation and delivery. -
l1_stubwill call thesend_l1_to_l2function ofrooch_transportto accomplish event logging and gas burning on L1 with the following parameters:- `msg_sequence
- `msg_sender
action4.min_gas_amount3.
-
send_l1_to_l2Emits theL1ToL2Eventevent upon completion of the check, which includes:msg_sequence- `msg_sender
actionmin_gas_amountfrom: the originator ofsend_l1_to_l2. In this case it isl1_stub.gas_amount: Base gas overhead on L2 based onmin_gas_amountand estimated fromactionsize. It is also the main basis for the amount of gas burned on L1.L1ToL2Event_version: event version number
L2
rooch_nodelistens to theL1ToL2Eventevent, parses its parameters, generates a proof of inclusion of the L1 event (that it happened on L1), and finally encapsulates it in an L2 tx. 2.- pass the L2 tx to executor to validate the L1 event containment proof, executor will use the light node contract corresponding to L1 to validate the event containment proof. 3. after successful validation, execute
L1ToL2Eventevent. - execute
actionafter successful verification.
Gas Fees
Gas Fee is divided into two parts:
- L1 contract calling overhead
- L2 contract calling overhead (realized by L1 combustion)
L1 contract call overhead accounts for most of the overall overhead, while L2 contract overhead is relatively small and has a certain free amount (for most of the asset transfer scenarios, the L2 free amount is more than enough). Anything above the free credit will be burned on L1 at a certain percentage:
It's like a Gas Variable speed device, for different chains we just replace the L1 gear (adjust the L2:L1 gas ratio) to automate the combustion on the L1. This way, no matter which L1, the user only needs to be concerned about the overhead of the objective function on L2. and does not need to be concerned with the complexity of gas pricing.
Burning will be implemented as a while loop in L1, with the following pseudo-code:
i = 0
while (i < burn_amount) {
i++
}Security
Rooch's L1 to L2 messaging mechanism guarantees that contract calls on L1 are correctly relayed to L2, and that the contract on L2 is responsible for checking the caller on L1 itself.
This requires that the relevant sender information be encapsulated as a parameter to the action in l1_stub.call_remote.