Skip to content

Commit 3e846a1

Browse files
gustavo-griecomontylysmonicas
authored
Added L1 to L2 message failure as a possible issue (#140)
* Added L2 to L1 message failure as a possible issue * Title was wrong * Update consider_L1_to_L2_message_failure.md * Fixed * Update not-so-smart-contracts/cairo/consider_L1_to_L2_message_failure.md Co-authored-by: Simone <79767264+smonicas@users.noreply.github.com> * Update not-so-smart-contracts/cairo/consider_L1_to_L2_message_failure.md Co-authored-by: Simone <79767264+smonicas@users.noreply.github.com> Co-authored-by: Feist Josselin <josselin@trailofbits.com> Co-authored-by: Simone <79767264+smonicas@users.noreply.github.com>
1 parent 4ca5681 commit 3e846a1

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Consider L1 to L2 message failure
2+
3+
In Starknet, [Ethereum contracts can send messages from L1 to L2, using a bridge](https://starknet.io/docs/hello_starknet/l1l2.html#messages-from-l1-to-l2). However, it is not guaranteed that the message will be processed by the sequencer.
4+
For instance, a message can fail to be processed if there is a sudden spike in the gas price and the value provided is too low. For that reason, Starknet developers provided a
5+
[API to cancel on-going messages](https://docs.starknet.io/docs/L1-L2%20Communication/messaging-mechanism/#l1--l2-messages)
6+
7+
# Example
8+
9+
Suppose that the following code to initiate L2 deposits from L1, taking the tokens from the user:
10+
11+
```solidity
12+
IERC20 public constant token; //some token to deposit on L2
13+
14+
function depositToL2(uint256 to, uint256 amount) public returns (bool) {
15+
require(token.transferFrom(to, address(this), amount));
16+
..
17+
StarknetCore.sendMessageToL2(..);
18+
return true;
19+
}
20+
```
21+
22+
If a L1 message is never processed by the sequencer, users will never receive their tokens either in L1 or L2, so they need a way to cancel it.
23+
24+
As a more real example, a recent [AAVE audit](https://github.com/aave-starknet-project/aave-starknet-bridge/pull/106#issue-1336925381) highlighed this issue and required to add code to cancel messages.
25+
26+
# Mitigations
27+
28+
When sending a message from L1 to L2, consider the case where a message is never processed by the sequencer. This can block either the contract to reach certain state or users to retrieve their funds. Allow to use `startL1ToL2MessageCancellation` and `cancelL1ToL2Message` to cancel ongoing messages, if needed.

0 commit comments

Comments
 (0)