Skip to content

Commit 88a70a6

Browse files
remove l1_handler and burn tokens
1 parent a18c083 commit 88a70a6

File tree

2 files changed

+10
-6
lines changed
  • not-so-smart-contracts/cairo

2 files changed

+10
-6
lines changed

not-so-smart-contracts/cairo/overconstrained_l1_l2_interaction/README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,28 @@ When interacting with contracts that are designed to interact with both L1 and L
44

55
## Example
66

7-
The following Starknet bridge contract allows for permissionless deposit to any address on L1 via the `deposit_to_L1` function. In particular, someone can deposit tokens to the `BAD_ADDRESS`.However the tokens will be trapped on L1 because the L1 contract's `depositFromL2` function is not permissionless and prevents `BAD_ADDRESS` from being the recipient.
7+
The following Starknet bridge contract allows for permissionless deposit to any address on L1 via the `deposit_to_L1` function. In particular, someone can deposit tokens to the `BAD_ADDRESS`. However, in that case the tokens will be lost forever, because the tokens are burned on L2 and the L1 contract's `depositFromL2` function prevents `BAD_ADDRESS` from being the recipient.
88

99
```Cairo
1010
#[storage]
1111
struct Storage {
1212
l1_bridge: EthAddress,
13-
13+
balances: LegacyMap<ContractAddress,u256>
1414
}
15+
1516
#[derive(Serde)]
1617
struct Deposit {
1718
recipient: EthAddress,
1819
token: EthAddress,
1920
amount: u256
2021
}
2122
22-
#[l1_handler]
23-
fn deposit_to_l1(ref self:ContractState, deposit: Deposit) {
23+
fn deposit_to_l1(ref self: ContractState, deposit: Deposit) {
24+
let caller = get_caller_address();
25+
//burn the tokens on the L2 side
26+
self.balances.write(caller, self.balances.read(caller) - deposit.amount);
2427
let payload = ArrayTrait::new();
25-
starknet::send_message_to_l1_syscall(self.l1_bridge.read(),deposit.serialize(ref payload)).unwrap();
28+
starknet::send_message_to_l1_syscall(self.l1_bridge.read(), deposit.serialize(ref payload)).unwrap();
2629
}
2730
```
2831

@@ -50,6 +53,7 @@ function _buildPayload(address recipient, address token, uint256 amount) interna
5053
[...]
5154
}
5255
```
56+
5357
## Mitigations
5458

5559
- Make sure to validate that the checks on both the L1 and L2 side are similar enough to prevent unexpected behavior. Ensure that any unsymmetric validations on either side cannot lead to a tokens being trapped or any other denial of service.

not-so-smart-contracts/cairo/unchecked_from_address_in_l1_handler/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct Storage {
3131
}
3232
3333
#[l1_handler]
34-
fn set_owner_from_l1(ref self:ContractState, from_address: felt252, new_owner: ContractAddress) {
34+
fn set_owner_from_l1(ref self: ContractState, from_address: felt252, new_owner: ContractAddress) {
3535
self.owner.write(new_owner);
3636
}
3737

0 commit comments

Comments
 (0)