Skip to content

Commit

Permalink
check that withdrawTo doesn't allow to withdraw to stETH on L1 address
Browse files Browse the repository at this point in the history
  • Loading branch information
kovalgek committed May 11, 2024
1 parent 2f895fa commit be90d6b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
6 changes: 6 additions & 0 deletions contracts/optimism/L2ERC20ExtendedTokensBridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ contract L2ERC20ExtendedTokensBridge is
onlyNonZeroAccount(to_)
onlySupportedL2Token(l2Token_)
{
/// @dev L1_TOKEN_REBASABLE doesn't allow to transfer to itself.
/// To prevent stucking tokens on L1 bridge this check was added.
if (to_ == L1_TOKEN_REBASABLE) {
revert ErrorTransferToL1TokenRebasableContract();
}
_withdrawTo(l2Token_, msg.sender, to_, amount_, l1Gas_, data_);
emit WithdrawalInitiated(_getL1Token(l2Token_), l2Token_, msg.sender, to_, amount_, data_);
}
Expand Down Expand Up @@ -209,4 +214,5 @@ contract L2ERC20ExtendedTokensBridge is

error ErrorSenderNotEOA();
error ErrorZeroAddressL1Bridge();
error ErrorTransferToL1TokenRebasableContract();
}
28 changes: 27 additions & 1 deletion test/optimism/L2ERC20ExtendedTokensBridge.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ unit("Optimism:: L2ERC20ExtendedTokensBridge", ctxFactory)
.test("initial state", async (ctx) => {
const {
l2TokenBridge,
accounts: {l1TokenBridgeEOA, l2MessengerStubEOA},
accounts: { l1TokenBridgeEOA, l2MessengerStubEOA },
stubs: { l1TokenNonRebasable, l2TokenNonRebasable, l1TokenRebasable, l2TokenRebasable },
} = ctx;

Expand Down Expand Up @@ -768,6 +768,32 @@ unit("Optimism:: L2ERC20ExtendedTokensBridge", ctxFactory)
assert.equalBN(await l2TokenNonRebasable.totalSupply(), totalSupplyBefore);
})

.test("withdrawTo() :: sending to L1 stETH address", async (ctx) => {
const {
l2TokenBridge,
accounts: { recipient },
stubs: {
l1TokenRebasable,
l2TokenRebasable
},
} = ctx;

const l1Gas = wei`1 wei`;
const data = "0xdeadbeaf";

await assert.revertsWith(
l2TokenBridge
.connect(recipient)
.withdrawTo(
l2TokenRebasable.address,
l1TokenRebasable.address,
0,
l1Gas,
data),
"ErrorTransferToL1TokenRebasableContract()"
);
})

.test("finalizeDeposit() :: deposits disabled", async (ctx) => {
const {
l2TokenBridge,
Expand Down

0 comments on commit be90d6b

Please sign in to comment.