-
Notifications
You must be signed in to change notification settings - Fork 374
Added L1 to L2 message failure as a possible issue #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
14cb898
Added L2 to L1 message failure as a possible issue
gustavo-grieco 57b362d
Title was wrong
gustavo-grieco 9e19a41
Update consider_L1_to_L2_message_failure.md
gustavo-grieco 8b8cc72
Fixed
gustavo-grieco 32e4494
Update not-so-smart-contracts/cairo/consider_L1_to_L2_message_failure.md
montyly 2de6923
Update not-so-smart-contracts/cairo/consider_L1_to_L2_message_failure.md
montyly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
not-so-smart-contracts/cairo/consider_L1_to_L2_message_failure.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Consider L1 to L2 message failure | ||
|
|
||
| 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. | ||
| 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 | ||
| [API to cancel on-going messages](https://docs.starknet.io/docs/L1-L2%20Communication/messaging-mechanism/#l1--l2-messages) | ||
|
|
||
| # Example | ||
|
|
||
| Suppose that the following code to initiate L2 deposits from L1, taking the tokens from the user: | ||
|
|
||
| ```solidity | ||
| IERC20 public constant token; //some token to deposit on L2 | ||
|
|
||
| function depositToL2(uint256 to, uint256 amount) public returns (bool) { | ||
| require(token.transferFrom(to, address(this), amount)); | ||
| .. | ||
| StarknetCore.sendMessageToL2(..); | ||
| return true; | ||
| } | ||
| ``` | ||
|
|
||
| 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. | ||
|
|
||
| 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. | ||
|
|
||
| # Mitigations | ||
|
|
||
| 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. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be moved to a
Examplessection at the bottom I think